From a18ac6b70b6716c79182da5150b0016c7d77c0cd Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Mon, 29 May 2023 11:13:20 +0800 Subject: [PATCH] * Adjusting table toolbar links and permissions. --- module/execution/js/task.ui.js | 11 ++ module/execution/ui/task.html.php | 192 ++++++++++++++++++++++++++++++ module/task/control.php | 17 ++- 3 files changed, 210 insertions(+), 10 deletions(-) create mode 100644 module/execution/js/task.ui.js create mode 100644 module/execution/ui/task.html.php diff --git a/module/execution/js/task.ui.js b/module/execution/js/task.ui.js new file mode 100644 index 0000000000..59ba2611d1 --- /dev/null +++ b/module/execution/js/task.ui.js @@ -0,0 +1,11 @@ +$(document).on('click', '.batch-btn', function() +{ + const dtable = zui.DTable.query($(this).target); + const checkedList = dtable.$.getChecks(); + if(!checkedList.length) return; + + const form = new FormData(); + const url = $(this).data('url'); + checkedList.forEach((id) => form.append('taskIdList[]', id)); + postAndLoadPage(url, form); +}); diff --git a/module/execution/ui/task.html.php b/module/execution/ui/task.html.php new file mode 100644 index 0000000000..84c0f9989b --- /dev/null +++ b/module/execution/ui/task.html.php @@ -0,0 +1,192 @@ + + * @package execution + * @link http://www.zentao.net + */ + +namespace zin; + +/* zin: Define the set::module('task') feature bar on main menu. */ +featureBar +( + set::current($browseType), + set::linkParams("executionID={$executionID}&status={key}"), + li(searchToggle(set::module('task'))) +); + +/* zin: Define the toolbar on main menu. */ +$canCreate = hasPriv('task', 'create'); +$canBatchCreate = hasPriv('task', 'batchCreate'); +$canImportTask = hasPriv('task', 'importTask'); +$canImportBug = hasPriv('task', 'importBug'); + +if(common::canModify('execution', $execution)) +{ + $params = isset($moduleID) ? "&storyID=0&moduleID=$moduleID" : ""; + $batchCreateLink = $this->createLink('task', 'batchCreate', "executionID={$executionID}{$params}"); + $createLink = $this->createLink('task', 'create', "executionID={$executionID}{$params}"); + if(commonModel::isTutorialMode()) + { + $wizardParams = helper::safe64Encode("executionID={$executionID}{$params}"); + $taskCreateLink = $this->createLink('tutorial', 'wizard', "module=task&method=create¶ms=$wizardParams"); + } + + $createItem = array('text' => $lang->task->create, 'url' => $createLink); + $batchCreateItem = array('text' => $lang->task->batchCreate, 'url' => $batchCreateLink); + + if($canImportTask && $execution->multiple) $importTaskItem = array('text' => $lang->execution->importTask, 'url' => $this->createLink('execution', 'importTask', "execution={$execution->id}")); + if($canImportBug && $execution->lifetime != 'ops' && !in_array($execution->attribute, array('request', 'review'))) + { + $importBugItem = array('text' => $lang->execution->importBug, 'url' => $this->createLink('execution', 'importBug', "execution={$execution->id}")); + } +} + +toolbar +( + hasPriv('task', 'report') ? item(set(array + ( + 'icon' => 'bar-chart', + 'class' => 'ghost', + 'url' => createLink('task', 'report', "execution={$executionID}&browseType={$browseType}") + ))) : null, + hasPriv('task', 'export') ? item(set(array + ( + 'icon' => 'export', + 'class' => 'ghost', + 'url' => createLink('task', 'export', "execution={$executionID}&orderBy={$orderBy}&type={$browseType}"), + 'data-toggle' => 'modal' + ))) : null, + (!empty($importTaskItem) || !empty($importBugItem)) ? dropdown( + btn( + setClass('ghost btn square btn-default'), + set::icon('import') + ), + set::arrow(false), + set::items(array_filter(array($importTaskItem, $importBugItem))), + set::placement('bottom-end'), + ) : null, + $canCreate && $canBatchCreate ? btngroup + ( + btn(setClass('btn primary'), set::icon('plus'), set::url($createLink), $lang->task->create), + dropdown + ( + btn(setClass('btn primary dropdown-toggle'), + setStyle(array('padding' => '6px', 'border-radius' => '0 2px 2px 0'))), + set::items(array_filter(array($createItem, $batchCreateItem))), + set::placement('bottom-end'), + ) + ) : null, + $canCreate && !$canBatchCreate ? item(set($createItem)) : null, + $canBatchCreate && !$canCreate ? item(set($batchCreateItem)) : null, +); + +/* zin: Define the sidebar in main content. */ +sidebar +( + // moduleMenu(set(array( + // 'modules' => $moduleTree, + // 'activeKey' => $moduleID, + // 'closeLink' => $this->createLink('execution', 'task') + // ))) +); + +/* zin: Define the dtable in main content. */ +$firstTask = reset($tasks); +$canBatchEdit = common::hasPriv('firstTask', 'batchEdit', !empty($firstTask) ? $firstTask : null); +$canBatchClose = (common::hasPriv('firstTask', 'batchClose', !empty($firstTask) ? $firstTask : null) && strtolower($browseType) != 'closed'); +$canBatchCancel = (common::hasPriv('firstTask', 'batchCancel', !empty($firstTask) ? $firstTask : null) && strtolower($browseType) != 'cancel'); +$canBatchAssignTo = common::hasPriv('firstTask', 'batchAssignTo', !empty($firstTask) ? $firstTask : null); +$canBatchChangeModule = common::hasPriv('firstTask', 'batchChangeModule', !empty($firstTask) ? $firstTask : null); +$canBatchAction = ($canBatchEdit || $canBatchClose || $canBatchCancel || $canBatchChangeModule || $canBatchAssignTo); + +$footToolbar = array(); +if($canBatchAction) +{ + if($canBatchClose || $canBatchCancel) + { + menu + ( + set::id('navActions'), + set::class('dropdown-menu'), + $canBatchClose ? item(set(array( + 'text' => $lang->close, + 'class' => 'batch-btn', 'data-url' => createLink('task', 'batchClose') + ))) : null, + $canBatchCancel ? item(set(array( + 'text' => $lang->task->cancel, + 'class' => 'batch-btn', 'data-url' => createLink('task', 'batchCancel') + ))) : null, + ); + } + + if($canBatchChangeModule) + { + $moduleItems = array(); + foreach($modules as $moduleID => $module) + { + $moduleItems[] = array('text' => $module, 'class' => 'batch-btn', 'data-url' => createLink('task', 'batchChangeModule', "moduleID=$moduleID")); + } + + menu + ( + set::id('navModule'), + set::class('dropdown-menu'), + set::items($moduleItems) + ); + } + + if($canBatchAssignTo) + { + $assignedToItems = array(); + foreach ($memberPairs as $account => $name) + { + $assignedToItems[] = array('text' => $name, 'class' => 'batch-btn', 'data-url' => createLink('task', 'batchAssignTo', "executionID={$executionID}&assignedTo={$account}")); + } + + menu + ( + set::id('navAssignedTo'), + set::class('dropdown-menu'), + set::items($assignedToItems) + ); + } + + if($canBatchClose || $canBatchCancel) + { + $footToolbar['items'][] = array( + 'type' => 'btn-group', + 'items' => array( + array('text' => $lang->edit, 'className' => 'batch-btn','btnType' => 'primary', 'data-url' => createLink('task', 'batchEdit', "executionID={$executionID}")), + array('caret' => 'up', 'btnType' => 'primary', 'url' => '#navActions', 'data-toggle' => 'dropdown', 'data-placement' => 'top-start'), + ) + ); + } + + if($canBatchChangeModule) $footToolbar['items'][] = array('caret' => 'up', 'text' => $lang->task->moduleAB, 'btnType' => 'primary', 'url' => '#navModule', 'data-toggle' => 'dropdown', 'data-placement' => 'top-start'); + if($canBatchAssignTo) $footToolbar['items'][] = array('caret' => 'up', 'text' => $lang->task->assignedTo, 'btnType' => 'primary', 'url' => '#navAssignedTo','data-toggle' => 'dropdown'); +} + +dtable +( + set::userMap($memberPairs), + set::cols(array_values($config->task->dtable->fieldList)), + set::data(array_values($tasks)), + set::checkable($canBatchAction), + set::sortLink(helper::createLink('execution', 'task', "executionID={$execution->id}&status={$status}¶m={$param}&orderBy={name}_{sortType}&recTotal={$recTotal}&recPerPage={$recPerPage}")), + set::footToolbar($footToolbar), + set::footPager( + usePager(), + set::page($pageID), + set::recPerPage($recPerPage), + set::recTotal($recTotal), + set::linkCreator(helper::createLink('execution', 'task', "executionID={$execution->id}&status={$status}¶m={$param}&orderBy=$orderBy&recTotal={$recTotal}&recPerPage={recPerPage}&page={page}")) + ), +); + +render(); diff --git a/module/task/control.php b/module/task/control.php index 0dd540d22f..17c8706b34 100755 --- a/module/task/control.php +++ b/module/task/control.php @@ -271,7 +271,7 @@ class task extends control $this->loadModel('score')->create('ajax', 'batchOther'); } - return print(js::reload('parent')); + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true)); } /** @@ -279,27 +279,24 @@ class task extends control * Batch update assign of task. * * @param int $executionID + * @param string $assignedTo * @access public * @return void */ - public function batchAssignTo(int $executionID) + public function batchAssignTo(int $executionID, string $assignedTo) { - if(!empty($_POST)) + if($this->post->taskIdList) { - if(!is_array($this->post->taskIdList)) return print(js::locate($this->createLink('execution', 'task', "executionID={$executionID}"), 'parent')); - - $taskData = $this->taskZen->buildTasksForBatchAssignTo($this->post->taskIdList, $this->post->assignedTo); + $taskData = $this->taskZen->buildTasksForBatchAssignTo($this->post->taskIdList, $assignedTo); foreach($taskData as $task) { - /* Assign task. */ $this->task->assign($task); - if(dao::isError()) return print(js::error(dao::getError())); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); } if(!dao::isError()) $this->loadModel('score')->create('ajax', 'batchOther'); - - return print(js::reload('parent')); } + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'load' => true)); } /**