mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-14 16:38:39 +00:00
JsHint fixes and comments
This commit is contained in:
parent
972bcb83a5
commit
56757de774
|
|
@ -11,6 +11,8 @@
|
||||||
*/
|
*/
|
||||||
(function (jsOMS)
|
(function (jsOMS)
|
||||||
{
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
jsOMS.Autoloader.defineNamespace('jsOMS.Event');
|
jsOMS.Autoloader.defineNamespace('jsOMS.Event');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -19,51 +21,56 @@
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
* @author Dennis Eichhorn <d.eichhorn@oms.com>
|
||||||
*/
|
*/
|
||||||
jsOMS.Event.EventManager = function ()
|
jsOMS.Event.EventManager = function (logger)
|
||||||
{
|
{
|
||||||
this.groups = {};
|
this.logger = logger;
|
||||||
|
this.groups = {};
|
||||||
this.callbacks = {};
|
this.callbacks = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Event.EventManager.prototype.addGroup = function(id, group)
|
jsOMS.Event.EventManager.prototype.addGroup = function (id, group)
|
||||||
{
|
{
|
||||||
if(typeof this.groups[group] == 'undefined') {
|
if (typeof this.groups[group] === 'undefined') {
|
||||||
this.groups[group] = {};
|
this.groups[group] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
this.groups[group][id] = false;
|
this.groups[group][id] = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Event.EventManager.prototype.hasOutstanding = function(group)
|
jsOMS.Event.EventManager.prototype.hasOutstanding = function (group)
|
||||||
{
|
{
|
||||||
if(typeof this.groups[group] === 'undefined') {
|
if (typeof this.groups[group] === 'undefined') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let id in this.groups[group]) {
|
for (let id in this.groups[group]) {
|
||||||
if (!this.groups[group][id]) {
|
if (this.groups[group].hasOwnProperty(id)) {
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
this.app.logger.warning('Invalid property.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Event.EventManager.prototype.triggerDone = function(id, group)
|
jsOMS.Event.EventManager.prototype.trigger = function (id, group)
|
||||||
{
|
{
|
||||||
if(typeof this.groups[group] !== 'undefined') {
|
if (typeof this.groups[group] !== 'undefined') {
|
||||||
this.groups[group][id] = true;
|
this.groups[group][id] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!this.hasOutstanding(group)) {
|
if (!this.hasOutstanding(group)) {
|
||||||
this.callbacks[group]();
|
this.callbacks[group].func();
|
||||||
delete this.callbacks[group];
|
delete this.callbacks[group];
|
||||||
delete this.groups[group];
|
delete this.groups[group];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Event.EventManager.prototype.setDone = function(group, callback)
|
jsOMS.Event.EventManager.prototype.attach = function (group, callback, remove)
|
||||||
{
|
{
|
||||||
this.callbacks[group] = callback;
|
remove = typeof remove === 'undefined' ? false : remove;
|
||||||
|
|
||||||
|
this.callbacks[group] = {remove: remove, func: callback};
|
||||||
};
|
};
|
||||||
}(window.jsOMS = window.jsOMS || {}));
|
}(window.jsOMS = window.jsOMS || {}));
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@
|
||||||
* @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)
|
(function (jsOMS)
|
||||||
{
|
{
|
||||||
"use strict";
|
"use strict";
|
||||||
/** @namespace jsOMS.Log */
|
/** @namespace jsOMS.Log */
|
||||||
jsOMS.Autoloader.defineNamespace('jsOMS.Log');
|
jsOMS.Autoloader.defineNamespace('jsOMS.Log');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -22,44 +22,46 @@
|
||||||
jsOMS.Log.Logger = function (verbose, ui, remote)
|
jsOMS.Log.Logger = function (verbose, ui, remote)
|
||||||
{
|
{
|
||||||
this.verbose = typeof verbose !== 'undefined' ? verbose : true;
|
this.verbose = typeof verbose !== 'undefined' ? verbose : true;
|
||||||
this.ui = typeof ui !== 'undefined' ? ui : true;
|
this.ui = typeof ui !== 'undefined' ? ui : true;
|
||||||
this.remote = typeof remote !== 'undefined' ? remote : false;
|
this.remote = typeof remote !== 'undefined' ? remote : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.layout = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}';
|
jsOMS.Log.Logger.layout = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}';
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.interpolate = function(message, context, level)
|
jsOMS.Log.Logger.prototype.interpolate = function (message, context, level)
|
||||||
{
|
{
|
||||||
let newMessage = jsOMS.Log.Logger.layout;
|
let newMessage = jsOMS.Log.Logger.layout;
|
||||||
|
|
||||||
for(let replace in context) {
|
for (let replace in context) {
|
||||||
newMessage = newMessage.replace('{'+replace+'}', context[replace]);
|
if (context.hasOwnProperty(replace)) {
|
||||||
|
newMessage = newMessage.replace('{' + replace + '}', context[replace]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newMessage;
|
return newMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.createContext = function(message, context, level)
|
jsOMS.Log.Logger.prototype.createContext = function (message, context, level)
|
||||||
{
|
{
|
||||||
context['datetime'] = (new Date()).toISOString();
|
context.datetime = (new Date()).toISOString();
|
||||||
context['version'] = '1.0.0';
|
context.version = '1.0.0';
|
||||||
context['os'] = jsOMS.Message.Request.Request.getOS();
|
context.os = jsOMS.Message.Request.Request.getOS();
|
||||||
context['browser'] = jsOMS.Message.Request.Request.getBrowser();
|
context.browser = jsOMS.Message.Request.Request.getBrowser();
|
||||||
context['path'] = window.location.href;
|
context.path = window.location.href;
|
||||||
context['level'] = level;
|
context.level = level;
|
||||||
context['message'] = message;
|
context.message = message;
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.write = function(message, context, level)
|
jsOMS.Log.Logger.prototype.write = function (message, context, level)
|
||||||
{
|
{
|
||||||
context = this.createContext(message, context, level);
|
context = this.createContext(message, context, level);
|
||||||
|
|
||||||
if(this.verbose) {
|
if (this.verbose) {
|
||||||
let color = '000';
|
let color = '000';
|
||||||
|
|
||||||
switch(level) {
|
switch (level) {
|
||||||
case 'info':
|
case 'info':
|
||||||
case 'notice':
|
case 'notice':
|
||||||
case 'log':
|
case 'log':
|
||||||
|
|
@ -82,89 +84,91 @@
|
||||||
console.log('%c' + this.interpolate(message, context, level), 'color: #' + color);
|
console.log('%c' + this.interpolate(message, context, level), 'color: #' + color);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.ui) {
|
if (this.ui) {
|
||||||
// todo: fill log box, set class and initiate animation
|
// todo: fill log box, set class and initiate animation
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.remote) {
|
if (this.remote) {
|
||||||
let request = new jsOMS.Message.Request.Request();
|
let request = new jsOMS.Message.Request.Request();
|
||||||
request.setData(context);
|
request.setData(context);
|
||||||
request.setType(jsOMS.Message.Response.Response.ResponseType.JSON);
|
request.setType(jsOMS.Message.Response.Response.ResponseType.JSON);
|
||||||
request.setUri('/{/lang}/api/log');
|
request.setUri('/{/lang}/api/log');
|
||||||
request.setMethod(jsOMS.Message.Request.Request.RequestMethod.POST);
|
request.setMethod(jsOMS.Message.Request.Request.RequestMethod.POST);
|
||||||
request.setRequestHeader('Content-Type', 'application/json');
|
request.setRequestHeader('Content-Type', 'application/json');
|
||||||
request.setSuccess(function (xhr) {});
|
request.setSuccess(function (xhr)
|
||||||
|
{
|
||||||
|
});
|
||||||
request.send();
|
request.send();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.emergency = function(message, context)
|
jsOMS.Log.Logger.prototype.emergency = function (message, context)
|
||||||
{
|
{
|
||||||
context = typeof context === 'undefined' ? {} : context;
|
context = typeof context === 'undefined' ? {} : context;
|
||||||
|
|
||||||
this.write(message, context, jsOMS.Log.LogLevel.EMERGENCY)
|
this.write(message, context, jsOMS.Log.LogLevel.EMERGENCY);
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.alert = function(message, context)
|
jsOMS.Log.Logger.prototype.alert = function (message, context)
|
||||||
{
|
{
|
||||||
context = typeof context === 'undefined' ? {} : context;
|
context = typeof context === 'undefined' ? {} : context;
|
||||||
|
|
||||||
this.write(message, context, jsOMS.Log.LogLevel.ALERT)
|
this.write(message, context, jsOMS.Log.LogLevel.ALERT);
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.critical = function(message, context)
|
jsOMS.Log.Logger.prototype.critical = function (message, context)
|
||||||
{
|
{
|
||||||
context = typeof context === 'undefined' ? {} : context;
|
context = typeof context === 'undefined' ? {} : context;
|
||||||
|
|
||||||
this.write(message, context, jsOMS.Log.LogLevel.CRITICAL)
|
this.write(message, context, jsOMS.Log.LogLevel.CRITICAL);
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.error = function(message, context)
|
jsOMS.Log.Logger.prototype.error = function (message, context)
|
||||||
{
|
{
|
||||||
context = typeof context === 'undefined' ? {} : context;
|
context = typeof context === 'undefined' ? {} : context;
|
||||||
|
|
||||||
this.write(message, context, jsOMS.Log.LogLevel.ERROR)
|
this.write(message, context, jsOMS.Log.LogLevel.ERROR);
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.warning = function(message, context)
|
jsOMS.Log.Logger.prototype.warning = function (message, context)
|
||||||
{
|
{
|
||||||
context = typeof context === 'undefined' ? {} : context;
|
context = typeof context === 'undefined' ? {} : context;
|
||||||
|
|
||||||
this.write(message, context, jsOMS.Log.LogLevel.WARNING)
|
this.write(message, context, jsOMS.Log.LogLevel.WARNING);
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.notice = function(message, context)
|
jsOMS.Log.Logger.prototype.notice = function (message, context)
|
||||||
{
|
{
|
||||||
context = typeof context === 'undefined' ? {} : context;
|
context = typeof context === 'undefined' ? {} : context;
|
||||||
|
|
||||||
this.write(message, context, jsOMS.Log.LogLevel.NOTICE)
|
this.write(message, context, jsOMS.Log.LogLevel.NOTICE);
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.info = function(message, context)
|
jsOMS.Log.Logger.prototype.info = function (message, context)
|
||||||
{
|
{
|
||||||
context = typeof context === 'undefined' ? {} : context;
|
context = typeof context === 'undefined' ? {} : context;
|
||||||
|
|
||||||
this.write(message, context, jsOMS.Log.LogLevel.INFO)
|
this.write(message, context, jsOMS.Log.LogLevel.INFO);
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.debug = function(message, context)
|
jsOMS.Log.Logger.prototype.debug = function (message, context)
|
||||||
{
|
{
|
||||||
context = typeof context === 'undefined' ? {} : context;
|
context = typeof context === 'undefined' ? {} : context;
|
||||||
|
|
||||||
this.write(message, context, jsOMS.Log.LogLevel.DEBUG)
|
this.write(message, context, jsOMS.Log.LogLevel.DEBUG);
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.log = function(level, message, context)
|
jsOMS.Log.Logger.prototype.log = function (level, message, context)
|
||||||
{
|
{
|
||||||
context = typeof context === 'undefined' ? {} : context;
|
context = typeof context === 'undefined' ? {} : context;
|
||||||
|
|
||||||
this.write(message, context, context)
|
this.write(message, context, context);
|
||||||
};
|
};
|
||||||
|
|
||||||
jsOMS.Log.Logger.prototype.console = function(level, message, context)
|
jsOMS.Log.Logger.prototype.console = function (level, message, context)
|
||||||
{
|
{
|
||||||
context = typeof context === 'undefined' ? {} : context;
|
context = typeof context === 'undefined' ? {} : context;
|
||||||
|
|
||||||
this.write(message, context, jsOMS.Log.LogLevel.INFO)
|
this.write(message, context, jsOMS.Log.LogLevel.INFO);
|
||||||
};
|
};
|
||||||
}(window.jsOMS = window.jsOMS || {}));
|
}(window.jsOMS = window.jsOMS || {}));
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
this.data = {};
|
this.data = {};
|
||||||
|
|
||||||
/** global: XMLHttpRequest */
|
/** global: XMLHttpRequest */
|
||||||
this.xhr = new XMLHttpRequest();
|
this.xhr = new XMLHttpRequest();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -339,9 +339,9 @@
|
||||||
{
|
{
|
||||||
if (self.xhr.readyState === 4 && self.xhr.status === 200) {
|
if (self.xhr.readyState === 4 && self.xhr.status === 200) {
|
||||||
self.success(self.xhr);
|
self.success(self.xhr);
|
||||||
} else if(self.xhr.readyState === 2) {
|
} else if (self.xhr.readyState === 2) {
|
||||||
// todo: handle server received request
|
// todo: handle server received request
|
||||||
} else if(self.xhr.readyState === 3) {
|
} else if (self.xhr.readyState === 3) {
|
||||||
// todo: server is handling request
|
// todo: server is handling request
|
||||||
} else {
|
} else {
|
||||||
// todo: create handler for error returns
|
// todo: create handler for error returns
|
||||||
|
|
|
||||||
13
UI/Button.js
13
UI/Button.js
|
|
@ -23,7 +23,7 @@
|
||||||
jsOMS.UI.Button.prototype.bind = function (id)
|
jsOMS.UI.Button.prototype.bind = function (id)
|
||||||
{
|
{
|
||||||
if (typeof id !== 'undefined') {
|
if (typeof id !== 'undefined') {
|
||||||
this.bindButton(id)
|
this.bindButton(id);
|
||||||
} else {
|
} else {
|
||||||
let buttons = document.getElementsByTagName('button'),
|
let buttons = document.getElementsByTagName('button'),
|
||||||
length = buttons.length;
|
length = buttons.length;
|
||||||
|
|
@ -45,8 +45,8 @@
|
||||||
|
|
||||||
// todo: carefull this means a type has to be unique in a button. no multiple actions with same type!!! CHANGE!
|
// todo: carefull this means a type has to be unique in a button. no multiple actions with same type!!! CHANGE!
|
||||||
for (let i = 1; i < actionLength; i++) {
|
for (let i = 1; i < actionLength; i++) {
|
||||||
this.app.eventManager.addGroup(actions[i - 1]['type'], id + actions[i - 1]['type']);
|
this.app.eventManager.addGroup(actions[i - 1].type, id + actions[i - 1].type);
|
||||||
this.app.eventManager.setDone(id + actions[i - 1]['type'], function ()
|
this.app.eventManager.setDone(id + actions[i - 1].type, function ()
|
||||||
{
|
{
|
||||||
// todo: how to pass result from previous action to next action?!
|
// todo: how to pass result from previous action to next action?!
|
||||||
self.runAction(document.getElementById(id), actions[i]);
|
self.runAction(document.getElementById(id), actions[i]);
|
||||||
|
|
@ -68,9 +68,12 @@
|
||||||
{
|
{
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
this.actions[action['type']](action, function ()
|
// todo: why am i accessing this.actions? shouldn't the callback be stored in the event manager?
|
||||||
|
// todo: what happens if i click the same button again? isn't it now removed from the eventmanager?
|
||||||
|
this.actions[action.type](action, function ()
|
||||||
{
|
{
|
||||||
self.app.eventManager.triggerDone(e.getAttribute('id'), e.getAttribute('id') + action['type']);
|
// todo: the event manager needs optional parameter to pass data to the callback.
|
||||||
|
self.app.eventManager.triggerDone(e.getAttribute('id'), e.getAttribute('id') + action.type);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}(window.jsOMS = window.jsOMS || {}));
|
}(window.jsOMS = window.jsOMS || {}));
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@
|
||||||
jsOMS.UI.FormManager.prototype.bind = function (id)
|
jsOMS.UI.FormManager.prototype.bind = function (id)
|
||||||
{
|
{
|
||||||
if (typeof id !== 'undefined' && typeof this.ignore[id] === 'undefined') {
|
if (typeof id !== 'undefined' && typeof this.ignore[id] === 'undefined') {
|
||||||
this.bindForm(id)
|
this.bindForm(id);
|
||||||
} else {
|
} else {
|
||||||
let forms = document.getElementsByTagName('form'),
|
let forms = document.getElementsByTagName('form'),
|
||||||
length = forms.length;
|
length = forms.length;
|
||||||
|
|
@ -158,17 +158,20 @@
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
|
||||||
for (let property in injects) {
|
for (let property in injects) {
|
||||||
counter++;
|
if (injects.hasOwnProperty(property)) {
|
||||||
this.app.eventManager.addGroup(counter, form.getId());
|
counter++;
|
||||||
|
this.app.eventManager.addGroup(counter, form.getId());
|
||||||
injects[property](form.getElement(), counter, form.getId());
|
injects[property](form.getElement(), counter, form.getId());
|
||||||
|
} else {
|
||||||
|
this.app.logger.warning('Invalid property.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.app.eventManager.setDone(form.getId(), function ()
|
this.app.eventManager.attach(form.getId(), function ()
|
||||||
{
|
{
|
||||||
self.submitForm(form);
|
self.submitForm(form);
|
||||||
});
|
});
|
||||||
this.app.eventManager.triggerDone('?', form.getId());
|
this.app.eventManager.trigger('?', form.getId());
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
18
UnhandledException.js
Normal file
18
UnhandledException.js
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
/**
|
||||||
|
* 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 ()
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
window.addEventListener('error', function (e)
|
||||||
|
{
|
||||||
|
console.log(e.error);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}(window.jsOMS = window.jsOMS || {}));
|
||||||
Loading…
Reference in New Issue
Block a user