diff --git a/module/program/control.php b/module/program/control.php index 167915d651..171eabc250 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -551,18 +551,17 @@ class program extends control { if($confirm == 'no') { - return print(js::confirm($this->lang->program->confirmUnlink, $this->inlink('unlinkStakeholder', "stakeholderID=$stakeholderID&programID=$programID&confirm=yes"))); + $actionUrl = $this->inlink('unlinkStakeholder', "stakeholderID=$stakeholderID&programID=$programID&confirm=yes"); + return $this->send(array('result' => 'success', 'message' => $this->lang->program->confirmUnlink, 'callback' => "unlinkStakeholderConfirm('{$this->lang->program->confirmUnlink}', '$actionUrl')")); } - else - { - $account = $this->dao->select('user')->from(TABLE_STAKEHOLDER)->where('id')->eq($stakeholderID)->fetch('user'); - $this->dao->delete()->from(TABLE_STAKEHOLDER)->where('id')->eq($stakeholderID)->exec(); - $this->loadModel('user')->updateUserView($programID, 'program', array($account)); - $this->updateChildUserView($programID, $account); + $account = $this->dao->select('user')->from(TABLE_STAKEHOLDER)->where('id')->eq($stakeholderID)->fetch('user'); + $this->dao->delete()->from(TABLE_STAKEHOLDER)->where('id')->eq($stakeholderID)->exec(); - return print(js::reload('parent')); - } + $this->loadModel('user')->updateUserView($programID, 'program', array($account)); + $this->updateChildUserView($programID, $account); + + return $this->send(array('result' => 'success', 'load' => true)); } /** @@ -580,18 +579,17 @@ class program extends control if($confirm == 'no') { - return print(js::confirm($this->lang->program->confirmBatchUnlink, $this->inlink('batchUnlinkStakeholders', "programID=$programID&stakeholderIDList=$stakeholderIDList&confirm=yes"))); + $actionUrl = $this->inlink('batchUnlinkStakeholders', "programID=$programID&stakeholderIDList=$stakeholderIDList&confirm=yes"); + return $this->send(array('result' => 'success', 'message' => $this->lang->program->confirmBatchUnlink, 'callback' => "unlinkStakeholderConfirm('{$this->lang->program->confirmBatchUnlink}', '$actionUrl')")); } - else - { - $account = $this->dao->select('user')->from(TABLE_STAKEHOLDER)->where('id')->in($stakeholderIDList)->fetchPairs('user'); - $this->dao->delete()->from(TABLE_STAKEHOLDER)->where('id')->in($stakeholderIDList)->exec(); - $this->loadModel('user')->updateUserView($programID, 'program', $account); - $this->updateChildUserView($programID, $account); + $account = $this->dao->select('user')->from(TABLE_STAKEHOLDER)->where('id')->in($stakeholderIDList)->fetchPairs('user'); + $this->dao->delete()->from(TABLE_STAKEHOLDER)->where('id')->in($stakeholderIDList)->exec(); - return print(js::reload('parent')); - } + $this->loadModel('user')->updateUserView($programID, 'program', $account); + $this->updateChildUserView($programID, $account); + + return $this->send(array('result' => 'success', 'load' => true)); } /** diff --git a/module/program/js/stakeholder.ui.js b/module/program/js/stakeholder.ui.js index 54733b0dcc..a464f12f0d 100644 --- a/module/program/js/stakeholder.ui.js +++ b/module/program/js/stakeholder.ui.js @@ -1,9 +1,28 @@ -window.footerGenerator = function() +window.unlinkStakeholderConfirm = function(confirmDeleteTip, actionUrl) { - const dtable = zui.DTable.query($(this).target); + zui.Modal + .confirm({message: confirmDeleteTip, icon:'icon-info-sign', iconClass: 'warning-pale rounded-full icon-2x'}) + .then((confirmed) => + { + if(confirmed) $.ajaxSubmit({url: actionUrl}); + }); +}; + +window.onClickBatchUnlink = function(event) +{ + const dtable = zui.DTable.query(event.target); const checkedList = dtable.$.getChecks(); - const statistic = summeryTpl.replace('%s', ' ' + checkedList.length + ' '); - return [{children: statistic, className: "text-dark"}, "flex", "pager"]; -} + if(checkedList.length === 0) return; + /* Generate checked stakeholder ID list string. */ + let idList = new Array(); + checkedList.forEach(function(id) + { + idList.push(id); + }); + + /* Set data-url for ajaxSubmit. */ + const button = $($(event.target).parents('button')); + button.data('url', button.data('href').replace('%s', idList.join(','))); +} diff --git a/module/program/ui/stakeholder.html.php b/module/program/ui/stakeholder.html.php index 4eeb79cbf9..108aacc049 100644 --- a/module/program/ui/stakeholder.html.php +++ b/module/program/ui/stakeholder.html.php @@ -68,10 +68,11 @@ $cols = $this->loadModel('datatable')->getSetting('stakeholder'); /* Set list and menu of actions to customize the actions of stakeholder in program module. */ $cols['actions']['list'] = array('unlinkStakeholder' => array( - "icon" => 'unlink', - "text" => $lang->program->unlinkStakeholder, - "hint" => $lang->program->unlinkStakeholder, - "url" => $this->createLink('program', 'unlinkStakeholder', "id={id}&programID={$programID}&confirm=no" + 'icon' => 'unlink', + 'class' => 'ajax-submit', + 'text' => $lang->program->unlinkStakeholder, + 'hint' => $lang->program->unlinkStakeholder, + 'url' => $this->createLink('program', 'unlinkStakeholder', "id={id}&programID={$programID}&confirm=no" ) )); $cols['actions']['menu'] = array('unlinkStakeholder'); @@ -92,17 +93,17 @@ dtable set::cols($cols), set::data($data), set::footPager(usePager()), - set::showToolbarOnChecked(true), + set::checkable(true), set::footToolbar(array( - 'items' => array( - array( - 'text' => $lang->unlink, - 'class' => 'btn secondary toolbar-item batch-btn size-sm', - 'data-url' => createLink('program', 'batchUnlinkStakeholders', "programID={$programID}") - ) - ) + 'type' => 'btn-group', + 'items' => array(array + ( + 'text' => $lang->unlink, + 'class' => 'btn secondary toolbar-item batch-btn size-sm ajax-submit', + 'onClick' => jsRaw('onClickBatchUnlink'), + 'data-href' => createLink('program', 'batchUnlinkStakeholders', "programID={$programID}&stakeholderIDList=%s") + )) )), - set::footer(jsRaw('function() {return window.footerGenerator.call(this);}')), ); render();