| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440 |
- <?php
- /**
- * The view file of datatable module of ZenTaoPMS.
- *
- * @copyright Copyright 2014-2014 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
- * @license business(商业软件)
- * @author Hao sun <sunhao@cnezsoft.com>
- * @package datatable
- * @version $Id$
- * @link https://www.zentao.net
- */
- class datatable extends control
- {
- /**
- * 设置列表页是否显示模块名。
- * Set display.
- *
- * @param string $datatableID
- * @param string $moduleName
- * @param string $methodName
- * @param string $currentModule
- * @param string $currentMethod
- * @access public
- * @return void
- */
- public function ajaxDisplay($datatableID, $moduleName, $methodName, $currentModule, $currentMethod)
- {
- $this->loadModel($currentModule);
- if($moduleName == 'execution' && $methodName == 'task' && $this->config->vision != 'lite') $this->view->execution = $this->execution->getByID($this->session->execution);
- $this->view->datatableID = $datatableID;
- $this->view->moduleName = $moduleName;
- $this->view->methodName = $methodName;
- $this->view->currentModule = $currentModule;
- $this->view->currentMethod = $currentMethod;
- $this->render();
- }
- /**
- * 保存列表页是否显示模块名的配置项。
- * Save config
- *
- * @access public
- * @return void
- */
- public function ajaxSave()
- {
- if(!empty($_POST))
- {
- $account = $this->app->user->account;
- if($account == 'guest') return $this->send(array('result' => 'fail', 'message' => 'guest.'));
- $module = $this->post->currentModule;
- $method = $this->post->currentMethod;
- $this->app->checkModuleName($module);
- $this->app->checkMethodName($method);
- $this->loadModel('setting')->setItem($account . '.' . $module . '.' . $method . '.showModule', $this->post->value);
- if($this->post->allModule !== false) $this->setting->setItem("$account.execution.task.allModule", $this->post->allModule);
- if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
- return $this->send(array('result' => 'success', 'closeModal' => true, 'load' => true));
- }
- }
- /**
- * 自定义列页面保存配置。
- * Ajax save fields.
- *
- * @param string $module
- * @param string $method
- * @param string $extra
- * @access public
- * @return void
- */
- public function ajaxSaveFields($module, $method, $extra = '')
- {
- if(!empty($_POST))
- {
- $account = $this->app->user->account;
- if($account == 'guest') return $this->send(array('result' => 'fail', 'message' => 'guest.'));
- $rawModule = zget($this->config->datatable->moduleAlias, "$module-$method", $module);
- if($rawModule == 'story' && $extra && $rawModule != $extra) $rawModule = $extra;
- $cols = $this->datatable->getSetting($module, $method, true, $extra);
- $postFields = json_decode($this->post->fields);
- /* 生成配置信息。 */
- $fields = array();
- $attrs = array('order', 'width', 'show', 'extraWidth', 'border'); // 需要保存的配置属性。
- foreach($cols as $id => $col)
- {
- $fields[$id] = array();
- foreach($attrs as $attr)
- {
- if($attr == 'show' && isset($col['required']) && $col['required']) $col['show'] = true;
- if(!isset($col[$attr])) continue;
- $fields[$id][$attr] = $col[$attr];
- }
- }
- foreach($postFields as $field)
- {
- $id = $field->id;
- if($module == 'testcase' && $id == 'caseID') $id = 'id';
- if(!isset($fields[$id])) continue;
- foreach($attrs as $attr)
- {
- if(!isset($field->$attr)) continue;
- if($attr == 'show') $field->$attr = $field->$attr ? true : false;
- $fields[$id][$attr] = $field->$attr;
- }
- }
- $name = 'datatable.' . $module . ucfirst($method) . '.cols';
- $value = json_encode($fields);
- /* Split story and requirement custom fields. */
- if(("$module-$method" == 'product-browse') && in_array($extra, array('story', 'requirement', 'epic'))) $name = 'datatable.' . $module . ucfirst($method) . ucfirst($extra) . '.cols';
- /* 保存个人配置信息。 */
- $this->loadModel('setting')->setItem($account . '.' . $name, $value);
- /* 保存全局配置信息。 */
- if($this->post->global) $this->setting->setItem('system.' . $name, $value);
- if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => 'dao error.'));
- $load = "$module-$method" == 'my-effort' ? $this->createLink('my', 'effort') : true;
- return $this->send(array('result' => 'success', 'closeModal' => true, 'load' => $load));
- }
- }
- /**
- * 自定义列配置页面。
- * custom fields.
- *
- * @param string $module
- * @param string $method
- * @param string $extra
- * @access public
- * @return void
- */
- public function ajaxCustom($module, $method, $extra = '')
- {
- $cols = $this->datatable->getSetting($module, $method, true, $extra);
- if(!$method) $method = $this->app->getMethodName();
- if($module == 'testcase')
- {
- unset($cols['assignedTo']);
- unset($cols['product']);
- unset($cols['module']);
- }
- if($module == 'bug')
- {
- unset($cols['product']);
- unset($cols['module']);
- }
- if(zget($this->config->datatable->moduleAlias, "$module-$method", $module) == 'story')
- {
- unset($cols['product'], $cols['module']);
- if($extra != 'story')
- {
- foreach(array('taskCount', 'bugCount', 'caseCount') as $field) unset($cols[$field]);
- $cols['title']['title'] = $cols['title']['title'] = $this->lang->story->name;
- }
- if($this->app->tab != 'product') $cols['title']['title'] = $this->lang->story->name;
- }
- if(($module == 'productplan' && $method == 'browse') || ($module == 'project' && $method == 'bug'))
- {
- $branchField = $module == 'productplan' ? 'branchName' : 'branch';
- if($this->session->currentProductType == 'normal')
- {
- unset($cols[$branchField]);
- }
- else
- {
- $this->app->loadLang('product');
- $cols[$branchField]['title'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$this->session->currentProductType]);
- }
- }
- if($module == 'project' && $method == 'bug')
- {
- $project = $this->loadModel('project')->getByID($this->session->project);
- if(!$project->multiple) unset($cols['execution']);
- if(!$project->hasProduct && ($project->model != 'scrum' || !$project->multiple)) unset($cols['plan']);
- if(!$project->hasProduct) unset($cols['branch']);
- }
- if($module == 'execution' && $method == 'bug')
- {
- unset($cols['execution']);
- unset($cols['branch']);
- $execution = $this->loadModel('execution')->getByID($this->session->execution);
- $project = $this->loadModel('project')->getByID($execution->project);
- if(!$project->hasProduct && $project->model != 'scrum') unset($cols['plan']);
- if(!$project->hasProduct) unset($cols['branch']);
- }
- if($module == 'execution' && $method == 'story')
- {
- $execution = $this->loadModel('execution')->getByID($this->session->execution);
- if(!$execution->hasProduct && !$execution->multiple) unset($cols['plan']);
- if(!$execution->hasProduct) unset($cols['branch']);
- }
- if($module == 'project' && $method == 'execution')
- {
- $project = $this->datatable->fetchByID($this->session->project, 'project');
- if(!empty($project->isTpl)) unset($cols['deliverable']);
- }
- if($module == 'deliverable')
- {
- $hasProcess = $this->loadModel('workflowgroup')->hasFeature((int)$extra, 'process');
- if(!$hasProcess) unset($cols['activity'], $cols['trimmable'], $cols['trimRule']);
- }
- if($extra == 'unsetStory' && isset($cols['story'])) unset($cols['story']);
- if($this->config->edition == 'ipd' && $module == 'product' && $method == 'browse' && $extra == 'story') unset($cols['roadmap']);
- if($this->app->tab == 'project' && !$this->session->multiple && $module == 'meeting' && $method == 'browse') unset($cols['execution']);
- $this->view->module = $module;
- $this->view->method = $method;
- $this->view->cols = $cols;
- $this->view->extra = $extra;
- $this->display();
- }
- /**
- * Save config
- *
- * @access public
- * @return void
- */
- public function ajaxOldSave()
- {
- if(!empty($_POST))
- {
- $account = $this->app->user->account;
- if($account == 'guest') return $this->send(array('result' => 'fail', 'target' => $target, 'message' => 'guest.'));
- $name = 'datatable.' . $this->post->target . '.' . $this->post->name;
- $this->loadModel('setting')->setItem($account . '.' . $name, $this->post->value);
- if($this->post->allModule !== false) $this->setting->setItem("$account.execution.task.allModule", $this->post->allModule);
- if($this->post->showBranch !== false) $this->setting->setItem($account . '.' . $this->post->currentModule . '.' . $this->post->currentMethod . '.showBranch', $this->post->showBranch);
- if($this->post->global) $this->setting->setItem('system.' . $name, $this->post->value);
- if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => 'dao error.'));
- return $this->send(array('result' => 'success'));
- }
- }
- /**
- * custom fields.
- *
- * @param string $module
- * @param string $method
- * @param string $extra
- * @access public
- * @return void
- */
- public function ajaxOldCustom($module, $method, $extra = '')
- {
- $moduleName = $module;
- $target = $module . ucfirst($method);
- $mode = isset($this->config->datatable->$target->mode) ? $this->config->datatable->$target->mode : 'table';
- $key = $mode == 'datatable' ? 'cols' : 'tablecols';
- if($module == 'testtask')
- {
- $this->loadModel('testcase');
- $this->app->loadConfig('testtask');
- $this->config->testcase->datatable->defaultField = $this->config->testtask->datatable->defaultField;
- $this->config->testcase->datatable->fieldList['actions']['width'] = '100';
- $this->config->testcase->datatable->fieldList['status']['width'] = '90';
- }
- if($module == 'testcase')
- {
- $this->loadModel('testcase');
- unset($this->config->testcase->datatable->fieldList['assignedTo']);
- }
- $this->view->module = $module;
- $this->view->method = $method;
- $this->view->mode = $mode;
- $module = zget($this->config->datatable->moduleAlias, "$module-$method", $module);
- $setting = '';
- if(isset($this->config->datatable->$target->$key)) $setting = $this->config->datatable->$target->$key;
- if(empty($setting))
- {
- $this->loadModel($module);
- $setting = json_encode($this->config->$module->datatable->defaultField);
- }
- $cols = $this->datatable->getOldFieldList($module);
- if($module == 'story' && $extra != 'requirement') unset($cols['SRS']);
- if($extra == 'requirement')
- {
- unset($cols['plan']);
- unset($cols['stage']);
- unset($cols['taskCount']);
- unset($cols['bugCount']);
- unset($cols['caseCount']);
- unset($cols['URS']);
- $cols['title']['title'] = str_replace($this->lang->SRCommon, $this->lang->URCommon, $this->lang->story->title);
- }
- if($moduleName == 'project' and $method == 'bug')
- {
- $project = $this->loadModel('project')->getByID($this->session->project);
- if(!$project->multiple) unset($cols['execution']);
- if(!$project->hasProduct and $project->model != 'scrum') unset($cols['plan']);
- if(!$project->hasProduct) unset($cols['branch']);
- }
- if($moduleName == 'execution' and $method == 'bug')
- {
- $execution = $this->loadModel('execution')->getByID($this->session->execution);
- $project = $this->loadModel('project')->getByID($execution->project);
- if(!$project->hasProduct and $project->model != 'scrum') unset($cols['plan']);
- if(!$project->hasProduct) unset($cols['branch']);
- }
- if($moduleName == 'execution' and $method == 'story')
- {
- $execution = $this->loadModel('execution')->getByID($this->session->execution);
- if(!$execution->hasProduct and !$execution->multiple) unset($cols['plan']);
- if(!$execution->hasProduct) unset($cols['branch']);
- }
- if($moduleName == 'auditplan' && $this->app->tab == 'project' && !$this->session->multiple) unset($cols['execution']);
- if($extra == 'unsetStory' and isset($cols['story'])) unset($cols['story']);
- $this->view->cols = $cols;
- $this->view->setting = $setting;
- $this->display();
- }
- /**
- * 恢复自定义项为默认配置。
- * Ajax reset cols.
- *
- * @param string $module
- * @param string $method
- * @param int $system
- * @param string $confirm
- * @param string $extra
- * @access public
- * @return void
- */
- public function ajaxReset($module, $method, $system = 0, $confirm = 'no', $extra = '')
- {
- if($confirm != 'yes')
- {
- $confirmURL = $this->createLink('datatable', 'ajaxreset', "module={$module}&method={$method}&system={$system}&confirm=yes&extra={$extra}");
- $tip = (int)$system ? $this->lang->datatable->confirmGlobalReset : $this->lang->datatable->confirmReset;
- return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.confirm({message: '{$tip}', icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) => {if(res) $.ajaxSubmit({url: '$confirmURL'});});"));
- }
- $account = !$system ? $this->app->user->account : "system,{$this->app->user->account}";
- $target = $module . ucfirst($method);
- $this->loadModel('setting')->deleteItems("owner={$account}&module=datatable§ion={$target}&key=cols");
- /* Delete story and requirement custom fields. */
- if(strpos(',product-browse,execution-story,', ",$module-$method,") !== false)
- {
- $extra = in_array($extra, array('story', 'requirement', 'epic')) ? ucfirst($extra) : 'Story';
- $section = $module . ucfirst($method) . $extra;
- $this->loadModel('setting')->deleteItems("owner={$account}&module=datatable§ion={$section}&key=cols");
- }
- return $this->send(array('result' => 'success', 'load' => true, 'callback' => "$('#table-$module-$method,[zui-create-dtable]').first().closest('[z-use-dtable]').attr('zui-create-dtable', '')"));
- }
- /**
- * Ajax reset old cols.
- *
- * @param string $module
- * @param string $method
- * @param int $system
- * @param string $confirm
- * @access public
- * @return void
- */
- public function ajaxOldReset($module, $method, $system = 0, $confirm = 'no')
- {
- if($confirm == 'no') return print(js::confirm($this->lang->datatable->confirmReset, inlink('ajaxOldReset', "module=$module&method=$method&system=$system&confirm=yes")));
- $account = $this->app->user->account;
- $target = $module . ucfirst($method);
- $mode = isset($this->config->datatable->$target->mode) ? $this->config->datatable->$target->mode : 'table';
- $key = $mode == 'datatable' ? 'cols' : 'tablecols';
- $this->loadModel('setting')->deleteItems("owner=$account&module=datatable§ion=$target&key=$key");
- if($system) $this->setting->deleteItems("owner=system&module=datatable§ion=$target&key=$key");
- return print(js::reload('parent'));
- }
- /**
- * 应用自定义列配置到全局。
- * Ajax save setting to global.
- *
- * @param string $module
- * @param string $method
- * @param string $extra
- * @param string $confirm
- * @access public
- * @return void
- */
- public function ajaxSaveGlobal($module, $method, $extra = '', $confirm = 'no')
- {
- if($confirm != 'yes')
- {
- $confirmURL = $this->createLink('datatable', 'ajaxsaveglobal', "module={$module}&method={$method}&extra={$extra}&confirm=yes");
- $tip = $this->lang->datatable->confirmSetGlobal;
- return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.confirm({message: '{$tip}', icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) => {if(res) $.ajaxSubmit({url: '$confirmURL'});});"));
- }
- $target = $module . ucfirst($method);
- if(strpos(',product-browse,execution-story,', ",$module-$method,") !== false && strpos(',story,requirement,epic,', ",$extra,") !== false) $target .= ucfirst($extra);
- $settings = isset($this->config->datatable->$target->cols) ? $this->config->datatable->$target->cols : '';
- if(!empty($settings)) $this->loadModel('setting')->setItem("system.datatable.{$target}.cols", $settings);
- return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess));
- }
- }
|