1/** 2 * Funció JQuery que transforma tots el camps d'un formulari donat 3 * al format JSON. 4 * 5 * OJO: Activo (i desprès desactivo) els camps marcats com a 'disabled' perquè tb s'enviïn 6 * 7 */ 8(function($) { 9 $.fn.serializeFormJSON = function() { 10 var list_disabled = this.find(':disabled'); 11 list_disabled.prop('disabled', false); 12 13 var o = {}; 14 var a = this.serializeArray(); 15 16 $.each(a, function() { 17 if (o[this.name]) { 18 if (!o[this.name].push) { 19 o[this.name] = [o[this.name]]; 20 } 21 o[this.name].push(this.value || ''); 22 } else { 23 o[this.name] = this.value || ''; 24 } 25 }); 26 27 list_disabled.prop('disabled', true); 28 return o; 29 }; 30})(jQuery); 31 32 33 34function is_array(input) { 35 return(typeof(input)=='object'&&(input instanceof Array)); 36} 37 38 39 40 41/** 42 * Funció que força l'entrada de números en el INPUT 43 * 44 */ 45(function($) { 46 $.fn.forceNumbers = function() { 47 return this.each(function() 48 { 49 $(this).keydown(function(e) 50 { 51 var key = e.charCode || e.keyCode || 0; 52 // allow backspace, tab, delete, arrows, numbers, intros and keypad numbers ONLY 53 // home, end, period, and numpad decimal 54 return ( 55 key == 8 || 56 key == 9 || 57 key == 13 || 58 key == 46 || 59 key == 110 || 60 key == 190 || 61 (key >= 35 && key <= 40) || 62 (key >= 48 && key <= 57) || 63 (key >= 96 && key <= 105)); 64 }); 65 }); 66 }; 67})(jQuery); 68 69 70/** 71 * Donat el nom d'un formulari i una URL destÃ, recupera tots el camps i genera un JSON per 72 * fer una crida AJAX contra la URL. 73 * 74 * @param formulari Nom del formulari 75 * @param desti URL destà 76 * @returns {Integer} Si ha anant correctament 77 * 78 */ 79function enviaFormulariPerAJAX(formulari, desti) { 80 var success = -1; 81 $(".loading-status-bar").empty().html('<img src="../images/icons/loading.gif">'); 82 83 $(formulari).find('.control-group').removeClass('error'); 84 $(formulari).find('.help-block').empty(); 85 86 $.ajax({ 87 type: "POST", 88 url: desti, 89 dataType: "json", 90 async: false, 91 data: $(formulari).serializeFormJSON(), 92 93 success: function(r) { 94 if (r.result != "ERROR") { 95 $(".loading-status-bar").empty().html('<img src="../images/icons/ok.gif">'); 96 } else { 97 $(".loading-status-bar").empty().html('<font color="red"><strong>' + r.message + '!</strong></font>'); 98 99 if (r.messageData != null) { 100 for(var i=0; i<r.messageData.length; i++) { 101 $("#cg_" + r.messageData[i].fieldName).addClass("error"); 102 $("#err_" + r.messageData[i].fieldName).empty().html(r.messageData[i].errorMessage); 103 } 104 } 105 } 106 success = r.errorCode; 107 }, 108 error: function() { 109 $(".loading-status-bar").empty().html('<font color="red"><strong>Error de comunicació!</strong></font>'); 110 } 111 }); 112 113 return(success); 114} 115 116 117/** 118 * Donat un formulari i un objecte retornar per JSON, busca en el formulari 119 * un camp anometat de la mateixa manera i li afegeix les dades 120 * 121 * @param formulari 122 * @param data 123 */ 124function messageData2Form(data, formulari) { 125 for(var memb in data) { 126 if (typeof(data[memb]) != "undefined") { 127 if (typeof(data[memb]) != "object") { 128 var ruta = "#" + formulari + " #"+ memb; 129 if ($(ruta) != null) { 130 131 // Canvi pels checkboxs 132 if (data[memb] == "on") $(ruta).attr('checked', true); 133 else $(ruta).val(data[memb]); 134 } 135 } else { 136 tractarCampComplexe(formulari,memb,data[memb]); 137 } 138 } 139 } 140} 141 142 143 144function activaCalendari(c) { 145 lang = $.cookie("optimalway-locale"); 146 147 if(lang === undefined || lang == null || lang == "") { 148 lang = "es_ES"; 149 } 150 151 lang = lang.slice(0, 2); 152 153 return $(c).datepicker({ 154 format: "dd/mm/yyyy", 155 weekStart: 1, 156 language: lang, 157 autoclose: true, 158 orientation: $(c).hasClass('datepicker-bottom') ? 'bottom' : 'top', 159 }); 160} 161 162 163function activaCalendaris() { 164 $('.datepicker').each(function() { 165 activaCalendari(this); 166 }); 167} 168 169 170function formEditable(form, editable) { 171 if (!editable) { 172 var llista_inputs = form.find(':input'); 173 $(llista_inputs).prop("disabled", true); 174 } 175} 176 177 178function formResetErrors(form) { 179 $(form).find('.control-group').removeClass('error'); 180 $(form).find('.help-block').empty(); 181 $('.loading-status-bar').empty(); 182} 183 184 185function formReset(form) { 186 $(form).each (function() { 187 this.reset(); 188 }); 189} 190 191 192/** 193 * DEPRECATED 194 * :/ 195 * 196 */ 197 198function mapejarDataToPantallaResultats(formulari, data) { 199 for(var memb in data) { 200 if(typeof(data[memb]) != "undefined") { 201 if(typeof(data[memb]) != "object") { 202 var ruta = "#" + formulari + " #"+ memb; 203 if($(ruta)!=null){ 204 $(ruta).val(data[memb]); 205 } 206 }else{ 207 tractarCampComplexe(formulari,memb,data[memb]); 208 } 209 } 210 } 211} 212 213function tractarCampComplexe(formulari,prefix,data){ 214 for(var memb in data) { 215 if(typeof(data[memb]) != "undefined") { 216 var ruta = "#" + formulari + " #"+prefix+"_"+ memb; 217 if($(ruta)!=null){ 218 $(ruta).val(data[memb]); 219 }else{ 220 continue; 221 } 222 } 223 } 224} 225 226function escriureError(div,text){ 227 $(div).removeClass('alert alert-success'); 228 $(div).removeClass('alert'); 229 $(div).removeClass('alert alert-info'); 230 $(div).addClass('alert alert-error'); 231 var aux = div ; 232 $(aux).html(text); 233} 234 235 236function recuperarLiteralFromServer(div, literal){ 237 $.getJSON('./getTextResource.do?id_text=' + literal, function(data) { 238 if(data.result=="OK"){ 239 var aux = data.messageData; 240 $(div).html(aux); 241 } 242 }); 243}
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.