* finish task#516.

This commit is contained in:
wangchunsheng
2011-10-20 12:36:11 +00:00
parent ec30c7df2b
commit 9b8415e5ca
3 changed files with 46 additions and 7 deletions

View File

@@ -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;
}
}

View File

@@ -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. */

View File

@@ -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))
{