add md-fund remove/order

This commit is contained in:
Li Jianxuan 2013-04-21 01:52:07 +00:00
parent e4307011e7
commit b315128848
4 changed files with 3908 additions and 3813 deletions

File diff suppressed because it is too large Load Diff

View File

@ -89,15 +89,15 @@ table thead tr th {background:#EBF2F6;}
<?php $autoindex=0; <?php $autoindex=0;
foreach ($this->paginator as $item): foreach ($this->paginator as $item):
$autoindex++;?> $autoindex++;?>
<tr id="DataLine_<?= $item['id']?>"> <tr id="DataLine_<?= $item['mfid']?>">
<td><?= $item['title'] ?></td> <td><?= $item['title'] ?></td>
<td><?= $item['fund_id'] ?></td> <td><?= $item['fund_id'] ?></td>
<td><?= $item['fund_type'] ?></td> <td><?= $item['fund_type'] ?></td>
<?php if($this->md) { ?> <?php if($this->md) { ?>
<?php if($this->ct) { ?> <?php if($this->ct) { ?>
<td><input type="text" name="order" id="order_<?= $item['id']?>" class="span12" /></td> <td><input type="text" name="order" id="order_<?= $item['id']?>" class="span12" /></td>
<?php }else{ ?> <?php }else{ ?>
<td><?= $item['place'] ?></td> <td><input type="text" name="order" id="order_<?= $item['mfid']?>" class="span12" value="<?= $item['place'] ?>" /></td>
<?php }?> <?php }?>
<?php }else{ ?> <?php }else{ ?>
<td><?= $item['title_en'] ?></td> <td><?= $item['title_en'] ?></td>
@ -107,9 +107,12 @@ table thead tr th {background:#EBF2F6;}
<td><a href="javascript:void(0);" class="addtomd" rel="<?= $item['id']?>">添加此项目</a></td> <td><a href="javascript:void(0);" class="addtomd" rel="<?= $item['id']?>">添加此项目</a></td>
<?php } ?> <?php } ?>
<td> <td>
<a href="/admin/data/fund/ac/edit/id/<?= $item['id']?>">编辑</a> <?php if(empty($this->md)) { ?>
<?php if(empty($this->ct)) { ?> <a href="/admin/data/fund/ac/edit/id/<?= $item['id']?>">编辑</a>
<a href="javascript:void(0);" onclick="onedel(<?= $item['id']?>)" id="delbtn_<?= $item['id']?>">删除</a> <a href="javascript:void(0);" onclick="onedel(<?= $item['id']?>)" id="delbtn_<?= $item['id']?>">删除</a>
<?php }else{ ?>
<?php if(empty($this->ct)) { ?><a href="javascript:void(0);" class="changeorder" rel="<?= $item['mfid']?>">排序</a> <?php } ?>
<a href="javascript:void(0);" onclick="onedel(<?= $item['mfid']?>)" id="delbtn_<?= $item['mfid']?>">移除</a>
<?php } ?> <?php } ?>
</td> </td>
</tr> </tr>
@ -124,6 +127,7 @@ table thead tr th {background:#EBF2F6;}
</div> </div>
<!-- //页面内容 --> <!-- //页面内容 -->
<script> <script>
<?php if(!empty($this->ct)) { ?>
$('.addtomd').each(function(index, element) { $('.addtomd').each(function(index, element) {
$(this).click(function(){ $(this).click(function(){
id = $(this).attr('rel'); id = $(this).attr('rel');
@ -131,11 +135,26 @@ $('.addtomd').each(function(index, element) {
self.location='/admin/data/fund/ac/formd/uuid/<?= $this->md['uuid'] ?>/id/'+id+'/order/'+ order self.location='/admin/data/fund/ac/formd/uuid/<?= $this->md['uuid'] ?>/id/'+id+'/order/'+ order
}); });
}); });
<?php if(empty($this->ct)) { ?> <?php }else{ ?>
$('.changeorder').each(function(index, element) {
$(this).click(function(){
id = $(this).attr('rel');
order = $('#order_'+id).val();
self.location='/admin/data/fund/ac/formd/uuid/<?= $this->md['uuid'] ?>/mfid/'+id+'/order/'+ order
});
});
<?php } ?>
<?php if(empty($this->md)) { ?>
var info = { var info = {
btn_prefix : "delbtn_", btn_prefix : "delbtn_",
item_prefix : "DataLine_", item_prefix : "DataLine_",
url : "/admin/data/fund/ac/del" url : "/admin/data/fund/ac/del"
} }
<?php }else{ ?>
var info = {
btn_prefix : "delbtn_",
item_prefix : "DataLine_",
url : "/admin/data/fund/ac/mdfunddel/uuid/<?= $this->md['uuid'] ?>"
}
<?php } ?> <?php } ?>
</script> </script>

View File

@ -1,139 +1,166 @@
<?php <?php
class Fund extends Zend_Controller_Plugin_Abstract class Fund extends Zend_Controller_Plugin_Abstract
{ {
private $db; //传入PDO对象. private $db; //传入PDO对象.
private $auth = NULL; //Zend_Auth 对象 private $auth = NULL; //Zend_Auth 对象
public $tbl_fund = "fund"; //项目 public $tbl_fund = "fund"; //项目
public $tbl_mdfund = "mdfund"; //对应表 public $tbl_mdfund = "mdfund"; //对应表
private $fundFields; private $fundFields;
function __construct($db,Zend_Auth $auth=NULL) function __construct($db,Zend_Auth $auth=NULL)
{ {
$this->db = $db; $this->db = $db;
$this->auth = $auth; $this->auth = $auth;
} }
function fetch($uuid = "",$include = true){ function fetch($uuid = "",$include = true){
if(empty($uuid)) if(empty($uuid))
{ {
$sql = "SELECT * FROM ".$this->tbl_fund." ORDER BY id DESC"; $sql = "SELECT * FROM ".$this->tbl_fund." ORDER BY id DESC";
$rs = $this->db->query($sql); $rs = $this->db->query($sql);
$rows = $rs->fetchAll(); $rows = $rs->fetchAll();
return $rows; return $rows;
}else{ }else{
if($include) if($include)
{ {
$sql = "SELECT f.*,mf.place FROM ".$this->tbl_fund." f $sql = "SELECT f.*,mf.place,mf.id as mfid FROM ".$this->tbl_fund." f
LEFT JOIN ".$this->tbl_mdfund." mf ON mf.fid=f.id LEFT JOIN ".$this->tbl_mdfund." mf ON mf.fid=f.id
WHERE uuid='$uuid' WHERE uuid='$uuid'
ORDER BY mf.place DESC"; ORDER BY mf.place DESC";
}else{ }else{
$fids = $this->getMdFunds($uuid); $fids = $this->getMdFunds($uuid);
if(count($fids)>0) if(count($fids)>0)
{ {
$fids = ' WHERE f.id NOT IN ('.join(",",$fids).')'; $fids = ' WHERE f.id NOT IN ('.join(",",$fids).')';
}else{ }else{
$fids = ""; $fids = "";
} }
$sql = "SELECT f.* FROM ".$this->tbl_fund." f $fids ORDER BY f.id DESC"; $sql = "SELECT f.* FROM ".$this->tbl_fund." f $fids ORDER BY f.id DESC";
} }
$rs = $this->db->query($sql); $rs = $this->db->query($sql);
$rows = $rs->fetchAll(); $rows = $rs->fetchAll();
return $rows; return $rows;
} }
} }
function add($data) function add($data)
{ {
include_once("helper/dbh.php"); include_once("helper/dbh.php");
$dbh = new dbh($this->db); $dbh = new dbh($this->db);
return $dbh->insert($this->tbl_fund,$data); return $dbh->insert($this->tbl_fund,$data);
} }
function update($data,$id) function update($data,$id)
{ {
include_once("helper/dbh.php"); include_once("helper/dbh.php");
$dbh = new dbh($this->db); $dbh = new dbh($this->db);
if(empty($id)) if(empty($id))
{ {
return "参数错误"; return "参数错误";
} }
$state = $dbh->update($this->tbl_fund,$data,"id=$id",true); $state = $dbh->update($this->tbl_fund,$data,"id=$id",true);
if( $state == true) if( $state == true)
{ {
return true; return true;
}else{ }else{
return $state; return $state;
} }
} }
function delete($id){ function delete($id){
$sql = "DELETE FROM ".$this->tbl_fund." WHERE id=$id"; $sql = "DELETE FROM ".$this->tbl_fund." WHERE id=$id";
return $this->db->exec($sql); return $this->db->exec($sql);
} }
function view($id){ function mfdelete($id){
$sql = "SELECT * FROM ".$this->tbl_fund." WHERE id=$id"; $sql = "DELETE FROM ".$this->tbl_mdfund." WHERE id=$id";
$rs = $this->db->query($sql); return $this->db->exec($sql);
$row = $rs->fetch(); }
return $row;
} function view($id){
$sql = "SELECT * FROM ".$this->tbl_fund." WHERE id=$id";
function getMdFunds($uuid){ $rs = $this->db->query($sql);
$sql = "SELECT * FROM ".$this->tbl_mdfund." WHERE uuid='$uuid'"; $row = $rs->fetch();
$rs = $this->db->query($sql); return $row;
$rows = $rs->fetchAll(); }
$fids = array(); function getMdFunds($uuid){
foreach($rows as $k=>$v) $sql = "SELECT * FROM ".$this->tbl_mdfund." WHERE uuid='$uuid'";
{ $rs = $this->db->query($sql);
$fids[] = $v['fid']; $rows = $rs->fetchAll();
}
return $fids; $fids = array();
} foreach($rows as $k=>$v)
{
function addToMdfund($uuid,$id,$order){ $fids[] = $v['fid'];
if(empty($order)) }
{ return $fids;
$order = 0; }
}
$data = array( function addToMdfund($uuid,$id,$order){
'uuid'=>$uuid, if(empty($order))
'fid'=>$id, {
'place'=>$order $order = 0;
); }
include_once("helper/dbh.php"); $data = array(
$dbh = new dbh($this->db); 'uuid'=>$uuid,
return $dbh->insert($this->tbl_mdfund,$data); 'fid'=>$id,
} 'place'=>$order
);
function addPaginator($data,$ctl,Zend_Controller_Request_Abstract $request) include_once("helper/dbh.php");
{ $dbh = new dbh($this->db);
$page = $request->getParam('page'); return $dbh->insert($this->tbl_mdfund,$data);
}
$paginator = Zend_Paginator::factory($data);
$paginator->setCurrentPageNumber($page); function changeorder($id,$order){
$paginator->setItemCountPerPage(12); if(!is_numeric($id) || !is_numeric($order))
$paginator->setView($ctl); {
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml'); return false;
$ctl->paginator = $paginator; }
}
$data = array(
function _getParams(Zend_Controller_Request_Abstract $request) 'place'=>$order
{ );
$data = array(
'title' => trim($request->getParam('title')), include_once("helper/dbh.php");
'fund_id' => trim($request->getParam('fund_id')), $dbh = new dbh($this->db);
'fund_type' => trim($request->getParam('fund_type')), $state = $dbh->update($this->tbl_mdfund,$data,"id=$id",true);
'title_en' => trim($request->getParam('title_en')),
'fund_type_en' => trim($request->getParam('fund_type_en')), if( $state == true)
); {
return $data; return true;
} }else{
return $state;
} }
}
function addPaginator($data,$ctl,Zend_Controller_Request_Abstract $request)
{
$page = $request->getParam('page');
$paginator = Zend_Paginator::factory($data);
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage(12);
$paginator->setView($ctl);
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination_param.phtml');
$ctl->paginator = $paginator;
}
function _getParams(Zend_Controller_Request_Abstract $request)
{
$data = array(
'title' => trim($request->getParam('title')),
'fund_id' => trim($request->getParam('fund_id')),
'fund_type' => trim($request->getParam('fund_type')),
'title_en' => trim($request->getParam('title_en')),
'fund_type_en' => trim($request->getParam('fund_type_en')),
);
return $data;
}
}

View File

@ -1,115 +1,125 @@
// JavaScript Document // JavaScript Document
$(document).ready(function() { $(document).ready(function() {
gebo_select_row.init(); gebo_select_row.init();
gebo_delete_rows.simple(); gebo_delete_rows.simple();
}); });
gebo_select_row = { gebo_select_row = {
init: function() { init: function() {
$('.select_rows').click(function () { $('.select_rows').click(function () {
var tableid = $(this).data('tableid'); var tableid = $(this).data('tableid');
$('#'+tableid).find('input[name=row_sel]').attr('checked', this.checked); $('#'+tableid).find('input[name=row_sel]').attr('checked', this.checked);
}); });
} }
}; };
gebo_delete_rows = { gebo_delete_rows = {
simple: function() { simple: function() {
$(".delete_rows_simple").on('click',function (e) { $(".delete_rows_simple").on('click',function (e) {
e.preventDefault(); e.preventDefault();
var tableid = $(this).data('tableid'); var tableid = $(this).data('tableid');
if($('input[name=row_sel]:checked', '#'+tableid).length) { if($('input[name=row_sel]:checked', '#'+tableid).length) {
$.colorbox({ $.colorbox({
initialHeight: '0', initialHeight: '0',
initialWidth: '0', initialWidth: '0',
href: "#confirm_dialog", href: "#confirm_dialog",
inline: true, inline: true,
opacity: '0.3', opacity: '0.3',
onComplete: function(){ onComplete: function(){
$('.confirm_yes').click(function(e){ $('.confirm_yes').click(function(e){
e.preventDefault(); e.preventDefault();
$('input[name=row_sel]:checked', '#'+tableid).each(function(index, element) { $('input[name=row_sel]:checked', '#'+tableid).each(function(index, element) {
del($(this).val()); del($(this).val());
}); });
$('input[name=select_rows]:checked').removeAttr('checked'); $('input[name=select_rows]:checked').removeAttr('checked');
$.colorbox.close(); $.colorbox.close();
}); });
$('.confirm_no').click(function(e){ $('.confirm_no').click(function(e){
e.preventDefault(); e.preventDefault();
$.colorbox.close(); $.colorbox.close();
}); });
} }
}); });
} }
}); });
} }
}; };
var confrimHTML = '<div class=""><div class="modal-header"><h3>是否确定删除?</h3></div>' var confrimHTML = '<div class=""><div class="modal-header"><h3>是否确定删除?</h3></div>'
+ '<div class="modal-footer"><a href="javascript:void(0);" class="btn btn-primary confirm_yes">是</a><a href="javascript:void(0);" class="btn confirm_no">否</a></div></div>'; + '<div class="modal-footer"><a href="javascript:void(0);" class="btn btn-primary confirm_yes">是</a><a href="javascript:void(0);" class="btn confirm_no">否</a></div></div>';
function onedel(id) function onedel(id)
{ {
$.colorbox({ if(typeof(info) == "undefined")
initialHeight: '100', {
initialWidth: '200', Alert('信息参数设置不正确');
//href: "#confirm_dialog", return false;
//inline: true, }
opacity: '0.3', $.colorbox({
onComplete: function(){ initialHeight: '100',
$('.confirm_yes').click(function(e){ initialWidth: '200',
e.preventDefault(); //href: "#confirm_dialog",
del(id); //inline: true,
$.colorbox.close(); opacity: '0.3',
}); onComplete: function(){
$('.confirm_no').click(function(e){ $('.confirm_yes').click(function(e){
e.preventDefault(); e.preventDefault();
$.colorbox.close(); del(id);
}); $.colorbox.close();
}, });
html: confrimHTML $('.confirm_no').click(function(e){
}); e.preventDefault();
} $.colorbox.close();
});
function del(id){ },
btn = $('#'+info.btn_prefix+id); html: confrimHTML
func = btn.attr('onclick'); });
html = btn.html(); }
$.ajax({
'type':"POST", function del(id){
'url': info.url, if(typeof(info) == "undefined")
'data': 'id='+id, {
'success':function(data){ alert('信息参数设置不正确');
if (typeof(data)=='object') return false;
{ }
if(typeof(data.error) !== 'undefined') btn = $('#'+info.btn_prefix+id);
{ func = btn.attr('onclick');
Alert(data.error);return false; html = btn.html();
} $.ajax({
if(typeof(data.deleted !== 'undefined')) 'type':"POST",
{ 'url': info.url,
$('#'+info.item_prefix+id).remove(); 'data': 'id='+id,
} 'success':function(data){
} if (typeof(data)=='object')
else{ {
Alert('出现错误,请稍后再试'); if(typeof(data.error) !== 'undefined')
} {
}, Alert(data.error);return false;
'timeout': 15000, }
'error': function(){ if(typeof(data.deleted !== 'undefined'))
Alert('处理中出现错误,请刷新页面后重试'); {
}, $('#'+info.item_prefix+id).remove();
'beforeSend':function(){ }
btn.attr('onclick',''); }
btn.html('<img src="/images/ajax-load-small.gif" />'); else{
}, Alert('出现错误,请稍后再试');
'complete':function(){ }
btn.attr('onclick',func); },
btn.html(html); 'timeout': 15000,
} 'error': function(){
}); Alert('处理中出现错误,请刷新页面后重试');
} },
'beforeSend':function(){
function Alert(content){ btn.attr('onclick','');
$.colorbox({innerWidth:'40%',html:'<div style="line-height:30px;font-size:16px;">'+ content +'</div>'}); btn.html('<img src="/images/ajax-load-small.gif" />');
},
'complete':function(){
btn.attr('onclick',func);
btn.html(html);
}
});
}
function Alert(content){
$.colorbox({innerWidth:'40%',html:'<div style="line-height:30px;font-size:16px;">'+ content +'</div>'});
} }