From 885ff64fe9509ff6649f41c895f99e437faf0aa7 Mon Sep 17 00:00:00 2001 From: "chencongzhi520@gmail.com" Date: Tue, 22 May 2012 08:51:42 +0000 Subject: [PATCH] * code for task#804. --- module/my/control.php | 1 + module/my/view/todo.html.php | 1 + module/todo/control.php | 55 +++++++++++++++++++++++++++ module/todo/lang/en.php | 1 + module/todo/lang/zh-cn.php | 1 + module/todo/model.php | 51 +++++++++++++++++++++++++ module/todo/view/batchedit.html.php | 59 +++++++++++++++++++++++++++++ 7 files changed, 169 insertions(+) create mode 100755 module/todo/view/batchedit.html.php diff --git a/module/my/control.php b/module/my/control.php index 6423a8191f..888bd4de71 100644 --- a/module/my/control.php +++ b/module/my/control.php @@ -88,6 +88,7 @@ class my extends control $this->view->todos = $this->todo->getList($type, $account, $status, 0, $pager); $this->view->date = (int)$type == 0 ? $this->todo->today() : $type; $this->view->type = $type; + $this->view->status = $status; $this->view->account = $this->app->user->account; $this->view->pager = $pager; $this->view->importFuture = ($type == 'before' or $type == 'future' or $type == TODOMODEL::DAY_IN_FUTURE); diff --git a/module/my/view/todo.html.php b/module/my/view/todo.html.php index c917af019d..0574b0ed22 100644 --- a/module/my/view/todo.html.php +++ b/module/my/view/todo.html.php @@ -36,6 +36,7 @@ export, '', 'class="export"'); common::printLink('todo', 'batchCreate', "", $lang->todo->batchCreate); + common::printLink('todo', 'batchEdit', "type=$type&account=$account&status=$status", $lang->todo->batchEdit); echo html::a($this->createLink('todo', 'create', "date=$date"), $lang->todo->create); ?> diff --git a/module/todo/control.php b/module/todo/control.php index 9fc7ad8b46..3a007767ba 100644 --- a/module/todo/control.php +++ b/module/todo/control.php @@ -88,6 +88,61 @@ class todo extends control $this->display(); } + /** + * Batch edit todo. + * + * @param string $type + * @param string $account + * @param string $status + * @access public + * @return void + */ + public function batchEdit($type = 'today', $account = '', $status = 'all') + { + if($account == '') $account = $this->app->user->account; + $bugs = $this->bug->getUserBugPairs($account); + $tasks = $this->task->getUserTaskPairs($account, $status); + $todos = $this->todo->getList($type, $account, $status); + + foreach($todos as $todo) + { + if($todo->type == 'task') $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_TASK)->fetch('name'); + if($todo->type == 'bug') $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_BUG)->fetch('title'); + $todo->date = str_replace('-', '', $todo->date); + $todo->begin = str_replace(':', '', $todo->begin); + $todo->end = str_replace(':', '', $todo->end); + + $todoIDList[$todo->id] = $todo->id; + } + + if(!empty($_POST)) + { + $changes = $this->todo->batchUpdate($todoIDList); + foreach($changes as $todoID => $change) + { + if(!empty($change)) + { + $actionID = $this->loadModel('action')->create('todo', $todoID, 'edited'); + $this->action->logHistory($actionID, $change); + } + } + + die(js::locate($this->createLink('my', 'todo',"type=$type&account=$account&status=$status"), 'parent')); + } + $header['title'] = $this->lang->my->common . $this->lang->colon . $this->lang->todo->create; + $position[] = $this->lang->todo->create; + + $this->view->bugs = $bugs; + $this->view->tasks = $tasks; + $this->view->todos = $todos; + $this->view->header = $header; + $this->view->position = $position; + $this->view->times = $this->todo->buildTimeList($this->config->todo->times->begin, $this->config->todo->times->end, $this->config->todo->times->delta); + $this->view->time = $this->todo->now(); + + $this->display(); + } + /** * Edit a todo. * diff --git a/module/todo/lang/en.php b/module/todo/lang/en.php index 34591c0474..369dc5bbfe 100644 --- a/module/todo/lang/en.php +++ b/module/todo/lang/en.php @@ -13,6 +13,7 @@ $lang->todo->common = 'TODO'; $lang->todo->index = "Index"; $lang->todo->create = "Create"; $lang->todo->batchCreate = "Batch create"; +$lang->todo->batchEdit = "Batch edit"; $lang->todo->edit = "Edit"; $lang->todo->view = "Info"; $lang->todo->viewAB = "Info"; diff --git a/module/todo/lang/zh-cn.php b/module/todo/lang/zh-cn.php index 732e03744f..5bfc659b19 100644 --- a/module/todo/lang/zh-cn.php +++ b/module/todo/lang/zh-cn.php @@ -13,6 +13,7 @@ $lang->todo->common = 'TODO'; $lang->todo->index = "todo一览"; $lang->todo->create = "新增TODO"; $lang->todo->batchCreate = "批量添加"; +$lang->todo->batchEdit = "批量编辑"; $lang->todo->edit = "更新TODO"; $lang->todo->view = "TODO详情"; $lang->todo->viewAB = "详情"; diff --git a/module/todo/model.php b/module/todo/model.php index 8f676c3772..39ea95c567 100644 --- a/module/todo/model.php +++ b/module/todo/model.php @@ -126,6 +126,57 @@ class todoModel extends model if(!dao::isError()) return common::createChanges($oldTodo, $todo); } + /** + * Batch update todo. + * + * @param array $todoIDList + * @access public + * @return void + */ + public function batchUpdate($todoIDList) + { + $todos = array(); + $changes = array(); + + /* Initialize todos from the post data. */ + foreach($todoIDList as $todoID) + { + $todo->date = $this->post->dates[$todoID]; + $todo->type = $this->post->types[$todoID]; + $todo->pri = $this->post->pris[$todoID]; + $todo->name = $todo->type == 'custom' ? $this->post->names[$todoID] : ''; + $todo->begin = $this->post->begins[$todoID]; + $todo->end = $this->post->ends[$todoID]; + if($todo->type == 'task') $todo->idvalue = $this->post->tasks[$todoID]; + if($todo->type == 'bug') $todo->idvalue = $this->post->bugs[$todoID]; + + $todos[$todoID] = $todo; + unset($todo); + } + + foreach($todos as $todoID => $todo) + { + $oldTodo = $this->getById($todoID); + if($oldTodo->type != 'custom') $oldTodo->name = ''; + $this->dao->update(TABLE_TODO)->data($todo) + ->autoCheck() + ->checkIF($todo->type == 'custom', $this->config->todo->edit->requiredFields, 'notempty')->where('id')->eq($todoID) + ->exec(); + + if(!dao::isError()) + { + $changes[$todoID] = common::createChanges($oldTodo, $todo); + } + else + { + echo js::error(dao::getError()); + die(js::reload('parent')); + } + } + + return $changes; + } + /** * Change the status of a todo. * diff --git a/module/todo/view/batchedit.html.php b/module/todo/view/batchedit.html.php new file mode 100755 index 0000000000..bf3201f711 --- /dev/null +++ b/module/todo/view/batchedit.html.php @@ -0,0 +1,59 @@ + + * @package todo + * @version $Id: create.html.php 2741 2012-04-07 07:24:21Z areyou123456 $ + * @link http://www.zentao.net + */ +?> + + +
+ + + + + + + + + + + + + + + + + + + + + +
todo->batchEdit . $lang->colon;?>
idAB;?>todo->date;?>todo->type;?>todo->pri;?>todo->name;?>todo->beginAndEnd;?>
id;?>id]", $todo->date, "class='text-1 date'");?>id]", $lang->todo->typeList, $todo->type, "onchange=loadList(this.value,$todo->id) class='select-1'");?>id]", $lang->todo->priList, $todo->pri, 'class=select-1');?> + +
+ type == 'custom') + { + echo html::input("names[$todo->id]", $todo->name, "class='f-left text-1'"); echo "*"; + } + elseif($todo->type == 'task') + { + echo html::select("tasks[$todo->id]", $tasks, $todo->idvalue, 'class="select-1 f-left"'); + } + elseif($todo->type == 'bug') + { + echo html::select("bugs[$todo->id]", $bugs, $todo->idvalue, 'class="select-1 f-left"'); + } + ?> +
+
id]", $times, $todo->begin) . html::select("ends[$todo->id]", $times, $todo->end);?> +
+
+ +