Merge pull request #2 from Orange-Management/restructure-1

Restructure 1
This commit is contained in:
Dennis Eichhorn 2016-04-09 13:35:33 +02:00
commit 5c0b920993
43 changed files with 1040 additions and 665 deletions

View File

@ -9,6 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.Account');
/** /**
* @constructor * @constructor
@ -16,7 +17,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.AccountManager = function () jsOMS.Account.AccountManager = function ()
{ {
this.accounts = []; this.accounts = [];
}; };
@ -31,7 +32,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.AccountManager.prototype.add = function (account) jsOMS.Account.AccountManager.prototype.add = function (account)
{ {
this.accounts[account.getId()] = account; this.accounts[account.getId()] = account;
}; };
@ -46,7 +47,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.AccountManager.prototype.remove = function (id) jsOMS.Account.AccountManager.prototype.remove = function (id)
{ {
if (typeof this.accounts[id] !== 'undefined') { if (typeof this.accounts[id] !== 'undefined') {
delete this.accounts[id]; delete this.accounts[id];
@ -69,7 +70,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.AccountManager.prototype.get = function (id) jsOMS.Account.AccountManager.prototype.get = function (id)
{ {
if (this.accounts[id]) { if (this.accounts[id]) {
return this.accounts[id]; return this.accounts[id];

View File

@ -9,7 +9,9 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.EnumAccountType = Object.freeze({ jsOMS.Autoloader.defineNamespace('jsOMS.Account');
jsOMS.Account.AccountType = Object.freeze({
USER: 0, USER: 0,
GROUP: 1 GROUP: 1
}); });

View File

@ -9,6 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.Asset');
/** /**
* @constructor * @constructor
@ -16,7 +17,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.AssetManager = function () jsOMS.Asset.AssetManager = function ()
{ {
this.assets = {}; this.assets = {};
}; };
@ -36,7 +37,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.AssetManager.prototype.load = function (path, filename, filetype, callback) jsOMS.Asset.AssetManager.prototype.load = function (path, filename, filetype, callback)
{ {
var hash; var hash;
@ -102,7 +103,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.AssetManager.prototype.get = function (id) jsOMS.Asset.AssetManager.prototype.get = function (id)
{ {
if (this.assets[id]) { if (this.assets[id]) {
return this.assets[id]; return this.assets[id];
@ -123,7 +124,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.AssetManager.prototype.remove = function (key) jsOMS.Asset.AssetManager.prototype.remove = function (key)
{ {
if (typeof this.assets[key] !== 'undefined') { if (typeof this.assets[key] !== 'undefined') {
delete this.assets[key]; delete this.assets[key];

View File

@ -9,6 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.Auth');
/** /**
* @constructor * @constructor
@ -16,7 +17,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Auth = function (uri) jsOMS.Auth.Auth = function (uri)
{ {
this.account = null; this.account = null;
this.uri = uri; this.uri = uri;
@ -32,7 +33,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Auth.prototype.setAccount = function (account) jsOMS.Auth.Auth.prototype.setAccount = function (account)
{ {
this.account = account; this.account = account;
}; };
@ -47,7 +48,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Auth.prototype.getAccount = function () jsOMS.Auth.Auth.prototype.getAccount = function ()
{ {
return this.account; return this.account;
}; };
@ -60,12 +61,12 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Auth.prototype.login = function () jsOMS.Auth.Auth.prototype.login = function ()
{ {
var authRequest = new jsOMS.Request(); var authRequest = new jsOMS.Message.Request.Request();
authRequest.setUri(this.uri); authRequest.setUri(this.uri);
authRequest.setMethod(jsOMS.EnumRequestMethod.POST); authRequest.setMethod(jsOMS.Message.Request.RequestMethod.POST);
authRequest.setResponseType(jsOMS.EnumRequestType.JSON); authRequest.setResponseType(jsOMS.Message.Request.RequestType.JSON);
authRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); authRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
authRequest.setSuccess(function (xhr) authRequest.setSuccess(function (xhr)
{ {
@ -83,7 +84,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Auth.prototype.logout = function () jsOMS.Auth.Auth.prototype.logout = function ()
{ {
location.reload(); location.reload();
}; };
@ -96,7 +97,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Auth.prototype.loginResult = function (xhr) jsOMS.Auth.Auth.prototype.loginResult = function (xhr)
{ {
console.log(xhr); console.log(xhr);
location.reload(); location.reload();

60
Autoloader.js Normal file
View File

@ -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 || {}));

View File

@ -9,6 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.Config');
/** /**
* @constructor * @constructor
@ -16,7 +17,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Options = function () jsOMS.Config.Options = function ()
{ {
this.options = {}; this.options = {};
}; };
@ -35,7 +36,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Options.prototype.set = function (key, value, overwrite) jsOMS.Config.Options.prototype.set = function (key, value, overwrite)
{ {
overwrite = typeof overwrite === bool ? overwrite : true; overwrite = typeof overwrite === bool ? overwrite : true;
@ -60,7 +61,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Options.prototype.get = function (key) jsOMS.Config.Options.prototype.get = function (key)
{ {
if (typeof this.options[key] !== 'undefined') { if (typeof this.options[key] !== 'undefined') {
return this.options[key]; return this.options[key];
@ -81,7 +82,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Options.prototype.remove = function (key) jsOMS.Config.Options.prototype.remove = function (key)
{ {
if (typeof this.options[key] !== 'undefined') { if (typeof this.options[key] !== 'undefined') {
delete this.options[key]; delete this.options[key];

View File

@ -1,6 +1,8 @@
(function (jsOMS, undefined) { (function (jsOMS, undefined) {
jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage');
// TODO: create comments // TODO: create comments
jsOMS.CacheManager = function () jsOMS.DataStorage.CacheManager = function ()
{ {
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -9,6 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage');
/** /**
* @constructor * @constructor
@ -16,7 +17,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.CookieJar = function () jsOMS.DataStorage.CookieJar = function ()
{ {
}; };
@ -36,7 +37,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
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(); var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays); exdate.setDate(exdate.getDate() + exdays);
@ -56,7 +57,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.CookieJar.prototype.getCookie = function (cName) jsOMS.DataStorage.CookieJar.prototype.getCookie = function (cName)
{ {
var cValue = document.cookie; var cValue = document.cookie;
var cStart = cValue.indexOf(" " + cName + "="); var cStart = cValue.indexOf(" " + cName + "=");

View File

@ -9,6 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage');
/** /**
* @constructor * @constructor
@ -16,7 +17,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.LocalStorage = function () jsOMS.DataStorage.LocalStorage = function ()
{ {
}; };
@ -30,7 +31,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.LocalStorage.prototype.available = function () jsOMS.DataStorage.LocalStorage.prototype.available = function ()
{ {
try { try {
return 'localStorage' in window && window.localStorage !== null; return 'localStorage' in window && window.localStorage !== null;

View File

@ -1,5 +1,7 @@
(function (jsOMS, undefined) { (function (jsOMS, undefined) {
jsOMS.StorageManager = function () jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage');
jsOMS.DataStorage.StorageManager = function ()
{ {
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -1,5 +1,7 @@
(function (jsOMS, undefined) { (function (jsOMS, undefined) {
jsOMS.Dispatcher = function () jsOMS.Autoloader.defineNamespace('jsOMS.Dispatcher');
jsOMS.Dispatcher.Dispatcher = function ()
{ {
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -1,4 +1,6 @@
(function (jsOMS, undefined) { (function (jsOMS, undefined) {
jsOMS.EventManager = function () { jsOMS.Autoloader.defineNamespace('jsOMS.Event');
jsOMS.Event.EventManager = function () {
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

24
Log/LogLevel.enum.js Normal file
View File

@ -0,0 +1,24 @@
/**
* Log Level enum.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined)
{
jsOMS.Autoloader.defineNamespace('jsOMS.Log');
jsOMS.Log.LogLevel = Object.freeze({
EMERGENCY: 'emergency',
ALERT: 'alert',
CRITICAL: 'critical',
ERROR: 'error',
WARNING: 'warning',
NOTICE: 'notice',
INFO: 'info',
DEBUG: 'debug'
});
}(window.jsOMS = window.jsOMS || {}));

147
Log/Logger.js Normal file
View File

@ -0,0 +1,147 @@
/**
* Logger class.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined)
{
"use strict";
jsOMS.Autoloader.defineNamespace('jsOMS.Log');
/**
* @constructor
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Log.Logger = function (verbose, ui, remote)
{
this.verbose = typeof verbose !== 'undefined' ? verbose : true;
this.ui = typeof ui !== 'undefined' ? ui : true;
this.remote = typeof remote !== 'undefined' ? remote : false;
};
jsOMS.Log.Logger.layout = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}';
jsOMS.Log.Logger.prototype.interpolate = function(message, context, level)
{
let newMessage = jsOMS.Log.Logger.layout;
for(let replace in context) {
newMessage = newMessage.replace('{'+replace+'}', context[replace]);
}
return newMessage;
};
jsOMS.Log.Logger.prototype.createContext = function(message, context, level)
{
context['datetime'] = (new Date()).toISOString();
context['version'] = '1.0.0';
context['os'] = jsOMS.Message.Request.Request.getOS();
context['browser'] = jsOMS.Message.Request.Request.getBrowser();
context['path'] = window.location.href;
context['level'] = level;
context['message'] = message;
return context;
}
jsOMS.Log.Logger.prototype.write = function(message, context, level)
{
context = this.createContext(message, context, level);
if(this.verbose) {
console.log('%c' + this.interpolate(message, context, level), 'color: #FFA600');
}
if(this.ui) {
// todo: fill log box, set class and initiate animation
}
if(this.remote) {
let request = new jsOMS.Message.Request.Request();
request.setData(context);
request.setType(jsOMS.Message.Response.Response.ResponseType.JSON);
request.setUri('/{/lang}/api/log');
request.setMethod(jsOMS.Message.Request.Request.RequestMethod.POST);
request.setRequestHeader('Content-Type', 'application/json');
request.setSuccess(function (xhr) {});
request.send();
}
};
jsOMS.Log.Logger.prototype.emergency = function(message, context)
{
context = typeof context === 'undefined' ? {} : context;
this.write(message, context, jsOMS.Log.LogLevel.EMERGENCY)
};
jsOMS.Log.Logger.prototype.alert = function(message, context)
{
context = typeof context === 'undefined' ? {} : context;
this.write(message, context, jsOMS.Log.LogLevel.ALERT)
};
jsOMS.Log.Logger.prototype.critical = function(message, context)
{
context = typeof context === 'undefined' ? {} : context;
this.write(message, context, jsOMS.Log.LogLevel.CRITICAL)
};
jsOMS.Log.Logger.prototype.error = function(message, context)
{
context = typeof context === 'undefined' ? {} : context;
this.write(message, context, jsOMS.Log.LogLevel.ERROR)
};
jsOMS.Log.Logger.prototype.warning = function(message, context)
{
context = typeof context === 'undefined' ? {} : context;
this.write(message, context, jsOMS.Log.LogLevel.WARNING)
};
jsOMS.Log.Logger.prototype.notice = function(message, context)
{
context = typeof context === 'undefined' ? {} : context;
this.write(message, context, jsOMS.Log.LogLevel.NOTICE)
};
jsOMS.Log.Logger.prototype.info = function(message, context)
{
context = typeof context === 'undefined' ? {} : context;
this.write(message, context, jsOMS.Log.LogLevel.INFO)
};
jsOMS.Log.Logger.prototype.debug = function(message, context)
{
context = typeof context === 'undefined' ? {} : context;
this.write(message, context, jsOMS.Log.LogLevel.DEBUG)
};
jsOMS.Log.Logger.prototype.log = function(level, message, context)
{
context = typeof context === 'undefined' ? {} : context;
this.write(message, context, context)
};
jsOMS.Log.Logger.prototype.console = function(level, message, context)
{
context = typeof context === 'undefined' ? {} : context;
this.write(message, context, jsOMS.Log.LogLevel.INFO)
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -0,0 +1,23 @@
/**
* Request data enum.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined)
{
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request');
jsOMS.Message.Request.BrowserType = Object.freeze({
OPERA: 'opera',
FIREFOX: 'firefox',
SAFARI: 'safari',
IE: 'msie',
EDGE: 'edge',
CHROME: 'chrome',
BLINK: 'blink',
});
}(window.jsOMS = window.jsOMS || {}));

View File

@ -0,0 +1,39 @@
/**
* Request data enum.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined)
{
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request');
jsOMS.Message.Request.OSType = Object.freeze({
WINDOWS_81: 'windows nt 6.3', /* Windows 8.1 */
WINDOWS_8: 'windows nt 6.2', /* Windows 8 */
WINDOWS_7: 'windows nt 6.1', /* Windows 7 */
WINDOWS_VISTA: 'windows nt 6.0', /* Windows Vista */
WINDOWS_SERVER: 'windows nt 5.2', /* Windows Server 2003/XP x64 */
WINDOWS_XP: 'windows nt 5.1', /* Windows XP */
WINDOWS_XP_2: 'windows xp', /* Windows XP */
WINDOWS_2000: 'windows nt 5.0', /* Windows 2000 */
WINDOWS_ME: 'windows me', /* Windows ME */
WINDOWS_98: 'win98', /* Windows 98 */
WINDOWS_95: 'win95', /* Windows 95 */
WINDOWS_311: 'win16', /* Windows 3.11 */
MAC_OS_X: 'macintosh', /* Mac OS X */
MAC_OS_X_2: 'mac os x', /* Mac OS X */
MAC_OS_9: 'mac_powerpc', /* Mac OS 9 */
LINUX : 'linux', /* Linux */
UBUNTU: 'ubuntu', /* Ubuntu */
IPHONE: 'iphone', /* IPhone */
IPOD: 'ipod', /* IPod */
IPAD: 'ipad', /* IPad */
ANDROID: 'android', /* Android */
BLACKBERRY: 'blackberry', /* Blackberry */
MOBILE: 'webos' /* Mobile */
});
}(window.jsOMS = window.jsOMS || {}));

