添加了数据文献的编辑功能,在文献列表页面添加了快速添加数据文献的按钮

This commit is contained in:
Li Jianxuan 2013-10-10 02:19:46 +00:00
parent e1f1a30f98
commit d978e0e8c7
6 changed files with 103 additions and 76 deletions

View File

@ -1147,11 +1147,13 @@ class Admin_DataController extends Zend_Controller_Action
//文献首页
if(empty($ac))
{
$this->view->referenceType = $reference->referenceType();
view::addPaginator($reference->fetchReferences(),$this,12);
return true;
}
else if ($ac == "water")
{
$this->view->referenceType = $reference->referenceType();
view::addPaginator($reference->fetchThemeReferences('water'),$this,10);
return true;
}

View File

@ -33,6 +33,7 @@
<?php } ?>
</div>
</div>
<input type="hidden" name="id" value="" />
</form>
</div>
<div id="alert-info"></div>
@ -40,6 +41,7 @@
<div class="progress progress-striped active" id="submit-loading" style="display:none;">
<div class="bar" style="width:100%;"></div>
</div>
<button onclick="$('#mdref')[0].reset();" class="btn">Reset</button>
<button onclick="$('#mdref-form').modal('hide');" class="btn">Close</button>
<button onclick="mdref.create()" class="btn btn-primary" id="submit_btn">Save changes</button>
</div>

View File

