From 7dbedb31ddcea0958419083df8955c9c2e3e6f41 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 15:31:45 +0100 Subject: [PATCH 01/27] Implement logger --- Log/LogLevel.enum.js | 22 ++++++++++ Log/Logger.js | 102 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 Log/LogLevel.enum.js create mode 100644 Log/Logger.js diff --git a/Log/LogLevel.enum.js b/Log/LogLevel.enum.js new file mode 100644 index 0000000..cd6967c --- /dev/null +++ b/Log/LogLevel.enum.js @@ -0,0 +1,22 @@ +/** + * 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.EnumLogLevel = Object.freeze({ + EMERGENCY: 'normal', + ALERT: 'normal', + CRITICAL: 'normal', + ERROR: 'normal', + WARNING: 'normal', + NOTICE: 'normal', + INFO: 'normal', + DEBUG: 'normal' + }); +}(window.jsOMS = window.jsOMS || {})); diff --git a/Log/Logger.js b/Log/Logger.js new file mode 100644 index 0000000..4466aff --- /dev/null +++ b/Log/Logger.js @@ -0,0 +1,102 @@ +/** + * 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"; + + /** + * @constructor + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + jsOMS.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.FormManager.prototype.interpolate = function(message, context, level) + { + }; + + jsOMS.FormManager.prototype.write = function(message, context, level) + { + if(this.verbose) { + console.log(this.interpolate(message, context, level))); + } + + if(this.ui) { + // todo: fill log box, set class and initiate animation + } + + if(this.remote) { + let request = new jsOMS.Request(), + request.setData(message); + request.setType('json'); + request.setUri(jsOMS.UriFactory.build('/{/lang}/api/log')); + request.setMethod(jsOMS.EnumRequestMethod.POST); + request.setRequestHeader('Content-Type', 'application/json'); + request.setSuccess(function (xhr) {}); + request.send(); + } + }; + + jsOMS.FormManager.prototype.emergency = function(message, context) + { + this.write(message, context, jsOMS.EnumLogLevel.EMERGENCY) + }; + + jsOMS.FormManager.prototype.alert = function(message, context) + { + this.write(message, context, jsOMS.EnumLogLevel.ALERT) + }; + + jsOMS.FormManager.prototype.critical = function(message, context) + { + this.write(message, context, jsOMS.EnumLogLevel.CRITICAL) + }; + + jsOMS.FormManager.prototype.error = function(message, context) + { + this.write(message, context, jsOMS.EnumLogLevel.ERROR) + }; + + jsOMS.FormManager.prototype.warning = function(message, context) + { + this.write(message, context, jsOMS.EnumLogLevel.WARNING) + }; + + jsOMS.FormManager.prototype.notice = function(message, context) + { + this.write(message, context, jsOMS.EnumLogLevel.NOTICE) + }; + + jsOMS.FormManager.prototype.info = function(message, context) + { + this.write(message, context, jsOMS.EnumLogLevel.INFO) + }; + + jsOMS.FormManager.prototype.debug = function(message, context) + { + this.write(message, context, jsOMS.EnumLogLevel.DEBUG) + }; + + jsOMS.FormManager.prototype.log = function(level, message, context) + { + this.write(message, context, context) + }; + + jsOMS.FormManager.prototype.console = function(level, message, context) + { + this.write(message, context, jsOMS.EnumLogLevel.INFO) + }; +}(window.jsOMS = window.jsOMS || {})); From 1a7a2e6e2e88cf73b52f4f81250f0b5bab7b6fab Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 15:32:07 +0100 Subject: [PATCH 02/27] Merging Uri and UriFactory --- Uri/Uri.js | 106 -------------------------------------------- Uri/UriFactory.js | 110 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 109 insertions(+), 107 deletions(-) delete mode 100644 Uri/Uri.js 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..510d8fe 100644 --- a/Uri/UriFactory.js +++ b/Uri/UriFactory.js @@ -1,3 +1,111 @@ (function (uriFactory, undefined) { + jsOMS.UriFactory = {}; + jsOMS.UriFactory.uri = {}; -}(window.jsOMS = window.jsOMS || {})); + jsOMS.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.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.UriFactory.setQuery = function(key, value, overwrite) + { + overwrite = typeof overwrite !== 'undefined' ? overwrite : true; + + if(overwrite || !jsOMS.UriFactory.uri.hasProperty(key)) { + jsOMS.UriFactory.uri[key] = value; + + return true; + } + + return false; + }; + + jsOMS.UriFactory.build = function(uri, toMatch) + { + let current = jsOMS.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.UriFactory.uri[match] !== 'undefined') { + return jsOMS.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)); + } 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 From 78ee0b0e9cc44ab89bddc69c3b9153bbe1c2fc54 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 15:32:38 +0100 Subject: [PATCH 03/27] Var to let and default parameters --- Message/Request/Request.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Message/Request/Request.js b/Message/Request/Request.js index 3cb2acd..e561ae4 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -16,15 +16,17 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request = function () + jsOMS.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.EnumRequestMethod.GET; this.requestHeader = []; this.success = null; - this.type = jsOMS.EnumRequestMethod.GET; + this.type = typeof type !== 'undefined' ? type : 'json'; this.data = {}; + + this.xhr = new XMLHttpRequest(); }; @@ -248,8 +250,8 @@ */ jsOMS.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])); } @@ -269,12 +271,12 @@ */ jsOMS.Request.prototype.send = function () { - var self = this; + let self = this; if (self.xhr.readyState !== 1) { self.xhr.open(this.method, 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]); } From c188acc02fb292ffc7371277824be2d1344cb897 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 15:33:31 +0100 Subject: [PATCH 04/27] Build uri by default --- Message/Request/Request.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Message/Request/Request.js b/Message/Request/Request.js index e561ae4..750e0bb 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -25,7 +25,7 @@ this.type = typeof type !== 'undefined' ? type : 'json'; this.data = {}; - + this.xhr = new XMLHttpRequest(); }; @@ -274,7 +274,7 @@ let self = this; if (self.xhr.readyState !== 1) { - self.xhr.open(this.method, this.uri); + self.xhr.open(this.method, jsOMS.UriFactory.build(this.uri)); for (let p in this.requestHeader) { if (this.requestHeader.hasOwnProperty(p)) { From 54e167fdd15c82c9bcf223bcbd8829652a1d9bd9 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 15:34:02 +0100 Subject: [PATCH 05/27] Remove build, is done by request! --- Log/Logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Log/Logger.js b/Log/Logger.js index 4466aff..163ff90 100644 --- a/Log/Logger.js +++ b/Log/Logger.js @@ -42,7 +42,7 @@ let request = new jsOMS.Request(), request.setData(message); request.setType('json'); - request.setUri(jsOMS.UriFactory.build('/{/lang}/api/log')); + request.setUri('/{/lang}/api/log'); request.setMethod(jsOMS.EnumRequestMethod.POST); request.setRequestHeader('Content-Type', 'application/json'); request.setSuccess(function (xhr) {}); From a68c76d3de943a654b17c76cbb2c2cb1d5b6c0b7 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 15:35:06 +0100 Subject: [PATCH 06/27] Draft --- Views/FormView.js | 177 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 154 insertions(+), 23 deletions(-) diff --git a/Views/FormView.js b/Views/FormView.js index e7da5c5..8453e8e 100644 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -1,37 +1,168 @@ (function (jsOMS, undefined) { "use strict"; - jsOMS.FormView = function (element) { - this.id = element.getAttribute('id'); - this.formElement = element; + jsOMS.FormView = function (id) { + this.id = id; - this.inputElement = {}; - this.textarea = {}; - this.button = {}; - this.select = {}; + this.initializeMembers(); + this.bind(); + }; + + jsOMS.FormView.prototype.initializeMembers = function() + { + this.submitInjects = {}; + this.method = 'POST'; + this.action = ''; + }; + + jsOMS.FormView.prototype.getMethod = function() + { + return this.method; + }; + + jsOMS.FormView.prototype.getAction = function() + { + return this.action; + }; + + jsOMS.FormView.prototype.getSubmit = function() + { + return document.getElementById(this.id).querySelectorAll('input[type=submit]')[0]; + }; + + jsOMS.FormView.prototype.injectSubmit = function(id, callback) + { + this.submitInjects[id] = callback; + }; + + jsOMS.FormView.prototype.getData = function() + { + let data = {}, + 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)), + length = elements.length, + i = 0; + + for(i = 0; i < length; i++) { + data[elements[i].getAttribute('name')] = elements[i].value; + } + + return data; + }; + + jsOMS.FormView.prototype.getSubmitInjects = function() + { + return this.submitInjects; }; jsOMS.FormView.prototype.bind = function() { - this.bindInput(); - this.bindTextarea(); - this.bindButton(); - this.bindSelect(); - } + this.clean(); - jsOMS.FormView.prototype.bindInput = function() - { - var self = this; + this.method = document.getElementById(this.id).method; + this.action = document.getElementById(this.id).action; - let inputs = this.formElement.getElementsByTagName('input'); + 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)), + length = elements.length, + i = 0; - Object.keys(inputs).forEach(function (key, element) { - self.inputElement[element.getAttribute('id')] = { - id: element.getAttribute('id'), - type: element.getAttribute('type') + for(i = 0; i < length; i++) { + switch(elements[i].tagName) { + case 'input': + this.bindInput(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.FormView.prototype.unbind = function() + { + + }; + + jsOMS.FormView.prototype.clean = function() + { + this.unbind(); + this.initializeMembers(); + }; + + jsOMS.FormView.prototype.bindInput = function(input) + { + let listId, list, + self = this; + + if((listId = input.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') { + input.addEventListener('change', function(event) { + self.addRemoteDatalistOptions(input, list); + }); + } + }; + + jsOMS.FormView.prototype.addRemoteDatalistOptions = function(input, datalist) + { + this.clearDatalistOptions(datalist); + + let request = new Request(); + request.setData(input.value); + request.setType('json'); + request.setUri(datalist.getAttribute('data-list-src')); + request.setMethod(jsOMS.EnumRequestMethod.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.get(k); + console.log(tempResponse); + + let option = null, + data = tempResponse.getData(), + length = data.length; + + for(let i = 0; i < length; i++) { + option = document.createElement('option'); + datalist.appendChild(option); + } + } + } catch (exception) { + self.app.logger.error('Invalid JSON object: ' + xhr, 'FormManager') + return false; + } + }); + + request.send(); + }; + + jsOMS.FormView.prototype.clearDatalistOptions = function(datalist) + { + let length = datalist.options.length, + i = 0; + + for(i = 0; i < length; i++) { + datalist.remove(0); + } + }; }(window.jsOMS = window.jsOMS || {})); From 6aed622a5798258b87fce217ce9c32c7de411602 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 15:35:49 +0100 Subject: [PATCH 07/27] Clean up tag handle --- UI/UIManager.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/UI/UIManager.js b/UI/UIManager.js index 3257337..9ce31e6 100644 --- a/UI/UIManager.js +++ b/UI/UIManager.js @@ -41,15 +41,16 @@ 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; + }; } }; From c1c5a1c1f33d935847d485f730f2292d62ae9480 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 15:36:20 +0100 Subject: [PATCH 08/27] Restructure & cleanup with FormView usage --- UI/FormManager.js | 453 ++++++++-------------------------------------- 1 file changed, 78 insertions(+), 375 deletions(-) diff --git a/UI/FormManager.js b/UI/FormManager.js index 709585c..b26e82c 100644 --- a/UI/FormManager.js +++ b/UI/FormManager.js @@ -7,8 +7,8 @@ * @license OMS License 1.0 * @version 1.0.0 * @since 1.0.0 */ -(function (jsOMS, undefined) -{ + (function (jsOMS, undefined) + { "use strict"; /** @@ -17,51 +17,63 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.FormManager = function (responseManager) - { - this.responseManager = responseManager; - this.ignore = []; - this.success = []; - this.injectSelector = []; - this.forms = []; + jsOMS.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.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.FormManager.prototype.isIgnored = function(id) { - if (!(selector in this.injectSelector)) { - this.injectSelector[selector] = callback; + return this.ignore.indexOf(id) !== -1; + }; + + jsOMS.FormManager.prototype.bind = function(id) + { + if (typeof id !== 'undefined' && this.ignore.indexOf(id) === -1) { + this.bindForm(id) + } else { + let forms = document.getElementsByTagName('form'), + length = forms.length; + + for (var i = 0; i < length; i++) { + if (this.ignore.indexOf(forms[i].id) === -1) { + this.bindForm(forms[i].id); + } + } + } + }; + + jsOMS.FormManager.prototype.bindForm = function(id) + { + let self = this; + + this.unbind(id); + + if(this.ignore.indexOf(id) === -1) { + this.forms[id] = new FormView(id); + } + + this.forms[id].getSubmit().addEventListener('click', function(event) { + self.submit(self.forms[id]); + jsOMS.preventAll(event); + }); + }; + + jsOMS.FormManager.prototype.unbindForm = function(id) + { + // todo: do i need the findex? can't i just use id? + let findex = 0; + + if((findex = this.forms.indexOf(id)) !== -1) { + this.forms[id].unbind(); + this.forms.splice(findex, 1); return true; } @@ -69,120 +81,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.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.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.setData(form.getData()); request.setType('json'); - request.setUri(e.action); - request.setMethod(e.method); + 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 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.get(k); + console.log(tempResponse); - /* 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(typeof (success = form.getSuccess()) !== 'undefined') { + success(tempResponse); + } else { + self.app.responseManager.run(tempResponse); } } } catch (exception) { - console.log('No valid json'); + self.app.logger.error('Invalid JSON object: ' + xhr, 'FormManager') return false; } }); @@ -190,240 +127,6 @@ 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 () { return this.forms.length; From 4ca251dd9b1d08ec7c59f93933c0e8edca40d736 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 16:52:33 +0100 Subject: [PATCH 09/27] Implementing logger interpolation --- Log/Logger.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Log/Logger.js b/Log/Logger.js index 163ff90..08f6a22 100644 --- a/Log/Logger.js +++ b/Log/Logger.js @@ -11,6 +11,8 @@ { "use strict"; + jsOMS.Logger.layout = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}' + /** * @constructor * @@ -26,10 +28,32 @@ jsOMS.FormManager.prototype.interpolate = function(message, context, level) { + let newMessage = jsOMS.Logger.layout; + + for(replace in context) { + newMessage = newMessage.replace('{'+replace+'}', context[replace]); + } + + return newMessage; }; + jsOMS.FormManager.prototype.createContext = function(message, context, level) + { + context['datetime'] = (new Date()).toISOString(); + context['version'] = '1.0.0'; + context['os'] = jsOMS.Request.getOS(); + context['browser'] = jsOMS.Request.getBrowser(); + context['path'] = window.location.href; + context['level'] = level; + context['message'] = message; + + return context; + } + jsOMS.FormManager.prototype.write = function(message, context, level) { + context = this.createContext(message, context, level); + if(this.verbose) { console.log(this.interpolate(message, context, level))); } @@ -41,7 +65,7 @@ if(this.remote) { let request = new jsOMS.Request(), request.setData(message); - request.setType('json'); + request.setType(jsOMS.EnumResponseType.JSON); request.setUri('/{/lang}/api/log'); request.setMethod(jsOMS.EnumRequestMethod.POST); request.setRequestHeader('Content-Type', 'application/json'); From 0826ffdbaa609a7aea6955e8bc0085e971612c11 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 16:53:11 +0100 Subject: [PATCH 10/27] Implementing browser and os support --- Message/Request/BrowserType.enum.js | 21 ++++++++++++++++ Message/Request/OSType.enum.js | 37 +++++++++++++++++++++++++++++ Message/Request/Request.js | 30 ++++++++++++++++++++++- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 Message/Request/BrowserType.enum.js create mode 100644 Message/Request/OSType.enum.js diff --git a/Message/Request/BrowserType.enum.js b/Message/Request/BrowserType.enum.js new file mode 100644 index 0000000..68e58fe --- /dev/null +++ b/Message/Request/BrowserType.enum.js @@ -0,0 +1,21 @@ +/** + * 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.EnumBrowserType = 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..8f33a69 --- /dev/null +++ b/Message/Request/OSType.enum.js @@ -0,0 +1,37 @@ +/** + * 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.EnumOSType = 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 750e0bb..fb706a9 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -22,7 +22,7 @@ this.method = typeof method !== 'undefined' ? method : jsOMS.EnumRequestMethod.GET; this.requestHeader = []; this.success = null; - this.type = typeof type !== 'undefined' ? type : 'json'; + this.type = typeof type !== 'undefined' ? type : jsOMS.EnumResponseType.JSON; this.data = {}; @@ -30,6 +30,34 @@ this.xhr = new XMLHttpRequest(); }; + jsOMS.Request.getBrowser = function() + { + if((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { + return jsOMS.EnumBrowser.OPERA; + } else if(typeof InstallTrigger !== 'undefined') { + return jsOMS.EnumBrowser.FIREFOX; + } else if(Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0) { + return return jsOMS.EnumBrowser.SAFARI; + } else if(/*@cc_on!@*/false || !!document.documentMode) { + return jsOMS.EnumBrowser.IE; + } else if(!isIE && !!window.StyleMedia) { + return jsOMS.EnumBrowser.EDGE; + } else if(!!window.chrome && !!window.chrome.webstore) { + return jsOMS.EnumBrowser.CHROME; + } else if((isChrome || isOpera) && !!window.CSS) { + return jsOMS.EnumBrowser.BLINK; + } + }; + + jsOMS.Request.getOS = function() + { + for(let os in jsOMS.EnumOSType) { + if(navigator.appversion.indexOf(jsOMS.EnumOSType[os]) !== -1) { + return jsOMS.EnumOSType[os]; + } + } + }; + /** * Set request method. * From 20774d535576f42a397d3a0fedb8840bce5d80d5 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 17:02:39 +0100 Subject: [PATCH 11/27] Minor fixes --- Log/Logger.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Log/Logger.js b/Log/Logger.js index 08f6a22..e9fc6ae 100644 --- a/Log/Logger.js +++ b/Log/Logger.js @@ -11,7 +11,7 @@ { "use strict"; - jsOMS.Logger.layout = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}' + jsOMS.Logger.layout = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}'; /** * @constructor @@ -64,7 +64,7 @@ if(this.remote) { let request = new jsOMS.Request(), - request.setData(message); + request.setData(context); request.setType(jsOMS.EnumResponseType.JSON); request.setUri('/{/lang}/api/log'); request.setMethod(jsOMS.EnumRequestMethod.POST); From e89cb9da52d374b35f586957c3b066d62b309a74 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 17:03:08 +0100 Subject: [PATCH 12/27] Fix function and const usage --- UI/FormManager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UI/FormManager.js b/UI/FormManager.js index b26e82c..f373144 100644 --- a/UI/FormManager.js +++ b/UI/FormManager.js @@ -94,7 +94,7 @@ self = this; request.setData(form.getData()); - request.setType('json'); + request.setType(jsOMS.EnumResponseType.JSON); request.setUri(form.getAction()); request.setMethod(form.getMethod()); request.setRequestHeader('Content-Type', 'application/json'); @@ -109,7 +109,7 @@ /* Handle responses (can be multiple response object) */ for (let k = 0; k < responseLength; k++) { - tempResponse = response.get(k); + tempResponse = response.getByIndex(k); console.log(tempResponse); if(typeof (success = form.getSuccess()) !== 'undefined') { From 91d8de12a5c792208bea5909fbbf406b95b39386 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 20:12:29 +0100 Subject: [PATCH 13/27] Namespace fix --- Auth/Auth.js | 2 +- Log/Logger.js | 6 ++--- Message/Request/Request.js | 38 +++++++++++++------------- Message/Request/RequestManager.js | 2 +- Message/Response/ResponseManager.js | 6 ++--- UI/FormManager.js | 18 ++++++------- UI/InputElements.js | 41 ----------------------------- UI/UIManager.js | 13 ++++----- 8 files changed, 43 insertions(+), 83 deletions(-) delete mode 100644 UI/InputElements.js diff --git a/Auth/Auth.js b/Auth/Auth.js index 04d15b4..4f2d3dc 100644 --- a/Auth/Auth.js +++ b/Auth/Auth.js @@ -62,7 +62,7 @@ */ jsOMS.Auth.prototype.login = function () { - var authRequest = new jsOMS.Request(); + var authRequest = new jsOMS.Message.Request(); authRequest.setUri(this.uri); authRequest.setMethod(jsOMS.EnumRequestMethod.POST); authRequest.setResponseType(jsOMS.EnumRequestType.JSON); diff --git a/Log/Logger.js b/Log/Logger.js index e9fc6ae..2c9436a 100644 --- a/Log/Logger.js +++ b/Log/Logger.js @@ -41,8 +41,8 @@ { context['datetime'] = (new Date()).toISOString(); context['version'] = '1.0.0'; - context['os'] = jsOMS.Request.getOS(); - context['browser'] = jsOMS.Request.getBrowser(); + context['os'] = jsOMS.Message.Request.getOS(); + context['browser'] = jsOMS.Message.Request.getBrowser(); context['path'] = window.location.href; context['level'] = level; context['message'] = message; @@ -63,7 +63,7 @@ } if(this.remote) { - let request = new jsOMS.Request(), + let request = new jsOMS.Message.Request(), request.setData(context); request.setType(jsOMS.EnumResponseType.JSON); request.setUri('/{/lang}/api/log'); diff --git a/Message/Request/Request.js b/Message/Request/Request.js index fb706a9..a8904a1 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -9,14 +9,14 @@ */ (function (jsOMS, undefined) { - + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request = function (uri, method, type) + jsOMS.Message.Request = function (uri, method, type) { this.uri = typeof uri !== 'undefined' ? uri : null; this.method = typeof method !== 'undefined' ? method : jsOMS.EnumRequestMethod.GET; @@ -30,7 +30,7 @@ this.xhr = new XMLHttpRequest(); }; - jsOMS.Request.getBrowser = function() + jsOMS.Message.Request.getBrowser = function() { if((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { return jsOMS.EnumBrowser.OPERA; @@ -49,7 +49,7 @@ } }; - jsOMS.Request.getOS = function() + jsOMS.Message.Request.getOS = function() { for(let os in jsOMS.EnumOSType) { if(navigator.appversion.indexOf(jsOMS.EnumOSType[os]) !== -1) { @@ -70,7 +70,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setMethod = function (method) + jsOMS.Message.Request.prototype.setMethod = function (method) { this.method = method; }; @@ -87,7 +87,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getMethod = function () + jsOMS.Message.Request.prototype.getMethod = function () { return this.method; }; @@ -104,7 +104,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setResponseType = function (type) + jsOMS.Message.Request.prototype.setResponseType = function (type) { this.xhr.responseType = type; }; @@ -121,7 +121,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getResponseType = function () + jsOMS.Message.Request.prototype.getResponseType = function () { return this.responseType; }; @@ -137,7 +137,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setRequestHeader = function (type, header) + jsOMS.Message.Request.prototype.setRequestHeader = function (type, header) { this.requestHeader[type] = header; }; @@ -152,7 +152,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getRequestHeader = function () + jsOMS.Message.Request.prototype.getRequestHeader = function () { return this.requestHeader; }; @@ -167,7 +167,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setUri = function (uri) + jsOMS.Message.Request.prototype.setUri = function (uri) { this.uri = uri; }; @@ -182,7 +182,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getUri = function () + jsOMS.Message.Request.prototype.getUri = function () { return this.uri; }; @@ -197,7 +197,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setSuccess = function (callback) + jsOMS.Message.Request.prototype.setSuccess = function (callback) { this.success = callback; }; @@ -212,7 +212,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setData = function (data) + jsOMS.Message.Request.prototype.setData = function (data) { this.data = data; }; @@ -227,7 +227,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getData = function () + jsOMS.Message.Request.prototype.getData = function () { return this.data }; @@ -244,7 +244,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.setType = function (type) + jsOMS.Message.Request.prototype.setType = function (type) { this.type = type; }; @@ -261,7 +261,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.getType = function () + jsOMS.Message.Request.prototype.getType = function () { return this.type; }; @@ -276,7 +276,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.queryfy = function (obj) + jsOMS.Message.Request.prototype.queryfy = function (obj) { let str = []; for (let p in obj) { @@ -297,7 +297,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Request.prototype.send = function () + jsOMS.Message.Request.prototype.send = function () { let self = this; diff --git a/Message/Request/RequestManager.js b/Message/Request/RequestManager.js index 16002ea..809c06a 100644 --- a/Message/Request/RequestManager.js +++ b/Message/Request/RequestManager.js @@ -18,7 +18,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.RequestManager = function () + jsOMS.Message.RequestManager = function () { }; }(window.jsOMS = window.jsOMS || {})); diff --git a/Message/Response/ResponseManager.js b/Message/Response/ResponseManager.js index ff9cb1c..ce1c646 100644 --- a/Message/Response/ResponseManager.js +++ b/Message/Response/ResponseManager.js @@ -18,7 +18,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.ResponseManager = function () + jsOMS.Message.ResponseManager = function () { this.messages = {}; }; @@ -37,7 +37,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.ResponseManager.prototype.add = function (key, message, request) + jsOMS.Message.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.ResponseManager.prototype.execute = function (key, data, request) + jsOMS.Message.ResponseManager.prototype.execute = function (key, data, request) { console.log(data); if (typeof request !== 'undefined' && typeof this.messages[key][request] !== 'undefined') { diff --git a/UI/FormManager.js b/UI/FormManager.js index f373144..061b375 100644 --- a/UI/FormManager.js +++ b/UI/FormManager.js @@ -17,24 +17,24 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.FormManager = function (app) + jsOMS.UI.FormManager = function (app) { this.app = app; this.forms = {}; this.ignore = {}; }; - jsOMS.FormManager.prototype.get = function(id) + jsOMS.UI.FormManager.prototype.get = function(id) { return this.forms[id]; }; - jsOMS.FormManager.prototype.isIgnored = function(id) + jsOMS.UI.FormManager.prototype.isIgnored = function(id) { return this.ignore.indexOf(id) !== -1; }; - jsOMS.FormManager.prototype.bind = function(id) + jsOMS.UI.FormManager.prototype.bind = function(id) { if (typeof id !== 'undefined' && this.ignore.indexOf(id) === -1) { this.bindForm(id) @@ -50,7 +50,7 @@ } }; - jsOMS.FormManager.prototype.bindForm = function(id) + jsOMS.UI.FormManager.prototype.bindForm = function(id) { let self = this; @@ -66,7 +66,7 @@ }); }; - jsOMS.FormManager.prototype.unbindForm = function(id) + jsOMS.UI.FormManager.prototype.unbindForm = function(id) { // todo: do i need the findex? can't i just use id? let findex = 0; @@ -81,7 +81,7 @@ return false; }; - jsOMS.FormManager.prototype.submit = function(form) + jsOMS.UI.FormManager.prototype.submit = function(form) { /* Handle injects */ let injects = form.getSubmitInjects(); @@ -90,7 +90,7 @@ } /* Handle default submit */ - let request = new jsOMS.Request(), + let request = new jsOMS.Message.Request(), self = this; request.setData(form.getData()); @@ -127,7 +127,7 @@ request.send(); }; - jsOMS.FormManager.prototype.count = function () + jsOMS.UI.FormManager.prototype.count = function () { return this.forms.length; }; 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/UIManager.js b/UI/UIManager.js index 9ce31e6..186c42c 100644 --- a/UI/UIManager.js +++ b/UI/UIManager.js @@ -9,6 +9,7 @@ */ (function (jsOMS, undefined) { + jsOMS.UI = {}; /** * @constructor @@ -16,10 +17,10 @@ * @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.formManager = new jsOMS.FormManager(this.app); this.tabManager = new jsOMS.TabManager(this.app.responseManager); this.tableManager = new jsOMS.TableManager(this.app.responseManager); }; @@ -34,7 +35,7 @@ * @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(); @@ -64,7 +65,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.UIManager.prototype.getFormManager = function () + jsOMS.UI.UIManager.prototype.getFormManager = function () { return this.formManager; }; @@ -79,7 +80,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.UIManager.prototype.getTabManager = function () + jsOMS.UI.UIManager.prototype.getTabManager = function () { return this.tabManager; }; @@ -94,7 +95,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.UIManager.prototype.getTableManager = function () + jsOMS.UI.UIManager.prototype.getTableManager = function () { return this.tabManager; }; From ef72b23a50e0edb0ea7aa69442e321ebcecd1a8d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 20:16:00 +0100 Subject: [PATCH 14/27] Pull out of input bind --- Views/FormView.js | 64 +---------------------------------------------- 1 file changed, 1 insertion(+), 63 deletions(-) diff --git a/Views/FormView.js b/Views/FormView.js index 8453e8e..b77f813 100644 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -78,7 +78,7 @@ for(i = 0; i < length; i++) { switch(elements[i].tagName) { case 'input': - this.bindInput(elements[i]); + jsOMS.UI.Input.bind(elements[i]) break; case 'select': this.bindSelect(elements[i]); @@ -103,66 +103,4 @@ this.unbind(); this.initializeMembers(); }; - - jsOMS.FormView.prototype.bindInput = function(input) - { - let listId, list, - self = this; - - if((listId = input.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') { - input.addEventListener('change', function(event) { - self.addRemoteDatalistOptions(input, list); - }); - } - }; - - jsOMS.FormView.prototype.addRemoteDatalistOptions = function(input, datalist) - { - this.clearDatalistOptions(datalist); - - let request = new Request(); - request.setData(input.value); - request.setType('json'); - request.setUri(datalist.getAttribute('data-list-src')); - request.setMethod(jsOMS.EnumRequestMethod.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.get(k); - console.log(tempResponse); - - let option = null, - data = tempResponse.getData(), - length = data.length; - - for(let i = 0; i < length; i++) { - option = document.createElement('option'); - datalist.appendChild(option); - } - } - } catch (exception) { - self.app.logger.error('Invalid JSON object: ' + xhr, 'FormManager') - return false; - } - }); - - request.send(); - }; - - jsOMS.FormView.prototype.clearDatalistOptions = function(datalist) - { - let length = datalist.options.length, - i = 0; - - for(i = 0; i < length; i++) { - datalist.remove(0); - } - }; }(window.jsOMS = window.jsOMS || {})); From cabb3937e42d56e9e4227449c453104c48adcb74 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 21:37:21 +0100 Subject: [PATCH 15/27] 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(); From df5d49d108a6deea875e5d7b2cb2b841377d253e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 21:37:31 +0100 Subject: [PATCH 16/27] Fixing Namesapces --- Message/Request/OSType.enum.js | 2 +- Message/Request/RequestMethod.enum.js | 2 +- Message/Request/RequestType.enum.js | 2 +- Message/Response/ResponseResultType.enum.js | 2 +- Message/Response/ResponseType.enum.js | 2 +- UI/FormManager.js | 2 +- oms.min.js | 10 +++++----- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Message/Request/OSType.enum.js b/Message/Request/OSType.enum.js index 8f33a69..adcb735 100644 --- a/Message/Request/OSType.enum.js +++ b/Message/Request/OSType.enum.js @@ -9,7 +9,7 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumOSType = Object.freeze({ + 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 */ diff --git a/Message/Request/RequestMethod.enum.js b/Message/Request/RequestMethod.enum.js index fc9ccfd..51c07a5 100644 --- a/Message/Request/RequestMethod.enum.js +++ b/Message/Request/RequestMethod.enum.js @@ -9,7 +9,7 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumRequestMethod = Object.freeze({ + 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..81ab583 100644 --- a/Message/Request/RequestType.enum.js +++ b/Message/Request/RequestType.enum.js @@ -9,7 +9,7 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumRequestType = Object.freeze({ + jsOMS.Message.Request.RequestType = Object.freeze({ JSON: 'json', RAW: 'raw' }); diff --git a/Message/Response/ResponseResultType.enum.js b/Message/Response/ResponseResultType.enum.js index 6b71086..59bf343 100644 --- a/Message/Response/ResponseResultType.enum.js +++ b/Message/Response/ResponseResultType.enum.js @@ -9,7 +9,7 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumResponseResultType = Object.freeze({ + 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..9c124e2 100644 --- a/Message/Response/ResponseType.enum.js +++ b/Message/Response/ResponseType.enum.js @@ -9,7 +9,7 @@ */ (function (jsOMS, undefined) { - jsOMS.EnumResponseType = Object.freeze({ + jsOMS.Message.Response.ResponseType = Object.freeze({ TEXT: 'text', JSON: 'json', DOCUMENT: 'document', diff --git a/UI/FormManager.js b/UI/FormManager.js index 061b375..d876a2c 100644 --- a/UI/FormManager.js +++ b/UI/FormManager.js @@ -94,7 +94,7 @@ self = this; request.setData(form.getData()); - request.setType(jsOMS.EnumResponseType.JSON); + request.setType(jsOMS.Message.Response.ResponseType.JSON); request.setUri(form.getAction()); request.setMethod(form.getMethod()); request.setRequestHeader('Content-Type', 'application/json'); 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', From 23f9ace93a4078eafc87e46e5074c71730b7fc3d Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 21:37:41 +0100 Subject: [PATCH 17/27] Init namespaces --- autoloader.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 autoloader.js diff --git a/autoloader.js b/autoloader.js new file mode 100644 index 0000000..d83798f --- /dev/null +++ b/autoloader.js @@ -0,0 +1,35 @@ +(function (jsOMS, undefined) { + jsOMS.Account = {}; + jsOMS.Asset = {}; + jsOMS.Auth = {}; + jsOMS.Chart = {}; + jsOMS.Config = {}; + jsOMS.DataStorage = {}; + jsOMS.Dispatcher = {}; + jsOMS.Event = {}; + jsOMS.Localization = {}; + jsOMS.Log = {}; + jsOMS.Math = {}; + jsOMS.Media = {}; + jsOMS.Media.Audio = {}; + jsOMS.Media.Video = {}; + jsOMS.Module = {}; + jsOMS.Message = {}; + jsOMS.Message.Request = {}; + jsOMS.Message.Response = {}; + jsOMS.Route = {}; + jsOMS.Security = {}; + jsOMS.Security.Hash = {}; + jsOMS.Socket = {}; + jsOMS.Socket.Client = {}; + jsOMS.Stdlib = {}; + jsOMS.System = {}; + jsOMS.UI = {}; + jsOMS.UI.Input = {}; + jsOMS.UI.Input.Keyboard = {}; + jsOMS.UI.Input.Mouse = {}; + jsOMS.Uri = {}; + jsOMS.Utils = {}; + jsOMS.Validation = {}; + jsOMS.Views = {}; +}(window.jsOMS = window.jsOMS || {})); \ No newline at end of file From f89a99426f4ea95d5d1aebb967a3c921a78f7f40 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 21:38:25 +0100 Subject: [PATCH 18/27] Response skeleton --- Message/Response/Resposne.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Message/Response/Resposne.js diff --git a/Message/Response/Resposne.js b/Message/Response/Resposne.js new file mode 100644 index 0000000..8e89c0d --- /dev/null +++ b/Message/Response/Resposne.js @@ -0,0 +1,15 @@ +(function (uriFactory, undefined) { + 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]]; + }; +}(window.jsOMS = window.jsOMS || {})); \ No newline at end of file From e117722f1d4e8425d454cbedb8373c49f0b764ec Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 25 Mar 2016 21:38:41 +0100 Subject: [PATCH 19/27] Input UI manager/binder --- UI/Input.js | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 UI/Input.js diff --git a/UI/Input.js b/UI/Input.js new file mode 100644 index 0000000..c313508 --- /dev/null +++ b/UI/Input.js @@ -0,0 +1,107 @@ +/** + * 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.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, ref = null; + + input.addEventListener('change', function changeBind(event) { + /* Handle remote datalist/autocomplete input element */ + let listId, list; + if((listId = this.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') { + self.addRemoteDatalistOptions(this, list); + } + + /* Handle dynamic change events */ + if(ref = this.getAttribute('data-ref') !== 'undefined') { + let e = document.getElementById(ref); + + switch(e.tagName) { + case 'ul': + break; + case 'table': + break; + }; + } + }); + + this.app.inputManager.getKeyboardManager().bind(input, 13, function() { + document.getElementById(this.getAttribute('data-button')).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 || {})); From 7ad8ccc39badb2aeacc40a73d4f37d5fe243bcbf Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 26 Mar 2016 10:41:58 +0100 Subject: [PATCH 20/27] Preparing for crazy autoloading expermiment --- UI/Input/InputManager.js | 16 +++++++++-- autoloader.js | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/UI/Input/InputManager.js b/UI/Input/InputManager.js index 5fca112..7b2b9ab 100644 --- a/UI/Input/InputManager.js +++ b/UI/Input/InputManager.js @@ -1,5 +1,15 @@ (function (jsOMS, undefined) { - jsOMS.InputManager = function () - { - }; + jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input'); + + jsOMS.Autoloader.include(['jsOMS/UI/Input/Keyboard/KeyBoardManager.js'], function() { + 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/autoloader.js b/autoloader.js index d83798f..e434864 100644 --- a/autoloader.js +++ b/autoloader.js @@ -1,4 +1,5 @@ (function (jsOMS, undefined) { + jsOMS.Autoloader = {}; jsOMS.Account = {}; jsOMS.Asset = {}; jsOMS.Auth = {}; @@ -32,4 +33,62 @@ jsOMS.Utils = {}; jsOMS.Validation = {}; jsOMS.Views = {}; + + 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(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 From 990ee6d7dd2c63cae18c37ab7669229dc137865e Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 26 Mar 2016 11:02:52 +0100 Subject: [PATCH 21/27] Input binding on change --- UI/Input.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/UI/Input.js b/UI/Input.js index c313508..aa0bde5 100644 --- a/UI/Input.js +++ b/UI/Input.js @@ -25,7 +25,7 @@ jsOMS.UI.Input.bind = function(input) { - let self = this, ref = null; + let self = this; input.addEventListener('change', function changeBind(event) { /* Handle remote datalist/autocomplete input element */ @@ -34,7 +34,14 @@ self.addRemoteDatalistOptions(this, list); } - /* Handle dynamic change events */ + /* Handle html defined functions */ + let change; + if((change = this.getAttribute('data-change-func')) !== 'undefined') { + change(this); + } + + /* Handle pre-defined dynamic change events */ + let ref; if(ref = this.getAttribute('data-ref') !== 'undefined') { let e = document.getElementById(ref); @@ -47,9 +54,12 @@ } }); - this.app.inputManager.getKeyboardManager().bind(input, 13, function() { - document.getElementById(this.getAttribute('data-button')).click(); - }); + let dataButton; + if((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) From 5350531511b272a7ef603f00a7bf487c4efaba2a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 26 Mar 2016 11:27:38 +0100 Subject: [PATCH 22/27] typeof fix. --- UI/Input.js | 8 ++++---- autoloader.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/UI/Input.js b/UI/Input.js index aa0bde5..3cd7573 100644 --- a/UI/Input.js +++ b/UI/Input.js @@ -30,19 +30,19 @@ input.addEventListener('change', function changeBind(event) { /* Handle remote datalist/autocomplete input element */ let listId, list; - if((listId = this.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') { + 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((change = this.getAttribute('data-change-func')) !== 'undefined') { + if(typeof (change = this.getAttribute('data-change-func')) !== 'undefined') { change(this); } /* Handle pre-defined dynamic change events */ let ref; - if(ref = this.getAttribute('data-ref') !== 'undefined') { + if(typeof (ref = this.getAttribute('data-ref')) !== 'undefined') { let e = document.getElementById(ref); switch(e.tagName) { @@ -55,7 +55,7 @@ }); let dataButton; - if((dataButton = input.getAttribute('data-button')) !== 'undefined') { + if(typeof (dataButton = input.getAttribute('data-button')) !== 'undefined') { this.app.inputManager.getKeyboardManager().bind(input, 13, function() { document.getElementById(dataButton).click(); }); diff --git a/autoloader.js b/autoloader.js index e434864..2905474 100644 --- a/autoloader.js +++ b/autoloader.js @@ -47,7 +47,7 @@ current = jsOMS; for(let i = 0; i < length; i++) { - if(current[paths[i]] === 'undefined') { + if(typeof current[paths[i]] === 'undefined') { current[paths[i]] = {}; } From 877528f859bf480e7e6533961b612dec2eb36eec Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 26 Mar 2016 21:39:18 +0100 Subject: [PATCH 23/27] Namespace fixes and applying autoloader/namespace --- Account/AccountManager.js | 11 ++-- Account/AccountType.enum.js | 4 +- Asset/AssetManager.js | 3 +- Auth/Auth.js | 1 + Autoloader.js | 60 +++++++++++++++++++++ Config/Options.js | 1 + DataStorage/CacheManager.js | 4 +- DataStorage/CookieJar.js | 3 +- DataStorage/LocalStorage.js | 3 +- DataStorage/StorageManager.js | 4 +- Dispatcher/Dispatcher.js | 4 +- Event/EventManager.js | 4 +- Log/LogLevel.enum.js | 2 + Log/Logger.js | 7 +-- Message/Request/BrowserType.enum.js | 2 + Message/Request/OSType.enum.js | 48 +++++++++-------- Message/Request/Request.js | 3 +- Message/Request/RequestData.enum.js | 4 +- Message/Request/RequestManager.js | 5 +- Message/Request/RequestMethod.enum.js | 2 + Message/Request/RequestType.enum.js | 2 + Message/Response/ResponseManager.js | 1 + Message/Response/ResponseResultType.enum.js | 2 + Message/Response/ResponseType.enum.js | 2 + Message/Response/Resposne.js | 2 + Module/ModuleFactory.js | 3 +- Module/ModuleManager.js | 3 +- Route/Route.js | 4 +- UI/FormManager.js | 6 +-- UI/Input.js | 1 + UI/Input/InputManager.js | 4 +- UI/Input/Keyboard/KeyboardManager.js | 8 +-- UI/TabManager.js | 9 ++-- UI/TableManager.js | 9 ++-- UI/UIManager.js | 10 ++-- Uri/UriFactory.js | 5 +- Views/FormView.js | 1 + 37 files changed, 175 insertions(+), 72 deletions(-) create mode 100644 Autoloader.js 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 cfa7cea..8033d2a 100644 --- a/Account/AccountType.enum.js +++ b/Account/AccountType.enum.js @@ -9,7 +9,9 @@ */ (function (jsOMS, undefined) { - jsOMS.Account.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 f91abd8..dfd598e 100644 --- a/Asset/AssetManager.js +++ b/Asset/AssetManager.js @@ -9,7 +9,8 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.Asset'); + /** * @constructor * diff --git a/Auth/Auth.js b/Auth/Auth.js index f7bd333..7fca725 100644 --- a/Auth/Auth.js +++ b/Auth/Auth.js @@ -9,6 +9,7 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Auth'); /** * @constructor 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 0b1f1e2..09fdb5a 100644 --- a/Config/Options.js +++ b/Config/Options.js @@ -9,6 +9,7 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Config'); /** * @constructor 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 809693e..53f0026 100644 --- a/DataStorage/CookieJar.js +++ b/DataStorage/CookieJar.js @@ -9,7 +9,8 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); + /** * @constructor * diff --git a/DataStorage/LocalStorage.js b/DataStorage/LocalStorage.js index ff8dc1b..2973ae5 100644 --- a/DataStorage/LocalStorage.js +++ b/DataStorage/LocalStorage.js @@ -9,7 +9,8 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); + /** * @constructor * 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 index 87adb41..06ca393 100644 --- a/Log/LogLevel.enum.js +++ b/Log/LogLevel.enum.js @@ -9,6 +9,8 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Log'); + jsOMS.Log.LogLevel = Object.freeze({ EMERGENCY: 'normal', ALERT: 'normal', diff --git a/Log/Logger.js b/Log/Logger.js index 21213aa..6712231 100644 --- a/Log/Logger.js +++ b/Log/Logger.js @@ -10,6 +10,7 @@ (function (jsOMS, undefined) { "use strict"; + jsOMS.Autoloader.defineNamespace('jsOMS.Log'); /** * @constructor @@ -17,7 +18,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Logger = function (verbose, ui, remote) + jsOMS.Log.Logger = function (verbose, ui, remote) { this.verbose = typeof verbose !== 'undefined' ? verbose : true; this.ui = typeof ui !== 'undefined' ? ui : true; @@ -55,7 +56,7 @@ context = this.createContext(message, context, level); if(this.verbose) { - console.log(this.interpolate(message, context, level))); + console.log(this.interpolate(message, context, level)); } if(this.ui) { @@ -63,7 +64,7 @@ } if(this.remote) { - let request = new jsOMS.Message.Request(), + let request = new jsOMS.Message.Request(); request.setData(context); request.setType(jsOMS.Message.Response.ResponseType.JSON); request.setUri('/{/lang}/api/log'); diff --git a/Message/Request/BrowserType.enum.js b/Message/Request/BrowserType.enum.js index 6ea33d0..eb2ef07 100644 --- a/Message/Request/BrowserType.enum.js +++ b/Message/Request/BrowserType.enum.js @@ -9,6 +9,8 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); + jsOMS.Message.Request.BrowserType = Object.freeze({ OPERA: 'opera', FIREFOX: 'firefox', diff --git a/Message/Request/OSType.enum.js b/Message/Request/OSType.enum.js index adcb735..06456b7 100644 --- a/Message/Request/OSType.enum.js +++ b/Message/Request/OSType.enum.js @@ -9,29 +9,31 @@ */ (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 */ + 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 1e36dd0..946ba41 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -9,6 +9,7 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); /** * @constructor @@ -37,7 +38,7 @@ } else if(typeof InstallTrigger !== 'undefined') { return jsOMS.EnumBrowser.FIREFOX; } else if(Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0) { - return return jsOMS.EnumBrowser.SAFARI; + return jsOMS.EnumBrowser.SAFARI; } else if(/*@cc_on!@*/false || !!document.documentMode) { return jsOMS.EnumBrowser.IE; } else if(!isIE && !!window.StyleMedia) { 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 809c06a..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.Message.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 51c07a5..6b22636 100644 --- a/Message/Request/RequestMethod.enum.js +++ b/Message/Request/RequestMethod.enum.js @@ -9,6 +9,8 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); + jsOMS.Message.Request.RequestMethod = Object.freeze({ POST: 'POST', GET: 'GET', diff --git a/Message/Request/RequestType.enum.js b/Message/Request/RequestType.enum.js index 81ab583..cdfb09c 100644 --- a/Message/Request/RequestType.enum.js +++ b/Message/Request/RequestType.enum.js @@ -9,6 +9,8 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); + jsOMS.Message.Request.RequestType = Object.freeze({ JSON: 'json', RAW: 'raw' diff --git a/Message/Response/ResponseManager.js b/Message/Response/ResponseManager.js index d11dfe4..c093761 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 diff --git a/Message/Response/ResponseResultType.enum.js b/Message/Response/ResponseResultType.enum.js index 59bf343..d0d1ef3 100644 --- a/Message/Response/ResponseResultType.enum.js +++ b/Message/Response/ResponseResultType.enum.js @@ -9,6 +9,8 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); + jsOMS.Message.Response.ResponseResultType = Object.freeze({ MULTI: 0, MESSAGE: 1, diff --git a/Message/Response/ResponseType.enum.js b/Message/Response/ResponseType.enum.js index 9c124e2..97c0678 100644 --- a/Message/Response/ResponseType.enum.js +++ b/Message/Response/ResponseType.enum.js @@ -9,6 +9,8 @@ */ (function (jsOMS, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); + jsOMS.Message.Response.ResponseType = Object.freeze({ TEXT: 'text', JSON: 'json', diff --git a/Message/Response/Resposne.js b/Message/Response/Resposne.js index 8e89c0d..7fa8dbd 100644 --- a/Message/Response/Resposne.js +++ b/Message/Response/Resposne.js @@ -1,4 +1,6 @@ (function (uriFactory, undefined) { + jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); + jsOMS.Message.Response.Response = function (data) { this.responses = data; }; diff --git a/Module/ModuleFactory.js b/Module/ModuleFactory.js index b980e5e..85e0a3a 100644 --- a/Module/ModuleFactory.js +++ b/Module/ModuleFactory.js @@ -9,7 +9,8 @@ */ (function (jsOMS, undefined) { - + jsOMS.Autoloader.defineNamespace('jsOMS.Module'); + /** * @constructor * diff --git a/Module/ModuleManager.js b/Module/ModuleManager.js index d7ca131..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 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/FormManager.js b/UI/FormManager.js index d876a2c..a6d1ead 100644 --- a/UI/FormManager.js +++ b/UI/FormManager.js @@ -9,15 +9,15 @@ */ (function (jsOMS, undefined) { - "use strict"; - + jsOMS.Autoloader.defineNamespace('jsOMS.UI'); + /** * @constructor * * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.UI.FormManager = function (app) + jsOMS.UI.FormManager = function(app) { this.app = app; this.forms = {}; diff --git a/UI/Input.js b/UI/Input.js index 3cd7573..9b26426 100644 --- a/UI/Input.js +++ b/UI/Input.js @@ -10,6 +10,7 @@ (function (jsOMS, undefined) { "use strict"; + jsOMS.Autoloader.defineNamespace('jsOMS.UI'); /** * @constructor diff --git a/UI/Input/InputManager.js b/UI/Input/InputManager.js index 7b2b9ab..1e82664 100644 --- a/UI/Input/InputManager.js +++ b/UI/Input/InputManager.js @@ -1,15 +1,13 @@ (function (jsOMS, undefined) { jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input'); - jsOMS.Autoloader.include(['jsOMS/UI/Input/Keyboard/KeyBoardManager.js'], function() { jsOMS.UI.Input.InputManager = function () { - this.keyBoardManager = new jsOMS.UI.Input.Keyboard.KeyBoardManager(); + 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 c3b5997..366475c 100644 --- a/UI/Input/Keyboard/KeyboardManager.js +++ b/UI/Input/Keyboard/KeyboardManager.js @@ -1,9 +1,11 @@ (function (jsOMS, undefined) { - jsOMS.UI.Input.KeyboardManager = function () + jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Keyboard'); + + jsOMS.UI.Input.Keyboard.KeyboardManager = function () { }; - jsOMS.UI.Input.KeyboardManager.prototype.bind = 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) { @@ -13,7 +15,7 @@ }; - jsOMS.UI.Input.KeyboardManager.prototype.unbind = function (element) + jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.unbind = function (element) { element.removeEventListener('keyup', keyBind, false); }; 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 186c42c..3d65cef 100644 --- a/UI/UIManager.js +++ b/UI/UIManager.js @@ -9,8 +9,8 @@ */ (function (jsOMS, undefined) { - jsOMS.UI = {}; - + jsOMS.Autoloader.defineNamespace('jsOMS.UI'); + /** * @constructor * @@ -20,9 +20,9 @@ jsOMS.UI.UIManager = function (app) { this.app = app; - this.formManager = new jsOMS.FormManager(this.app); - 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); }; /** diff --git a/Uri/UriFactory.js b/Uri/UriFactory.js index e6c4aca..f7252d4 100644 --- a/Uri/UriFactory.js +++ b/Uri/UriFactory.js @@ -1,6 +1,5 @@ (function (uriFactory, undefined) { - jsOMS.Uri.UriFactory = {}; - jsOMS.Uri.UriFactory.uri = {}; + jsOMS.Autoloader.defineNamespace('jsOMS.Uri.UriFactory'); jsOMS.Uri.UriFactory.parseUrl = function (str, component) { @@ -89,7 +88,7 @@ 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) { + return uri.replace('\{[\/#\?@\.\$][a-zA-Z0-9]*\}', function(match) { match = substr(match[0], 1, match[0].length - 2); if(toMatch.hasProperty(match)) { diff --git a/Views/FormView.js b/Views/FormView.js index 1cda58b..dd7fb47 100644 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -1,5 +1,6 @@ (function (jsOMS, undefined) { "use strict"; + jsOMS.Autoloader.defineNamespace('jsOMS.Views'); jsOMS.Views.FormView = function (id) { this.id = id; From 8b608d7d4c557805de4fcacece8c5eae89ee1b91 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 26 Mar 2016 21:39:26 +0100 Subject: [PATCH 24/27] Renamed --- autoloader.js | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/autoloader.js b/autoloader.js index 2905474..166824b 100644 --- a/autoloader.js +++ b/autoloader.js @@ -1,39 +1,5 @@ (function (jsOMS, undefined) { jsOMS.Autoloader = {}; - jsOMS.Account = {}; - jsOMS.Asset = {}; - jsOMS.Auth = {}; - jsOMS.Chart = {}; - jsOMS.Config = {}; - jsOMS.DataStorage = {}; - jsOMS.Dispatcher = {}; - jsOMS.Event = {}; - jsOMS.Localization = {}; - jsOMS.Log = {}; - jsOMS.Math = {}; - jsOMS.Media = {}; - jsOMS.Media.Audio = {}; - jsOMS.Media.Video = {}; - jsOMS.Module = {}; - jsOMS.Message = {}; - jsOMS.Message.Request = {}; - jsOMS.Message.Response = {}; - jsOMS.Route = {}; - jsOMS.Security = {}; - jsOMS.Security.Hash = {}; - jsOMS.Socket = {}; - jsOMS.Socket.Client = {}; - jsOMS.Stdlib = {}; - jsOMS.System = {}; - jsOMS.UI = {}; - jsOMS.UI.Input = {}; - jsOMS.UI.Input.Keyboard = {}; - jsOMS.UI.Input.Mouse = {}; - jsOMS.Uri = {}; - jsOMS.Utils = {}; - jsOMS.Validation = {}; - jsOMS.Views = {}; - jsOMS.Autoloader.loaded = []; jsOMS.Autoloader.namespaced = []; From 199d27f6862d37cc5d88e324cd8f0ce15ea3c505 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 26 Mar 2016 21:57:35 +0100 Subject: [PATCH 25/27] Fix array/object mixup --- UI/FormManager.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/UI/FormManager.js b/UI/FormManager.js index a6d1ead..95fdf8b 100644 --- a/UI/FormManager.js +++ b/UI/FormManager.js @@ -34,16 +34,21 @@ return this.ignore.indexOf(id) !== -1; }; + jsOMS.UI.FormManager.prototype.unbind = function(id) + { + + }; + jsOMS.UI.FormManager.prototype.bind = function(id) { - if (typeof id !== 'undefined' && this.ignore.indexOf(id) === -1) { + 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 (this.ignore.indexOf(forms[i].id) === -1) { + if (typeof this.ignore[forms[i].id] === 'undefined') { this.bindForm(forms[i].id); } } @@ -52,12 +57,16 @@ jsOMS.UI.FormManager.prototype.bindForm = function(id) { + if(typeof id === 'undefined' || !id) { + throw false; + } + let self = this; this.unbind(id); - if(this.ignore.indexOf(id) === -1) { - this.forms[id] = new FormView(id); + if(typeof this.ignore[id] === 'undefined') { + this.forms[id] = new jsOMS.Views.FormView(id); } this.forms[id].getSubmit().addEventListener('click', function(event) { @@ -71,7 +80,7 @@ // todo: do i need the findex? can't i just use id? let findex = 0; - if((findex = this.forms.indexOf(id)) !== -1) { + if((findex = this.forms[id]) !== 'undefined') { this.forms[id].unbind(); this.forms.splice(findex, 1); From f96b6322aa91a5cbb01887a2051933a14ee6ee41 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 3 Apr 2016 21:18:58 +0200 Subject: [PATCH 26/27] Rename --- Message/Response/{Resposne.js => Response.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Message/Response/{Resposne.js => Response.js} (100%) diff --git a/Message/Response/Resposne.js b/Message/Response/Response.js similarity index 100% rename from Message/Response/Resposne.js rename to Message/Response/Response.js From 6e9c6653cad634f0b45a2bd78fb1094c46756853 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 9 Apr 2016 13:34:57 +0200 Subject: [PATCH 27/27] Remaining bug fixes for restructure-1 --- Auth/Auth.js | 2 +- Log/LogLevel.enum.js | 16 +++++++------- Log/Logger.js | 34 +++++++++++++++++++++++------ Message/Request/Request.js | 20 ++++++++--------- Message/Response/Response.js | 8 ++++++- Message/Response/ResponseManager.js | 2 +- UI/FormManager.js | 15 +++++++------ Views/FormView.js | 34 ++++++++++++++++++++++++++++- 8 files changed, 95 insertions(+), 36 deletions(-) diff --git a/Auth/Auth.js b/Auth/Auth.js index 7fca725..5e738ce 100644 --- a/Auth/Auth.js +++ b/Auth/Auth.js @@ -63,7 +63,7 @@ */ jsOMS.Auth.Auth.prototype.login = function () { - var authRequest = new jsOMS.Message.Request(); + var authRequest = new jsOMS.Message.Request.Request(); authRequest.setUri(this.uri); authRequest.setMethod(jsOMS.Message.Request.RequestMethod.POST); authRequest.setResponseType(jsOMS.Message.Request.RequestType.JSON); diff --git a/Log/LogLevel.enum.js b/Log/LogLevel.enum.js index 06ca393..e900404 100644 --- a/Log/LogLevel.enum.js +++ b/Log/LogLevel.enum.js @@ -12,13 +12,13 @@ jsOMS.Autoloader.defineNamespace('jsOMS.Log'); jsOMS.Log.LogLevel = Object.freeze({ - EMERGENCY: 'normal', - ALERT: 'normal', - CRITICAL: 'normal', - ERROR: 'normal', - WARNING: 'normal', - NOTICE: 'normal', - INFO: 'normal', - DEBUG: 'normal' + 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 index 6712231..7ed4b36 100644 --- a/Log/Logger.js +++ b/Log/Logger.js @@ -31,7 +31,7 @@ { let newMessage = jsOMS.Log.Logger.layout; - for(replace in context) { + for(let replace in context) { newMessage = newMessage.replace('{'+replace+'}', context[replace]); } @@ -42,8 +42,8 @@ { context['datetime'] = (new Date()).toISOString(); context['version'] = '1.0.0'; - context['os'] = jsOMS.Message.Request.getOS(); - context['browser'] = jsOMS.Message.Request.getBrowser(); + 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; @@ -56,7 +56,7 @@ context = this.createContext(message, context, level); if(this.verbose) { - console.log(this.interpolate(message, context, level)); + console.log('%c' + this.interpolate(message, context, level), 'color: #FFA600'); } if(this.ui) { @@ -64,11 +64,11 @@ } if(this.remote) { - let request = new jsOMS.Message.Request(); + let request = new jsOMS.Message.Request.Request(); request.setData(context); - request.setType(jsOMS.Message.Response.ResponseType.JSON); + request.setType(jsOMS.Message.Response.Response.ResponseType.JSON); request.setUri('/{/lang}/api/log'); - request.setMethod(jsOMS.Message.Request.RequestMethod.POST); + request.setMethod(jsOMS.Message.Request.Request.RequestMethod.POST); request.setRequestHeader('Content-Type', 'application/json'); request.setSuccess(function (xhr) {}); request.send(); @@ -77,51 +77,71 @@ 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/Request.js b/Message/Request/Request.js index 946ba41..b74661b 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -34,26 +34,26 @@ jsOMS.Message.Request.Request.getBrowser = function() { if((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { - return jsOMS.EnumBrowser.OPERA; + return jsOMS.Message.Request.BrowserType.OPERA; } else if(typeof InstallTrigger !== 'undefined') { - return jsOMS.EnumBrowser.FIREFOX; + return jsOMS.Message.Request.BrowserType.FIREFOX; } else if(Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0) { - return jsOMS.EnumBrowser.SAFARI; + return jsOMS.Message.Request.BrowserType.SAFARI; } else if(/*@cc_on!@*/false || !!document.documentMode) { - return jsOMS.EnumBrowser.IE; - } else if(!isIE && !!window.StyleMedia) { - return jsOMS.EnumBrowser.EDGE; + 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.EnumBrowser.CHROME; + return jsOMS.Message.Request.BrowserType.CHROME; } else if((isChrome || isOpera) && !!window.CSS) { - return jsOMS.EnumBrowser.BLINK; + return jsOMS.Message.Request.BrowserType.BLINK; } }; jsOMS.Message.Request.Request.getOS = function() { for(let os in jsOMS.Message.Request.OSType) { - if(navigator.appversion.indexOf(jsOMS.Message.Request.OSType[os]) !== -1) { + if(navigator.appVersion.toLowerCase().indexOf(jsOMS.Message.Request.OSType[os]) !== -1) { return jsOMS.Message.Request.OSType[os]; } } @@ -303,7 +303,7 @@ let self = this; if (self.xhr.readyState !== 1) { - self.xhr.open(this.method, jsOMS.UriFactory.build(this.uri)); + self.xhr.open(this.method, jsOMS.Uri.UriFactory.build(this.uri)); for (let p in this.requestHeader) { if (this.requestHeader.hasOwnProperty(p)) { diff --git a/Message/Response/Response.js b/Message/Response/Response.js index 7fa8dbd..007abff 100644 --- a/Message/Response/Response.js +++ b/Message/Response/Response.js @@ -12,6 +12,12 @@ jsOMS.Message.Response.Response.prototype.getByIndex = function(index) { - return this.responses[Object.keys(this.responses).sort()[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 c093761..d5456b6 100644 --- a/Message/Response/ResponseManager.js +++ b/Message/Response/ResponseManager.js @@ -62,7 +62,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Message.Response.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/UI/FormManager.js b/UI/FormManager.js index 95fdf8b..d5921c3 100644 --- a/UI/FormManager.js +++ b/UI/FormManager.js @@ -58,7 +58,8 @@ jsOMS.UI.FormManager.prototype.bindForm = function(id) { if(typeof id === 'undefined' || !id) { - throw false; + this.app.logger.info('A form doesn\'t have an ID.'); + return; } let self = this; @@ -99,7 +100,7 @@ } /* Handle default submit */ - let request = new jsOMS.Message.Request(), + let request = new jsOMS.Message.Request.Request(), self = this; request.setData(form.getData()); @@ -111,7 +112,7 @@ { try { let o = JSON.parse(xhr.response), - response = new Response(o), + response = new jsOMS.Message.Response.Response(o), responseLength = response.count(), tempResponse = null, success = null; @@ -119,16 +120,16 @@ /* Handle responses (can be multiple response object) */ for (let k = 0; k < responseLength; k++) { tempResponse = response.getByIndex(k); - console.log(tempResponse); - if(typeof (success = form.getSuccess()) !== 'undefined') { + if((success = form.getSuccess()) !== null) { success(tempResponse); } else { - self.app.responseManager.run(tempResponse); + self.app.responseManager.run(tempResponse.type, tempResponse, request); } } } catch (exception) { - self.app.logger.error('Invalid JSON object: ' + xhr, 'FormManager') + self.app.logger.error('Invalid Login response: ' + JSON.stringify(xhr)); + return false; } }); diff --git a/Views/FormView.js b/Views/FormView.js index dd7fb47..b7d9f7e 100644 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -7,6 +7,7 @@ this.initializeMembers(); this.bind(); + this.success = null; }; jsOMS.Views.FormView.prototype.initializeMembers = function() @@ -31,6 +32,16 @@ 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; @@ -57,12 +68,33 @@ i = 0; for(i = 0; i < length; i++) { - data[elements[i].getAttribute('name')] = elements[i].value; + data[this.getElementId(elements[i])] = elements[i].value; } 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;