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;
foreach ($this->paginator as $item):
$autoindex++;?>
<tr id="DataLine_<?= $item['id']?>">
<tr id="DataLine_<?= $item['mfid']?>">
<td><?= $item['title'] ?></td>
<td><?= $item['fund_id'] ?></td>
<td><?= $item['fund_type'] ?></td>
<?php if($this->md) { ?>
<?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{ ?>
<td><?= $item['place'] ?></td>
<td><input type="text" name="order" id="order_<?= $item['mfid']?>" class="span12" value="<?= $item['place'] ?>" /></td>
<?php }?>
<?php }else{ ?>
<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>
<?php } ?>
<td>
<a href="/admin/data/fund/ac/edit/id/<?= $item['id']?>">编辑</a>
<?php if(empty($this->ct)) { ?>
<?php if(empty($this->md)) { ?>
<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>
<?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 } ?>
</td>
</tr>
@ -124,6 +127,7 @@ table thead tr th {background:#EBF2F6;}
</div>
<!-- //页面内容 -->
<script>
<?php if(!empty($this->ct)) { ?>
$('.addtomd').each(function(index, element) {
$(this).click(function(){
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
});
});
<?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 = {
btn_prefix : "delbtn_",
item_prefix : "DataLine_",
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 } ?>
</script>

View File

@ -1,139 +1,166 @@
<?php
class Fund extends Zend_Controller_Plugin_Abstract
{
private $db; //传入PDO对象.
private $auth = NULL; //Zend_Auth 对象
public $tbl_fund = "fund"; //项目
public $tbl_mdfund = "mdfund"; //对应表
private $fundFields;
function __construct($db,Zend_Auth $auth=NULL)
{
$this->db = $db;
$this->auth = $auth;
}
function fetch($uuid = "",$include = true){
if(empty($uuid))
{
$sql = "SELECT * FROM ".$this->tbl_fund." ORDER BY id DESC";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
return $rows;
}else{
if($include)
{
$sql = "SELECT f.*,mf.place FROM ".$this->tbl_fund." f
LEFT JOIN ".$this->tbl_mdfund." mf ON mf.fid=f.id
WHERE uuid='$uuid'
ORDER BY mf.place DESC";
}else{
$fids = $this->getMdFunds($uuid);
if(count($fids)>0)
{
$fids = ' WHERE f.id NOT IN ('.join(",",$fids).')';
}else{
$fids = "";
}
$sql = "SELECT f.* FROM ".$this->tbl_fund." f $fids ORDER BY f.id DESC";
}
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
return $rows;
}
}
function add($data)
{
include_once("helper/dbh.php");
$dbh = new dbh($this->db);
return $dbh->insert($this->tbl_fund,$data);
}
function update($data,$id)
{
include_once("helper/dbh.php");
$dbh = new dbh($this->db);
if(empty($id))
{
return "参数错误";
}
$state = $dbh->update($this->tbl_fund,$data,"id=$id",true);
if( $state == true)
{
return true;
}else{
return $state;
}
}
function delete($id){
$sql = "DELETE FROM ".$this->tbl_fund." WHERE id=$id";
return $this->db->exec($sql);
}
function view($id){
$sql = "SELECT * FROM ".$this->tbl_fund." WHERE id=$id";
$rs = $this->db->query($sql);
$row = $rs->fetch();
return $row;
}
function getMdFunds($uuid){
$sql = "SELECT * FROM ".$this->tbl_mdfund." WHERE uuid='$uuid'";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
$fids = array();
foreach($rows as $k=>$v)
{
$fids[] = $v['fid'];
}
return $fids;
}
function addToMdfund($uuid,$id,$order){
if(empty($order))
{
$order = 0;
}
$data = array(
'uuid'=>$uuid,
'fid'=>$id,
'place'=>$order
);
include_once("helper/dbh.php");
$dbh = new dbh($this->db);
return $dbh->insert($this->tbl_mdfund,$data);
}
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;
}
}
<?php
class Fund extends Zend_Controller_Plugin_Abstract
{
private $db; //传入PDO对象.
private $auth = NULL; //Zend_Auth 对象
public $tbl_fund = "fund"; //项目
public $tbl_mdfund = "mdfund"; //对应表
private $fundFields;
function __construct($db,Zend_Auth $auth=NULL)
{
$this->db = $db;
$this->auth = $auth;
}
function fetch($uuid = "",$include = true){
if(empty($uuid))
{
$sql = "SELECT * FROM ".$this->tbl_fund." ORDER BY id DESC";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
return $rows;
}else{
if($include)
{
$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
WHERE uuid='$uuid'
ORDER BY mf.place DESC";
}else{
$fids = $this->getMdFunds($uuid);
if(count($fids)>0)
{
$fids = ' WHERE f.id NOT IN ('.join(",",$fids).')';
}else{
$fids = "";
}
$sql = "SELECT f.* FROM ".$this->tbl_fund." f $fids ORDER BY f.id DESC";
}
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
return $rows;
}
}
function add($data)
{
include_once("helper/dbh.php");
$dbh = new dbh($this->db);
return $dbh->insert($this->tbl_fund,$data);
}
function update($data,$id)
{
include_once("helper/dbh.php");
$dbh = new dbh($this->db);
if(empty($id))
{
return "参数错误";
}
$state = $dbh->update($this->tbl_fund,$data,"id=$id",true);
if( $state == true)
{
return true;
}else{
return $state;
}
}
function delete($id){
$sql = "DELETE FROM ".$this->tbl_fund." WHERE id=$id";
return $this->db->exec($sql);
}
function mfdelete($id){
$sql = "DELETE FROM ".$this->tbl_mdfund." WHERE id=$id";
return $this->db->exec($sql);
}
function view($id){
$sql = "SELECT * FROM ".$this->tbl_fund." WHERE id=$id";
$rs = $this->db->query($sql);
$row = $rs->fetch();
return $row;
}
function getMdFunds($uuid){
$sql = "SELECT * FROM ".$this->tbl_mdfund." WHERE uuid='$uuid'";
$rs = $this->db->query($sql);
$rows = $rs->fetchAll();
$fids = array();
foreach($rows as $k=>$v)
{
$fids[] = $v['fid'];
}
return $fids;
}
function addToMdfund($uuid,$id,$order){
if(empty($order))
{
$order = 0;
}
$data = array(
'uuid'=>$uuid,
'fid'=>$id,
'place'=>$order
);
include_once("helper/dbh.php");
$dbh = new dbh($this->db);
return $dbh->insert($this->tbl_mdfund,$data);
}
function changeorder($id,$order){
if(!is_numeric($id) || !is_numeric($order))
{
return false;
}
$data = array(
'place'=>$order
);
include_once("helper/dbh.php");
$dbh = new dbh($this->db);
$state = $dbh->update($this->tbl_mdfund,$data,"id=$id",true);
if( $state == true)
{
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
$(document).ready(function() {
gebo_select_row.init();
gebo_delete_rows.simple();
});
gebo_select_row = {
init: function() {
$('.select_rows').click(function () {
var tableid = $(this).data('tableid');
$('#'+tableid).find('input[name=row_sel]').attr('checked', this.checked);
});
}
};
gebo_delete_rows = {
simple: function() {
$(".delete_rows_simple").on('click',function (e) {
e.preventDefault();
var tableid = $(this).data('tableid');
if($('input[name=row_sel]:checked', '#'+tableid).length) {
$.colorbox({
initialHeight: '0',
initialWidth: '0',
href: "#confirm_dialog",
inline: true,
opacity: '0.3',
onComplete: function(){
$('.confirm_yes').click(function(e){
e.preventDefault();
$('input[name=row_sel]:checked', '#'+tableid).each(function(index, element) {
del($(this).val());
});
$('input[name=select_rows]:checked').removeAttr('checked');
$.colorbox.close();
});
$('.confirm_no').click(function(e){
e.preventDefault();
$.colorbox.close();
});
}
});
}
});
}
};
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>';
function onedel(id)
{
$.colorbox({
initialHeight: '100',
initialWidth: '200',
//href: "#confirm_dialog",
//inline: true,
opacity: '0.3',
onComplete: function(){
$('.confirm_yes').click(function(e){
e.preventDefault();
del(id);
$.colorbox.close();
});
$('.confirm_no').click(function(e){
e.preventDefault();
$.colorbox.close();
});
},
html: confrimHTML
});
}
function del(id){
btn = $('#'+info.btn_prefix+id);
func = btn.attr('onclick');
html = btn.html();
$.ajax({
'type':"POST",
'url': info.url,
'data': 'id='+id,
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error) !== 'undefined')
{
Alert(data.error);return false;
}
if(typeof(data.deleted !== 'undefined'))
{
$('#'+info.item_prefix+id).remove();
}
}
else{
Alert('出现错误,请稍后再试');
}
},
'timeout': 15000,
'error': function(){
Alert('处理中出现错误,请刷新页面后重试');
},
'beforeSend':function(){
btn.attr('onclick','');
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>'});
// JavaScript Document
$(document).ready(function() {
gebo_select_row.init();
gebo_delete_rows.simple();
});
gebo_select_row = {
init: function() {
$('.select_rows').click(function () {
var tableid = $(this).data('tableid');
$('#'+tableid).find('input[name=row_sel]').attr('checked', this.checked);
});
}
};
gebo_delete_rows = {
simple: function() {
$(".delete_rows_simple").on('click',function (e) {
e.preventDefault();
var tableid = $(this).data('tableid');
if($('input[name=row_sel]:checked', '#'+tableid).length) {
$.colorbox({
initialHeight: '0',
initialWidth: '0',
href: "#confirm_dialog",
inline: true,
opacity: '0.3',
onComplete: function(){
$('.confirm_yes').click(function(e){
e.preventDefault();
$('input[name=row_sel]:checked', '#'+tableid).each(function(index, element) {
del($(this).val());
});
$('input[name=select_rows]:checked').removeAttr('checked');
$.colorbox.close();
});
$('.confirm_no').click(function(e){
e.preventDefault();
$.colorbox.close();
});
}
});
}
});
}
};
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>';
function onedel(id)
{
if(typeof(info) == "undefined")
{
Alert('信息参数设置不正确');
return false;
}
$.colorbox({
initialHeight: '100',
initialWidth: '200',
//href: "#confirm_dialog",
//inline: true,
opacity: '0.3',
onComplete: function(){
$('.confirm_yes').click(function(e){
e.preventDefault();
del(id);
$.colorbox.close();
});
$('.confirm_no').click(function(e){
e.preventDefault();
$.colorbox.close();
});
},
html: confrimHTML
});
}
function del(id){
if(typeof(info) == "undefined")
{
alert('信息参数设置不正确');
return false;
}
btn = $('#'+info.btn_prefix+id);
func = btn.attr('onclick');
html = btn.html();
$.ajax({
'type':"POST",
'url': info.url,
'data': 'id='+id,
'success':function(data){
if (typeof(data)=='object')
{
if(typeof(data.error) !== 'undefined')
{
Alert(data.error);return false;
}
if(typeof(data.deleted !== 'undefined'))
{
$('#'+info.item_prefix+id).remove();
}
}
else{
Alert('出现错误,请稍后再试');
}
},
'timeout': 15000,
'error': function(){
Alert('处理中出现错误,请刷新页面后重试');
},
'beforeSend':function(){
btn.attr('onclick','');
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>'});
}