* code for task#804.

This commit is contained in:
chencongzhi520@gmail.com
2012-05-22 08:51:42 +00:00
parent e243aab428
commit 885ff64fe9
7 changed files with 169 additions and 0 deletions
+1
View File
@@ -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);
+1
View File
@@ -36,6 +36,7 @@
<?php
common::printLink('todo', 'export', "account=$account&orderBy=id_desc", $lang->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);
?>
</div>
+55
View File
@@ -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.
*
+1
View File
@@ -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";
+1
View File
@@ -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 = "详情";
+51
View File
@@ -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.
*
+59
View File
@@ -0,0 +1,59 @@
<?php
/**
* The batch edit view of todo module of ZenTaoPMS.
*
* @copyright Copyright 2009-2012 青岛易软天创网络科技有限公司 (QingDao Nature Easy Soft Network Technology Co,LTD www.cnezsoft.com)
* @license LGPL (http://www.gnu.org/licenses/lgpl.html)
* @author Congzhi Chen <congzhi@cnezsoft.com>
* @package todo
* @version $Id: create.html.php 2741 2012-04-07 07:24:21Z areyou123456 $
* @link http://www.zentao.net
*/
?>
<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/datepicker.html.php';?>
<form method='post'>
<table class='table-1 fixed'>
<caption><?php echo $lang->todo->batchEdit . $lang->colon;?></caption>
<tr>
<th class='w-20px'><?php echo $lang->idAB;?></th>
<th class='w-200px'><?php echo $lang->todo->date;?></th>
<th class='w-100px'><?php echo $lang->todo->type;?></th>
<th class='w-70px'><?php echo $lang->todo->pri;?></th>
<th class='w-p65'><?php echo $lang->todo->name;?></th>
<th class='w-120px'><?php echo $lang->todo->beginAndEnd;?></th>
</tr>
<?php foreach($todos as $todo):?>
<tr class='a-center'>
<td><?php echo $todo->id;?></td>
<td><?php echo html::input("dates[$todo->id]", $todo->date, "class='text-1 date'");?></td>
<td><?php echo html::select("types[$todo->id]", $lang->todo->typeList, $todo->type, "onchange=loadList(this.value,$todo->id) class='select-1'");?></td>
<td><?php echo html::select("pris[$todo->id]", $lang->todo->priList, $todo->pri, 'class=select-1');?></td>
<td>
<div class='nameBox hidden'><? echo html::input("names[$todo->id]", $todo->name, "class='f-left text-1 hiddenwin'"); echo "<span class='star'>*</span>";?></div>
<div id='<?php echo "nameBox" . $todo->id;?>' class='nameBox'>
<?php
if($todo->type == 'custom')
{
echo html::input("names[$todo->id]", $todo->name, "class='f-left text-1'"); echo "<span class='star'>*</span>";
}
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"');
}
?>
</div>
</td>
<td><?php echo html::select("begins[$todo->id]", $times, $todo->begin) . html::select("ends[$todo->id]", $times, $todo->end);?><td>
</tr>
<?php endforeach;?>
<tr><td colspan='6' class='a-center'><?php echo html::submitButton();?></td></tr>
</table>
</form>
<?php include './footer.html.php';?>
<script language='Javascript'>selectNext();</script>