* refactory story-batchedit.

* code for task#1562.
This commit is contained in:
chencongzhi520@gmail.com
2013-07-12 06:23:59 +00:00
parent 1b782cfe21
commit 0c461470dd
5 changed files with 89 additions and 112 deletions
+1 -1
View File
@@ -66,7 +66,7 @@
if($canBatchEdit)
{
$actionLink = $this->createLink('story', 'batchEdit', "from=productBrowse&productID=$productID&projectID=0&orderBy=$orderBy");
$actionLink = $this->createLink('story', 'batchEdit', "productID=$productID&projectID=0");
echo html::commonButton($lang->edit, "onclick=\"changeAction('productStoryForm', 'batchEdit', '$actionLink')\"");
}
if($canBatchClose)
+1 -1
View File
@@ -101,7 +101,7 @@
if($canBatchEdit)
{
$actionLink = $this->createLink('story', 'batchEdit', "from=projectStory&productID=0&projectID=$project->id&orderBy=$orderBy");
$actionLink = $this->createLink('story', 'batchEdit', "productID=0&projectID=$project->id");
echo html::commonButton($lang->edit, "onclick=\"changeAction('projectStoryForm', 'batchEdit', '$actionLink')\"");
}
if($canBatchClose)
+3
View File
@@ -4,6 +4,9 @@ $config->story = new stdclass();
$config->story->batchCreate = 10;
$config->story->affectedFixedNum = 7;
$config->story->batchEdit = new stdclass();
$config->story->batchEdit->columns = 10;
$config->story->create = new stdclass();
$config->story->edit = new stdclass();
$config->story->change = new stdclass();
+60 -86
View File
@@ -289,106 +289,80 @@ class story extends control
/**
* Batch edit story.
*
* @param string $from productBrowse|projectStory|storyBatchEdit.
* @param int $productID
* @param int $projectID
* @param string $orderBy
* @access public
* @return void
*/
public function batchEdit($from = '', $productID = 0, $projectID = 0, $orderBy = '')
public function batchEdit($productID = 0, $projectID = 0)
{
/* Get post data for product-Browse or project-Story. */
if($from == 'productBrowse' or $from == 'projectStory')
if($this->post->titles)
{
/* Init vars. */
$editedStories = array();
$storyIDList = $this->post->storyIDList ? $this->post->storyIDList : array();
$columns = 9;
$showSuhosinInfo = false;
$allChanges = $this->story->batchUpdate();
/* Get all stories. */
if(!$projectID)
if($allChanges)
{
/* Set menu. */
$this->product->setMenu($this->product->getPairs('nodeleted'), $productID);
$allStories = $this->dao->select('*')->from(TABLE_STORY)->where($this->session->storyQueryCondition)->orderBy($orderBy)->fetchAll('id');
}
else
{
$this->lang->story->menu = $this->lang->project->menu;
$this->project->setMenu($this->project->getPairs('nodeleted'), $projectID);
$this->lang->set('menugroup.story', 'project');
$this->lang->story->menuOrder = $this->lang->project->menuOrder;
$allStories = $this->story->getProjectStories($projectID, $orderBy);
}
if(!$allStories) $allStories = array();
/* Initialize the stories whose need to edited. */
$moduleOptionMenus = array();
$productPlans = array();
$this->loadModel('productplan');
foreach($allStories as $story)
{
if(in_array($story->id, $storyIDList))
foreach($allChanges as $storyID => $changes)
{
$editedStories[$story->id] = $story;
if(!isset($moduleOptionMenus[$story->product]))
{
$moduleOptionMenus[$story->product] = $this->tree->getOptionMenu($story->product, $viewType = 'story');
$productPlans[$story->product] = $this->productplan->getPairs($story->product);
}
}
}
/* Judge whether the editedStories is too large. */
$showSuhosinInfo = $this->loadModel('common')->judgeSuhosinSetting(count($editedStories), $columns);
/* Set the sessions. */
$this->app->session->set('showSuhosinInfo', $showSuhosinInfo);
/* Assign. */
if(!$projectID)
{
$product = $this->product->getByID($productID);
$this->view->title = $product->name . $this->lang->colon . $this->lang->story->batchEdit;
}
else
{
$project = $this->project->getByID($projectID);
$this->view->title = $project->name . $this->lang->colon . $this->lang->story->batchEdit;
}
if($showSuhosinInfo) $this->view->suhosinInfo = $this->lang->suhosinInfo;
$this->view->position[] = $this->lang->story->common;
$this->view->position[] = $this->lang->story->batchEdit;
$this->view->users = $this->loadModel('user')->getPairs('nodeleted');
$this->view->moduleOptionMenus = $moduleOptionMenus;
$this->view->productPlans = $productPlans;
$this->view->productID = $productID;
$this->view->editedStories = $editedStories;
$this->display();
}
/* Get post data for story-batchEdit. */
elseif($from == 'storyBatchEdit')
{
if(!empty($_POST))
{
$allChanges = $this->story->batchUpdate();
if($allChanges)
{
foreach($allChanges as $storyID => $changes)
{
$actionID = $this->action->create('story', $storyID, 'Edited');
$this->action->logHistory($actionID, $changes);
$this->sendMail($storyID, $actionID);
}
$actionID = $this->action->create('story', $storyID, 'Edited');
$this->action->logHistory($actionID, $changes);
$this->sendMail($storyID, $actionID);
}
}
die(js::locate($this->session->storyList, 'parent'));
}
$storyIDList = $this->post->storyIDList ? $this->post->storyIDList : die(js::locate($this->session->storyList, 'parent'));
/* Get edited stories. */
$stories = $this->dao->select('*')->from(TABLE_STORY)->where('id')->in($storyIDList)->fetchAll('id');
/* The stories of a product. */
if(!$projectID)
{
$this->product->setMenu($this->product->getPairs('nodeleted'), $productID);
$product = $this->product->getByID($productID);
$this->view->title = $product->name . $this->lang->colon . $this->lang->story->batchEdit;
}
/* The stories of a project. */
else
{
$this->lang->story->menu = $this->lang->project->menu;
$this->project->setMenu($this->project->getPairs('nodeleted'), $projectID);
$this->lang->set('menugroup.story', 'project');
$this->lang->story->menuOrder = $this->lang->project->menuOrder;
$project = $this->project->getByID($projectID);
$this->view->title = $project->name . $this->lang->colon . $this->lang->story->batchEdit;
}
/* Get the module and productplan of edited stories. */
$moduleOptionMenus = array();
$productPlans = array();
$this->loadModel('productplan');
foreach($stories as $story)
{
$moduleOptionMenus[$story->product] = $this->tree->getOptionMenu($story->product, $viewType = 'story');
$productPlans[$story->product] = $this->productplan->getPairs($story->product);
}
/* Judge whether the editedStories is too large and set session. */
$showSuhosinInfo = false;
$showSuhosinInfo = $this->loadModel('common')->judgeSuhosinSetting(count($stories), $this->config->story->batchEdit->columns);
$this->app->session->set('showSuhosinInfo', $showSuhosinInfo);
if($showSuhosinInfo) $this->view->suhosinInfo = $this->lang->suhosinInfo;
$this->view->position[] = $this->lang->story->common;
$this->view->position[] = $this->lang->story->batchEdit;
$this->view->users = $this->loadModel('user')->getPairs('nodeleted');
$this->view->moduleOptionMenus = $moduleOptionMenus;
$this->view->productPlans = $productPlans;
$this->view->productID = $productID;
$this->view->storyIDList = $storyIDList;
$this->view->stories = $stories;
$this->display();
}
/**
+24 -24
View File
@@ -27,50 +27,50 @@
<th class='w-100px'><?php echo $lang->story->closedBy;?></th>
<th class='w-120px a-left'><?php echo $lang->story->closedReason;?></th>
</tr>
<?php foreach($editedStories as $story):?>
<?php foreach($storyIDList as $storyID):?>
<tr class='a-center'>
<td><?php echo $story->id . html::hidden("storyIDList[$story->id]", $story->id);?></td>
<td><?php echo html::select("modules[$story->id]", $moduleOptionMenus[$story->product], $story->module, 'class=select-1');?></td>
<td><?php echo html::select("plans[$story->id]", $productPlans[$story->product], $story->plan, 'class=select-1');?></td>
<td><?php echo html::input("titles[$story->id]", $story->title, 'class=text-1'); ?></td>
<td><?php echo html::input("estimates[$story->id]", $story->estimate, 'class=text-1'); ?></td>
<td><?php echo html::select("pris[$story->id]", (array)$lang->story->priList, $story->pri, 'class=select-1');?></td>
<td><?php echo html::select("sources[$story->id]", $lang->story->sourceList, $story->source, 'class=select-1');?></td>
<td><?php echo $lang->story->statusList[$story->status];?></td>
<td><?php echo $storyID . html::hidden("storyIDList[$storyID]", $storyID);?></td>
<td><?php echo html::select("modules[$storyID]", $moduleOptionMenus[$stories[$storyID]->product], $stories[$storyID]->module, 'class=select-1');?></td>
<td><?php echo html::select("plans[$storyID]", $productPlans[$stories[$storyID]->product], $stories[$storyID]->plan, 'class=select-1');?></td>
<td><?php echo html::input("titles[$storyID]", $stories[$storyID]->title, 'class=text-1'); ?></td>
<td><?php echo html::input("estimates[$storyID]", $stories[$storyID]->estimate, 'class=text-1'); ?></td>
<td><?php echo html::select("pris[$storyID]", (array)$lang->story->priList, $stories[$storyID]->pri, 'class=select-1');?></td>
<td><?php echo html::select("sources[$storyID]", $lang->story->sourceList, $stories[$storyID]->source, 'class=select-1');?></td>
<td><?php echo $lang->story->statusList[$stories[$storyID]->status];?></td>
<?php if($story->status != 'draft'):?>
<td><?php echo html::select("stages[$story->id]", $lang->story->stageList, $story->stage, 'class=select-1');?></td>
<?php if($stories[$storyID]->status != 'draft'):?>
<td><?php echo html::select("stages[$storyID]", $lang->story->stageList, $stories[$storyID]->stage, 'class=select-1');?></td>
<?php else:?>
<td><?php echo html::select("stages[$story->id]", $lang->story->stageList, $story->stage, 'class="select-1" disabled="disabled"');?></td>
<td><?php echo html::select("stages[$storyID]", $lang->story->stageList, $stories[$storyID]->stage, 'class="select-1" disabled="disabled"');?></td>
<?php endif;?>
<?php if($story->status == 'closed'):?>
<td><?php echo html::select("closedBys[$story->id]", $users, $story->closedBy, 'class="select-1"');?></td>
<?php if($stories[$storyID]->status == 'closed'):?>
<td><?php echo html::select("closedBys[$storyID]", $users, $stories[$storyID]->closedBy, 'class="select-1"');?></td>
<?php else:?>
<td><?php echo html::select("closedBys[$story->id]", $users, $story->closedBy, 'class="select-1" disabled="disabled"');?></td>
<td><?php echo html::select("closedBys[$storyID]", $users, $stories[$storyID]->closedBy, 'class="select-1" disabled="disabled"');?></td>
<?php endif;?>
<?php if($story->status == 'closed'):?>
<?php if($stories[$storyID]->status == 'closed'):?>
<td>
<div class='f-left'><?php echo html::select("closedReasons[$story->id]", $lang->story->reasonList, $story->closedReason, "class=w-60px onchange=setDuplicateAndChild(this.value,$story->id)");?></div>
<div class='f-left'><?php echo html::select("closedReasons[$storyID]", $lang->story->reasonList, $stories[$storyID]->closedReason, "class=w-60px onchange=setDuplicateAndChild(this.value,$storyID)");?></div>
<div class='f-left' id='<?php echo 'duplicateStoryBox' . $story->id;?>' <?php if($story->closedReason != 'duplicate') echo "style='display:none'";?>>
<?php echo html::input("duplicateStoryIDList[$story->id]", '', "class=w-30px placeholder='{$lang->idAB}'");?>
<div class='f-left' id='<?php echo 'duplicateStoryBox' . $storyID;?>' <?php if($stories[$storyID]->closedReason != 'duplicate') echo "style='display:none'";?>>
<?php echo html::input("duplicateStoryIDList[$storyID]", '', "class=w-30px placeholder='{$lang->idAB}'");?>
</div>
<div class='f-left' id='<?php echo 'childStoryBox' . $story->id;?>' <?php if($story->closedReason != 'subdivided') echo "style='display:none'";?>>
<?php echo html::input("childStoriesIDList[$story->id]", '', "class=w-30px placeholder='{$lang->idAB}'");?>
<div class='f-left' id='<?php echo 'childStoryBox' . $storyID;?>' <?php if($stories[$storyID]->closedReason != 'subdivided') echo "style='display:none'";?>>
<?php echo html::input("childStoriesIDList[$storyID]", '', "class=w-30px placeholder='{$lang->idAB}'");?>
</div>
</td>
<?php else:?>
<td><div class='f-left'><?php echo html::select("closedReasons[$story->id]", $lang->story->reasonList, $story->closedReason, 'class="w-60px" disabled="disabled"');?><div></td>
<td><div class='f-left'><?php echo html::select("closedReasons[$storyID]", $lang->story->reasonList, $stories[$storyID]->closedReason, 'class="w-60px" disabled="disabled"');?><div></td>
<?php endif;?>
</tr>
<?php endforeach;?>
<?php if(isset($suhosinInfo)):?>
<tr><td colspan='11'><div class='f-left blue'><?php echo $suhosinInfo;?></div></td></tr>
<tr><td colspan='<?php echo $this->config->story->batchEdit->columns;?>'><div class='f-left blue'><?php echo $suhosinInfo;?></div></td></tr>
<?php endif;?>
<tr><td colspan='11' class='a-center'><?php echo html::submitButton();?></td></tr>
<tr><td colspan='<?php echo $this->config->story->batchEdit->columns;?>' class='a-center'><?php echo html::submitButton();?></td></tr>
</table>
</form>
<?php include '../../common/view/footer.html.php';?>