Advertisement
Guest User

Untitled

a guest
May 4th, 2010
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function lect_load()
  2. {
  3.     // build batisse select
  4.     for (var i in batisses)
  5.     {
  6.         var batisse = batisses[i];
  7.        
  8.         // Vérifi si la batisse a des compteurs
  9.         var bFound = 0;
  10.         for (var j in compteurs)
  11.         {
  12.             var compteur = compteurs[j];
  13.             if (batisse.batcode == compteur.BATCODE)
  14.                 bFound = 1;
  15.         }
  16.        
  17.         if (bFound == 0)
  18.             continue;
  19.        
  20.         var oBat = $('<option value="' + batisse.batcode + '">' + batisse.projname + '</option>');
  21.         $("#filter_batcode").append(oBat);
  22.     }
  23.    
  24.     $("#filter_batcode").change(function() { lect_change_batisse() });
  25. }
  26. function lect_change_batisse()
  27. {
  28.     $("#filter_idclient").attr('disabled', 'disabled');
  29.     var BATCODE = $("#filter_batcode option:selected").val();
  30.     if (BATCODE == "0")
  31.     {
  32.         $("#no_batisse").css('display', '');
  33.         $("#lectures").css('display', 'none');
  34.         return;
  35.     }
  36.     $("#filter_idclient").attr('disabled', '');
  37.     $("#filter_idclient").removeOption(/./);
  38.     $("#filter_idclient").addOption("null", "*** tous les compteurs");
  39.     for (var i in compteurs)
  40.     {
  41.         var compteur = compteurs[i];
  42.         if (compteur.BATCODE == BATCODE)
  43.             $("#filter_idclient").addOption(compteur.ID_COMPTEUR, compteur.NUMERO_COMPTEUR);
  44.     }
  45.     $("#filter_idclient").selectOptions("null");
  46. }
  47.  
  48. function buildAjout()
  49. {
  50.     var BATCODE = $("#filter_batcode option:selected").val();
  51.     if (BATCODE == "0")
  52.     {
  53.         pt_alert('Vous devez sélectionner une batisse.');
  54.         return;
  55.     }
  56.     $("#no_batisse").css('display', 'none');
  57.     $("#lectures").html("");
  58.     $("#lectures").css('display', '');
  59.    
  60.     var ID_COMPTEUR = $("#filter_idclient option:selected").val();
  61.     if (ID_COMPTEUR == "null")
  62.     {
  63.         // tous les compteurs
  64.         for (var i in compteurs)
  65.         {
  66.             var compteur = compteurs[i];
  67.             if (compteur.BATCODE != BATCODE)
  68.                 continue;
  69.            
  70.             switch (compteur.ID_TYPE_ENERGIE)
  71.             {
  72.                 case "1": // Électricité
  73.                     buildElectric($("#lectures"), compteur);
  74.                     break;
  75.                
  76.                 case "2": // Gaz
  77.                     buildGaz($("#lectures"), compteur);
  78.                     break;
  79.                
  80.                 case "3": // Mazout
  81.                 case "4": // Huile
  82.                     buildHuileMazout($("#lectures"), compteur);
  83.                     break;
  84.             }
  85.         }      
  86.     }
  87.     else
  88.     {
  89.         // ben juste un
  90.         for (var i in compteurs)
  91.         {
  92.             var compteur = compteurs[i];
  93.             if (compteur.ID_COMPTEUR == ID_COMPTEUR)
  94.                 break;
  95.         }
  96.        
  97.         switch (compteur.ID_TYPE_ENERGIE)
  98.         {
  99.             case "1": // Électricité
  100.                 buildElectric($("#lectures"), compteur);
  101.                 break;
  102.            
  103.             case "2": // Gaz
  104.                 buildGaz($("#lectures"), compteur);
  105.                 break;
  106.            
  107.             case "3": // Mazout
  108.             case "4": // Huile
  109.                 buildHuileMazout($("#lectures"), compteur);
  110.                 break;
  111.         }
  112.     }
  113.    
  114.     // CSS
  115.     $("#lectures").find("input").css('width', '98%');
  116.    
  117.     // Refocus
  118.     $("#lectures > table > tbody > tr:first > td:nth-child(2) > input").focus();
  119. }
  120.  
  121. function buildElectric(oContainer, compteur)
  122. {
  123.     if ($(oContainer).is("tbody") == false)
  124.     {
  125.         var oTable = $("<table style='width: 100%;'></table>");
  126.    
  127.         // Header
  128.         var oHeader = $("<thead></thead>");
  129.         var oLigne = $("<tr></tr>");
  130.    
  131.         var oCell = $("<th>Numéro</th>");
  132.         $(oLigne).append(oCell);
  133.        
  134.         var oCell = $("<th>kWh</th>");
  135.         $(oLigne).append(oCell);
  136.        
  137.         if (compteur.ID_TYPE_COMPTEUR == 2)
  138.         {
  139.             var oCell = $("<th>Wmax</th>");
  140.             $(oLigne).append(oCell);
  141.            
  142.             var oCell = $("<th>VAmax</th>");
  143.             $(oLigne).append(oCell);
  144.            
  145.             var oCell = $("<th>Wcum</th>");
  146.             $(oLigne).append(oCell);
  147.            
  148.             var oCell = $("<th>VAcum</th>");
  149.             $(oLigne).append(oCell);
  150.         }
  151.            
  152.         var oCell = $("<th style='width: 100px;'>Status</th>");
  153.         $(oLigne).append(oCell);
  154.        
  155.         $(oHeader).append(oLigne);
  156.         $(oTable).append(oHeader);
  157.        
  158.         // Data
  159.         var oBody = $("<tbody></tbody>");
  160.     }
  161.     else
  162.         oBody = $(oContainer);
  163.    
  164.     var oLigne = $("<tr id='" + pt_uniqid() + "'></tr>");
  165.    
  166.     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>");
  167.     $(oLigne).append(oCell);
  168.    
  169.     var oCellkWh = $("<td><input type='text' name='kWh' value=''></td>");
  170.     $(oLigne).append(oCellkWh);
  171.    
  172.     if (compteur.ID_TYPE_COMPTEUR == 2)
  173.     {
  174.         var oCell = $("<td><input type='text' name='Wmax' value=''></td>");
  175.         $(oLigne).append(oCell);
  176.        
  177.         var oCell = $("<td><input type='text' name='VAmax' value=''></td>");
  178.         $(oLigne).append(oCell);
  179.        
  180.         var oCell = $("<td><input type='text' name='Wcum' value=''></td>");
  181.         $(oLigne).append(oCell);
  182.        
  183.         var oCell = $("<td><input type='text' name='VAcum' value=''></td>");
  184.         $(oLigne).append(oCell);
  185.     }
  186.    
  187.     var oCell = $("<td>en attente...</td>");
  188.     $(oLigne).append(oCell);
  189.     $(oBody).append(oLigne);
  190.    
  191.     if ($(oContainer).is("tbody") == false)
  192.     {
  193.         $(oTable).append(oBody);
  194.         $(oContainer).append(oTable);  
  195.     }
  196.  
  197.     // onBlur
  198.     $(oLigne).find("input").blur(function() { onBlurLecture(oLigne); });
  199. }
  200.  
  201. function buildGaz(oContainer, compteur)
  202. {
  203.     var oTable = $("<table style='width: 100%;'></table>");
  204.    
  205.     // Header
  206.     var oHeader = $("<thead></thead>");
  207.     var oLigne = $("<tr></tr>");
  208.    
  209.     var oCell = $("<th>Numéro</th>");
  210.     $(oLigne).append(oCell);
  211.    
  212.     var oCell = $("<th>mètre cube (m3)</th>");
  213.     $(oLigne).append(oCell);
  214.    
  215.     var oCell = $("<th style='width: 100px;'>Status</th>");
  216.     $(oLigne).append(oCell);
  217.    
  218.     $(oHeader).append(oLigne);
  219.     $(oTable).append(oHeader);
  220.    
  221.     // Data
  222.     var oBody = $("<tbody></tbody>");
  223.     var oLigne = $("<tr id='" + pt_uniqid() + "'></tr>");
  224.        
  225.     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>");
  226.     $(oLigne).append(oCell);
  227.    
  228.     var oCellVol = $("<td><input type='text' name='VOLUME' value=''></td>");
  229.     $(oLigne).append(oCellVol);
  230.    
  231.     var oCell = $("<td>en attente...</td>");
  232.     $(oLigne).append(oCell);
  233.    
  234.     $(oBody).append(oLigne);
  235.     $(oTable).append(oBody);
  236.     $(oContainer).append(oTable);
  237.    
  238.     // onBlur
  239.     $(oLigne).find("input").blur(function() { onBlurLecture(oLigne); });
  240. }
  241.  
  242. function buildHuileMazout(oContainer, compteur)
  243. {
  244.     var oTable = $("<table style='width: 100%;'></table>");
  245.    
  246.     // Header
  247.     var oHeader = $("<thead></thead>");
  248.     var oLigne = $("<tr></tr>");
  249.    
  250.     var oCell = $("<th>Numéro</th>");
  251.     $(oLigne).append(oCell);
  252.    
  253.     var oCell = $("<th>litre</th>");
  254.     $(oLigne).append(oCell);
  255.    
  256.     var oCell = $("<th style='width: 100px;'>Status</th>");
  257.     $(oLigne).append(oCell);
  258.    
  259.     $(oHeader).append(oLigne);
  260.     $(oTable).append(oHeader);
  261.    
  262.     // Data
  263.     var oBody = $("<tbody></tbody>");
  264.     var oLigne = $("<tr id='" + pt_uniqid() + "'></tr>");
  265.    
  266.     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>");
  267.     $(oLigne).append(oCell);
  268.    
  269.     var oCellVol = $("<td><input type='text' name='VOLUME' value=''></td>");
  270.     $(oLigne).append(oCellVol);
  271.    
  272.     var oCell = $("<td>en attente...</td>");
  273.     $(oLigne).append(oCell);
  274.    
  275.     $(oBody).append(oLigne);
  276.     $(oTable).append(oBody);
  277.     $(oContainer).append(oTable);
  278.  
  279.     // onBlur
  280.     $(oLigne).find("input").blur(function() { onBlurLecture(oLigne); });
  281. }
  282.  
  283. function onBlurLecture(tr_parent)
  284. {
  285.     var iNbFields = 0;
  286.     var iNbFieldsFull = 0;
  287.    
  288.     var oData = [];
  289.     oData.AJAX_ID = $(tr_parent).attr('id');
  290.     $(tr_parent).find('input').each(function()
  291.     {
  292.         iNbFields++;
  293.         var sVal = $(this).val();
  294.         if (sVal.length)
  295.             iNbFieldsFull++;
  296.            
  297.         eval ("oData." + $(this).attr('name') + " = '" + sVal + "';");
  298.     });
  299.  
  300.     if (iNbFields == iNbFieldsFull)
  301.     {
  302.         // tous les champs sont remplis! on save!
  303.         SendCommand('compteurs', 'lecture_add', oData);
  304.     }
  305. }
  306.  
  307. function callback_compteurs_lecture_add(AJAX_ID)
  308. {
  309.     // Met à jour la ligne
  310.     $("#" + AJAX_ID).find("td:last").html('enregistré');
  311.    
  312.     // rajoute une ligne
  313.     var ID_COMPTEUR = $("#" + AJAX_ID).find("input:first").val();
  314.     for (var i in compteurs)
  315.     {
  316.         var compteur = compteurs[i];
  317.         if (compteur.ID_COMPTEUR == ID_COMPTEUR)
  318.             break;
  319.     }
  320.    
  321.     switch (compteur.ID_TYPE_ENERGIE)
  322.     {
  323.         case "1": // Électricité
  324.             buildElectric($("#" + AJAX_ID).parent(), compteur);
  325.             //$("#lectures").find('tr:last > td:nth-child(2) > input').focus();
  326.             //$("#" + AJAX_ID).closest('tbody').find('tr:last > td:nth-child(2) > input').focus();
  327.             $("table").parent().find('tr:last > td:nth-child(2) > input').focus();
  328.             //buildElectric($("#lectures > table > tbody"), compteur);
  329.            
  330.             //$("#lectures > table > tbody > tr:first > td:nth-child(2) > input").focus();
  331.            
  332.             //$("#lectures > table > tbody").find('tr:last > td').eq(1).find('input').focus();
  333.             //$("#lectures > table > tbody").find('tr:last > td').eq(1).find('input').css('background-color', 'red');
  334.             break;
  335.        
  336.         case "2": // Gaz
  337.             buildGaz($("#" + AJAX_ID).parent(), compteur);
  338.             break;
  339.        
  340.         case "3": // Mazout
  341.         case "4": // Huile
  342.             buildHuileMazout($("#" + AJAX_ID ).parent(), compteur);
  343.             break;
  344.     }
  345.    
  346.     // CSS
  347.     $("#lectures").find("input").css('width', '98%');
  348.    
  349.     // Refocus (works in firecox only :S)
  350.    
  351.     //$("#" + AJAX_ID).parent().find('tr:last > td:nth-child(2) > input').focus();
  352.     //$("#lectures > table > tbody").find("tr:last").find("input[type=text]:last").focus();
  353. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement