public string BuildScratchDeviceTab(int id) { StringBuilder sb = new StringBuilder(); SiidDevice Dev = SiidDevice.GetFromListByID(Instance.Devices, id); htmlBuilder ScratchBuilder = new htmlBuilder("Scratch" + Instance.ajaxName); sb.Append("<div><h2>ScratchPad Rules:<h2><hl>"); htmlTable ScratchTable = ScratchBuilder.htmlTable(); ScratchTable.addHead(new string[] { "Rule Name", "Value", "Enable Rule", "Is Accumulator", "Reset Type", "Reset Interval", "Rule String", "Fixed Cost", "Show Tiered Rates", "Rate ($ per unit)", "Real Time Data Rule String", "Rule Formatting", "HomeseerID" }); //0,1,2,3,4,5 int ID = Dev.Ref; List <string> Row = new List <string>(); var EDO = Dev.Extra; var parts = HttpUtility.ParseQueryString(EDO.GetNamed("SSIDKey").ToString()); Row.Add(ScratchBuilder.stringInput("Name_" + ID, Dev.Device.get_Name(Instance.host)).print()); Row.Add(parts["DisplayedValue"]); Row.Add(ScratchBuilder.checkBoxInput("IsEnabled_" + ID, bool.Parse(parts["IsEnabled"])).print()); Row.Add(ScratchBuilder.checkBoxInput("IsAccumulator_" + ID, bool.Parse(parts["IsAccumulator"])).print()); //Reset type is 0=periodically, 1=daily,2=weekly,3=monthly Row.Add(ScratchBuilder.selectorInput(ScratchpadDevice.ResetType, "ResetType_" + ID, "ResetType_" + ID, Convert.ToInt32(parts["ResetType"])).print()); //Based on what selector input, this next cell will be crowded with the different input possibilities where all but one have display none StringBuilder ComplexCell = new StringBuilder(); ComplexCell.Append("<div id=0_" + ID + " style=display:none>Interval in minutes: " + ScratchBuilder.numberInput("ResetInterval_" + ID + "_0", Convert.ToInt32(parts["ResetInterval"])).print() + "</div>"); ComplexCell.Append("<div id=1_" + ID + " style=display:none>" + ScratchBuilder.timeInput("ResetTime_" + ID + "_1", parts["ResetTime"]).print() + "</div>"); ComplexCell.Append("<div id=2_" + ID + " style=display:none>" + ScratchBuilder.selectorInput(GeneralHelperFunctions.DaysOfWeek, "DayOfWeek_" + ID + "_2", "DayOfWeek_" + ID + "_2", Convert.ToInt32(parts["DayOfWeek"])).print() + "</div>"); ComplexCell.Append("<div id=3_" + ID + " style=display:none>Day of the month: " + ScratchBuilder.numberInput("DayOfMonth_" + ID + "_3", Convert.ToInt32(parts["DayOfMonth"])).print() + "</div>"); ComplexCell.Append(@"<script> UpdateDisplay=function(id){ console.log('UPDATING DISPLAY '+id); $('#0_'+id)[0].style.display='none'; $('#1_'+id)[0].style.display='none'; $('#2_'+id)[0].style.display='none'; $('#3_'+id)[0].style.display='none'; V = $('#ResetType_'+id)[0].value; $('#'+V+'_'+id)[0].style.display=''; } DoChange=function(){ console.log('DoChange'); console.log(this); UpdateDisplay(this.id.split('_')[1]); } UpdateDisplay(" + ID + @"); $('#ResetType_" + ID + @"').change(DoChange); //OK HERE </script>"); Row.Add(ComplexCell.ToString()); Row.Add(ScratchBuilder.stringInput("ScratchPadString_" + ID, parts["ScratchPadString"].Replace("(^p^)", "+")).print()); if (parts["FixedCost"] == null) { parts["FixedCost"] = "0"; } Row.Add(ScratchBuilder.stringInput("FixedCost_" + ID, parts["FixedCost"].Replace("(^p^)", "+")).print()); if (parts["showTier"] == null) { parts["showTier"] = "False"; } Row.Add(ScratchBuilder.checkBoxInput("showTier_" + ID, bool.Parse(parts["showTier"])).print()); if (parts["RateTier1"] == null) { parts["RateTier1"] = "0"; } if (parts["RateTier2"] == null) { parts["RateTier2"] = "0"; } if (parts["RateTier3"] == null) { parts["RateTier3"] = "0"; } if (parts["RateTier4"] == null) { parts["RateTier4"] = "0"; } if (parts["AWCOrLot"] == null) { parts["AWCOrLot"] = "8000"; } if (parts["showTier"] == "True") { Row.Add("<div id='tiers" + ID + "' style='display:inline'>Tier 1:" + ScratchBuilder.stringInput("RateTier1_" + ID, parts["RateTier1"]).print() + " Tier 2:" + ScratchBuilder.stringInput("RateTier2_" + ID, parts["RateTier2"]).print() + " Tier 3:" + ScratchBuilder.stringInput("RateTier3_" + ID, parts["RateTier3"]).print() + " Tier 4:" + ScratchBuilder.stringInput("RateTier4_" + ID, parts["RateTier4"]).print() + " AWC or LotSize:" + ScratchBuilder.stringInput("AWCOrLot_" + ID, parts["AWCOrLot"]).print() + "</div>" + "<div id='rate" + ID + "' style='display:none'>" + ScratchBuilder.stringInput("RateValue_" + ID, parts["RateValue"]).print() + "</div>" + @"<script> UpdateTier=function(id){ IsChecked = $('#showTier_' + id)[0].checked; if(IsChecked){ $('#tiers'+id)[0].style.display='inline'; $('#rate'+id)[0].style.display='none'; } else{ $('#tiers'+id)[0].style.display='none'; $('#rate'+id)[0].style.display='inline'; } } TierChange=function(){ console.log('TierChange'); console.log(this); UpdateTier(this.id.split('_')[1]); } UpdateTier(" + ID + @"); $('#showTier_" + ID + @"').change(TierChange); //OK HERE </script>"); } else { Row.Add("<div id='tiers" + ID + "' style='display:none'>Tier 1:" + ScratchBuilder.stringInput("RateTier1_" + ID, parts["RateTier1"]).print() + " Tier 2:" + ScratchBuilder.stringInput("RateTier2_" + ID, parts["RateTier2"]).print() + " Tier 3:" + ScratchBuilder.stringInput("RateTier3_" + ID, parts["RateTier3"]).print() + " Tier 4:" + ScratchBuilder.stringInput("RateTier4_" + ID, parts["RateTier4"]).print() + " AWC or LotSize:" + ScratchBuilder.stringInput("AWCOrLot_" + ID, parts["AWCOrLot"]).print() + "</div>" + "<div id='rate" + ID + "' style='display:none'>" + ScratchBuilder.stringInput("RateValue_" + ID, parts["RateValue"]).print() + "</div>" + @"<script> UpdateTier=function(id){ IsChecked = $('#showTier_' + id)[0].checked; if(IsChecked){ $('#tiers'+id)[0].style.display='inline'; $('#rate'+id)[0].style.display='none'; } else{ $('#tiers'+id)[0].style.display='none'; $('#rate'+id)[0].style.display='inline'; } } TierChange=function(){ console.log('TierChange'); console.log(this); UpdateTier(this.id.split('_')[1]); } UpdateTier(" + ID + @"); $('#showTier_" + ID + @"').change(TierChange); //OK HERE </script>"); } Row.Add(ScratchBuilder.stringInput("LiveUpdateID_" + ID, parts["LiveUpdateID"]).print()); //Instance.hspi.Log(parts["ScratchPadString"],0); Row.Add(ScratchBuilder.stringInput("DisplayString_" + ID, parts["DisplayString"]).print()); Row.Add("" + Dev.Ref); Row.Add(ScratchBuilder.button("R_" + ID.ToString(), "Reset").print()); Row.Add(ScratchBuilder.DeleteDeviceButton(ID.ToString()).print()); // Row.Add(ScratchBuilder.button("S_" + ID.ToString(), "Add Associated Device").print()); ScratchTable.addArrayRow(Row.ToArray()); sb.Append(ScratchTable.print()); sb.Append("</div>"); return(sb.ToString()); }
public ScratchpadDevicePage(string pagename, InstanceHolder instance) : base(pagename) { Instance = instance; ScratchpadBuilder = new htmlBuilder("Scratchpad" + Instance.ajaxName); }