text: ﻿/*
  Impianti Operators Config Heating System Servomotor 
  ------------------------------------------*/
  $(function () {
  
      $(document).ready(function () {
          var $elementCode;
          $("#pageOperation").empty();
  
          Readhs();
          ReadVrd();
          loadAssignedProbes();
          //loadAvailableProbes();
          setlanguage();
  
          function Readhs() {
              var req = $.DataAccess.HeatingSystem_Read(localStorage.getItem("hsId"));
              req.success(function (json) {
                  var data = json.d;
                  if (data) {                   
                      $("#hsDescr").text(data.Descr);
                  }
              });
          }
  
  
          function ReadVrd() {
              var req = $.DataAccess.hs_Vrd_Read(localStorage.getItem("VrdId"));
              req.success(function (json) {
                  var data = json.d;
                  if (data) {
                      $elementCode = data.VrdCod;
                      $("#VrdDesc").text(data.VrdDesc);
                  }
              });
          }
  
          /*
          Probes for boiler
          -----------------------------------------------------------------*/
          function loadAssignedProbes() {
              $("#assignedList").empty();
              var req = $.DataAccess.hs_TemperatureProbeElem_List(localStorage.getItem("hsId"), $elementCode);
              req.success(function (json) {
                  var data = json.d;
                  if (data) {
                      $("#tmplassignedList").tmpl(data).appendTo("#assignedList");
                      $("#assignedList").niceScroll({
                          cursorcolor: "#1FB5AD",
                          cursorborder: "0px solid #fff",
                          cursorborderradius: "0px",
                          cursorwidth: "3px"
                      });
                      loadAvailableProbes();
                  }
                  else {
                      loadAvailableProbes();
                  }
  
              });
          }
  
          function loadAvailableProbes() {
              $("#availableList").empty();
              var req = $.DataAccess.hs_TemperatureProbes_List(localStorage.getItem("hsId"));
              req.success(function (json) {
                  var data = json.d;
                  if (data) {
                      $("#tmplavailableList").tmpl(data).appendTo("#availableList");
                      $("#availableList").niceScroll({
                          cursorcolor: "#1FB5AD",
                          cursorborder: "0px solid #fff",
                          cursorborderradius: "0px",
                          cursorwidth: "3px"
                      });
  
                      $("#assignedList li").each(function () {
                          var assigned = $(this).text().trim();
                          $("#availableList li").each(function () {
                              if ($(this).text().search(new RegExp(assigned, "i")) < 0) {
                                  console.log('trovato : ' + assigned);
                                  //$(this).fadeOut();
                              } else {
                                  //$(this).show();
                                  $(this).fadeOut();
                              }
                          });
                      });
  
                  }
              });
          }
  
          $.fnseleAvailProbe = function (ProbeCod) {
              var req = $.DataAccess.hs_TemperatureProbeElem_Add(localStorage.getItem("hsId"), $elementCode, ProbeCod);
              req.success(function (json) {
                  loadAssignedProbes();
                  //loadAvailableProbes();
              });
          }
  
          $.selassignedProbe = function (id) {
              var req = $.DataAccess.hs_TemperatureProbeElem_Del(id);
              req.success(function (json) {
                  loadAssignedProbes();
                  //loadAvailableProbes();
              });
          }
          /*---------------------------------------------------------------*/
  
      }); //document ready
  
  });
  
  function seleAvailProbe(ProbeCod) {
      $.fnseleAvailProbe(ProbeCod);
  }
  function selassignedProbe(id) {
      $.selassignedProbe(id);
  }