diff --git a/Account/AccountManager.js b/Account/AccountManager.js index 3740d53..598bd9c 100644 --- a/Account/AccountManager.js +++ b/Account/AccountManager.js @@ -9,14 +9,15 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.Account'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.AccountManager = function () + jsOMS.Account.AccountManager = function () { this.accounts = []; }; @@ -31,7 +32,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.AccountManager.prototype.add = function (account) + jsOMS.Account.AccountManager.prototype.add = function (account) { this.accounts[account.getId()] = account; }; @@ -46,7 +47,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.AccountManager.prototype.remove = function (id) + jsOMS.Account.AccountManager.prototype.remove = function (id) { if (typeof this.accounts[id] !== 'undefined') { delete this.accounts[id]; @@ -69,7 +70,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.AccountManager.prototype.get = function (id) + jsOMS.Account.AccountManager.prototype.get = function (id) { if (this.accounts[id]) { return this.accounts[id]; diff --git a/Account/AccountType.enum.js b/Account/AccountType.enum.js index b9a08f0..8033d2a 100644 --- a/Account/AccountType.enum.js +++ b/Account/AccountType.enum.js @@ -9,7 +9,9 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumAccountType = Object.freeze({ + jsOMS.Autoloader.defineNamespace('jsOMS.Account'); + + jsOMS.Account.AccountType = Object.freeze({ USER: 0, GROUP: 1 }); diff --git a/Asset/AssetManager.js b/Asset/AssetManager.js index 06bda89..dfd598e 100644 --- a/Asset/AssetManager.js +++ b/Asset/AssetManager.js @@ -9,14 +9,15 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.Asset'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.AssetManager = function () + jsOMS.Asset.AssetManager = function () { this.assets = {}; }; @@ -36,7 +37,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.AssetManager.prototype.load = function (path, filename, filetype, callback) + jsOMS.Asset.AssetManager.prototype.load = function (path, filename, filetype, callback) { var hash; @@ -102,7 +103,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.AssetManager.prototype.get = function (id) + jsOMS.Asset.AssetManager.prototype.get = function (id) { if (this.assets[id]) { return this.assets[id]; @@ -123,7 +124,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.AssetManager.prototype.remove = function (key) + jsOMS.Asset.AssetManager.prototype.remove = function (key) { if (typeof this.assets[key] !== 'undefined') { delete this.assets[key]; diff --git a/Auth/Auth.js b/Auth/Auth.js index 04d15b4..5e738ce 100644 --- a/Auth/Auth.js +++ b/Auth/Auth.js @@ -9,6 +9,7 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Auth'); /** * @constructor @@ -16,7 +17,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Auth = function (uri) + jsOMS.Auth.Auth = function (uri) { this.account = null; this.uri = uri; @@ -32,7 +33,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Auth.prototype.setAccount = function (account) + jsOMS.Auth.Auth.prototype.setAccount = function (account) { this.account = account; }; @@ -47,7 +48,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Auth.prototype.getAccount = function () + jsOMS.Auth.Auth.prototype.getAccount = function () { return this.account; }; @@ -60,12 +61,12 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Auth.prototype.login = function () + jsOMS.Auth.Auth.prototype.login = function () { - var authRequest = new jsOMS.Request(); + var authRequest = new jsOMS.Message.Request.Request(); authRequest.setUri(this.uri); - authRequest.setMethod(jsOMS.EnumRequestMethod.POST); - authRequest.setResponseType(jsOMS.EnumRequestType.JSON); + authRequest.setMethod(jsOMS.Message.Request.RequestMethod.POST); + authRequest.setResponseType(jsOMS.Message.Request.RequestType.JSON); authRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); authRequest.setSuccess(function (xhr) { @@ -83,7 +84,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Auth.prototype.logout = function () + jsOMS.Auth.Auth.prototype.logout = function () { location.reload(); }; @@ -96,7 +97,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Auth.prototype.loginResult = function (xhr) + jsOMS.Auth.Auth.prototype.loginResult = function (xhr) { console.log(xhr); location.reload(); diff --git a/Autoloader.js b/Autoloader.js new file mode 100644 index 0000000..166824b --- /dev/null +++ b/Autoloader.js @@ -0,0 +1,60 @@ +(function (jsOMS, undefined) { + jsOMS.Autoloader = {}; + jsOMS.Autoloader.loaded = []; + jsOMS.Autoloader.namespaced = []; + + jsOMS.Autoloader.defineNamespace = function(namespace) + { + if(jsOMS.Autoloader.namespaced.indexOf(namespace) === -1) { + let paths = namespace.split('.'); + paths.splice(0, 1); + + let length = paths.length, + current = jsOMS; + + for(let i = 0; i < length; i++) { + if(typeof current[paths[i]] === 'undefined') { + current[paths[i]] = {}; + } + + current = current[paths[i]]; + } + + jsOMS.Autoloader.namespaced.push(namespace); + } + }; + + jsOMS.Autoloader.initPreloaded = function() + { + let scripts = document.getElementsByTagName('script'), + length = scripts.length; + + for(let i = 0; i < length; i++) { + scripts[i].src.replace(URL + '/', ''); + + if(jsOMS.Autoloader.loaded.indexOf(scripts[i].src) === -1) { + jsOMS.Autoloader.loaded.push(scripts[i].src); + } + } + }; + + jsOMS.Autoloader.setPreloaded = function(file) + { + if(jsOMS.Autoloader.loaded.indexOf(file) === -1) { + jsOMS.Autoloader.loaded.push(file); + } + }; + + jsOMS.Autoloader.include = function(file, callback) + { + let length = file.length; + + for(let i = 0; i < length; i++) { + if(jsOMS.Autoloader.loaded.indexOf(file) === -1) { + // todo: implement asset loading and pass callback + + jsOMS.Autoloader.loaded.push(file); + } + } + }; +}(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/Config/Options.js b/Config/Options.js index 277b149..09fdb5a 100644 --- a/Config/Options.js +++ b/Config/Options.js @@ -9,6 +9,7 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Config'); /** * @constructor @@ -16,7 +17,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Options = function () + jsOMS.Config.Options = function () { this.options = {}; }; @@ -35,7 +36,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Options.prototype.set = function (key, value, overwrite) + jsOMS.Config.Options.prototype.set = function (key, value, overwrite) { overwrite = typeof overwrite === bool ? overwrite : true; @@ -60,7 +61,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Options.prototype.get = function (key) + jsOMS.Config.Options.prototype.get = function (key) { if (typeof this.options[key] !== 'undefined') { return this.options[key]; @@ -81,7 +82,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Options.prototype.remove = function (key) + jsOMS.Config.Options.prototype.remove = function (key) { if (typeof this.options[key] !== 'undefined') { delete this.options[key]; diff --git a/DataStorage/CacheManager.js b/DataStorage/CacheManager.js index a8c888e..3667e66 100644 --- a/DataStorage/CacheManager.js +++ b/DataStorage/CacheManager.js @@ -1,6 +1,8 @@ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); + // TODO: create comments - jsOMS.CacheManager = function () + jsOMS.DataStorage.CacheManager = function () { }; }(window.jsOMS = window.jsOMS || {})); diff --git a/DataStorage/CookieJar.js b/DataStorage/CookieJar.js index fd13695..53f0026 100644 --- a/DataStorage/CookieJar.js +++ b/DataStorage/CookieJar.js @@ -9,14 +9,15 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.CookieJar = function () + jsOMS.DataStorage.CookieJar = function () { }; @@ -36,7 +37,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.CookieJar.prototype.setCookie = function (cName, value, exdays, domain, path) + jsOMS.DataStorage.CookieJar.prototype.setCookie = function (cName, value, exdays, domain, path) { var exdate = new Date(); exdate.setDate(exdate.getDate() + exdays); @@ -56,7 +57,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.CookieJar.prototype.getCookie = function (cName) + jsOMS.DataStorage.CookieJar.prototype.getCookie = function (cName) { var cValue = document.cookie; var cStart = cValue.indexOf(" " + cName + "="); diff --git a/DataStorage/LocalStorage.js b/DataStorage/LocalStorage.js index 69b70a7..2973ae5 100644 --- a/DataStorage/LocalStorage.js +++ b/DataStorage/LocalStorage.js @@ -9,14 +9,15 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.LocalStorage = function () + jsOMS.DataStorage.LocalStorage = function () { }; @@ -30,7 +31,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.LocalStorage.prototype.available = function () + jsOMS.DataStorage.LocalStorage.prototype.available = function () { try { return 'localStorage' in window && window.localStorage !== null; diff --git a/DataStorage/StorageManager.js b/DataStorage/StorageManager.js index 6354a72..2b87c28 100644 --- a/DataStorage/StorageManager.js +++ b/DataStorage/StorageManager.js @@ -1,5 +1,7 @@ (function (jsOMS, undefined) { - jsOMS.StorageManager = function () + jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); + + jsOMS.DataStorage.StorageManager = function () { }; }(window.jsOMS = window.jsOMS || {})); diff --git a/Dispatcher/Dispatcher.js b/Dispatcher/Dispatcher.js index 7bb5da6..d9256b7 100644 --- a/Dispatcher/Dispatcher.js +++ b/Dispatcher/Dispatcher.js @@ -1,5 +1,7 @@ (function (jsOMS, undefined) { - jsOMS.Dispatcher = function () + jsOMS.Autoloader.defineNamespace('jsOMS.Dispatcher'); + + jsOMS.Dispatcher.Dispatcher = function () { }; }(window.jsOMS = window.jsOMS || {})); diff --git a/Event/EventManager.js b/Event/EventManager.js index 8a1617c..6283ac7 100644 --- a/Event/EventManager.js +++ b/Event/EventManager.js @@ -1,4 +1,6 @@ (function (jsOMS, undefined) { - jsOMS.EventManager = function () { + jsOMS.Autoloader.defineNamespace('jsOMS.Event'); + + jsOMS.Event.EventManager = function () { }; }(window.jsOMS = window.jsOMS || {})); diff --git a/Log/LogLevel.enum.js b/Log/LogLevel.enum.js new file mode 100644 index 0000000..e900404 --- /dev/null +++ b/Log/LogLevel.enum.js @@ -0,0 +1,24 @@ +/** + * Log Level enum. + * + * @author OMS Development Team + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 * @since 1.0.0 + */ +(function (jsOMS, undefined) +{ + jsOMS.Autoloader.defineNamespace('jsOMS.Log'); + + jsOMS.Log.LogLevel = Object.freeze({ + EMERGENCY: 'emergency', + ALERT: 'alert', + CRITICAL: 'critical', + ERROR: 'error', + WARNING: 'warning', + NOTICE: 'notice', + INFO: 'info', + DEBUG: 'debug' + }); +}(window.jsOMS = window.jsOMS || {})); diff --git a/Log/Logger.js b/Log/Logger.js new file mode 100644 index 0000000..7ed4b36 --- /dev/null +++ b/Log/Logger.js @@ -0,0 +1,147 @@ +/** + * Logger class. + * + * @author OMS Development Team + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 * @since 1.0.0 + */ + (function (jsOMS, undefined) + { + "use strict"; + jsOMS.Autoloader.defineNamespace('jsOMS.Log'); + + /** + * @constructor + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Log.Logger = function (verbose, ui, remote) + { + this.verbose = typeof verbose !== 'undefined' ? verbose : true; + this.ui = typeof ui !== 'undefined' ? ui : true; + this.remote = typeof remote !== 'undefined' ? remote : false; + }; + + jsOMS.Log.Logger.layout = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}'; + + jsOMS.Log.Logger.prototype.interpolate = function(message, context, level) + { + let newMessage = jsOMS.Log.Logger.layout; + + for(let replace in context) { + newMessage = newMessage.replace('{'+replace+'}', context[replace]); + } + + return newMessage; + }; + + jsOMS.Log.Logger.prototype.createContext = function(message, context, level) + { + context['datetime'] = (new Date()).toISOString(); + context['version'] = '1.0.0'; + context['os'] = jsOMS.Message.Request.Request.getOS(); + context['browser'] = jsOMS.Message.Request.Request.getBrowser(); + context['path'] = window.location.href; + context['level'] = level; + context['message'] = message; + + return context; + } + + jsOMS.Log.Logger.prototype.write = function(message, context, level) + { + context = this.createContext(message, context, level); + + if(this.verbose) { + console.log('%c' + this.interpolate(message, context, level), 'color: #FFA600'); + } + + if(this.ui) { + // todo: fill log box, set class and initiate animation + } + + if(this.remote) { + let request = new jsOMS.Message.Request.Request(); + request.setData(context); + request.setType(jsOMS.Message.Response.Response.ResponseType.JSON); + request.setUri('/{/lang}/api/log'); + request.setMethod(jsOMS.Message.Request.Request.RequestMethod.POST); + request.setRequestHeader('Content-Type', 'application/json'); + request.setSuccess(function (xhr) {}); + request.send(); + } + }; + + jsOMS.Log.Logger.prototype.emergency = function(message, context) + { + context = typeof context === 'undefined' ? {} : context; + + this.write(message, context, jsOMS.Log.LogLevel.EMERGENCY) + }; + + jsOMS.Log.Logger.prototype.alert = function(message, context) + { + context = typeof context === 'undefined' ? {} : context; + + this.write(message, context, jsOMS.Log.LogLevel.ALERT) + }; + + jsOMS.Log.Logger.prototype.critical = function(message, context) + { + context = typeof context === 'undefined' ? {} : context; + + this.write(message, context, jsOMS.Log.LogLevel.CRITICAL) + }; + + jsOMS.Log.Logger.prototype.error = function(message, context) + { + context = typeof context === 'undefined' ? {} : context; + + this.write(message, context, jsOMS.Log.LogLevel.ERROR) + }; + + jsOMS.Log.Logger.prototype.warning = function(message, context) + { + context = typeof context === 'undefined' ? {} : context; + + this.write(message, context, jsOMS.Log.LogLevel.WARNING) + }; + + jsOMS.Log.Logger.prototype.notice = function(message, context) + { + context = typeof context === 'undefined' ? {} : context; + + this.write(message, context, jsOMS.Log.LogLevel.NOTICE) + }; + + jsOMS.Log.Logger.prototype.info = function(message, context) + { + context = typeof context === 'undefined' ? {} : context; + + this.write(message, context, jsOMS.Log.LogLevel.INFO) + }; + + jsOMS.Log.Logger.prototype.debug = function(message, context) + { + context = typeof context === 'undefined' ? {} : context; + + this.write(message, context, jsOMS.Log.LogLevel.DEBUG) + }; + + jsOMS.Log.Logger.prototype.log = function(level, message, context) + { + context = typeof context === 'undefined' ? {} : context; + + this.write(message, context, context) + }; + + jsOMS.Log.Logger.prototype.console = function(level, message, context) + { + context = typeof context === 'undefined' ? {} : context; + + this.write(message, context, jsOMS.Log.LogLevel.INFO) + }; +}(window.jsOMS = window.jsOMS || {})); diff --git a/Message/Request/BrowserType.enum.js b/Message/Request/BrowserType.enum.js new file mode 100644 index 0000000..eb2ef07 --- /dev/null +++ b/Message/Request/BrowserType.enum.js @@ -0,0 +1,23 @@ +/** + * Request data enum. + * + * @author OMS Development Team + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 * @since 1.0.0 + */ +(function (jsOMS, undefined) +{ + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); + + jsOMS.Message.Request.BrowserType = Object.freeze({ + OPERA: 'opera', + FIREFOX: 'firefox', + SAFARI: 'safari', + IE: 'msie', + EDGE: 'edge', + CHROME: 'chrome', + BLINK: 'blink', + }); +}(window.jsOMS = window.jsOMS || {})); diff --git a/Message/Request/OSType.enum.js b/Message/Request/OSType.enum.js new file mode 100644 index 0000000..06456b7 --- /dev/null +++ b/Message/Request/OSType.enum.js @@ -0,0 +1,39 @@ +/** + * Request data enum. + * + * @author OMS Development Team + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 * @since 1.0.0 + */ +(function (jsOMS, undefined) +{ + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); + + jsOMS.Message.Request.OSType = Object.freeze({ + WINDOWS_81: 'windows nt 6.3', /* Windows 8.1 */ + WINDOWS_8: 'windows nt 6.2', /* Windows 8 */ + WINDOWS_7: 'windows nt 6.1', /* Windows 7 */ + WINDOWS_VISTA: 'windows nt 6.0', /* Windows Vista */ + WINDOWS_SERVER: 'windows nt 5.2', /* Windows Server 2003/XP x64 */ + WINDOWS_XP: 'windows nt 5.1', /* Windows XP */ + WINDOWS_XP_2: 'windows xp', /* Windows XP */ + WINDOWS_2000: 'windows nt 5.0', /* Windows 2000 */ + WINDOWS_ME: 'windows me', /* Windows ME */ + WINDOWS_98: 'win98', /* Windows 98 */ + WINDOWS_95: 'win95', /* Windows 95 */ + WINDOWS_311: 'win16', /* Windows 3.11 */ + MAC_OS_X: 'macintosh', /* Mac OS X */ + MAC_OS_X_2: 'mac os x', /* Mac OS X */ + MAC_OS_9: 'mac_powerpc', /* Mac OS 9 */ + LINUX : 'linux', /* Linux */ + UBUNTU: 'ubuntu', /* Ubuntu */ + IPHONE: 'iphone', /* IPhone */ + IPOD: 'ipod', /* IPod */ + IPAD: 'ipad', /* IPad */ + ANDROID: 'android', /* Android */ + BLACKBERRY: 'blackberry', /* Blackberry */ + MOBILE: 'webos' /* Mobile */ + }); +}(window.jsOMS = window.jsOMS || {})); diff --git a/Message/Request/Request.js b/Message/Request/Request.js index 3cb2acd..b74661b 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -9,25 +9,56 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request = function () + jsOMS.Message.Request.Request = function (uri, method, type) { - this.uri = null; - this.method = null; + this.uri = typeof uri !== 'undefined' ? uri : null; + this.method = typeof method !== 'undefined' ? method : jsOMS.Message.Request.RequestMethod.GET; this.requestHeader = []; this.success = null; - this.type = jsOMS.EnumRequestMethod.GET; + this.type = typeof type !== 'undefined' ? type : jsOMS.Message.Response.ResponseType.JSON; this.data = {}; + + this.xhr = new XMLHttpRequest(); }; + jsOMS.Message.Request.Request.getBrowser = function() + { + if((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { + return jsOMS.Message.Request.BrowserType.OPERA; + } else if(typeof InstallTrigger !== 'undefined') { + return jsOMS.Message.Request.BrowserType.FIREFOX; + } else if(Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0) { + return jsOMS.Message.Request.BrowserType.SAFARI; + } else if(/*@cc_on!@*/false || !!document.documentMode) { + return jsOMS.Message.Request.BrowserType.IE; + } else if(!!window.StyleMedia) { + return jsOMS.Message.Request.BrowserType.EDGE; + } else if(!!window.chrome && !!window.chrome.webstore) { + return jsOMS.Message.Request.BrowserType.CHROME; + } else if((isChrome || isOpera) && !!window.CSS) { + return jsOMS.Message.Request.BrowserType.BLINK; + } + }; + + jsOMS.Message.Request.Request.getOS = function() + { + for(let os in jsOMS.Message.Request.OSType) { + if(navigator.appVersion.toLowerCase().indexOf(jsOMS.Message.Request.OSType[os]) !== -1) { + return jsOMS.Message.Request.OSType[os]; + } + } + }; + /** * Set request method. * @@ -40,7 +71,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setMethod = function (method) + jsOMS.Message.Request.Request.prototype.setMethod = function (method) { this.method = method; }; @@ -57,7 +88,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getMethod = function () + jsOMS.Message.Request.Request.prototype.getMethod = function () { return this.method; }; @@ -74,7 +105,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setResponseType = function (type) + jsOMS.Message.Request.Request.prototype.setResponseType = function (type) { this.xhr.responseType = type; }; @@ -91,7 +122,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getResponseType = function () + jsOMS.Message.Request.Request.prototype.getResponseType = function () { return this.responseType; }; @@ -107,7 +138,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setRequestHeader = function (type, header) + jsOMS.Message.Request.Request.prototype.setRequestHeader = function (type, header) { this.requestHeader[type] = header; }; @@ -122,7 +153,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getRequestHeader = function () + jsOMS.Message.Request.Request.prototype.getRequestHeader = function () { return this.requestHeader; }; @@ -137,7 +168,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setUri = function (uri) + jsOMS.Message.Request.Request.prototype.setUri = function (uri) { this.uri = uri; }; @@ -152,7 +183,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getUri = function () + jsOMS.Message.Request.Request.prototype.getUri = function () { return this.uri; }; @@ -167,7 +198,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setSuccess = function (callback) + jsOMS.Message.Request.Request.prototype.setSuccess = function (callback) { this.success = callback; }; @@ -182,7 +213,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setData = function (data) + jsOMS.Message.Request.Request.prototype.setData = function (data) { this.data = data; }; @@ -197,7 +228,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getData = function () + jsOMS.Message.Request.Request.prototype.getData = function () { return this.data }; @@ -214,7 +245,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setType = function (type) + jsOMS.Message.Request.Request.prototype.setType = function (type) { this.type = type; }; @@ -231,7 +262,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getType = function () + jsOMS.Message.Request.Request.prototype.getType = function () { return this.type; }; @@ -246,10 +277,10 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.queryfy = function (obj) + jsOMS.Message.Request.Request.prototype.queryfy = function (obj) { - var str = []; - for (var p in obj) { + let str = []; + for (let p in obj) { if (obj.hasOwnProperty(p)) { str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); } @@ -267,14 +298,14 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.send = function () + jsOMS.Message.Request.Request.prototype.send = function () { - var self = this; + let self = this; if (self.xhr.readyState !== 1) { - self.xhr.open(this.method, this.uri); + self.xhr.open(this.method, jsOMS.Uri.UriFactory.build(this.uri)); - for (var p in this.requestHeader) { + for (let p in this.requestHeader) { if (this.requestHeader.hasOwnProperty(p)) { self.xhr.setRequestHeader(p, this.requestHeader[p]); } @@ -288,14 +319,14 @@ } }; - if (this.type === jsOMS.EnumRequestType.JSON) { + if (this.type === jsOMS.Message.Request.RequestType.JSON) { if (typeof this.requestHeader !== 'undefined' && this.requestHeader['Content-Type'] === 'application/json') { console.log(JSON.stringify(this.data)); self.xhr.send(JSON.stringify(this.data)); } else { self.xhr.send(this.queryfy(this.data)); } - } else if (this.type === jsOMS.EnumRequestType.RAW) { + } else if (this.type === jsOMS.Message.Request.RequestType.RAW) { self.xhr.send(this.data); } }; diff --git a/Message/Request/RequestData.enum.js b/Message/Request/RequestData.enum.js index b866749..397db81 100644 --- a/Message/Request/RequestData.enum.js +++ b/Message/Request/RequestData.enum.js @@ -9,7 +9,9 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumLinkRequestData = Object.freeze({ + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); + + jsOMS.Message.RequestLinkRequestData = Object.freeze({ NORMAL: 'normal', OBJECT: 'object' }); diff --git a/Message/Request/RequestManager.js b/Message/Request/RequestManager.js index 16002ea..7945719 100644 --- a/Message/Request/RequestManager.js +++ b/Message/Request/RequestManager.js @@ -11,14 +11,15 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.RequestManager = function () + jsOMS.Message.Request.RequestManager = function () { }; }(window.jsOMS = window.jsOMS || {})); diff --git a/Message/Request/RequestMethod.enum.js b/Message/Request/RequestMethod.enum.js index fc9ccfd..6b22636 100644 --- a/Message/Request/RequestMethod.enum.js +++ b/Message/Request/RequestMethod.enum.js @@ -9,7 +9,9 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumRequestMethod = Object.freeze({ + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); + + jsOMS.Message.Request.RequestMethod = Object.freeze({ POST: 'POST', GET: 'GET', PUT: 'PUT', diff --git a/Message/Request/RequestType.enum.js b/Message/Request/RequestType.enum.js index d08817d..cdfb09c 100644 --- a/Message/Request/RequestType.enum.js +++ b/Message/Request/RequestType.enum.js @@ -9,7 +9,9 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumRequestType = Object.freeze({ + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); + + jsOMS.Message.Request.RequestType = Object.freeze({ JSON: 'json', RAW: 'raw' }); diff --git a/Message/Response/Response.js b/Message/Response/Response.js new file mode 100644 index 0000000..007abff --- /dev/null +++ b/Message/Response/Response.js @@ -0,0 +1,23 @@ +(function (uriFactory, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); + + jsOMS.Message.Response.Response = function (data) { + this.responses = data; + }; + + jsOMS.Message.Response.Response.prototype.get = function(id) + { + return this.responses[id]; + }; + + jsOMS.Message.Response.Response.prototype.getByIndex = function(index) + { + //return this.responses[Object.keys(this.responses).sort()[index]]; + return this.responses; + }; + + jsOMS.Message.Response.Response.prototype.count = function() + { + return 1; + }; +}(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/Message/Response/ResponseManager.js b/Message/Response/ResponseManager.js index ff9cb1c..d5456b6 100644 --- a/Message/Response/ResponseManager.js +++ b/Message/Response/ResponseManager.js @@ -11,6 +11,7 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); /** * @constructor @@ -18,7 +19,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.ResponseManager = function () + jsOMS.Message.Response.ResponseManager = function () { this.messages = {}; }; @@ -37,7 +38,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.ResponseManager.prototype.add = function (key, message, request) + jsOMS.Message.Response.ResponseManager.prototype.add = function (key, message, request) { request = typeof request !== 'undefined' ? request : 'any'; if (typeof this.messages[key] === 'undefined') { @@ -61,7 +62,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.ResponseManager.prototype.execute = function (key, data, request) + jsOMS.Message.Response.ResponseManager.prototype.run = function (key, data, request) { console.log(data); if (typeof request !== 'undefined' && typeof this.messages[key][request] !== 'undefined') { diff --git a/Message/Response/ResponseResultType.enum.js b/Message/Response/ResponseResultType.enum.js index 6b71086..d0d1ef3 100644 --- a/Message/Response/ResponseResultType.enum.js +++ b/Message/Response/ResponseResultType.enum.js @@ -9,7 +9,9 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumResponseResultType = Object.freeze({ + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); + + jsOMS.Message.Response.ResponseResultType = Object.freeze({ MULTI: 0, MESSAGE: 1, INFO: 2, diff --git a/Message/Response/ResponseType.enum.js b/Message/Response/ResponseType.enum.js index 83cd396..97c0678 100644 --- a/Message/Response/ResponseType.enum.js +++ b/Message/Response/ResponseType.enum.js @@ -9,7 +9,9 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumResponseType = Object.freeze({ + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); + + jsOMS.Message.Response.ResponseType = Object.freeze({ TEXT: 'text', JSON: 'json', DOCUMENT: 'document', diff --git a/Module/ModuleFactory.js b/Module/ModuleFactory.js index 6b7e038..85e0a3a 100644 --- a/Module/ModuleFactory.js +++ b/Module/ModuleFactory.js @@ -9,14 +9,15 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.Module'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.ModuleFactory = function () + jsOMS.Module.ModuleFactory = function () { }; @@ -33,7 +34,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.ModuleFactory.getInstance = function (module, app) + jsOMS.Module.ModuleFactory.getInstance = function (module, app) { return new window['jsOMS']['Modules'][module](app); }; diff --git a/Module/ModuleManager.js b/Module/ModuleManager.js index 44b8241..7064c22 100644 --- a/Module/ModuleManager.js +++ b/Module/ModuleManager.js @@ -9,8 +9,7 @@ */ (function (jsOMS, undefined) { - jsOMS.Modules = {}; - jsOMS.Modules.Models = {}; + jsOMS.Autoloader.defineNamespace('jsOMS.Module'); /** * @constructor @@ -18,7 +17,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.ModuleManager = function (app) + jsOMS.Module.ModuleManager = function (app) { this.modules = {}; this.app = app; @@ -36,7 +35,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.ModuleManager.prototype.get = function (module) + jsOMS.Module.ModuleManager.prototype.get = function (module) { if (this.modules[module] === undefined) { this.modules[module] = jsOMS.ModuleFactory.getInstance(module, this.app); diff --git a/Route/Route.js b/Route/Route.js index a52310a..4839840 100644 --- a/Route/Route.js +++ b/Route/Route.js @@ -1,6 +1,8 @@ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Route'); + // TODO: create comments - jsOMS.Route = function () + jsOMS.Route.Route = function () { this.routes = null; }; diff --git a/UI/LinkManager.js b/UI/Button.js similarity index 100% rename from UI/LinkManager.js rename to UI/Button.js diff --git a/UI/FormManager.js b/UI/FormManager.js index 709585c..d5921c3 100644 --- a/UI/FormManager.js +++ b/UI/FormManager.js @@ -7,61 +7,83 @@ * @license OMS License 1.0 * @version 1.0.0 * @since 1.0.0 */ -(function (jsOMS, undefined) -{ - "use strict"; - + (function (jsOMS, undefined) + { + jsOMS.Autoloader.defineNamespace('jsOMS.UI'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.FormManager = function (responseManager) - { - this.responseManager = responseManager; - this.ignore = []; - this.success = []; - this.injectSelector = []; - this.forms = []; + jsOMS.UI.FormManager = function(app) + { + this.app = app; + this.forms = {}; + this.ignore = {}; }; - /** - * Ignore form from handling. - * - * @param {string} [id] Form id - * - * @method - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.FormManager.prototype.ignore = function (id) + jsOMS.UI.FormManager.prototype.get = function(id) { - this.ignore.push(id); + return this.forms[id]; }; - /** - * Add submit callback. - * - * Used for calling callback before form is submitted. If there is a submit injection the injection itself has to execute the submit since only the injection knows when it finished. - * - * @todo: maybe let the injected callback call a continue() function in here which then continues the form submit process. - * - * @param {string} selector Form id - * @param {requestCallback} callback Callback to execute before submit - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.FormManager.prototype.injectSubmit = function (selector, callback) + jsOMS.UI.FormManager.prototype.isIgnored = function(id) { - if (!(selector in this.injectSelector)) { - this.injectSelector[selector] = callback; + return this.ignore.indexOf(id) !== -1; + }; + + jsOMS.UI.FormManager.prototype.unbind = function(id) + { + + }; + + jsOMS.UI.FormManager.prototype.bind = function(id) + { + if (typeof id !== 'undefined' && typeof this.ignore[id] === 'undefined') { + this.bindForm(id) + } else { + let forms = document.getElementsByTagName('form'), + length = forms.length; + + for (var i = 0; i < length; i++) { + if (typeof this.ignore[forms[i].id] === 'undefined') { + this.bindForm(forms[i].id); + } + } + } + }; + + jsOMS.UI.FormManager.prototype.bindForm = function(id) + { + if(typeof id === 'undefined' || !id) { + this.app.logger.info('A form doesn\'t have an ID.'); + return; + } + + let self = this; + + this.unbind(id); + + if(typeof this.ignore[id] === 'undefined') { + this.forms[id] = new jsOMS.Views.FormView(id); + } + + this.forms[id].getSubmit().addEventListener('click', function(event) { + self.submit(self.forms[id]); + jsOMS.preventAll(event); + }); + }; + + jsOMS.UI.FormManager.prototype.unbindForm = function(id) + { + // todo: do i need the findex? can't i just use id? + let findex = 0; + + if((findex = this.forms[id]) !== 'undefined') { + this.forms[id].unbind(); + this.forms.splice(findex, 1); return true; } @@ -69,120 +91,45 @@ return false; }; - /** - * Set success callback for form. - * - * @param {string} id Form id - * @param {requestCallback} callback Callback for success - * - * @method - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.FormManager.prototype.setSuccess = function (id, callback) + jsOMS.UI.FormManager.prototype.submit = function(form) { - this.success[id] = callback; - }; - - /** - * Bind form. - * - * @param {string} [id] Form id - * - * @method - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.FormManager.prototype.bind = function (id) - { - if (typeof id !== 'undefined' && this.ignore.indexOf(id) === -1) { - let form = document.getElementById(id); - - this.forms.push(form); - this.bindElement(form); - } else { - let forms = document.getElementsByTagName('form'); - - for (var i = 0; i < forms.length; i++) { - if (this.ignore.indexOf(forms[i].id) === -1) { - this.forms.push(forms[i]); - this.bindElement(forms[i]); - } - } - } - }; - - /** - * Validating form element. - * - * @param {Object} e Form element - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.FormManager.prototype.validateFormElement = function (e) - { - /** Validate on change */ - if (typeof e.pattern !== 'undefined') { - if (!(new RegExp(e.pattern)).test(e.value)) { - return false; - } + /* Handle injects */ + let injects = form.getSubmitInjects(); + for(let property in injects) { + property(); } - return true; - }; + /* Handle default submit */ + let request = new jsOMS.Message.Request.Request(), + self = this; - /** - * Submit data. - * - * @param {Object} e Form element - * @param {Object} data Data to submit - * - * @method - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.FormManager.prototype.submit = function (e, data) - { - var request = new jsOMS.Request(), - self = this; - - request.setData(data); - request.setType('json'); - request.setUri(e.action); - request.setMethod(e.method); + request.setData(form.getData()); + request.setType(jsOMS.Message.Response.ResponseType.JSON); + request.setUri(form.getAction()); + request.setMethod(form.getMethod()); request.setRequestHeader('Content-Type', 'application/json'); request.setSuccess(function (xhr) { - console.log(xhr); // TODO: remove this is for error checking try { - var o = JSON.parse(xhr.response), - response = Object.keys(o).map(function (k) - { - return o[k] - }); + let o = JSON.parse(xhr.response), + response = new jsOMS.Message.Response.Response(o), + responseLength = response.count(), + tempResponse = null, + success = null; - for (var k = 0; k < response.length; k++) { - if (response[k] !== null) { - console.log(response[k]); + /* Handle responses (can be multiple response object) */ + for (let k = 0; k < responseLength; k++) { + tempResponse = response.getByIndex(k); - /* Handle success */ - if (!self.success[e.id]) { - self.responseManager.execute(response[k].type, response[k]); - } else { - self.success[e.id](response[k].type, response[k]); - } + if((success = form.getSuccess()) !== null) { + success(tempResponse); + } else { + self.app.responseManager.run(tempResponse.type, tempResponse, request); } } } catch (exception) { - console.log('No valid json'); + self.app.logger.error('Invalid Login response: ' + JSON.stringify(xhr)); + return false; } }); @@ -190,241 +137,7 @@ request.send(); }; - /** - * Collect all data associated with the form. - * - * @param {Object} e Form element - * - * @method - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.FormManager.prototype.getData = function (e) - { - var input = e.getElementsByTagName('input'), - select = e.getElementsByTagName('select'), - textarea = e.getElementsByTagName('textarea'), - datalist = e.getElementsByTagName('datalist'), - formelements = Array.prototype.slice.call(input).concat(Array.prototype.slice.call(select), Array.prototype.slice.call(textarea), Array.prototype.slice.call(datalist)), - self = this; - - var validForm = true, - submitdata = {}; - - for (var k = 0; k < formelements.length; k++) { - if (!self.validateFormElement(e)) { - validForm = false; - // TODO: maybe jump out here since invalid and the elements get checked on changed by default - // will this change in the future? if yes then I need to check all and also add markup/styles here - } - - submitdata[formelements[k].getAttribute('name')] = formelements[k].value; - } - - if (!validForm) { - console.log('Form contains invalid data'); - } - - //noinspection JSUnresolvedVariable - if (typeof e.dataset.formfields !== 'undefined') { - try { - //noinspection JSUnresolvedVariable - var formdata = JSON.parse(e.dataset.formfields); - - Object.keys(formdata).forEach(function (key) - { - if (formdata[key].startsWith('.') || formdata[key].startsWith('#')) { - var formElement = document.querySelector(formdata[key]); - - if (formElement.type === 'checkbox') { - submitdata[key] = formElement.checked; - } else { - submitdata[key] = formElement.value; - } - } - }); - } catch (exception) { - } - } - - return submitdata; - }; - - /** - * Bind form. - * - * @param {Object} e Form element - * - * @method - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.FormManager.prototype.bindElement = function (e) - { - var input = e.getElementsByTagName('input'), - select = e.getElementsByTagName('select'), - textarea = e.getElementsByTagName('textarea'), - datalist = e.getElementsByTagName('datalist'), - buttons = (Array.prototype.slice.call(e.getElementsByTagName('button'))).concat(Array.prototype.slice.call(e.querySelectorAll('input[type=button]'))), - submits = e.querySelectorAll('input[type=submit]'), - self = this, - submitdata = {}; - - /** Handle submits */ - for (var j = 0; j < submits.length; j++) { - submits[j].addEventListener('click', function (event) - { - submitdata = self.getData(e); - - /* Handle injection */ - var injected = false; - - for (var key in self.injectSelector) { - if (e.id === key) { - // This calls the injection callback which in returns executes the form submit afterwards - // @todo: maybe let provide a continue() function here which continues the execution; - self.injectSelector[key](e); - - injected = true; - } - } - - if (!injected) { - self.submit(e, submitdata); - } - - jsOMS.preventAll(event); - }); - } - - var i; - /** Handle input */ - for (i = 0; i < input.length; i++) { - /** Validate on change */ - if (typeof input[i].dataset.validate !== 'undefined') { - var validator = new RegExp(input[i].dataset.validate); - - input[i].onkeyup = function (e) - { - var selfL = this; - jsOMS.watcher(function (e) - { - if (!validator.test(selfL.value)) { - jsOMS.addClass(selfL, 'invalid'); - console.log('wrong input:' + i); - } - }, 500); - }; - } - - /** Request on change */ - if (typeof input[i].dataset.request !== 'undefined') { - // handle request during typing - } - } - - /** Handle select */ - for (i = 0; i < select.length; i++) { - /** Redirect on change */ - //noinspection JSUnresolvedVariable - if (typeof select[i].dataset.redirect !== 'undefined') { - select[i].onchange = function () - { - // TODO: use URI factory (which i still have to create :)) - //noinspection JSUnresolvedVariable - window.document.href = e.action.replace('{' + select[i].dataset.redirect + '}', select[i].value); - }; - } - } - - /** Handle button */ - for (i = 0; i < buttons.length; i++) { - /** Redirect in new window on click */ - //noinspection JSUnresolvedVariable - if (typeof buttons[i].dataset.ropen !== 'undefined' || typeof buttons[i].dataset.redirect !== 'undefined') { - buttons[i].addEventListener('click', function (event) - { - //noinspection JSUnresolvedVariable - let ropen = typeof this.dataset.ropen !== 'undefined' ? this.dataset.ropen : this.dataset.redirect, - matches = ropen.match(new RegExp("\{[#\?\.a-zA-Z0-9]*\}", "gi")), - current = jsOMS.Uri.parseUrl(window.location.href), - value = null; - - // TODO: find a way to use existing query parameters as well and just overwrite them if defined differently here - // eg. use &? in dummy urls to indicate that the url should use existing query parameters as well if not overwritten - for (var c = 0; c < matches.length; c++) { - var match = matches[c].substring(1, matches[c].length - 1); - if (match.indexOf('#') === 0) { - value = document.getElementById(match.substring(1, match.length)).value; - } else if (match.indexOf('.') === 0) { - - } else if (match.indexOf('?') === 0) { - value = jsOMS.Uri.getUriQueryParameter(current.query, match.substring(1, match.length)); - } - - ropen = ropen.replace(matches[c], value); - } - - //noinspection JSUnresolvedVariable - if (typeof this.dataset.ropen !== 'undefined') { - var win = window.open(ropen, '_blank'); - win.focus(); - } else { - window.document.href = ropen; - } - }); - } else if (jsOMS.hasClass(buttons[i], 'form-list') && buttons[i].dataset.name !== 'undefined') { - - // TODO: maybe validate input value??? if not done during typing - // TODO: maybe use id here instead? then this needs to get changed in the form builder - let inputButton = document.querySelector('input[name=' + buttons[i].dataset.name + ']'), - list = document.querySelector('ul[data-name=l-' + buttons[i].dataset.name + ']'), - hidden = document.querySelector('input[type=hidden][name=h-' + buttons[i].dataset.name + ']'); - buttons[i].addEventListener('click', function (event) - { - - if (hidden.bind === undefined) { - hidden.bind = []; - } - - hidden.bind.push(inputButton.bind ? inputButton.bind : inputButton.value); - hidden.value = JSON.stringify(hidden.bind); - - var element = document.createElement('li'); - element.appendChild(document.createTextNode(inputButton.value)); - list.appendChild(element); - }); - } else if (jsOMS.hasClass(buttons[i], 'form-table') && buttons[i].dataset.name !== 'undefined') { - // TODO: maybe use id here instead? then this needs to get changed in the form builder - let inputButton = document.querySelector('input[name=' + buttons[i].dataset.name + ']'), - table = document.querySelector('table[data-name=l-' + buttons[i].dataset.name + ']'), - hidden = document.querySelector('input[type=hidden][name=h-' + buttons[i].dataset.name + ']'); - - buttons[i].addEventListener('click', function (event) - { - // TODO: maybe validate input value??? if not done during typing - - if (hidden.bind === undefined) { - hidden.bind = []; - } - - hidden.bind.push(inputButton.bind ? inputButton.bind : inputButton.value); - hidden.value = JSON.stringify(hidden.bind); - - // TODO: handle table add - }); - } - } - }; - - jsOMS.FormManager.prototype.getElements = function () - { - return this.forms; - }; - - jsOMS.FormManager.prototype.count = function () + jsOMS.UI.FormManager.prototype.count = function () { return this.forms.length; }; diff --git a/UI/Input.js b/UI/Input.js new file mode 100644 index 0000000..9b26426 --- /dev/null +++ b/UI/Input.js @@ -0,0 +1,118 @@ +/** + * Form manager class. + * + * @author OMS Development Team + * @author Dennis Eichhorn + * @copyright 2013 Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 * @since 1.0.0 + */ +(function (jsOMS, undefined) +{ + "use strict"; + jsOMS.Autoloader.defineNamespace('jsOMS.UI'); + + /** + * @constructor + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.UI.Input.unbind = function(input) + { + this.app.inputManager.getKeyboardManager().unbind(input); + input.removeEventListener('change', changeBind, false); + }; + + jsOMS.UI.Input.bind = function(input) + { + let self = this; + + input.addEventListener('change', function changeBind(event) { + /* Handle remote datalist/autocomplete input element */ + let listId, list; + if(typeof (listId = this.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') { + self.addRemoteDatalistOptions(this, list); + } + + /* Handle html defined functions */ + let change; + if(typeof (change = this.getAttribute('data-change-func')) !== 'undefined') { + change(this); + } + + /* Handle pre-defined dynamic change events */ + let ref; + if(typeof (ref = this.getAttribute('data-ref')) !== 'undefined') { + let e = document.getElementById(ref); + + switch(e.tagName) { + case 'ul': + break; + case 'table': + break; + }; + } + }); + + let dataButton; + if(typeof (dataButton = input.getAttribute('data-button')) !== 'undefined') { + this.app.inputManager.getKeyboardManager().bind(input, 13, function() { + document.getElementById(dataButton).click(); + }); + } + }; + + jsOMS.UI.Input.addRemoteDatalistOptions = function(input, datalist) + { + this.clearDatalistOptions(datalist); + + let request = new Request(); + request.setData(input.value); + request.setType(jsOMS.Message.Response.ResponseType.JSON); + request.setUri(datalist.getAttribute('data-list-src')); + request.setMethod(jsOMS.Message.Request.RequestMethod.POST); + request.setRequestHeader('Content-Type', 'application/json'); + request.setSuccess(function (xhr) { + try { + let o = JSON.parse(xhr.response), + response = new Response(o), + responseLength = response.count(), + tempResponse = null, + success = null; + + for (let k = 0; k < responseLength; k++) { + tempResponse = response.getByIndex(k); + console.log(tempResponse); + + let option = null, + data = tempResponse.getData(), + length = data.length; + + for(let i = 0; i < length; i++) { + option = document.createElement('option'); + option.value = tempResponse.value; + option.text = tempResponse.text; + + datalist.appendChild(option); + } + } + } catch (exception) { + self.app.logger.error('Invalid JSON object: ' + xhr, 'FormManager') + return false; + } + }); + + request.send(); + }; + + jsOMS.UI.Input.clearDatalistOptions = function(datalist) + { + let length = datalist.options.length, + i = 0; + + for(i = 0; i < length; i++) { + datalist.remove(0); + } + }; +}(window.jsOMS = window.jsOMS || {})); diff --git a/UI/Input/InputManager.js b/UI/Input/InputManager.js index 5fca112..1e82664 100644 --- a/UI/Input/InputManager.js +++ b/UI/Input/InputManager.js @@ -1,5 +1,13 @@ (function (jsOMS, undefined) { - jsOMS.InputManager = function () - { - }; + jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input'); + + jsOMS.UI.Input.InputManager = function () + { + this.keyBoardManager = new jsOMS.UI.Input.Keyboard.KeyboardManager(); + }; + + jsOMS.UI.Input.InputManager.prototype.getKeyboardManager = function() + { + return this.keyBoardManager; + }; }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/Input/Keyboard/KeyboardManager.js b/UI/Input/Keyboard/KeyboardManager.js index b75d0cf..366475c 100644 --- a/UI/Input/Keyboard/KeyboardManager.js +++ b/UI/Input/Keyboard/KeyboardManager.js @@ -1,11 +1,22 @@ (function (jsOMS, undefined) { - jsOMS.KeyboardManager = function () + jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Keyboard'); + + jsOMS.UI.Input.Keyboard.KeyboardManager = function () { }; - jsOMS.KeyboardManager.prototype.attach = function (element, keys, callback) { + jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.bind = function (element, keys, callback) + { + element.addEventListener('keyup', function keyBind(event) { + if(event.keyCode === keys.keyCode) { + callback(); + } + }); + }; - jsOMS.KeyboardManager.prototype.detach = function (eventId) { + jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.unbind = function (element) + { + element.removeEventListener('keyup', keyBind, false); }; }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/InputElements.js b/UI/InputElements.js deleted file mode 100644 index e9aa0bc..0000000 --- a/UI/InputElements.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Form manager class. - * - * @author OMS Development Team - * @author Dennis Eichhorn - * @copyright 2013 Dennis Eichhorn - * @license OMS License 1.0 - * @version 1.0.0 * @since 1.0.0 - */ -(function (jsOMS, undefined) -{ - "use strict"; - - /** - * @constructor - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.InputElements = function () - { - this.elements = []; - }; - - jsOMS.InputElements.prototype.bind = function(id) - { - - }; - - jsOMS.InputElements.prototype.bindElement = function(e) - { - switch(e.dataset.type) { - case jsOMS.InputElementsEnum.AUTOCOMPLETE: - // autocomplete with drop down returns object - // { value: , text: , data: 'could be object'} - break; - case jsOMS.InputElementsEnum.POPUP: - break; - } - }; -} \ No newline at end of file diff --git a/UI/Select.js b/UI/Select.js new file mode 100644 index 0000000..e69de29 diff --git a/UI/TabManager.js b/UI/TabManager.js index e988670..8e45cfd 100644 --- a/UI/TabManager.js +++ b/UI/TabManager.js @@ -9,14 +9,15 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.UI'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.TabManager = function (responseManager) + jsOMS.UI.TabManager = function (responseManager) { this.responseManager = responseManager; }; @@ -31,7 +32,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.TabManager.prototype.bind = function (id) + jsOMS.UI.TabManager.prototype.bind = function (id) { if (typeof id !== 'undefined') { this.bindElement(document.getElementById(id)); @@ -54,7 +55,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.TabManager.prototype.bindElement = function (e) + jsOMS.UI.TabManager.prototype.bindElement = function (e) { var nodes = e.querySelectorAll('.tab-links a'); diff --git a/UI/TableManager.js b/UI/TableManager.js index 07a9873..d16f544 100644 --- a/UI/TableManager.js +++ b/UI/TableManager.js @@ -9,14 +9,15 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.UI'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.TableManager = function (responseManager) + jsOMS.UI.TableManager = function (responseManager) { this.responseManager = responseManager; }; @@ -31,7 +32,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.TableManager.prototype.bind = function (id) + jsOMS.UI.TableManager.prototype.bind = function (id) { if (typeof id !== 'undefined') { this.bindElement(document.getElementById(id)); @@ -54,7 +55,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.TableManager.prototype.bindElement = function (e) + jsOMS.UI.TableManager.prototype.bindElement = function (e) { }; }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/UIManager.js b/UI/UIManager.js index 3257337..3d65cef 100644 --- a/UI/UIManager.js +++ b/UI/UIManager.js @@ -9,19 +9,20 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.UI'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.UIManager = function (app) + jsOMS.UI.UIManager = function (app) { this.app = app; - this.formManager = new jsOMS.FormManager(this.app.responseManager); - this.tabManager = new jsOMS.TabManager(this.app.responseManager); - this.tableManager = new jsOMS.TableManager(this.app.responseManager); + this.formManager = new jsOMS.UI.FormManager(this.app); + this.tabManager = new jsOMS.UI.TabManager(this.app.responseManager); + this.tableManager = new jsOMS.UI.TableManager(this.app.responseManager); }; /** @@ -34,22 +35,23 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.UIManager.prototype.bind = function (id) + jsOMS.UI.UIManager.prototype.bind = function (id) { if (typeof id === 'undefined') { this.formManager.bind(); this.tabManager.bind(); this.tableManager.bind(); } else { - var tag = document.getElementById(id); + let tag = document.getElementById(id); - if (tag.tagName === 'form') { - this.formManager.bind(id); - } else if (tag.tagName === 'table') { - this.tableManager.bind(id); - } else if (tag.tagName === 'div') { - // Todo: be more specific in order to handle tab - } + switch(tag.tagName) { + case 'form': + this.formManager.bind(id); + break; + case 'table': + this.tableManager.bind(id); + break; + }; } }; @@ -63,7 +65,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.UIManager.prototype.getFormManager = function () + jsOMS.UI.UIManager.prototype.getFormManager = function () { return this.formManager; }; @@ -78,7 +80,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.UIManager.prototype.getTabManager = function () + jsOMS.UI.UIManager.prototype.getTabManager = function () { return this.tabManager; }; @@ -93,7 +95,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.UIManager.prototype.getTableManager = function () + jsOMS.UI.UIManager.prototype.getTableManager = function () { return this.tabManager; }; diff --git a/Uri/Uri.js b/Uri/Uri.js deleted file mode 100644 index 0afff17..0000000 --- a/Uri/Uri.js +++ /dev/null @@ -1,106 +0,0 @@ -/** - * UI manager for handling basic ui elements. - * - * @author OMS Development Team - * @author Dennis Eichhorn - * @copyright 2013 Dennis Eichhorn - * @license OMS License 1.0 - * @version 1.0.0 * @since 1.0.0 - */ -(function (jsOMS, undefined) -{ - - /** - * @constructor - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.Uri = function () - { - }; - - /** - * Prases a url. - * - * @param {string} str Url string - * @param {string} [component] I have no idea ?!?!??!?! - * - * @return {Object} - * - * @todo: fix this some parts are not used like components, mode, ini etc. - * - * @method - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.Uri.parseUrl = function (str, component) - { - var query, key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', - 'relative', 'path', 'directory', 'file', 'query', 'fragment' - ], - ini = (this.phpJs && this.phpJs.ini) || {}, - mode = (ini['phpjs.parseUrl.mode'] && - ini['phpjs.parseUrl.mode'].local_value) || 'php', - parser = { - php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, - strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, - loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this) - }; - - var m = parser[mode].exec(str), - uri = {}, - i = 14; - - while (i--) { - if (m[i]) { - uri[key[i]] = m[i]; - } - } - - if (component) { - return uri[component.replace('PHP_URL_', '') - .toLowerCase()]; - } - - if (mode !== 'php') { - var name = (ini['phpjs.parseUrl.queryKey'] && - ini['phpjs.parseUrl.queryKey'].local_value) || 'queryKey'; - parser = /(?:^|&)([^&=]*)=?([^&]*)/g; - uri[name] = {}; - query = uri[key[12]] || ''; - query.replace(parser, function ($0, $1, $2) - { - if ($1) { - uri[name][$1] = $2; - } - }); - } - - delete uri.source; - - return uri; - }; - - /** - * Get Uri query parameters. - * - * @param {string} query Uri query - * @param {string} name Name of the query to return - * - * @return {null|string} - * - * @method - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.Uri.getUriQueryParameter = function (query, name) - { - name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); - var regex = new RegExp("[\\?&]*" + name + "=([^&#]*)"), - results = regex.exec(query); - return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); - }; -}(window.jsOMS = window.jsOMS || {})); diff --git a/Uri/UriFactory.js b/Uri/UriFactory.js index 30d1572..f7252d4 100644 --- a/Uri/UriFactory.js +++ b/Uri/UriFactory.js @@ -1,3 +1,110 @@ (function (uriFactory, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Uri.UriFactory'); -}(window.jsOMS = window.jsOMS || {})); + jsOMS.Uri.UriFactory.parseUrl = function (str, component) + { + let query, key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', + 'relative', 'path', 'directory', 'file', 'query', 'fragment' + ], + ini = {}, + mode = 'php', + parser = { + php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, + strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, + loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this) + }; + + let m = parser[mode].exec(str), + uri = {}, + i = 14; + + while (i--) { + if (m[i]) { + uri[key[i]] = m[i]; + } + } + + if (component) { + return uri[component.replace('PHP_URL_', '').toLowerCase()]; + } + + if (mode !== 'php') { + let name = 'queryKey'; + parser = /(?:^|&)([^&=]*)=?([^&]*)/g; + uri[name] = {}; + query = uri[key[12]] || ''; + + query.replace(parser, function ($0, $1, $2) + { + if ($1) { + uri[name][$1] = $2; + } + }); + } + + delete uri.source; + + return uri; + }; + + /** + * Get Uri query parameters. + * + * @param {string} query Uri query + * @param {string} name Name of the query to return + * + * @return {null|string} + * + * @method + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.Uri.UriFactory.getUriQueryParameter = function (query, name) + { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + + let regex = new RegExp("[\\?&]*" + name + "=([^&#]*)"), + results = regex.exec(query); + + return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); + }; + + jsOMS.Uri.UriFactory.setQuery = function(key, value, overwrite) + { + overwrite = typeof overwrite !== 'undefined' ? overwrite : true; + + if(overwrite || !jsOMS.Uri.UriFactory.uri.hasProperty(key)) { + jsOMS.Uri.UriFactory.uri[key] = value; + + return true; + } + + return false; + }; + + jsOMS.Uri.UriFactory.build = function(uri, toMatch) + { + let current = jsOMS.Uri.UriFactory.parseUrl(window.location.href); + // match(new RegExp("\{[#\?\.a-zA-Z0-9]*\}", "gi")); + + return uri.replace('\{[\/#\?@\.\$][a-zA-Z0-9]*\}', function(match) { + match = substr(match[0], 1, match[0].length - 2); + + if(toMatch.hasProperty(match)) { + return toMatch[match]; + } else if(jsOMS.Uri.UriFactory.uri[match] !== 'undefined') { + return jsOMS.Uri.UriFactory.uri[match]; + } else if (match.indexOf('#') === 0) { + return document.getElementById(match.substring(1, match.length)).value; + } else if(match.indexOf('?') === 0) { + return jsOMS.Uri.UriFactory.getUriQueryParameter(current.query, match.substring(1, match.length)); + } else if(match.indexOf('/') === 0) { + // todo: second match should return second path + return 'ERROR PATH'; + } else { + return match; + } + }); + }; +}(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/Views/FormView.js b/Views/FormView.js index e7da5c5..b7d9f7e 100644 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -1,37 +1,161 @@ (function (jsOMS, undefined) { "use strict"; + jsOMS.Autoloader.defineNamespace('jsOMS.Views'); - jsOMS.FormView = function (element) { - this.id = element.getAttribute('id'); - this.formElement = element; + jsOMS.Views.FormView = function (id) { + this.id = id; - this.inputElement = {}; - this.textarea = {}; - this.button = {}; - this.select = {}; + this.initializeMembers(); + this.bind(); + this.success = null; }; - jsOMS.FormView.prototype.bind = function() + jsOMS.Views.FormView.prototype.initializeMembers = function() { - this.bindInput(); - this.bindTextarea(); - this.bindButton(); - this.bindSelect(); + this.submitInjects = {}; + this.method = 'POST'; + this.action = ''; + }; + + jsOMS.Views.FormView.prototype.getMethod = function() + { + return this.method; + }; + + jsOMS.Views.FormView.prototype.getAction = function() + { + return this.action; + }; + + jsOMS.Views.FormView.prototype.getSubmit = function() + { + return document.getElementById(this.id).querySelectorAll('input[type=submit]')[0]; + }; + + jsOMS.Views.FormView.prototype.getSuccess = function() + { + return this.success; + }; + + jsOMS.Views.FormView.prototype.setSuccess = function(callback) + { + this.success = callback; + }; + + jsOMS.Views.FormView.prototype.injectSubmit = function(id, callback) + { + this.submitInjects[id] = callback; + }; + + jsOMS.Views.FormView.prototype.getFormElements = function(id) + { + let form = document.getElementById(id), + selects = form.getElementsByTagName('select'), + textareas = form.getElementsByTagName('textarea'), + inputs = form.getElementsByTagName('input'), + external = document.querySelectorAll('[form='+id+']'), + elements = Array.prototype.slice.call(inputs).concat(Array.prototype.slice.call(selects), Array.prototype.slice.call(textareas), Array.prototype.slice.call(external)), + length = elements.length; + + return elements; } - jsOMS.FormView.prototype.bindInput = function() + jsOMS.Views.FormView.prototype.getData = function() { - var self = this; + let data = {}, + elements = this.getFormElements(this.id), + length = elements.length, + i = 0; - let inputs = this.formElement.getElementsByTagName('input'); + for(i = 0; i < length; i++) { + data[this.getElementId(elements[i])] = elements[i].value; + } - Object.keys(inputs).forEach(function (key, element) { - self.inputElement[element.getAttribute('id')] = { - id: element.getAttribute('id'), - type: element.getAttribute('type') + return data; + }; + + jsOMS.Views.FormView.prototype.getElementId = function(e) + { + let id = null; + + id = e.getAttribute('name'); + + if(id === null) { + id = e.getAttribute('id'); + } else { + return id; + } + + if(id === null) { + id = e.getAttribute('type'); + } else { + return id; + } + + return id; + } + + jsOMS.Views.FormView.prototype.getSubmitInjects = function() + { + return this.submitInjects; + }; + + jsOMS.Views.FormView.prototype.bind = function() + { + this.clean(); + + this.method = document.getElementById(this.id).method; + this.action = document.getElementById(this.id).action; + + let elements = this.getFormElements(this.id), + length = elements.length, + i = 0; + + for(i = 0; i < length; i++) { + switch(elements[i].tagName) { + case 'input': + jsOMS.UI.Input.bind(elements[i]) + break; + case 'select': + this.bindSelect(elements[i]); + break; + case 'textarea': + this.bindTextarea(elements[i]); + break; + case 'button': + this.bindButton(elements[i]); + break; }; - }); - } + } + }; - jsOMS.FormView.prototype.bind + jsOMS.Views.FormView.prototype.unbind = function() + { + let elements = this.getFormElements(this.id), + length = elements.length, + i = 0; + + for(i = 0; i < length; i++) { + switch(elements[i].tagName) { + case 'input': + jsOMS.UI.Input.unbind(elements[i]) + break; + case 'select': + this.bindSelect(elements[i]); + break; + case 'textarea': + this.bindTextarea(elements[i]); + break; + case 'button': + this.bindButton(elements[i]); + break; + }; + } + }; + + jsOMS.Views.FormView.prototype.clean = function() + { + this.unbind(); + this.initializeMembers(); + }; }(window.jsOMS = window.jsOMS || {})); diff --git a/autoloader.js b/autoloader.js new file mode 100644 index 0000000..166824b --- /dev/null +++ b/autoloader.js @@ -0,0 +1,60 @@ +(function (jsOMS, undefined) { + jsOMS.Autoloader = {}; + jsOMS.Autoloader.loaded = []; + jsOMS.Autoloader.namespaced = []; + + jsOMS.Autoloader.defineNamespace = function(namespace) + { + if(jsOMS.Autoloader.namespaced.indexOf(namespace) === -1) { + let paths = namespace.split('.'); + paths.splice(0, 1); + + let length = paths.length, + current = jsOMS; + + for(let i = 0; i < length; i++) { + if(typeof current[paths[i]] === 'undefined') { + current[paths[i]] = {}; + } + + current = current[paths[i]]; + } + + jsOMS.Autoloader.namespaced.push(namespace); + } + }; + + jsOMS.Autoloader.initPreloaded = function() + { + let scripts = document.getElementsByTagName('script'), + length = scripts.length; + + for(let i = 0; i < length; i++) { + scripts[i].src.replace(URL + '/', ''); + + if(jsOMS.Autoloader.loaded.indexOf(scripts[i].src) === -1) { + jsOMS.Autoloader.loaded.push(scripts[i].src); + } + } + }; + + jsOMS.Autoloader.setPreloaded = function(file) + { + if(jsOMS.Autoloader.loaded.indexOf(file) === -1) { + jsOMS.Autoloader.loaded.push(file); + } + }; + + jsOMS.Autoloader.include = function(file, callback) + { + let length = file.length; + + for(let i = 0; i < length; i++) { + if(jsOMS.Autoloader.loaded.indexOf(file) === -1) { + // todo: implement asset loading and pass callback + + jsOMS.Autoloader.loaded.push(file); + } + } + }; +}(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/oms.min.js b/oms.min.js index f79a1e8..8fe7334 100644 --- a/oms.min.js +++ b/oms.min.js @@ -390,8 +390,8 @@ { var authRequest = new jsOMS.Request(); authRequest.setUri(this.uri); - authRequest.setMethod(jsOMS.EnumRequestMethod.POST); - authRequest.setResponseType(jsOMS.EnumRequestType.JSON); + authRequest.setMethod(jsOMS.Message.Request.RequestMethod.POST); + authRequest.setResponseType(jsOMS.Message.Request.RequestType.JSON); authRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); authRequest.setSuccess(function (xhr) { this.loginResult(xhr); @@ -1030,7 +1030,7 @@ with ({p: MathProcessor.prototype}) { }; }(window.jsOMS = window.jsOMS || {})); (function (jsOMS, undefined) { - jsOMS.EnumRequestMethod = Object.freeze({ + jsOMS.Message.Request.RequestMethod = Object.freeze({ POST: 'POST', GET: 'GET', PUT: 'PUT', @@ -1070,7 +1070,7 @@ with ({p: MathProcessor.prototype}) { } }(window.jsOMS = window.jsOMS || {})); (function (jsOMS, undefined) { - jsOMS.EnumResponseResultType = Object.freeze({ + jsOMS.Message.Response.ResponseResultType = Object.freeze({ MULTI: 0, MESSAGE: 1, INFO: 2, @@ -1079,7 +1079,7 @@ with ({p: MathProcessor.prototype}) { }); }(window.jsOMS = window.jsOMS || {})); (function (jsOMS, undefined) { - jsOMS.EnumRequestType = Object.freeze({ + jsOMS.Message.Request.RequestType = Object.freeze({ TEXT: 'text', JSON: 'json', DOCUMENT: 'document',