diff --git a/Log/Logger.js b/Log/Logger.js index 7ed4b36..e4e46ec 100644 --- a/Log/Logger.js +++ b/Log/Logger.js @@ -49,14 +49,36 @@ context['message'] = message; return context; - } + }; jsOMS.Log.Logger.prototype.write = function(message, context, level) { context = this.createContext(message, context, level); if(this.verbose) { - console.log('%c' + this.interpolate(message, context, level), 'color: #FFA600'); + let color = '000'; + + switch(level) { + case 'info': + case 'notice': + case 'log': + color = '000'; + break; + case 'debug': + color = '289E39'; + break; + case 'warning': + case 'alert': + color = 'FFA600'; + break; + case 'error': + case 'critical': + case 'emergency': + color = 'CF304A'; + break; + } + + console.log('%c' + this.interpolate(message, context, level), 'color: #' + color); } if(this.ui) { diff --git a/Message/Request/OSType.enum.js b/Message/Request/OSType.enum.js index 06456b7..3a1abc0 100644 --- a/Message/Request/OSType.enum.js +++ b/Message/Request/OSType.enum.js @@ -12,6 +12,7 @@ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); jsOMS.Message.Request.OSType = Object.freeze({ + WINDOWS_10: 'windows nt 10.0', /* Windows 10 */ 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/Request.js b/Message/Request/Request.js index b74661b..7b1be46 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -25,9 +25,6 @@ this.success = null; this.type = typeof type !== 'undefined' ? type : jsOMS.Message.Response.ResponseType.JSON; this.data = {}; - - - this.xhr = new XMLHttpRequest(); }; @@ -191,7 +188,8 @@ /** * Set success callback. * - * @param {requestCallback} callback Success callback + * @callback requestCallback + * @param {requestCallback} callback - Success callback * * @method * diff --git a/Module/ModuleFactory.js b/Module/ModuleFactory.js index 85e0a3a..4a276d8 100644 --- a/Module/ModuleFactory.js +++ b/Module/ModuleFactory.js @@ -36,6 +36,6 @@ */ jsOMS.Module.ModuleFactory.getInstance = function (module, app) { - return new window['jsOMS']['Modules'][module](app); + return new jsOMS.Modules[module](app); }; }(window.jsOMS = window.jsOMS || {})); diff --git a/Module/ModuleManager.js b/Module/ModuleManager.js index 7064c22..562574b 100644 --- a/Module/ModuleManager.js +++ b/Module/ModuleManager.js @@ -38,7 +38,7 @@ jsOMS.Module.ModuleManager.prototype.get = function (module) { if (this.modules[module] === undefined) { - this.modules[module] = jsOMS.ModuleFactory.getInstance(module, this.app); + this.modules[module] = jsOMS.Module.ModuleFactory.getInstance(module, this.app); } return this.modules[module]; diff --git a/UI/FormManager.js b/UI/FormManager.js index d5921c3..8a40913 100644 --- a/UI/FormManager.js +++ b/UI/FormManager.js @@ -71,8 +71,8 @@ } this.forms[id].getSubmit().addEventListener('click', function(event) { - self.submit(self.forms[id]); jsOMS.preventAll(event); + self.submit(self.forms[id]); }); }; @@ -93,10 +93,15 @@ jsOMS.UI.FormManager.prototype.submit = function(form) { + if(!form.isValid()) { + this.app.logger.debug('Form "' + form.getId() + '" has invalid values.'); + return; + } + /* Handle injects */ let injects = form.getSubmitInjects(); for(let property in injects) { - property(); + injects[property](form.getElement()); } /* Handle default submit */ @@ -128,7 +133,7 @@ } } } catch (exception) { - self.app.logger.error('Invalid Login response: ' + JSON.stringify(xhr)); + self.app.logger.error('Invalid form response: ' + JSON.stringify(xhr)); return false; } diff --git a/UI/UIManager.js b/UI/UIManager.js index 3d65cef..2dc9270 100644 --- a/UI/UIManager.js +++ b/UI/UIManager.js @@ -51,7 +51,7 @@ case 'table': this.tableManager.bind(id); break; - }; + } } }; diff --git a/Uri/UriFactory.js b/Uri/UriFactory.js index f7252d4..f838053 100644 --- a/Uri/UriFactory.js +++ b/Uri/UriFactory.js @@ -1,12 +1,13 @@ (function (uriFactory, undefined) { jsOMS.Autoloader.defineNamespace('jsOMS.Uri.UriFactory'); - jsOMS.Uri.UriFactory.parseUrl = function (str, component) + jsOMS.Uri.UriFactory.uri = {}; + + jsOMS.Uri.UriFactory.parseUrl = function (str) { let query, key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'fragment' ], - ini = {}, mode = 'php', parser = { php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, @@ -24,24 +25,6 @@ } } - 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; @@ -86,12 +69,11 @@ jsOMS.Uri.UriFactory.build = function(uri, toMatch) { let current = jsOMS.Uri.UriFactory.parseUrl(window.location.href); - // match(new RegExp("\{[#\?\.a-zA-Z0-9]*\}", "gi")); - return uri.replace('\{[\/#\?@\.\$][a-zA-Z0-9]*\}', function(match) { - match = substr(match[0], 1, match[0].length - 2); + return uri.replace(new RegExp('\{[\/#\?@\.\$][a-zA-Z0-9]*\}', 'g'), function(match) { + match = match.substr(1, match.length - 2); - if(toMatch.hasProperty(match)) { + if(typeof toMatch !== 'undefined' && toMatch.hasProperty(match)) { return toMatch[match]; } else if(jsOMS.Uri.UriFactory.uri[match] !== 'undefined') { return jsOMS.Uri.UriFactory.uri[match]; diff --git a/Views/FormView.js b/Views/FormView.js index b7d9f7e..311fec0 100644 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -12,7 +12,7 @@ jsOMS.Views.FormView.prototype.initializeMembers = function() { - this.submitInjects = {}; + this.submitInjects = []; this.method = 'POST'; this.action = ''; }; @@ -44,41 +44,62 @@ jsOMS.Views.FormView.prototype.injectSubmit = function(id, callback) { - this.submitInjects[id] = callback; + this.submitInjects.push(callback); }; - jsOMS.Views.FormView.prototype.getFormElements = function(id) + jsOMS.Views.FormView.prototype.getFormElements = function() { - let form = document.getElementById(id), + let form = document.getElementById(this.id), selects = form.getElementsByTagName('select'), textareas = form.getElementsByTagName('textarea'), inputs = form.getElementsByTagName('input'), - external = document.querySelectorAll('[form='+id+']'), - elements = Array.prototype.slice.call(inputs).concat(Array.prototype.slice.call(selects), Array.prototype.slice.call(textareas), Array.prototype.slice.call(external)), - length = elements.length; + 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)); return elements; - } + }; jsOMS.Views.FormView.prototype.getData = function() { let data = {}, - elements = this.getFormElements(this.id), + elements = this.getFormElements(), length = elements.length, i = 0; for(i = 0; i < length; i++) { - data[this.getElementId(elements[i])] = elements[i].value; + data[jsOMS.Views.FormView.getElementId(elements[i])] = elements[i].value; } return data; }; - jsOMS.Views.FormView.prototype.getElementId = function(e) + jsOMS.Views.FormView.prototype.getId = function() { - let id = null; + return this.id; + }; - id = e.getAttribute('name'); + jsOMS.Views.FormView.prototype.isValid = function() + { + let elements = this.getFormElements(), + length = elements.length; + + for(let i = 0; i < length; i++) { + if((elements[i].required && elements[i].value === '') || (typeof elements[i].pattern !== 'undefined' && elements[i].pattern !== '' && (new RegExp(elements[i].pattern)).test(elements[i].value))) { + return false; + } + } + + return true; + }; + + jsOMS.Views.FormView.prototype.getElement = function() + { + return document.getElementById(this.getId()); + }; + + jsOMS.Views.FormView.getElementId = function(e) + { + let id = e.getAttribute('name'); if(id === null) { id = e.getAttribute('id'); @@ -93,7 +114,7 @@ } return id; - } + }; jsOMS.Views.FormView.prototype.getSubmitInjects = function() { @@ -107,7 +128,7 @@ this.method = document.getElementById(this.id).method; this.action = document.getElementById(this.id).action; - let elements = this.getFormElements(this.id), + let elements = this.getFormElements(), length = elements.length, i = 0; @@ -131,7 +152,7 @@ jsOMS.Views.FormView.prototype.unbind = function() { - let elements = this.getFormElements(this.id), + let elements = this.getFormElements(), length = elements.length, i = 0; diff --git a/oms.min.js b/oms.min.js deleted file mode 100644 index 8fe7334..0000000 --- a/oms.min.js +++ /dev/null @@ -1,1979 +0,0 @@ -/** - * Core JS functionality - * - * This logic is supposed to minimize coding and support core javascript functionality. - * - * @category App - * @package Framework - * @since 1.0.0 - */ -(function (jsOMS, undefined) { - - /** - * Property loader - * - * @param {Object} ele DOM Element - * @param {string} value Property to get - * - * @return string - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.getPropertyValue = function (ele, value) { - return window.getComputedStyle(ele, null).getPropertyValue(value); - }; - - /** - * Class finder - * - * Checking if a element has a class - * - * @param {Object} ele DOM Element - * @param {string} cls Class to find - * - * @return boolean - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.hasClass = function (ele, cls) { - return ele !== undefined && ele !== null && ele.className !== undefined && ele.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)')); - }; - - /** - * Add class - * - * Adding a class to an element - * - * @param ele DOM Element - * @param cls Class to add - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.addClass = function (ele, cls) { - if (!jsOMS.hasClass(ele, cls)) { - ele.className += " " + cls; - } - }; - - /** - * Remove class - * - * Removing a class form an element - * - * @param ele DOM Element - * @param cls Class to remove - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.removeClass = function (ele, cls) { - if (jsOMS.hasClass(ele, cls)) { - var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)'); - ele.className = ele.className.replace(reg, ''); - } - }; - - /** - * Delayed watcher - * - * Used to fire event after delay - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.watcher = function () { - var timer = 0; - return function (callback, ms) { - clearTimeout(timer); - timer = setTimeout(callback, ms); - }; - }(); - - /** - * Action prevent - * - * Preventing event from firering and passing through - * - * @param event Event Event to stop - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.preventAll = function(event) { - if (event.stopPropagation) { - event.stopPropagation(); - } else { - event.cancelBubble = true; - } - - event.preventDefault(); - }; - - /** - * Ready invoke - * - * Invoking a function after page load - * - * @param func Callback function - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.ready = function (func) { - // TODO: IE problems? + Maybe interactive + loaded can cause problems since elements might not be loaded yet?!!?!!?! - if (document.readyState === 'complete' || document.readyState === 'loaded' || document.readyState === 'interactive') { - func(); - } else { - document.addEventListener("DOMContentLoaded", function (event) { - func(); - }); - } - }; - - /** - * Each loop - * - * Looping over a node array and performing a task with these nodes - * - * @param nodes DOM Nodes - * @param func Callback function - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.each = function (nodes, func) { - var length = nodes.length; - - for (var i = 0; i < length; i++) { - func(nodes[i]); - } - }; - - /** - * Empty element - * - * Deleting content from element - * - * @param ele DOM Element - * - * @return void - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.empty = function (ele) { - while (ele.firstChild) { - ele.removeChild(ele.firstChild); - } - }; - - jsOMS.hash = function (str) { - var res = 0, - len = str.length; - for (var i = 0; i < len; i++) { - res = res * 31 + str.charCodeAt(i); - } - return res; - }; - - /** - * Check node - * - * Checking if a selection is a node - * - * @param ele DOM Node - * - * @return boolean - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.isNode = function (ele) { - return ( - typeof Node === "object" ? ele instanceof Node : - ele && typeof ele === "object" && typeof ele.nodeType === "number" && typeof ele.nodeName === "string" - ); - }; - - /** - * Check element - * - * Checking if a selection is a element - * - * @param o DOM Element - * - * @return boolean - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.isElement = function (o) { - return ( - typeof HTMLElement === "object" ? o instanceof HTMLElement : o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName === "string" - ); - }; - - /** - * Getting element by class - * - * Getting a element by class in the first level - * - * @param ele DOM Element - * @param cls Class to find - * - * @return Element - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.getByClass = function (ele, cls) { - var length = ele.childNodes.length; - - for (var i = 0; i < length; i++) { - if (jsOMS.hasClass(ele.childNodes[i], cls)) { - return ele.childNodes[i]; - } - } - - return null; - }; - - /** - * Getting element by tag - * - * Getting a element by tag in the first level - * - * @param ele DOM Element - * @param tag Tag to find - * - * @return Element - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.getByTag = function (ele, tag) { - return ele.getElementsByTagName(tag); - }; - - /** - * Merging two arrays recursively - * - * @param target Target array - * @param source Source array - * - * @return array - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.merge = function (target, source) { - for (var p in source) { - try { - if (source[p].constructor == Object) { - target[p] = merge(target[p], source[p]); - - } else { - target[p] = source[p]; - } - - } catch (e) { - target[p] = source[p]; - - } - } - - return target; - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.Options = function () - { - this.options = {}; - }; - - // TODO: create comments - jsOMS.Options.prototype.set = function (key, value, overwrite) - { - overwrite = typeof overwrite === bool ? overwrite : true; - - if (overwrite || !options[key]) { - options[key] = value; - } - - // TODO: return boolean for success - }; - - // TODO: create comments - jsOMS.Options.prototype.get = function (key) - { - // TODO: handle isset - return options[key]; - }; - - // TODO: create comments - jsOMS.Options.prototype.remove = function (key) - { - // TODO: Handle isset and return boolean - delete options[key]; - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.AccountManager = function () - { - this.accounts = []; - }; - - // TODO: create comments - jsOMS.AccountManager.prototype.add = function(account) - { - this.accounts[account.getId()] = account; - }; - - // TODO: create comments - jsOMS.AccountManager.prototype.remove = function(id) - { - if (typeof this.accounts[id] !== 'undefined') { - delete this.accounts[id]; - - return true; - } - - return false; - }; - - // TODO: create comments - jsOMS.AccountManager.prototype.get = function(id) - { - if (this.accounts[id]) { - return this.accounts[id]; - } - - return undefined; - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.Auth = function (uri) - { - this.account = null; - this.uri = uri; - }; - - // TODO: create comments - jsOMS.Auth.prototype.setAccount = function (account) - { - this.account = account; - }; - - // TODO: create comments - jsOMS.Auth.prototype.getAccount = function () { - return this.account; - }; - - // TODO: create comments - jsOMS.Auth.prototype.login = function () - { - var authRequest = new jsOMS.Request(); - authRequest.setUri(this.uri); - 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); - }); - - authRequest.send(); - }; - - // TODO: create comments - jsOMS.Auth.prototype.logout = function () - { - this.refresh(); - }; - - // TODO: create comments - jsOMS.Auth.prototype.loginResult = function (xhr) - { - console.log(xhr); - location.reload(); - }; - - // TODO: create comments - jsOMS.Auth.prototype.handshake = function () - { - - }; - - // TODO: create comments - jsOMS.Auth.prototype.setAuthKey = function () - { - - }; - - // TODO: create comments - jsOMS.Auth.prototype.getAuthKey = function () - { - - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.Uri = function () - { - }; - - // TODO: create comments - 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; - }; - - // TODO: create comments - 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 || {})); -(function (uriFactory, undefined) { - -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.FormView = function (node) { - if (node) { - this.setNode(node); - } - }; - - jsOMS.FormView.prototype.setNode = function () { - }; - - jsOMS.FormView.prototype.submit = function () { - - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.TableView = function () { - this.table = null; - }; - - /** - * None, Pagination, Infinite - */ - jsOMS.TableView.prototype.setExtensible = function () { - - }; - - jsOMS.TableView.prototype.add = function (element) { - - }; - - jsOMS.TableView.prototype.addCollection = function (collection) { - - }; - - jsOMS.TableView.prototype.remove = function (id) { - - }; - - jsOMS.TableView.prototype.get = function (id) { - - }; - - jsOMS.TableView.prototype.filter = function (id) { - - }; - - jsOMS.TableView.prototype.request = function (filter) { - - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.ViewAbstract = function () - { - this.element = null; - this.data = []; - }; - - jsOMS.ViewAbstract.prototype.bind = function (node) - { - this.element = node; - }; - - jsOMS.ViewAbstract.prototype.addData = function(id, data, overwrite) - { - overwrite = typeof overwrite !== 'undefined' ? overwrite : false; - - if(typeof this.data[id] === 'undefined' || overwrite) { - this.data[id] = data; - - return true; - } - - return false; - }; - - jsOMS.ViewAbstract.prototype.getData = function(id) - { - return typeof this.data[id] !== 'undefined' ? this.data[id] : undefined; - } -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.Account = function () { - this.login = ''; - this.password = ''; - this.id = 0; - this.auth = null; - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.CacheManager = function () - { - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.CookieJar = function () { - }; - - /** - * Saving data to cookie - * - * @param {string} cName Cookie name - * @param {string} value Value to save - * @param {number} exdays Lifetime for the cookie - * @param {string} domain Domain for the cookie - * @param {string} path Path for the cookie - * - * @return array - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.CookieJar.prototype.setCookie = function (cName, value, exdays, domain, path) { - var exdate = new Date(); - exdate.setDate(exdate.getDate() + exdays); - var cValue = encodeURI(value) + ((exdays === null) ? "" : "; expires=" + exdate.toUTCString()) + ";domain=" + domain + ";path=" + path; - document.cookie = cName + "=" + cValue; - }; - - /** - * Loading cookie data - * - * @param {string} cName Cookie name - * - * @return {string} - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ - jsOMS.CookieJar.prototype.getCookie = function (cName) { - var cValue = document.cookie; - var cStart = cValue.indexOf(" " + cName + "="); - - if (cStart === -1) { - cStart = cValue.indexOf(cName + "="); - } - - if (cStart === -1) { - cValue = null; - } else { - cStart = cValue.indexOf("=", cStart) + 1; - var cEnd = cValue.indexOf(";", cStart); - - if (cEnd === -1) { - cEnd = cValue.length; - } - - cValue = decodeURI(cValue.substring(cStart, cEnd)); - } - return cValue; - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.LocalStorage = function () { - }; - - // TODO: create comments - jsOMS.LocalStorage.prototype.available = function () { - try { - return 'localStorage' in window && window.localStorage !== null; - } catch (e) { - return false; - } - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.StorageManager = function () - { - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.ModuleFactory = function() {}; - - // TODO: create comments - jsOMS.ModuleFactory.getInstance = function (module, app) - { - return new window['jsOMS']['Modules'][module](app) - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.Modules = {}; - jsOMS.Modules.Models = {}; - - // TODO: create comments - jsOMS.ModuleManager = function (app) - { - this.modules = {}; - this.app = app; - }; - - // TODO: create comments - jsOMS.ModuleManager.prototype.initModule = function (module) - { - this.modules[module] = jsOMS.ModuleFactory.getInstance(module, this.app); - }; - - // TODO: create comments - jsOMS.ModuleManager.prototype.get = function (module) - { - return this.modules[module]; - }; -}(window.jsOMS = window.jsOMS || {})); -//+ Jonas Raoni Soares Silva -//@ http://jsfromhell.com/classes/math-processor [rev. #1] - -var MathProcessor = function () { - var o = this; - o.o = { - "+": function (a, b) { - return +a + b; - }, - "-": function (a, b) { - return a - b; - }, - "%": function (a, b) { - return a % b; - }, - "/": function (a, b) { - return a / b; - }, - "*": function (a, b) { - return a * b; - }, - "^": function (a, b) { - return Math.pow(a, b); - }, - "~": function (a, b) { - return Math.sqrt(a, b); - } - }; - o.s = {"^": 3, "~": 3, "*": 2, "/": 2, "%": 1, "+": 0, "-": 0}; - o.u = {"+": 1, "-": -1}, o.p = {"(": 1, ")": -1}; -}; -with ({p: MathProcessor.prototype}) { - p.methods = { - div: function (a, b) { - return parseInt(a / b); - }, - fra: function (a) { - return a - parseInt(a); - }, - sum: function (n1, n2, n3, n) { - for (var r = 0, a, l = (a = arguments).length; l; r += a[--l]) { - ; - } - return r; - }, - medium: function (n1, n2, n3, n) { - for (var r = 0, a, l = (a = arguments).length; l; r += a[--l]) { - ; - } - return r / a.length; - } - }; - p.parse = function (e) { - for (var n, x, _ = this, o = [], s = [x = _.RPN(e.replace(/ /g, "").split(""))]; s.length;) { - for ((n = s[s.length - 1], --s.length); n[2]; o[o.length] = n, s[s.length] = n[3], n = n[2]) { - ; - } - } - for (; (n = o.pop()) != undefined; n[0] = _.o[n[0]](isNaN(n[2][0]) ? _.f(n[2][0]) : n[2][0], isNaN(n[3][0]) ? _.f(n[3][0]) : n[3][0])) { - ; - } - return +x[0]; - }; - p.RPN = function (e) { - var x, r, _ = this, c = r = [, , , 0]; - if (e[0] in _.u || !e.unshift("+")) { - for (; e[1] in _.u; e[0] = _.u[e.shift()] * _.u[e[0]] + 1 ? "+" : "-") { - ; - } - } - (c[3] = [_.u[e.shift()], c, , 0])[1][0] = "*", (r = [, , c, 0])[2][1] = r; - (c[2] = _.v(e))[1] = c; - (!e.length && (r = c)) || (e[0] in _.s && ((c = r)[0] = e.shift(), !e.length && _.error())); - while (e.length) { - if (e[0] in _.u) { - for (; e[1] in _.u; e[0] = _.u[e.shift()] * _.u[e[0]] + 1 ? "+" : "-") { - ; - } - (c = c[3] = ["*", c, , 0])[2] = [-1, c, , 0]; - } - (c[3] = _.v(e))[1] = c; - e[0] in _.s && (c = _.s[e[0]] > _.s[c[0]] ? - ((c[3] = (x = c[3], c[2]))[1][2] = [e.shift(), c, x, 0])[2][1] = c[2] - : r == c ? (r = [e.shift(), , c, 0])[2][1] = r - : ((r[2] = (x = r[2], [e.shift(), r, , 0]))[2] = x)[1] = r[2]); - } - return r; - }; - p.v = function (e) { - var i, j, l, _ = this; - if ("0123456789.".indexOf(e[0]) + 1) { - for (i = -1, l = e.length; ++i < l && "0123456789.".indexOf(e[i]) + 1;) { - ; - } - return [+e.splice(0, i).join(""), , , 0]; - } - else if (e[0] == "(") { - for (i = 0, l = e.length, j = 1; ++i < l && (e[i] in _.p && (j += _.p[e[i]]), j);) { - ; - } - return _.RPN(l = e.splice(0, i), l.shift(), !j && e.shift()); - } - else { - if (((j = e[0].toLowerCase()) >= "a" && j <= "z") || j == "_") { - for (i = 0; ((j = e[++i].toLowerCase()) >= "a" && j <= "z") || j == "_" || (j >= 0 && j <= 9);) { - ; - } - if (j == "(") { - for (var l = e.length, j = 1; ++i < l && (e[i] in _.p && (j += _.p[e[i]]), j);) { - ; - } - return [e.splice(0, i + 1).join(""), , , 0]; - } - } - } - _.error(); - }; - p.f = function (e) { - var n, i = 0, _ = this; - if (((e = e.split(""))[i] >= "a" && e[i] <= "z") || e[i] == "_") { - while ((e[++i] >= "a" && e[i] <= "z") || e[i] == "_" || (e[i] >= 0 && e[i] <= 9)) { - ; - } - if (e[i] == "(") { - !_.methods[n = e.splice(0, i).join("")] && _.error("Function \"" + n + "\" not found"), e.shift(); - for (var a = [], i = -1, j = 1; e[++i] && (e[i] in _.p && (j += _.p[e[i]]), j);) { - j == 1 && e[i] == "," && (a.push(_.parse(e.splice(0, i).join(""))), e.shift(), i = -1); - } - a.push(_.parse(e.splice(0, i).join(""))), !j && e.shift(); - } - return _.methods[n].apply(_, a); - } - }; - p.error = function (s) { - return; - //throw new Error("MathProcessor: " + (s || "Wrong expression")); - }; -} -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.Route = function () - { - this.routes = null; - }; - - // TODO: create comments - jsOMS.Route.prototype.add = function (path, callback, exact) - { - exact = typeof exact !== 'undefined' ? exact : true; - - // todo: create array key path like i did for php - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.Dispatcher = function () - { - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.Request = function () - { - this.uri = null; - this.method = null; - this.requestHeader = []; - this.success = null; - this.type = 'GET'; - this.data = {}; - - this.xhr = new XMLHttpRequest(); - }; - - // TODO: create comments - jsOMS.Request.prototype.setMethod = function (method) - { - this.method = method; - }; - - // TODO: create comments - jsOMS.Request.prototype.getMethod = function () - { - return this.method; - }; - - // TODO: create comments - jsOMS.Request.prototype.setResponseType = function (type) - { - this.xhr.responseType = type; - }; - - // TODO: create comments - jsOMS.Request.prototype.getResponseType = function () - { - return this.responseType; - }; - - // TODO: create comments - jsOMS.Request.prototype.setRequestHeader = function (type, header) - { - this.requestHeader[type] = header; - }; - - // TODO: create comments - jsOMS.Request.prototype.getRequestHeader = function () - { - return this.requestHeader; - }; - - // TODO: create comments - jsOMS.Request.prototype.setUri = function (uri) - { - this.uri = uri; - }; - - // TODO: create comments - jsOMS.Request.prototype.getUri = function () - { - return this.uri; - }; - - // TODO: create comments - jsOMS.Request.prototype.setSuccess = function (callback) - { - this.success = callback; - }; - - // TODO: create comments - jsOMS.Request.prototype.setData = function (data) - { - this.data = data; - }; - - // TODO: create comments - jsOMS.Request.prototype.getData = function () - { - - }; - - // TODO: create comments - jsOMS.Request.prototype.setType = function (type) - { - this.type = type; - }; - - // TODO: create comments - jsOMS.Request.prototype.getType = function () - { - - }; - - // TODO: create comments - jsOMS.Request.prototype.serializeData = function () - { - - }; - - // TODO: create comments - jsOMS.Request.prototype.queryfy = function (obj) - { - var str = []; - for (var p in obj) { - if (obj.hasOwnProperty(p)) { - str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); - } - } - return str.join("&"); - }; - - // TODO: create comments - jsOMS.Request.prototype.send = function () - { - var self = this; - - if(self.xhr.readyState !== 1) { - self.xhr.open(this.method, this.uri); - - for (var p in this.requestHeader) { - if(this.requestHeader.hasOwnProperty(p)) { - self.xhr.setRequestHeader(p, this.requestHeader[p]); - } - } - } - - self.xhr.onreadystatechange = function () { - if (self.xhr.readyState === 4 && self.xhr.status === 200) { - self.success(self.xhr); - } - }; - - if(this.type === '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 === 'raw') { - self.xhr.send(this.data); - } - }; - - /** - * AJAX - * - * @param obj AJAX variables - * - * The following obj variables are expected: - * responseType - Type of the response - * requestHeader - Header description for the request - * success - Success callback function - * error - Error callback function - * type - GET, PUT, DELETE, POST type - * url - Request url - * data - Data to send - * - * @since 1.0.0 - * @author Dennis Eichhorn - */ -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.EnumLinkRequestData = Object.freeze({ - NORMAL: 'normal', - OBJECT: 'object' - }); -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.RequestManager = function () - { - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.Message.Request.RequestMethod = Object.freeze({ - POST: 'POST', - GET: 'GET', - PUT: 'PUT', - DELETE: 'DELETE', - HEAD: 'HEAD' - }); -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.ResponseManager = function () - { - this.messages = {}; - }; - - // TODO: create comments - jsOMS.ResponseManager.prototype.add = function (key, message, request) - { - request = typeof request !== 'undefined' ? request : 'any'; - if (typeof this.messages[key] === 'undefined') { - this.messages[key] = []; - } - - this.messages[key][request] = message; - }; - - // TODO: create comments - jsOMS.ResponseManager.prototype.execute = function (key, data, request) - { - console.log(data); - if (typeof request !== 'undefined' && typeof this.messages[key][request] !== 'undefined') { - this.messages[key][request](data); - } else if(typeof this.messages[key] !== 'undefined') { - this.messages[key].any(data); - } else { - console.log('does not exist'); - } - } -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.Message.Response.ResponseResultType = Object.freeze({ - MULTI: 0, - MESSAGE: 1, - INFO: 2, - DATA: 3, - LIST: 4 - }); -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.Message.Request.RequestType = Object.freeze({ - TEXT: 'text', - JSON: 'json', - DOCUMENT: 'document', - BLOB: 'blob', - ARRAYBUFFER: 'arraybuffer', - DEFAULT: '' - }); -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.EventManager = function () { - }; -}(window.jsOMS = window.jsOMS || {})); -SHA1 = function (l) { - function p(b, a) { - return b << a | b >>> 32 - a - } - - l += "€"; - for (var n = Math, c = [1518500249, 1859775393, 2400959708, 3395469782, 1732584193, 4023233417, 2562383102, 271733878, 3285377520, 4294967295], s = n.ceil(l.length / 4) + 2, q = n.ceil(s / 16), g = [], a = 0, h = [], j, d, e, f, m, i, b, k; a < q; a++) { - g[a] = []; - for (k = 0; k < 16; k++) { - function o(b, c) { - return l.charCodeAt(a * 64 + k * 4 + b) << c - } - - g[a][k] = o(0, 24) | o(1, 16) | o(2, 8) | o(3, 0) - } - } - i = l.length * 8 - 8; - a = q - 1; - g[a][14] = i / (c[9] + 1); - g[a][14] = n.floor(g[a][14]); - g[a][15] = i & c[9]; - for (a = 0; a < q; a++) { - for (b = 0; b < 16; b++) { - h[b] = g[a][b]; - } - for (b = 16; b < 80; b++) { - h[b] = p(h[b - 3] ^ h[b - 8] ^ h[b - 14] ^ h[b - 16], 1); - } - j = c[4]; - d = c[5]; - e = c[6]; - f = c[7]; - m = c[8]; - for (b = 0; b < 80; b++) { - var r = n.floor(b / 20), t = p(j, 5) + (r < 1 ? d & e ^ ~d & f : r == 2 ? d & e ^ d & f ^ e & f : d ^ e ^ f) + m + c[r] + h[b] & c[9]; - m = f; - f = e; - e = p(d, 30); - d = j; - j = t - } - c[4] += j; - c[5] += d; - c[6] += e; - c[7] += f; - c[8] += m - } - i = ""; - for (z = 4; z < 9; z++) { - for (a = 7; a >= 0; a--) { - i += ((c[z] & c[9]) >>> a * 4 & 15).toString(16); - } - } - return i; -}; -function SHA1(s) { - function U(a, b, c) { - while (0 < c--) { - a.push(b) - } - } - - function L(a, b) { - return (a << b) | (a >>> (32 - b)) - } - - function P(a, b, c) { - return a ^ b ^ c - } - - function A(a, b) { - var c = (b & 0xFFFF) + (a & 0xFFFF), d = (b >>> 16) + (a >>> 16) + (c >>> 16); - return ((d & 0xFFFF) << 16) | (c & 0xFFFF) - } - - var B = "0123456789abcdef"; - return (function (a) { - var c = [], d = a.length * 4, e; - for (var i = 0; i < d; i++) { - e = a[i >> 2] >> ((3 - (i % 4)) * 8); - c.push(B.charAt((e >> 4) & 0xF) + B.charAt(e & 0xF)) - } - return c.join('') - }((function (a, b) { - var c, d, e, f, g, h = a.length, v = 0x67452301, w = 0xefcdab89, x = 0x98badcfe, y = 0x10325476, z = 0xc3d2e1f0, M = []; - U(M, 0x5a827999, 20); - U(M, 0x6ed9eba1, 20); - U(M, 0x8f1bbcdc, 20); - U(M, 0xca62c1d6, 20); - a[b >> 5] |= 0x80 << (24 - (b % 32)); - a[(((b + 65) >> 9) << 4) + 15] = b; - for (var i = 0; i < h; i += 16) { - c = v; - d = w; - e = x; - f = y; - g = z; - for (var j = 0, O = []; j < 80; j++) { - O[j] = j < 16 ? a[j + i] : L(O[j - 3] ^ O[j - 8] ^ O[j - 14] ^ O[j - 16], 1); - var k = (function (a, b, c, d, e) { - var f = (e & 0xFFFF) + (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF), g = (e >>> 16) + (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + (f >>> 16); - return ((g & 0xFFFF) << 16) | (f & 0xFFFF) - })(j < 20 ? (function (t, a, b) { - return (t & a) ^ (~t & b) - }(d, e, f)) : j < 40 ? P(d, e, f) : j < 60 ? (function (t, a, b) { - return (t & a) ^ (t & b) ^ (a & b) - }(d, e, f)) : P(d, e, f), g, M[j], O[j], L(c, 5)); - g = f; - f = e; - e = L(d, 30); - d = c; - c = k - } - v = A(v, c); - w = A(w, d); - x = A(x, e); - y = A(y, f); - z = A(z, g) - } - return [v, w, x, y, z] - }((function (t) { - var a = [], b = 255, c = t.length * 8; - for (var i = 0; i < c; i += 8) { - a[i >> 5] |= (t.charCodeAt(i / 8) & b) << (24 - (i % 32)) - } - return a - }(s)).slice(), s.length * 8)))) -} -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.AssetManager = function () - { - this.assets = {}; - }; - - // TODO: create comments - jsOMS.AssetManager.prototype.load = function (path, filename, filetype, callback) - { - var hash; - - if (!this.assets[(hash = jsOMS.hash(path + '/' + filename))]) { - var fileref = null; - - if (filetype === 'js') { - fileref = document.createElement('script'); - fileref.setAttribute('type', 'text/javascript'); - fileref.setAttribute('src', path + '/' + filename); - - if (typeof fileref !== 'undefined') { - document.getElementsByTagName('head')[0].appendChild(fileref); - } - - this.assets[hash] = path + '/' + filename; - } else if (filetype === 'css') { - fileref = document.createElement('link'); - fileref.setAttribute('rel', 'stylesheet'); - fileref.setAttribute('type', 'text/css'); - fileref.setAttribute('href', path + '/' + filename); - - if (typeof fileref !== 'undefined') { - document.getElementsByTagName('head')[0].appendChild(fileref); - } - - this.assets[hash] = path + '/' + filename; - } else if (filetype === 'img') { - this.assets[hash] = new Image(); - this.assets[hash].src = path + '/' + filename; - } else if (filetype === 'audio') { - // TODO: implement audio asset - } else if (filetype === 'video') { - // TODO: implement video asset - } - - if (callback) { - fileref.onreadystatechange = function () { - if (this.readyState == 'complete') { - callback(); - } - }; - - fileref.onload = callback(); - } - - return hash; - } - - return false; - }; - - // TODO: create comments - jsOMS.AssetManager.prototype.get = function (id) - { - if (this.assets[id]) { - return this.assets[id]; - } - - return undefined; - }; - - // TODO: create comments - jsOMS.AssetManager.prototype.unload = function (key) - { - if (typeof this.assets[key] !== 'undefined') { - delete this.assets[key]; - - return true; - } - - return false; - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.FormManager = function (responseManager) - { - this.responseManager = responseManager; - this.ignore = []; - this.success = []; - this.injectSelector = []; - }; - - // TODO: create comments - jsOMS.FormManager.prototype.ignore = function (id) - { - this.ignore.push(id); - }; - - // TODO: create comments - jsOMS.FormManager.prototype.injectSubmit = function (selector, callback) - { - if (!(selector in this.injectSelector)) { - this.injectSelector[selector] = callback; - return true; - } - - return false; - }; - - // TODO: create comments - jsOMS.FormManager.prototype.setSuccess = function (id, callback) - { - this.success[id] = callback; - }; - - jsOMS.FormManager.prototype.bind = function (id) - { - if (typeof id !== 'undefined' && this.ignore.indexOf(id) === -1) { - this.bindElement(document.getElementById(id)); - } else { - var forms = document.getElementsByTagName('form'); - - for (var i = 0; i < forms.length; i++) { - if (this.ignore.indexOf(forms[i].id) === -1) { - this.bindElement(forms[i]); - } - } - } - }; - - // TODO: create comments - jsOMS.FormManager.prototype.validateFormElement = function (e) - { - /** Validate on change */ - if (typeof e.dataset.validate !== 'undefined') { - if (!(new RegExp(e.dataset.validate)).test(e.value)) { - return false; - } - } - - return true; - }; - - // TODO: create comments - jsOMS.FormManager.prototype.submit = function (e, data) - { - var request = new jsOMS.Request(), - self = this; - - request.setData(data); - request.setType('json'); - request.setUri(e.action); - request.setMethod(e.method); - request.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] - }); - - for (var k = 0; k < response.length; k++) { - if (response[k] !== null) { - console.log(response[k]); - - /* Handle success */ - if (!self.success[e.id]) { - self.responseManager.execute(response[k].type, response[k]); - } else { - self.success[e.id](response[k].type, response[k]); - } - } - } - } catch (exception) { - console.log('No valid json'); - return false; - } - }); - - request.send(); - }; - - // TODO: create comments - 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'); - } - - if(typeof e.dataset.formfields !== 'undefined') { - try { - 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; - }; - - // TODO: create comments - 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) { - self.injectSelector[key](e); - - injected = true; - } - } - - if(!injected) { - self.submit(e, submitdata); - } - - jsOMS.preventAll(event); - }); - }; - - /** Handle input */ - for (var 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 (var i = 0; i < select.length; i++) { - /** Redirect on change */ - if (typeof select[i].dataset.redirect !== 'undefined') { - select[i].onchange = function () { - // TODO: use URI factory (which i still have to create :)) - window.document.href = e.action.replace('{' + select[i].dataset.redirect + '}', select[i].value); - }; - } - } - - /** Handle button */ - for (var i = 0; i < buttons.length; i++) { - /** Redirect in new window on click */ - if (typeof buttons[i].dataset.ropen !== 'undefined' || typeof buttons[i].dataset.redirect !== 'undefined') { - buttons[i].addEventListener('click', function (event) { - var 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.parse_url(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); - } - - 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 use id here instead? then this needs to get changed in the form builder - var 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) { - // 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); - - 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 - var 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 - }); - } - } - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.InputManager = function () - { - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - jsOMS.KeyboardManager = function () - { - }; - - jsOMS.KeyboardManager.prototype.attach = function (element, keys, callback) { - }; - - jsOMS.KeyboardManager.prototype.detach = function (eventId) { - }; -}(window.jsOMS = window.jsOMS || {})); -var MathEvaluator = function () { - -}; - -MathEvaluator.prototype.attach = function () { - -}; - -MathEvaluator.prototype.detach = function () { - -}; - -MathEvaluator.prototype.trigger = function (node) { - var value = node.value; - - if (!value.slice(0, 1) == '=') { - return; - } - - var processor = new MathProcessor(); - return processor.parse(value); -}; -var MouseClickType = Object.freeze({ - LEFT: 1, - MIDDLE: 2, - RIGHT: 3 -}); -(function (jsOMS, undefined) { - jsOMS.MouseManager = function () - { - }; - - jsOMS.MouseManager.prototype.attach = function (clickType, element, callback) { - }; - - jsOMS.MouseManager.prototype.detach = function (eventId) { - }; -}(window.jsOMS = window.jsOMS || {})); -/* responsible for loading external ui elements (css,html,js) */(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.TabManager = function (responseManager) { - this.responseManager = responseManager; - }; - - // TODO: create comments - jsOMS.TabManager.prototype.bind = function (id) { - if (typeof id !== 'undefined') { - this.bindElement(document.getElementById(id)); - } else { - var tabs = document.querySelectorAll('.tabview'); - - for (var i = 0; i < tabs.length; i++) { - this.bindElement(tabs[i]); - } - } - }; - - // TODO: create comments - jsOMS.TabManager.prototype.bindElement = function (e) { - var nodes = e.querySelectorAll('.tab-links a'); - - nodes.addEventListener('click', function (evt) { - /* Change Tab */ - var attr = this.getAttribute('href').substring(1), - cont = this.parentNode.parentNode.parentNode.children[1]; - - jsOMS.removeClass(jsOMS.getByClass(this.parentNode.parentNode, 'active'), 'active'); - jsOMS.addClass(this.parentNode, 'active'); - jsOMS.removeClass(jsOMS.getByClass(cont, 'active'), 'active'); - jsOMS.addClass(jsOMS.getByClass(cont, attr), 'active'); - - /* Modify url */ - - jsOMS.preventAll(evt); - }); - }; -}(window.jsOMS = window.jsOMS || {})); -(function (jsOMS, undefined) { - // TODO: create comments - jsOMS.UIManager = function (app) - { - this.app = app; - this.formManager = new jsOMS.FormManager(this.app.responseManager); - this.tabManager = new jsOMS.TabManager(this.app.responseManager); - }; - - // TODO: create comments - jsOMS.UIManager.prototype.bind = function() - { - this.formManager.bind(); - this.tabManager.bind(); - } - - // TODO: create comments - jsOMS.UIManager.prototype.getFormManager = function() - { - return this.formManager; - } -}(window.jsOMS = window.jsOMS || {})); -/* Handle minimize and maximize logic for boxes */ -var nodes = document.querySelectorAll('.b > h1 .max, .b > h2 .max'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - var box = jsOMS.getByClass(e.parentNode.parentNode, 'bc-1'); - jsOMS.removeClass(box, 'vh'); - }); -}); - -nodes = document.querySelectorAll('.b > h1 .min, .b > h2 .min'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - var box = jsOMS.getByClass(e.parentNode.parentNode, 'bc-1'); - jsOMS.addClass(box, 'vh'); - }); -}); -/* - * Handle global min/max logic. - * This switches min/max visibility on click. - */ -var nodes = document.getElementsByClassName('min'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - jsOMS.addClass(e, 'vh'); - jsOMS.removeClass(jsOMS.getByClass(e.parentNode, 'max'), 'vh'); - }); -}); - -nodes = document.getElementsByClassName('max'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - jsOMS.addClass(e, 'vh'); - jsOMS.removeClass(jsOMS.getByClass(e.parentNode, 'min'), 'vh'); - }); -}); - -/* - * Handle global dim - * This allows to activate and deactivate the background dim on certain elements/classes - */ -/* Deactivate dim if click on class .close or .save */ -var dim = document.getElementById('dim'); -nodes = document.querySelectorAll('.close, .save'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - jsOMS.addClass(e.parentNode.parentNode.parentNode, 'vh'); - - jsOMS.addClass(dim, 'vh') - }); -}); - -/* Activate dim if click on element with class dim */ -nodes = document.getElementsByClassName('dim'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - jsOMS.removeClass(dim, 'vh') - }); -}); -/* - * Handle special case link and button clicks. - * This is usefull in order to support ajax calls and dynamic page changes without reloads - */ -var nodes = document.querySelectorAll('a, button, input[type=submit]'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - if (!e.hasAttribute('data-request') || !e.hasAttribute('data-http')) { - return true; - } - - // TODO: create request object - - var requestType = e.getAttribute('data-request'), - httpType = e.getAttribute('data-http'), - requestUri = '', - requestData = e.getAttribute('data-json'); - - if (requestType === 'URL') { - requestUri = e.getAttribute('href'); - } else { - requestUri = e.getAttribute('data-uri'); - } - - jsOMS.ajax({ - type: httpType, - url: URL + requestUri, - data: requestData, - requestHeader: "application/json; charset=utf-8", - responseType: "text", - success: function (ret) { - console.log(ret); - }, - error: function (ret) { - console.log('error'); - } - }); - - evt.preventDefault(); - return false; - }); -}); -/* Handling minimizing */ -var nodes = document.querySelectorAll('thead .min'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - var body = jsOMS.getByTag(e.parentNode.parentNode.parentNode.parentNode, 'tbody'); - jsOMS.addClass(body[0], 'vh'); - }); -}); - -/* Handling maximizing */ -nodes = document.querySelectorAll('thead .max'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - var body = jsOMS.getByTag(e.parentNode.parentNode.parentNode.parentNode, 'tbody'); - jsOMS.removeClass(body[0], 'vh'); - }); -}); - -/* Handling header element click */ -nodes = document.querySelectorAll('thead span'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - var filter = e.parentNode.childNodes[4]; - - if (jsOMS.hasClass(filter, 'vh')) { - jsOMS.removeClass(filter, 'vh'); - jsOMS.removeClass(e.parentNode.childNodes[1], 'vh'); - } - }); -}); - -/* Handling sort click */ -nodes = document.querySelectorAll('thead td :nth-child(2)'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - jsOMS.addClass(e, 'vh'); - jsOMS.removeClass(e.parentNode.childNodes[2], 'vh'); - }); -}); - -/* Handling sort click */ -nodes = document.querySelectorAll('thead td :nth-child(3)'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - jsOMS.addClass(e, 'vh'); - jsOMS.removeClass(e.parentNode.childNodes[3], 'vh'); - }); -}); - -/* Handling sort click */ -nodes = document.querySelectorAll('thead td :nth-child(4)'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - jsOMS.addClass(e, 'vh'); - jsOMS.removeClass(e.parentNode.childNodes[1], 'vh'); - }); -}); - -/* Handling sort close click */ -nodes = document.querySelectorAll('thead td :nth-child(5)'); -jsOMS.each(nodes, function (ele) { - jsOMS.listenEvent(ele, 'click', function (evt, e) { - var iParent = e.parentNode; - jsOMS.addClass(iParent.childNodes[1], 'vh'); - jsOMS.addClass(iParent.childNodes[2], 'vh'); - jsOMS.addClass(iParent.childNodes[3], 'vh'); - jsOMS.addClass(iParent.childNodes[4], 'vh'); - }); -}); - -/* Handling filter view (creating and saving data) */ -var list_filter_arr = [ - [] -]; - -nodes = document.querySelectorAll('thead .f'); -jsOMS.each(nodes, function (ele) { - var c = 0; - - jsOMS.listenEvent(ele, 'click', function (evt, e) { - var table = e.parentNode.parentNode.parentNode.childNodes[2], - filter = document.getElementById('t-f'), - flist = document.querySelectorAll('#tf ul'); - - jsOMS.empty(flist); - - var titles = jsOMS.getByTag(table, 'td'); - - jsOMS.each(titles, function (t) { - c++; - - var val = '', - tid = e.parentNode.parentNode.parentNode.parentNode.getAttribute('id'); - - if ((tid in list_filter_arr) && ('i-' + c in list_filter_arr[tid])) { - val = list_filter_arr[tid]['i-' + c]; - } - - /* Still not working */ - flist.innerHTML += '
  • ' + '
  • '; - }); - - jsOMS.removeClass(filter, 'vh'); - }); -}); -var formValidationMessage = function (data) { - var form = document.getElementById(data.form), - eEles = document.getElementsByClassName('i-' + data.form); - - while (eEles.length > 0) { - eEles[0].parentNode.removeChild(eEles[0]); - } - - data.errors.forEach(function (error) { - var eEle = document.getElementById(error.id), - msgEle = document.createElement('i'), - msg = document.createTextNode(error.msg); - - msgEle.id = 'i-' + error.id; - msgEle.class = 'i-' + data.form; - msgEle.appendChild(msg); - eEle.parentNode.insertBefore(msgEle, eEle.nextSibling); - }); -}; -var notifyMessage = function (data) { - setTimeout(function () { - var notify = document.createElement('div'), - h = document.createElement('h1'), - inner = document.createElement('div'), - title = document.createTextNode(data.title), - content = document.createTextNode(data.content); - - notify.id = 'notify'; - notify.class = data.level; - h.appendChild(title); - inner.appendChild(content); - notify.appendChild(h); - notify.appendChild(inner); - - if (data.stay > 0) { - setTimeout(function () { - notify.parentElement.removeChild(notify); - }, data.stay); - } - }, parseInt(data.delay)); -}; -(function (jsOMS, undefined) { - jsOMS.EnumNotifyType = Object.freeze({ - BINARY: 0, - INFO: 1, - WARNING: 2, - ERROR: 3, - FATAL: 4 - }); -}(window.jsOMS = window.jsOMS || {})); -var redirectMessage = function (data) { - setTimeout(function () { - document.location.href = data.url; - }, parseInt(data.delay)); -}; -var reloadMessage = function (data) { - setTimeout(function () { - document.location.reload(true); - }, parseInt(data.delay)); -};