diff --git a/module/product/model.php b/module/product/model.php index b5905756ac..fb31c29fae 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -179,7 +179,13 @@ class productModel extends model { if($this->checkPriv($product)) { - if(strpos($mode, 'nocode') === false and $product->code) $product->name = strtoupper(substr($product->code, 0, 1)) . ':' . $product->name; + + if(strpos($mode, 'nocode') === false and $product->code) + { + $firstChar = strtoupper(substr($product->code, 0, 1)); + if(ord($firstChar) < 127) $product->name = $firstChar . ':' . $product->name; + } + $pairs[$product->id] = $product->name; } } diff --git a/module/project/model.php b/module/project/model.php index f5632d75a2..3f5785227c 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -14,7 +14,7 @@ class projectModel extends model { /* The members every linking. */ - const LINK_MEMBERS_ONE_TIME = 10; + const LINK_MEMBERS_ONE_TIME = 20; /** * Check the privilege. @@ -74,7 +74,7 @@ class projectModel extends model $moduleName = $this->app->getModuleName(); $methodName = $this->app->getMethodName(); - $selectHtml = html::select('projectID', $projects, $projectID, "onchange=\"switchProject(this.value, '$moduleName', '$methodName');\""); + $selectHtml = $this->select($projects, $projectID, $moduleName, $methodName); foreach($this->lang->project->menu as $key => $menu) { $replace = $key == 'list' ? $selectHtml . $this->lang->arrow : $projectID; @@ -82,6 +82,28 @@ class projectModel extends model } } + /** + * Create the select code of projects. + * + * @param array $projects + * @param int $projectID + * @param string $currentModule + * @param string $currentMethod + * @access public + * @return string + */ + public function select($projects, $projectID, $currentModule, $currentMethod) + { + /* See product's model method:select. */ + $switchCode = "switchProject($('#projectID').val(), '$currentModule', '$currentMethod');"; + $onchange = "onchange=\"$switchCode\""; + $onkeypress = "onkeypress=\"eventKeyCode=event.keyCode; if(eventKeyCode == 13) $switchCode\""; + $onclick = "onclick=\"eventKeyCode = 13; $switchCode\""; + $selectHtml = html::select('projectID', $projects, $projectID, "tabindex=2 $onchange $onkeypress"); + $selectHtml .= html::commonButton($this->lang->go, "id='projectSwitcher' tabindex=3 $onclick"); + return $selectHtml; + } + /** * Save the project id user last visited to session. * @@ -193,17 +215,25 @@ class projectModel extends model */ public function getPairs($mode = '') { - if($mode == '') $mode = $this->cookie->projectMode ? $this->cookie->projectMode : 'noclosed'; + $mode .= $this->cookie->projectMode; $projects = $this->dao->select('*')->from(TABLE_PROJECT) ->where('iscat')->eq(0) ->andWhere('deleted')->eq(0) - ->orderBy('status, end desc') + ->orderBy('status, code') ->fetchAll(); $pairs = array(); foreach($projects as $project) { - if($mode == 'noclosed' and $project->status == 'done') continue; - if($this->checkPriv($project)) $pairs[$project->id] = $project->name; + if(strpos($mode, 'noclosed') !== false and $project->status == 'done') continue; + if($this->checkPriv($project)) + { + if(strpos($mode, 'nocode') === false and $project->code) + { + $firstChar = strtoupper(substr($project->code, 0, 1)); + if(ord($firstChar) < 127) $project->name = $firstChar . ':' . $project->name; + } + $pairs[$project->id] = $project->name; + } } /* If the pairs is empty, to make sure there's an project in the pairs. */ diff --git a/www/js/my.full.js b/www/js/my.full.js index ee06b4e404..cda7576a46 100644 --- a/www/js/my.full.js +++ b/www/js/my.full.js @@ -247,6 +247,9 @@ function setProjectSwitcher() */ function switchProject(projectID, module, method) { + if(typeof(eventKeyCode) == 'undefined') eventKeyCode = 0; + if(eventKeyCode > 0 && eventKeyCode != 13) return false; + /* The projec id is a string, use it as the project model. */ if(isNaN(projectID)) {