diff --git a/module/bug/control.php b/module/bug/control.php
index 9fb4edfa17..615928ae18 100755
--- a/module/bug/control.php
+++ b/module/bug/control.php
@@ -2315,6 +2315,21 @@ class bug extends control
return print(html::select('assignedTo', $allUsers, $selectedUser, 'class="form-control"'));
}
+ /**
+ * AJAX: get a project by execution id.
+ *
+ * @param string $executionID
+ * @access public
+ * @return string
+ */
+ public function ajaxGetProjectByExecutionID($executionID)
+ {
+ $execution = $this->loadModel('execution')->getByID($executionID);
+ $projectPairs = $this->loadModel('project')->getPairsByIdList($execution->project);
+
+ return print(html::select('project', $projectPairs, array_keys($projectPairs), 'class="form-control"'));
+ }
+
/**
* AJAX: get actions of a bug. for web app.
*
diff --git a/module/bug/js/common.js b/module/bug/js/common.js
index e7baa1bba6..f138d95bd9 100644
--- a/module/bug/js/common.js
+++ b/module/bug/js/common.js
@@ -294,7 +294,7 @@ function loadProductStories(productID)
function loadProductProjects(productID)
{
required = $('#project_chosen').hasClass('required');
- branch = $('#branch').val();
+ branch = $('#branch').val();
if(typeof(branch) == 'undefined') branch = 0;
link = createLink('product', 'ajaxGetProjects', 'productID=' + productID + '&branch=' + branch + '&projectID=' + oldProjectID);
$('#projectBox').load(link, function()
@@ -466,7 +466,9 @@ function loadProductBuilds(productID)
*/
function loadExecutionRelated(executionID)
{
- executionID = parseInt(executionID);
+ executionID = parseInt(executionID);
+ currentProjectID = $('#project').val() == 'undefined' ? 0 : $('#project').val();
+
if(executionID)
{
loadExecutionTasks(executionID);
@@ -474,10 +476,10 @@ function loadExecutionRelated(executionID)
loadExecutionBuilds(executionID);
loadAssignedTo(executionID, $('#assignedTo').val());
loadTestTasks($('#product').val(), executionID);
+ if(currentProjectID ==0) loadProjectByExecutionID(executionID);
}
else
{
- var currentProjectID = $('#project').val() == 'undefined' ? 0 : $('#project').val();
var currentProductID = $('#product').val();
$('#taskIdBox').innerHTML = ''; // Reset the task.
@@ -496,6 +498,30 @@ function loadExecutionRelated(executionID)
}
}
+/**
+ * Load a project by execution id.
+ *
+ * @param executionID $executionID
+ * @access public
+ * @return void
+ */
+function loadProjectByExecutionID(executionID)
+{
+ link = createLink('bug', 'ajaxGetProjectByExecutionID', 'executionID=' + executionID);
+ required = $('#project_chosen').hasClass('required');
+
+ $.post(link, function(data)
+ {
+ if(!data) data = '';
+ $('#project').replaceWith(data);
+ $('#project_chosen').remove();
+ $('#project').next('.picker').remove();
+ $("#project").chosen();
+
+ if(required) $('#project_chosen').addClass('required');
+ })
+}
+
/**
* Load execution tasks.
*
diff --git a/module/bug/model.php b/module/bug/model.php
index e24d83085f..be1187583c 100644
--- a/module/bug/model.php
+++ b/module/bug/model.php
@@ -81,8 +81,6 @@ class bugModel extends model
->remove('files,labels,uid,oldTaskID,contactListMenu,region,lane,ticket')
->get();
- if($bug->execution != 0) $bug->project = $this->dao->select('project')->from(TABLE_EXECUTION)->where('id')->eq($bug->execution)->fetch('project');
-
/* Check repeat bug. */
$result = $this->loadModel('common')->removeDuplicate('bug', $bug, "product={$bug->product}");
if($result and $result['stop']) return array('status' => 'exists', 'id' => $result['duplicate']);
@@ -219,8 +217,6 @@ class bugModel extends model
if(isset($data->lanes[$i])) $bug->laneID = $data->lanes[$i];
- if($bug->execution != 0) $bug->project = $this->dao->select('project')->from(TABLE_EXECUTION)->where('id')->eq($bug->execution)->fetch('project');
-
/* Assign the bug to the person in charge of the module. */
if(!empty($moduleOwners[$bug->module]))
{