From cabb3937e42d56e9e4227449c453104c48adcb74 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 21:37:21 +0100 Subject: [PATCH] Fixing namesapces --- Account/AccountType.enum.js | 2 +- Asset/AssetManager.js | 8 ++-- Auth/Auth.js | 16 +++---- Config/Options.js | 8 ++-- DataStorage/CookieJar.js | 6 +-- DataStorage/LocalStorage.js | 4 +- Log/LogLevel.enum.js | 2 +- Log/Logger.js | 54 +++++++++++------------ Message/Request/BrowserType.enum.js | 2 +- Message/Request/Request.js | 50 +++++++++++----------- Message/Response/ResponseManager.js | 6 +-- Module/ModuleFactory.js | 4 +- Module/ModuleManager.js | 4 +- UI/{LinkManager.js => Button.js} | 0 UI/Input/Keyboard/KeyboardManager.js | 15 +++++-- UI/Select.js | 0 Uri/UriFactory.js | 24 +++++------ Views/FormView.js | 64 +++++++++++++++++++--------- 18 files changed, 150 insertions(+), 119 deletions(-) rename UI/{LinkManager.js => Button.js} (100%) create mode 100644 UI/Select.js diff --git a/Account/AccountType.enum.js b/Account/AccountType.enum.js index b9a08f0..cfa7cea 100644 --- a/Account/AccountType.enum.js +++ b/Account/AccountType.enum.js @@ -9,7 +9,7 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumAccountType = Object.freeze({ + jsOMS.Account.EnumAccountType = Object.freeze({ USER: 0, GROUP: 1 }); diff --git a/Asset/AssetManager.js b/Asset/AssetManager.js index 06bda89..f91abd8 100644 --- a/Asset/AssetManager.js +++ b/Asset/AssetManager.js @@ -16,7 +16,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.AssetManager = function () + jsOMS.Asset.AssetManager = function () { this.assets = {}; }; @@ -36,7 +36,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 +102,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 +123,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 4f2d3dc..f7bd333 100644 --- a/Auth/Auth.js +++ b/Auth/Auth.js @@ -16,7 +16,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 +32,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 +47,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Auth.prototype.getAccount = function () + jsOMS.Auth.Auth.prototype.getAccount = function () { return this.account; }; @@ -60,12 +60,12 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Auth.prototype.login = function () + jsOMS.Auth.Auth.prototype.login = function () { var authRequest = new jsOMS.Message.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 +83,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Auth.prototype.logout = function () + jsOMS.Auth.Auth.prototype.logout = function () { location.reload(); }; @@ -96,7 +96,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/Config/Options.js b/Config/Options.js index 277b149..0b1f1e2 100644 --- a/Config/Options.js +++ b/Config/Options.js @@ -16,7 +16,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Options = function () + jsOMS.Config.Options = function () { this.options = {}; }; @@ -35,7 +35,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 +60,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 +81,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/CookieJar.js b/DataStorage/CookieJar.js index fd13695..809693e 100644 --- a/DataStorage/CookieJar.js +++ b/DataStorage/CookieJar.js @@ -16,7 +16,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.CookieJar = function () + jsOMS.DataStorage.CookieJar = function () { }; @@ -36,7 +36,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 +56,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..ff8dc1b 100644 --- a/DataStorage/LocalStorage.js +++ b/DataStorage/LocalStorage.js @@ -16,7 +16,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.LocalStorage = function () + jsOMS.DataStorage.LocalStorage = function () { }; @@ -30,7 +30,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/Log/LogLevel.enum.js b/Log/LogLevel.enum.js index cd6967c..87adb41 100644 --- a/Log/LogLevel.enum.js +++ b/Log/LogLevel.enum.js @@ -9,7 +9,7 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumLogLevel = Object.freeze({ + jsOMS.Log.LogLevel = Object.freeze({ EMERGENCY: 'normal', ALERT: 'normal', CRITICAL: 'normal', diff --git a/Log/Logger.js b/Log/Logger.js index 2c9436a..21213aa 100644 --- a/Log/Logger.js +++ b/Log/Logger.js @@ -11,8 +11,6 @@ { "use strict"; - jsOMS.Logger.layout = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}'; - /** * @constructor * @@ -26,9 +24,11 @@ this.remote = typeof remote !== 'undefined' ? remote : false; }; - jsOMS.FormManager.prototype.interpolate = function(message, context, level) + jsOMS.Log.Logger.layout = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}'; + + jsOMS.Log.Logger.prototype.interpolate = function(message, context, level) { - let newMessage = jsOMS.Logger.layout; + let newMessage = jsOMS.Log.Logger.layout; for(replace in context) { newMessage = newMessage.replace('{'+replace+'}', context[replace]); @@ -37,7 +37,7 @@ return newMessage; }; - jsOMS.FormManager.prototype.createContext = function(message, context, level) + jsOMS.Log.Logger.prototype.createContext = function(message, context, level) { context['datetime'] = (new Date()).toISOString(); context['version'] = '1.0.0'; @@ -50,7 +50,7 @@ return context; } - jsOMS.FormManager.prototype.write = function(message, context, level) + jsOMS.Log.Logger.prototype.write = function(message, context, level) { context = this.createContext(message, context, level); @@ -65,62 +65,62 @@ if(this.remote) { let request = new jsOMS.Message.Request(), request.setData(context); - request.setType(jsOMS.EnumResponseType.JSON); + request.setType(jsOMS.Message.Response.ResponseType.JSON); request.setUri('/{/lang}/api/log'); - request.setMethod(jsOMS.EnumRequestMethod.POST); + request.setMethod(jsOMS.Message.Request.RequestMethod.POST); request.setRequestHeader('Content-Type', 'application/json'); request.setSuccess(function (xhr) {}); request.send(); } }; - jsOMS.FormManager.prototype.emergency = function(message, context) + jsOMS.Log.Logger.prototype.emergency = function(message, context) { - this.write(message, context, jsOMS.EnumLogLevel.EMERGENCY) + this.write(message, context, jsOMS.Log.LogLevel.EMERGENCY) }; - jsOMS.FormManager.prototype.alert = function(message, context) + jsOMS.Log.Logger.prototype.alert = function(message, context) { - this.write(message, context, jsOMS.EnumLogLevel.ALERT) + this.write(message, context, jsOMS.Log.LogLevel.ALERT) }; - jsOMS.FormManager.prototype.critical = function(message, context) + jsOMS.Log.Logger.prototype.critical = function(message, context) { - this.write(message, context, jsOMS.EnumLogLevel.CRITICAL) + this.write(message, context, jsOMS.Log.LogLevel.CRITICAL) }; - jsOMS.FormManager.prototype.error = function(message, context) + jsOMS.Log.Logger.prototype.error = function(message, context) { - this.write(message, context, jsOMS.EnumLogLevel.ERROR) + this.write(message, context, jsOMS.Log.LogLevel.ERROR) }; - jsOMS.FormManager.prototype.warning = function(message, context) + jsOMS.Log.Logger.prototype.warning = function(message, context) { - this.write(message, context, jsOMS.EnumLogLevel.WARNING) + this.write(message, context, jsOMS.Log.LogLevel.WARNING) }; - jsOMS.FormManager.prototype.notice = function(message, context) + jsOMS.Log.Logger.prototype.notice = function(message, context) { - this.write(message, context, jsOMS.EnumLogLevel.NOTICE) + this.write(message, context, jsOMS.Log.LogLevel.NOTICE) }; - jsOMS.FormManager.prototype.info = function(message, context) + jsOMS.Log.Logger.prototype.info = function(message, context) { - this.write(message, context, jsOMS.EnumLogLevel.INFO) + this.write(message, context, jsOMS.Log.LogLevel.INFO) }; - jsOMS.FormManager.prototype.debug = function(message, context) + jsOMS.Log.Logger.prototype.debug = function(message, context) { - this.write(message, context, jsOMS.EnumLogLevel.DEBUG) + this.write(message, context, jsOMS.Log.LogLevel.DEBUG) }; - jsOMS.FormManager.prototype.log = function(level, message, context) + jsOMS.Log.Logger.prototype.log = function(level, message, context) { this.write(message, context, context) }; - jsOMS.FormManager.prototype.console = function(level, message, context) + jsOMS.Log.Logger.prototype.console = function(level, message, context) { - this.write(message, context, jsOMS.EnumLogLevel.INFO) + 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 index 68e58fe..6ea33d0 100644 --- a/Message/Request/BrowserType.enum.js +++ b/Message/Request/BrowserType.enum.js @@ -9,7 +9,7 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumBrowserType = Object.freeze({ + jsOMS.Message.Request.BrowserType = Object.freeze({ OPERA: 'opera', FIREFOX: 'firefox', SAFARI: 'safari', diff --git a/Message/Request/Request.js b/Message/Request/Request.js index a8904a1..1e36dd0 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -16,13 +16,13 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request = function (uri, method, type) + jsOMS.Message.Request.Request = function (uri, method, type) { this.uri = typeof uri !== 'undefined' ? uri : null; - this.method = typeof method !== 'undefined' ? method : jsOMS.EnumRequestMethod.GET; + this.method = typeof method !== 'undefined' ? method : jsOMS.Message.Request.RequestMethod.GET; this.requestHeader = []; this.success = null; - this.type = typeof type !== 'undefined' ? type : jsOMS.EnumResponseType.JSON; + this.type = typeof type !== 'undefined' ? type : jsOMS.Message.Response.ResponseType.JSON; this.data = {}; @@ -30,7 +30,7 @@ this.xhr = new XMLHttpRequest(); }; - jsOMS.Message.Request.getBrowser = function() + jsOMS.Message.Request.Request.getBrowser = function() { if((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { return jsOMS.EnumBrowser.OPERA; @@ -49,11 +49,11 @@ } }; - jsOMS.Message.Request.getOS = function() + jsOMS.Message.Request.Request.getOS = function() { - for(let os in jsOMS.EnumOSType) { - if(navigator.appversion.indexOf(jsOMS.EnumOSType[os]) !== -1) { - return jsOMS.EnumOSType[os]; + for(let os in jsOMS.Message.Request.OSType) { + if(navigator.appversion.indexOf(jsOMS.Message.Request.OSType[os]) !== -1) { + return jsOMS.Message.Request.OSType[os]; } } }; @@ -70,7 +70,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.setMethod = function (method) + jsOMS.Message.Request.Request.prototype.setMethod = function (method) { this.method = method; }; @@ -87,7 +87,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.getMethod = function () + jsOMS.Message.Request.Request.prototype.getMethod = function () { return this.method; }; @@ -104,7 +104,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.setResponseType = function (type) + jsOMS.Message.Request.Request.prototype.setResponseType = function (type) { this.xhr.responseType = type; }; @@ -121,7 +121,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.getResponseType = function () + jsOMS.Message.Request.Request.prototype.getResponseType = function () { return this.responseType; }; @@ -137,7 +137,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.setRequestHeader = function (type, header) + jsOMS.Message.Request.Request.prototype.setRequestHeader = function (type, header) { this.requestHeader[type] = header; }; @@ -152,7 +152,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.getRequestHeader = function () + jsOMS.Message.Request.Request.prototype.getRequestHeader = function () { return this.requestHeader; }; @@ -167,7 +167,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.setUri = function (uri) + jsOMS.Message.Request.Request.prototype.setUri = function (uri) { this.uri = uri; }; @@ -182,7 +182,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.getUri = function () + jsOMS.Message.Request.Request.prototype.getUri = function () { return this.uri; }; @@ -197,7 +197,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.setSuccess = function (callback) + jsOMS.Message.Request.Request.prototype.setSuccess = function (callback) { this.success = callback; }; @@ -212,7 +212,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.setData = function (data) + jsOMS.Message.Request.Request.prototype.setData = function (data) { this.data = data; }; @@ -227,7 +227,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.getData = function () + jsOMS.Message.Request.Request.prototype.getData = function () { return this.data }; @@ -244,7 +244,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.setType = function (type) + jsOMS.Message.Request.Request.prototype.setType = function (type) { this.type = type; }; @@ -261,7 +261,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.getType = function () + jsOMS.Message.Request.Request.prototype.getType = function () { return this.type; }; @@ -276,7 +276,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.queryfy = function (obj) + jsOMS.Message.Request.Request.prototype.queryfy = function (obj) { let str = []; for (let p in obj) { @@ -297,7 +297,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Request.prototype.send = function () + jsOMS.Message.Request.Request.prototype.send = function () { let self = this; @@ -318,14 +318,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/Response/ResponseManager.js b/Message/Response/ResponseManager.js index ce1c646..d11dfe4 100644 --- a/Message/Response/ResponseManager.js +++ b/Message/Response/ResponseManager.js @@ -18,7 +18,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.ResponseManager = function () + jsOMS.Message.Response.ResponseManager = function () { this.messages = {}; }; @@ -37,7 +37,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.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 +61,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.ResponseManager.prototype.execute = function (key, data, request) + jsOMS.Message.Response.ResponseManager.prototype.execute = function (key, data, request) { console.log(data); if (typeof request !== 'undefined' && typeof this.messages[key][request] !== 'undefined') { diff --git a/Module/ModuleFactory.js b/Module/ModuleFactory.js index 6b7e038..b980e5e 100644 --- a/Module/ModuleFactory.js +++ b/Module/ModuleFactory.js @@ -16,7 +16,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.ModuleFactory = function () + jsOMS.Module.ModuleFactory = function () { }; @@ -33,7 +33,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..d7ca131 100644 --- a/Module/ModuleManager.js +++ b/Module/ModuleManager.js @@ -18,7 +18,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.ModuleManager = function (app) + jsOMS.Module.ModuleManager = function (app) { this.modules = {}; this.app = app; @@ -36,7 +36,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/UI/LinkManager.js b/UI/Button.js similarity index 100% rename from UI/LinkManager.js rename to UI/Button.js diff --git a/UI/Input/Keyboard/KeyboardManager.js b/UI/Input/Keyboard/KeyboardManager.js index b75d0cf..c3b5997 100644 --- a/UI/Input/Keyboard/KeyboardManager.js +++ b/UI/Input/Keyboard/KeyboardManager.js @@ -1,11 +1,20 @@ (function (jsOMS, undefined) { - jsOMS.KeyboardManager = function () + jsOMS.UI.Input.KeyboardManager = function () { }; - jsOMS.KeyboardManager.prototype.attach = function (element, keys, callback) { + jsOMS.UI.Input.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.KeyboardManager.prototype.unbind = function (element) + { + element.removeEventListener('keyup', keyBind, false); }; }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/Select.js b/UI/Select.js new file mode 100644 index 0000000..e69de29 diff --git a/Uri/UriFactory.js b/Uri/UriFactory.js index 510d8fe..e6c4aca 100644 --- a/Uri/UriFactory.js +++ b/Uri/UriFactory.js @@ -1,8 +1,8 @@ (function (uriFactory, undefined) { - jsOMS.UriFactory = {}; - jsOMS.UriFactory.uri = {}; + jsOMS.Uri.UriFactory = {}; + jsOMS.Uri.UriFactory.uri = {}; - jsOMS.UriFactory.parseUrl = function (str, component) + jsOMS.Uri.UriFactory.parseUrl = function (str, component) { let query, key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'fragment' @@ -61,7 +61,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.UriFactory.getUriQueryParameter = function (query, name) + jsOMS.Uri.UriFactory.getUriQueryParameter = function (query, name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); @@ -71,12 +71,12 @@ return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); }; - jsOMS.UriFactory.setQuery = function(key, value, overwrite) + jsOMS.Uri.UriFactory.setQuery = function(key, value, overwrite) { overwrite = typeof overwrite !== 'undefined' ? overwrite : true; - if(overwrite || !jsOMS.UriFactory.uri.hasProperty(key)) { - jsOMS.UriFactory.uri[key] = value; + if(overwrite || !jsOMS.Uri.UriFactory.uri.hasProperty(key)) { + jsOMS.Uri.UriFactory.uri[key] = value; return true; } @@ -84,9 +84,9 @@ return false; }; - jsOMS.UriFactory.build = function(uri, toMatch) + jsOMS.Uri.UriFactory.build = function(uri, toMatch) { - let current = jsOMS.UriFactory.parseUrl(window.location.href); + 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) { @@ -94,12 +94,12 @@ if(toMatch.hasProperty(match)) { return toMatch[match]; - } else if(jsOMS.UriFactory.uri[match] !== 'undefined') { - return jsOMS.UriFactory.uri[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.UriFactory.getUriQueryParameter(current.query, match.substring(1, match.length)); + 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'; diff --git a/Views/FormView.js b/Views/FormView.js index b77f813..1cda58b 100644 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -1,49 +1,57 @@ (function (jsOMS, undefined) { "use strict"; - jsOMS.FormView = function (id) { + jsOMS.Views.FormView = function (id) { this.id = id; this.initializeMembers(); this.bind(); }; - jsOMS.FormView.prototype.initializeMembers = function() + jsOMS.Views.FormView.prototype.initializeMembers = function() { this.submitInjects = {}; this.method = 'POST'; this.action = ''; }; - jsOMS.FormView.prototype.getMethod = function() + jsOMS.Views.FormView.prototype.getMethod = function() { return this.method; }; - jsOMS.FormView.prototype.getAction = function() + jsOMS.Views.FormView.prototype.getAction = function() { return this.action; }; - jsOMS.FormView.prototype.getSubmit = function() + jsOMS.Views.FormView.prototype.getSubmit = function() { return document.getElementById(this.id).querySelectorAll('input[type=submit]')[0]; }; - jsOMS.FormView.prototype.injectSubmit = function(id, callback) + jsOMS.Views.FormView.prototype.injectSubmit = function(id, callback) { this.submitInjects[id] = callback; }; - jsOMS.FormView.prototype.getData = function() + jsOMS.Views.FormView.prototype.getFormElements = function(id) { - let data = {}, - form = document.getElementById(this.id), + let form = document.getElementById(id), selects = form.getElementsByTagName('select'), textareas = form.getElementsByTagName('textarea'), inputs = form.getElementsByTagName('input'), - external = document.querySelectorAll('[form='+this.id+']'), + 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.Views.FormView.prototype.getData = function() + { + let data = {}, + elements = this.getFormElements(this.id), length = elements.length, i = 0; @@ -54,24 +62,19 @@ return data; }; - jsOMS.FormView.prototype.getSubmitInjects = function() + jsOMS.Views.FormView.prototype.getSubmitInjects = function() { return this.submitInjects; }; - jsOMS.FormView.prototype.bind = function() + jsOMS.Views.FormView.prototype.bind = function() { this.clean(); this.method = document.getElementById(this.id).method; this.action = document.getElementById(this.id).action; - let form = document.getElementById(this.id), - selects = form.getElementsByTagName('select'), - textareas = form.getElementsByTagName('textarea'), - inputs = form.getElementsByTagName('input'), - external = document.querySelectorAll('[form='+this.id+']'), - elements = Array.prototype.slice.call(inputs).concat(Array.prototype.slice.call(selects), Array.prototype.slice.call(textareas), Array.prototype.slice.call(external)), + let elements = this.getFormElements(this.id), length = elements.length, i = 0; @@ -93,12 +96,31 @@ } }; - jsOMS.FormView.prototype.unbind = function() + 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.FormView.prototype.clean = function() + jsOMS.Views.FormView.prototype.clean = function() { this.unbind(); this.initializeMembers();