diff --git a/module/program/control.php b/module/program/control.php index 4e469600b1..6601a366bc 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -388,10 +388,11 @@ class program extends control * Delete a program. * * @param int $programID + * @param string $confirm * @access public * @return void */ - public function delete(int $programID) + public function delete(int $programID, string $confirm = 'no') { /* The program can NOT be deleted if it has a child program. */ $childrenPairs = $this->program->getChildrenPairsByID($programID); @@ -403,17 +404,23 @@ class program extends control /* The program can NOT be deleted if it has a product. */ $productPairs = $this->program->getProductPairsByID($programID); - if(count($productPairs)) return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.alert('{$this->lang->program->hasProduct}');")); + if(count($productPairs)) return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.alert({icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x', message: '{$this->lang->program->hasProduct}'})")); /* Mark the program is deleted and record the action log. */ $program = $this->dao->select('*')->from(TABLE_PROGRAM)->where('id')->eq($programID)->andWhere('deleted')->eq('0')->fetch(); - if($program) + if($confirm == 'no') { - $this->dao->update(TABLE_PROGRAM)->set('deleted')->eq('1')->where('id')->eq($programID)->exec(); - $this->loadModel('action')->create('program', $programID, 'deleted', '', actionModel::CAN_UNDELETED); + return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.confirm({icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x', message: '" . sprintf($this->lang->program->confirmDelete, $program->name) . "'}).then((res) => {if(res) $.ajaxSubmit({url: '" . $this->createLink('program', 'delete', "programID={$programID}&confirm=yes") . "'});});")); + } + else + { + if($program) + { + $this->dao->update(TABLE_PROGRAM)->set('deleted')->eq('1')->where('id')->eq($programID)->exec(); + $this->loadModel('action')->create('program', $programID, 'deleted', '', actionModel::CAN_UNDELETED); + } + return $this->send(array('result' => 'success', 'load' => true)); } - - return $this->send(array('result' => 'success')); } /** @@ -745,30 +752,4 @@ class program extends control $this->render(); } - - /** - * 获取项目集的子项目集数量。 - * - * @param int $programID - * @access public - * @return int - */ - public function ajaxGetChildrenCount(int $programID): int - { - $childrenPairs = $this->program->getChildrenPairsByID($programID); - return print(count($childrenPairs)); - } - - /** - * 获取项目集下的产品数量。 - * - * @param int $programID - * @access public - * @return int - */ - public function ajaxGetProductCount(int $programID): int - { - $productPairs = $this->program->getProductPairsByID($programID); - return print(count($productPairs)); - } } diff --git a/module/program/js/browse.ui.js b/module/program/js/browse.ui.js index 0f428693e3..ad6071419b 100644 --- a/module/program/js/browse.ui.js +++ b/module/program/js/browse.ui.js @@ -48,38 +48,21 @@ window.confirmDelete = function(projectID, module, projectName) let deleteURL = $.createLink(module, 'delete', "projectID=" + projectID); if(module == 'program') { - $.get($.createLink('program', 'ajaxGetChildrenCount', `programID=${projectID}`), function(childrenCount) - { - if(childrenCount > 0) + $.ajaxSubmit( { - zui.Modal.alert({message: hasChildrenTip, icon:'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}); - } - else - { - $.get($.createLink('program', 'ajaxGetProductCount', `programID=${projectID}`), function(productCount) + url: deleteURL, + onComplete: function(result) { - if(productCount > 0) - { - zui.Modal.alert({message: hasProductTip, icon:'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}); - } - else - { - deleteURL = $.createLink('program', 'delete', "programID=" + projectID + '&confirm=yes'); - zui.Modal.confirm({message: confirmDeleteLang[module].replace('%s', projectName), icon:'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) => - { - if(res) $.ajaxSubmit({url: deleteURL, load: true}); - }); - } - }); - } - }) + if(result.result == 'success') loadCurrentPage(); + } + }); } else { zui.Modal.confirm({message: confirmDeleteLang[module].replace('%s', projectName), icon:'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) => - { - if(res) $.ajaxSubmit({url: deleteURL, load: true}); - }); + { + if(res) $.ajaxSubmit({url: deleteURL, load: true}); + }); } } diff --git a/module/program/ui/browse.html.php b/module/program/ui/browse.html.php index 912767879c..95dbee86c0 100644 --- a/module/program/ui/browse.html.php +++ b/module/program/ui/browse.html.php @@ -1,7 +1,6 @@ program->confirmDelete; $confirmDeleteLang['project'] = $lang->project->confirmDelete; jsVar('confirmDeleteLang', $confirmDeleteLang); jsVar('programBudgetLang', $lang->program->programBudget); @@ -10,8 +9,6 @@ jsVar('sumSubBudgetLang', $lang->program->sumSubBudget); jsVar('exceededBudgetLang', $lang->program->exceededBudget); jsVar('remainingBudgetLang', $lang->program->remainingBudget); jsVar('langManDay', $lang->program->manDay); -jsVar('hasChildrenTip', $lang->program->hasChildren); -jsVar('hasProductTip', $lang->program->hasProduct); $this->loadModel('project'); $cols = $this->loadModel('datatable')->getSetting('program');