From f87de9e5699e36f9341ef76d628d024d5d102217 Mon Sep 17 00:00:00 2001 From: holan20180123 Date: Mon, 16 Aug 2021 16:16:32 +0800 Subject: [PATCH] * Code for task #41238. --- module/project/control.php | 37 +++++++++++++++++++++++++++++-- module/project/js/team.js | 35 +++++++++++++++++++++++++++++ module/project/lang/zh-cn.php | 2 ++ module/project/model.php | 9 +++++++- module/project/view/team.html.php | 3 +-- 5 files changed, 81 insertions(+), 5 deletions(-) diff --git a/module/project/control.php b/module/project/control.php index 8255a7ddb1..ff7c0c0f47 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -172,6 +172,38 @@ class project extends control echo $html; } + /** + * Ajax get unlink tips when unlink team member. + * + * @param int $projectID + * @param int $account + * @access public + * @return void + */ + public function ajaxGetUnlinkTips($projectID, $account) + { + $executions = $this->loadModel('execution')->getByProject($projectID, 'undone', 0, true); + $executionMembers = $this->dao->select('t1.root,t2.name')->from(TABLE_TEAM)->alias('t1') + ->leftJoin(TABLE_EXECUTION)->alias('t2')->on('t1.root=t2.id') + ->where('t1.root')->in(array_keys($executions)) + ->andWhere('t1.type')->eq('execution') + ->andWhere('t1.account')->eq($account) + ->fetchPairs(); + + $executionNames = ''; + $count = 0; + foreach($executionMembers as $executionName) + { + if($count == 0) $executionNames = $executionName; + if($count == 1) $executionNames .= ',' . $executionName; + if($count > 1) break; + $count++; + } + if(count($executionMembers) <= 2) $this->lang->project->etc = ' '; + $this->lang->project->unlinkExecutionMember = sprintf($this->lang->project->unlinkExecutionMember, $executionNames, $this->lang->project->etc, count($executionMembers)); + die($this->lang->project->unlinkExecutionMember); + } + /** * Project index view. * @@ -1139,17 +1171,18 @@ class project extends control * @param int $projectID * @param int $userID * @param string $confirm yes|no + * @param string $removeExecution yes|no * @access public * @return void */ - public function unlinkMember($projectID, $userID, $confirm = 'no') + public function unlinkMember($projectID, $userID, $confirm = 'no', $removeExecution = 'no') { if($confirm == 'no') die(js::confirm($this->lang->project->confirmUnlinkMember, $this->inlink('unlinkMember', "projectID=$projectID&userID=$userID&confirm=yes"))); $user = $this->loadModel('user')->getById($userID, 'id'); $account = $user->account; - $this->project->unlinkMember($projectID, $account); + $this->project->unlinkMember($projectID, $account, $removeExecution); if(!dao::isError()) $this->loadModel('action')->create('team', $projectID, 'managedTeam'); /* if ajax request, send result. */ diff --git a/module/project/js/team.js b/module/project/js/team.js index d58ba42f6b..57262563b2 100644 --- a/module/project/js/team.js +++ b/module/project/js/team.js @@ -2,3 +2,38 @@ function checkUserDept(userID) { alert(noAccess); } + +/** + * Delete memeber of project team. + * + * @param projectID $projectID + * @param account $account + * @param userID $userID + * @access public + * @return void + */ +function deleteMemeber(projectID, account, userID) +{ + if(confirm(confirmUnlinkMember)) + { + var removeConfirm = ''; + var tipsLink = createLink('project', 'ajaxGetUnlinkTips', 'projectID=' + projectID + '&account=' + account); + $.get(tipsLink, function(tips) + { + if(confirm(tips)) + { + var unlinkURL = createLink('project', 'unlinkMember', 'projectID=' + projectID + '&userID=' + userID + '&confirm=yes&removeExecution=yes'); + } + else + { + var unlinkURL = createLink('project', 'unlinkMember', 'projectID=' + projectID + '&userID=' + userID + '&confirm=yes&removeExecution=no'); + } + + $.get(unlinkURL, function(data) + { + data = JSON.parse(data); + if(data.result == 'success') window.location.reload(); + }); + }) + } +} diff --git a/module/project/lang/zh-cn.php b/module/project/lang/zh-cn.php index 14fd47a8b9..b4af0fd2e2 100644 --- a/module/project/lang/zh-cn.php +++ b/module/project/lang/zh-cn.php @@ -129,6 +129,7 @@ $lang->project->longTime = '长期'; $lang->project->future = '待定'; $lang->project->moreProject = '更多项目'; $lang->project->days = '可用工作日'; +$lang->project->etc = "等"; $lang->project->productNotEmpty = '请关联产品或创建产品。'; $lang->project->existProductName = '产品名称已存在。'; @@ -138,6 +139,7 @@ $lang->project->linkedProjectsTip = '关联的项目如下'; $lang->project->multiLinkedProductsTip = '该项目关联的如下产品还关联了其他项目,请取消关联后再操作'; $lang->project->linkStoryByPlanTips = "此操作会将所选计划下面的{$lang->SRCommon}全部关联到此项目中"; $lang->project->createExecution = "该项目下没有{$lang->executionCommon},请先创建{$lang->executionCommon}"; +$lang->project->unlinkExecutionMember = "该用户参与了%s%s%s个{$lang->executionCommon},是否同时将其移除?(该用户所产生的数据不会受影响。)"; $lang->project->tenThousand = '万'; diff --git a/module/project/model.php b/module/project/model.php index 7e3f2374c6..b84d447f26 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -1261,13 +1261,20 @@ class projectModel extends model * * @param int $projectID * @param string $account + * @param string $removeExecution no|yes * @access public * @return void */ - public function unlinkMember($projectID, $account) + public function unlinkMember($projectID, $account, $removeExecution = 'no') { $this->dao->delete()->from(TABLE_TEAM)->where('root')->eq((int)$projectID)->andWhere('type')->eq('project')->andWhere('account')->eq($account)->exec(); + if($removeExecution == 'yes') + { + $executions = $this->loadModel('execution')->getByProject($projectID, 'undone', 0, true); + $this->dao->delete()->from(TABLE_TEAM)->where('root')->in(array_keys($executions))->andWhere('type')->eq('execution')->andWhere('account')->eq($account)->exec(); + } + $this->loadModel('user'); $this->user->updateUserView($projectID, 'project', array($account)); diff --git a/module/project/view/team.html.php b/module/project/view/team.html.php index 71ddb64495..e026f40b9c 100644 --- a/module/project/view/team.html.php +++ b/module/project/view/team.html.php @@ -91,8 +91,7 @@ createLink('project', 'unlinkMember', "projectID=$projectID&userID=$member->userID&confirm=yes"); - echo html::a("javascript:ajaxDelete(\"$unlinkURL\", \"mainContent\", confirmUnlinkMember)", '', '', "class='btn' title='{$lang->project->unlinkMember}'"); + echo html::a("javascript:deleteMemeber($projectID, \"{$member->account}\", \"{$member->userID}\")", '', '', "class='btn' title='{$lang->project->unlinkMember}'"); } ?>