var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var sw_266; (function (sw_266) { sw_266.LOGO = "logo"; sw_266.LOGOLONG = "logolong"; sw_266.MODAL = "modal"; sw_266.POPUP = "popup"; })(sw_266 || (sw_266 = {})); var sw_266; (function (sw_266) { /** * Publishes some sort of event that other object(s) will receive a message. */ var Publisher = /** @class */ (function () { function Publisher() { this.listeners = []; } Publisher.prototype.addListener = function (listener) { this.listeners.push(listener); }; Publisher.prototype.removeListener = function (listener) { for (var x = 0; x < this.listeners.length; x++) { if (this.listeners[x] == listener) { this.listeners.splice(x, 1); return; } } }; Publisher.prototype.publish = function (func) { var temp = []; for (var x = 0; x < this.listeners.length; x++) { temp.push(this.listeners[x]); } for (var x = 0; x < temp.length; x++) { func(temp[x]); } }; return Publisher; }()); sw_266.Publisher = Publisher; })(sw_266 || (sw_266 = {})); var sw_266; (function (sw_266) { /********************************************************************************************************************************** * Base class for all components. * This is structured in a way so that it doesnt create any html elements until you call setParent(). * Until then there is no reason to create a bunch of stuff and waste memory if you dont put it on the * screen. Thats why you see the setParent() method actually call build functions. Which you * must implement. * You should override the build method to build the actual HTML element you need. All of the elements you * need should be children of the "element" property of this class. You will need to create the "element" property * also during the build method. */ var Component = /** @class */ (function () { function Component() { this.componentId = window['system'].nextUniqueNumber(); this.parent = null; this.element = null; } Component.prototype.getComponentID = function () { return this.componentId; }; Component.prototype.$ = function (id) { return document.querySelector('#' + this.element.className + this.componentId + ' #' + id); }; /** * Should be able to set the parent of a component. */ Component.prototype.setParent = function (parms) { var parentBefore; if (parms.parent == this.parent) { return; } parentBefore = this.parent; if (this.parent != null) { if (parms.parent == null) { this.beforeRemovedFromDOM(); } if (this.element.parentElement == this.parent) { this.parent.removeChild(this.element); } } this.parent = parms.parent; if (this.parent == null) { if (parentBefore != null) { this.afterRemovedFromDOM(); } } else { if (!this.isBuilt()) { this.build(); } if (parentBefore == null && this.parent != null) { this.beforeAddedToDOM(); } this.parent.appendChild(this.element); if (parentBefore == null && this.parent != null) { this.afterAddedToDOM(); } } }; /** * Used to see if the component has been built or not. So, we wont build again, etc. */ Component.prototype.isBuilt = function () { if (this.element == null) { return false; } return true; }; /** * Some components need to know exactly when they are added to the DOM so they can setup certain javascript. * This lets those components override this method to setup that javascript. */ Component.prototype.beforeAddedToDOM = function () { }; /** * Some components need to know exactly when they are added to the DOM so they can setup certain javascript. * This lets those components override this method to setup that javascript. */ Component.prototype.afterAddedToDOM = function () { }; /** * Some components need to know exactly when they are remove from the DOM so they can remove certain javascript. * This lets those components override this method to remove that javascript. */ Component.prototype.beforeRemovedFromDOM = function () { }; /** * Some components need to know exactly when they are remove from the DOM so they can remove certain javascript. * This lets those components override this method to remove that javascript. */ Component.prototype.afterRemovedFromDOM = function () { }; /** * Returns the parent html element for this component. */ Component.prototype.getParent = function () { return this.parent; }; /** * Returns the element for this component. */ Component.prototype.getElement = function () { this.build(); return this.element; }; return Component; }()); sw_266.Component = Component; })(sw_266 || (sw_266 = {})); var sw_266; (function (sw_266) { function toDate(epoch) { if (epoch == 0 || epoch == null) { return null; } return new Date(epoch * 1000); } sw_266.toDate = toDate; function toEpoch(date) { if (date == null) { return null; } return date.getTime() / 1000; } sw_266.toEpoch = toEpoch; })(sw_266 || (sw_266 = {})); /// var sw_266; (function (sw_266) { var YearMonthDay = /** @class */ (function () { function YearMonthDay(year, month, day) { this.value = year * 10000; this.value = this.value + (month * 100); this.value = this.value + day; } YearMonthDay.fromDate = function (date) { var ymd; if (date == null) { ymd = new YearMonthDay(0, 0, 0); ymd.value = null; return ymd; } return new YearMonthDay(date.getFullYear(), date.getMonth() + 1, date.getDate()); }; YearMonthDay.fromEpoch = function (epoch) { var ymd; if (epoch == 0 || epoch == null) { ymd = new YearMonthDay(0, 0, 0); ymd.value = null; return ymd; } var date = sw_266.toDate(epoch); return new YearMonthDay(date.getFullYear(), date.getMonth() + 1, date.getDate()); }; YearMonthDay.prototype.getValue = function () { return this.value; }; return YearMonthDay; }()); sw_266.YearMonthDay = YearMonthDay; })(sw_266 || (sw_266 = {})); /// /// /// /// var sw_266; (function (sw_266) { var Dim = /** @class */ (function () { function Dim() { } return Dim; }()); sw_266.Dim = Dim; function getDim(e) { var dim = new Dim(); dim.bounds = e.getBoundingClientRect(); dim.style = window.getComputedStyle(e); dim.boxSizing = dim.style.boxSizing; dim.marginRight = parseInt(dim.style.marginRight) || 0; dim.marginLeft = parseInt(dim.style.marginLeft) || 0; dim.marginTop = parseInt(dim.style.marginTop) || 0; dim.marginBottom = parseInt(dim.style.marginBottom) || 0; dim.paddingRight = parseInt(dim.style.paddingRight) || 0; dim.paddingLeft = parseInt(dim.style.paddingLeft) || 0; dim.paddingTop = parseInt(dim.style.paddingTop) || 0; dim.paddingBottom = parseInt(dim.style.paddingBottom) || 0; dim.borderRight = parseInt(dim.style.borderRightWidth) || 0; dim.borderLeft = parseInt(dim.style.borderLeftWidth) || 0; dim.borderBottom = parseInt(dim.style.borderBottomWidth) || 0; dim.borderTop = parseInt(dim.style.borderTopWidth) || 0; if (dim.boxSizing == 'content-box') { dim.outerWidth = dim.bounds.width + dim.marginLeft + dim.marginRight; dim.outerHeight = dim.bounds.height + dim.marginTop + dim.marginBottom; } else { dim.outerWidth = dim.bounds.width; dim.outerHeight = dim.bounds.height; } dim.innerWidth = dim.bounds.width - (dim.borderLeft + dim.borderRight); dim.innerHeight = dim.bounds.height - (dim.borderTop + dim.borderBottom); dim.offsetLeft = dim.marginLeft + dim.borderLeft; dim.offsetTop = dim.marginTop + dim.borderTop; dim.offsetRight = dim.marginRight + dim.borderRight; dim.offsetBottom = dim.marginBottom + dim.borderBottom; dim.extraWidth = dim.offsetLeft + dim.offsetRight; dim.extraHeight = dim.offsetTop + dim.offsetBottom; var rec2 = e.parentElement.getBoundingClientRect(); dim.rel = { left: dim.bounds.left - rec2.left, top: dim.bounds.top - rec2.top, width: dim.bounds.width, height: dim.bounds.height, bottom: dim.bounds.bottom - rec2.top, right: dim.bounds.right - rec2.left }; return dim; } sw_266.getDim = getDim; function escapeHtml(str) { if (str == null) { return ""; } var div = document.createElement('div'); div.appendChild(document.createTextNode(str)); return div.innerHTML; } sw_266.escapeHtml = escapeHtml; /** * Use this one when you are putting a value into an input. Vs, the other escape function you are outputing html. */ function escapeQuotes(str) { if (str == null) { return ""; } return str.replace(/"/g, """); } sw_266.escapeQuotes = escapeQuotes; function startsWith(str, searchString) { return str.substr(0, searchString.length) === searchString; } sw_266.startsWith = startsWith; function toNum(value) { if (value == null) { return null; } if (value.trim().length == 0) { return null; } return Number(value); } sw_266.toNum = toNum; function nextUniqueID() { return 'id' + window['system'].nextUniqueNumber(); } sw_266.nextUniqueID = nextUniqueID; function checkField(name, value, checks, alertErrors) { if (alertErrors === void 0) { alertErrors = true; } if (checks.hasOwnProperty('required')) { if (value == null) { if (alertErrors) { alert(name + ' is required.'); } return false; } if (value.trim().length == 0) { if (alertErrors) { alert(name + ' is required.'); } return false; } } if (checks.hasOwnProperty('numeric') || checks.hasOwnProperty('maxDecimals')) { if (value != null) { if (value.trim().length > 0) { if (!isNumeric(value)) { if (alertErrors) { alert(name + ' must be a number.'); } return false; } } } } if (checks.hasOwnProperty('maxDecimals')) { var s = '' + value; var num = 0; for (var x = s.length - 1; x >= 0; x--) { if (s.charAt(x) == '.') { num = (s.length - 1) - x; break; } } if (num > checks.maxDecimals) { if (alertErrors) { alert(name + ' must have no more than ' + checks.maxDecimals + ' decimal places.'); } return false; } } return true; } sw_266.checkField = checkField; function isNumeric(val) { if (isNaN(val) || isNaN(parseFloat(val))) { return false; } return true; } sw_266.isNumeric = isNumeric; function setOuterRect(element, width, height) { var dim = getDim(element); if (dim.boxSizing == 'content-box') { element.style.width = (width - (dim.marginLeft + dim.borderLeft + dim.paddingLeft + dim.paddingRight + dim.borderRight + dim.marginRight)) + 'px'; element.style.height = (height - (dim.marginTop + dim.borderTop + dim.paddingTop + dim.paddingBottom + dim.borderBottom + dim.marginBottom)) + 'px'; } else { element.style.width = width + 'px'; element.style.height = height + 'px'; } } sw_266.setOuterRect = setOuterRect; function setOuterWidth(element, width) { var dim = getDim(element); if (dim.boxSizing == 'content-box') { element.style.width = (width - (dim.marginLeft + dim.borderLeft + dim.paddingLeft + dim.paddingRight + dim.borderRight + dim.marginRight)) + 'px'; } else { element.style.width = width + 'px'; } } sw_266.setOuterWidth = setOuterWidth; function setOuterHeight(element, height) { var dim = getDim(element); if (dim.boxSizing == 'content-box') { element.style.height = (height - (dim.marginTop + dim.borderTop + dim.paddingTop + dim.paddingBottom + dim.borderBottom + dim.marginBottom)) + 'px'; } else { element.style.height = height + 'px'; } } sw_266.setOuterHeight = setOuterHeight; function buildCountrySelect(select) { var ALL_COUNTRIES = [ "US", "Afghanistan", "Akrotiri", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Ashmore and Cartier Islands", "Australia", "Austria", "Azerbaijan", "Bahamas, The", "Bahrain", "Bangladesh", "Barbados", "Bassas da India", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burma", "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Clipperton Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Congo", "Cook Islands", "Coral Sea Islands", "Costa Rica", "Cote d'Ivoire", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", "Dhekelia", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Ethiopia", "Europa Island", "Falkland Islands (Islas Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern and Antarctic Lands", "Gabon", "Gambia, The", "Gaza Strip", "Georgia", "Germany", "Ghana", "Gibraltar", "Glorioso Islands", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island and McDonald Islands", "Holy See (Vatican City)", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Jan Mayen", "Japan", "Jersey", "Jordan", "Juan de Nova Island", "Kazakhstan", "Kenya", "Kiribati", "Korea, North", "Korea, South", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macau", "Macedonia", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia, Federated States of", "Moldova", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Namibia", "Nauru", "Navassa Island", "Nepal", "Netherlands", "Netherlands Antilles", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paracel Islands", "Paraguay", "Peru", "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar", "Reunion", "Romania", "Russia", "Rwanda", "Saint Helena", "Saint Kitts and Nevis", "Saint Lucia", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "Spain", "Spratly Islands", "Sri Lanka", "Sudan", "Suriname", "Svalbard", "Swaziland", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tromelin Island", "Tunisia", "Turkey", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "Uruguay", "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands", "Wake Island", "Wallis and Futuna", "West Bank", "Western Sahara", "Yemen", "Zambia", "Zimbabwe" ]; select.options.length = 0; for (var x = 0; x < ALL_COUNTRIES.length; x++) { select.options.add(new Option(ALL_COUNTRIES[x], ALL_COUNTRIES[x])); } } sw_266.buildCountrySelect = buildCountrySelect; })(sw_266 || (sw_266 = {})); /// var sw_266; (function (sw_266) { /** * A set of common abstract classes and interfaces that should not change. This way * the implementing classes may change with versions, but the interfaces should stay the * same. */ var System = /** @class */ (function () { function System() { } return System; }()); sw_266.System = System; /** * This represents the location of a server and if the javascript for that server * has been loaded then it stores it. */ var ApplicationLocation = /** @class */ (function () { function ApplicationLocation() { } return ApplicationLocation; }()); sw_266.ApplicationLocation = ApplicationLocation; var Application = /** @class */ (function () { function Application() { } return Application; }()); sw_266.Application = Application; var DivSession = /** @class */ (function (_super) { __extends(DivSession, _super); function DivSession() { return _super !== null && _super.apply(this, arguments) || this; } return DivSession; }(sw_266.Component)); sw_266.DivSession = DivSession; var Session = /** @class */ (function () { function Session() { } return Session; }()); sw_266.Session = Session; var SystemLogonResult = /** @class */ (function () { function SystemLogonResult() { } return SystemLogonResult; }()); sw_266.SystemLogonResult = SystemLogonResult; var ApplicationLogonResult = /** @class */ (function () { function ApplicationLogonResult() { } return ApplicationLogonResult; }()); sw_266.ApplicationLogonResult = ApplicationLogonResult; })(sw_266 || (sw_266 = {})); var sw_266; (function (sw_266) { /********************************************************************************************************************************** * Base class for different types of popups. * Takes over the entire screen and disables all inputs when shown. Then * reenables all inputs that were enabled before when it is done. */ var Popup = /** @class */ (function (_super) { __extends(Popup, _super); function Popup(allowEsc) { if (allowEsc === void 0) { allowEsc = true; } var _this = _super.call(this) || this; _this.allowEsc = allowEsc; return _this; } Popup.prototype.show = function () { this.setParent({ parent: document.body }); }; Popup.prototype.hide = function () { this.setParent({ parent: null }); }; Popup.prototype.keyUp = function (event) { if (!this.allowEsc) { return false; } if (event.keyCode == 27) { this.back(); return false; } if (event.keyCode == 8) { if (document.activeElement && (document.activeElement.type == 'text' || document.activeElement.type == 'textarea' || document.activeElement.type == 'select-one')) { return true; } this.back(); return false; } // since this is a popup, no other controls on the screen should get any keyboard events but this one. return false; }; Popup.prototype.beforeAddedToDOM = function () { var sys; _super.prototype.afterAddedToDOM.call(this); sys = window['system']; sys.getBackButtonManager().push(this); sys.disableInputs(); sys.addKeyUpListener(this); }; Popup.prototype.afterRemovedFromDOM = function () { var sys; _super.prototype.afterRemovedFromDOM.call(this); sys = window['system']; sys.getBackButtonManager().pop(this); sys.enableInputs(); sys.removeKeyUpListener(this); }; Popup.prototype.build = function () { var table; var tbody; var tr; var td; var me = this; this.element = document.createElement('table'); this.element.className = 'POPUP2'; this.element.id = this.element.className + this.componentId; this.element.onclick = function (event) { var dim; if (event.clientX < 0 || event.clientY < 0) { return; } //console.log('clientX: ' + event.clientX + ', clientY: ' + event.clientY + ', ' + event.srcElement + ', ' + event.target + ', ' + (event.target == me.element.rows[0].cells[0])); dim = sw_266.getDim(me.element.rows[0].cells[0].firstElementChild); if (!(event.clientX >= dim.bounds.left && event.clientX < dim.bounds.right && event.clientY >= dim.bounds.top && event.clientY <= dim.bounds.bottom)) { if (!event.target || (me.element.rows[0].cells[0] == event.target)) { console.log('back called again'); me.back(); } } }; tbody = document.createElement('tbody'); this.element.appendChild(tbody); tr = tbody.insertRow(); td = tr.insertCell(); td.align = 'center'; td.vAlign = 'center'; table = document.createElement('table'); table.className = 'POPUP_CONTENT'; td.appendChild(table); tbody = document.createElement('tbody'); table.appendChild(tbody); tr = tbody.insertRow(); td = tr.insertCell(); this.divMessage = document.createElement('div'); this.divMessage.className = sw_266.POPUP; td.appendChild(this.divMessage); }; Popup.prototype.buildTitleBar = function (title) { var table; var tbody; var tr; var td; var button; var me = this; table = document.createElement('table'); table.className = 'POPUP_TITLEBAR'; tbody = document.createElement('tbody'); table.appendChild(tbody); tr = tbody.insertRow(); td = tr.insertCell(); td.className = 'POPUP_TITLEBAR_LEFT'; td.innerHTML = title; td = tr.insertCell(); td.className = 'POPUP_TITLEBAR_RIGHT'; button = document.createElement('input'); button.type = 'button'; button.value = 'X'; button.onclick = function () { me.close(); }; td.appendChild(button); return table; }; /** * if you build a title bar, the close button on the title bar will simply call back. * which you can override if u want to put your custom functionality in instead. */ Popup.prototype.close = function () { this.back(); }; Popup.prototype.back = function () { if (!this.allowEsc) { return; } this.setParent({ parent: null }); }; /** * You may use html in your message in the popup. For example, *
Hey this is
multiple lines centered.
*/ Popup.prototype.setMessage = function (parms) { this.divMessage.innerHTML = parms.message; return this; }; return Popup; }(sw_266.Component)); sw_266.Popup = Popup; })(sw_266 || (sw_266 = {})); /// /// var sw_266; (function (sw_266) { var SCRIPT_VERSION_NAME = "version.jsp"; var SCRIPT_FILE_NAME = "application.js"; var SystemImp = /** @class */ (function (_super) { __extends(SystemImp, _super); function SystemImp() { var _this = _super.call(this) || this; _this.locations = []; _this.backButtonManager = new BackButtonManagerImpl(); _this.inputDisablerStack = []; _this.listenersKeyUp = []; _this.divMain = null; _this.uniqueID = 0; window['system'] = _this; return _this; } SystemImp.prototype.nextUniqueNumber = function () { this.uniqueID++; return this.uniqueID; }; SystemImp.prototype.setDivMain = function (divMain) { this.divMain = divMain; }; SystemImp.prototype.createSystemMenu = function (text) { if (this.divMain == null) { return null; } return this.divMain.createSystemMenu(text); }; SystemImp.prototype.addSystemMenu = function (menu) { if (this.divMain == null) { return; } this.divMain.addSystemMenu(menu); }; SystemImp.prototype.addSystemMenus = function (menu) { if (this.divMain == null) { return; } this.divMain.addSystemMenus(menu); }; SystemImp.prototype.clearSystemMenus = function () { if (this.divMain == null) { return; } this.divMain.clearSystemMenus(); }; SystemImp.prototype.removeSystemMenu = function (menu) { if (this.divMain == null) { return; } this.divMain.removeSystemMenu(menu); }; SystemImp.prototype.openWithPost = function (url, parms) { var input; var target = 't' + sw_266.nextUniqueID(); var form = document.createElement('form'); form.setAttribute('method', 'post'); form.setAttribute('action', url); form.setAttribute('target', target); for (var i in parms) { if (parms.hasOwnProperty(i)) { input = document.createElement('input'); input.type = 'hidden'; input.name = i; input.value = parms[i]; form.appendChild(input); } } document.body.appendChild(form); window.open("blank.html", target); form.submit(); document.body.removeChild(form); }; SystemImp.prototype.addKeyUpListener = function (listener) { var me = this; this.listenersKeyUp.push(listener); if (document.onkeyup == null) { document.onkeyup = function (event) { // copy the list first, in case one of the listeners removes itself during the propogation of the event. var temp = []; for (var x = 0; x < me.listenersKeyUp.length; x++) { temp.push(me.listenersKeyUp[x]); } for (var x = temp.length - 1; x >= 0; x--) { if (!temp[x].keyUp(event)) { return; } } }; } }; SystemImp.prototype.removeKeyUpListener = function (listener) { var me = this; for (var x = 0; x < me.listenersKeyUp.length; x++) { if (me.listenersKeyUp[x] == listener) { me.listenersKeyUp.splice(x, 1); break; } } if (me.listenersKeyUp.length == 0) { document.onkeyup = null; } }; SystemImp.prototype.logon = function (name, password, callback) { var me = this; var index; var hostName; var hostNames; var result; var serverResult; var applicationLocation; var popup; popup = new sw_266.Popup(false); index = name.indexOf("@"); if (index > -1) { // only try to login to the company on the one server that they specify. hostName = name.substring(index + 1); name = name.substring(0, index); hostNames = [this.normalizeHostCandidate(hostName)]; } else { // try to login to the company on any server we can. hostNames = this.getConfiguredLogonHosts(); } result = new SystemLogonResultImp(name); popup.setParent({ parent: document.body }); popup.setMessage({ message: "
Connecting to servers
Please wait...
" }); callback.logonStarting(me, result); for (var x = 0; x < hostNames.length; x++) { hostName = hostNames[x]; applicationLocation = this.getApplicationLocation(window.location.protocol, hostName); if (applicationLocation == null) { applicationLocation = new ApplicationLocationImp(window.location.protocol, hostName); this.locations.push(applicationLocation); } serverResult = new ApplicationLogonResultImp(result, applicationLocation); applicationLocation.load({ beforeVersionRead: function (location) { callback.beforeVersionRead(me, location); }, versionRead: function (location, version) { // tell the logon callback that the version page was read. callback.versionRead(me, location, version); }, versionChanged: function (location, oldVersion, newVersion) { callback.versionChanged(me, location, oldVersion, newVersion); }, httpError2: function (location, page, status, responseText) { serverResult.page = page; serverResult.status = status; serverResult.text = responseText; result.logonsHttpError.push(serverResult); callback.httpError2(me, location, page, status, responseText); if (result.countFinished() == hostNames.length) { // finished popup.setParent({ parent: null }); callback.logonFinished(me, result); } }, beforeLoading: function (location) { callback.beforeLoading(me, location); }, loaded: function (location, api) { callback.loaded(me, location, api); api.logon({ name: name, password: password, callback: { httpError: function (application, protocol, hostName, status, responseText) { serverResult.text = 'HTTP error occured trying to communicate with ' + protocol + '//' + hostName; result.logonsFailed.push(serverResult); callback.logonFailed(me, api, serverResult.text); if (result.countFinished() == hostNames.length) { // finished popup.setParent({ parent: null }); callback.logonFinished(me, result); } }, logonFailed: function (api, message) { serverResult.text = message; result.logonsFailed.push(serverResult); callback.logonFailed(me, api, message); if (result.countFinished() == hostNames.length) { // finished popup.setParent({ parent: null }); callback.logonFinished(me, result); } }, logonCompleted: function (api, session) { serverResult.session = session; result.logonsCompleted.push(serverResult); callback.logonCompleted(me, api, session); if (result.countFinished() == hostNames.length) { // finished popup.setParent({ parent: null }); callback.logonFinished(me, result); } } } }); }, timedOutLoadingScript: function (location) { result.logonsTimedOut.push(serverResult); callback.timedOutLoadingScript(me, location); if (result.countFinished() == hostNames.length) { // finished popup.setParent({ parent: null }); callback.logonFinished(me, result); } } }); } if (result.countFinished() == hostNames.length) { // finished popup.setParent({ parent: null }); callback.logonFinished(me, result); } }; SystemImp.prototype.getApplicationLocations = function () { return this.locations; }; SystemImp.prototype.getApplicationLocation = function (protocol, hostName) { for (var x = 0; x < this.locations.length; x++) { if (this.locations[x].getProtocol() == protocol && this.locations[x].getHostName() == hostName) { return this.locations[x]; } } return null; }; SystemImp.prototype.getConfiguredLogonHosts = function () { var hostNames = []; var configured = window['smartwerksDiscoveryHosts']; if (typeof configured === "string") { this.addHostCandidates(hostNames, configured.split(/[,\n\r;]+/)); } else if (configured != null && configured.length != null) { this.addHostCandidates(hostNames, configured); } if (hostNames.length == 0) { hostNames = this.buildDefaultLogonHosts(); } this.addHostName(hostNames, window.location.host); return hostNames; }; SystemImp.prototype.buildDefaultLogonHosts = function () { var hostNames = []; var currentHostName = window.location.hostname.toLowerCase(); var pieces = currentHostName.split("."); var subdomain; var rootDomain; var defaults = [ "app", "app1", "app2", "app3", "preferred", "preferred1", "preferred2", "preferred3", "prod", "disaster", "disaster1", "disaster2", "disaster3", "disaster4", "disaster5", "disaster6", "disaster7" ]; if (pieces.length > 2) { subdomain = pieces[0]; rootDomain = pieces.slice(1).join("."); if (/^(app[0-9]*|preferred[0-9]*|prod|disaster[0-9]*)$/.test(subdomain)) { for (var x = 0; x < defaults.length; x++) { this.addHostName(hostNames, defaults[x] + "." + rootDomain); } } } if (hostNames.length == 0) { this.addHostName(hostNames, window.location.host); } return hostNames; }; SystemImp.prototype.addHostCandidates = function (hostNames, candidates) { for (var x = 0; x < candidates.length; x++) { this.addHostName(hostNames, candidates[x]); } }; SystemImp.prototype.addHostName = function (hostNames, candidate) { var normalized = this.normalizeHostCandidate(candidate); if (normalized.length == 0) { return; } for (var x = 0; x < hostNames.length; x++) { if (hostNames[x].toLowerCase() == normalized.toLowerCase()) { return; } } hostNames.push(normalized); }; SystemImp.prototype.normalizeHostCandidate = function (candidate) { var link; var slashIndex; if (candidate == null) { return ""; } candidate = candidate.trim(); if (candidate.length == 0) { return ""; } if (candidate.indexOf("://") > -1) { link = document.createElement("a"); link.href = candidate; return link.host; } slashIndex = candidate.indexOf("/"); if (slashIndex > -1) { candidate = candidate.substring(0, slashIndex); } return candidate; }; SystemImp.prototype.disableInputs = function () { var inputDisabler; inputDisabler = new InputDisabler(); this.inputDisablerStack.push(inputDisabler); inputDisabler.disable(); }; SystemImp.prototype.enableInputs = function () { var inputDisabler; if (this.inputDisablerStack.length == 0) { console.log('couldnt get an input disabler, something is wrong, check your code.'); return; } inputDisabler = this.inputDisablerStack.pop(); inputDisabler.enable(); }; SystemImp.prototype.getBackButtonManager = function () { return this.backButtonManager; }; SystemImp.prototype.setStyleSheetName = function (name) { var list; //var list: NodeListOf; var index; var path; // first figure out where we are storing the css goodies. path = "/"; if (document.styleSheets.length > 0) { index = document.styleSheets[0].href.lastIndexOf("/"); if (index > -1) { path = document.styleSheets[0].href.substring(0, index + 1); } } // get rid of all the style sheet links. list = document.getElementsByTagName('link'); for (var x = 0; x < list.length; x++) { list.item(x).parentNode.removeChild(list.item(x)); } var head = document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.rel = 'stylesheet'; link.type = 'text/css'; link.href = path + name + '.css'; link.href = ""; head.appendChild(link); }; SystemImp.prototype.getStyleSheetName = function () { var index; var name; if (document.styleSheets.length > 0) { index = document.styleSheets[0].href.lastIndexOf("/"); if (index > -1) { name = document.styleSheets[0].href.substring(index + 1); } else { name = document.styleSheets[0].href; } index = name.indexOf("."); if (index > -1) { name = name.substring(0, index); } return name; } return ""; }; SystemImp.prototype.loadScript = function (url) { console.log('loading script: ' + url); var node = document.createElement('script'); node.src = url; node.type = 'text/javascript'; node.async = true; node.charset = 'utf-8'; document.getElementsByTagName('head')[0].appendChild(node); }; SystemImp.prototype.setCookie = function (name, value, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toUTCString(); document.cookie = name + "=" + value + "; " + expires; }; SystemImp.prototype.getCookie = function (name) { var name = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; }; return SystemImp; }(sw_266.System)); sw_266.SystemImp = SystemImp; /******************************************************************************************************** * */ var SystemLogonResultImp = /** @class */ (function (_super) { __extends(SystemLogonResultImp, _super); function SystemLogonResultImp(name) { var _this = _super.call(this) || this; _this.logonsTimedOut = []; // timed out waiting for the script to load. _this.logonsHttpError = []; // http error occured when trying to read version.jsp page. _this.logonsCompleted = []; // got a login result. have a session. _this.logonsFailed = []; // bad user name/password, etc. _this.name = name; return _this; } SystemLogonResultImp.prototype.getLogonName = function () { return name; }; SystemLogonResultImp.prototype.getSessions = function () { var tmp = []; for (var x = 0; x < this.logonsCompleted.length; x++) { tmp.push(this.logonsCompleted[x].getSession()); } return tmp; }; SystemLogonResultImp.prototype.getTimedOut = function () { return this.logonsTimedOut; }; SystemLogonResultImp.prototype.getHttpError = function () { return this.logonsHttpError; }; SystemLogonResultImp.prototype.getCompleted = function () { return this.logonsCompleted; }; SystemLogonResultImp.prototype.getFailed = function () { return this.logonsFailed; }; SystemLogonResultImp.prototype.countFinished = function () { return this.logonsCompleted.length + this.logonsHttpError.length + this.logonsTimedOut.length + this.logonsFailed.length; }; return SystemLogonResultImp; }(sw_266.SystemLogonResult)); /******************************************************************************************************** * */ var ApplicationLogonResultImp = /** @class */ (function (_super) { __extends(ApplicationLogonResultImp, _super); function ApplicationLogonResultImp(logon, serverLocation) { var _this = _super.call(this) || this; _this.logon = logon; _this.serverLocation = serverLocation; return _this; } ApplicationLogonResultImp.prototype.getSystemLogonResult = function () { return this.logon; }; ApplicationLogonResultImp.prototype.getApplicationLocation = function () { return this.serverLocation; }; ApplicationLogonResultImp.prototype.getPage = function () { return this.page; }; ApplicationLogonResultImp.prototype.getStatus = function () { return this.status; }; ApplicationLogonResultImp.prototype.getText = function () { return this.text; }; ApplicationLogonResultImp.prototype.getSession = function () { return this.session; }; return ApplicationLogonResultImp; }(sw_266.ApplicationLogonResult)); /****************************************************************************************** * Loads up the javascript from a server. */ var ApplicationLocationImp = /** @class */ (function (_super) { __extends(ApplicationLocationImp, _super); function ApplicationLocationImp(protocol, hostName) { var _this = _super.call(this) || this; _this.loading = false; _this.protocol = protocol; _this.hostName = hostName; return _this; } ApplicationLocationImp.prototype.getProtocol = function () { return this.protocol; }; ApplicationLocationImp.prototype.getHostName = function () { return this.hostName; }; ApplicationLocationImp.prototype.getBaseURL = function () { return this.protocol + '//' + this.hostName; }; ApplicationLocationImp.prototype.getVersion = function () { return this.version; }; ApplicationLocationImp.prototype.getApplication = function () { return this.application; }; ApplicationLocationImp.prototype.load = function (callback) { var me = this; if (me.loading) { return; } me.loading = true; me.callback = callback; callback.beforeVersionRead(this); this.readPage(SCRIPT_VERSION_NAME, 3000, { pageRead: function (applicationLocation, page, text) { callback.versionRead(me, text.trim()); if (me.version == null) { me.version = text.trim(); me.loadAPI(); } else if (me.version != text.trim()) { // check it from before if it changes, we throw an event and load the new one. me.version = text.trim(); callback.versionChanged(me, me.version, text.trim()); me.loadAPI(); } else { // if it hasnt changed, we throw event that api was loaded. me.loading = false; if (me.callback != null) { me.callback.loaded(me, me.application); me.callback = null; } } }, httpError: function (applicationLocation, page, status, responseText) { // pass back the error and store it. me.status = status; me.responseText = responseText; me.loading = false; if (callback != null) { callback.httpError2(me, page, status, responseText); me.callback = null; } } }); }; /** * Posts data to a web page and returns a result. */ ApplicationLocationImp.prototype.post = function (page, data, callback, message) { var popup; var me = this; popup = new sw_266.Popup(false); var get = new XMLHttpRequest(); get.onreadystatechange = function () { if (get.readyState == 4) { popup.setParent({ parent: null }); if (get.status == 200) { callback.finished(me, page, get.responseText); } else { callback.httpError(me, page, get.status, get.statusText); } } }; popup.setParent({ parent: document.body }); if (message == null) { popup.setMessage({ message: "
Connecting to servers
Please wait...
" }); } else { popup.setMessage({ message: "
" + message + "
" }); } get.open("POST", this.protocol + "//" + this.hostName + "/" + page, true); get.timeout = 0; get.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); get.send("data=" + encodeURIComponent(JSON.stringify(data))); }; ApplicationLocationImp.prototype.readPage = function (page, timeout, callback) { if (timeout === void 0) { timeout = 3000; } var me = this; var popup; var get = new XMLHttpRequest(); popup = new sw_266.Popup(false); get.onreadystatechange = function () { if (get.readyState == 4) { popup.setParent({ parent: null }); if (get.status == 200) { callback.pageRead(me, page, get.responseText); } else { callback.httpError(me, page, get.status, get.statusText); } } }; popup.setParent({ parent: document.body }); popup.setMessage({ message: "
Connecting to servers
Please wait...
" }); // get.open("GET", location + "/version.jsp", true); get.open("GET", this.protocol + "//" + this.hostName + "/" + page, true); get.timeout = timeout; get.send(null); }; ApplicationLocationImp.prototype.loadAPI = function () { var me = this; var system; me.application = null; me.timeoutId = setTimeout(function () { // fire an event that we timed out trying to load the script. clearTimeout(me.timeoutId); me.timeoutId = 0; me.loading = false; if (me.callback != null) { me.callback.timedOutLoadingScript(me); me.callback = null; } }, 30000); system = window['system']; me.callback.beforeLoading(this); system.loadScript(me.protocol + "//" + me.hostName + "/js/" + this.version + '/' + SCRIPT_FILE_NAME + '?r=' + new Date().getMilliseconds()); }; ApplicationLocationImp.prototype.setApplication = function (api) { var me = this; if (this.timeoutId != 0) { clearTimeout(this.timeoutId); this.timeoutId = 0; } this.application = api; me.loading = false; if (me.callback != null) { me.callback.loaded(me, api); me.callback = null; } }; return ApplicationLocationImp; }(sw_266.ApplicationLocation)); /********************************************************************************************************************************** * Disables all the controls in the browser that could receive focus that are not disabled. * Then later reenables them. * This is used when a modal dialog needs to popup. All other controls should not receive focus. * Then when it is done displaying they should be reenabled, but only the ones that were already enabled. */ var InputDisabler = /** @class */ (function () { function InputDisabler() { this.disabledInputs = []; this.disabledSelects = []; this.focusedBefore = null; } InputDisabler.prototype.disable = function () { var inputs; var selects; this.focusedBefore = document.activeElement; this.disabledInputs = []; inputs = document.getElementsByTagName('input'); for (var x = 0; x < inputs.length; x++) { if (!inputs[x].disabled) { inputs[x].disabled = true; this.disabledInputs.push(inputs[x]); } } this.disabledSelects = []; selects = document.getElementsByTagName('select'); for (var x = 0; x < selects.length; x++) { if (!selects[x].disabled) { selects[x].disabled = true; this.disabledSelects.push(selects[x]); } } }; InputDisabler.prototype.enable = function () { for (var x = 0; x < this.disabledInputs.length; x++) { this.disabledInputs[x].disabled = false; } for (var x = 0; x < this.disabledSelects.length; x++) { this.disabledSelects[x].disabled = false; } if (this.focusedBefore != null) { this.focusedBefore.focus(); } }; return InputDisabler; }()); /** * Manages the back button. A single global instance of this variable will exist. You may push and pop handlers * into the manager. Only the last handler that is pushed into the manager will receive the back button event. */ var BackButtonManagerImpl = /** @class */ (function () { function BackButtonManagerImpl() { /** * Keep track of who is listening to the backbutton. We only allow one at a time. So, if you */ this.backButtonListeners = null; } BackButtonManagerImpl.prototype.push = function (listener) { if (this.backButtonListeners == null) { this.backButtonListeners = []; var me = this; window.history.pushState(null, null, location.pathname); window.addEventListener('popstate', function (e) { if (me.backButtonListeners.length > 0) { window.history.pushState(null, null, location.pathname); me.backButtonListeners[me.backButtonListeners.length - 1].back(); } }); } this.backButtonListeners.push(listener); }; BackButtonManagerImpl.prototype.pop = function (listener) { for (var x = this.backButtonListeners.length - 1; x >= 0; x--) { if (this.backButtonListeners[x] == listener) { this.backButtonListeners.splice(x, 1); return; } } }; return BackButtonManagerImpl; }()); })(sw_266 || (sw_266 = {})); /// /// var sw_266; (function (sw_266) { /********************************************************************************************************************************** * Div for logging into the system. */ var DivLogin = /** @class */ (function (_super) { __extends(DivLogin, _super); function DivLogin() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.formElement = null; _this.textFieldCompany = null; _this.textFieldBranch = null; _this.textFieldUser = null; _this.passwordField = null; _this.buttonGo = null; _this.callback = null; return _this; } DivLogin.prototype.build = function () { var table; var tbody; var tr; var td; var divLogo; var me = this; var tmp; var sys; if (this.isBuilt()) { return; } this.element = document.createElement('div'); this.element.className = "DIV_LOGIN"; this.element.id = this.element.className + this.componentId; this.element.style.width = '100%'; this.element.style.height = '100%'; sys = window['system']; this.formElement = document.createElement('form'); this.formElement.onsubmit = function () { me.logon(); return false; }; this.element.appendChild(this.formElement); table = document.createElement('table'); table.style.width = '100%'; table.style.height = '100%'; this.formElement.appendChild(table); tbody = document.createElement('tbody'); table.appendChild(tbody); tr = tbody.insertRow(); td = tr.insertCell(); table = document.createElement('table'); table.style.width = '100%'; td.appendChild(table); tbody = document.createElement('tbody'); table.appendChild(tbody); tr = tbody.insertRow(); td = tr.insertCell(); divLogo = document.createElement('div'); divLogo.className = sw_266.LOGOLONG; td.appendChild(divLogo); tr = tbody.insertRow(); td = tr.insertCell(); td.innerHTML = 'Company'; tr = tbody.insertRow(); td = tr.insertCell(); this.textFieldCompany = document.createElement('input'); this.textFieldCompany.setAttribute('type', 'textfield'); tmp = sys.getCookie("login_company"); if (tmp != null) { this.textFieldCompany.value = tmp; } td.appendChild(this.textFieldCompany); tr = tbody.insertRow(); td = tr.insertCell(); td.innerHTML = 'Branch'; tr = tbody.insertRow(); td = tr.insertCell(); this.textFieldBranch = document.createElement('input'); this.textFieldBranch.setAttribute('type', 'textfield'); tmp = sys.getCookie('login_branch'); if (tmp != null) { this.textFieldBranch.value = tmp; } td.appendChild(this.textFieldBranch); tr = tbody.insertRow(); td = tr.insertCell(); td.innerHTML = 'User'; tr = tbody.insertRow(); td = tr.insertCell(); this.textFieldUser = document.createElement('input'); this.textFieldUser.setAttribute('type', 'textfield'); tmp = sys.getCookie("login_user"); if (tmp != null) { this.textFieldUser.value = tmp; } td.appendChild(this.textFieldUser); tr = tbody.insertRow(); td = tr.insertCell(); td.innerHTML = 'Password'; tr = tbody.insertRow(); td = tr.insertCell(); this.passwordField = document.createElement('input'); this.passwordField.setAttribute('type', 'password'); td.appendChild(this.passwordField); tr = tbody.insertRow(); td = tr.insertCell(); this.buttonGo = document.createElement('input'); this.buttonGo.setAttribute('type', 'submit'); this.buttonGo.value = 'LOGIN'; this.buttonGo.className = 'ABUTTON'; td.appendChild(this.buttonGo); }; DivLogin.prototype.afterAddedToDOM = function () { _super.prototype.afterAddedToDOM.call(this); this.passwordField.value = ''; if (this.textFieldUser.value.trim().length == 0) { this.textFieldUser.focus(); } else { this.passwordField.focus(); } }; /** * Set the class to receive the event of a login. */ DivLogin.prototype.setCallBack = function (parms) { this.callback = parms.callback; }; DivLogin.prototype.logon = function () { var me; var system; me = this; if (this.textFieldUser.value.trim().length == 0) { alert("User name is required."); this.textFieldUser.focus(); return; } if (this.passwordField.value.trim().length == 0) { alert("Password is required."); this.passwordField.focus(); return; } if (this.textFieldBranch.value.trim().length > 0) { if (this.textFieldCompany.value.trim().length == 0) { alert("Company is required."); this.textFieldCompany.focus(); return; } } system = window['system']; system.setCookie("login_user", this.textFieldUser.value, 9999); system.setCookie("login_company", this.textFieldCompany.value, 9999); system.setCookie("login_branch", this.textFieldBranch.value, 9999); system.logon((this.textFieldCompany.value.trim() + this.textFieldUser.value.trim()), this.passwordField.value.trim(), { logonStarting: function (system, result) { console.log('starting logon.'); }, logonFinished: function (system, result) { var session; var sessionSelected; var company; var companySelected = null; var branch; var branchSelected = null; var branches; console.log('finished logon'); if (result.getSessions().length == 0) { alert('Unable to login. Please try again.'); return; } // if they entered a branch, then they must enter a company as well, and the company and branch must be // in the list of company/branches that they can log into. This is to support the stupid way some people // think we should log in with company and branch, even though we shouldnt do that. if (me.textFieldCompany.value.trim().length > 0) { findCompany: { for (var c = 0; c < result.getSessions().length; c++) { session = result.getSessions()[c]; for (var x = 0; x < session.getCompanies().length; x++) { company = session.getCompanies()[x]; if (company.code.trim().toLowerCase() == me.textFieldCompany.value.trim().toLowerCase()) { sessionSelected = session; companySelected = company; break findCompany; } } } } if (companySelected == null) { alert('Unable to login. Please try again.'); return; } } if (me.textFieldBranch.value.trim().length > 0) { findBranch: { branches = sessionSelected.getBranchesForCompany(companySelected); for (var b = 0; b < branches.length; b++) { branch = branches[b]; if (branch.branch_num.trim().toLowerCase() == me.textFieldBranch.value.trim().toLowerCase()) { branchSelected = branch; break findBranch; } } } if (branchSelected == null) { alert('Unable to login. Please try again.'); return; } } me.callback.loginComplete({ loginDialog: me, result: result, sessionSelected: sessionSelected, companySelected: companySelected, branchSelected: branchSelected }); }, // deals with loading the version from the server. beforeVersionRead: function (system, location) { console.log('reading version for server: ' + location.getHostName()); }, versionRead: function (system, location, version) { console.log('read version for server: ' + location.getHostName() + ' = ' + version); }, versionChanged: function (system, location, oldVersion, newVersion) { console.log('version changed for a server we had loaded: ' + location.getHostName()); }, httpError2: function (system, location, page, status, responseText) { console.log('http error happened while trying to read version for server: ' + location.getHostName()); }, // deals with loading the javascript source file from the server. beforeLoading: function (system, location) { console.log('starting to load the javascript for server: ' + location.getHostName()); }, loaded: function (system, location, api) { console.log('finished loading javascript for server: ' + location.getHostName() + ", api version: " + api.getVersion()); }, timedOutLoadingScript: function (system, location) { console.log('timed out waiting for javascript to load at server: ' + location.getHostName()); }, // deals with actually logging in. logonFailed: function (system, api, message) { console.log('api logon failed: ' + message + ', at: ' + api.getApplicationLocation().getHostName()); }, logonCompleted: function (system, api, session) { console.log('api logon completed at: ' + api.getApplicationLocation().getHostName() + ' with token: ' + session.getToken()); } }); }; return DivLogin; }(sw_266.Component)); sw_266.DivLogin = DivLogin; })(sw_266 || (sw_266 = {})); /// /// var sw_266; (function (sw_266) { var PopupBranchChooser = /** @class */ (function (_super) { __extends(PopupBranchChooser, _super); function PopupBranchChooser(logonResult, companySelected) { var _this = _super.call(this) || this; _this.formElement = null; _this.selectCompany = null; _this.selectBranch = null; _this.companyCount = 0; _this.buttonOk = null; _this.buttonCancel = null; _this.callback = null; _this.logonResult = logonResult; _this.companySelected = companySelected; return _this; } PopupBranchChooser.prototype.afterAddedToDOM = function () { _super.prototype.afterAddedToDOM.call(this); this.buttonOk.focus(); }; PopupBranchChooser.prototype.build = function () { var me = this; var sessions; var session; var companyFirst = null; var companies; var option; var temp; var table; var tbody; var tr; var td; if (this.isBuilt()) { return; } _super.prototype.build.call(this); this.element.innerHTML = ''; tbody = document.createElement('tbody'); this.element.appendChild(tbody); tr = tbody.insertRow(); td = tr.insertCell(); td.align = 'center'; td.vAlign = 'center'; this.formElement = document.createElement('form'); td.appendChild(this.formElement); this.formElement.className = 'FORM_BRANCH_CHOOSER'; table = document.createElement('table'); this.formElement.appendChild(table); table.className = 'POPUP_BRANCH_CHOOSER POPUP_CONTENT'; tbody = document.createElement('tbody'); table.appendChild(tbody); tr = tbody.insertRow(); td = tr.insertCell(); td.colSpan = 2; td.appendChild(this.buildTitleBar('Open Session')); this.selectCompany = document.createElement('select'); sessions = this.logonResult.getSessions(); for (var x = 0; x < sessions.length; x++) { session = sessions[x]; companies = session.getCompanies(); for (var c = 0; c < companies.length; c++) { this.companyCount++; if (this.companyCount = 1) { companyFirst = companies[c]; } option = document.createElement('option'); option.value = companies[c].id + '@' + session.getApplication().getProtocol() + "//" + session.getApplication().getHostName(); option.innerHTML = sw_266.escapeHtml(companies[c].name); if (companies[c].id == this.companySelected.id) { option.selected = true; } this.selectCompany.appendChild(option); } } if (this.companyCount > 1 && this.companySelected == null) { tr = tbody.insertRow(); td = tr.insertCell(); td.colSpan = 2; td.innerHTML = 'Company'; tr = tbody.insertRow(); td = tr.insertCell(); td.colSpan = 2; td.appendChild(this.selectCompany); } // TODO: // add a listener, so that when the user selects a company // it will populate the branch combobox with the branches for that company. tr = tbody.insertRow(); td = tr.insertCell(); td.colSpan = 2; td.innerHTML = 'Branch'; tr = tbody.insertRow(); td = tr.insertCell(); td.colSpan = 2; this.selectBranch = document.createElement('select'); td.appendChild(this.selectBranch); // TODO: or if a companySelected is passed in, then dont show the company select box. if (this.companySelected != null) { companyFirst = this.companySelected; } temp = session.getBranchesForCompany(companyFirst); for (var b = 0; b < temp.length; b++) { option = document.createElement('option'); option.value = '' + temp[b].id; option.innerHTML = '' + sw_266.escapeHtml(temp[b].branch_num); this.selectBranch.appendChild(option); } this.formElement.onsubmit = function () { var company; var branches; var branch; var companyId; var branchId; var value; var index; var serverName; value = me.selectCompany.options[me.selectCompany.selectedIndex].value; index = value.lastIndexOf("@"); if (index == -1) { return false; } companyId = Number(value.substring(0, index)); serverName = value.substring(index + 1); branchId = Number(me.selectBranch.options[me.selectBranch.selectedIndex].value); //console.log(serverName + ", " + companyId + ", " + branchId); // find the server, company, branch selected, and return them. for (var s = 0; s < me.logonResult.getSessions().length; s++) { var session = me.logonResult.getSessions()[s]; if (session.getApplication().getProtocol() + "//" + session.getApplication().getHostName() == serverName) { for (var c = 0; c < session.getCompanies().length; c++) { if (session.getCompanies()[c].id == companyId) { branches = session.getBranchesForCompany(session.getCompanies()[c]); for (var b = 0; b < branches.length; b++) { if (branches[b].id == branchId) { me.callback.branchChooserComplete({ dialog: me, session: session, company: session.getCompanies()[c], branch: branches[b] }); return false; } } } } } } // couldnt find the server, company, branch, that they selected. return false; }; tr = tbody.insertRow(); td = tr.insertCell(); this.buttonCancel = document.createElement('input'); this.buttonCancel.setAttribute('type', 'button'); this.buttonCancel.value = 'CANCEL'; this.buttonCancel.setAttribute("accesskey", "C"); this.buttonCancel.onclick = function () { me.back(); }; td.appendChild(this.buttonCancel); td = tr.insertCell(); this.buttonOk = document.createElement('input'); this.buttonOk.setAttribute('type', 'submit'); this.buttonOk.setAttribute("accesskey", "O"); this.buttonOk.value = 'OK'; td.appendChild(this.buttonOk); }; PopupBranchChooser.prototype.setCallBack = function (parms) { this.callback = parms.callback; }; PopupBranchChooser.prototype.back = function () { if (this.callback != null) { this.setParent({ parent: null }); this.callback.branchChooserCanceled({ dialog: this }); } }; return PopupBranchChooser; }(sw_266.Popup)); sw_266.PopupBranchChooser = PopupBranchChooser; })(sw_266 || (sw_266 = {})); /// var sw_266; (function (sw_266) { /********************************************************************************************************************************** */ var TabTable = /** @class */ (function (_super) { __extends(TabTable, _super); function TabTable() { var _this = _super.call(this) || this; _this.children = []; _this.showSingleTabs = false; // if only one tab default to not showing its header. _this.callback = null; _this.closeCallback = null; return _this; } TabTable.prototype.keyUp = function (event) { if (this.children.length > 1) { if (event.ctrlKey) { if (event.keyCode == 37 /* left arrow */) { this.setSelectedTabIndex(this.getSelectedTabIndex() - 1); return false; } else if (event.keyCode == 39 /* right arrow */) { this.setSelectedTabIndex(this.getSelectedTabIndex() + 1); return false; } } } return true; }; TabTable.prototype.setShowSingleTabs = function (showSingleTabs) { this.showSingleTabs = showSingleTabs; }; TabTable.prototype.setCallBack = function (listener) { this.callback = listener; }; TabTable.prototype.setCloseCallBack = function (listener) { this.closeCallback = listener; }; TabTable.prototype.getTabCount = function () { return this.tdBody.children.length; }; TabTable.prototype.addCloseableTab = function (title, div) { var span; var divClose; var me = this; span = this.addTab(title, div); divClose = document.createElement('div'); divClose.className = 'close_tab'; span.appendChild(divClose); divClose.onclick = function () { if (me.closeCallback != null) { if (!me.closeCallback.shouldTabClose(me, div)) { return; } } me.removeTab(div); if (me.closeCallback != null) { me.closeCallback.tabCLosed(me, div); } }; return span; }; TabTable.prototype.addTab = function (title, child) { var span; var me = this; var index; var td; if (!this.isBuilt()) { this.build(); } this.children.push(child); child.setParent({ parent: this.tdBody }); span = document.createElement('div'); span.innerHTML = title; span.style.whiteSpace = 'nowrap'; span.style.top = '0px'; td = this.trHeaderTabs.insertCell(); td.appendChild(span); span.onclick = function () { me.setSelectedTab(child); }; if (this.showSingleTabs || this.children.length > 1) { this.trHeader.style.display = null; } return span; }; TabTable.prototype.removeTab = function (tab) { var index; index = this.getIndexForTab(tab); if (index < 0) { return; } this.removeTabForIndex(index); }; TabTable.prototype.removeTabForIndex = function (index) { var selected; if (!this.isBuilt()) { this.build(); } if (index < 0 || index >= this.getTabCount()) { return; } selected = this.getSelectedTabIndex(); if (selected == index && this.callback != null) { this.callback.tabNotSelected(this, index, this.children[index]); } this.trHeaderTabs.removeChild(this.trHeaderTabs.children.item(index)); this.children[index].setParent({ parent: null }); this.children.splice(index, 1); if (index < selected) { selected--; } if (selected >= this.children.length) { selected = this.children.length - 1; } this.setSelectedTabIndex(selected); if (!this.showSingleTabs && this.children.length == 1) { this.trHeader.style.display = 'none'; } }; TabTable.prototype.getSelectedTabIndex = function () { var e; for (var x = 0; x < this.tdBody.children.length; x++) { e = this.tdBody.children.item(x); if (e.style.display != 'none') { return x; } } return -1; }; TabTable.prototype.getSelectedTab = function () { if (this.getSelectedTabIndex() < 0) { return null; } return this.children[this.getSelectedTabIndex()]; }; TabTable.prototype.setSelectedTab = function (tab) { var index; index = this.getIndexForTab(tab); if (index < 0) { return; } this.setSelectedTabIndex(index); }; TabTable.prototype.setSelectedTabIndex = function (index) { var element; var header; var before; if (index < 0 || index >= this.children.length) { return; } if (!this.isBuilt()) { return; } if (this.parent == null) { return; } before = this.getSelectedTabIndex(); if (before > -1 && this.callback != null) { this.callback.tabNotSelected(this, before, this.children[before]); } for (var x = 0; x < this.tdBody.children.length; x++) { header = this.trHeaderTabs.children.item(x).firstChild; element = this.tdBody.children.item(x); if (x == index) { element.style.display = null; header.className = 'TAB_HEADER_SELECTED'; } else { element.style.display = 'none'; header.className = 'TAB_HEADER'; } } if (this.callback != null) { this.callback.tabSelected(this, index, this.children[index]); } }; TabTable.prototype.getTabForIndex = function (index) { return this.trHeaderTabs.children.item(index).firstChild; }; TabTable.prototype.getTabDivForIndex = function (index) { return this.children[index]; }; TabTable.prototype.getIndexForTab = function (tab) { for (var x = 0; x < this.children.length; x++) { if (this.children[x] == tab) { return x; } } return -1; }; TabTable.prototype.afterAddedToDOM = function () { var sys = window['system']; _super.prototype.afterAddedToDOM.call(this); sys.addKeyUpListener(this); }; TabTable.prototype.afterRemovedFromDOM = function () { var sys = window['system']; _super.prototype.afterRemovedFromDOM.call(this); sys.removeKeyUpListener(this); }; TabTable.prototype.build = function () { var table; var tbody; var td; var tr; if (this.isBuilt()) { return; } this.element = document.createElement('table'); this.element.style.width = '100%'; this.element.style.height = '100%'; tbody = document.createElement('tbody'); this.element.appendChild(tbody); this.trHeader = tbody.insertRow(); this.trHeader.style.display = 'none'; td = this.trHeader.insertCell(); td.className = 'TAB_HEADER_CONTAINER'; td.style.overflow = 'hidden'; tr = tbody.insertRow(); this.tdBody = tr.insertCell(); this.tdBody.className = 'TAB_BODY'; table = document.createElement('table'); table.style.width = '100%'; table.style.height = '100%'; td.appendChild(table); tbody = document.createElement('tbody'); table.appendChild(tbody); tr = table.insertRow(); td = tr.insertCell(); table = document.createElement('table'); td.appendChild(table); tbody = document.createElement('tbody'); table.appendChild(tbody); this.trHeaderTabs = table.insertRow(); td = tr.insertCell(); td.className = "TAB_HEADER_FILLER"; td.innerHTML = "
 
