Advertisement
DrRandom

button create

Sep 1st, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* button classes */
  2.     class Simple {
  3.         constructor(nth,name,id,classname) {
  4.           this.NTH      = nth;
  5.           this.NAME     = name;
  6.           this.ID       = id;
  7.           this.CLASS    = classname;
  8.         }
  9.         assemble(){
  10.             var URL = "/UserBtn";
  11.             var Param = "nth=" + this.NTH;
  12.             var $Col_for_Btns = $("<div>", { class: "col s2" });
  13.             var $Click_for_Btns = $("<a>", { id: this.ID, name: this.NAME, class: "waves-effect waves-light btn", onclick: 'httpGetAsync(\'' + URL + '\', Callback, \'' + Param + '\' );' });
  14.             var $Icon_for_Btns = $("<i>", { class: "material-icons", text: "wb_incandescent" });
  15.             $($Click_for_Btns).append($Icon_for_Btns);
  16.             $($Col_for_Btns).append($Click_for_Btns);
  17.             SimpIDS.push(this.NTH);
  18.             return $Col_for_Btns;
  19.         }
  20.       }
  21.  
  22.     class PWM{
  23.         constructor(nth,name,id,amper) {
  24.             this.NTH      = nth;
  25.             this.NAME     = name;
  26.             this.ID       = id;
  27.             this.AMPER    = amper;
  28.           }
  29.         assemble(){
  30.             var URL = "/UserBtnPWM";
  31.             var Param = "nth=" + this.NTH;
  32.             Param += "&percent=" + this.AMPER;
  33.             var $Col_for_Btns = $("<div>", { class: "col s2" });
  34.             var $Click_for_Btns = $("<a>", { id: this.ID, name: this.NAME, class: "waves-effect waves-light btn scale-transition", onclick: 'httpGetAsync(\'' + URL + '\', Callback, \'' + Param + '\' );' });
  35.             var $Icon_for_Btns = $("<i>", { class: "material-icons", text: "equalizer" });
  36.  
  37.             var pwmid = this.ID + "scaled";
  38.             var $PWMSlider = $("<div>", { style: "display:none", class: "PWMredonyslider scale-transition scale-out", name: this.NAME, id: pwmid, nth: this.NTH, maxamper: this.AMPER })
  39.  
  40.             $($Click_for_Btns).append($Icon_for_Btns);
  41.             $($Col_for_Btns).append($Click_for_Btns);
  42.             $($Col_for_Btns).append($PWMSlider);
  43.             PWMIDS.push(this.NTH);
  44.             LongPressIDs.push(this.ID);
  45.             return $Col_for_Btns;
  46.         }
  47.     }
  48.  
  49.     class SHUT{
  50.         constructor(nth,name,id,classname) {
  51.             this.NTH      = nth;
  52.             this.NAME     = name;
  53.             this.ID       = id;
  54.             this.CLASS    = classname;
  55.         }
  56.         assemble(){
  57.             var $RedonyHandler = $("<div>", { class: "redonyslider " + this.CLASS, name: this.NAME, idke: this.ID, nth:this.NTH });
  58.             ShutIDS.push(this.NTH);
  59.             return $RedonyHandler;
  60.         }
  61.     }
  62.  
  63.     class THERM{
  64.         constructor(nth,name,id,roomname) {
  65.             this.NTH      = nth;
  66.             this.NAME     = name;
  67.             this.ID       = id;
  68.             this.ROOM     = roomname;
  69.             this.col;
  70.         }
  71.         assemble(){
  72.             var $Col_for_Btns = $("<div>", { class: "col s2" });
  73.             var $Click_for_Btns = $("<a>", {
  74.                 id: this.ID, name: this.NAME, class: "waves-effect waves-light btn",
  75.                 onclick: 'ThermosModalOpen(\'' + this.ROOM + '\')'
  76.             });
  77.  
  78.             var $Icon_for_Btns = $("<i>", { class: "material-icons", text: "ac_unit" });
  79.             $($Click_for_Btns).append($Icon_for_Btns);
  80.             $($Col_for_Btns).append($Click_for_Btns);
  81.             ThermIDS.push(this.NTH);
  82.             this.col = $Col_for_Btns;
  83.             return $Col_for_Btns;
  84.         }
  85.         get Button(){
  86.             return this.col;
  87.         }
  88.     }
  89. /* button classes */
  90.  
  91. function Generate_Buttons(Data) {
  92.     console.log("Teljes Adat: ",Data);
  93.     for (var i = 0; i < Data.length; i++) {
  94.         var HasShutter = false;
  95.         var RedonyID = "";
  96.         var RoomName = Data[i].RoomName.replace(/\s+/g, '');
  97.         if (ExistingGroups.includes(RoomName)) {
  98.             var Indexi = ExistingGroups.indexOf(RoomName);
  99.             ExistingGroups.splice(Indexi, 1);
  100.             $("#WholeRoom" + RoomName).remove();
  101.         }
  102.         ExistingGroups.push(RoomName);
  103.         var $GroupLI = $("<li>", { id: "WholeRoom" + RoomName });
  104.         var $GroupHeader = $("<div>", { id: "GroupHead" + RoomName, class: "collapsible-header transparent teal-text text-darken-1" });
  105.         var $GroupHeaderIcon = $("<i>", { class: "material-icons left", text: Data[i].icon });
  106.         var $GroupBody = $("<div>", { class: "collapsible-body", id: "GBody" + RoomName });
  107.         var $BtnRow = $("<div>", { class: "row", });
  108.         var $BtnFirstCol = $("<div>", { id: "GroupID" + RoomName, class: "col s12" });
  109.         $($BtnRow).append($BtnFirstCol);
  110.         $($GroupHeader).append($GroupHeaderIcon);
  111.         $($GroupBody).append($BtnRow);
  112.  
  113.         $($GroupLI).append($GroupHeader);
  114.         $($GroupLI).append($GroupBody);
  115.         $("#homecontrols").prepend($GroupLI);
  116.         $("#GroupHead" + RoomName).append(Data[i].RoomName);
  117.  
  118.         if ("BTNS" in Data[i]) {
  119.             for (var k = 0; k < Data[i].BTNS.length; k++) {
  120.                 if (Data[i].BTNS[k].BTNID.includes("SIMP")) {
  121.                     SimpButton = new Simple(parseInt(Data[i].BTNS[k].NTH),Data[i].BTNS[k].BtnName,Data[i].BTNS[k].BTNID);
  122.                     //console.log(SimpButton.assemble());
  123.                     $("#GroupID" + RoomName).append(SimpButton.assemble());
  124.                 } else if (Data[i].BTNS[k].BTNID.includes("PWM")) {
  125.                     PWMButton = new PWM(Data[i].BTNS[k].NTH,Data[i].BTNS[k].BtnName,Data[i].BTNS[k].BTNID,Data[i].BTNS[k].MaxAmper);
  126.                     $("#GroupID" + RoomName).append(PWMButton.assemble());
  127.  
  128.                 } else if (Data[i].BTNS[k].BTNID.includes("SHUT")) {
  129.                     var ColorClass = "NotConfigured";
  130.                     if("PercentBefore" in Data[i].BTNS[k]){
  131.                         ColorClass = "Configured";
  132.                     }
  133.                     SHUTButton = new SHUT(Data[i].BTNS[k].NTH,Data[i].BTNS[k].BtnName,Data[i].BTNS[k].BTNID,ColorClass);
  134.                     if (!HasShutter) {
  135.                         HasShutter = true; RedonyID = "Redony" + RoomName;
  136.                         $("#GBody" + RoomName).append(MakeShutter(RedonyID));
  137.                     }
  138.                     $("#" + RedonyID).append(SHUTButton.assemble());
  139.                 } else if (Data[i].BTNS[k].BTNID.includes("THERM")) {
  140.                     THERMButton = new THERM(Data[i].BTNS[k].NTH,Data[i].BTNS[k].ThermBtnName,Data[i].BTNS[k].BTNID,RoomName);
  141.                     $("#GroupID" + RoomName).append(THERMButton.assemble());
  142.                 }
  143.             }
  144.         }
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement