diff --git a/module/program/control.php b/module/program/control.php index 8cd10a8b1f..ad8b78ca15 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -650,7 +650,7 @@ class program extends control if($order != $oldOrders[$programID]) $this->dao->update(TABLE_PROJECT)->set('`order`')->eq($order)->where('id')->eq($programID)->exec(); } - return $this->send(array('result' => 'success')); + return $this->send(array('result' => 'success', 'load' => true)); } /* diff --git a/module/program/js/productview.ui.js b/module/program/js/productview.ui.js index 44a7a15420..24d6aa015d 100644 --- a/module/program/js/productview.ui.js +++ b/module/program/js/productview.ui.js @@ -55,3 +55,63 @@ $(document).off('click', '[data-formaction]').on('click', '[data-formaction]', f if($this.data('page') == 'batch') postAndLoadPage($this.data('formaction'), postData); }); + +/** + * 拖拽的项目集或者产品是否允许放下。 + * Is it allowed to drop the dragged program or project. + * + * @param from 拖动的行信息 + * @param to 被拖动到的行信息 + * @access public + * @return bool + */ +window.canSortTo = function(from, to) +{ + if(!from || !to) return false; + if(from.data.parent != to.data.parent) return false; + if(from.data.type != to.data.type) return false; + return true; +}; + +/** + * 拖拽项目集或产品。 + * Drag program or project. + * + * @param from 拖动的行信息 + * @param to 被拖动到的行信息 + * @access public + * @return bool + */ +window.onSortEnd = function(from, to) +{ + if(!canSortTo(from, to)) return false; + + const programIdList = []; + const productIdList = []; + const orders = this.state.rowOrders; + for(id in orders) + { + if(id.includes('program')) + { + programID = id.slice(id.indexOf('-') + 1); + programIdList[programID] = orders[id]; + } + else + { + productIdList[id] = orders[id]; + } + } + + const fromType = from.data.type; + const url = $.createLink(fromType, 'updateOrder'); + const form = new FormData(); + if(fromType == 'program') form.append('programIdList', JSON.stringify(programIdList)); + if(fromType == 'product') + { + form.append('orderBy', 'order_asc'); + form.append('products', JSON.stringify(productIdList)); + } + $.ajaxSubmit({url, data:form}); + + return true; +}; diff --git a/module/program/ui/productview.html.php b/module/program/ui/productview.html.php index c8f38f29ad..b23893e939 100644 --- a/module/program/ui/productview.html.php +++ b/module/program/ui/productview.html.php @@ -256,6 +256,7 @@ featureBar ); toolbar($fnGenerateCreateProgramBtns()); +$canSort = common::hasPriv('program', 'updateOrder') && strpos(',program_asc,order_asc,', ",$orderBy,") !== false; dtable ( setID('productviews'), @@ -270,6 +271,10 @@ dtable set::canRowCheckable(jsRaw("function(rowID){return this.getRowInfo(rowID).data.type == 'product';}")), set::onRenderCell(jsRaw('window.renderCellProductView')), set::orderBy($orderBy), + set::plugins(array('sortable')), + set::sortable($canSort), + set::onSortEnd($canSort ? jsRaw('window.onSortEnd') : null), + set::canSortTo($canSort ? jsRaw('window.canSortTo') : null), set::sortLink(createLink('program', 'productview', "browseType={$browseType}&orderBy={name}_{sortType}¶m={$param}&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}")), set::footToolbar(array (