"; }; return TabTable; }(sw_266.Component)); sw_266.TabTable = TabTable; })(sw_266 || (sw_266 = {})); /// /// /** * This is the main panel for the application. * There is only ever one Main panel open. */ var sw_266; (function (sw_266) { var DivMain = /** @class */ (function (_super) { __extends(DivMain, _super); function DivMain(systemLoginResult, sessionSelected, companySelected, branchSelected) { var _this = _super.call(this) || this; _this.callback = null; _this.menus = []; _this.ID_TABLE_TO_RESET = sw_266.nextUniqueID(); _this.ID_SW_LOGO = sw_266.nextUniqueID(); _this.ID_START_MENU = sw_266.nextUniqueID(); _this.ID_MAIN_CENTER = sw_266.nextUniqueID(); _this.ID_MENUS = sw_266.nextUniqueID(); _this.ID_STATUS = sw_266.nextUniqueID(); _this.ID_LOGOUT = sw_266.nextUniqueID(); var me = _this; var $ = function (id) { return me.$(id); }; var count; var session; var branches; _this.systemLoginResult = systemLoginResult; _this.sessionSelected = sessionSelected; _this.companySelected = companySelected; _this.branchSelected = branchSelected; // this bit of nasty code here is for certain tablets. // they dont resize correctly. They put our main table up about 9 pixels // when the keyboard comes out, but then dont reset it correctly when the keyboard goes away. // so we look for the keyboard event, and then check to see if our table is out of alignment. // then if it is, we reset it. var checkit = function () { var tableToReset; tableToReset = $(me.ID_TABLE_TO_RESET); if (tableToReset != null) { if (tableToReset.getBoundingClientRect().top < 0) { tableToReset.style.height = null; setTimeout(function () { tableToReset.style.height = '100%'; }, 200); } } }; document.addEventListener('focusout', function (e) { // console.log('focusout'); checkit(); setTimeout(function () { checkit(); }, 300); }); // if no company selected and only one company, then set it as the default. duh. if (_this.companySelected == null) { count = 0; for (var c = 0; c < _this.systemLoginResult.getSessions().length; c++) { session = _this.systemLoginResult.getSessions()[c]; count += session.getCompanies().length; } if (count == 1) { _this.sessionSelected = _this.systemLoginResult.getSessions()[0]; _this.companySelected = _this.systemLoginResult.getSessions()[0].getCompanies()[0]; } } if (_this.branchSelected == null) { // see if there is only one branch for the company selected if (_this.companySelected != null) { branches = _this.sessionSelected.getBranchesForCompany(_this.companySelected); if (branches.length == 1) { _this.branchSelected = branches[0]; } } } return _this; } DivMain.prototype.build = function () { var me = this; var $ = function (id) { return me.$(id); }; if (this.isBuilt()) { return; } this.element = document.createElement('div'); this.element.className = "DIV_MAIN"; this.element.id = this.element.className + this.componentId; this.element.style.width = '100%'; this.element.style.height = '100%'; this.element.innerHTML = "\n \n \n \n \n \n \n
\n \n \n \n \n \n \n \n \n \n \n
\n
\n \n \n  \n Help\n  \n Logout\n  \n
\n
\n
\n
\n "; }; DivMain.prototype.setMenuOnClickFuntion = function (menu) { menu.button.onclick = function () { if (menu.callback != null) { menu.callback.systemMenuClicked(menu); } }; }; DivMain.prototype.createSystemMenu = function (text) { return new SystemMenuImpl(this, text); }; DivMain.prototype.addSystemMenu = function (menu) { var tmp; var me = this; var $ = function (id) { return me.$(id); }; tmp = menu; this.menus.push(tmp); tmp.button = document.createElement('input'); tmp.button.type = 'button'; tmp.button.className = 'SYSTEM_MENU SYSTEM_MENU_' + menu.getText(); tmp.button.value = menu.getText(); tmp.button.disabled = !menu.isEnabled(); $(me.ID_MENUS).appendChild(tmp.button); this.setMenuOnClickFuntion(tmp); }; DivMain.prototype.addSystemMenus = function (menus) { for (var x = 0; x < menus.length; x++) { this.addSystemMenu(menus[x]); } }; DivMain.prototype.clearSystemMenus = function () { for (var x = 0; x < this.menus.length; x++) { this.menus[x].button.parentElement.removeChild(this.menus[x].button); this.menus[x].button = null; } this.menus = []; }; DivMain.prototype.removeSystemMenu = function (menu) { for (var x = 0; x < this.menus.length; x++) { if (this.menus[x].getText() == menu.getText()) { if (this.menus[x].button != null) { this.menus[x].button.parentElement.removeChild(this.menus[x].button); this.menus[x].button = null; } this.menus.splice(x, 1); return; } } }; DivMain.prototype.setCallBack = function (parms) { this.callback = parms.callback; }; DivMain.prototype.afterAddedToDOM = function () { var sys = window['system']; var me = this; var $ = function (id) { return me.$(id); }; var td; _super.prototype.afterAddedToDOM.call(this); sys.addKeyUpListener(this); td = $(me.ID_START_MENU); $(me.ID_SW_LOGO).onmouseup = td.onmouseup = function (e) { if (e.button == 1) { // middle button!!! prompt to open a session. // or just open a session. me.openASession(false); } else { var tab = me.tabSessions.getSelectedTab(); td.className = 'start_menu_button_selected'; tab.showMenu({ finished: function () { td.className = 'start_menu_button'; } }); } }; $(me.ID_LOGOUT).onclick = function () { me.sessionClosed(me.tabSessions.getSelectedTab()); }; this.tabSessions = new sw_266.TabTable(); this.tabSessions.setParent({ parent: $(me.ID_MAIN_CENTER) }); this.tabSessions.setShowSingleTabs(false); // so we can update the status bar this.tabSessions.setCallBack({ tabSelected: function (tabDiv, index, tab) { me.clearSystemMenus(); if (tab == null) { $(me.ID_STATUS).innerHTML = ''; } else { $(me.ID_STATUS).innerHTML = sw_266.escapeHtml(tab.getSession().getUserName() + ', ' + tab.getBranch().branch_num + ', ' + tab.getCompany().name); me.addSystemMenus(tab.getSystemMenus()); } }, tabNotSelected: function (tabDiv, index, tab) { me.clearSystemMenus(); $(me.ID_STATUS).innerHTML = ''; } }); this.openASession(true); }; DivMain.prototype.afterRemovedFromDOM = function () { var sys = window['system']; _super.prototype.afterRemovedFromDOM.call(this); sys.removeKeyUpListener(this); }; DivMain.prototype.keyUp = function (event) { var me = this; var $ = function (id) { return me.$(id); }; var td; if (event.ctrlKey && event.altKey && (event.keyCode == 83 /* S */ || event.keyCode == 90 /* Z */)) { me.openASession(false); return false; } else if (event.altKey && (event.keyCode == 83 /* S */ || event.keyCode == 90 /* Z */)) { td = $(me.ID_START_MENU); td.className = 'start_menu_button_selected'; me.tabSessions.getSelectedTab().showMenu({ finished: function () { td.className = 'start_menu_button'; } }); return false; } return true; }; DivMain.prototype.openASession = function (closeDialog) { var me = this; var dlgBranchChooser = null; // do we prompt them for the connection/company/branch here? or have they selected one already? if (this.branchSelected == null) { if (dlgBranchChooser != null) { return; } dlgBranchChooser = new sw_266.PopupBranchChooser(this.systemLoginResult, this.companySelected); dlgBranchChooser.setParent({ parent: document.body }); dlgBranchChooser.setCallBack({ callback: { branchChooserCanceled: function (parms) { // close out this main dialog? dlgBranchChooser.setParent({ parent: null }); dlgBranchChooser = null; if (closeDialog) { me.setParent({ parent: null }); me.callback.dialogMainClosed({ dialog: me }); } }, branchChooserComplete: function (parms) { dlgBranchChooser.setParent({ parent: null }); dlgBranchChooser = null; me.addSession(parms.session, parms.branch, parms.company); } } }); } else { me.addSession(me.sessionSelected, me.branchSelected, this.companySelected); } }; DivMain.prototype.addSession = function (session, branch, company) { var divSession; // depending on the number of sessions, we will display tabs. divSession = session.getApplication().createSessionDiv(session, branch, company); if (divSession != null) { divSession.setCallBack(this); //this.tabSessions.addTab(session.getUserName() + "@" + branch.branch_num + ":" + company.code, divSession); this.tabSessions.addTab(company.code + "/" + branch.branch_num, divSession); this.tabSessions.setSelectedTabIndex(this.tabSessions.getTabCount() - 1); } }; DivMain.prototype.sessionClosed = function (divSession) { this.tabSessions.removeTab(divSession); if (this.tabSessions.getTabCount() == 0) { this.setParent({ parent: null }); this.callback.dialogMainClosed({ dialog: this }); } }; return DivMain; }(sw_266.Component)); sw_266.DivMain = DivMain; var SystemMenuImpl = /** @class */ (function () { function SystemMenuImpl(divMain, text) { this.enabled = true; this.button = null; this.divMain = divMain; this.text = text; } SystemMenuImpl.prototype.setEnabled = function (enabled) { this.enabled = enabled; if (this.button != null) { this.button.disabled = !enabled; } }; SystemMenuImpl.prototype.isEnabled = function () { return this.enabled; }; SystemMenuImpl.prototype.setCallBack = function (callback) { this.callback = callback; }; SystemMenuImpl.prototype.getText = function () { return this.text; }; return SystemMenuImpl; }()); })(sw_266 || (sw_266 = {})); /// /// /// function startApp() { var sysImp = new sw_266.SystemImp(); var divLogon = new sw_266.DivLogin(); divLogon.setCallBack({ callback: { loginComplete: function (parms) { divLogon.setParent({ parent: null }); var divMain = new sw_266.DivMain(parms.result, parms.sessionSelected, parms.companySelected, parms.branchSelected); sysImp.setDivMain(divMain); divMain.setCallBack({ callback: { dialogMainClosed: function (parms) { sysImp.setDivMain(null); divLogon.setParent({ parent: document.body }); } } }); divMain.setParent({ parent: document.body }); } } }); divLogon.setParent({ parent: document.body }); }