* Optimize code for bug #48271.

This commit is contained in:
liumengyi
2024-04-25 08:52:51 +08:00
parent 8ca008736a
commit e1ec138058
3 changed files with 23 additions and 62 deletions
+14 -33
View File
@@ -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));
}
}
+9 -26
View File
@@ -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});
});
}
}
-3
View File
@@ -1,7 +1,6 @@
<?php
namespace zin;
$confirmDeleteLang['program'] = $lang->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');