1// This function is used by the login screen to validate user/pass 2// are entered. 3function validateRequired(form) { 4 var bValid = true; 5 var focusField = null; 6 var i = 0; 7 var fields = new Array(); 8 oRequired = new required(); 9 for (x in oRequired) { 10 if ((form[oRequired[x][0]].type == 'text' || form[oRequired[x][0]].type == 'textarea' || form[oRequired[x][0]].type == 'select-one' || form[oRequired[x][0]].type == 'radio' || form[oRequired[x][0]].type == 'password') && form[oRequired[x][0]].value == '') { 11 if (i == 0) 12 focusField = form[oRequired[x][0]]; 13 fields[i++] = oRequired[x][1]; 14 bValid = false; 15 } 16 } 17 18 if (fields.length > 0) { 19 focusField.focus(); 20 alert(fields.join('\n')); 21 } 22 23 return bValid; 24} 25 26// This function is a generic function to create form elements 27function createFormElement(element, type, name, id, value, parent) { 28 var e = document.createElement(element); 29 e.setAttribute("name", name); 30 e.setAttribute("type", type); 31 e.setAttribute("id", id); 32 e.setAttribute("value", value); 33 parent.appendChild(e); 34} 35 36function confirmDelete(obj) { 37 var msg = "Are you sure you want to delete this " + obj + "?"; 38 ans = confirm(msg); 39 return ans; 40} 41 42// 18n version of confirmDelete. Message must be already built. 43function confirmMessage(obj) { 44 var msg = "" + obj; 45 ans = confirm(msg); 46 return ans; 47} 48/* 49 * Função para verificar se um valor de um filtro faz parte de um valor de um campo 50 * (útil para campos com autocomplete) 51 * @param {string} itemLabel 52 * @param {string} filterValue 53 * @returns {Boolean} 54 */ 55function filterValueMatches(itemLabel, filterValue) { 56 var filterValueLower = filterValue.toLowerCase(); 57 var itemLabelLower = itemLabel.toLowerCase(); 58 return (new RegExp(filterValueLower)).test(itemLabelLower); 59} 60 61/* 62 * Função para copiar o conteúdo de um elemento para outro 63 * @param {string} src id 64 * @param {string} target id 65 * @returns {undefined} 66 */ 67function copyContent(srcId, targetId) { 68 var srcTextarea = document.getElementById(srcId); 69 var destTextarea = document.getElementById(targetId); 70 destTextarea.value = srcTextarea.value; 71} 72 73/* 74 PrimeFaces.widget.ColumnToggler.prototype.render = function() { 75 //variable for creating id referance for each checkbox in ColumnToggler 76 var id = 0; 77 this.columns = this.thead.find("> tr > th:visible:not(.ui-static-column)"); 78 this.panel = $("<div></div>").attr("id", this.cfg.id).addClass("ui-columntoggler ui-widget ui-widget-content ui-shadow ui-corner-all").append('<ul class="ui-columntoggler-items"></ul').appendTo(document.body); 79 this.itemContainer = this.panel.children("ul"); 80 for (var a = 0; a < this.columns.length; a++) { 81 id++; 82 var b = this.columns.eq(a); 83 $('<li class="ui-columntoggler-item"><div class="ui-chkbox ui-widget"><div id="cb' + id + '" class="ui-chkbox-box ui-widget ui-corner-all ui-state-default ui-state-active"><span class="ui-chkbox-icon ui-icon ui-icon-check"></span></div></div><label>' + b.children(".ui-column-title").text() + "</label></li>").data("column", b.attr("id")).appendTo(this.itemContainer); 84 85 //access clumns using class reference(not-show-at-start) created in jsf page 86 if (b.hasClass("not-show-at-start")) { 87 //access checkbox using id attribute created above and uncheck it 88 //this will hide columns that have "not-show-at-start" class 89 this.uncheck($('#cb' + id)); 90 } 91 } 92 93 this.hide(); 94 }*/ 95 96function goBack() { 97 blockPage(); 98 history.back(); 99} 100 101function filterConfidentialUsers(varClass) { 102 var valThis = returnContainer(varClass); 103 if (valThis) { 104 valThis = valThis.value.toUpperCase(); 105 if (valThis === "") { 106//.ui-selectmanycheckbox > tbody > tr > td:nth-child(2) > label 107 $('.ui-selectmanycheckbox > tbody > tr ').show(); 108 } else { 109 $('.ui-selectmanycheckbox > tbody > tr ').each(function () { 110 var text = $(this).text().toUpperCase(); 111 var valThisArr = valThis.split(' '); 112 if (valThisArr) { 113 var hasAMatch = false;
114 for (var i = 0; i < valThisArr.length && !hasAMatch; i++) { 115 var pattern = valThisArr[i]; 116 hasAMatch = hasAMatch || (text.search(pattern) >= 0); 117 } 118 if (hasAMatch) { 119 $(this).show(); 120 } else { 121 $(this).hide(); 122 } 123 } 124 }); 125 } 126 } 127} 128function returnContainer(matchClass) { 129 var elems = document.getElementsByTagName('*'), i; 130 for (i in elems) { 131 if ((' ' + elems[i].className + ' ').indexOf(' ' + matchClass + ' ') > -1) { 132 return elems[i]; 133 } 134 } 135 return null; 136} 137 138function blockPage() { 139 PF('fullPageBlocker').block(); 140} 141 142function unblockPage() { 143 PF('fullPageBlocker').unblock(); 144 // outras acoes como detetar se houve timeout ou erro 145} 146 147function scrollToTop() { 148 $("html, body").animate({scrollTop: $('#stepPanel').offset().top}, 1000); 149} 150 151/* Ignora excecoes */ 152function blockComponent(c) { 153 try { 154 c.block(); 155 } catch (err) { 156 } 157} 158 159function unblockComponent(c) { 160 try { 161 c.unblock(); 162 } catch (err) { 163 } 164} 165 166/* Workaround para problema que já deveria estar resolvido no PrimeFaces Issue #4879 */ 167function fixPFDialogToggleMaximize(dlg) { 168 if (dlg.doToggleMaximize === undefined) { 169 dlg.doToggleMaximize = dlg.toggleMaximize; 170 dlg.toggleMaximize = function () { 171 this.doToggleMaximize(); 172 var marginsDiff = this.content.outerHeight() - this.content.height(); 173 var newHeight = this.jq.innerHeight() - this.titlebar.outerHeight() - marginsDiff; 174 this.content.height(newHeight); 175 }; 176 } 177} 178/** 179 * Função para fazer toggle dos nodes de uma tree primefaces 180 * @param {type} treeId ID da tree 181 * @returns {undefined} 182 */ 183function toggleTree(treeId) { 184 $(treeId + ' .ui-tree-toggler').click(); 185} 186 187/** 188 * color for avatar based in complete user name 189 * @param {type} string 190 * @returns {String} 191 */ 192function colorAvatar(string) { 193 return '#' + md5(string).slice(0, 6); 194} 195/** 196 * parse complete user name in initials(ex: parseName({value: 'Nuno Marinho', maxChar: 3}) = NM) 197 * @param {type} params 198 * @returns {String} 199 */ 200function parseNameAvatar(params) { 201 var name = params.value; 202 var maxChar = params.maxChar; 203 var words = name.split(" "); 204 var character = ''; 205 if (words !== '') { 206 $.each(words, function (index, value) { 207 /*if (value) { 208 if (character.length < maxChar) { 209 character += value[0]; 210 } 211 }*/ 212 if (index === 0) { 213 character += value[0]; 214 } 215 if (words.length > 1 && index === (words.length - 1)) { 216 character += value[0]; 217 } 218 }); 219 } else { 220 character += '...'; 221 } 222 return character.toUpperCase(); 223} 224/** 225 * generate avatar 226 * @param {type} el 227 * @param {type} nameEl 228 * @param {type} sizeEl 229 * @returns {undefined} 230 */ 231function generateGravatar(el, nameEl, sizeEl) { 232 /** create avatar**/ 233 var color0 = colorAvatar(nameEl); 234 var initials = new Avatar(el, { 235 'useGravatar': false, 236 'initials': parseNameAvatar({value: nameEl, maxChar: 2}), 237 'initial_bg': color0, 238 'size': sizeEl, 239 'initial_fg': '#FFFFFF' 240 }); 241 /* 242 * Visto que o generateGravatar recebe o apontador para a img e faz 243 * update da mesma é necessário fazer reset ao unload. Caso contrário 244 * entra em ciclo infinito. 245 246 * Sempre que uma imagem é atualizada o onload é chamada, sempre que o 247 * unload é chamado caso não se faça reset voltamos a chamar um método 248 * que faz update à imagem... 249 */ 250 el.onload = ''; 251} 252 253 254/** 255 * Módulo de funções auxiliares para o FutureDoc 256 * @type type 257 */ 258var FutureDocUtils = { 259 /** 260 * Função auxiliar para simular o retainAll de um array; Retorna os elementos de B que não estão em A 261 * @param {type} a 262 * @param {type} b 263 * @returns {Array|ListTasksController.retainAll.missing}
263 o array de B que não está contido em A 264 */ 265 retainAll: function (a, b) { 266 var ai, aElement, missing = []; 267 for (ai = 0; ai < a.length; ai++) { 268 aElement = a[ai]; 269 if ($.inArray(aElement, b) === -1) { 270 missing.push(aElement); 271 } 272 } 273 return missing; 274 }, 275 /** 276 * Remove o elemento do array e retorna o elemento removido (se existir; se 277 * não existir retorna undefined). 278 * Ex.: popElement([1,2,3], 2); retorna 2; array = [1, 3] 279 * @param {type} array 280 * @param {type} element 281 * @returns {unresolved} 282 */ 283 popElement: function (array, element) { 284 var i, e; 285 if (array) { 286 i = array.indexOf(element); 287 if (i > -1) { 288 e = array[i]; 289 array.splice(i, 1); 290 } 291 } 292 return e; 293 }, 294 /** 295 * Remove elementos de um array. 296 * Ex.: removeElementsFromArray([1,2,3],[1,2,3,4,5]) = [4,5] 297 * @param {type} remove elementos a remover 298 * @param {type} array array original 299 * @returns {unresolved} 300 */ 301 removeElementsFromArray: function (remove, array) { 302 if (array) { 303 var i, r; 304 for (i = 0; i < remove.length; i++) { 305 r = remove[i]; 306 FutureDocUtils.popElement(array, r); 307 } 308 return array; 309 } 310 }, 311 /** 312 * Generate random UUID 313 * http://jsfiddle.net/briguy37/2MVFd/ 314 * @returns {String} 315 */ 316 generateUUID: function () { 317 var d = new Date().getTime(); 318 var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { 319 var r = (d + Math.random() * 16) % 16 | 0; 320 d = Math.floor(d / 16); 321 return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16); 322 }); 323 return uuid; 324 }, 325 /** 326 * Função para mostrar todos os elementos seleccionados com o `jQuerySelector` 327 * @param {jQuery object} jQuerySelector 328 * @returns {undefined} 329 */ 330 show: function (jQuerySelector) { 331 this.visibility(jQuerySelector, true); 332 }, 333 /** 334 * Função para esconder todos os elementos seleccionados com o `jQuerySelector` 335 * @param {jQuery object} jQuerySelector 336 * @returns {undefined} 337 */ 338 hide: function (jQuerySelector) { 339 this.visibility(jQuerySelector, false); 340 }, 341 /** 342 * Função para controlar a visibilidade de todos os elementos seleccionados 343 * com o `jQuerySelector` 344 * @param {jQuery object} jQuerySelector 345 * @param {boolean} show 346 * @returns {undefined} objetos jQuery alterados 347 */ 348 visibility: function (jQuerySelector, show) { 349 if (show) { 350 var shown = $(jQuerySelector).show(); 351 shown.removeClass('invisible'); 352 return shown; 353 } else { 354 return $(jQuerySelector).hide(); 355 } 356 } 357}; 358/** 359 * Naming container para utils de Storage de HTML5 360 * @type type 361 */ 362var StorageUtils = { 363 supportsLocalStorage: function () { 364 try { 365 return window.hasOwnProperty('localStorage') && window.localStorage !== null; 366 } catch (e) { 367 return false; 368 } 369 }, 370 assertLocalStorageSupport: function () { 371 if (!StorageUtils.supportsLocalStorage()) { 372 throw new Error('HTML 5 local storage unsupported'); 373 } 374 }, 375 /** 376 * Extrai um array de local storage (HTML5) 377 * @param {string} key 378 * @param {function} elementParser (opcional) ex: function(e) { return parseInt(e,10);} 379 * @returns {array} 380 */ 381 getLocalArray: function (key, elementParser) { 382 StorageUtils.assertLocalStorageSupport(); 383 var array = []; 384 var splits, local = localStorage.getItem(key); 385 var it, element; 386 if (local !== null) { 387 var i; 388 splits = local.split(';'); 389 for (i = 0; i < splits.length; i++) { 390 it = splits[i]; 391 element = elementParser !== undefined ? elementParser(it) : it; 392 array.push(element); 393 } 394 return array; 395 } 396 }, 397 /** 398 * Guarda um array em local storage (HTML5) 399 * @param {type} key 400 * @param {type} array 401 * @returns {undefined} 402 */ 403 setLocalArray: function (key, array) { 404 StorageUtils.assertLocalStorageSupport(); 405 var i, parsedValue = '', delimiter = ';'; 406 for (i = 0; i < array.length; i++) { 407 parsedValue += array[i]; 408 if (i + 1 < array.length) { 409 parsedValue += delimiter; 410 } 411 } 412 localStorage.setItem(key, parsedValue); 413 } 414}; 415 416/** 417 * Remove as tooltips do corpo do editor do CKEditor. 418 * @param {string} source ID do editor ("source" dos eventos do pe:javascript). 419 */ 420function hideCKEditorTooltip(source) { 421 var src = "#cke_" + source.replace(/:/g, "\\:"); // obter ID do editor para o jQuery 422 var selector = src + " .cke_wysiwyg_frame" // selector jQuery para o editor normal 423 + ", " + src + " .cke_source"; // selector jQuery para o editor de código fonte 424 425 // Remover as tooltips 426 $(selector).each(function(index) { 427 $(this).attr("title", ""); 428 }); 429} 430 431/** 432 * Definir o URL de upload de imagens do CKEditor. 433 * @param {String} url O URL. 434 */ 435function setupCKEditorUploadUrl(url) { 436 window.CKEDITOR.config.filebrowserImageUploadUrl = url; 437} 438
439/** 440 * Move a caixa de diálogo indicada para o fundo. 441 * <p>Se a caixa de diálogo não couber no ecrã é redimensionada, sendo o tamanho 442 * original atribuido a <code>dialog.data("originalHeight")</code>.</p> 443 * @param {object} dialog A caixa de diálogo. 444 */ 445function moveDialogToBottom(dialog) { 446 if(dialog.is(":visible")) { // verificar se a dialog está visÃvel 447 // Guardar a altura original da dialog caso ainda não tenha sido guardada 448 if(dialog.data("originalHeight") === undefined) { 449 dialog.data("originalHeight", dialog.height()); 450 } 451 452 // Determinar nova posição vertical e altura 453 var height = dialog.data("originalHeight"); 454 var top = $(window).height() - height; 455 if(top < 0) { 456 // Não cabe na janela -> redimensionar a dialog 457 top = 0; 458 height = $(window).height() - top; 459 } else { 460 // Cabe na janela 461 height = dialog.data("originalHeight"); 462 } 463 464 // Actualizar as propriedades do componente 465 dialog.css({top: top, height: height}); 466 } 467} 468 469/** 470 * Move a caixa de diálogo seleccionada pelo selector CSS indicado para o fundo. 471 * <p>Se a caixa de diálogo não couber no ecrã é redimensionada, sendo o tamanho 472 * original atribuido a <code>dialog.data("originalHeight")</code>.</p> 473 * @param {string} selector Selector CSS da caixa de diálogo. 474 */ 475function moveDialogBySelectorToBottom(selector) { 476 moveDialogToBottom($(selector)); 477} 478 479/** 480* Inicia o poll para manter a sessão viva. 481*/ 482function startKeepAlive() { 483 PF("keepAlivePoll").start(); 484 console.log("keepAlive iniciado"); 485} 486 487/** 488* Termina o poll que mantém a sessão viva. 489*/ 490function stopKeepAlive() { 491 PF("keepAlivePoll").stop(); 492 console.log("keepAlive terminado"); 493} 494 495/** 496* Activa a caixa de dialogo de confirmação para sair da página. 497*/ 498function enableConfirmPageClose() { 499 window.confirmPageClose = true; 500} 501 502/** 503* Desactiva a caixa de dialogo de confirmação para sair da página. 504*/ 505function disableConfirmPageClose() { 506 window.confirmPageClose = false; 507} 508 509/** 510 * Mostra a "loading bar" no topo da página. 511 */ 512function showTopLoadingBar() { 513 $("#topLoadingBar").show(); 514} 515 516/** 517 * Oculta a "loading bar" do topo da página. 518 */ 519function hideTopLoadingBar() { 520 $("#topLoadingBar").hide(); 521} 522 523 524$(window).load(function() { 525 // Mantém todas as caixas de diálogo que tenham a classe CSS "dialog-bottom" no 526 // fundo da janela do browser quando este é redimensionado, redimensionando 527 // as caixas de diálogo que não couberem na janela. 528 $(window).resize(function() { 529 $(".dialog-bottom").each(function(index) { 530 var dialog = $(this); 531 moveDialogToBottom($(this)); 532 }); 533 534 535 }); 536 537 // Adiciona uma caixa de diálogo de confirmação ao fechar a página 538 // (mostrada apenas se window.confirmPageClose === true 539 window.confirmPageClose = false; 540 $(window).on("beforeunload", function() { 541 if(window.confirmPageClose === true) { 542 return "Tem a certeza que pretende deixar a página? Podem existir ainda dados por gravar."; 543 } 544 }); 545}); 546 547/** 548 * Colocar a div em fullscreen 549 */ 550function setFullScreen() { 551 var tab = document.getElementById("tab-content"); 552 tab.classList.toggle("fullscreen"); 553 tab.height = window.innerHeight; 554 // alert(window.innerHeight); 555} 556 557/** 558 * FUTURE ATTENDANCE 559 */ 560 561//var loginMessage = document.getElementById('loginMessage'); 562// 563//window.addEventListener('resize', function () { 564// alert("Teste"); 565// var currentWidth = Math.min(window.innerWidth || Infinity, screen.width), 566// currentClass = currentWidth > 800 ? 'col-xs-6' : 'col-xs-12'; 567// element.classList.add('no-transition'); 568// if (currentWidth > 800) { 569// element.classList.add(currentClass); 570// element.classList.add('middle-align'); 571// } else { 572// element.classList.remove('middle-align'); 573// } 574// element.classList.remove('no-transition'); 575// 576//}); 577 578//var loginMessage = document.getElementById('loginMessage'); 579// 580//$(window).on("resize", function () { 581// console.log($(this).width()) 582// if ($(this).width() <= 800) { 583// $('loginMessage').removeClass('middle-align') 584// $('loginMessage').addClass('col-xs-12') 585// } else { 586// $('loginMessage').addClass('middle-align') 587// $('loginMessage').addClass('col-xs-12') 588// } 589//}).trigger('resize'); 590 591function removeWarning(x) { 592 $('label[for="' + x.id + '"]').removeClass("ui-state-error"); 593}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.