JsHint fixes and comments

This commit is contained in:
Dennis Eichhorn 2016-06-12 09:52:05 +02:00
parent 972bcb83a5
commit 56757de774
6 changed files with 105 additions and 70 deletions

View File

@ -11,6 +11,8 @@
*/
(function (jsOMS)
{
"use strict";
jsOMS.Autoloader.defineNamespace('jsOMS.Event');
/**
@ -19,15 +21,16 @@
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
jsOMS.Event.EventManager = function ()
jsOMS.Event.EventManager = function (logger)
{
this.logger = logger;
this.groups = {};
this.callbacks = {};
};
jsOMS.Event.EventManager.prototype.addGroup = function (id, group)
{
if(typeof this.groups[group] == 'undefined') {
if (typeof this.groups[group] === 'undefined') {
this.groups[group] = {};
}
@ -41,29 +44,33 @@
}
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') {
this.groups[group][id] = true;
}
if (!this.hasOutstanding(group)) {
this.callbacks[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 || {}));

View File

@ -33,21 +33,23 @@
let newMessage = jsOMS.Log.Logger.layout;
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)
{
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;
};
@ -93,7 +95,9 @@
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();
}
};
@ -102,69 +106,69 @@
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
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)
{
context = typeof context === 'undefined' ? {} : context;
this.write(message, context, 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)
this.write(message, context, jsOMS.Log.LogLevel.INFO);
};
}(window.jsOMS = window.jsOMS || {}));

View File

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

View File

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