Jquery Funciones
Jquery Funciones
which <= 57 )) { 6 event.preventDefault(); 7 } 8 }); 9 }, 10 //permitir solo minusculas 11 minusculas : function(nombreInput) { 12 $('#' + nombreInput).keypress(function(event) { 13 if(event.which && (event.which < 97 || event.which > 122) || (event.which < 65 || event.which > 90 )) { 14 event.preventDefault(); 15 } 16 }); 17 }, 18 // permitir solo mayusculas 19 mayusculas : function(nombreInput) { 20 $('#' + nombreInput).keypress(function(event) { 21 if(event.which && (event.which < 65 || event.which > 90 )) { 22 event.preventDefault(); 23 } 24 }); 25 }, 26 //campanha 27 getCampanha : function(nombreInput) { 28 var date = new Date(); 29 var mes = date.getMonth(); 30 var campanas = $("#" + nombreInput); 31 if(mes >= 1 && mes <= 6) 32 var campana = 'invierno'; 33 else 34 var campana = 'verano'; 35 var ano = date.getFullYear().toString(); 36 campanas.attr('value', campana + '/' + ano); 37 }, 38 //generar password 39 generarPass : function(nombreObj) { 40 var newPass = ''; 41 $.ajax({ 42 url : 'control/login/login.ctrl.php?page=generar', 43 type : 'POST', 44 success : function(response) { 45 $("#" + nombreObj).val(response); 46 } 47 }) 48 }, 49 //cargar formulario solicitado en home.php 50 ajaxLoad : function(model, opcion, pagina) { 51 if(pagina == 'index2') { 52 $.ajax({ 53 url : 'control/' + model + '/' + model + '.ctrl.php?page=' + opcion, 54 type : 'POST', 55 async : true, Page 1
jquery.funciones.js 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 success : function(response) { var msj = '<h3>Cargando el formulario</h3>' $.blockUI({ theme : true, title : 'Sistema CERFIS', message : '<img src="images/loader_1.gif" /> ' + msj, timeout : 500 }); location.href = response; } }); } else { $.ajax({ url : 'control/' + model + '/' + model + '.ctrl.php?page=' + opcion, type : 'POST', async : true, success : function(response) { var msj = '<h3>Cargando el formulario</h3>' $.blockUI({ message : '<img src="images/loader_1.gif" /> ' + msj, timeout : 1000 }); $('.post').slideDown(1000).load(response); } }); $("#view2").ajaxForm({ target : ".post", url : 'control/usuario/usuario.ctrl.php', type : 'post', data : { page : 'vsemilla' } }); } }, /** * formatea el numero a la forma xxx,xxx,xxx.xx * */ modificar_decimales : function(input) { $('#' + input).blur(function() { numero = $(this).val(); var posDot = numero.length - numero.lastIndexOf('.'); var size = numero.length; var difSize = size - posDot; var miles = numero.substring(0, difSize); var decimales = numero.substring(difSize + 1, posDot); if(miles.indexOf(',') < -1) var aux1 = miles.split(','); var aux2; var tamanho = aux.length; for(var i = 0; i <= tamanho - 1; i++) { aux2 += aux1[i] + ','; } aux2 += aux1[tamanho]; Page 2
jquery.funciones.js 112 113 114 115 116 117 118 119 120 121 aux2 += '.' + decimales; $('#' + input).empty().val(aux2);
}); }, /** * destino id del select donde seran cargados los datos * model nombre del controlador * opcion opcion q es solicitada */ cargarSelect : function(destino, model, opcion, opcion2, opcion3, nombre, apellido, cultivo) { 122 $('#' + destino).removeAttr('disabled'); 123 var url = 'includes/' + model + '.php'; 124 var datos = { 125 page : opcion, 126 semillera : opcion2, 127 opt : opcion3, 128 nombre : nombre, 129 apellido : apellido, 130 cultivo : cultivo 131 }; 132 $.getJSON(url, datos, function(json) { 133 if(json.length > 0 ) { 134 $('#' + destino).empty(); 135 if(opcion == 'campoLab') { 136 $('#' + destino).empty().append('<option value="">-Seleccione numero de campo-</option>'); 137 } else { 138 $('#' + destino).empty().append('<option value="">-Selecione ' + opcion + '-</option>'); 139 } 140 if(opcion == 'categoria') { 141 $.each(json, function(index, value) { 142 $('#' + destino).append('<option value="' + index + '">' + value + '</option>'); 143 }); 144 } else { 145 146 $.each(json, function(index, value) { 147 if(value != 'no existen datos') 148 $('#' + destino).append('<option value="' + value + '">' + value + '</option>'); 149 }); 150 } 151 } else { 152 $('#' + destino).empty().append('<option value="">-No existen datos-</option>').attr('disabled', 'disabled'); 153 } 154 155 }); 156 }, 157 /** 158 * carga resultados en un input en el form cuenta 159 * input1 superficie 160 * input2 categoria campo 161 * input3 id superficie Page 3
jquery.funciones.js 162 163 164 165 166 167 168 * semillera * nombre * apellido * cultivo * nroCampo */ datosCosecha : function(input1, input2, input3, semillera, nombre, apellido, cultivo, nroCampo) { 169 var url = 'includes/operaciones.php'; 170 var datos = { 171 page : 'datosCosecha', 172 semillera : semillera, 173 nombre : nombre, 174 apellido : apellido, 175 cultivo : cultivo, 176 nro_campo : nroCampo 177 }; 178 $.getJSON(url, datos, function(json) { 179 var superficie = json.superficie; 180 var categCampo = json.categCampo; 181 var superficieID = json.isuperficie; 182 $('#' + input1).val(superficie); 183 $('#' + input2).val(categCampo); 184 $('#' + input3).val(superficieID); 185 }); 186 }, 187 datosSemillaP : function(input1, input2, campo) { 188 var url = 'includes/operaciones.php'; 189 var datos = { 190 page : 'semillap', 191 campo : campo 192 }; 193 $.getJSON(url, datos, function(json) { 194 var laboratorio = json.laboratorio; 195 var cosecha = json.cosecha; 196 $('#' + input1).val(cosecha); 197 $('#' + input2).val(laboratorio); 198 }); 199 }, 200 cargarInput : function(in1, in2, in3, in4, in5, in6, in7, in8, in9, opcion, nombre_, apellido_, campanha, cultivo_, variedad_) { 201 var url = 'includes/operaciones.php'; 202 if(opcion == 'resumenCta') { 203 204 // esto es para cuenta 205 var datos = { 206 page : opcion, 207 nombre : nombre_, 208 apellido : apellido_, 209 campania : campanha, 210 cultivo : cultivo_, 211 variedad : variedad_ 212 }; 213 $.getJSON(url, datos, function(json) { 214 var cAprobada = json.catAprobada; 215 var sAprobada = json.supAprobada; Page 4
jquery.funciones.js 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 var var var var var var var sTotal = json.supTotal; bolsa = json.bolsa; inscripcion = json.inscripcion; icampo = json.inspeccion; analabet = json.anlet; acondicionamiento = json.acondicionamiento plantines = json.plantines;
$('#' + in1).val(cAprobada); $('#' + in2).val(sAprobada); $('#' + in3).val(sTotal); $('#' + in4).val(bolsa); $('#' + in5).val(inscripcion); $('#' + in6).val(icampo); $('#' + in7).val(analabet); $('#' + in8).val(acondicionamiento); $('#' + in9).val(plantines); $('#total1').val(bolsa);
var inscripcion_ = $('#' + in5).val(); var inspeccion_ = $('#' + in6).val(); var acondicionamiento_ = $('#' + in8).val(); var costos = $('#' + in7).val(); var bolsaEtiqueta = $('#bolsa').val(); if(!isNaN(bolsaEtiqueta)) var total = 1 * costos; var sbtotal2 = parseFloat(inscripcion_) + parseFloat(inspeccion_) + parseFloat(acondicionamiento_) + parseFloat(total); 243 //+parseFloat(plantines); 244 $('#total2').val(sbtotal2); 245 $('#anlet').val(total); 246 $('#montoPagado').keyup(function() { 247 var monto = parseFloat($(this).val()); 248 var sbtotal = parseFloat($('#total2').val()); 249 if(monto <= sbtotal) { 250 var saldo = parseFloat(sbtotal) - monto; 251 $('#saldo').val(saldo); 252 } 253 }); 254 /*var urlA = 'includes/operaciones.php?page=sup_aprobada'; 255 var url = '&campania=' + campanha + '&variedad=' + variedad_ + '&cultivo=' + cultivo_; 256 url += '&nombre=' + nombre_ + '&apellido=' + apellido_; 257 url += '&catAprobada=' + cAprobada; 258 $.getJSON(urlA + url, function(data) { 259 $('#superficie').val(data.aprobada); 260 })*/ 261 urlA = ''; 262 urlA = 'includes/operaciones.php?page=sup_total'; 263 $.getJSON(urlA, function(data) { 264 $('#superficietot').val(data.total); 265 }); 266 return false; 267 }); 268 } else { 269 var datos = { Page 5
jquery.funciones.js 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 page : opcion, nroCampo : in2 }; $.getJSON(url, datos, function(json) { $('#' + in1).val(json) }); } }, /** * Agrega * si tiene espacio para ser enviada * semillera nombre de la semillera */ prepararSemillera : function(semillera) { var palabras = semillera.split(" "); semillera = ''; semillera = palabras.join("*");
return semillera; }, // carga las semilleras de acuerdo a la etapa en al que se encuentran cargarSemilleras : function(tabla) { $("#semillera").append('<option value=""> Cargando...</option>'); var productor = $('#productor'); var solicitud = $('input[name=solicitud]'); $.getJSON('includes/operaciones.php', { page : 'semillera', opt : 'all', tbl : tabla }, function(json) { if(json.length > 0) { $('#semillera').empty().append('<option value="">[ Seleccione semillera ]</option>'); 302 $.each(json, function(index, value) { 303 $('#semillera').append('<option value="' + value + '">' + value + '</option>'); 304 }); 305 } else { 306 $("#semillera").empty().append('<option value="">No existen semilleras</option>').attr('disabled', 'disabled'); 307 } 308 }); 309 }, 310 //semilleras q tienen como cultivo papa 311 cargarSemillerasPapa : function() { 312 $.getJSON('includes/operaciones.php', { 313 page : 'semillera', 314 opt : 'superficie' 315 }, function(data) { 316 if(data != '') { 317 $('#semillera').append('<option value=>---------------------</option>'); 318 $.each(data, function(index, value) { 319 $('#semillera').append('<option value="' + value + '">' + value + '</option>'); 320 }) Page 6
jquery.funciones.js 321 322 323 324 325 326 327 328 329 330 331 332 } });
}, // productores q tienen papa cargarProductoresPapa : function(semillera) { $.getJSON('includes/operaciones.php', { page : 'productor_papa', semillera : semillera, tipo : 1 }, function(data) { if(data.length > 0) { $("#productor").empty().append('<option value="">Seleccione productor</option>'); 333 $.each(data, function(index, value) { 334 $('#productor').append('<option value="' + value + '">' + value + '</option>'); 335 }) 336 }; 337 }); 338 }, 339 340 //cargar campaas 341 cargarCampanhas : function() { 342 $('#campanha').append('<option value="">Cargando...</option>'); 343 $.getJSON('control/busqueda/busqueda.ctrl.php', { 344 page : 'campanhas' 345 }, function(json) { 346 if(json.length > 0 && json.length) { 347 $("#campanha").empty().removeAttr('disabled').append('<option value="">[ Seleccione campaña ]</option>'); 348 $.each(json, function(index, value) { 349 $("#campanha").append('<option value="' + value + '">' + value + '</option>'); 350 }); 351 352 }else{ 353 $("#campanha").empty().append('<option value="">No existen campañas</option>'); 354 } 355 }); 356 }, 357 verificarLogin : function(nombre){ 358 var login = $("#"+nombre).val(); 359 if(login != '' && (login.length > 5)) { 360 $(this).removeAttr('style'); 361 $.getJSON('includes/operaciones.php', { 362 usuario : login, 363 page : 'comprobarLogin' 364 }, function(response) { 365 if(response != 'OK') { 366 367 $("#login").removeAttr('style').css({ 368 "color" : "#FFBDC2", 369 'font-style' : 'italic' 370 }); 371 $(".checked").empty().removeClass('libre').append('No Page 7
jquery.funciones.js disponible').addClass('ocupado'); $("#login").removeAttr('style').css({ "color" : "#FB7535", 'font-style' : 'italic' }); } else { $(".checked").empty().removeClass('ocupado').append('Disponibl e').addClass('libre'); 378 } 379 //$('<pre>ya esta en uso</pre>').css({'color':'red'}).appendTo("body"); 380 }); 381 } else { 382 $("#login").css({ 383 "background-color" : "#ff9c9c" 384 }); 385 $(".checked").empty().removeClass('libre').append('nombre de usuario inválido').addClass('ocupado'); 386 } 387 } 388 }; 389 372 373 374 375 376 377
Page 8