mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-01-11 01:48:40 +00:00
JsHint fixes and comments
This commit is contained in:
parent
972bcb83a5
commit
56757de774
|
|
@ -11,6 +11,8 @@
|
|||
*/
|
||||
(function (jsOMS)
|
||||
{
|
||||
"use strict";
|
||||
|
||||
jsOMS.Autoloader.defineNamespace('jsOMS.Event');
|
||||
|
||||
/**
|
||||
|
|
@ -19,51 +21,56 @@
|
|||
* @since 1.0.0
|
||||
* @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 = {};
|
||||
};
|
||||
|
||||
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][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;
|
||||
}
|
||||
|
||||
for (let id in this.groups[group]) {
|
||||
if (!this.groups[group][id]) {
|
||||
if (this.groups[group].hasOwnProperty(id)) {
|
||||
return true;
|
||||
} else {
|
||||
this.app.logger.warning('Invalid property.');
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if(!this.hasOutstanding(group)) {
|
||||
this.callbacks[group]();
|
||||
if (!this.hasOutstanding(group)) {
|
||||
this.callbacks[group].func();
|
||||
delete this.callbacks[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 || {}));
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@
|
|||
* @license OMS License 1.0
|
||||
* @version 1.0.0 * @since 1.0.0
|
||||
*/
|
||||
(function (jsOMS)
|
||||
{
|
||||
(function (jsOMS)
|
||||
{
|
||||
"use strict";
|
||||
/** @namespace jsOMS.Log */
|
||||
/** @namespace jsOMS.Log */
|
||||
jsOMS.Autoloader.defineNamespace('jsOMS.Log');
|
||||
|
||||
/**
|
||||
|
|
@ -22,44 +22,46 @@
|
|||
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;
|
||||
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)
|
||||
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]);
|
||||
for (let replace in context) {
|
||||
if (context.hasOwnProperty(replace)) {
|
||||
newMessage = newMessage.replace('{' + replace + '}', context[replace]);
|
||||
}
|
||||
}
|
||||
|
||||
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['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;
|
||||
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)
|
||||
jsOMS.Log.Logger.prototype.write = function (message, context, level)
|
||||
{
|
||||
context = this.createContext(message, context, level);
|
||||
|
||||
if(this.verbose) {
|
||||
if (this.verbose) {
|
||||
let color = '000';
|
||||
|
||||
switch(level) {
|
||||
switch (level) {
|
||||
case 'info':
|
||||
case 'notice':
|
||||
case 'log':
|
||||
|
|
@ -82,89 +84,91 @@
|
|||
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
|
||||
}
|
||||
|
||||
if(this.remote) {
|
||||
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.setSuccess(function (xhr)
|
||||
{
|
||||
});
|
||||
request.send();
|
||||
}
|
||||
};
|
||||
|
||||
jsOMS.Log.Logger.prototype.emergency = function(message, context)
|
||||
jsOMS.Log.Logger.prototype.emergency = function (message, 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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
this.write(message, context, jsOMS.Log.LogLevel.INFO)
|
||||
this.write(message, context, jsOMS.Log.LogLevel.INFO);
|
||||
};
|
||||
}(window.jsOMS = window.jsOMS || {}));
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
this.data = {};
|
||||
|
||||
/** global: XMLHttpRequest */
|
||||
this.xhr = new XMLHttpRequest();
|
||||
this.xhr = new XMLHttpRequest();
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -339,9 +339,9 @@
|
|||
{
|
||||
if (self.xhr.readyState === 4 && self.xhr.status === 200) {
|
||||
self.success(self.xhr);
|
||||
} else if(self.xhr.readyState === 2) {
|
||||
} else if (self.xhr.readyState === 2) {
|
||||
// todo: handle server received request
|
||||
} else if(self.xhr.readyState === 3) {
|
||||
} else if (self.xhr.readyState === 3) {
|
||||
// todo: server is handling request
|
||||
} else {
|
||||
// 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)
|
||||
{
|
||||
if (typeof id !== 'undefined') {
|
||||
this.bindButton(id)
|
||||
this.bindButton(id);
|
||||
} else {
|
||||
let buttons = document.getElementsByTagName('button'),
|
||||
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!
|
||||
for (let i = 1; i < actionLength; i++) {
|
||||
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.addGroup(actions[i - 1].type, id + actions[i - 1].type);
|
||||
this.app.eventManager.setDone(id + actions[i - 1].type, function ()
|
||||
{
|
||||
// todo: how to pass result from previous action to next action?!
|
||||
self.runAction(document.getElementById(id), actions[i]);
|
||||
|
|
@ -68,9 +68,12 @@
|
|||
{
|
||||
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 || {}));
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@
|
|||
jsOMS.UI.FormManager.prototype.bind = function (id)
|
||||
{
|
||||
if (typeof id !== 'undefined' && typeof this.ignore[id] === 'undefined') {
|
||||
this.bindForm(id)
|
||||
this.bindForm(id);
|
||||
} else {
|
||||
let forms = document.getElementsByTagName('form'),
|
||||
length = forms.length;
|
||||
|
|
@ -158,17 +158,20 @@
|
|||
counter = 0;
|
||||
|
||||
for (let property in injects) {
|
||||
counter++;
|
||||
this.app.eventManager.addGroup(counter, form.getId());
|
||||
|
||||
injects[property](form.getElement(), counter, form.getId());
|
||||
if (injects.hasOwnProperty(property)) {
|
||||
counter++;
|
||||
this.app.eventManager.addGroup(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);
|
||||
});
|
||||
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