@ -8,6 +8,7 @@ $this->breadcrumb('文献管理');
$this->breadcrumb()->setSeparator(' > ');
$this->theme->AppendPlus($this,'colorbox');
$this->theme->AppendPlus($this,'admin_plugin');
$this->theme->AppendModel($this,'admin-data-ref');
?>
<style>
table thead tr th {background:#EBF2F6;}
@ -26,13 +27,14 @@ table thead tr th {background:#EBF2F6;}
<?php if(!empty($this->msg)) { ?>
<?= $this->msg ?>
<?php } else{ ?>
<button type="button" class="btn btn-primary" onclick="$('#mdref-form').modal('show');">添加一条</button>
<button type="button" class="btn btn-primary" onclick="$('#mdref')[0].reset();$('#mdref-form').modal('show');">添加一条</button>
<div id="datalist">
<?php if (count($this->paginator)): ?>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>元数据</th>
<th>类型</th>
<th>排序</th>
<th width="140">操作</th>
</tr>
@ -43,9 +45,10 @@ table thead tr th {background:#EBF2F6;}
$autoindex++;?>
<tr id="DataLine_<?= $item['id']?>">
<td><?= $item['title'] ?></td>
<td><?= isset($this->referenceType[$item['reftype']]) ? $this->referenceType[$item['reftype']]:"" ?></td>
<td><?= $item['place'] ?></td>
<td>
<a href="javascript:void(0);" onclick="mdref.edit(<?= $item['id']?>)">编辑</a>
<a href="javascript:void(0);" onclick="mdref.edit(<?= $item['id'] ?>,<?= $item['refid']?>,'<?= $item['uuid'] ?>',<?= $item['reftype'] ?>,<?= $item['place'] ?>)">编辑</a>
<a href="/admin/data/ref/ac/delmdref/id/<?= $item['id']?>">移除</a>
</td>
</tr>
@ -63,60 +66,4 @@ table thead tr th {background:#EBF2F6;}
<script>
$(document).ready(function(e) {
});
var mdref = {
create : function(){
data = $('#mdref').serialize();
$.ajax({
'type':"POST",
'url':"/admin/data/ref/ac/mdref/",
'data':data,
'success':mdref.onsuccessed,
'timeout': 30000,
'error': function(){
$("#alert-info").attr('class','alert alert-error');
$("#alert-info").html("出现错误,请稍后重试");
$('#submit-loading').hide();
return false;
},
'beforeSend': function(){
$("#submit_btn").addClass('disabled');
$("#submit_btn").attr('disabled','disabled');
$('#submit-loading').show();
},
'complete': function(){
$("#submit_btn").removeClass('disabled');
$("#submit_btn").removeAttr('disabled');
$('#submit-loading').hide();
}
});
},
onsuccessed : function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{
$("#alert-info").attr('class','alert alert-error');
$("#alert-info").html(data.error);
return false;
}
if(typeof(data.success)!='undefined')
{
$("#alert-info").attr('class','alert alert-success');
$("#alert-info").html("添加成功!");
setTimeout("$('#mdref-form').modal('hide');",1000);
setTimeout("window.location.href = window.location.href",2000);
return false;
}
}
else{
$("#alert-info").attr('class','alert alert-error');
$("#alert-info").html('请求中发生错误,请重试');
return false;
}
},
edit : function(id)
{
alert(id);
}
}
</script>

View File

@ -8,6 +8,7 @@ $this->breadcrumb('文献管理');
$this->breadcrumb()->setSeparator(' > ');
$this->theme->AppendPlus($this,'colorbox');
$this->theme->AppendPlus($this,'admin_plugin');
$this->theme->AppendModel($this,'admin-data-ref');
?>
<style>
table thead tr th {background:#EBF2F6;}
@ -63,7 +64,7 @@ table thead tr th {background:#EBF2F6;}
<td><?= $item['year'] ?></td>
<td rowspan="2">
<a href="/admin/data/ref/ac/add/id/<?= $item['id']?>">编辑</a>
<a href="/admin/data/ref/ac/data/id/<?= $item['id'] ?>">数据</a>
<a href="/admin/data/ref/ac/data/id/<?= $item['id'] ?>">数据</a>(<a href="javascript:void(0);" onclick="$('#mdref')[0].reset();mdref.edit(<?= $item['id'] ?>,<?= $item['id']?>,'',0,0)">+</a>)
<a href="/admin/data/ref/ac/deleteref/id/<?= $item['id']?>">删除</a>
</td>
</tr>
@ -90,5 +91,4 @@ table thead tr th {background:#EBF2F6;}
</div>
</div>
<!-- //页面内容 -->
<script>
</script>
<?= $this->partial('data/ref-mdref-form.phtml',array('referenceType'=>$this->referenceType,'refid'=>$this->refid)); ?>

View File

@ -280,7 +280,7 @@ class Reference
}
//建立文献与数据的关系
public function createRelationFromReferenceToData($refid,$uuid,$reftype,$place)
public function createRelationFromReferenceToData($refid,$uuid,$reftype,$place,$id = NULL)
{
if(empty($refid) || !is_numeric($refid))
{
@ -301,14 +301,26 @@ class Reference
$dbh = new dbh();
$id = $dbh->insert($this->table->metadata_reference,$data,true);
if(is_numeric($id))
if(empty($id))
{
return $id;
$id = $dbh->insert($this->table->metadata_reference,$data,true);
if(is_numeric($id))
{
return $id;
}else{
return "关系写入失败,请检查是否已经存在";
}
}else{
return "关系写入失败,请检查是否已经存在";
}
$status = $dbh->update($this->table->metadata_reference,$data," id=$id ");
if($status === true)
{
return $id;
}else{
return "修改失败";
}
}
}
//获得某个文献关联的数据 (根据文献获得数据)
@ -319,9 +331,10 @@ class Reference
return "参数错误";
}
$sql = "SELECT mr.id,mr.reftype,mr.place,md.title,md.uuid FROM {$this->table->metadata_reference} mr
$sql = "SELECT mr.id,mr.refid,mr.reftype,mr.place,md.title,md.uuid FROM {$this->table->metadata_reference} mr
LEFT JOIN {$this->table->metadata} md ON mr.uuid=md.uuid
WHERE mr.refid=$id";
WHERE mr.refid=$id
ORDER BY mr.place ASC";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
@ -370,12 +383,9 @@ class Reference
}
//写入数据文献
public function makeMdref($data = NULL)
public function makeMdref($id = NULL)
{
if(empty($data))
{
$data = $this->getMdrefParam();
}
$data = $this->getMdrefParam();
$results = $this->events()->trigger('mdref.checkParam', $this, compact('data'));
$cache_data = $results->bottom();
@ -388,7 +398,7 @@ class Reference
$results = $this->events()->trigger('mdref.processData', $this, compact('data'));
$data = $results->bottom();
$id = $this->createRelationFromReferenceToData($data['refid'],$data['uuid'],$data['reftype'],$data['place']);
$id = $this->createRelationFromReferenceToData($data['refid'],$data['uuid'],$data['reftype'],$data['place'],$id);
if(is_numeric($id))
{

View File

@ -0,0 +1,66 @@
var mdref = {
create : function(){
data = $('#mdref').serialize();
$.ajax({
'type':"POST",
'url':"/admin/data/ref/ac/mdref/",
'data':data,
'success':mdref.onsuccessed,
'timeout': 30000,
'error': function(){
$("#alert-info").attr('class','alert alert-error');
$("#alert-info").html("出现错误,请稍后重试");
$('#submit-loading').hide();
return false;
},
'beforeSend': function(){
$("#submit_btn").addClass('disabled');
$("#submit_btn").attr('disabled','disabled');
$('#submit-loading').show();
},
'complete': function(){
$("#submit_btn").removeClass('disabled');
$("#submit_btn").removeAttr('disabled');
$('#submit-loading').hide();
}
});
},
onsuccessed : function(data){
if (typeof(data)=='object')
{
if(typeof(data.error)!='undefined')
{
$("#alert-info").attr('class','alert alert-error');
$("#alert-info").html(data.error);
return false;
}
if(typeof(data.success)!='undefined')
{
$("#alert-info").attr('class','alert alert-success');
$("#alert-info").html("添加成功!");
setTimeout("$('#mdref-form').modal('hide');",1000);
setTimeout("window.location.href = window.location.href",2000);
return false;
}
}
else{
$("#alert-info").attr('class','alert alert-error');
$("#alert-info").html('请求中发生错误,请重试');
return false;
}
},
edit : function(id,refid,uuid,reftype,place)
{
$('#mdref input[name=id]').val(id);
$('#mdref input[name=refid]').val(refid);
$('#mdref input[name=uuid]').val(uuid);
$('#mdref input[name=place]').val(place);
$('input[name=reftype]').each(function(index, element) {
if($(this).val() == reftype)
{
$(this).attr('checked','checked');
}
});
$('#mdref-form').modal('show');
}
}