Changeset 2160 for sandbox/workflow/trunk
- Timestamp:
- 03/04/10 13:29:43 (14 years ago)
- Location:
- sandbox/workflow/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/workflow/trunk/inc/local/classes/class.wf_location.php
r795 r2160 72 72 c.id_city AS id_city, 73 73 c.city_name AS city_name, 74 c.is_district, 74 75 s.id_state AS id_state, 75 76 s.state_name AS state_name, … … 125 126 * Busca as cidades de um estado 126 127 * @param int $state_id Numero ID do estado 127 * @return mixed (array ou boolean) 128 * @access public 129 */ 130 function getCitiesFromState($state_id) 131 { 132 if (!is_numeric($state_id)) 128 * @param bool $include_districts True, busca cidades e distritos. False, busca apenas cidades. 129 * @return mixed (array ou boolean) 130 * @access public 131 */ 132 function getCitiesFromState($state_id, $include_districts = true) 133 { 134 if (!is_numeric($state_id) || !is_bool($include_districts)) 133 135 return false; 134 136 … … 137 139 return $this->citiesFromState[$state_id]; 138 140 141 $where = ""; 142 if(!$include_districts){ 143 $where = " AND c.is_district = 'F' "; 144 } 145 139 146 $sql = 140 147 "SELECT 141 148 c.id_city AS id_city, 142 c.city_name AS city_name 149 c.city_name AS city_name, 150 c.is_district 143 151 FROM 144 152 phpgw_cc_state s, … … 147 155 c.id_state = s.id_state AND 148 156 s.id_country = 'BR' AND 149 c.id_state = ? 157 c.id_state = ? " . $where . " 150 158 ORDER BY 151 159 city_name"; … … 160 168 } 161 169 /** 162 * Busca os estados brasileiros 163 * @return mixed (array ou boolean) 164 * @access public 165 */ 166 function getStates() 167 { 168 $sql = 169 "SELECT 170 id_state, 171 state_name 172 FROM 173 phpgw_cc_state 174 WHERE 175 id_country = 'BR' 170 * Busca as cidades por parte do nome, sem considerar maiúsculas e/ou minúsculas e nem acentuação (retorna 10 resultados) 171 * @param string Parte do nome da cidade 172 * @param int $state_id Numero ID do estado 173 * @param bool $include_districts True, busca cidades e distritos. False, busca apenas cidades. 174 * @return mixed (array ou boolean) 175 * @access public 176 */ 177 function getCitiesByKey($key, $state_id = 0, $include_districts = true) 178 { 179 if (!is_string($key) || !is_numeric($state_id) || !is_bool($include_districts)) 180 return false; 181 182 $where = ""; 183 if($state_id > 0){ 184 $where = " AND c.id_state = " . $state_id; 185 } 186 187 if(!$include_districts){ 188 $where = " AND c.is_district = 'F' "; 189 } 190 191 $sql = 192 "SELECT 193 c.id_city AS id_city, 194 c.city_name AS city_name, 195 s.id_state AS id_state, 196 s.state_name AS state_name, 197 s.state_symbol AS state_symbol 198 FROM 199 phpgw_cc_state s, 200 phpgw_cc_city c 201 WHERE 202 c.id_state = s.id_state AND 203 s.id_country = 'BR' AND 204 TO_ASCII(c.city_name) ILIKE TO_ASCII('" . $key . "%') 205 " . $where . " 176 206 ORDER BY 177 state_name"; 207 city_name 208 LIMIT 10"; 178 209 179 210 $result = $this->db->query($sql); … … 184 215 return $output; 185 216 } 217 /** 218 * Busca os estados brasileiros 219 * @return mixed (array ou boolean) 220 * @access public 221 */ 222 function getStates() 223 { 224 $sql = 225 "SELECT 226 id_state, 227 state_name 228 FROM 229 phpgw_cc_state 230 WHERE 231 id_country = 'BR' 232 ORDER BY 233 state_name"; 234 235 $result = $this->db->query($sql); 236 $output = array(); 237 while ($row = $result->fetchRow()) 238 $output[] = $row; 239 240 return $output; 241 } 186 242 } 187 243 ?> -
sandbox/workflow/trunk/inc/smarty/wf_plugins/function.wf_autocomplete_input.php
r1935 r2160 28 28 $defaultValues = array( 29 29 'minLength' => 1, 30 'style' => "width: 200px" 30 'style' => "width: 200px", 31 'mode' => "POPULATE_ON_LOAD" 31 32 ); 32 33 $extractParams = array( … … 38 39 'idValue', 39 40 'textValue', 40 'style' 41 'style', 42 'mode' 41 43 ); 42 44 … … 79 81 $extraParams = json_encode($extraParams); 80 82 83 /* se o componente for do tipo padrão (POPULATE_ON_LOAD), não necessita de função para onkeyup */ 84 if ($mode == 'POPULATE_ON_LOAD'){ 85 $inputElement = <<<EOF 86 <input id="$name_input" name="$name_input" type="text" value="$textValue" style="$style" onfocus="checkDataLoaded('$name');" onblur="setTimeout('selectAutocompleteElement(\'$name\')', 500);"/> 87 EOF; 88 } 89 elseif ($mode == 'REPOPULATE_ON_CHANGE'){ 90 $inputElement = <<<EOF 91 <input id="$name_input" name="$name_input" type="text" value="$textValue" style="$style" onblur="setTimeout('selectAutocompleteElement(\'$name\')', 500);" onkeyup="updateCacheRequestsTimeout('$name', '$ajaxClass', '$ajaxMethod', this.value, '$mode')"/> 92 EOF; 93 } 94 95 /* Cria todos os elementos HTML necessários para o componente */ 81 96 $output = <<<EOF 82 97 <input id="$name" name="$name" type="hidden"/> 83 <input id="$name_input" name="$name_input" type="text" value="$textValue" style="$style" onfocus="checkDataLoaded('$name');" onblur="setTimeout('selectAutocompleteElement(\'$name\')', 500);"/>98 $inputElement 84 99 <span id="$name_response"></span> 85 100 <div id="$name_list" class="autocomplete" style="display: none;"></div> 86 <script>autocompleteSelect('$name', '$ajaxClass', '$ajaxMethod', $sep$methodParam$sep, $extraParams);</script>101 <script>autocompleteSelect('$name', '$ajaxClass', '$ajaxMethod', $sep$methodParam$sep, '$mode', $extraParams);</script> 87 102 EOF; 88 103 return $output; -
sandbox/workflow/trunk/js/jscode/get_form_fields.js
r795 r2160 6 6 function get_form_fields(form_id){ 7 7 var elems = document.forms[form_id].elements; 8 var arr = new Object();9 var j = 0;8 var arr = new Object(); 9 var j = 0; 10 10 for(var i = 0; i < elems.length; i++){ 11 11 if(elems[i].id.substr(0,1) == "_"){ … … 33 33 continue; 34 34 } 35 36 // if the element has [] in the end of its name, return its values (or checked elements) like an array 37 if(elems[i].name.substr(-2,2) == "[]"){ 38 elem_name = elems[i].name.substr(0, elems[i].name.length - 2); 39 if(arr[elem_name] == undefined){ 40 arr[elem_name] = new Array(); 41 } 42 43 if(elems[i].type != "checkbox") 44 arr[elem_name].push(elems[i].value); 45 else if(elems[i].checked) 46 arr[elem_name].push(elems[i].value); 47 } 48 35 49 arr[elems[i].id] = elems[i].value; 36 50 j++; -
sandbox/workflow/trunk/js/jscode/wf_autocomplete_input.js
r1935 r2160 1 1 var _cache = new Array(); 2 2 var autocompleterObjs = new Array(); 3 var myTimer; 4 5 /* Verifica se o componente já foi populado (usado quando o tipo do componente é POPULATE_ON_LOAD) */ 3 6 function checkDataLoaded(elementId) 4 7 { … … 18 21 } 19 22 23 /* Faz a verificação se o conteúdo digitado tem um correspondente na lista */ 20 24 function selectAutocompleteElement(elementId) 21 25 { 22 26 if ($('input' + elementId) == null) return -1; 23 27 var value = $('input' + elementId).value; 24 var items = _cache['requests'][_cache['elements'][elementId]['hash']]['data']; 28 var items = new Object(); 29 if(_cache['requests'][_cache['elements'][elementId]['hash']] != undefined) 30 items = _cache['requests'][_cache['elements'][elementId]['hash']]['data']; 25 31 var index = autocompleteIndexOf(items, value); 26 32 $(elementId).value = index; … … 30 36 } 31 37 32 function autocompleteIndexOf(array, value) 33 { 34 for (key in array){ 35 if (array[key].toLowerCase() == value.toLowerCase()){ 36 return key; 38 /* Percorre o objeto comparando cada item com o valor digitado no componente, e retorna o índice, se encontrar */ 39 function autocompleteIndexOf(items, value) 40 { 41 for (key in items){ 42 if(items.hasOwnProperty(key)){ 43 if (items[key].toLowerCase() == value.toLowerCase()){ 44 return key; 45 } 37 46 } 38 47 } … … 40 49 } 41 50 42 function arrayValues( array)51 function arrayValues(items) 43 52 { 44 53 var i = 0; 45 54 var arr = Array(); 46 for (key in array){47 arr[i++] = array[key];55 for (key in items){ 56 arr[i++] = items[key]; 48 57 } 49 58 return arr; 50 59 } 51 60 61 function removeAccents(text) { 62 var accents = 'áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ'; 63 var normalLetters = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC'; 64 var newText = ''; 65 66 for (i = 0; i < text.length; i++) { 67 if (accents.search(text.substr(i, 1)) >= 0) { 68 newText += normalLetters.substr(accents.search(text.substr(i, 1)), 1); 69 } 70 else { 71 newText += text.substr(i, 1); 72 } 73 } 74 75 return newText; 76 } 77 78 /* Cria, ou recria, o objeto autocompleter do componente, carregando a lista com os valores que já devem estar no cache */ 52 79 function autocompletePopulate(elementId) 53 80 { … … 55 82 var items = _cache['requests'][_cache['elements'][elementId]['hash']]['data']; 56 83 var values = arrayValues(items); 57 new Autocompleter.Local('input' + elementId, 'list' + elementId, values, {84 autocompleterObjs[elementId] = new Autocompleter.Local('input' + elementId, 'list' + elementId, values, { 58 85 'choices':9, 59 86 'partialChars': _cache['elements'][elementId]['minLength'] 60 87 }); 61 } 62 _cache['elements'][elementId]['populated'] = true; 63 } 64 65 function catchJsonError(dados){ return false; } 66 67 function autocompleteSelect(elementId, ajaxClass, ajaxMethod, methodParam, extraParams) 68 { 69 // se o parâmetro for um objeto, transforma em uma string para gerar o hash 88 _cache['elements'][elementId]['populated'] = true; 89 } 90 } 91 92 /* Cria array para armazenar os elementos */ 93 function createCacheElementsArray(){ 94 if(_cache['elements'] == null) 95 _cache['elements'] = new Array(); 96 } 97 98 /* Cria array para armazenar os valores das requisições ajax */ 99 function createCacheRequestsArray(){ 100 if(_cache['requests'] == null) 101 _cache['requests'] = new Array(); 102 } 103 104 /* Seta os valores do componente no _cache */ 105 function createCacheElement(elementId, ajaxClass, ajaxMethod, methodParam, componentMode, extraParams){ 106 // se o parâmetro for um objeto, transforma em uma string para gerar o hash 70 107 var _param = (typeof(methodParam) == 'object')? JSON.stringify(methodParam) : methodParam; 71 var str = ajaxClass + ajaxMethod + _param; 72 // Cria hash que identifica classe, método e parâmetro. 73 // Componente verifica se hash já existe para não fazer requisições ajax desnecessárias 74 var hash = new SHA1(str).hexdigest(); 108 109 // se o componente tiver que ser populado em sua criação, calcula o hash 110 if (componentMode == 'POPULATE_ON_LOAD'){ 111 var str = ajaxClass + ajaxMethod + _param; 112 // Cria hash que identifica classe, método e parâmetro. 113 // Componente verifica se hash já existe para não fazer requisições ajax desnecessárias 114 var hash = new SHA1(str).hexdigest(); 115 } 116 // senão, não há a necessidade de calcular o hash, pois a lista será carregada posteriormente 117 else 118 var hash = ""; 75 119 76 120 if(extraParams['minLength'] == null){ … … 89 133 } 90 134 91 func = function (dados) 92 { 93 var result = dados[ajaxMethod]['data']; 94 if (result !== false){ 95 // guarda valores localmente 96 _cache['requests'][hash]['data'] = result; 97 _cache['requests'][hash]['populated'] = true; 98 // Envia dados para o componente 99 autocompletePopulate(elementId); 100 } 101 }; 102 103 // Relaciona chamada ajax ao objeto 104 if(_cache['elements'] == null){ 105 _cache['elements'] = new Array(); 106 } 135 createCacheElementsArray(); 107 136 108 137 if(_cache['elements'][elementId] == null){ … … 111 140 _cache['elements'][elementId]['minLength'] = extraParams['minLength']; 112 141 } else { 113 // por algum motivo componente j áexiste.114 // Se o _cache na posi ção hash não for null, requisição ajax jáfoi feita.115 // Se o objeto j á foi populado e está sendo escrito novamente, manda popular denovo116 // (isso pode acontecer quando o componente é escrito através de javascript)142 // por algum motivo componente já existe. 143 // Se o _cache na posição hash não for null, requisição ajax já foi feita. 144 // Se o objeto já foi populado e está sendo escrito novamente, manda popular denovo 145 // (isso pode acontecer quando o componente é escrito através de javascript) 117 146 if(_cache['requests'][hash] != null) 118 147 if (_cache['requests'][hash]['populated'] == true){ … … 121 150 } 122 151 } 123 124 // Cria array para armazenar localmente os valores da requisição ajax 125 if(_cache['requests'] == null) 126 _cache['requests'] = new Array(); 152 } 153 154 function catchJsonError(dados){ return false; } 155 156 /* Controle de timeout para chamar a função updateCacheRequests quando o usuário ficar 0.3 segundos sem digitar. (chamada no onkeyup do componente do tipo REPOPULATE_ON_CHANGE) */ 157 function updateCacheRequestsTimeout(elementId, ajaxClass, ajaxMethod, methodParam, componentMode){ 158 clearTimeout(myTimer); 159 myTimer = setTimeout("updateCacheRequests('" + elementId + "', '" + ajaxClass + "', '" + ajaxMethod + "', '" + methodParam + "', '" + componentMode + "')", 300); 160 } 161 162 /* Função que faz o gerenciamento das chamadas ajax e atualiza a lista de opções para seleção. */ 163 var updateCacheRequests = function(elementId, ajaxClass, ajaxMethod, methodParam, componentMode){ 164 // se o parâmetro for um objeto, transforma em uma string para gerar o hash 165 var _param = (typeof(methodParam) == 'object')? JSON.stringify(methodParam) : methodParam; 166 var str = ajaxClass + ajaxMethod + _param; 167 // Cria hash que identifica classe, método e parâmetro. 168 // Componente verifica se hash já existe para não fazer requisições ajax desnecessárias 169 var hash = new SHA1(str).hexdigest(); 127 170 128 171 if(_cache['requests'][hash] == null){ … … 131 174 _cache['requests'][hash]['data'] = new Array(); 132 175 133 // Faz a requisição ajax/Json 134 var nc = new NanoController(); 135 nc.setWfUrl(); 136 nc.setSuccessHandler(func); 137 nc.setExceptionHandler(catchJsonError); 138 nc.setErrorHandler(catchJsonError); 139 nc.addVirtualRequest(ajaxMethod, 140 { 141 action: ajaxClass, 142 mode: ajaxMethod 143 }, methodParam); 144 nc.sendRequest(); 145 } 146 } 176 if (componentMode == 'POPULATE_ON_LOAD'){ 177 func = function (dados) 178 { 179 var result = dados[ajaxMethod]['data']; 180 if (result !== false){ 181 // guarda valores localmente 182 _cache['requests'][hash]['data'] = result; 183 _cache['requests'][hash]['populated'] = true; 184 // Envia dados para o componente 185 autocompletePopulate(elementId); 186 } 187 }; 188 189 // Faz a requisição ajax/Json 190 var nc = new NanoController(); 191 nc.setWfUrl(); 192 nc.setSuccessHandler(func); 193 nc.setExceptionHandler(catchJsonError); 194 nc.setErrorHandler(catchJsonError); 195 nc.addVirtualRequest(ajaxMethod, 196 { 197 action: ajaxClass, 198 mode: ajaxMethod 199 }, methodParam); 200 nc.sendRequest(); 201 } 202 else{ 203 if(_param.length >= 3){ 204 func = function (dados) 205 { 206 var result = dados[ajaxMethod]['data']; 207 if(typeof(result) == "object" && result.length != 0){ 208 // guarda valores localmente 209 _cache['requests'][hash]['data'] = result; 210 _cache['requests'][hash]['populated'] = true; 211 _cache['elements'][elementId]['hash'] = hash; 212 var values = arrayValues(result); 213 autocompleterObjs[elementId].options.array = values; 214 autocompleterObjs[elementId].getUpdatedChoices(); 215 } 216 }; 217 218 // Faz a requisição ajax/Json 219 var nc = new NanoController(); 220 nc.setWfUrl(); 221 nc.setSuccessHandler(func); 222 nc.setExceptionHandler(catchJsonError); 223 nc.setErrorHandler(catchJsonError); 224 nc.addVirtualRequest(ajaxMethod, 225 { 226 action: ajaxClass, 227 mode: ajaxMethod 228 }, removeAccents(methodParam)); 229 nc.sendRequest(); 230 } 231 } 232 } 233 else{ 234 // Se for do modo que deve repopular a lista a cada tecla pressionada e o _cache referente à entrada digitada já estiver populada 235 if (componentMode == 'REPOPULATE_ON_CHANGE' && _cache['requests'][hash]['populated']){ 236 _cache['elements'][elementId]['hash'] = hash; 237 var values = arrayValues(_cache['requests'][hash]['data']); 238 autocompleterObjs[elementId].options.array = values; 239 } 240 } 241 } 242 243 /* Função que prepara o _cache, criando e setando os valores para cada componente */ 244 function autocompleteSelect(elementId, ajaxClass, ajaxMethod, methodParam, componentMode, extraParams) 245 { 246 createCacheElement(elementId, ajaxClass, ajaxMethod, methodParam, componentMode, extraParams); 247 createCacheRequestsArray(); 248 249 // Se o componente é do tipo que deve repopular a lista a cada tecla, cria um objeto autocompleter com a lista vazia 250 if(componentMode == 'REPOPULATE_ON_CHANGE') 251 autocompleterObjs[elementId] = new Autocompleter.Local('input' + elementId, 'list' + elementId, new Array(), { 252 'choices':9, 253 'partialChars': _cache['elements'][elementId]['minLength'] 254 }); 255 256 updateCacheRequests(elementId, ajaxClass, ajaxMethod, methodParam, componentMode); 257 }
Note: See TracChangeset
for help on using the changeset viewer.