[795] | 1 | var participantsClone = null; |
---|
| 2 | var searchTimer = null; |
---|
| 3 | var globalSearchEnter = true; |
---|
| 4 | |
---|
| 5 | function callAjax(action, mode, handler, parameters) |
---|
| 6 | { |
---|
| 7 | var url = '$this.' + action + '.' + mode; |
---|
| 8 | if (parameters) |
---|
| 9 | cExecute(url, handler, $H(parameters).toQueryString()); |
---|
| 10 | else |
---|
| 11 | cExecute(url, handler); |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | function getSectors() |
---|
| 15 | { |
---|
| 16 | function resultGetSectors(data) |
---|
| 17 | { |
---|
| 18 | setSelectValue($('sector'), data['sectors']); |
---|
| 19 | $('sector').onchange = getParticipants; |
---|
| 20 | resultGetParticipants(data['participants']); |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | var params = { |
---|
| 24 | organization: $F('organization'), |
---|
| 25 | entities: $F('entities'), |
---|
| 26 | id: $F('id'), |
---|
| 27 | usePreffix: $F('usePreffix') |
---|
| 28 | }; |
---|
| 29 | callAjax('bo_participants', 'getSectors', resultGetSectors, params); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | function getParticipants() |
---|
| 33 | { |
---|
| 34 | var params = { |
---|
| 35 | context: $F('sector'), |
---|
| 36 | entities: $F('entities'), |
---|
| 37 | id: $F('id'), |
---|
| 38 | usePreffix: $F('usePreffix') |
---|
| 39 | }; |
---|
| 40 | callAjax('bo_participants', 'getEntities', resultGetParticipants, params); |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | function resultGetParticipants(data) |
---|
| 44 | { |
---|
| 45 | $('search').value = ''; |
---|
| 46 | setSelectValue($('participants'), data); |
---|
| 47 | participantsClone = data; |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | function searchParticipantsTimer(e) |
---|
| 51 | { |
---|
| 52 | if (checkShortcuts((e) ? e : window.event)) |
---|
| 53 | return true; |
---|
| 54 | |
---|
| 55 | if (searchTimer) |
---|
| 56 | clearTimeout(searchTimer); |
---|
| 57 | |
---|
| 58 | searchTimer = setTimeout(function(){searchParticipants($F('search'));}, 250); |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | function searchParticipants(searchString) |
---|
| 62 | { |
---|
| 63 | var reg = new RegExp("<option[^>]*>[^<]*" + searchString + "[^<]*<\/option>", "gi"); |
---|
| 64 | setSelectValue($('participants'), participantsClone.match(reg)); |
---|
| 65 | |
---|
| 66 | var participants = $('participants'); |
---|
| 67 | if (participants.options[0]) |
---|
| 68 | participants.selectedIndex = 0; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | function checkShortcuts(e) |
---|
| 72 | { |
---|
| 73 | var whichCode = (e.which) ? e.which : e.keyCode; |
---|
| 74 | var handled = false; |
---|
| 75 | |
---|
| 76 | if (whichCode == 13) /* ENTER */ |
---|
| 77 | { |
---|
| 78 | $('addUserLink').onclick(); |
---|
| 79 | handled = true; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | if (whichCode == 27) /* ESC */ |
---|
| 83 | { |
---|
| 84 | $('exitLink').onclick(); |
---|
| 85 | handled = true; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | if (whichCode == 38) /* key up */ |
---|
| 89 | { |
---|
| 90 | var participants = $('participants'); |
---|
| 91 | if (participants.selectedIndex > 0) |
---|
| 92 | if (!participants[participants.selectedIndex - 1].disabled) |
---|
| 93 | participants.selectedIndex--; |
---|
| 94 | handled = true; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if (whichCode == 40) /* key down */ |
---|
| 98 | { |
---|
| 99 | var participants = $('participants'); |
---|
| 100 | if (participants.selectedIndex < participants.length - 1) |
---|
| 101 | if (!participants[participants.selectedIndex + 1].disabled) |
---|
| 102 | participants.selectedIndex++; |
---|
| 103 | handled = true; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | return handled; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | if (Event.observe) |
---|
| 110 | { |
---|
| 111 | Event.observe(window, 'load', function() { |
---|
| 112 | if (typeof Prototype == 'undefined') |
---|
| 113 | return; |
---|
| 114 | /* atribui as ações aos eventos */ |
---|
| 115 | var obj = $('organization'); |
---|
| 116 | if (obj) |
---|
| 117 | obj.onchange = getSectors; |
---|
| 118 | |
---|
| 119 | obj = $('sector'); |
---|
| 120 | if (obj) |
---|
| 121 | obj.onchange = getParticipants; |
---|
| 122 | |
---|
| 123 | obj = $('search'); |
---|
| 124 | if (obj) |
---|
| 125 | obj.onkeydown = searchParticipantsTimer; |
---|
| 126 | |
---|
| 127 | obj = $('participants'); |
---|
| 128 | if (obj) |
---|
| 129 | participantsClone = obj.innerHTML; |
---|
| 130 | |
---|
| 131 | obj = $('exitLink'); |
---|
| 132 | if (obj) |
---|
| 133 | obj.onclick = function(){window.close();}; |
---|
| 134 | |
---|
| 135 | obj = $('addUserLink'); |
---|
| 136 | if (obj) |
---|
| 137 | obj.onclick = addUser; |
---|
| 138 | |
---|
| 139 | obj = $('search'); |
---|
| 140 | if (obj) |
---|
| 141 | obj.focus(); |
---|
| 142 | |
---|
| 143 | obj = $('useGlobalSearch'); |
---|
| 144 | if (obj) |
---|
| 145 | { |
---|
| 146 | obj.onclick = toggleFullSearch; |
---|
| 147 | toggleFullSearch(); |
---|
| 148 | } |
---|
| 149 | }); |
---|
| 150 | }; |
---|
| 151 | |
---|
| 152 | function participantsFilterName(name) |
---|
| 153 | { |
---|
| 154 | if (!$('useGlobalSearch').checked) |
---|
| 155 | return name; |
---|
| 156 | |
---|
| 157 | return name.substr(0, name.lastIndexOf('(') - 1); |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | function addUser() |
---|
| 161 | { |
---|
| 162 | var participants = $('participants'); |
---|
| 163 | var target = window.opener.document.getElementById($F('target')); |
---|
| 164 | var previous = ''; |
---|
| 165 | var current = ''; |
---|
| 166 | |
---|
| 167 | if ((target.tagName == 'INPUT') || (target.tagName == 'TEXTAREA')) |
---|
| 168 | { |
---|
| 169 | previous = target.value; |
---|
| 170 | if ($F('id') == 'mail') |
---|
| 171 | { |
---|
| 172 | var participantsLength = participants.options.length; |
---|
| 173 | var current = null; |
---|
| 174 | for (var i = 0; i < participantsLength; i++) |
---|
| 175 | { |
---|
| 176 | current = participants.options[i]; |
---|
| 177 | if (current.selected) |
---|
| 178 | target.value += '"' + participantsFilterName(current.text) + '" ' + '<' + current.value + '>, '; |
---|
| 179 | } |
---|
| 180 | } |
---|
| 181 | else |
---|
| 182 | { |
---|
| 183 | if (participants.selectedIndex > -1) |
---|
| 184 | { |
---|
| 185 | target.value = participants.options[participants.selectedIndex].value.replace('u',''); |
---|
| 186 | window.opener.document.getElementById(target.id + '_desc').value = participantsFilterName(participants.options[participants.selectedIndex].text); |
---|
| 187 | } |
---|
| 188 | } |
---|
| 189 | current = target.value; |
---|
| 190 | } |
---|
| 191 | else |
---|
| 192 | { |
---|
| 193 | previous = target.innerHTML; |
---|
| 194 | var options = ''; |
---|
| 195 | var participantsLength = participants.options.length; |
---|
| 196 | var current = null; |
---|
| 197 | var insertElement; |
---|
| 198 | for (var i = 0; i < participantsLength; i++) |
---|
| 199 | { |
---|
| 200 | current = participants.options[i]; |
---|
| 201 | if (current.selected) |
---|
| 202 | { |
---|
| 203 | /* checa se o elemento que será inserido já existe na select box destino */ |
---|
| 204 | insertElement = true; |
---|
| 205 | for (var j = 0; j < target.options.length; j++) |
---|
| 206 | if (target.options[j].value == current.value) |
---|
| 207 | { |
---|
| 208 | insertElement = false; |
---|
| 209 | break; |
---|
| 210 | } |
---|
| 211 | if (insertElement) |
---|
| 212 | options += '<option value="' + current.value + '">' + participantsFilterName(current.text) + '</option>'; |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | if (options.length > 0) |
---|
| 216 | { |
---|
| 217 | setSelectValue(target, target.innerHTML + options); |
---|
| 218 | /* refaz o link que se perde quando modifica-se o innerHTML da select box */ |
---|
| 219 | target = window.opener.document.getElementById($F('target')); |
---|
| 220 | } |
---|
| 221 | current = target.innerHTML; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | /* se o código do desenvolvedor está esperando o evento onchange, dispara o evento */ |
---|
| 225 | if (target.onchange) |
---|
| 226 | if (current != previous) |
---|
| 227 | target.onchange(); |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | function setSelectValue(obj, value) |
---|
| 231 | { |
---|
| 232 | /* IE MAGIC */ |
---|
| 233 | if (obj.outerHTML) |
---|
| 234 | { |
---|
| 235 | obj.innerHTML = ''; |
---|
| 236 | obj.outerHTML = obj.outerHTML.match(/<select[^>]*>/gi) + value + '</select>'; |
---|
| 237 | } |
---|
| 238 | else |
---|
| 239 | obj.innerHTML = value; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | function participantsRemoveUser(obj) |
---|
| 243 | { |
---|
| 244 | if (obj.tagName == 'INPUT') |
---|
| 245 | { |
---|
| 246 | obj.value = ''; |
---|
| 247 | obj = document.getElementById(obj.id + '_desc'); |
---|
| 248 | if (obj) |
---|
| 249 | obj.value = ''; |
---|
| 250 | } |
---|
| 251 | else |
---|
| 252 | { |
---|
| 253 | for(var i = 0;i < obj.options.length; i++) |
---|
| 254 | if(obj.options[i].selected) |
---|
| 255 | obj.options[i--] = null; |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | function toggleFullSearch() |
---|
| 260 | { |
---|
| 261 | $('search').value = ''; |
---|
| 262 | |
---|
| 263 | if ($('useGlobalSearch').checked) |
---|
| 264 | { |
---|
| 265 | globalSearchEnter = true; |
---|
| 266 | if ($('organizationSectors')) |
---|
| 267 | $('organizationSectors').hide(); |
---|
| 268 | if ($('globalSearchTitle')) |
---|
| 269 | $('globalSearchTitle').show(); |
---|
| 270 | setSelectValue($('participants'), ''); |
---|
| 271 | $('search').onkeydown = globalSearchKeyAnalyzer; |
---|
| 272 | $('globalSearchWarnings').innerHTML = 'Para executar a busca, pressione ENTER.'; |
---|
| 273 | } |
---|
| 274 | else |
---|
| 275 | { |
---|
| 276 | $('globalSearchWarnings').innerHTML = ''; |
---|
| 277 | if ($('globalSearchTitle')) |
---|
| 278 | $('globalSearchTitle').hide(); |
---|
| 279 | if ($('organizationSectors')) |
---|
| 280 | $('organizationSectors').show(); |
---|
| 281 | searchParticipants(''); |
---|
| 282 | $('search').onkeydown = searchParticipantsTimer; |
---|
| 283 | } |
---|
| 284 | $('search').focus(); |
---|
| 285 | } |
---|
| 286 | |
---|
| 287 | function checkGlobalSearchShortcuts(e) |
---|
| 288 | { |
---|
| 289 | var whichCode = (e.which) ? e.which : e.keyCode; |
---|
| 290 | var handled = false; |
---|
| 291 | |
---|
| 292 | /* ENTER */ |
---|
| 293 | if ((whichCode == 13) && globalSearchEnter) |
---|
| 294 | { |
---|
| 295 | performGlobalSearch(); |
---|
| 296 | handled = true; |
---|
| 297 | globalSearchEnter = false; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | if (handled == false) |
---|
| 301 | { |
---|
| 302 | handled = checkShortcuts(e); |
---|
| 303 | if (handled == true) |
---|
| 304 | globalSearchEnter = false; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | if (handled == false) |
---|
| 308 | globalSearchEnter = true; |
---|
| 309 | |
---|
| 310 | return handled; |
---|
| 311 | } |
---|
| 312 | |
---|
| 313 | function globalSearchKeyAnalyzer(e) |
---|
| 314 | { |
---|
| 315 | if (checkGlobalSearchShortcuts((e) ? e : window.event)) |
---|
| 316 | return true; |
---|
| 317 | |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | function performGlobalSearch() |
---|
| 321 | { |
---|
| 322 | function resultPerformGlobalSearch(data) |
---|
| 323 | { |
---|
| 324 | setSelectValue($('participants'), data['participants']); |
---|
| 325 | if (data['warnings']) |
---|
| 326 | if (data['warnings'].length > 0) |
---|
| 327 | $('globalSearchWarnings').innerHTML = data['warnings'].join('<br/>'); |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | $('globalSearchWarnings').innerHTML = ''; |
---|
| 331 | var params = { |
---|
| 332 | searchTerm: $F('search'), |
---|
| 333 | entities: $F('entities'), |
---|
| 334 | id: $F('id'), |
---|
| 335 | usePreffix: $F('usePreffix') |
---|
| 336 | }; |
---|
| 337 | callAjax('bo_participants', 'globalSearch', resultPerformGlobalSearch, params); |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | function openParticipants(target, option) |
---|
| 341 | { |
---|
| 342 | newWidth = 500; |
---|
| 343 | newHeight = 290; |
---|
| 344 | newScreenX = screen.width - newWidth; |
---|
| 345 | newScreenY = 0; |
---|
| 346 | page = 'index.php?menuaction=workflow.ui_participants.form'; |
---|
| 347 | if (target) |
---|
| 348 | page += "&target_element=" + target; |
---|
| 349 | if (option) |
---|
| 350 | page += "&" + option; |
---|
| 351 | |
---|
| 352 | window.open(page,'','width='+newWidth+',height='+newHeight+',screenX='+newScreenX+',left='+newScreenX+',screenY='+newScreenY+',top='+newScreenY+',toolbar=no,scrollbars=no,resizable=no'); |
---|
| 353 | } |
---|