/* ======================= Mosaico World Graphic User Interface Framework Library V1.0 Author: Francesco Di Giorgio Date: 2021-02-18 MosaicoGroup Copyright 2021 ======================= */ function TMWGUI() { this.MainWindow; this.MainDocument; this.MainBody; this.MessageBox; this.MainFrame; this.MainFrameBody; this.MainMenu; this.MainMenuTranslateStructure; this.SpanHeaderUserNickName ; this.SpanHeaderUserPoolDescription ; this.ServiceContainer; this.HeaderPageTitle = null; this.HeaderPageLogo = null; this.HeaderPageUserImage = null; this.AriannaThread; var WaitForScanElementFn; //var DictionaryIsLoaded = true; this.clientHeight; this.clientWidth; this.CurrentLanguage = "it"; this.Master; this.Detail; this.DictionaryLanguage = {}; this.SessionState; this.Plants; this.PlantGroups; this.pathname = window.location.pathname; this.FirstTime = false; this.PasswordExpirationPeriodNotNull = null; this.ChangePasswordIsWorking = false; this.SiteDescription; this.SiteAddress; this.SiteCity; this.SiteStateProvince; this.SitePostalCode; this.SiteCountry; this.SitePhone; this.phoneIcon; this.SiteEmail; this.emailIcon; this.MainLogo; this.FirstTime = true; this.IconHideShowCustomBoxes; if (this.pathname[this.pathname.length-1]=='/') this.pathname += "index.html"; if(window.location.search.indexOf("Lang=") > -1) { this.CurrentLanguage = window.location.search.substring( window.location.search.indexOf("Lang=") + 5, 100); } if (parent.$MWGUI != null) { if (parent.$MWGUI != this ) { this.ParentMWGUI = parent.$MWGUI.clientHeight; var ProcessResguiList = []; this.clientHeight = parent.$MWGUI.clientHeight; this.clientWidth = parent.$MWGUI.clientWidth; this.CurrentLanguage = parent.$MWGUI.CurrentLanguage; this.MainDocument = parent.$MWGUI.MainDocument; this.MainWindow = parent.$MWGUI.MainWindow; this.MainBody = parent.$MWGUI.MainBody; this.SpanHeaderUserNickName = parent.$MWGUI.SpanHeaderUserNickName; this.SpanHeaderUserPoolDescription = parent.$MWGUI.SpanHeaderUserPoolDescription; this.ServiceContainer = parent.$MWGUI.ServiceContainer; this.HeaderPageTitle = parent.$MWGUI.HeaderPageTitle; this.HeaderPageLogo = parent.$MWGUI.HeaderPageLogo; this.MessageBox = parent.$MWGUI.MessageBox; this.ActionCallBack = parent.$MWGUI.ActionCallBack; //if($MW) //$MW.MWGUIReference = this; this.MainFrame = parent.$MWGUI.MainFrame; this.MainFrameBody = parent.$MWGUI.MainFrameBody; this.MainIframeContainer = parent.$MWGUI.MainIframeContainer; this.MainFrameWindow = parent.$MWGUI.MainFrameWindow this.MainFrameDocument = parent.$MWGUI.MainFrameDocument this.BlurDiv = parent.$MWGUI.BlurDiv; this.IconHideShowCustomBoxes = parent.$MWGUI.IconHideShowCustomBoxes; /*this.MainMenuTranslateStructure = parent.$MWGUI.MainMenuTranslateStructure; this.AriannaThread = parent.$MWGUI.MainMenu; this.SessionState = parent.$MWGUI.SessionState; this.Plants = parent.$MWGUI.Plants; this.PlantGroups = parent.$MWGUI.PlantGroups; this.UpdatePlantsAndPlantGroups = parent.$MWGUI.UpdatePlantsAndPlantGroups(); this.GetSiteInfo = parent.$MWGUI.GetSiteInfo(); this.SiteDescription=parent.$MWGUI.SiteDescription; this.SiteAddress=parent.$MWGUI.SiteAddress; this.SiteCity=parent.$MWGUI.SiteCity; this.SiteStateProvince=parent.$MWGUI.SiteStateProvince; this.SitePostalCode=parent.$MWGUI.SitePostalCode; this.SiteCountry=parent.$MWGUI.SiteCountry; this.SitePhone=parent.$MWGUI.SitePhone; this.phoneIcon=parent.$MWGUI.phoneIcon; this.SiteEmail=parent.$MWGUI.SiteEmail; this.emailIcon=parent.$MWGUI.emailIcon; this.MainLogo=parent.$MWGUI.MainLogo;*/ this.vhfactor = this.clientHeight/document.documentElement.clientHeight; this.vwfactor = this.clientWidth/document.documentElement.clientWidth; this.vminfactor = (this.clientHeightthis.clientWidth ? this.clientHeight : this.clientWidth) / (document.documentElement.clientHeight > document.documentElement.clientWidth ? document.documentElement.clientHeight : document.documentElement.clientWidth); var root = document.documentElement; var rootStyles = window.getComputedStyle(root); for( var StyleSheetIndex in document.styleSheets) { var styleSheets = document.styleSheets[StyleSheetIndex]; for(var ruleIndex in styleSheets.cssRules) { var rule = styleSheets.cssRules[ruleIndex]; if (rule.selectorText ==":root") { var patt =/--resgui(-\w*)+/g; var resguiarray = rule.cssText.match(patt); for(var resguiarrayindex in resguiarray) { var rootStyleItem =resguiarray[resguiarrayindex] if (ProcessResguiList[rootStyleItem] == null) { ProcessResguiList[rootStyleItem] = rootStyleItem; var Value = rootStyles.getPropertyValue(rootStyleItem); var reg = /^\s?[+-]?\d+(\.\d+)?/g; var numValue = parseFloat(Value.match(reg)); reg = /[a-z]+/g; var unit = Value.match(reg); if(unit!=null) if (unit.length > 0) { switch(unit[0]) { case "vh": root.style.setProperty(rootStyleItem, (numValue * this.vhfactor ) + unit[0]); break; case "vw": root.style.setProperty(rootStyleItem, (numValue * this.vwfactor ) + unit[0]); break; case "vmin": root.style.setProperty(rootStyleItem, (numValue * this.vminfactor ) + unit[0]); break; case "vmax": root.style.setProperty(rootStyleItem, (numValue * this.vmaxfactor ) + unit[0]); break; } } } } } } } } } this.MessageLogout = false; var Languages = { "0":"af", "1":"sq", "2":"ar_dz", "3":"ar_bh", "4":"ar_eg", "5":"ar_iq", "6":"ar_jo", "7":"ar_kw", "8":"ar_lb", "9":"ar_ly", "10":"ar_ma", "11":"ar_om", "12":"ar_qa", "13":"ar_sa", "14":"ar_sy", "15":"ar_tn", "16":"ar_ae", "17":"ar_ye", "18":"eu", "19":"be", "20":"bg", "21":"ca", "22":"zh_hk", "23":"zh_cn", "24":"zh_sg", "25":"zh_tw", "26":"hr", "27":"cs", "28":"da", "29":"nl_be", "30":"nl", "31":"en", "32":"en_au", "33":"en_bz", "34":"en_ca", "35":"en_ie", "36":"en_jm", "37":"en_nz", "38":"en_za", "39":"en_tt", "40":"en_gb", "41":"en_us", "42":"et", "43":"fo", "44":"fa", "45":"fi", "46":"fr_be", "47":"fr_ca", "48":"fr_lu", "49":"fr", "50":"fr_ch", "51":"gd", "52":"de_at", "53":"de_li", "54":"de_lu", "55":"de", "56":"de_ch", "57":"el", "58":"he", "59":"hi", "60":"hu", "61":"is", "62":"id", "63":"ga", "64":"it", "65":"it_ch", "66":"ja", "67":"ko", "68":"lv", "69":"lt", "70":"mk", "71":"ms", "72":"mt", "73":"no", "74":"pl", "75":"pt_br", "76":"pt", "77":"rm", "78":"ro", "79":"ro_mo", "80":"ru", "81":"ru_mo", "82":"sz", "83":"sr", "84":"sk", "85":"sl", "86":"sb", "87":"es_ar", "88":"es_bo", "89":"es_cl", "90":"es_co", "91":"es_cr", "92":"es_do", "93":"es_ec", "94":"es_sv", "95":"es_gt", "96":"es_hn", "97":"es_mx", "98":"es_ni", "99":"es_pa", "100":"es_py", "101":"es_pe", "102":"es_pr", "103":"es", "104":"es_uy", "105":"es_ve", "106":"sx", "107":"sv", "108":"sv_fi", "109":"th", "110":"ts", "111":"tn", "112":"tr", "113":"uk", "114":"ur", "115":"ve", "116":"vi", "117":"xh", "118":"ji", "119":"zu" }; this.setCurrentLanguage = function (Language) { this.CurrentLanguage = Languages[Language]; if (parent.$MWGUI != null) { if (parent.$MWGUI != this ) { parent.$MWGUI.setCurrentLanguage(Language); return; } } } this.Initialize = function(){ if (parent.$MWGUI == $MWGUI) { this.ParentMWGUI = this; this.MainDocument = document; this.MainWindow = window; this.MainBody = document.getElementById("mainBody"); this.clientHeight = document.documentElement.clientHeight; this.clientWidth = document.documentElement.clientWidth; this.MessageBox = document.getElementById("message-box"); if (this.MessageBox == null) console.log("#Error MWGUI:MessageBox not found!") this.SpanHeaderUserNickName = document.getElementById("Header-User.NickName"); this.SpanHeaderUserPoolDescription = document.getElementById("Header-UserPool.Description"); this.ServiceContainer = document.getElementById("ServiceContainer"); if(!this.HeaderPageLogo && this.MainDocument) this.HeaderPageLogo = this.MainDocument.getElementById("HeadPage-Logo"); if(!this.HeaderPageUserImage && this.MainDocument) this.HeaderPageUserImage = this.MainDocument.getElementById("Header-Page.UserImage"); this.MainFrame = document.getElementById("MainIframe"); if (this.MainFrame == null) console.log("#Error MWGUI:MainFrame not found!"); this.MainFrame.onload = function (ev) { $MWGUI.ParentMWGUI.MainFrameBody = ev.target.contentDocument.body $MWGUI.MainFrameBody = ev.target.contentDocument.body $MWGUI.MainFrameWindow = ev.target.contentWindow $MWGUI.MainFrameDocument = ev.target.contentDocument $MWGUI.MainFrameBody.onclick = function () { $MWGUI.IconHideShowCustomBoxes.OnHideFunction = true; $MWGUI.IconHideShowCustomBoxes.click(); //Me.HideAllCustomBoxes(); } } this.MainIframeContainer = document.getElementById("MainIframeContainer"); if (this.MainIframeContainer == null) console.log("#Error MWGUI:MainFrame not found!"); this.MainMenu = document.getElementById("main_menu"); this.BlurDiv = document.getElementById("blur_div"); this.IconHideShowCustomBoxes = document.getElementById("HIdeShowContestualCustomBoxes"); } var watcher = new MutationObserver(function(ElementsList, sender){ for(var Element in ElementsList) { if (ElementsList[Element].addedNodes.length > 0) { var inputs = document.querySelectorAll("input[type='checkbox']"); for(var i = 0; i < inputs.length; i++) { //console.log(inputs[i].getAttribute("data-Preserve")) if (inputs[i].Preserve || (inputs[i].getAttribute("data-Preserve") != null && inputs[i].getAttribute("data-Preserve") != undefined)) { let OldDisplay = inputs[i].style.display.slice(); if (inputs[i].checkReference == null) { inputs[i].style.display="none"; inputs[i].isChecked = inputs[i].checked; Object.defineProperty(inputs[i],"checked",{ get:function(){return this.isChecked;}, set:function(value){ this.isChecked = value; if(this.readOnly == false) { if (this.isChecked == true) { this.divCheck.className = this.divCheck.className.replace(new RegExp(" checkboxPreserved-off","g"),""); this.divCheck.className =" checkboxPreserved-on"; if(this.divCheck.children.length>0) { this.divCheck.children[0].className = this.divCheck.children[0].className.replace(new RegExp(" checkboxPreserved-CheckStyle-off","g"),""); this.divCheck.children[0].className = " checkboxPreserved-CheckStyle-on"; } } else { this.divCheck.className = this.divCheck.className.replace(new RegExp(" checkboxPreserved-on","g"),""); this.divCheck.className =" checkboxPreserved-off"; if(this.divCheck.children.length>0) { this.divCheck.children[0].className = this.divCheck.children[0].className.replace(new RegExp(" checkboxPreserved-CheckStyle-on","g"),""); this.divCheck.children[0].className = " checkboxPreserved-CheckStyle-off"; } } } else { this.divCheck.className ="checkboxPreserved-ReadOnly-off"; if (this.isChecked == true) { this.divCheck.className = "checkboxPreserved-ReadOnly-on" if(this.divCheck.children.length>0) { this.divCheck.children[0].className = " checkboxPreserved-CheckStyle-on"; } } else { this.divCheck.children[0].className = " checkboxPreserved-CheckStyle-off"; } this.click(); } }, }); var divCheck = document.createElement("div"); if(OldDisplay == "none") divCheck.style.display = "none" var DivCheckOnCheckbox= document.createElement("div"); divCheck.appendChild(DivCheckOnCheckbox); if (inputs[i].readOnly == false) { //divCheck.className ="checkboxPreserved-off"; divCheck.className += inputs[i].checked == true ? " checkboxPreserved-on" : " checkboxPreserved-off"; DivCheckOnCheckbox.className += inputs[i].checked == true ? " checkboxPreserved-CheckStyle-on" : " checkboxPreserved-CheckStyle-off"; } else { divCheck.className ="checkboxPreserved-ReadOnly-off"; if (inputs[i].checked == true) { divCheck.className = "checkboxPreserved-ReadOnly-on" if(divCheck.children.length>0) { divCheck.children[0].className = " checkboxPreserved-CheckStyle-on"; } } } inputs[i].divCheck = divCheck; divCheck.input =inputs[i]; //if (inputs[i].readOnly == false) //{ divCheck.addEventListener("click",function(event){ if(this.input.readOnly == false) { var CheckElement = this; //console.log(CheckElement.input); if(CheckElement.input.checked == false) { CheckElement.className = CheckElement.className.replace(new RegExp("checkboxPreserved-off","g"),""); CheckElement.className = " checkboxPreserved-on"; CheckElement.children[0].className =CheckElement.children[0].className.replace(new RegExp("checkboxPreserved-CheckStyle-off","g"),""); CheckElement.children[0].className = " checkboxPreserved-CheckStyle-on"; CheckElement.input.checked = true; } else { CheckElement.className = CheckElement.className.replace(new RegExp("checkboxPreserved-on","g"),""); CheckElement.className = " checkboxPreserved-off"; CheckElement.children[0].className =CheckElement.children[0].className.replace(new RegExp("checkboxPreserved-CheckStyle-on","g"),""); CheckElement.children[0].className = " checkboxPreserved-CheckStyle-off"; CheckElement.input.checked = false; } if (CheckElement.input.Changed != null) CheckElement.input.Changed(CheckElement); var Ev= new Event("change"); CheckElement.input.dispatchEvent(Ev); if(CheckElement.input.onchange!=null) { CheckElement.input.onchange(event); } if(CheckElement.input.oninput) CheckElement.input.oninput(event); } }); //} inputs[i].checkReference = divCheck; //console.log(inputs[i].parentElement.children.filter((HTMLElementOfParent)=> HTMLElementOfParent == inputs[i])); for(var HtmlElement in inputs[i].parentElement.children) { if(inputs[i].parentElement.children[HtmlElement] == inputs[i]) { if(inputs[i].parentElement.children[(parseInt(HtmlElement)+1)]) { inputs[i].parentElement.insertBefore(divCheck, inputs[i].parentElement.children[(parseInt(HtmlElement)+1)]); break; } else { inputs[i].parentElement.appendChild(divCheck); break; } } } //inputs[i].parentElement.insertBefore(divCheck, inputs[i]); //inputs[i].parentElement.insertBefore(divCheck); if (inputs[i].Changed != null) inputs[i].Changed(inputs[i].divCheck); continue; } } if (inputs[i].checkReference == null) { inputs[i].style.display="none"; inputs[i].isChecked = inputs[i].checked; Object.defineProperty(inputs[i],"checked",{ get:function(){return this.isChecked;}, set:function(value){ this.isChecked = value; if (this.isChecked == true) { this.divCheck.className = this.divCheck.className.replace(new RegExp(" checkbox-off","g"),""); this.divCheck.className +=" checkbox-on"; } else { this.divCheck.className = this.divCheck.className.replace(new RegExp(" checkbox-on","g"),""); this.divCheck.className +=" checkbox-off"; } }, }); var divCheck = document.createElement("div"); //if(OldDisplay == "none") divCheck.style.display = "none" if (inputs[i].readOnly == false) { divCheck.className ="checkbox"; divCheck.className += inputs[i].checked == true ? " checkbox-on" : " checkbox-off"; } else { divCheck.className ="checkboxReadOnly"; if (inputs[i].checked == true) divCheck.className += " checkboxReadOnly-on" } inputs[i].divCheck = divCheck; divCheck.input =inputs[i]; var divCheckCursor = document.createElement("div"); divCheck.appendChild(divCheckCursor); if (inputs[i].readOnly == false) divCheck.addEventListener("click",function(event){ var CheckElement = this; if(CheckElement.input.checked == false) { CheckElement.className = CheckElement.className.replace(new RegExp(" checkbox-off","g"),""); CheckElement.className +=" checkbox-on"; CheckElement.input.checked = true; } else { CheckElement.className = CheckElement.className.replace(new RegExp(" checkbox-on","g"),""); CheckElement.className +=" checkbox-off"; CheckElement.input.checked = false; } if (CheckElement.input.Changed != null) CheckElement.input.Changed(CheckElement); if(CheckElement.input.onchange!=null) CheckElement.input.onchange(event); if(CheckElement.input.oninput) CheckElement.input.oninput(event); }); inputs[i].checkReference = divCheck; inputs[i].parentElement.insertBefore(divCheck, inputs[i]); if (inputs[i].Changed != null) inputs[i].Changed(inputs[i].divCheck); } } } } }); watcher.observe(document.body,{attributes:false, childList:true, subtree:true}); console.log(document.getElementsByTagName("body")); document.getElementsByTagName("body")[0].addEventListener("onpagehide",function (params) { $MW.Logout(); }); console.log(document.getElementsByTagName("body")); /*$MWGUI.RefreshPreserveRatio(); window.addEventListener("resize",function(){$MWGUI.RefreshPreserveRatio();});*/ } this.ChangePage = function(PageName, PageURL) { if(window != $MWGUI.MainWindow) parent.$MWGUI.ChangePage(PageName, PageURL); if(PageURL != null && PageURL != undefined && PageURL != "") { $MWGUI.MainFrame.src = PageURL; } if(!$MWGUI.HeaderPageTitle) { $MWGUI.HeaderPageTitle = $MWGUI.MainDocument.getElementById("Header-Page.PageName"); } $MWGUI.HeaderPageTitle.innerHTML = PageName; document.body.style.display ="flex"; } this.GetLanguageString=function(Key) { if ($MWGUI.DictionaryLanguage[Key] == null) return null; return $MWGUI.DictionaryLanguage[Key][$MWGUI.CurrentLanguage]; } this.RegisterLanguageString = function(key, values) { $MWGUI.DictionaryLanguage[key] = values; } this.LoadDictionary = function(Callback) { //console.log($MWGUI.pathname); var Request = {}; Request["database"] = "MosaicoWorld"; Request["PathPage"] = $MWGUI.pathname; Request["Dictionary"] = $MWGUI.DictionaryLanguage; //var string=JSON.stringify(Request); $MW.ExeLambda("MosaicoWorldApplication-GetLanguageString-4L8QMVMS7U9U",Request, function(Answer,OriginalMessage) { if(Answer) { $MWGUI.DictionaryLanguage=Answer; if(Callback!=null)Callback(); } else { console.error(OriginalMessage); } }, function(Error,ErrorStack) { } ,undefined,true); } this.MessageBoxShow = function(Title, Message, Icon, Buttons){ if (window != $MWGUI.MainWindow) { return $MWGUI.MainWindow.$MWGUI.MessageBoxShow(Title, Message, Icon, Buttons); } this.MessageBox.className ="MessageBoxMain"; this.MessageBox.onclick = function (ev) { ev.stopPropagation(); } this.MessageBox.children[0].className = this.MessageBox.children[0].className.replace(" MessageBoxFormExit",""); this.MessageBox.children[0].className += " MessageBoxFormEntry"; this.MessageBox.children[0].children[0].children[0].innerHTML=Title; this.MessageBox.children[0].children[2].children[1].innerHTML=Message; switch(Icon.toLowerCase()) { case "error": { this.MessageBox.children[0].children[2].children[0].src ="../../../../../../../../../../images/icons/msgboxerror.png"; break; } case "warning": { this.MessageBox.children[0].children[2].children[0].src ="../../../../../../../../../../images/icons/msgboxwarning.png"; break; } case "info": { this.MessageBox.children[0].children[2].children[0].src ="../../../../../../../../../../images/icons/msgboxinfo.png"; break; } case "quest": { this.MessageBox.children[0].children[2].children[0].src ="../../../../../../../../../../images/icons/msgboxquest.png"; break; } default: { this.MessageBox.children[0].children[2].children[0].src =""; this.MessageBox.children[0].children[2].children[0].className ="display-none"; break; } } this.MessageBox.children[0].children[4].innerHTML =""; for(var Button in Buttons) { var divButton = document.createElement("div"); var spanButton = document.createElement("span"); spanButton.innerHTML = Buttons[Button].text; divButton.appendChild(spanButton); divButton.className ="button-application"; this.MessageBox.children[0].children[4].appendChild(divButton); divButton.MessageBox = this.MessageBox; divButton.Action = Buttons[Button].Callback; divButton.addEventListener("click", function(ev) { ev.stopPropagation(); $MWGUI.MessageBoxClose(this); }); } } this.MessageBoxClose = function(sender) { sender.MessageBox.children[0].className = sender.MessageBox.children[0].className.replace(/ MessageBoxFormEntry/g,""); sender.MessageBox.children[0].className += " MessageBoxFormExit"; //setTimeout(function(){$MWGUI.MessageBox.className ="display-none";},300); $MWGUI.MessageBox.className ="display-none"; try{ if(sender.Action != null) sender.Action(); }catch{} } /*this.EndInitializeCallback = null; this.RegisterEndInitializeCallback = function(CallbackFunction) { if(CallbackFunction) $MWGUI.EndInitializeCallback = CallbackFunction; } this.EndInitialize = function (Callback) { if (Callback) Callback(); if($MWGUI.EndInitializeCallback!=null) { $MWGUI.EndInitializeCallback(); $MWGUI.EndInitializeCallback= null; } } this.CreateMainMenu = function(Callback){ $Prime.PostMessage("PrimeGUIMainMenu","",function(Answer) { if (Answer.MessageResult =="OK") { $MWGUI.MainMenuTranslateStructure = Answer.Content; PopulateMenu(Answer.Content, $MWGUI.MainMenu, "main_submenu1"); } if(Callback != null) Callback(); }); } function PopulateMenu(ListMenu, ElementContainer,IdNextContainer) { ElementContainer.innerHTML = ""; for (var ElementKey in ListMenu) { if(ListMenu[ElementKey]["Language"] == null) continue; var HasChildren = false; var Children = [] for(var Field in ListMenu[ElementKey]) { if (Field != "Language") { HasChildren = true; Children[Field] = ListMenu[ElementKey][Field] } } var divRow = document.createElement("div"); var divImage = document.createElement("div"); divRow.appendChild(divImage); var imageRow = document.createElement("img"); divImage.appendChild(imageRow); divImage.className +="resgui-1row resgui-halfcolumn align-items-center justify-content-center"; var spanText = document.createElement("span"); divRow.Path = "../../../../../../../../../../../../--mainmenu/" + ListMenu[ElementKey]["Language"]["Id"].replace(/_/g, '/')+"/"; imageRow.src = divRow.Path + "menuicon.png"; imageRow.className = "icon-image"; imageRow.addEventListener("error",function(){this.style.display="none"}); divRow.appendChild(spanText); ElementContainer.appendChild(divRow); divRow.className = "main_menu_row decor-solid-border-bottom-dark"; spanText.className="letter-spacing-l resgui-font-height-s"; spanText.innerHTML=ListMenu[ElementKey]["Language"]["Content"][$MWGUI.CurrentLanguage]; divRow.Title = spanText.innerHTML; if (HasChildren) { if (IdNextContainer != null) { divRow.IdNextContainer = IdNextContainer; divRow.ElementContainer = ElementContainer; divRow.MenuChildred = Children; divRow.addEventListener("click", function(){ var SubMenu = document.getElementById(this.IdNextContainer); SubMenu.main_submenu_exit = " " + this.IdNextContainer + "_exit"; SubMenu.main_submenu_entry = " " + this.IdNextContainer + "_entry"; SubMenu.ParentMenu = this.ElementContainer; this.ElementContainer.SubMenu = SubMenu; if (ElementContainer.CurrentRow != null) if (this != ElementContainer.CurrentRow) { ElementContainer.CurrentRow.className = ElementContainer.CurrentRow.className.replace(" with_child",""); } if (this.className.indexOf("with_child") == -1) { this.className += " with_child"; ElementContainer.CurrentRow = this; var IdNextContainer; switch (this.IdNextContainer) { case "main_submenu1": {IdNextContainer = "main_submenu2"; break;} case "main_submenu2": {IdNextContainer = "main_submenu3"; break;} case "main_submenu3": {IdNextContainer = "main_submenu4"; break;} case "main_submenu4": {IdNextContainer = "main_submenu5"; break;} default: {IdNextContainer = null; break;} } PopulateMenu(this.MenuChildred,SubMenu,IdNextContainer); if (SubMenu.className.indexOf(SubMenu.main_submenu_exit) > -1) SubMenu.className =SubMenu.className.replace(SubMenu.main_submenu_exit,""); if (SubMenu.className.indexOf(SubMenu.main_submenu_entry) == -1) SubMenu.className += SubMenu.main_submenu_entry; } else { this.className = this.className.replace(" with_child", ""); CloseSubMenu(SubMenu); ElementContainer.CurrentRow = null; } }); } } else { if(divRow.Path.indexOf("rebootsystem") > -1) { divRow.addEventListener("click", function() { $MWGUI.MessageBoxShow($MWGUI.GetLanguageString("RebootSystemTitle"),$MWGUI.GetLanguageString("RebootSystemContent"),"info",[{"text":"OK","Callback":function(){ $Prime.Post("PVCRebootSystem", null, function() { $MWGUI.MessageBoxShow($MWGUI.GetLanguageString("RebootSystemTitle"),$MWGUI.GetLanguageString("RebootSystemContentNow"),"info",[{"text":"OK","Callback":function(){}}]); }); }}, {"text":$MWGUI.GetLanguageString("Null"),"Callback":function(){}}]); }); } else if(divRow.Path.indexOf("clearcache") > -1) { divRow.addEventListener("click", function() { $Prime.Post("PrimeClearWebCache", null, function() { window.location.href = "../../../../../../../../../../../../index.html"; }); }); } else if(divRow.Path.indexOf("@shutdownsystem") > -1) { divRow.addEventListener("click", function() { $MWGUI.MessageBoxShow($MWGUI.GetLanguageString("ShutdownSystemTitle"),$MWGUI.GetLanguageString("ShutdownSystemContent"),"info",[{"text":"OK","Callback":function(){ $Prime.Post("PrimeStopSystem", null, function() { $MWGUI.MessageBoxShow($MWGUI.GetLanguageString("ShutdownSystemTitle"),$MWGUI.GetLanguageString("ShutdownSystemContentNow"),"info",[{"text":"OK","Callback":function(){}}]); }); }}, {"text":$MWGUI.GetLanguageString("Null"),"Callback":function(){}}]); }); } else { divRow.addEventListener("click",function(){ $MWGUI.MainFrameLoadPage(this.Path,this.Title); }); } } } } function CloseSubMenu(SubMenu) { if (SubMenu.SubMenu != null) CloseSubMenu(SubMenu.SubMenu); if (SubMenu.className.indexOf(SubMenu.main_submenu_entry) > -1) SubMenu.className =SubMenu.className.replace(SubMenu.main_submenu_entry,""); if (SubMenu.className.indexOf(SubMenu.main_submenu_exit) == -1) SubMenu.className += SubMenu.main_submenu_exit; } this.MainFrameLoadPage = function(location, AriannaThreadTitle, AriannaThreadDescriptions){ if (this.MainFrame != null) { this.MainFrame.src = location; while(this.AriannaThread.children.length > 1) this.AriannaThread.removeChild(this.AriannaThread.lastChild); this.AriannaThread.children[this.AriannaThread.children.length -1].className = this.AriannaThread.children[this.AriannaThread.children.length -1].className.replace("ariannathread_element_active",""); $MWGUI.AddAriannaThreadElement(AriannaThreadTitle, AriannaThreadDescriptions); $MWGUI.HiddenMainMenu(); } } this.AddAriannaThreadElement = function(AriannaThreadTitle, AriannaThreadDescriptions){ var divContent = document.createElement("div"); divContent.className="ariannathread_element ariannathread_element_active"; $MWGUI.AriannaThread.appendChild(divContent); var a = document.createElement("a"); //a.href="about:black"; divContent.appendChild(a); if (AriannaThreadTitle != null) { var spanInner = document.createElement("span"); spanInner.className = "ariannathread__inner"; a.appendChild(spanInner); var spanTitle = document.createElement("span"); spanTitle.innerHTML = AriannaThreadTitle; spanTitle.className = "ariannathread__title"; spanInner.appendChild(spanTitle); } } this.RegisterMaster=function(){ if (parent.$MWGUI != null) { parent.$MWGUI.Master = this; } } this.RegisterDetail=function(LoadDetail){ if (parent.$MWGUI != null) { parent.$MWGUI.Detail = this; } } this.ShowDetail=function(Item){ if (parent.$MWGUI != null) { if (parent.$MWGUI.Detail.LoadDetail != null) parent.$MWGUI.Detail.LoadDetail(Item) } } this.UpdateMasterFromDetail=function(Item){ if (parent.$MWGUI != null) { if (parent.$MWGUI.Master.OnUpdateDetail != null) parent.$MWGUI.Master.OnUpdateDetail(Item) } } this.DeleteMasterFromDetail=function(Item){ if (parent.$MWGUI != null) { if (parent.$MWGUI.Master.OnDeleteDetail != null) parent.$MWGUI.Master.OnDeleteDetail(Item) } } this.ScanElements = function() { //console.log(DictionaryIsLoaded); if(!DictionaryIsLoaded){ WaitForScanElementFn = function(){ $MWGUI.ScanElements()}; return; } var Elements = document.getElementsByTagName('*'); for (var i = 0; i < Elements.length; i++) { var Datadictionary = []; for (var ia = 0; ia < Elements[i].attributes.length; ia++) { var Name = Elements[i].attributes[ia].nodeName.toLowerCase(); if (Name.indexOf('data-gui-prime') == 0) { var PrimeLinkArray = JSON.parse(Elements[i].attributes[ia].value); Elements[i][PrimeLinkArray["target"]] = $MWGUI.GetLanguageString(PrimeLinkArray["key"]); } if (Name.indexOf('data-gui-contextmenu') == 0){ try { var ContextMenu = document.getElementById(Elements[i].attributes[ia].value); if(ContextMenu!=null) if (ContextMenu.className.indexOf("ContextMenu") > -1) { var Parent = ContextMenu.parentNode; ContextMenu.parentNode.removeChild(ContextMenu); ContextMenu.className = ContextMenu.className.replace("ContextMenu",""); ContextMenu.className += " ContextMenuContent"; var NewMenu = document.createElement("div"); NewMenu.className ="fullContextMenu"; Parent.appendChild(NewMenu); var NewMenuHeader = document.createElement("div"); NewMenuHeader.className = "fullContextMenuHeader"; NewMenuHeader.addEventListener("click", function(event){ NewMenu.style.display ="none"; }); var NewMenuHeaderContent = document.createElement("div"); NewMenuHeaderContent.className="fullContextMenuHeaderContent"; NewMenuHeader.appendChild(NewMenuHeaderContent); var Close = document.createElement("span"); Close.innerHTML ="X"; NewMenuHeaderContent.appendChild(Close); NewMenu.appendChild(NewMenuHeader); ContextMenu.addEventListener("click",function(){NewMenu.style.display ="none";}); NewMenu.appendChild(ContextMenu); var footer = document.createElement("div"); footer.className="fullContextMenuFooter"; NewMenu.appendChild(footer); Elements[i].ContextMenu = NewMenu; Elements[i].style.cursor ="pointer"; Elements[i].addEventListener("click", function(e){ ShowContextMenu(e); }); } } catch (err) {console.error(err)} } } } try { //$MWGUI.EndInitialize(); } catch (err){} } function ShowContextMenu(Event) { var ContextMenu = Event.target.ContextMenu; if (ContextMenu != null) { ContextMenu.style.display = "flex"; ContextMenu.style.top = (Event.clientY + $MWGUI.clientHeight * 0.02) + "px"; ContextMenu.style.left = (Event.clientX - ContextMenu.offsetWidth / 2) + "px"; } } this.LoadDeviceViewCallback = function(DeviceObject) { console.log(DeviceObject); } this.EditUserImage = function() { $Prime.UploadFile("*", function(GUID){ var Request = {}; Request["Key"] = GUID; Request["DevicePath"] = "images/avatar/"; Request["Filename"] = $MWGUI.SessionState.UserGUID + ".image"; var objRequest = {}; objRequest["ID"] = $MWGUI.SessionState.UserGUID; objRequest["Type"] = $MWGUI.SessionState.UserType; objRequest["NickName"] = $MWGUI.SessionState.Username; var obj = btoa(JSON.stringify(objRequest)); $Prime.PostMessage("PVCUploadDeviceResourceFile", Request, function(Answer, Req){ $Prime.PostMessage("PrimeGetUserDetail", objRequest, function(Answer, R) { Answer.Content.UserImage = "../../../../../../../../../../../../" + R["DevicePath"] + R["Filename"]; $Prime.PostMessage("PrimeEditUserDetail", Answer.Content, function(){ $MWGUI.FirstTime = false; }); }, Req); }, Request); }); } this.SetUserImage = function() { var Elements = document.getElementsByTagName('*'); for (var i = 0; i < Elements.length; i++) { for (var ia = 0; ia < Elements[i].attributes.length; ia++) { var Name = Elements[i].attributes[ia].nodeName.toLowerCase(); if (Name.indexOf('data-gui-contextmenu') == 0 && Elements[i].attributes[ia].value == "AvatarContextMenu") { if($MWGUI.SessionState.UserImageUrl != "" && $MWGUI.SessionState.UserImageUrl != null) { Elements[i].src = "../../../../../../../../../../../../" + $MWGUI.SessionState.UserImageUrl + "?" + new Date().getTime(); } break; } } } } this.RespectRatioCollection = []; this.AddElementPreserveRatio = function(Element, Width, Height) { if (Element != null && Width != null, Height != null) { $MWGUI.RespectRatioCollection.push( { "Element":Element,"Width":Width,"Height":Height}); } } this.RefreshPreserveRatio = function() { for(var i =0; i < $MWGUI.RespectRatioCollection.length; i++) { if (($MWGUI.RespectRatioCollection[i].Element.parentNode.offsetWidth / $MWGUI.RespectRatioCollection[i].Width) < ($MWGUI.RespectRatioCollection[i].Element.parentNode.offsetHeight / $MWGUI.RespectRatioCollection[i].Height)) { $MWGUI.RespectRatioCollection[i].Element.style.width = $MWGUI.RespectRatioCollection[i].Element.parentNode.offsetWidth + "px"; $MWGUI.RespectRatioCollection[i].Element.style.height = $MWGUI.RespectRatioCollection[i].Element.parentNode.offsetWidth * $MWGUI.RespectRatioCollection[i].Height / $MWGUI.RespectRatioCollection[i].Width + "px"; } else { $MWGUI.RespectRatioCollection[i].Element.style.width = $MWGUI.RespectRatioCollection[i].Width * $MWGUI.RespectRatioCollection[i].Element.parentNode.offsetHeight / $MWGUI.RespectRatioCollection[i].Height + "px"; $MWGUI.RespectRatioCollection[i].Element.style.height = $MWGUI.RespectRatioCollection[i].Element.parentNode.offsetHeight + "px"; } } } this.GetSiteInfo=function(Callback) { $Prime.PostMessage("PrimeGetSiteInfo", null, function (Answer){ if (Answer.MessageResult == "OK") { if ($MWGUI.MainLogo) $MWGUI.MainLogo.setAttribute("src", "data:image/png;base64," + Answer.Content.Logo); if ($MWGUI.SiteDescription) $MWGUI.SiteDescription.innerHTML = Answer.Content.Description; if ($MWGUI.SiteAddress) $MWGUI.SiteAddress.innerHTML = Answer.Content.Address; if ($MWGUI.SiteCity) $MWGUI.SiteCity.innerHTML = Answer.Content.City; if ($MWGUI.SiteStateProvince) $MWGUI.SiteStateProvince.innerHTML = Answer.Content.StateProvince; if ($MWGUI.SitePostalCode) $MWGUI.SitePostalCode.innerHTML = Answer.Content.PostalCode; if ($MWGUI.SiteCountry) $MWGUI.SiteCountry.innerHTML = Answer.Content.Country; if ( Answer.Content.Phone != "") { if ($MWGUI.SitePhone) { $MWGUI.SitePhone.style.display = ""; $MWGUI.SitePhone.innerHTML = Answer.Content.Phone; } if ($MWGUI.phoneIcon) $MWGUI.phoneIcon.style.display=""; } else { if ($MWGUI.SitePhone) $MWGUI.SitePhone.style.display = "none"; if ($MWGUI.phoneIcon) $MWGUI.phoneIcon.style.display="none"; } if ( Answer.Content.email != "") { if ($MWGUI.SiteEmail) { $MWGUI.SiteEmail.style.display = ""; $MWGUI.SiteEmail.innerHTML = Answer.Content.email; } if ($MWGUI.emailIcon) $MWGUI.emailIcon.style.display=""; } else { if ($MWGUI.SiteEmail) $MWGUI.SiteEmail.style.display = "none"; if ($MWGUI.emailIcon) $MWGUI.emailIcon.style.display="none"; } } if (Callback != null) Callback(); }); }*/ this.InitMainMenu = function(InitOptions, Container = null) { if (parent.$MWGUI != null) { if (parent.$MWGUI != this ) { parent.$MWGUI.InitMainMenu(InitOptions, Container); return; } } if(Container == null) { $MWGUI.MainMenu.innerHTML = ""; if(InitOptions == null){ console.error("Please insert some options!"); return; } if(InitOptions.Pages == null) { console.error("Please insert some Pages!"); return; } } else { Container.innerHTML = ""; } //console.log("---------") //console.log(parent.$MWGUI); //console.log(InitOptions); //console.log("---------") for(var PageKey in InitOptions.Pages) { var divRow = document.createElement("div"); divRow.className = "main_menu_row decor-solid-border-bottom-dark"; if(Container == null) $MWGUI.MainMenu.appendChild(divRow); else Container.appendChild(divRow); divRow.parentNode.onclick =function() { //console.log("ciao!!!") } var divImage = document.createElement("div"); divImage.className +="resgui-1row resgui-halfcolumn align-items-center justify-content-center"; divRow.appendChild(divImage); var imageRow = document.createElement("img"); imageRow.src = InitOptions.Pages[PageKey].Icon; imageRow.className = "icon-image"; imageRow.addEventListener("error",function(){this.style.display="none"}); divImage.appendChild(imageRow); var spanText = document.createElement("span"); spanText.className = "letter-spacing-l resgui-font-height-s"; spanText.innerHTML = InitOptions.Pages[PageKey].Label; divRow.appendChild(spanText); if(InitOptions.Pages[PageKey].Children != undefined) { var IdNextContainer = null; if(Container == null) { switch ($MWGUI.MainMenu.id) { case "main_menu": {IdNextContainer = "main_submenu1"; break;} case "main_submenu1": {IdNextContainer = "main_submenu2"; break;} case "main_submenu2": {IdNextContainer = "main_submenu3"; break;} case "main_submenu3": {IdNextContainer = "main_submenu4"; break;} case "main_submenu4": {IdNextContainer = "main_submenu5"; break;} default: {IdNextContainer = null; break;} } } else { switch (Container) { case "main_menu": {IdNextContainer = "main_submenu1"; break;} case "main_submenu1": {IdNextContainer = "main_submenu2"; break;} case "main_submenu2": {IdNextContainer = "main_submenu3"; break;} case "main_submenu3": {IdNextContainer = "main_submenu4"; break;} case "main_submenu4": {IdNextContainer = "main_submenu5"; break;} default: {IdNextContainer = null; break;} } } //$MWGUI.InitMainMenu({"Pages":InitOptions.Pages[PageKey].Children}, $MWGUI.MainDocument.getElementById(IdNextContainer)); divRow.IdNextContainer = IdNextContainer; divRow.ElementContainer = (Container == null) ? $MWGUI.MainMenu : Container; divRow.Pages = InitOptions.Pages[PageKey].Children; divRow.addEventListener("click", function(){ $MWGUI.InitMainMenu({"Pages":this.Pages }, $MWGUI.MainDocument.getElementById(this.IdNextContainer)); var SubMenu = $MWGUI.MainDocument.getElementById(this.IdNextContainer); SubMenu.main_submenu_exit = " " + this.IdNextContainer + "_exit"; SubMenu.main_submenu_entry = " " + this.IdNextContainer + "_entry"; SubMenu.ParentMenu = this.ElementContainer; this.ElementContainer.SubMenu = SubMenu; if (this.ElementContainer.CurrentRow != null) if (this != this.ElementContainer.CurrentRow) { this.ElementContainer.CurrentRow.className = this.ElementContainer.CurrentRow.className.replace(" with_child",""); } if (this.className.indexOf("with_child") == -1) { this.className += " with_child"; this.ElementContainer.CurrentRow = this; var IdNextContainer; switch (this.IdNextContainer) { case "main_submenu1": {IdNextContainer = "main_submenu2"; break;} case "main_submenu2": {IdNextContainer = "main_submenu3"; break;} case "main_submenu3": {IdNextContainer = "main_submenu4"; break;} case "main_submenu4": {IdNextContainer = "main_submenu5"; break;} default: {IdNextContainer = null; break;} } if (SubMenu.className.indexOf(SubMenu.main_submenu_exit) > -1) SubMenu.className = SubMenu.className.replace(SubMenu.main_submenu_exit,""); if (SubMenu.className.indexOf(SubMenu.main_submenu_entry) == -1) SubMenu.className += SubMenu.main_submenu_entry; } else { this.className = this.className.replace(" with_child", ""); CloseSubMenu(SubMenu); this.ElementContainer.CurrentRow = null; } }); } else { if(InitOptions.Pages[PageKey].CustomFunction == undefined) { divRow.Path = InitOptions.Pages[PageKey].Location; divRow.Title = InitOptions.Pages[PageKey].PageTitle; divRow.addEventListener("click",function(){ $MWGUI.ChangePage(this.Title, this.Path); //console.log("test"); $MWGUI.HiddenMainMenu(); }); } else { divRow.CustomFunction = InitOptions.Pages[PageKey].CustomFunction; divRow.addEventListener("click",function(){ this.CustomFunction(); }); } //divRow.click(); } } //console.log("END") } function CloseSubMenu(SubMenu) { if (SubMenu.SubMenu != null) CloseSubMenu(SubMenu.SubMenu); if (SubMenu.className.indexOf(SubMenu.main_submenu_entry) > -1) SubMenu.className = SubMenu.className.replace(SubMenu.main_submenu_entry,""); if (SubMenu.className.indexOf(SubMenu.main_submenu_exit) == -1) SubMenu.className += SubMenu.main_submenu_exit; } this.HiddenMainMenu = function(){ for (var i = 1; i < 7; i++) { var ref = "main_submenu" + i; var Menu = $MWGUI.MainDocument.getElementById(ref); if (Menu != null) { if (Menu.className.indexOf(" " + ref + "_entry") > -1) { Menu.className = Menu.className.replace(" " + ref + "_entry",""); if (Menu.className.indexOf(" " + ref + "_exit") == -1) Menu.className +=" " + ref + "_exit"; } } } for (var childIndex in $MWGUI.MainMenu.childNodes) { var child = $MWGUI.MainMenu.childNodes[childIndex]; if (child.className != undefined && child.className != null) child.className = child.className.replace("with_child",""); } if ($MWGUI.MainMenu.className.indexOf("main_menu_entry") != -1) { $MWGUI.MainMenu.className = $MWGUI.MainMenu.className.replace(" main_menu_entry",""); $MWGUI.MainMenu.className +=" main_menu_exit"; $MWGUI.BlurDiv.style.display = "none"; } } this.ShowMainMenu = function(){ if ($MWGUI.MainMenu.className.indexOf("main_menu_entry") == -1) { $MWGUI.MainMenu.className = $MWGUI.MainMenu.className.replace(" main_menu_exit",""); $MWGUI.MainMenu.className +=" main_menu_entry"; $MWGUI.BlurDiv.style.display = "flex"; } } this.ToggleMainMenu = function(){ if ($MWGUI.MainMenu.className.indexOf("main_menu_entry") == -1) { $MWGUI.ShowMainMenu(); } else { $MWGUI.HiddenMainMenu(); } } this.ScanElements = function() { var Elements = document.getElementsByTagName('*'); for (var i = 0; i < Elements.length; i++) { var Datadictionary = []; for (var ia = 0; ia < Elements[i].attributes.length; ia++) { var Name = Elements[i].attributes[ia].nodeName.toLowerCase(); if (Name.indexOf('data-gui-mw') == 0) { var PrimeLinkArray = JSON.parse(Elements[i].attributes[ia].value); Elements[i][PrimeLinkArray["target"]] = $MWGUI.GetLanguageString(PrimeLinkArray["key"]); } if (Name.indexOf('data-gui-contextmenu') == 0){ try { var ContextMenu = document.getElementById(Elements[i].attributes[ia].value); if(ContextMenu!=null) if (ContextMenu.className.indexOf("ContextMenu") > -1) { var Parent = ContextMenu.parentNode; ContextMenu.parentNode.removeChild(ContextMenu); ContextMenu.className = ContextMenu.className.replace("ContextMenu",""); ContextMenu.className += " ContextMenuContent"; var NewMenu = document.createElement("div"); NewMenu.className ="fullContextMenu"; Parent.appendChild(NewMenu); var NewMenuHeader = document.createElement("div"); NewMenuHeader.className = "fullContextMenuHeader"; NewMenuHeader.addEventListener("click", function(event){ NewMenu.style.display ="none"; }); var NewMenuHeaderContent = document.createElement("div"); NewMenuHeaderContent.className="fullContextMenuHeaderContent"; NewMenuHeader.appendChild(NewMenuHeaderContent); var Close = document.createElement("span"); Close.innerHTML ="X"; NewMenuHeaderContent.appendChild(Close); NewMenu.appendChild(NewMenuHeader); ContextMenu.addEventListener("click",function(){NewMenu.style.display ="none";}); NewMenu.appendChild(ContextMenu); var footer = document.createElement("div"); footer.className="fullContextMenuFooter"; NewMenu.appendChild(footer); Elements[i].ContextMenu = NewMenu; Elements[i].style.cursor ="pointer"; Elements[i].addEventListener("click", function(e){ ShowContextMenu(e); }); } } catch (err) {console.error(err)} } } } try { //$MWGUI.EndInitialize(); } catch (err){} } this.LoadPrimeGateView = function(TemplateObject, DeviceObject, IframeElement) { var HTMLTemplatePages = JSON.parse(TemplateObject["HTMLPage"]["HTMLTemplatePages"]); IframeElement.src = "../../../../../../../../../../PrimeGate/DeviceTemplates/" + HTMLTemplatePages[0].Url; IframeElement.addEventListener('load', function(){ IframeElement.contentWindow.$MWGUI.LoadDeviceViewCallback(TemplateObject, DeviceObject); }); } this.RegisterMaster=function(){ if (parent.$MWGUI != null) { parent.$MWGUI.Master = this; } } this.RegisterDetail=function(LoadDetail){ if (parent.$MWGUI != null) { parent.$MWGUI.Detail = this; } } this.ShowDetail=function(Item){ if (parent.$MWGUI != null) { if (parent.$MWGUI.Detail.LoadDetail != null) parent.$MWGUI.Detail.LoadDetail(Item) } } this.UpdateMasterFromDetail=function(Item){ if (parent.$MWGUI != null) { if (parent.$MWGUI.Master.OnUpdateDetail != null) parent.$MWGUI.Master.OnUpdateDetail(Item) } } this.DeleteMasterFromDetail=function(Item){ if (parent.$MWGUI != null) { if (parent.$MWGUI.Master.OnDeleteDetail != null) parent.$MWGUI.Master.OnDeleteDetail(Item) } } } var $MWGUI = new TMWGUI(); if (window.addEventListener) { window.addEventListener('load', function () { $MWGUI.Initialize(); }) } else { window.attachEvent('onload', function () { $MWGUI.Initialize(); }) }