1Widgets.SiteUserToolbar = function (options = null) { 2 this.className = "defaultSiteUserToolbarContainer"; 3 4 Widgets.BaseWidget.call(this, "/Widgets/SiteUser/SiteUserToolbar", this.className); 5 6 //custom overriding options 7 BaseHelper.MergeIntoObject(this, options); 8 9 this._setup = function () { 10 Widgets.BaseWidget.prototype._setup.call(this); 11 this.onUpdateSiteUserToolbarCompleteArr = []; 12 this.onLogoutCompleteArr = []; 13 this.LoggedIn = false; 14 }; 15 16 this.getLoadData = async function () { 17 let result = await Widgets.BaseWidget.prototype.getLoadData.call(this); 18 this.sulLoginModal = await BaseHelper.CreateModal("SiteUserLoginModal", "Welcome"); 19 $(this.sulLoginModal.modal).on('hidden.bs.modal', (e) => { 20 if (this.onLoginHide != null) { 21 this.onLoginHide(e); 22 } 23 }) 24 this.sulWidget = new Widgets.SiteUserLogin(); 25 this.sulWidget._initialize(); 26 this.sulWidget.onSaveComplete = this.UpdateSiteUserToolbar; 27 this.sulLoginModal.body.appendChild(this.sulWidget.element); 28 return result; 29 }; 30 31 this.DisplayLogin = async () => { 32 this.sulWidget.onReady((e) => { 33 this.sulWidget.refresh() 34 $(this.sulLoginModal.modal).modal("show"); 35 }); 36 }; 37 38 this.GetSiteUserData = async () => { 39 let json_data = await BaseHelper.MakeAJAXPostJSONRequest("/api/SiteUser/SiteUserStatus"); 40 let data = JSON.parse(json_data); 41 //console.log("SiteUserStatus", data); 42 this.LoggedIn = data.LoggedIn; 43 this.WebsiteTypeTblID = data.WebsiteTypeTblID; 44 //console.log("this.WebsiteTypeTblID", this.WebsiteTypeTblID); 45 return data; 46 } 47 48 this.UpdateSiteUserToolbar = async () => { 49 50 this.profileDropdown.classList.add("disabled"); 51 this.btnLogin.classList.add("disabled"); 52 53 this.profileDropdown.classList.remove("disabled"); 54 this.btnLogin.classList.remove("disabled"); 55 56 let data = await this.GetSiteUserData(); 57 if (data == null) { 58 return; 59 } 60 if (data.WebsiteTypeTblID == 3) { 61 this.profileDropdown.classList.add("d-none"); 62 this.btnLogin.classList.add("d-none"); 63 } 64 else { 65 this.profileDropdown.classList.remove("d-none"); 66 this.btnLogin.classList.remove("d-none"); 67 } 68 69 this.currentData = data; 70 if (data.LoggedIn == true) { 71 this.SetLoggedIn(true); 72 let fn = data.SiteUser[0]["FirstName"]; 73 let ln = data.SiteUser[0]["LastName"]; 74 let initial = "N/A"; 75 if ( 76 fn != null && 77 ln != null && 78 fn.length > 0 && 79 ln.length > 0 80 ) { 81 initial = fn.substr(0, 1).toUpperCase(); 82 initial += ln.substr(0, 1).toUpperCase(); 83 } 84 this.profileDropdownButton.innerText = initial; 85 if ($(this.sulLoginModal.modal).is(':visible')) { 86 $(this.sulLoginModal.modal).modal("hide"); 87 } 88 } 89 else { 90 this.SetLoggedIn(false); 91 } 92 if (this.onUpdateSiteUserToolbarCompleteArr.length > 0) { 93 this.onUpdateSiteUserToolbarCompleteArr.forEach((onUpdate) => { 94 onUpdate(); 95 }); 96 } 97 }; 98 99 100 101 this.SetLoggedIn = function (LoggedIn) { 102 this.LoggedIn = LoggedIn; 103 if (LoggedIn == true) { 104 this.btnLogin.style.display = "none" 105 this.profileDropdown.style.display = "block" 106 } 107 else { 108 this.btnLogin.style.display = "block" 109 this.profileDropdown.style.display = "none" 110 } 111 }; 112 113 this.onTemplateLoad = async function () { 114 let divSiteUserToolbar = this.divSiteUserToolbar = this.element.querySelector(".SiteUserToolbar"); 115 this.btnLogin = divSiteUserToolbar.querySelector(".btnLogin"); 116 this.btnManage = divSiteUserToolbar.querySelector(".btnManage"); 117 this.btnLogout = divSiteUserToolbar.querySelector(".btnLogout"); 118 this.profileDropdown = divSiteUserToolbar.querySelector(".profileDropdown"); 119 this.profileDropdownButton = divSiteUserToolbar.querySelector(".profileDropdown button"); 120 this.btnLogin.addEventListener("click", (e) => { 121 this.sulWidget.onReady((e) => { 122 if (this.btnLogin.classList.contains("disabled")) { 123 return; 124 } 125 if (!window.location.pathname.includes("/SiteUserRegistration")) { 126 let url = window.location.href; 127 window.location = "/SiteUserRegistration?target=" + encodeURIComponent(url); 128 } 129 //this.sulWidget.clearFields(); 130 //this.sulWidget.refresh(); 131 //$(this.sulLoginModal.modal).modal("show"); 132 }); 133 }); 134 this.btnLogout.addEventListener("click", async (e) => { 135 if (this.btnLogout.classList.contains("disabled")) { 136 return; 137 } 138 this.btnLogout.classList.add("disabled"); 139 this.profileDropdown.classList.add("disabled"); 140 await BaseHelper.MakeAJAXPostJSONRequest("/api/SiteUser/Logout"); 141 this.btnLogout.classList.remove("disabled"); 142 this.profileDropdown.classList.remove("disabled"); 143 await this.UpdateSiteUserToolbar(); 144 if (this.onLogoutCompleteArr != null) { 145 this.onLogoutCompleteArr.forEach((f) => { 146 f(this); 147 }) 148 } 149 }); 150 await this.UpdateSiteUserToolbar(); 151 }; 152} 153Widgets.SiteUserToolbar.prototype = new Widgets.SiteUserToolbar();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.