From d06b0a941af0b4db5fb518ceabfc75549c7b459f Mon Sep 17 00:00:00 2001 From: Gustavo Cruz Date: Thu, 12 Feb 2015 11:09:24 -0400 Subject: [PATCH] Changes the form field type to a suggest box so now the user needs to type the 4 first letters of the first name, last name or username field in order to retrieve the field --- .../engine/methods/cases/casesList_Ajax.php | 24 +++- workflow/engine/templates/cases/casesList.js | 107 +++++++++--------- 2 files changed, 75 insertions(+), 56 deletions(-) diff --git a/workflow/engine/methods/cases/casesList_Ajax.php b/workflow/engine/methods/cases/casesList_Ajax.php index 5ee66a725..ed5a00827 100755 --- a/workflow/engine/methods/cases/casesList_Ajax.php +++ b/workflow/engine/methods/cases/casesList_Ajax.php @@ -42,14 +42,26 @@ G::LoadClass( 'case' ); $actionAjax = isset( $_REQUEST['actionAjax'] ) ? $_REQUEST['actionAjax'] : null; +function filterUserListArray($users = array(), $filter = '') +{ + $filteredUsers = array(); + foreach ($users as $user) { + if(stripos($user['USR_FULLNAME'], $filter) || empty($filter)) { + $filteredUsers[] = $user; + } + } + return $filteredUsers; +} + if ($actionAjax == "userValues") { //global $oAppCache; $oAppCache = new AppCacheView(); $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : null; + $query = isset( $_REQUEST['query'] ) ? $_REQUEST['query'] : null; $users = array(); $users[] = array ("USR_UID" => "", "USR_FULLNAME" => G::LoadTranslation( "ID_ALL_USERS" )); $users[] = array ("USR_UID" => "CURRENT_USER", "USR_FULLNAME" => G::LoadTranslation( "ID_CURRENT_USER" )); - + $users = filterUserListArray($users, $query); //now get users, just for the Search action switch ($action) { case 'search_simple': @@ -67,6 +79,14 @@ if ($actionAjax == "userValues") { $cUsers->addSelectColumn(UsersPeer::USR_FIRSTNAME); $cUsers->addSelectColumn(UsersPeer::USR_LASTNAME); $cUsers->add( UsersPeer::USR_STATUS, 'CLOSED', Criteria::NOT_EQUAL ); + + if (!is_null($query)) { + $filters = $cUsers->getNewCriterion( UsersPeer::USR_FIRSTNAME, '%'.$query.'%', Criteria::LIKE )->addOr( + $cUsers->getNewCriterion( UsersPeer::USR_LASTNAME, '%'.$query.'%', Criteria::LIKE )->addOr( + $cUsers->getNewCriterion( UsersPeer::USR_USERNAME, '%'.$query.'%', Criteria::LIKE ))); + $cUsers->addOr( $filters ); + } + $cUsers->setLimit(20); $cUsers->addAscendingOrderByColumn(UsersPeer::TABLE_NAME . "." . $conf->userNameFormatGetFirstFieldByUsersTable()); $oDataset = UsersPeer::doSelectRS( $cUsers ); $oDataset->setFetchmode( ResultSet::FETCHMODE_ASSOC ); @@ -453,7 +473,7 @@ if ($actionAjax == 'showDynaformListHistory') { var showDynaformHistoryGlobal = {}; showDynaformHistoryGlobal.dynUID = ''; showDynaformHistoryGlobal.tablename = ''; - showDynaformHistoryGlobal.dynDate = '';casesList_Ajax.php + showDynaformHistoryGlobal.dynDate = ''; showDynaformHistoryGlobal.dynTitle = ''; function showDynaformHistory(dynUID,tablename,dynDate,dynTitle){ showDynaformHistoryGlobal.dynUID = dynUID; diff --git a/workflow/engine/templates/cases/casesList.js b/workflow/engine/templates/cases/casesList.js index a40c81fa3..f2bec66a1 100755 --- a/workflow/engine/templates/cases/casesList.js +++ b/workflow/engine/templates/cases/casesList.js @@ -25,33 +25,17 @@ var textJump; var ids = ''; var winReassignInCasesList; -function formatAMPM(date, initVal, calendarDate) { - - var currentDate = new Date(); - var currentDay = currentDate.getDate(); - var currentMonth = currentDate.getMonth()+1; - if (currentDay < 10) { - currentDay = '0' + currentDay; - } - if (currentMonth < 10) { - currentMonth = '0' + currentMonth; - } - currentDate = currentMonth + '-' + currentDay; - if (currentDate == calendarDate) { - var hours = date.getHours(); - var minutes = (initVal === true)? ((date.getMinutes()<15)? 15: ((date.getMinutes()<30)? 30: ((date.getMinutes()<45)? 45: 45))): date.getMinutes(); - var ampm = hours >= 12 ? 'PM' : 'AM'; - hours = hours % 12; - hours = hours ? hours : 12; // the hour '0' should be '12' - minutes = minutes < 10 ? '0' + minutes : minutes; - var strTime = hours + ':' + minutes + ' ' + ampm; - } else { - var strTime = '12:00 AM'; - } +function formatAMPM(date, initVal) { + var hours = date.getHours(); + var minutes = (initVal === true)? ((date.getMinutes()<15)? 0: ((date.getMinutes()<30)? 15: ((date.getMinutes()<45)? 30: 45))): date.getMinutes(); + var ampm = hours >= 12 ? 'PM' : 'AM'; + hours = hours % 12; + hours = hours ? hours : 12; // the hour '0' should be '12' + minutes = minutes < 10 ? '0' + minutes : minutes; + var strTime = hours + ':' + minutes + ' ' + ampm; return strTime; } - Ext.Ajax.timeout = 4 * 60 * 1000; var caseSummary = function() { @@ -264,14 +248,13 @@ function pauseCase(date){ items: [ { html: '
' + _('ID_PAUSE_CASE_TO_DATE') +' '+date.format('M j, Y')+'?

' - }, new Ext.form.TimeField({ id: 'unpauseTime', fieldLabel: _('ID_UNPAUSE_TIME'), name: 'unpauseTime', - value: formatAMPM(new Date(), false, date.format('m-d')), - minValue: formatAMPM(new Date(), true, date.format('m-d')), + value: formatAMPM(new Date(), false), + minValue: formatAMPM(new Date(), true), format: 'h:i A' }), { @@ -1147,44 +1130,59 @@ Ext.onReady ( function() { }); // ComboBox creation processValues - var comboUser = new Ext.form.ComboBox({ - store : new Ext.data.Store( { - proxy : new Ext.data.HttpProxy( { - url : 'casesList_Ajax?actionAjax=userValues&action='+action, - method : 'POST' - }), - reader : new Ext.data.JsonReader( { - fields : [ { - name : 'USR_UID' - }, { - name : 'USR_FULLNAME' - } ] - }) - }), + var userStore = new Ext.data.Store( { + proxy : new Ext.data.HttpProxy( { + url : 'casesList_Ajax?actionAjax=userValues&action='+action, + method : 'POST' + }), + reader : new Ext.data.JsonReader( { + fields : [ { + name : 'USR_UID' + }, { + name : 'USR_FULLNAME' + } ] + }) + }); + + var userStore = new Ext.data.Store( { + proxy : new Ext.data.HttpProxy({ + url : 'casesList_Ajax?actionAjax=userValues&action='+action, + method : 'POST' + }), + reader : new Ext.data.JsonReader({ + fields : [{ + name : 'USR_UID' + }, { + name : 'USR_FULLNAME' + }] + }) + }); + + var suggestUser = new Ext.form.ComboBox({ + store: userStore, valueField : 'USR_UID', - displayField : 'USR_FULLNAME', - triggerAction : 'all', + displayField:'USR_FULLNAME', + typeAhead: true, + triggerAction: 'all', emptyText : _('ID_ALL_USERS'), selectOnFocus : true, - editable : false, + editable : true, width: 180, allowBlank : true, autocomplete: true, typeAhead: true, - //allowBlankText : _('ID_SHOULD_SELECT_LANGUAGE_FROM_LIST'), + hideTrigger:true, listeners:{ scope: this, 'select': function() { - storeCases.setBaseParam("user", comboUser.store.getAt(0).get(comboUser.valueField)); - filterUser = comboUser.value; - storeCases.setBaseParam( 'user', filterUser); - storeCases.setBaseParam( 'start', 0); - storeCases.setBaseParam( 'limit', pageSize); - //storeCases.load(); + //storeCases.setBaseParam( 'user', comboUser.store.getAt(0).get(comboUser.valueField)); + filterUser = suggestUser.value; + storeCases.setBaseParam( 'user', filterUser); + storeCases.setBaseParam( 'start', 0); + storeCases.setBaseParam( 'limit', pageSize); } } - }); - + }); var textSearch = new Ext.form.TextField ({ allowBlank: true, @@ -1858,7 +1856,8 @@ Ext.onReady ( function() { comboStatus, "-", _("ID_USER"), - comboUser, + //comboUser, + suggestUser, '   ' //'-', //textSearch,