Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function lect_load()
- {
- // build batisse select
- for (var i in batisses)
- {
- var batisse = batisses[i];
- // Vérifi si la batisse a des compteurs
- var bFound = 0;
- for (var j in compteurs)
- {
- var compteur = compteurs[j];
- if (batisse.batcode == compteur.BATCODE)
- bFound = 1;
- }
- if (bFound == 0)
- continue;
- var oBat = $('<option value="' + batisse.batcode + '">' + batisse.projname + '</option>');
- $("#filter_batcode").append(oBat);
- }
- $("#filter_batcode").change(function() { lect_change_batisse() });
- }
- function lect_change_batisse()
- {
- $("#filter_idclient").attr('disabled', 'disabled');
- var BATCODE = $("#filter_batcode option:selected").val();
- if (BATCODE == "0")
- {
- $("#no_batisse").css('display', '');
- $("#lectures").css('display', 'none');
- return;
- }
- $("#filter_idclient").attr('disabled', '');
- $("#filter_idclient").removeOption(/./);
- $("#filter_idclient").addOption("null", "*** tous les compteurs");
- for (var i in compteurs)
- {
- var compteur = compteurs[i];
- if (compteur.BATCODE == BATCODE)
- $("#filter_idclient").addOption(compteur.ID_COMPTEUR, compteur.NUMERO_COMPTEUR);
- }
- $("#filter_idclient").selectOptions("null");
- }
- function buildAjout()
- {
- var BATCODE = $("#filter_batcode option:selected").val();
- if (BATCODE == "0")
- {
- pt_alert('Vous devez sélectionner une batisse.');
- return;
- }
- $("#no_batisse").css('display', 'none');
- $("#lectures").html("");
- $("#lectures").css('display', '');
- var ID_COMPTEUR = $("#filter_idclient option:selected").val();
- if (ID_COMPTEUR == "null")
- {
- // tous les compteurs
- for (var i in compteurs)
- {
- var compteur = compteurs[i];
- if (compteur.BATCODE != BATCODE)
- continue;
- switch (compteur.ID_TYPE_ENERGIE)
- {
- case "1": // Électricité
- buildElectric($("#lectures"), compteur);
- break;
- case "2": // Gaz
- buildGaz($("#lectures"), compteur);
- break;
- case "3": // Mazout
- case "4": // Huile
- buildHuileMazout($("#lectures"), compteur);
- break;
- }
- }
- }
- else
- {
- // ben juste un
- for (var i in compteurs)
- {
- var compteur = compteurs[i];
- if (compteur.ID_COMPTEUR == ID_COMPTEUR)
- break;
- }
- switch (compteur.ID_TYPE_ENERGIE)
- {
- case "1": // Électricité
- buildElectric($("#lectures"), compteur);
- break;
- case "2": // Gaz
- buildGaz($("#lectures"), compteur);
- break;
- case "3": // Mazout
- case "4": // Huile
- buildHuileMazout($("#lectures"), compteur);
- break;
- }
- }
- // CSS
- $("#lectures").find("input").css('width', '98%');
- // Refocus
- $("#lectures > table > tbody > tr:first > td:nth-child(2) > input").focus();
- }
- function buildElectric(oContainer, compteur)
- {
- if ($(oContainer).is("tbody") == false)
- {
- var oTable = $("<table style='width: 100%;'></table>");
- // Header
- var oHeader = $("<thead></thead>");
- var oLigne = $("<tr></tr>");
- var oCell = $("<th>Numéro</th>");
- $(oLigne).append(oCell);
- var oCell = $("<th>kWh</th>");
- $(oLigne).append(oCell);
- if (compteur.ID_TYPE_COMPTEUR == 2)
- {
- var oCell = $("<th>Wmax</th>");
- $(oLigne).append(oCell);
- var oCell = $("<th>VAmax</th>");
- $(oLigne).append(oCell);
- var oCell = $("<th>Wcum</th>");
- $(oLigne).append(oCell);
- var oCell = $("<th>VAcum</th>");
- $(oLigne).append(oCell);
- }
- var oCell = $("<th style='width: 100px;'>Status</th>");
- $(oLigne).append(oCell);
- $(oHeader).append(oLigne);
- $(oTable).append(oHeader);
- // Data
- var oBody = $("<tbody></tbody>");
- }
- else
- oBody = $(oContainer);
- var oLigne = $("<tr id='" + pt_uniqid() + "'></tr>");
- var oCell = $("<td><input type='hidden' name='ID_COMPTEUR' value='" + compteur.ID_COMPTEUR + "'><input type='text' readonly='readonly' name='NUMERO_COMPTEUR' value='" + compteur.NUMERO_COMPTEUR + "'></td>");
- $(oLigne).append(oCell);
- var oCellkWh = $("<td><input type='text' name='kWh' value=''></td>");
- $(oLigne).append(oCellkWh);
- if (compteur.ID_TYPE_COMPTEUR == 2)
- {
- var oCell = $("<td><input type='text' name='Wmax' value=''></td>");
- $(oLigne).append(oCell);
- var oCell = $("<td><input type='text' name='VAmax' value=''></td>");
- $(oLigne).append(oCell);
- var oCell = $("<td><input type='text' name='Wcum' value=''></td>");
- $(oLigne).append(oCell);
- var oCell = $("<td><input type='text' name='VAcum' value=''></td>");
- $(oLigne).append(oCell);
- }
- var oCell = $("<td>en attente...</td>");
- $(oLigne).append(oCell);
- $(oBody).append(oLigne);
- if ($(oContainer).is("tbody") == false)
- {
- $(oTable).append(oBody);
- $(oContainer).append(oTable);
- }
- // onBlur
- $(oLigne).find("input").blur(function() { onBlurLecture(oLigne); });
- }
- function buildGaz(oContainer, compteur)
- {
- var oTable = $("<table style='width: 100%;'></table>");
- // Header
- var oHeader = $("<thead></thead>");
- var oLigne = $("<tr></tr>");
- var oCell = $("<th>Numéro</th>");
- $(oLigne).append(oCell);
- var oCell = $("<th>mètre cube (m3)</th>");
- $(oLigne).append(oCell);
- var oCell = $("<th style='width: 100px;'>Status</th>");
- $(oLigne).append(oCell);
- $(oHeader).append(oLigne);
- $(oTable).append(oHeader);
- // Data
- var oBody = $("<tbody></tbody>");
- var oLigne = $("<tr id='" + pt_uniqid() + "'></tr>");
- var oCell = $("<td><input type='hidden' name='ID_COMPTEUR' value='" + compteur.ID_COMPTEUR + "'><input type='text' readonly='readonly' name='NUMERO_COMPTEUR' value='" + compteur.NUMERO_COMPTEUR + "'></td>");
- $(oLigne).append(oCell);
- var oCellVol = $("<td><input type='text' name='VOLUME' value=''></td>");
- $(oLigne).append(oCellVol);
- var oCell = $("<td>en attente...</td>");
- $(oLigne).append(oCell);
- $(oBody).append(oLigne);
- $(oTable).append(oBody);
- $(oContainer).append(oTable);
- // onBlur
- $(oLigne).find("input").blur(function() { onBlurLecture(oLigne); });
- }
- function buildHuileMazout(oContainer, compteur)
- {
- var oTable = $("<table style='width: 100%;'></table>");
- // Header
- var oHeader = $("<thead></thead>");
- var oLigne = $("<tr></tr>");
- var oCell = $("<th>Numéro</th>");
- $(oLigne).append(oCell);
- var oCell = $("<th>litre</th>");
- $(oLigne).append(oCell);
- var oCell = $("<th style='width: 100px;'>Status</th>");
- $(oLigne).append(oCell);
- $(oHeader).append(oLigne);
- $(oTable).append(oHeader);
- // Data
- var oBody = $("<tbody></tbody>");
- var oLigne = $("<tr id='" + pt_uniqid() + "'></tr>");
- var oCell = $("<td><input type='hidden' name='ID_COMPTEUR' value='" + compteur.ID_COMPTEUR + "'><input type='text' readonly='readonly' name='NUMERO_COMPTEUR' value='" + compteur.NUMERO_COMPTEUR + "'></td>");
- $(oLigne).append(oCell);
- var oCellVol = $("<td><input type='text' name='VOLUME' value=''></td>");
- $(oLigne).append(oCellVol);
- var oCell = $("<td>en attente...</td>");
- $(oLigne).append(oCell);
- $(oBody).append(oLigne);
- $(oTable).append(oBody);
- $(oContainer).append(oTable);
- // onBlur
- $(oLigne).find("input").blur(function() { onBlurLecture(oLigne); });
- }
- function onBlurLecture(tr_parent)
- {
- var iNbFields = 0;
- var iNbFieldsFull = 0;
- var oData = [];
- oData.AJAX_ID = $(tr_parent).attr('id');
- $(tr_parent).find('input').each(function()
- {
- iNbFields++;
- var sVal = $(this).val();
- if (sVal.length)
- iNbFieldsFull++;
- eval ("oData." + $(this).attr('name') + " = '" + sVal + "';");
- });
- if (iNbFields == iNbFieldsFull)
- {
- // tous les champs sont remplis! on save!
- SendCommand('compteurs', 'lecture_add', oData);
- }
- }
- function callback_compteurs_lecture_add(AJAX_ID)
- {
- // Met à jour la ligne
- $("#" + AJAX_ID).find("td:last").html('enregistré');
- // rajoute une ligne
- var ID_COMPTEUR = $("#" + AJAX_ID).find("input:first").val();
- for (var i in compteurs)
- {
- var compteur = compteurs[i];
- if (compteur.ID_COMPTEUR == ID_COMPTEUR)
- break;
- }
- switch (compteur.ID_TYPE_ENERGIE)
- {
- case "1": // Électricité
- buildElectric($("#" + AJAX_ID).parent(), compteur);
- //$("#lectures").find('tr:last > td:nth-child(2) > input').focus();
- //$("#" + AJAX_ID).closest('tbody').find('tr:last > td:nth-child(2) > input').focus();
- $("table").parent().find('tr:last > td:nth-child(2) > input').focus();
- //buildElectric($("#lectures > table > tbody"), compteur);
- //$("#lectures > table > tbody > tr:first > td:nth-child(2) > input").focus();
- //$("#lectures > table > tbody").find('tr:last > td').eq(1).find('input').focus();
- //$("#lectures > table > tbody").find('tr:last > td').eq(1).find('input').css('background-color', 'red');
- break;
- case "2": // Gaz
- buildGaz($("#" + AJAX_ID).parent(), compteur);
- break;
- case "3": // Mazout
- case "4": // Huile
- buildHuileMazout($("#" + AJAX_ID ).parent(), compteur);
- break;
- }
- // CSS
- $("#lectures").find("input").css('width', '98%');
- // Refocus (works in firecox only :S)
- //$("#" + AJAX_ID).parent().find('tr:last > td:nth-child(2) > input').focus();
- //$("#lectures > table > tbody").find("tr:last").find("input[type=text]:last").focus();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement