* Fix bug #48271.
This commit is contained in:
@@ -394,16 +394,16 @@ class program extends control
|
||||
public function delete(int $programID)
|
||||
{
|
||||
/* The program can NOT be deleted if it has a child program. */
|
||||
$childrenCount = $this->dao->select('count(*) as count')->from(TABLE_PROGRAM)->where('parent')->eq($programID)->andWhere('deleted')->eq('0')->fetch('count');
|
||||
if($childrenCount)
|
||||
$childrenPairs = $this->program->getChildrenPairsByID($programID);
|
||||
if(count($childrenPairs))
|
||||
{
|
||||
if($this->viewType == 'json' or (defined('RUN_MODE') && RUN_MODE == 'api')) return $this->send(array('result' => 'fail', 'message' => 'Can not delete the program has children.'));
|
||||
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->hasChildren}'})"));
|
||||
}
|
||||
|
||||
/* The program can NOT be deleted if it has a product. */
|
||||
$productCount = $this->dao->select('count(*) as count')->from(TABLE_PRODUCT)->where('program')->eq($programID)->andWhere('deleted')->eq('0')->fetch('count');
|
||||
if($productCount) return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.alert('{$this->lang->program->hasProduct}');"));
|
||||
$productPairs = $this->program->getProductPairsByID($programID);
|
||||
if(count($productPairs)) return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.alert('{$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();
|
||||
@@ -745,4 +745,30 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,13 +40,42 @@ window.renderCell = function(result, {col, row})
|
||||
|
||||
window.confirmDelete = function(projectID, module, projectName)
|
||||
{
|
||||
var deleteURL = $.createLink(module, 'delete', "projectID=" + projectID);
|
||||
if(module == 'program') 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) =>
|
||||
let deleteURL = $.createLink(module, 'delete', "projectID=" + projectID);
|
||||
if(module == 'program')
|
||||
{
|
||||
if(res) $.ajaxSubmit({url: deleteURL, load: true});
|
||||
});
|
||||
$.get($.createLink('program', 'ajaxGetChildrenCount', `programID=${projectID}`), function(childrenCount)
|
||||
{
|
||||
if(childrenCount > 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
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});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(document).off('click', '[data-formaction]').on('click', '[data-formaction]', function()
|
||||
|
||||
@@ -1382,4 +1382,28 @@ class programModel extends model
|
||||
{
|
||||
return !empty($programID) && ($this->app->user->admin || (strpos(",{$this->app->user->view->programs},", ",{$programID},") !== false));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过项目集ID获取子项目集和项目。
|
||||
*
|
||||
* @param int $programID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getChildrenPairsByID(int $programID): array
|
||||
{
|
||||
return $this->dao->select('id, name')->from(TABLE_PROGRAM)->where('parent')->eq($programID)->andWhere('deleted')->eq('0')->fetchPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过项目集ID获取产品。
|
||||
*
|
||||
* @param int $programID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getProductPairsByID(int $programID): array
|
||||
{
|
||||
return $this->dao->select('id, name')->from(TABLE_PRODUCT)->where('program')->eq($programID)->andWhere('deleted')->eq('0')->fetchPairs();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ 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');
|
||||
|
||||
Reference in New Issue
Block a user