View File

@ -9,6 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request');
/** /**
* @constructor * @constructor
@ -16,18 +17,48 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request = function () jsOMS.Message.Request.Request = function (uri, method, type)
{ {
this.uri = null; this.uri = typeof uri !== 'undefined' ? uri : null;
this.method = null; this.method = typeof method !== 'undefined' ? method : jsOMS.Message.Request.RequestMethod.GET;
this.requestHeader = []; this.requestHeader = [];
this.success = null; this.success = null;
this.type = jsOMS.EnumRequestMethod.GET; this.type = typeof type !== 'undefined' ? type : jsOMS.Message.Response.ResponseType.JSON;
this.data = {}; this.data = {};
this.xhr = new XMLHttpRequest(); this.xhr = new XMLHttpRequest();
}; };
jsOMS.Message.Request.Request.getBrowser = function()
{
if((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) {
return jsOMS.Message.Request.BrowserType.OPERA;
} else if(typeof InstallTrigger !== 'undefined') {
return jsOMS.Message.Request.BrowserType.FIREFOX;
} else if(Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0) {
return jsOMS.Message.Request.BrowserType.SAFARI;
} else if(/*@cc_on!@*/false || !!document.documentMode) {
return jsOMS.Message.Request.BrowserType.IE;
} else if(!!window.StyleMedia) {
return jsOMS.Message.Request.BrowserType.EDGE;
} else if(!!window.chrome && !!window.chrome.webstore) {
return jsOMS.Message.Request.BrowserType.CHROME;
} else if((isChrome || isOpera) && !!window.CSS) {
return jsOMS.Message.Request.BrowserType.BLINK;
}
};
jsOMS.Message.Request.Request.getOS = function()
{
for(let os in jsOMS.Message.Request.OSType) {
if(navigator.appVersion.toLowerCase().indexOf(jsOMS.Message.Request.OSType[os]) !== -1) {
return jsOMS.Message.Request.OSType[os];
}
}
};
/** /**
* Set request method. * Set request method.
* *
@ -40,7 +71,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.setMethod = function (method) jsOMS.Message.Request.Request.prototype.setMethod = function (method)
{ {
this.method = method; this.method = method;
}; };
@ -57,7 +88,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.getMethod = function () jsOMS.Message.Request.Request.prototype.getMethod = function ()
{ {
return this.method; return this.method;
}; };
@ -74,7 +105,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.setResponseType = function (type) jsOMS.Message.Request.Request.prototype.setResponseType = function (type)
{ {
this.xhr.responseType = type; this.xhr.responseType = type;
}; };
@ -91,7 +122,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.getResponseType = function () jsOMS.Message.Request.Request.prototype.getResponseType = function ()
{ {
return this.responseType; return this.responseType;
}; };
@ -107,7 +138,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.setRequestHeader = function (type, header) jsOMS.Message.Request.Request.prototype.setRequestHeader = function (type, header)
{ {
this.requestHeader[type] = header; this.requestHeader[type] = header;
}; };
@ -122,7 +153,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.getRequestHeader = function () jsOMS.Message.Request.Request.prototype.getRequestHeader = function ()
{ {
return this.requestHeader; return this.requestHeader;
}; };
@ -137,7 +168,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.setUri = function (uri) jsOMS.Message.Request.Request.prototype.setUri = function (uri)
{ {
this.uri = uri; this.uri = uri;
}; };
@ -152,7 +183,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.getUri = function () jsOMS.Message.Request.Request.prototype.getUri = function ()
{ {
return this.uri; return this.uri;
}; };
@ -167,7 +198,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.setSuccess = function (callback) jsOMS.Message.Request.Request.prototype.setSuccess = function (callback)
{ {
this.success = callback; this.success = callback;
}; };
@ -182,7 +213,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.setData = function (data) jsOMS.Message.Request.Request.prototype.setData = function (data)
{ {
this.data = data; this.data = data;
}; };
@ -197,7 +228,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.getData = function () jsOMS.Message.Request.Request.prototype.getData = function ()
{ {
return this.data return this.data
}; };
@ -214,7 +245,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.setType = function (type) jsOMS.Message.Request.Request.prototype.setType = function (type)
{ {
this.type = type; this.type = type;
}; };
@ -231,7 +262,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.getType = function () jsOMS.Message.Request.Request.prototype.getType = function ()
{ {
return this.type; return this.type;
}; };
@ -246,10 +277,10 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.queryfy = function (obj) jsOMS.Message.Request.Request.prototype.queryfy = function (obj)
{ {
var str = []; let str = [];
for (var p in obj) { for (let p in obj) {
if (obj.hasOwnProperty(p)) { if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
} }
@ -267,14 +298,14 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.Request.prototype.send = function () jsOMS.Message.Request.Request.prototype.send = function ()
{ {
var self = this; let self = this;
if (self.xhr.readyState !== 1) { if (self.xhr.readyState !== 1) {
self.xhr.open(this.method, this.uri); self.xhr.open(this.method, jsOMS.Uri.UriFactory.build(this.uri));
for (var p in this.requestHeader) { for (let p in this.requestHeader) {
if (this.requestHeader.hasOwnProperty(p)) { if (this.requestHeader.hasOwnProperty(p)) {
self.xhr.setRequestHeader(p, this.requestHeader[p]); self.xhr.setRequestHeader(p, this.requestHeader[p]);
} }
@ -288,14 +319,14 @@
} }
}; };
if (this.type === jsOMS.EnumRequestType.JSON) { if (this.type === jsOMS.Message.Request.RequestType.JSON) {
if (typeof this.requestHeader !== 'undefined' && this.requestHeader['Content-Type'] === 'application/json') { if (typeof this.requestHeader !== 'undefined' && this.requestHeader['Content-Type'] === 'application/json') {
console.log(JSON.stringify(this.data)); console.log(JSON.stringify(this.data));
self.xhr.send(JSON.stringify(this.data)); self.xhr.send(JSON.stringify(this.data));
} else { } else {
self.xhr.send(this.queryfy(this.data)); 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); self.xhr.send(this.data);
} }
}; };

View File

@ -9,7 +9,9 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.EnumLinkRequestData = Object.freeze({ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request');
jsOMS.Message.RequestLinkRequestData = Object.freeze({
NORMAL: 'normal', NORMAL: 'normal',
OBJECT: 'object' OBJECT: 'object'
}); });

View File

@ -11,6 +11,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request');
/** /**
* @constructor * @constructor
@ -18,7 +19,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.RequestManager = function () jsOMS.Message.Request.RequestManager = function ()
{ {
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -9,7 +9,9 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.EnumRequestMethod = Object.freeze({ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request');
jsOMS.Message.Request.RequestMethod = Object.freeze({
POST: 'POST', POST: 'POST',
GET: 'GET', GET: 'GET',
PUT: 'PUT', PUT: 'PUT',

View File

@ -9,7 +9,9 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.EnumRequestType = Object.freeze({ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request');
jsOMS.Message.Request.RequestType = Object.freeze({
JSON: 'json', JSON: 'json',
RAW: 'raw' RAW: 'raw'
}); });

View File

@ -0,0 +1,23 @@
(function (uriFactory, undefined) {
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response');
jsOMS.Message.Response.Response = function (data) {
this.responses = data;
};
jsOMS.Message.Response.Response.prototype.get = function(id)
{
return this.responses[id];
};
jsOMS.Message.Response.Response.prototype.getByIndex = function(index)
{
//return this.responses[Object.keys(this.responses).sort()[index]];
return this.responses;
};
jsOMS.Message.Response.Response.prototype.count = function()
{
return 1;
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -11,6 +11,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response');
/** /**
* @constructor * @constructor
@ -18,7 +19,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.ResponseManager = function () jsOMS.Message.Response.ResponseManager = function ()
{ {
this.messages = {}; this.messages = {};
}; };
@ -37,7 +38,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.ResponseManager.prototype.add = function (key, message, request) jsOMS.Message.Response.ResponseManager.prototype.add = function (key, message, request)
{ {
request = typeof request !== 'undefined' ? request : 'any'; request = typeof request !== 'undefined' ? request : 'any';
if (typeof this.messages[key] === 'undefined') { if (typeof this.messages[key] === 'undefined') {
@ -61,7 +62,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.ResponseManager.prototype.execute = function (key, data, request) jsOMS.Message.Response.ResponseManager.prototype.run = function (key, data, request)
{ {
console.log(data); console.log(data);
if (typeof request !== 'undefined' && typeof this.messages[key][request] !== 'undefined') { if (typeof request !== 'undefined' && typeof this.messages[key][request] !== 'undefined') {

View File

@ -9,7 +9,9 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.EnumResponseResultType = Object.freeze({ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response');
jsOMS.Message.Response.ResponseResultType = Object.freeze({
MULTI: 0, MULTI: 0,
MESSAGE: 1, MESSAGE: 1,
INFO: 2, INFO: 2,

View File

@ -9,7 +9,9 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.EnumResponseType = Object.freeze({ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response');
jsOMS.Message.Response.ResponseType = Object.freeze({
TEXT: 'text', TEXT: 'text',
JSON: 'json', JSON: 'json',
DOCUMENT: 'document', DOCUMENT: 'document',

View File

@ -9,6 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.Module');
/** /**
* @constructor * @constructor
@ -16,7 +17,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.ModuleFactory = function () jsOMS.Module.ModuleFactory = function ()
{ {
}; };
@ -33,7 +34,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.ModuleFactory.getInstance = function (module, app) jsOMS.Module.ModuleFactory.getInstance = function (module, app)
{ {
return new window['jsOMS']['Modules'][module](app); return new window['jsOMS']['Modules'][module](app);
}; };

View File

@ -9,8 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Modules = {}; jsOMS.Autoloader.defineNamespace('jsOMS.Module');
jsOMS.Modules.Models = {};
/** /**
* @constructor * @constructor
@ -18,7 +17,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.ModuleManager = function (app) jsOMS.Module.ModuleManager = function (app)
{ {
this.modules = {}; this.modules = {};
this.app = app; this.app = app;
@ -36,7 +35,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.ModuleManager.prototype.get = function (module) jsOMS.Module.ModuleManager.prototype.get = function (module)
{ {
if (this.modules[module] === undefined) { if (this.modules[module] === undefined) {
this.modules[module] = jsOMS.ModuleFactory.getInstance(module, this.app); this.modules[module] = jsOMS.ModuleFactory.getInstance(module, this.app);

View File

@ -1,6 +1,8 @@
(function (jsOMS, undefined) { (function (jsOMS, undefined) {
jsOMS.Autoloader.defineNamespace('jsOMS.Route');
// TODO: create comments // TODO: create comments
jsOMS.Route = function () jsOMS.Route.Route = function ()
{ {
this.routes = null; this.routes = null;
}; };

View File

@ -7,9 +7,9 @@
* @license OMS License 1.0 * @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0 * @version 1.0.0 * @since 1.0.0
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
"use strict"; jsOMS.Autoloader.defineNamespace('jsOMS.UI');
/** /**
* @constructor * @constructor
@ -17,51 +17,73 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.FormManager = function (responseManager) jsOMS.UI.FormManager = function(app)
{ {
this.responseManager = responseManager; this.app = app;
this.ignore = []; this.forms = {};
this.success = []; this.ignore = {};
this.injectSelector = [];
this.forms = [];
}; };
/** jsOMS.UI.FormManager.prototype.get = function(id)
* Ignore form from handling.
*
* @param {string} [id] Form id
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.FormManager.prototype.ignore = function (id)
{ {
this.ignore.push(id); return this.forms[id];
}; };
/** jsOMS.UI.FormManager.prototype.isIgnored = function(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 <d.eichhorn@oms.com>
*/
jsOMS.FormManager.prototype.injectSubmit = function (selector, callback)
{ {
if (!(selector in this.injectSelector)) { return this.ignore.indexOf(id) !== -1;
this.injectSelector[selector] = callback; };
jsOMS.UI.FormManager.prototype.unbind = function(id)
{
};
jsOMS.UI.FormManager.prototype.bind = function(id)
{
if (typeof id !== 'undefined' && typeof this.ignore[id] === 'undefined') {
this.bindForm(id)
} else {
let forms = document.getElementsByTagName('form'),
length = forms.length;
for (var i = 0; i < length; i++) {
if (typeof this.ignore[forms[i].id] === 'undefined') {
this.bindForm(forms[i].id);
}
}
}
};
jsOMS.UI.FormManager.prototype.bindForm = function(id)
{
if(typeof id === 'undefined' || !id) {
this.app.logger.info('A form doesn\'t have an ID.');
return;
}
let self = this;
this.unbind(id);
if(typeof this.ignore[id] === 'undefined') {
this.forms[id] = new jsOMS.Views.FormView(id);
}
this.forms[id].getSubmit().addEventListener('click', function(event) {
self.submit(self.forms[id]);
jsOMS.preventAll(event);
});
};
jsOMS.UI.FormManager.prototype.unbindForm = function(id)
{
// todo: do i need the findex? can't i just use id?
let findex = 0;
if((findex = this.forms[id]) !== 'undefined') {
this.forms[id].unbind();
this.forms.splice(findex, 1);
return true; return true;
} }
@ -69,120 +91,45 @@
return false; return false;
}; };
/** jsOMS.UI.FormManager.prototype.submit = function(form)
* Set success callback for form.
*
* @param {string} id Form id
* @param {requestCallback} callback Callback for success
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.FormManager.prototype.setSuccess = function (id, callback)
{ {
this.success[id] = callback; /* Handle injects */
}; let injects = form.getSubmitInjects();
for(let property in injects) {
/** property();
* Bind form.
*
* @param {string} [id] Form id
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
jsOMS.FormManager.prototype.validateFormElement = function (e)
{
/** Validate on change */
if (typeof e.pattern !== 'undefined') {
if (!(new RegExp(e.pattern)).test(e.value)) {
return false;
}
} }
return true; /* Handle default submit */
}; let request = new jsOMS.Message.Request.Request(),
self = this;
/** request.setData(form.getData());
* Submit data. request.setType(jsOMS.Message.Response.ResponseType.JSON);
* request.setUri(form.getAction());
* @param {Object} e Form element request.setMethod(form.getMethod());
* @param {Object} data Data to submit
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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.setRequestHeader('Content-Type', 'application/json');
request.setSuccess(function (xhr) request.setSuccess(function (xhr)
{ {
console.log(xhr); // TODO: remove this is for error checking
try { try {
var o = JSON.parse(xhr.response), let o = JSON.parse(xhr.response),
response = Object.keys(o).map(function (k) response = new jsOMS.Message.Response.Response(o),
{ responseLength = response.count(),
return o[k] tempResponse = null,
}); success = null;
for (var k = 0; k < response.length; k++) { /* Handle responses (can be multiple response object) */
if (response[k] !== null) { for (let k = 0; k < responseLength; k++) {
console.log(response[k]); tempResponse = response.getByIndex(k);
/* Handle success */ if((success = form.getSuccess()) !== null) {
if (!self.success[e.id]) { success(tempResponse);
self.responseManager.execute(response[k].type, response[k]); } else {
} else { self.app.responseManager.run(tempResponse.type, tempResponse, request);
self.success[e.id](response[k].type, response[k]);
}
} }
} }
} catch (exception) { } catch (exception) {
console.log('No valid json'); self.app.logger.error('Invalid Login response: ' + JSON.stringify(xhr));
return false; return false;
} }
}); });
@ -190,241 +137,7 @@
request.send(); request.send();
}; };
/** jsOMS.UI.FormManager.prototype.count = function ()
* Collect all data associated with the form.
*
* @param {Object} e Form element
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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; return this.forms.length;
}; };

118
UI/Input.js Normal file
View File

@ -0,0 +1,118 @@
/**
* Form manager class.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0 * @since 1.0.0
*/
(function (jsOMS, undefined)
{
"use strict";
jsOMS.Autoloader.defineNamespace('jsOMS.UI');
/**
* @constructor
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.UI.Input.unbind = function(input)
{
this.app.inputManager.getKeyboardManager().unbind(input);
input.removeEventListener('change', changeBind, false);
};
jsOMS.UI.Input.bind = function(input)
{
let self = this;
input.addEventListener('change', function changeBind(event) {
/* Handle remote datalist/autocomplete input element */
let listId, list;
if(typeof (listId = this.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') {
self.addRemoteDatalistOptions(this, list);
}
/* Handle html defined functions */
let change;
if(typeof (change = this.getAttribute('data-change-func')) !== 'undefined') {
change(this);
}
/* Handle pre-defined dynamic change events */
let ref;
if(typeof (ref = this.getAttribute('data-ref')) !== 'undefined') {
let e = document.getElementById(ref);
switch(e.tagName) {
case 'ul':
break;
case 'table':
break;
};
}
});
let dataButton;
if(typeof (dataButton = input.getAttribute('data-button')) !== 'undefined') {
this.app.inputManager.getKeyboardManager().bind(input, 13, function() {
document.getElementById(dataButton).click();
});
}
};
jsOMS.UI.Input.addRemoteDatalistOptions = function(input, datalist)
{
this.clearDatalistOptions(datalist);
let request = new Request();
request.setData(input.value);
request.setType(jsOMS.Message.Response.ResponseType.JSON);
request.setUri(datalist.getAttribute('data-list-src'));
request.setMethod(jsOMS.Message.Request.RequestMethod.POST);
request.setRequestHeader('Content-Type', 'application/json');
request.setSuccess(function (xhr) {
try {
let o = JSON.parse(xhr.response),
response = new Response(o),
responseLength = response.count(),
tempResponse = null,
success = null;
for (let k = 0; k < responseLength; k++) {
tempResponse = response.getByIndex(k);
console.log(tempResponse);
let option = null,
data = tempResponse.getData(),
length = data.length;
for(let i = 0; i < length; i++) {
option = document.createElement('option');
option.value = tempResponse.value;
option.text = tempResponse.text;
datalist.appendChild(option);
}
}
} catch (exception) {
self.app.logger.error('Invalid JSON object: ' + xhr, 'FormManager')
return false;
}
});
request.send();
};
jsOMS.UI.Input.clearDatalistOptions = function(datalist)
{
let length = datalist.options.length,
i = 0;
for(i = 0; i < length; i++) {
datalist.remove(0);
}
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,5 +1,13 @@
(function (jsOMS, undefined) { (function (jsOMS, undefined) {
jsOMS.InputManager = function () jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input');
{
}; jsOMS.UI.Input.InputManager = function ()
{
this.keyBoardManager = new jsOMS.UI.Input.Keyboard.KeyboardManager();
};
jsOMS.UI.Input.InputManager.prototype.getKeyboardManager = function()
{
return this.keyBoardManager;
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -1,11 +1,22 @@
(function (jsOMS, undefined) { (function (jsOMS, undefined) {
jsOMS.KeyboardManager = function () jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Keyboard');
jsOMS.UI.Input.Keyboard.KeyboardManager = function ()
{ {
}; };
jsOMS.KeyboardManager.prototype.attach = function (element, keys, callback) { jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.bind = function (element, keys, callback)
{
element.addEventListener('keyup', function keyBind(event) {
if(event.keyCode === keys.keyCode) {
callback();
}
});
}; };
jsOMS.KeyboardManager.prototype.detach = function (eventId) { jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.unbind = function (element)
{
element.removeEventListener('keyup', keyBind, false);
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -1,41 +0,0 @@
/**
* Form manager class.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <d.eichhorn@oms.com>
*/
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;
}
};
}

0
UI/Select.js Normal file
View File

View File

@ -9,6 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.UI');
/** /**
* @constructor * @constructor
@ -16,7 +17,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.TabManager = function (responseManager) jsOMS.UI.TabManager = function (responseManager)
{ {
this.responseManager = responseManager; this.responseManager = responseManager;
}; };
@ -31,7 +32,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.TabManager.prototype.bind = function (id) jsOMS.UI.TabManager.prototype.bind = function (id)
{ {
if (typeof id !== 'undefined') { if (typeof id !== 'undefined') {
this.bindElement(document.getElementById(id)); this.bindElement(document.getElementById(id));
@ -54,7 +55,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.TabManager.prototype.bindElement = function (e) jsOMS.UI.TabManager.prototype.bindElement = function (e)
{ {
var nodes = e.querySelectorAll('.tab-links a'); var nodes = e.querySelectorAll('.tab-links a');

View File

@ -9,6 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.UI');
/** /**
* @constructor * @constructor
@ -16,7 +17,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.TableManager = function (responseManager) jsOMS.UI.TableManager = function (responseManager)
{ {
this.responseManager = responseManager; this.responseManager = responseManager;
}; };
@ -31,7 +32,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.TableManager.prototype.bind = function (id) jsOMS.UI.TableManager.prototype.bind = function (id)
{ {
if (typeof id !== 'undefined') { if (typeof id !== 'undefined') {
this.bindElement(document.getElementById(id)); this.bindElement(document.getElementById(id));
@ -54,7 +55,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.TableManager.prototype.bindElement = function (e) jsOMS.UI.TableManager.prototype.bindElement = function (e)
{ {
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -9,6 +9,7 @@
*/ */
(function (jsOMS, undefined) (function (jsOMS, undefined)
{ {
jsOMS.Autoloader.defineNamespace('jsOMS.UI');
/** /**
* @constructor * @constructor
@ -16,12 +17,12 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.UIManager = function (app) jsOMS.UI.UIManager = function (app)
{ {
this.app = app; this.app = app;
this.formManager = new jsOMS.FormManager(this.app.responseManager); this.formManager = new jsOMS.UI.FormManager(this.app);
this.tabManager = new jsOMS.TabManager(this.app.responseManager); this.tabManager = new jsOMS.UI.TabManager(this.app.responseManager);
this.tableManager = new jsOMS.TableManager(this.app.responseManager); this.tableManager = new jsOMS.UI.TableManager(this.app.responseManager);
}; };
/** /**
@ -34,22 +35,23 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.UIManager.prototype.bind = function (id) jsOMS.UI.UIManager.prototype.bind = function (id)
{ {
if (typeof id === 'undefined') { if (typeof id === 'undefined') {
this.formManager.bind(); this.formManager.bind();
this.tabManager.bind(); this.tabManager.bind();
this.tableManager.bind(); this.tableManager.bind();
} else { } else {
var tag = document.getElementById(id); let tag = document.getElementById(id);
if (tag.tagName === 'form') { switch(tag.tagName) {
this.formManager.bind(id); case 'form':
} else if (tag.tagName === 'table') { this.formManager.bind(id);
this.tableManager.bind(id); break;
} else if (tag.tagName === 'div') { case 'table':
// Todo: be more specific in order to handle tab this.tableManager.bind(id);
} break;
};
} }
}; };
@ -63,7 +65,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.UIManager.prototype.getFormManager = function () jsOMS.UI.UIManager.prototype.getFormManager = function ()
{ {
return this.formManager; return this.formManager;
}; };
@ -78,7 +80,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.UIManager.prototype.getTabManager = function () jsOMS.UI.UIManager.prototype.getTabManager = function ()
{ {
return this.tabManager; return this.tabManager;
}; };
@ -93,7 +95,7 @@
* @since 1.0.0 * @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com> * @author Dennis Eichhorn <d.eichhorn@oms.com>
*/ */
jsOMS.UIManager.prototype.getTableManager = function () jsOMS.UI.UIManager.prototype.getTableManager = function ()
{ {
return this.tabManager; return this.tabManager;
}; };

View File

@ -1,106 +0,0 @@
/**
* UI manager for handling basic ui elements.
*
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 <d.eichhorn@oms.com>
*/
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 || {}));

View File

@ -1,3 +1,110 @@
(function (uriFactory, undefined) { (function (uriFactory, undefined) {
jsOMS.Autoloader.defineNamespace('jsOMS.Uri.UriFactory');
jsOMS.Uri.UriFactory.parseUrl = function (str, component)
{
let query, key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port',
'relative', 'path', 'directory', 'file', 'query', 'fragment'
],
ini = {},
mode = 'php',
parser = {
php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this)
};
let m = parser[mode].exec(str),
uri = {},
i = 14;
while (i--) {
if (m[i]) {
uri[key[i]] = m[i];
}
}
if (component) {
return uri[component.replace('PHP_URL_', '').toLowerCase()];
}
if (mode !== 'php') {
let name = 'queryKey';
parser = /(?:^|&)([^&=]*)=?([^&]*)/g;
uri[name] = {};
query = uri[key[12]] || '';
query.replace(parser, function ($0, $1, $2)
{
if ($1) {
uri[name][$1] = $2;
}
});
}
delete uri.source;
return uri;
};
/**
* Get Uri query parameters.
*
* @param {string} query Uri query
* @param {string} name Name of the query to return
*
* @return {null|string}
*
* @method
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Uri.UriFactory.getUriQueryParameter = function (query, name)
{
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
let regex = new RegExp("[\\?&]*" + name + "=([^&#]*)"),
results = regex.exec(query);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
jsOMS.Uri.UriFactory.setQuery = function(key, value, overwrite)
{
overwrite = typeof overwrite !== 'undefined' ? overwrite : true;
if(overwrite || !jsOMS.Uri.UriFactory.uri.hasProperty(key)) {
jsOMS.Uri.UriFactory.uri[key] = value;
return true;
}
return false;
};
jsOMS.Uri.UriFactory.build = function(uri, toMatch)
{
let current = jsOMS.Uri.UriFactory.parseUrl(window.location.href);
// match(new RegExp("\{[#\?\.a-zA-Z0-9]*\}", "gi"));
return uri.replace('\{[\/#\?@\.\$][a-zA-Z0-9]*\}', function(match) {
match = substr(match[0], 1, match[0].length - 2);
if(toMatch.hasProperty(match)) {
return toMatch[match];
} else if(jsOMS.Uri.UriFactory.uri[match] !== 'undefined') {
return jsOMS.Uri.UriFactory.uri[match];
} else if (match.indexOf('#') === 0) {
return document.getElementById(match.substring(1, match.length)).value;
} else if(match.indexOf('?') === 0) {
return jsOMS.Uri.UriFactory.getUriQueryParameter(current.query, match.substring(1, match.length));
} else if(match.indexOf('/') === 0) {
// todo: second match should return second path
return 'ERROR PATH';
} else {
return match;
}
});
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -1,37 +1,161 @@
(function (jsOMS, undefined) { (function (jsOMS, undefined) {
"use strict"; "use strict";
jsOMS.Autoloader.defineNamespace('jsOMS.Views');
jsOMS.FormView = function (element) { jsOMS.Views.FormView = function (id) {
this.id = element.getAttribute('id'); this.id = id;
this.formElement = element;
this.inputElement = {}; this.initializeMembers();
this.textarea = {}; this.bind();
this.button = {}; this.success = null;
this.select = {};
}; };
jsOMS.FormView.prototype.bind = function() jsOMS.Views.FormView.prototype.initializeMembers = function()
{ {
this.bindInput(); this.submitInjects = {};
this.bindTextarea(); this.method = 'POST';
this.bindButton(); this.action = '';
this.bindSelect(); };
jsOMS.Views.FormView.prototype.getMethod = function()
{
return this.method;
};
jsOMS.Views.FormView.prototype.getAction = function()
{
return this.action;
};
jsOMS.Views.FormView.prototype.getSubmit = function()
{
return document.getElementById(this.id).querySelectorAll('input[type=submit]')[0];
};
jsOMS.Views.FormView.prototype.getSuccess = function()
{
return this.success;
};
jsOMS.Views.FormView.prototype.setSuccess = function(callback)
{
this.success = callback;
};
jsOMS.Views.FormView.prototype.injectSubmit = function(id, callback)
{
this.submitInjects[id] = callback;
};
jsOMS.Views.FormView.prototype.getFormElements = function(id)
{
let form = document.getElementById(id),
selects = form.getElementsByTagName('select'),
textareas = form.getElementsByTagName('textarea'),
inputs = form.getElementsByTagName('input'),
external = document.querySelectorAll('[form='+id+']'),
elements = Array.prototype.slice.call(inputs).concat(Array.prototype.slice.call(selects), Array.prototype.slice.call(textareas), Array.prototype.slice.call(external)),
length = elements.length;
return elements;
} }
jsOMS.FormView.prototype.bindInput = function() jsOMS.Views.FormView.prototype.getData = function()
{ {
var self = this; let data = {},
elements = this.getFormElements(this.id),
length = elements.length,
i = 0;
let inputs = this.formElement.getElementsByTagName('input'); for(i = 0; i < length; i++) {
data[this.getElementId(elements[i])] = elements[i].value;
}
Object.keys(inputs).forEach(function (key, element) { return data;
self.inputElement[element.getAttribute('id')] = { };
id: element.getAttribute('id'),
type: element.getAttribute('type') jsOMS.Views.FormView.prototype.getElementId = function(e)
{
let id = null;
id = e.getAttribute('name');
if(id === null) {
id = e.getAttribute('id');
} else {
return id;
}
if(id === null) {
id = e.getAttribute('type');
} else {
return id;
}
return id;
}
jsOMS.Views.FormView.prototype.getSubmitInjects = function()
{
return this.submitInjects;
};
jsOMS.Views.FormView.prototype.bind = function()
{
this.clean();
this.method = document.getElementById(this.id).method;
this.action = document.getElementById(this.id).action;
let elements = this.getFormElements(this.id),
length = elements.length,
i = 0;
for(i = 0; i < length; i++) {
switch(elements[i].tagName) {
case 'input':
jsOMS.UI.Input.bind(elements[i])
break;
case 'select':
this.bindSelect(elements[i]);
break;
case 'textarea':
this.bindTextarea(elements[i]);
break;
case 'button':
this.bindButton(elements[i]);
break;
}; };
}); }
} };
jsOMS.FormView.prototype.bind jsOMS.Views.FormView.prototype.unbind = function()
{
let elements = this.getFormElements(this.id),
length = elements.length,
i = 0;
for(i = 0; i < length; i++) {
switch(elements[i].tagName) {
case 'input':
jsOMS.UI.Input.unbind(elements[i])
break;
case 'select':
this.bindSelect(elements[i]);
break;
case 'textarea':
this.bindTextarea(elements[i]);
break;
case 'button':
this.bindButton(elements[i]);
break;
};
}
};
jsOMS.Views.FormView.prototype.clean = function()
{
this.unbind();
this.initializeMembers();
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

60
autoloader.js Normal file
View File

@ -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 || {}));

10
oms.min.js vendored
View File

@ -390,8 +390,8 @@
{ {
var authRequest = new jsOMS.Request(); var authRequest = new jsOMS.Request();
authRequest.setUri(this.uri); authRequest.setUri(this.uri);
authRequest.setMethod(jsOMS.EnumRequestMethod.POST); authRequest.setMethod(jsOMS.Message.Request.RequestMethod.POST);
authRequest.setResponseType(jsOMS.EnumRequestType.JSON); authRequest.setResponseType(jsOMS.Message.Request.RequestType.JSON);
authRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); authRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
authRequest.setSuccess(function (xhr) { authRequest.setSuccess(function (xhr) {
this.loginResult(xhr); this.loginResult(xhr);
@ -1030,7 +1030,7 @@ with ({p: MathProcessor.prototype}) {
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));
(function (jsOMS, undefined) { (function (jsOMS, undefined) {
jsOMS.EnumRequestMethod = Object.freeze({ jsOMS.Message.Request.RequestMethod = Object.freeze({
POST: 'POST', POST: 'POST',
GET: 'GET', GET: 'GET',
PUT: 'PUT', PUT: 'PUT',
@ -1070,7 +1070,7 @@ with ({p: MathProcessor.prototype}) {
} }
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));
(function (jsOMS, undefined) { (function (jsOMS, undefined) {
jsOMS.EnumResponseResultType = Object.freeze({ jsOMS.Message.Response.ResponseResultType = Object.freeze({
MULTI: 0, MULTI: 0,
MESSAGE: 1, MESSAGE: 1,
INFO: 2, INFO: 2,
@ -1079,7 +1079,7 @@ with ({p: MathProcessor.prototype}) {
}); });
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));
(function (jsOMS, undefined) { (function (jsOMS, undefined) {
jsOMS.EnumRequestType = Object.freeze({ jsOMS.Message.Request.RequestType = Object.freeze({
TEXT: 'text', TEXT: 'text',
JSON: 'json', JSON: 'json',
DOCUMENT: 'document', DOCUMENT: 'document',