diff --git a/module/bug/control.php b/module/bug/control.php index 615928ae18..9fb4edfa17 100755 --- a/module/bug/control.php +++ b/module/bug/control.php @@ -2315,21 +2315,6 @@ 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 f138d95bd9..c903bb9985 100644 --- a/module/bug/js/common.js +++ b/module/bug/js/common.js @@ -471,12 +471,12 @@ function loadExecutionRelated(executionID) if(executionID) { + if(currentProjectID == 0) loadProjectByExecutionID(executionID); loadExecutionTasks(executionID); loadExecutionStories(executionID); loadExecutionBuilds(executionID); loadAssignedTo(executionID, $('#assignedTo').val()); loadTestTasks($('#product').val(), executionID); - if(currentProjectID ==0) loadProjectByExecutionID(executionID); } else { @@ -507,19 +507,32 @@ function loadExecutionRelated(executionID) */ function loadProjectByExecutionID(executionID) { - link = createLink('bug', 'ajaxGetProjectByExecutionID', 'executionID=' + executionID); - required = $('#project_chosen').hasClass('required'); + link = createLink('project', 'ajaxGetPairsByExecution', 'executionID=' + executionID, 'json'); + required = $('#project_chosen').hasClass('required'); + productID = $('#product').val(); $.post(link, function(data) { - if(!data) data = ''; - $('#project').replaceWith(data); + var originProject = $('#project').html(); + + if($('#project').find('option[value="' + data.id + '"]').length > 0) + { + $('#project').find('option[value="' + data.id + '"]').attr('selected', 'selected'); + originProject = $('#project').html(); + $('#project').replaceWith(''); + } + else + { + var newProject = ''; + $('#project').replaceWith(''); + } + $('#project_chosen').remove(); $('#project').next('.picker').remove(); - $("#project").chosen(); + $('#project').chosen(); if(required) $('#project_chosen').addClass('required'); - }) + }, 'json') } /** diff --git a/module/project/control.php b/module/project/control.php index 52d6916bec..c4b23bbaf1 100755 --- a/module/project/control.php +++ b/module/project/control.php @@ -2313,6 +2313,32 @@ class project extends control return print(html::select('execution', $executions, $executionID, "class='form-control'")); } + /** + * AJAX: get a project by execution id. + * + * @param string $executionID + * @access public + * @return string + */ + public function ajaxGetPairsByExecution($executionID) + { + $execution = $this->loadModel('execution')->getByID($executionID); + $projectPairs = $this->loadModel('project')->getPairsByIdList($execution->project); + + if($this->app->getViewType() == 'json') + { + $project = array('id' => key($projectPairs), 'name' => reset($projectPairs)); + $pinyin = common::convert2Pinyin(array(reset($projectPairs))); + $project['namePinyin'] = zget($pinyin, $project['name']); + + return print(json_encode($project)); + } + else + { + return print(html::select('project', $projectPairs, $execution->project, "class='form-control' onchange='loadProductExecutions({$execution->project}, this.value)'")); + } + } + /** * Link projects and code repositories. *