* Adjust actions map for program browse page.

This commit is contained in:
wangyidong
2023-06-20 14:05:05 +08:00
parent 8d7c6ef781
commit 469b490039
6 changed files with 201 additions and 176 deletions
+6 -155
View File
@@ -1236,8 +1236,9 @@ class programModel extends model
if(!isset($program->type)) return true;
if($action == 'close') return $program->status != 'closed';
if($action == 'activate') return $program->status == 'done' or $program->status == 'closed';
if($action == 'suspend') return $program->status == 'wait' or $program->status == 'doing';
if($action == 'activate') return $program->status == 'done' || $program->status == 'closed';
if($action == 'suspend') return $program->status == 'wait' || $program->status == 'doing';
if($action == 'start') return $program->status == 'wait' || $program->status == 'suspended';
return true;
}
@@ -1732,158 +1733,8 @@ class programModel extends model
*/
public function buildActions($program)
{
$this->loadModel('project');
$actionsMap = array();
$canStartProgram = common::hasPriv('program', 'start');
$canSuspendProgram = common::hasPriv('program', 'suspend');
$canCloseProgram = common::hasPriv('program', 'close');
$canActivateProgram = common::hasPriv('program', 'activate');
$canStartProject = common::hasPriv('project', 'start');
$canSuspendProject = common::hasPriv('project', 'suspend');
$canCloseProject = common::hasPriv('project', 'close');
$canActivateProject = common::hasPriv('project', 'activate');
if($program->type == 'program' && strpos(",{$this->app->user->view->programs},", ",$program->id,") !== false)
{
$normalActions = array('start', 'close', 'activate');
foreach($normalActions as $action)
{
if($action == 'start' and (!$canStartProgram or ($program->status != 'wait' and $program->status != 'suspended'))) continue;
if($action == 'close' and (!$canCloseProgram or $program->status != 'doing')) continue;
if($action == 'activate' and (!$canActivateProgram or $program->status != 'closed')) continue;
$item = new stdclass();
$item->name = $action;
$item->hint = $this->lang->program->$action;
$actionsMap[] = $item;
}
$canCloseCurrentProgram = $canCloseProgram && $program->status != 'doing';
$canActivateCurrentProgram = $canActivateProgram && $program->status != 'closed';
if($canSuspendProgram or $canCloseCurrentProgram or $canActivateCurrentProgram)
{
$other = new stdclass();
$other->name = 'other';
$other->items = array();
$otherActions = array('suspend', 'close', 'activate');
foreach($otherActions as $action)
{
if($action == 'close' and $program->status == 'doing') continue;
if(!common::hasPriv('program', $action)) continue;
$item = new stdclass();
$item->name = $action;
$item->text = $this->lang->program->$action;
if(!$this->isClickable($program, $action)) $item->disabled = true;
if($action == 'close' and $program->status == 'closed') $item->hint = $this->lang->program->tip->closed;
if($action == 'suspend' and $program->status == 'closed') $item->hint = $this->lang->program->tip->notSuspend;
if($action == 'suspend' and $program->status == 'suspended') $item->hint = $this->lang->program->tip->suspended;
if($action == 'activate' and $program->status == 'doing') $item->hint = $this->lang->program->tip->actived;
$other->items[] = $item;
}
$actionsMap[] = $other;
}
$normalActions = array('edit', 'create', 'delete');
foreach($normalActions as $action)
{
if(!common::hasPriv('program', $action)) continue;
$item = new stdclass();
$item->name = $action;
$item->hint = $this->lang->program->$action;
if($action == 'create' and $program->status == 'closed')
{
$item->disabled = true;
$item->hint = $this->lang->program->tip->notCreate;
}
$actionsMap[] = $item;
}
}
elseif($program->type == 'project')
{
$normalActions = array('start', 'close', 'activate');
foreach($normalActions as $action)
{
if($action == 'start' and (!$canStartProject or ($program->status != 'wait' and $program->status != 'suspended'))) continue;
if($action == 'close' and (!$canCloseProject or $program->status != 'doing')) continue;
if($action == 'activate' and (!$canActivateProgram or $program->status != 'closed')) continue;
$item = new stdclass();
$item->name = $action;
$item->hint = $this->lang->project->$action;
$actionsMap[] = $item;
}
if($canSuspendProject or ($canCloseProject and $program->status != 'doing') or ($canActivateProject and $program->status != 'closed'))
{
$other = new stdclass();
$other->name = 'other';
$other->items = array();
$otherActions = array('suspend', 'close', 'activate');
foreach($otherActions as $action)
{
if($action == 'close' and $program->status == 'doing') continue;
if(!common::hasPriv('project', $action)) continue;
$item = new stdclass();
$item->name = $action;
$item->text = $this->lang->project->$action;
if(!$this->project->isClickable($program, $action)) $item->disabled = true;
if($action == 'close' and $program->status == 'closed') $item->hint = $this->lang->project->tip->closed;
if($action == 'suspend' and $program->status == 'closed') $item->hint = $this->lang->project->tip->notSuspend;
if($action == 'suspend' and $program->status == 'suspended') $item->hint = $this->lang->project->tip->suspended;
if($action == 'activate' and $program->status == 'doing') $item->hint = $this->lang->project->tip->actived;
$other->items[] = $item;
}
$actionsMap[] = $other;
}
if(common::hasPriv('project', 'edit')) $actionsMap[] = 'edit';
if(common::hasPriv('project', 'team')) $actionsMap[] = 'team';
if(common::hasPriv('project', 'manageProducts') || common::hasPriv('project', 'whitelist') || common::hasPriv('project', 'delete'))
{
$more = new stdclass();
$more->name = 'more';
$more->items = array();
$moreActions = array('group', 'manageProducts', 'whitelist', 'delete');
foreach($moreActions as $action)
{
if($aciton == 'group' && common::hasPriv('project', 'group'))
{
$item = new stdclass();
$item->name = 'group';
if($program->model == 'kanban')
{
$item->disabled = true;
$item->hint = $this->lang->project->tip->group;
}
$more->items[] = $item;
continue;
}
if(!common::hasPriv('project', $action)) continue;
$item = new stdclass();
$item->name = $action == 'manageProducts' ? 'link' : $action;
$item->text = $this->lang->project->$action;
if($action == 'whitelist' and $program->acl == 'open')
{
$item->disabled = true;
$item->hint = $this->lang->project->tip->whitelist;
}
$more->items[] = $item;
}
$actionsMap[] = $more;
}
}
return $actionsMap;
if($program->type == 'program') return $this->programTao->buildProgramActionsMap($program);
if($program->type == 'project') return $this->programTao->buildProjectActionsMap($program);
return array();
}
}