Implement class keyword instead of prototype

This commit is contained in:
Dennis Eichhorn 2018-04-25 22:38:23 +02:00
parent a5474c68cb
commit 5b305db3d2
42 changed files with 4099 additions and 4017 deletions

View File

@ -12,67 +12,70 @@
jsOMS.Autoloader.defineNamespace('jsOMS.Account'); jsOMS.Autoloader.defineNamespace('jsOMS.Account');
/**
* @constructor jsOMS.Account.AccountManager = class {
* /**
* @since 1.0.0 * @constructor
*/ *
jsOMS.Account.AccountManager = function () * @since 1.0.0
{ */
this.accounts = []; constructor ()
}; {
this.accounts = [];
};
/** /**
* Add account. * Add account.
* *
* @param {Object} account Account * @param {Object} account Account
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Account.AccountManager.prototype.add = function (account) add (account)
{ {
this.accounts[account.getId()] = account; this.accounts[account.getId()] = account;
}; };
/** /**
* Remove account. * Remove account.
* *
* @param {int} id Account id * @param {int} id Account id
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Account.AccountManager.prototype.remove = function (id) remove (id)
{ {
if (typeof this.accounts[id] !== 'undefined') { if (typeof this.accounts[id] !== 'undefined') {
delete this.accounts[id]; delete this.accounts[id];
return true; return true;
} }
return false; return false;
}; };
/** /**
* Get account by id. * Get account by id.
* *
* @param {int} id Account id * @param {int} id Account id
* *
* @return {Object} * @return {Object}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Account.AccountManager.prototype.get = function (id) get (id)
{ {
if (this.accounts[id]) { if (this.accounts[id]) {
return this.accounts[id]; return this.accounts[id];
} }
return undefined; return undefined;
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,117 +13,119 @@
/** @namespace jsOMS.Animation.Canvas */ /** @namespace jsOMS.Animation.Canvas */
jsOMS.Autoloader.defineNamespace('jsOMS.Animation.Canvas'); jsOMS.Autoloader.defineNamespace('jsOMS.Animation.Canvas');
/** jsOMS.Animation.Canvas.Particle = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Animation.Canvas.Particle = function (posX, posY, velX, velY, radius) */
{ constructor (posX, posY, velX, velY, radius)
this.posX = posX; {
this.posY = posY; this.posX = posX;
this.velX = velX; this.posY = posY;
this.velY = velY; this.velX = velX;
this.velY = velY;
this.radius = radius; this.radius = radius;
this.color = {r: 255, g: 255, b: 255, a: 0.5}; this.color = {r: 255, g: 255, b: 255, a: 0.5};
}; };
/** /**
* Get particle radius * Get particle radius
* *
* @return {int} * @return {int}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Animation.Canvas.Particle.prototype.getRadius = function () getRadius ()
{ {
return this.radius; return this.radius;
}; };
/** /**
* Set particle position * Set particle position
* *
* @param {int} posX Position x * @param {int} posX Position x
* @param {int} posY Position y * @param {int} posY Position y
* *
* @return {void} * @return {void}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Animation.Canvas.Particle.prototype.setPosition = function (posX, posY) setPosition (posX, posY)
{ {
this.posX = posX; this.posX = posX;
this.posY = posY; this.posY = posY;
}; };
/** /**
* Get position * Get position
* *
* @return {Object} * @return {Object}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Animation.Canvas.Particle.prototype.getPosition = function () getPosition ()
{ {
return {x: this.posX, y: this.posY}; return {x: this.posX, y: this.posY};
}; };
/** /**
* Set particle velocity * Set particle velocity
* *
* @param {float} velX Velocity x * @param {float} velX Velocity x
* @param {float} velY Velocity y * @param {float} velY Velocity y
* *
* @return {void} * @return {void}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Animation.Canvas.Particle.prototype.setVelocity = function (velX, velY) setVelocity (velX, velY)
{ {
this.velX = velX; this.velX = velX;
this.velY = velY; this.velY = velY;
}; };
/** /**
* Get velocity * Get velocity
* *
* @return {Object} * @return {Object}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Animation.Canvas.Particle.prototype.getVelocity = function () getVelocity ()
{ {
return {x: this.velX, y: this.velY}; return {x: this.velX, y: this.velY};
}; };
/** /**
* Draw particle to canvas * Draw particle to canvas
* *
* @param {object} ctx Canvas * @param {object} ctx Canvas
* *
* @return {void} * @return {void}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Animation.Canvas.Particle.prototype.draw = function (ctx) draw (ctx)
{ {
ctx.fillStyle = 'rgba(' + this.color.r + ', ' + this.color.g + ', ' + this.color.b + ', ' + this.color.a + ')'; ctx.fillStyle = 'rgba(' + this.color.r + ', ' + this.color.g + ', ' + this.color.b + ', ' + this.color.a + ')';
ctx.beginPath(); ctx.beginPath();
ctx.arc(this.posX, this.posY, this.radius, 0, Math.PI * 2, false); ctx.arc(this.posX, this.posY, this.radius, 0, Math.PI * 2, false);
ctx.fill(); ctx.fill();
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,176 +13,178 @@
/** @namespace jsOMS.Animation.Canvas */ /** @namespace jsOMS.Animation.Canvas */
jsOMS.Autoloader.defineNamespace('jsOMS.Animation.Canvas'); jsOMS.Autoloader.defineNamespace('jsOMS.Animation.Canvas');
/** jsOMS.Animation.Canvas.ParticleAnimation = class {
* /**
* @param {object} canvas Canvas *
* * @param {object} canvas Canvas
* @constructor *
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Animation.Canvas.ParticleAnimation = function (canvas) */
{ constructor (canvas)
this.canvas = canvas;
this.ctx = canvas.getContext('2d');
/** global: screen */
this.width = screen.width;
this.height = screen.height;
this.canvas.width = this.width;
this.canvas.height = this.height;
this.particles = [];
this.maxDistance = 70;
this.gravitation = 10000000;
for (let i = 0; i < this.width * this.height / 3000; ++i) {
this.particles.push(new jsOMS.Animation.Canvas.Particle(
Math.random() * this.width,
Math.random() * this.height,
-1 + Math.random() * 2,
-1 + Math.random() * 2,
1
));
}
};
/**
* Draw everything
*
* @param {object} self Object reference for self invoke
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Animation.Canvas.ParticleAnimation.prototype.draw = function (self)
{
self = typeof self !== 'undefined' ? self : this;
self.invalidate();
const length = self.particles.length;
for (let i = 0; i < length; ++i) {
self.particles[i].draw(self.ctx);
}
self.updateParticles();
jsOMS.Animation.Animation.requestAnimationFrame.call(window, function ()
{ {
self.draw(self); this.canvas = canvas;
}); this.ctx = canvas.getContext('2d');
};
/** /** global: screen */
* Invalidate/clean canvas this.width = screen.width;
* this.height = screen.height;
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Animation.Canvas.ParticleAnimation.prototype.invalidate = function ()
{
this.ctx.clearRect(0, 0, this.width, this.height);
};
/** this.canvas.width = this.width;
* Update particle this.canvas.height = this.height;
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Animation.Canvas.ParticleAnimation.prototype.updateParticles = function ()
{
let particle,
pos,
vel,
radius;
const length = this.particles.length; this.particles = [];
this.maxDistance = 70;
this.gravitation = 10000000;
for (let i = 0; i < length; ++i) { for (let i = 0; i < this.width * this.height / 3000; ++i) {
particle = this.particles[i]; this.particles.push(new jsOMS.Animation.Canvas.Particle(
pos = particle.getPosition(); Math.random() * this.width,
vel = particle.getVelocity(); Math.random() * this.height,
radius = particle.getRadius(); -1 + Math.random() * 2,
-1 + Math.random() * 2,
1
));
}
};
pos.x += vel.x; /**
pos.y += vel.y; * Draw everything
*
* @param {object} self Object reference for self invoke
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
draw (self)
{
self = typeof self !== 'undefined' ? self : this;
self.invalidate();
// Change on wall hit const length = self.particles.length;
if (pos.x + radius > this.width) {
pos.x = radius; for (let i = 0; i < length; ++i) {
} else if (pos.x - radius < 0) { self.particles[i].draw(self.ctx);
pos.x = this.width - radius;
} }
if (pos.y + radius > this.height) { self.updateParticles();
pos.y = radius; jsOMS.Animation.Animation.requestAnimationFrame.call(window, function ()
} else if (pos.y - radius < 0) { {
pos.y = this.height - radius; self.draw(self);
});
};
/**
* Invalidate/clean canvas
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
invalidate ()
{
this.ctx.clearRect(0, 0, this.width, this.height);
};
/**
* Update particle
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
updateParticles ()
{
let particle,
pos,
vel,
radius;
const length = this.particles.length;
for (let i = 0; i < length; ++i) {
particle = this.particles[i];
pos = particle.getPosition();
vel = particle.getVelocity();
radius = particle.getRadius();
pos.x += vel.x;
pos.y += vel.y;
// Change on wall hit
if (pos.x + radius > this.width) {
pos.x = radius;
} else if (pos.x - radius < 0) {
pos.x = this.width - radius;
}
if (pos.y + radius > this.height) {
pos.y = radius;
} else if (pos.y - radius < 0) {
pos.y = this.height - radius;
}
particle.setPosition(pos.x, pos.y);
particle.setVelocity(vel.x, vel.y);
for (let j = i + 1; j < length; ++j) {
this.updateDistance(particle, this.particles[j]);
}
} }
};
particle.setPosition(pos.x, pos.y); /**
particle.setVelocity(vel.x, vel.y); * Handle distance between particles
*
* @param {Particle} p1 Particle
* @param {Particle} p2 Particle
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
updateDistance (p1, p2)
{
const pos1 = p1.getPosition(),
pos2 = p2.getPosition(),
dx = pos1.x - pos2.x,
dy = pos1.y - pos2.y,
dist = Math.sqrt(dx * dx + dy * dy);
for (let j = i + 1; j < length; ++j) { let vel1 = p1.getVelocity(),
this.updateDistance(particle, this.particles[j]); vel2 = p2.getVelocity();
// Draw line if particles are close
if (dist <= this.maxDistance) {
this.ctx.beginPath();
this.ctx.strokeStyle = 'rgba(255, 255, 255, ' + ((1.2 - dist / this.maxDistance) * 0.5) + ')';
this.ctx.moveTo(pos1.x, pos1.y);
this.ctx.lineTo(pos2.x, pos2.y);
this.ctx.stroke();
this.ctx.closePath();
// Accelerate based on distance (no acceleration yet)
let ax = dx / this.gravitation,
ay = dy / this.gravitation;
vel1.x -= ax;
vel1.y -= ay;
p1.setVelocity(vel1.x, vel1.y);
vel2.x -= ax;
vel2.y -= ay;
p2.setVelocity(vel2.x, vel2.y);
} }
} };
}; }
/**
* Handle distance between particles
*
* @param {Particle} p1 Particle
* @param {Particle} p2 Particle
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Animation.Canvas.ParticleAnimation.prototype.updateDistance = function (p1, p2)
{
const pos1 = p1.getPosition(),
pos2 = p2.getPosition(),
dx = pos1.x - pos2.x,
dy = pos1.y - pos2.y,
dist = Math.sqrt(dx * dx + dy * dy);
let vel1 = p1.getVelocity(),
vel2 = p2.getVelocity();
// Draw line if particles are close
if (dist <= this.maxDistance) {
this.ctx.beginPath();
this.ctx.strokeStyle = 'rgba(255, 255, 255, ' + ((1.2 - dist / this.maxDistance) * 0.5) + ')';
this.ctx.moveTo(pos1.x, pos1.y);
this.ctx.lineTo(pos2.x, pos2.y);
this.ctx.stroke();
this.ctx.closePath();
// Accelerate based on distance (no acceleration yet)
let ax = dx / this.gravitation,
ay = dy / this.gravitation;
vel1.x -= ax;
vel1.y -= ay;
p1.setVelocity(vel1.x, vel1.y);
vel2.x -= ax;
vel2.y -= ay;
p2.setVelocity(vel2.x, vel2.y);
}
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -12,157 +12,159 @@
jsOMS.Asset = {}; jsOMS.Asset = {};
/** jsOMS.Asset.AssetManager = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Asset.AssetManager = function () */
{ constructor ()
this.assets = {}; {
this.registerLoadedAssets(); this.assets = {};
}; this.registerLoadedAssets();
};
/** /**
* Register all loaded assets. * Register all loaded assets.
* *
* @return {void} * @return {void}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Asset.AssetManager.prototype.registerLoadedAssets = function () registerLoadedAssets ()
{ {
const scripts = document.getElementsByTagName('script'), const scripts = document.getElementsByTagName('script'),
length = !scripts ? 0 : scripts.length; length = !scripts ? 0 : scripts.length;
this.assets = {}; this.assets = {};
for (let i = 0; i < length; ++i) { for (let i = 0; i < length; ++i) {
this.assets[jsOMS.hash(scripts[i].src)] = scripts[i].src; this.assets[jsOMS.hash(scripts[i].src)] = scripts[i].src;
} }
}; };
/** /**
* Load asset. * Load asset.
* *
* @param {string} path Asset path * @param {string} path Asset path
* @param {string} filetype Filetype of the asset * @param {string} filetype Filetype of the asset
* @param {requestCallback} [callback] Callback after load * @param {requestCallback} [callback] Callback after load
* *
* @return {string|boolean} * @return {string|boolean}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Asset.AssetManager.prototype.load = function (path, filetype, callback) load (path, filetype, callback)
{ {
let hash; let hash;
if (!this.assets[(hash = jsOMS.hash(path))]) { if (!this.assets[(hash = jsOMS.hash(path))]) {
let fileref = null; let fileref = null;
if (filetype === 'js') { if (filetype === 'js') {
fileref = document.createElement('script'); fileref = document.createElement('script');
fileref.setAttribute('type', 'text/javascript'); fileref.setAttribute('type', 'text/javascript');
fileref.setAttribute('src', path); fileref.setAttribute('src', path);
if (typeof fileref !== 'undefined') { if (typeof fileref !== 'undefined') {
const head = document.getElementsByTagName('head'); const head = document.getElementsByTagName('head');
if (head) { if (head) {
head[0].appendChild(fileref); head[0].appendChild(fileref);
}
} }
this.assets[hash] = path;
} else if (filetype === 'css') {
fileref = document.createElement('link');
fileref.setAttribute('rel', 'stylesheet');
fileref.setAttribute('type', 'text/css');
fileref.setAttribute('href', path);
if (typeof fileref !== 'undefined') {
const head = document.getElementsByTagName('head');
if (head) {
head[0].appendChild(fileref);
}
}
this.assets[hash] = path;
} else if (filetype === 'img') {
/** global: Image */
this.assets[hash] = new Image();
this.assets[hash].src = path;
} else if (filetype === 'audio') {
// TODO: implement audio asset
} else if (filetype === 'video') {
// TODO: implement video asset
} }
this.assets[hash] = path; if (callback) {
} else if (filetype === 'css') { fileref.onreadystatechange ()
fileref = document.createElement('link'); {
fileref.setAttribute('rel', 'stylesheet'); if (this.readyState === 'complete') {
fileref.setAttribute('type', 'text/css'); callback();
fileref.setAttribute('href', path); }
};
if (typeof fileref !== 'undefined') { fileref.onload = callback();
const head = document.getElementsByTagName('head');
if (head) {
head[0].appendChild(fileref);
}
} }
this.assets[hash] = path; return hash;
} else if (filetype === 'img') {
/** global: Image */
this.assets[hash] = new Image();
this.assets[hash].src = path;
} else if (filetype === 'audio') {
// TODO: implement audio asset
} else if (filetype === 'video') {
// TODO: implement video asset
} }
if (callback) { return false;
fileref.onreadystatechange = function () };
{
if (this.readyState === 'complete') {
callback();
}
};
fileref.onload = callback(); /**
* Get asset.
*
* @param {string} key Key of the asset
*
* @return
*
* @method
*
* @since 1.0.0
*/
get (key)
{
key = jsOMS.hash(key);
if (this.assets[key]) {
return this.assets[key];
} }
return hash; return null;
} };
return false; /**
}; * Remove asset.
*
* @param {string} key Key of the asset
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
remove (key)
{
key = jsOMS.hash(key);
/** if (typeof this.assets[key] !== 'undefined') {
* Get asset. delete this.assets[key];
*
* @param {string} key Key of the asset
*
* @return
*
* @method
*
* @since 1.0.0
*/
jsOMS.Asset.AssetManager.prototype.get = function (key)
{
key = jsOMS.hash(key);
if (this.assets[key]) { return true;
return this.assets[key]; }
}
return null; return false;
}; };
/**
* Remove asset.
*
* @param {string} key Key of the asset
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Asset.AssetManager.prototype.remove = function (key)
{
key = jsOMS.hash(key);
if (typeof this.assets[key] !== 'undefined') {
delete this.assets[key];
return true;
}
return false;
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -12,88 +12,90 @@
jsOMS.Autoloader.defineNamespace('jsOMS.Auth'); jsOMS.Autoloader.defineNamespace('jsOMS.Auth');
/** jsOMS.Auth.Auth = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Auth.Auth = function (uri) */
{ constructor (uri)
this.account = null;
this.uri = uri;
};
/**
* Set account for authentication.
*
* @param {Object} account Account
*
* @method
*
* @since 1.0.0
*/
jsOMS.Auth.Auth.prototype.setAccount = function (account)
{
this.account = account;
};
/**
* Get account.
*
* @return {Object}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Auth.Auth.prototype.getAccount = function ()
{
return this.account;
};
/**
* Login account.
*
* @method
*
* @since 1.0.0
*/
jsOMS.Auth.Auth.prototype.login = function ()
{
const authRequest = new jsOMS.Message.Request.Request();
authRequest.setUri(this.uri);
authRequest.setMethod(jsOMS.Message.Request.RequestMethod.POST);
authRequest.setResponseType(jsOMS.Message.Request.RequestType.JSON);
authRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
authRequest.setSuccess(function (xhr)
{ {
this.loginResult(xhr); this.account = null;
}); this.uri = uri;
};
authRequest.send(); /**
}; * Set account for authentication.
*
* @param {Object} account Account
*
* @method
*
* @since 1.0.0
*/
setAccount (account)
{
this.account = account;
};
/** /**
* Logout account. * Get account.
* *
* @method * @return {Object}
* *
* @since 1.0.0 * @method
*/ *
jsOMS.Auth.Auth.prototype.logout = function () * @since 1.0.0
{ */
location.reload(); getAccount ()
}; {
return this.account;
};
/** /**
* Handle login result. * Login account.
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Auth.Auth.prototype.loginResult = function (xhr) login ()
{ {
location.reload(); const authRequest = new jsOMS.Message.Request.Request();
authRequest.setUri(this.uri);
authRequest.setMethod(jsOMS.Message.Request.RequestMethod.POST);
authRequest.setResponseType(jsOMS.Message.Request.RequestType.JSON);
authRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
authRequest.setSuccess(function (xhr)
{
this.loginResult(xhr);
});
authRequest.send();
};
/**
* Logout account.
*
* @method
*
* @since 1.0.0
*/
logout ()
{
location.reload();
};
/**
* Handle login result.
*
* @method
*
* @since 1.0.0
*/
loginResult (xhr)
{
location.reload();
};
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -16,79 +16,81 @@
/** @namespace jsOMS.Config */ /** @namespace jsOMS.Config */
jsOMS.Autoloader.defineNamespace('jsOMS.Config'); jsOMS.Autoloader.defineNamespace('jsOMS.Config');
/** jsOMS.Config.Options = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Config.Options = function () */
{ constructor ()
this.options = {}; {
}; this.options = {};
};
/** /**
* Set option. * Set option.
* *
* @param {int|string} key Option key * @param {int|string} key Option key
* @param {boolean|int|float|string|Array} value Option value * @param {boolean|int|float|string|Array} value Option value
* @param {boolean} [overwrite] Overwrite value * @param {boolean} [overwrite] Overwrite value
* *
* @return {boolean} * @return {boolean}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Config.Options.prototype.set = function (key, value, overwrite = false) set (key, value, overwrite = false)
{ {
if (overwrite || typeof this.options[key] === 'undefined') { if (overwrite || typeof this.options[key] === 'undefined') {
this.options[key] = value; this.options[key] = value;
return true; return true;
} }
return false; return false;
}; };
/** /**
* Get option. * Get option.
* *
* @param {int|string} key Option key * @param {int|string} key Option key
* *
* @return {boolean|int|float|string|Array} * @return {boolean|int|float|string|Array}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Config.Options.prototype.get = function (key) get (key)
{ {
if (typeof this.options[key] !== 'undefined') { if (typeof this.options[key] !== 'undefined') {
return this.options[key]; return this.options[key];
} }
return null; return null;
}; };
/** /**
* Remove option. * Remove option.
* *
* @param {int|string} key Option key * @param {int|string} key Option key
* *
* @return {boolean} * @return {boolean}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Config.Options.prototype.remove = function (key) remove (key)
{ {
if (typeof this.options[key] !== 'undefined') { if (typeof this.options[key] !== 'undefined') {
delete this.options[key]; delete this.options[key];
return true; return true;
} }
return false; return false;
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -4,7 +4,11 @@
jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage');
// TODO: create comments // TODO: create comments
jsOMS.DataStorage.CacheManager = function ()
{ jsOMS.DataStorage.CacheManager = class {
constructor ()
{
}
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -17,71 +17,73 @@
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.DataStorage.CookieJar = function () jsOMS.DataStorage.CookieJar = class {
{ constructor ()
}; {
/**
* Saving data to cookie
*
* @param {string} cName Cookie name
* @param {string} value Value to save
* @param {number} exdays Lifetime for the cookie
* @param {string} domain Domain for the cookie
* @param {string} path Path for the cookie
*
* @return array
*
* @method
*
* @since 1.0.0
*/
jsOMS.DataStorage.CookieJar.prototype.setCookie = function (cName, value, exdays, domain, path)
{
const exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
const cValue = encodeURI(value)
+ ((exdays === null) ? "" : "; expires="
+ exdate.toUTCString()) + ";domain="
+ domain + ";path="
+ path;
document.cookie = cName + "=" + cValue;
};
/**
* Loading cookie data
*
* @param {string} cName Cookie name
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.DataStorage.CookieJar.prototype.getCookie = function (cName)
{
let cValue = document.cookie,
cStart = cValue.indexOf(" " + cName + "=");
if (cStart === -1) {
cStart = cValue.indexOf(cName + "=");
} }
if (cStart === -1) { /**
cValue = null; * Saving data to cookie
} else { *
cStart = cValue.indexOf("=", cStart) + 1; * @param {string} cName Cookie name
let cEnd = cValue.indexOf(";", cStart); * @param {string} value Value to save
* @param {number} exdays Lifetime for the cookie
* @param {string} domain Domain for the cookie
* @param {string} path Path for the cookie
*
* @return array
*
* @method
*
* @since 1.0.0
*/
setCookie (cName, value, exdays, domain, path)
{
const exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
if (cEnd === -1) { const cValue = encodeURI(value)
cEnd = cValue.length; + ((exdays === null) ? "" : "; expires="
+ exdate.toUTCString()) + ";domain="
+ domain + ";path="
+ path;
document.cookie = cName + "=" + cValue;
};
/**
* Loading cookie data
*
* @param {string} cName Cookie name
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getCookie (cName)
{
let cValue = document.cookie,
cStart = cValue.indexOf(" " + cName + "=");
if (cStart === -1) {
cStart = cValue.indexOf(cName + "=");
} }
cValue = decodeURI(cValue.substring(cStart, cEnd)); if (cStart === -1) {
} cValue = null;
return cValue; } else {
cStart = cValue.indexOf("=", cStart) + 1;
let cEnd = cValue.indexOf(";", cStart);
if (cEnd === -1) {
cEnd = cValue.length;
}
cValue = decodeURI(cValue.substring(cStart, cEnd));
}
return cValue;
};
}; };
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -12,30 +12,32 @@
jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage');
/** jsOMS.DataStorage.LocalStorage = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.DataStorage.LocalStorage = function () */
{ constructor ()
}; {
};
/** /**
* Is local storage available? * Is local storage available?
* *
* @return {boolean} * @return {boolean}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.DataStorage.LocalStorage.prototype.available = function () available ()
{ {
try { try {
return 'localStorage' in window && window.localStorage !== null; return 'localStorage' in window && window.localStorage !== null;
} catch (e) { } catch (e) {
return false; return false;
} }
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -3,7 +3,9 @@
jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage');
jsOMS.DataStorage.StorageManager = function () jsOMS.DataStorage.StorageManager = class {
{ constructor ()
}; {
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -3,7 +3,9 @@
jsOMS.Autoloader.defineNamespace('jsOMS.Dispatcher'); jsOMS.Autoloader.defineNamespace('jsOMS.Dispatcher');
jsOMS.Dispatcher.Dispatcher = function () jsOMS.Dispatcher.Dispatcher = class {
{ constructor ()
}; {
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -14,179 +14,181 @@
jsOMS.Autoloader.defineNamespace('jsOMS.Event'); jsOMS.Autoloader.defineNamespace('jsOMS.Event');
/** jsOMS.Event.EventManager = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Event.EventManager = function () */
{ constructor ()
this.logger = jsOMS.Log.Logger.getInstance(); {
this.groups = {}; this.logger = jsOMS.Log.Logger.getInstance();
this.callbacks = {}; this.groups = {};
}; this.callbacks = {};
};
/** /**
* Add event group (element) * Add event group (element)
* *
* Adding the same event overwrites the existing one as "waiting" * Adding the same event overwrites the existing one as "waiting"
* *
* @param {string|int} group Group id * @param {string|int} group Group id
* @param {string|int} id Event id * @param {string|int} id Event id
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Event.EventManager.prototype.addGroup = function (group, id) addGroup (group, id)
{ {
if (typeof this.groups[group] === 'undefined') { if (typeof this.groups[group] === 'undefined') {
this.groups[group] = {}; this.groups[group] = {};
}
this.groups[group][id] = false;
};
/**
* Resets the group status
*
* @param {string|int} group Group id
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Event.EventManager.prototype.reset = function (group)
{
for (let id in this.groups[group]) {
if (this.groups[group].hasOwnProperty(id)) {
this.groups[group][id] = false;
} }
}
};
/** this.groups[group][id] = false;
* Does group have outstanding events };
*
* @param {string|int} group Group id
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Event.EventManager.prototype.hasOutstanding = function (group)
{
if (typeof this.groups[group] === 'undefined') {
return false;
}
for (let id in this.groups[group]) { /**
if (!this.groups[group].hasOwnProperty(id) || !this.groups[group][id]) { * Resets the group status
return true; *
* @param {string|int} group Group id
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
reset (group)
{
for (let id in this.groups[group]) {
if (this.groups[group].hasOwnProperty(id)) {
this.groups[group][id] = false;
}
} }
} };
return false; /**
}; * Does group have outstanding events
*
/** * @param {string|int} group Group id
* Trigger event finished *
* * @return {boolean}
* Executes the callback specified for this group if all events are finished *
* * @method
* @param {string|int} group Group id *
* @param {string|int} [id] Event id * @since 1.0.0
* @param {Object} [data] Data for event */
* hasOutstanding (group)
* @return {boolean} {
* if (typeof this.groups[group] === 'undefined') {
* @method return false;
*
* @since 1.0.0
*/
jsOMS.Event.EventManager.prototype.trigger = function (group, id, data)
{
id = typeof id !== 'undefined' ? id : 0;
if (!this.callbacks.hasOwnProperty(group)) {
return false;
}
if (typeof this.groups[group] !== 'undefined') {
this.groups[group][id] = true;
}
if (!this.hasOutstanding(group)) {
// todo if it is route then call dispatcher?
this.callbacks[group].func(data);
if (this.callbacks[group].remove) {
this.detach(group);
} else if (this.callbacks[group].reset) {
this.reset(group);
} }
}
return true; for (let id in this.groups[group]) {
}; if (!this.groups[group].hasOwnProperty(id) || !this.groups[group][id]) {
return true;
}
}
/**
* Detach event
*
* @param {string|int} group Group id
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Event.EventManager.prototype.detach = function (group)
{
delete this.callbacks[group];
delete this.groups[group];
};
/**
* Attach callback to event group
*
* @param {string|int} group Group id
* @param {function} callback Callback or route for the event
* @param {boolean} [remove] Should be removed after execution
* @param {boolean} [reset] Reset after triggering
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Event.EventManager.prototype.attach = function (group, callback, remove = false, reset = false)
{
if (this.callbacks.hasOwnProperty(group)) {
return false; return false;
} };
this.callbacks[group] = {remove: remove, reset: reset, func: callback}; /**
* Trigger event finished
*
* Executes the callback specified for this group if all events are finished
*
* @param {string|int} group Group id
* @param {string|int} [id] Event id
* @param {Object} [data] Data for event
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
trigger (group, id, data)
{
id = typeof id !== 'undefined' ? id : 0;
return true; if (!this.callbacks.hasOwnProperty(group)) {
}; return false;
}
/** if (typeof this.groups[group] !== 'undefined') {
* Count events this.groups[group][id] = true;
* }
* @return {int}
* if (!this.hasOutstanding(group)) {
* @method // todo if it is route then call dispatcher?
* this.callbacks[group].func(data);
* @since 1.0.0
*/ if (this.callbacks[group].remove) {
jsOMS.Event.EventManager.prototype.count = function () this.detach(group);
{ } else if (this.callbacks[group].reset) {
return this.callbacks.length; this.reset(group);
}; }
}
return true;
};
/**
* Detach event
*
* @param {string|int} group Group id
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
detach (group)
{
delete this.callbacks[group];
delete this.groups[group];
};
/**
* Attach callback to event group
*
* @param {string|int} group Group id
* @param {function} callback Callback or route for the event
* @param {boolean} [remove] Should be removed after execution
* @param {boolean} [reset] Reset after triggering
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
attach (group, callback, remove = false, reset = false)
{
if (this.callbacks.hasOwnProperty(group)) {
return false;
}
this.callbacks[group] = {remove: remove, reset: reset, func: callback};
return true;
};
/**
* Count events
*
* @return {int}
*
* @method
*
* @since 1.0.0
*/
count ()
{
return this.callbacks.length;
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -12,331 +12,332 @@
/** @namespace jsOMS.Log */ /** @namespace jsOMS.Log */
jsOMS.Autoloader.defineNamespace('jsOMS.Log'); jsOMS.Autoloader.defineNamespace('jsOMS.Log');
/** jsOMS.Log.Logger = class {
* @constructor /**
* * @constructor
* @param {boolean} verbose Verbose logging *
* @param {boolean} ui Ui logging * @param {boolean} verbose Verbose logging
* @param {boolean} remote Remote logging * @param {boolean} ui Ui logging
* * @param {boolean} remote Remote logging
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Log.Logger = function (verbose, ui, remote) */
{ constructor (verbose, ui, remote)
this.verbose = typeof verbose !== 'undefined' ? verbose : true; {
this.ui = typeof ui !== 'undefined' ? ui : true; this.verbose = typeof verbose !== 'undefined' ? verbose : true;
this.remote = typeof remote !== 'undefined' ? remote : false; this.ui = typeof ui !== 'undefined' ? ui : true;
}; this.remote = typeof remote !== 'undefined' ? remote : false;
};
/**
* Get logging instance
*
* @param {boolean} [verbose] Verbose logging
* @param {boolean} [ui] Ui logging
* @param {boolean} [remote] Remote logging
*
* @return {Object}
*
* @method
*
* @since 1.0.0
*/
static getInstance (verbose, ui, remote)
{
if(!jsOMS.Log.Logger.instance) {
jsOMS.Log.Logger.instance = new jsOMS.Log.Logger(verbose, ui, remote);
}
return jsOMS.Log.Logger.instance;
};
/**
* Interpolate message
*
* @param {string} message Message structure
* @param {Object} [context] Context to put into message
* @param {string} [level] Log level
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
interpolate (message, context, level)
{
let newMessage = jsOMS.Log.Logger.MSG_FULL;
for (let replace in context) {
if (context.hasOwnProperty(replace)) {
newMessage = newMessage.replace('{' + replace + '}', context[replace]);
}
}
return newMessage;
};
/**
* Create context
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
* @param {string} level Log level
*
* @return {Object}
*
* @method
*
* @since 1.0.0
*/
createContext (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;
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
* @param {string} level Log level
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
write (message, context, level)
{
context = this.createContext(message, context, level);
if (this.verbose) {
let color = '000';
switch (level) {
case 'info':
case 'notice':
case 'log':
color = '000';
break;
case 'debug':
color = '289E39';
break;
case 'warning':
case 'alert':
color = 'FFA600';
break;
case 'error':
case 'critical':
case 'emergency':
color = 'CF304A';
break;
default:
}
console.log('%c' + this.interpolate(message, context, level), 'color: #' + color);
}
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();
}
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
emergency (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.EMERGENCY);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
alert (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.ALERT);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
critical (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.CRITICAL);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
error (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.ERROR);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
warning (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.WARNING);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
notice (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.NOTICE);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
info (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.INFO);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
debug (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.DEBUG);
};
/**
* Create log message
*
* @param {string} level Log level
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
log (level, message, context = {})
{
this.write(message, context, level);
};
/**
* Create log message
*
* @param {string} level Log level
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
console (level, message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.INFO);
};
}
jsOMS.Log.Logger.instance = null; jsOMS.Log.Logger.instance = null;
/**
* Get logging instance
*
* @param {boolean} [verbose] Verbose logging
* @param {boolean} [ui] Ui logging
* @param {boolean} [remote] Remote logging
*
* @return {Object}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.getInstance = function(verbose, ui, remote)
{
if(!jsOMS.Log.Logger.instance) {
jsOMS.Log.Logger.instance = new jsOMS.Log.Logger(verbose, ui, remote);
}
return jsOMS.Log.Logger.instance;
};
jsOMS.Log.Logger.MSG_FULL = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}'; jsOMS.Log.Logger.MSG_FULL = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}';
/**
* Interpolate message
*
* @param {string} message Message structure
* @param {Object} [context] Context to put into message
* @param {string} [level] Log level
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.interpolate = function (message, context, level)
{
let newMessage = jsOMS.Log.Logger.MSG_FULL;
for (let replace in context) {
if (context.hasOwnProperty(replace)) {
newMessage = newMessage.replace('{' + replace + '}', context[replace]);
}
}
return newMessage;
};
/**
* Create context
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
* @param {string} level Log level
*
* @return {Object}
*
* @method
*
* @since 1.0.0
*/
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;
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
* @param {string} level Log level
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.write = function (message, context, level)
{
context = this.createContext(message, context, level);
if (this.verbose) {
let color = '000';
switch (level) {
case 'info':
case 'notice':
case 'log':
color = '000';
break;
case 'debug':
color = '289E39';
break;
case 'warning':
case 'alert':
color = 'FFA600';
break;
case 'error':
case 'critical':
case 'emergency':
color = 'CF304A';
break;
default:
}
console.log('%c' + this.interpolate(message, context, level), 'color: #' + color);
}
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();
}
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.emergency = function (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.EMERGENCY);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.alert = function (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.ALERT);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.critical = function (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.CRITICAL);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.error = function (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.ERROR);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.warning = function (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.WARNING);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.notice = function (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.NOTICE);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.info = function (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.INFO);
};
/**
* Create log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.debug = function (message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.DEBUG);
};
/**
* Create log message
*
* @param {string} level Log level
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.log = function (level, message, context = {})
{
this.write(message, context, level);
};
/**
* Create log message
*
* @param {string} level Log level
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Log.Logger.prototype.console = function (level, message, context = {})
{
this.write(message, context, jsOMS.Log.LogLevel.INFO);
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,39 +13,41 @@
/** @namespace jsOMS.Message.Notification.App */ /** @namespace jsOMS.Message.Notification.App */
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification.App'); jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification.App');
jsOMS.Message.Notification.App.AppNotification = function() jsOMS.Message.Notification.App.AppNotification = class {
{ constructor ()
this.status = 0;
};
jsOMS.Message.Notification.App.AppNotification.prototype.setStatus = function(status)
{
this.status = status;
};
jsOMS.Message.Notification.App.AppNotification.prototype.requestPermission = function()
{
const self = this;
};
jsOMS.Message.Notification.App.AppNotification.prototype.send = function(msg)
{
const tpl = document.getElementById('app-message');
if (tpl === null) {
return;
}
let output = document.importNode(tpl.content, true);
output.querySelector('.log-msg').classList.add('log-msg-status-' + msg.status);
output.querySelector('.log-msg-title').innerHTML = msg.title;
output.querySelector('.log-msg-content').innerHTML = msg.message;
tpl.parentNode.appendChild(output);
setTimeout(function ()
{ {
document.getElementsByClassName('log-msg')[0].remove(); this.status = 0;
}, 3000); };
};
setStatus (status)
{
this.status = status;
};
requestPermission ()
{
const self = this;
};
send (msg)
{
const tpl = document.getElementById('app-message');
if (tpl === null) {
return;
}
let output = document.importNode(tpl.content, true);
output.querySelector('.log-msg').classList.add('log-msg-status-' + msg.status);
output.querySelector('.log-msg-title').innerHTML = msg.title;
output.querySelector('.log-msg-content').innerHTML = msg.message;
tpl.parentNode.appendChild(output);
setTimeout(function ()
{
document.getElementsByClassName('log-msg')[0].remove();
}, 3000);
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,35 +13,37 @@
/** @namespace jsOMS.Message.Notification.Browser */ /** @namespace jsOMS.Message.Notification.Browser */
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification.Browser'); jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification.Browser');
jsOMS.Message.Notification.Browser.BrowserNotification = function() jsOMS.Message.Notification.Browser.BrowserNotification = class {
{ constructor()
this.status = 0; {
}; this.status = 0;
};
jsOMS.Message.Notification.Browser.BrowserNotification.prototype.setStatus = function(status) setStatus (status)
{ {
this.status = status; this.status = status;
}; };
jsOMS.Message.Notification.Browser.BrowserNotification.prototype.requestPermission = function() requestPermission ()
{ {
const self = this; const self = this;
/** global: Notification */ /** global: Notification */
if(Notification.permission !== 'granted' && Notification.permission !== 'denied') { if(Notification.permission !== 'granted' && Notification.permission !== 'denied') {
Notification.requestPermission(function(permission) { Notification.requestPermission(function(permission) {
if(permission === 'granted') { if(permission === 'granted') {
let msg = new jsOMS.Message.Notification.NotificationMessage(); let msg = new jsOMS.Message.Notification.NotificationMessage();
self.send(msg); self.send(msg);
} }
}); });
} }
}; };
jsOMS.Message.Notification.Browser.BrowserNotification.prototype.send = function(msg) send (msg)
{ {
/** global: Notification */ /** global: Notification */
let n = new Notification(/* ... */); let n = new Notification(/* ... */);
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,28 +13,30 @@
/** @namespace jsOMS.Message.Notification */ /** @namespace jsOMS.Message.Notification */
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification'); jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification');
jsOMS.Message.Notification.NotificationManager = function() jsOMS.Message.Notification.NotificationManager = class {
{ constructor()
this.appNotifier = new jsOMS.Message.Notification.App.AppNotification(); {
this.browserNotifier = new jsOMS.Message.Notification.Browser.BrowserNotification(); this.appNotifier = new jsOMS.Message.Notification.App.AppNotification();
}; this.browserNotifier = new jsOMS.Message.Notification.Browser.BrowserNotification();
};
jsOMS.Message.Notification.NotificationManager.prototype.send = function(message, type) send (message, type)
{ {
if (jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION === type) { if (jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION === type) {
this.appNotifier.send(message); this.appNotifier.send(message);
} else { } else {
this.browserNotifier.send(message); this.browserNotifier.send(message);
} }
}; };
jsOMS.Message.Notification.NotificationManager.prototype.getAppNotifier = function() getAppNotifier ()
{ {
return this.appNotifier; return this.appNotifier;
}; };
jsOMS.Message.Notification.NotificationManager.prototype.getBrowserNotifier = function() getBrowserNotifier ()
{ {
return this.browserNotifier; return this.browserNotifier;
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -12,10 +12,12 @@
/** @namespace jsOMS.Message.Notification.App */ /** @namespace jsOMS.Message.Notification.App */
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification'); jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification');
jsOMS.Message.Notification.NotificationMessage = function (status, title, message) jsOMS.Message.Notification.NotificationMessage = class {
{ constructor(status, title, message)
this.status = status; {
this.title = title; this.status = status;
this.message = message; this.title = title;
}; this.message = message;
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,369 +13,371 @@
/** @namespace jsOMS.Message.Request */ /** @namespace jsOMS.Message.Request */
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request');
/** jsOMS.Message.Request.Request = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Message.Request.Request = function (uri, method, type) */
{ constructor (uri, method, type)
this.uri = typeof uri !== 'undefined' ? uri : null;
this.method = typeof method !== 'undefined' ? method : jsOMS.Message.Request.RequestMethod.GET;
this.requestHeader = [];
this.result = {};
this.type = typeof type !== 'undefined' ? type : jsOMS.Message.Response.ResponseType.JSON;
this.data = {};
// todo: create log;
this.result[0] = function ()
{ {
//console.log('invalid response'); this.uri = typeof uri !== 'undefined' ? uri : null;
this.method = typeof method !== 'undefined' ? method : jsOMS.Message.Request.RequestMethod.GET;
this.requestHeader = [];
this.result = {};
this.type = typeof type !== 'undefined' ? type : jsOMS.Message.Response.ResponseType.JSON;
this.data = {};
// todo: create log;
this.result[0] = function()
{
//console.log('invalid response');
};
/** global: XMLHttpRequest */
this.xhr = new XMLHttpRequest();
}; };
/** global: XMLHttpRequest */ /**
this.xhr = new XMLHttpRequest(); * Get browser.
}; *
* @return {string}
/** *
* Get browser. * @method
* *
* @return {string} * @since 1.0.0
* */
* @method static getBrowser()
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.getBrowser = function ()
{
/** global: InstallTrigger */
/** global: navigator */
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;
}
return jsOMS.Message.Request.BrowserType.UNKNOWN;
};
/**
* Get os.
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.getOS = function ()
{
for (let os in jsOMS.Message.Request.OSType) {
if (jsOMS.Message.Request.OSType.hasOwnProperty(os)) {
/** global: navigator */
if (navigator.appVersion.toLowerCase().indexOf(jsOMS.Message.Request.OSType[os]) !== -1) {
return jsOMS.Message.Request.OSType[os];
}
}
}
return jsOMS.Message.Request.OSType.UNKNOWN;
};
/**
* Set request method.
*
* EnumRequestMethod
*
* @param {string} method Method type
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.setMethod = function (method)
{
this.method = method;
};
/**
* Get request method.
*
* EnumRequestMethod
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.getMethod = function ()
{
return this.method;
};
/**
* Set response type.
*
* EnumResponseType
*
* @param {string} type Method type
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.setResponseType = function (type)
{
this.xhr.responseType = type;
};
/**
* Get response type.
*
* EnumResponseType
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.getResponseType = function ()
{
return this.responseType;
};
/**
* Set request header.
*
* @param {string} type Request type
* @param {string} header Request header
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.setRequestHeader = function (type, header)
{
this.requestHeader[type] = header;
};
/**
* Get request header.
*
* @return {Array}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.getRequestHeader = function ()
{
return this.requestHeader;
};
/**
* Set request uri.
*
* @param {string} uri Request uri
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.setUri = function (uri)
{
this.uri = uri;
};
/**
* Get request uri.
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.getUri = function ()
{
return this.uri;
};
/**
* Set success callback.
*
* @callback requestCallback
* @param {requestCallback} callback - Success callback
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.setSuccess = function (callback)
{
this.result[200] = callback;
};
/**
* Set result callback.
*
* @param {int} status Http response status
* @param {function} callback Callback
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.setResultCallback = function (status, callback)
{
this.result[status] = callback;
};
/**
* Set request data.
*
* @param {Array} data Request data
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.setData = function (data)
{
this.data = data;
};
/**
* Get request data.
*
* @return {Array}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.getData = function ()
{
return this.data;
};
/**
* Set request type.
*
* EnumRequestType
*
* @param {string} type Method type
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.setType = function (type)
{
this.type = type;
};
/**
* Get request type.
*
* EnumRequestType
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.getType = function ()
{
return this.type;
};
/**
* Create query from object.
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.queryfy = function (obj)
{
const str = [];
for (let p in obj) {
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
}
return str.join("&");
};
/**
* Get request data.
*
* @return {Array}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Message.Request.Request.prototype.send = function ()
{
const self = this;
if (this.xhr.readyState !== 1) {
this.xhr.open(this.method, jsOMS.Uri.UriFactory.build(this.uri));
for (let p in this.requestHeader) {
if (this.requestHeader.hasOwnProperty(p)) {
this.xhr.setRequestHeader(p, this.requestHeader[p]);
}
}
}
this.xhr.onreadystatechange = function ()
{ {
switch (self.xhr.readyState) { /** global: InstallTrigger */
case 4: /** global: navigator */
if (typeof self.result[self.xhr.status] === 'undefined') { if ((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) {
self.result[0](self.xhr); return jsOMS.Message.Request.BrowserType.OPERA;
} else { } else if (typeof InstallTrigger !== 'undefined') {
self.result[self.xhr.status](self.xhr); return jsOMS.Message.Request.BrowserType.FIREFOX;
} else if (Object.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;
}
return jsOMS.Message.Request.BrowserType.UNKNOWN;
};
/**
* Get os.
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
static getOS()
{
for (let os in jsOMS.Message.Request.OSType) {
if (jsOMS.Message.Request.OSType.hasOwnProperty(os)) {
/** global: navigator */
if (navigator.appVersion.toLowerCase().indexOf(jsOMS.Message.Request.OSType[os]) !== -1) {
return jsOMS.Message.Request.OSType[os];
} }
break; }
case 2:
// todo: handle server received request
break;
case 3:
// todo: server is handling request
break;
default:
// todo: create handler for error returns
} }
return jsOMS.Message.Request.OSType.UNKNOWN;
}; };
if (this.type === jsOMS.Message.Request.RequestType.JSON) { /**
if (typeof this.requestHeader !== 'undefined' && this.requestHeader['Content-Type'] === 'application/json') { * Set request method.
this.xhr.send(JSON.stringify(this.data)); *
} else { * EnumRequestMethod
this.xhr.send(this.queryfy(this.data)); *
* @param {string} method Method type
*
* @method
*
* @since 1.0.0
*/
setMethod(method)
{
this.method = method;
};
/**
* Get request method.
*
* EnumRequestMethod
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getMethod()
{
return this.method;
};
/**
* Set response type.
*
* EnumResponseType
*
* @param {string} type Method type
*
* @method
*
* @since 1.0.0
*/
setResponseType(type)
{
this.xhr.responseType = type;
};
/**
* Get response type.
*
* EnumResponseType
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getResponseType()
{
return this.responseType;
};
/**
* Set request header.
*
* @param {string} type Request type
* @param {string} header Request header
*
* @method
*
* @since 1.0.0
*/
setRequestHeader(type, header)
{
this.requestHeader[type] = header;
};
/**
* Get request header.
*
* @return {Array}
*
* @method
*
* @since 1.0.0
*/
getRequestHeader()
{
return this.requestHeader;
};
/**
* Set request uri.
*
* @param {string} uri Request uri
*
* @method
*
* @since 1.0.0
*/
setUri(uri)
{
this.uri = uri;
};
/**
* Get request uri.
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getUri()
{
return this.uri;
};
/**
* Set success callback.
*
* @callback requestCallback
* @param {requestCallback} callback - Success callback
*
* @method
*
* @since 1.0.0
*/
setSuccess(callback)
{
this.result[200] = callback;
};
/**
* Set result callback.
*
* @param {int} status Http response status
* @param {function} callback Callback
*
* @method
*
* @since 1.0.0
*/
setResultCallback(status, callback)
{
this.result[status] = callback;
};
/**
* Set request data.
*
* @param {Array} data Request data
*
* @method
*
* @since 1.0.0
*/
setData(data)
{
this.data = data;
};
/**
* Get request data.
*
* @return {Array}
*
* @method
*
* @since 1.0.0
*/
getData()
{
return this.data;
};
/**
* Set request type.
*
* EnumRequestType
*
* @param {string} type Method type
*
* @method
*
* @since 1.0.0
*/
setType(type)
{
this.type = type;
};
/**
* Get request type.
*
* EnumRequestType
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getType()
{
return this.type;
};
/**
* Create query from object.
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
queryfy(obj)
{
const str = [];
for (let p in obj) {
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
} }
} else if (this.type === jsOMS.Message.Request.RequestType.RAW) {
this.xhr.send(this.data); return str.join("&");
} };
};
/**
* Get request data.
*
* @return {Array}
*
* @method
*
* @since 1.0.0
*/
send()
{
const self = this;
if (this.xhr.readyState !== 1) {
this.xhr.open(this.method, jsOMS.Uri.UriFactory.build(this.uri));
for (let p in this.requestHeader) {
if (this.requestHeader.hasOwnProperty(p)) {
this.xhr.setRequestHeader(p, this.requestHeader[p]);
}
}
}
this.xhr.onreadystatechange = function()
{
switch (self.xhr.readyState) {
case 4:
if (typeof self.result[self.xhr.status] === 'undefined') {
self.result[0](self.xhr);
} else {
self.result[self.xhr.status](self.xhr);
}
break;
case 2:
// todo: handle server received request
break;
case 3:
// todo: server is handling request
break;
default:
// todo: create handler for error returns
}
};
if (this.type === jsOMS.Message.Request.RequestType.JSON) {
if (typeof this.requestHeader !== 'undefined' && this.requestHeader['Content-Type'] === 'application/json') {
this.xhr.send(JSON.stringify(this.data));
} else {
this.xhr.send(this.queryfy(this.data));
}
} else if (this.type === jsOMS.Message.Request.RequestType.RAW) {
this.xhr.send(this.data);
}
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -15,23 +15,25 @@
/** @namespace jsOMS.Message.Response */ /** @namespace jsOMS.Message.Response */
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response');
jsOMS.Message.Response.Response = function (data) jsOMS.Message.Response.Response = class {
{ constructor (data)
this.responses = data; {
}; this.responses = data;
};
jsOMS.Message.Response.Response.prototype.get = function (id) get (id)
{ {
return this.responses[id]; return this.responses[id];
}; };
jsOMS.Message.Response.Response.prototype.getByIndex = function (index) getByIndex (index)
{ {
return this.responses[index]; return this.responses[index];
}; };
jsOMS.Message.Response.Response.prototype.count = function () count ()
{ {
return this.responses.length; return this.responses.length;
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -15,60 +15,62 @@
/** @namespace jsOMS.Message.Response */ /** @namespace jsOMS.Message.Response */
jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response');
/** jsOMS.Message.Response.ResponseManager = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Message.Response.ResponseManager = function () */
{ constructor()
this.messages = {}; {
}; this.messages = {};
};
/** /**
* Add response handler. * Add response handler.
* *
* This allows the response handler to generally handle responses and also handle specific requests if defined. * This allows the response handler to generally handle responses and also handle specific requests if defined.
* *
* @param {string} key Response key * @param {string} key Response key
* @param {requestCallback} message Callback for message * @param {requestCallback} message Callback for message
* @param {string} [request] Request id in order to only handle a specific request * @param {string} [request] Request id in order to only handle a specific request
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Message.Response.ResponseManager.prototype.add = function (key, message, request) add(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') {
this.messages[key] = []; this.messages[key] = [];
} }
this.messages[key][request] = message; this.messages[key][request] = message;
}; };
/** /**
* Execute a predefined callback. * Execute a predefined callback.
* *
* Tries to execute a request specific callback or otherwise a general callback if defined. * Tries to execute a request specific callback or otherwise a general callback if defined.
* *
* @param {string} key Response key * @param {string} key Response key
* @param {Array|Object} data Date to use in callback * @param {Array|Object} data Date to use in callback
* @param {jsOMS.Message.Request.Request} [request] Request id for request specific execution * @param {jsOMS.Message.Request.Request} [request] Request id for request specific execution
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Message.Response.ResponseManager.prototype.run = function (key, data, request) run(key, data, request)
{ {
if (typeof request !== 'undefined' && typeof this.messages[key] !== 'undefined' && typeof this.messages[key][request] !== 'undefined') { if (typeof request !== 'undefined' && typeof this.messages[key] !== 'undefined' && typeof this.messages[key][request] !== 'undefined') {
this.messages[key][request](data); this.messages[key][request](data);
} else if (typeof this.messages[key] !== 'undefined') { } else if (typeof this.messages[key] !== 'undefined') {
this.messages[key].any(data); this.messages[key].any(data);
} else { } else {
jsOMS.Log.Logger.instance.warning('Undefined type: ' + key); jsOMS.Log.Logger.instance.warning('Undefined type: ' + key);
} }
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -12,29 +12,31 @@
jsOMS.Autoloader.defineNamespace('jsOMS.Module'); jsOMS.Autoloader.defineNamespace('jsOMS.Module');
/** jsOMS.Module.ModuleFactory = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Module.ModuleFactory = function () */
{ constructor ()
}; {
};
/** /**
* Get module instance. * Get module instance.
* *
* @param {string} module Module name * @param {string} module Module name
* @param {Object} app Application reference * @param {Object} app Application reference
* *
* @return {Object} * @return {Object}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Module.ModuleFactory.getInstance = function (module, app) static getInstance (module, app)
{ {
return new jsOMS.Modules[module](app); return new jsOMS.Modules[module](app);
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,34 +13,36 @@
/** @namespace jsOMS.Module */ /** @namespace jsOMS.Module */
jsOMS.Autoloader.defineNamespace('jsOMS.Module'); jsOMS.Autoloader.defineNamespace('jsOMS.Module');
/** jsOMS.Module.ModuleManager = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Module.ModuleManager = function (app) */
{ constructor(app)
this.modules = {}; {
this.app = app; this.modules = {};
}; this.app = app;
};
/** /**
* Get module. * Get module.
* *
* @param {string} module Module name * @param {string} module Module name
* *
* @return {Object} * @return {Object}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Module.ModuleManager.prototype.get = function (module) get (module)
{ {
if (typeof this.modules[module] === 'undefined') { if (typeof this.modules[module] === 'undefined') {
this.modules[module] = jsOMS.Module.ModuleFactory.getInstance(module, this.app); this.modules[module] = jsOMS.Module.ModuleFactory.getInstance(module, this.app);
} }
return this.modules[module]; return this.modules[module];
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -3,17 +3,19 @@
jsOMS.Autoloader.defineNamespace('jsOMS.Route'); jsOMS.Autoloader.defineNamespace('jsOMS.Route');
// TODO: create comments jsOMS.Route.Route = class {
jsOMS.Route.Route = function () // TODO: create comments
{ constructor ()
this.routes = null; {
}; this.routes = null;
};
// TODO: create comments // TODO: create comments
jsOMS.Route.prototype.add = function (path, callback, exact) add (path, callback, exact)
{ {
exact = typeof exact !== 'undefined' ? exact : true; exact = typeof exact !== 'undefined' ? exact : true;
// todo: create array key path like i did for php // todo: create array key path like i did for php
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -96,6 +96,7 @@
for (let j = 0; j < length; ++j) { for (let j = 0; j < length; ++j) {
self.bindListener(data.addedNodes[j].id, listeners[i], true); self.bindListener(data.addedNodes[j].id, listeners[i], true);
// todo only make removable if action itself is defined as auto removable
} }
}); });
@ -127,13 +128,14 @@
for (let j = 1; j < actionLength; ++j) { for (let j = 1; j < actionLength; ++j) {
if (typeof id === 'undefined' || typeof listener.key === 'undefined') { if (typeof id === 'undefined' || typeof listener.key === 'undefined') {
throw 'Invalid element id/key.' jsOMS.Log.Logger.instance.error('Invalid element id/key: ' + id + '/' + listener.key);
return;
} }
this.app.eventManager.attach(id + '-' + listener.key + '-' + listener.action[j - 1].key, function (data) this.app.eventManager.attach(id + '-' + listener.key + '-' + listener.action[j - 1].key, function (data)
{ {
self.runAction(id, listener, listener.action[j], data); self.runAction(id, listener, listener.action[j], data);
}, removable, true); // todo: make actions removable e.g. in case of child elements getting removed = tag list }, removable, true);
} }
// todo: the true here is a memory leak since it should be removed at some point?! // todo: the true here is a memory leak since it should be removed at some point?!
// todo: handle onload action right after registering everything. this will be used for onload api calls in order to get content such as lists or models. Maybe in the main application after registering a invoke('onload') should be called if the application wants to execute the onload elements // todo: handle onload action right after registering everything. this will be used for onload api calls in order to get content such as lists or models. Maybe in the main application after registering a invoke('onload') should be called if the application wants to execute the onload elements

View File

@ -13,258 +13,258 @@
/** @namespace jsOMS.UI */ /** @namespace jsOMS.UI */
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Component'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.Component');
/** jsOMS.UI.Component.Form = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.Component.Form = function (app) */
{ constructor (app)
this.app = app; {
this.forms = {}; this.app = app;
this.ignore = {}; this.forms = {};
}; this.ignore = {};
};
/** /**
* Get form * Get form
* *
* @param {string} id Form Id * @param {string} id Form Id
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Component.Form.prototype.get = function (id) get (id)
{ {
return this.forms[id]; return this.forms[id];
}; };
/** /**
* Is form ignored? * Is form ignored?
* *
* @param {string} id Form Id * @param {string} id Form Id
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Component.Form.prototype.isIgnored = function (id) isIgnored (id)
{ {
return this.ignore.indexOf(id) !== -1; return this.ignore.indexOf(id) !== -1;
}; };
/** /**
* Unbind form * Unbind form
* *
* @param {string} id Form Id * @param {string} id Form Id
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Component.Form.prototype.unbind = function (id) unbind (id)
{ {
}; };
/** /**
* Bind form * Bind form
* *
* @param {string} id Form Id (optional) * @param {string} id Form Id (optional)
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Component.Form.prototype.bind = function (id) bind (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 {
const forms = document.getElementsByTagName('form'), const forms = document.getElementsByTagName('form'),
length = !forms ? 0 : forms.length; length = !forms ? 0 : forms.length;
for (let i = 0; i < length; ++i) {
if (typeof forms[i].getAttribute('id') !== 'undefined' && forms[i].getAttribute('id') !== null && typeof this.ignore[forms[i].getAttribute('id')] === 'undefined') {
this.bindForm(forms[i].getAttribute('id'));
}
}
}
};
/**
* Bind form
*
* @param {string} id Form Id
*
* @since 1.0.0
*/
bindForm (id)
{
if (typeof id === 'undefined' || !id) {
jsOMS.Log.Logger.instance.info('A form doesn\'t have an ID.');
return;
}
const self = this;
this.forms[id] = new jsOMS.Views.FormView(id);
this.unbind(id);
const submits = this.forms[id].getSubmit(),
length = submits.length;
for (let i = 0; i < length; ++i) { for (let i = 0; i < length; ++i) {
if (typeof forms[i].getAttribute('id') !== 'undefined' && forms[i].getAttribute('id') !== null && typeof this.ignore[forms[i].getAttribute('id')] === 'undefined') { submits[i].addEventListener('click', function (event)
this.bindForm(forms[i].getAttribute('id')); {
} jsOMS.preventAll(event);
self.submit(self.forms[id]);
});
} }
} };
};
/** /**
* Bind form * Unbind form
* *
* @param {string} id Form Id * @param {string} id Form Id
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Component.Form.prototype.bindForm = function (id) unbindForm (id)
{ {
if (typeof id === 'undefined' || !id) { // todo: do i need the findex? can't i just use id?
jsOMS.Log.Logger.instance.info('A form doesn\'t have an ID.'); let findex = 0;
return;
}
const self = this; if ((findex = this.forms[id]) !== 'undefined') {
this.forms[id] = new jsOMS.Views.FormView(id); this.forms[id].unbind();
this.forms.splice(findex, 1);
this.unbind(id); return true;
}
const submits = this.forms[id].getSubmit(), return false;
length = submits.length; };
for (let i = 0; i < length; ++i) { /**
submits[i].addEventListener('click', function (event) * Submit form
*
* Calls injections first befor executing the actual form submit
*
* @param {Object} form Form object
*
* @since 1.0.0
*/
submit (form)
{
/* Handle injects */
const self = this,
injects = form.getSubmitInjects();
let counter = 0;
// todo: test if attach necessary (maybe already attached in event manager)
// Register normal form behavior
this.app.eventManager.attach(form.getId(), function ()
{ {
jsOMS.preventAll(event); self.submitForm(form);
self.submit(self.forms[id]);
}); });
}
};
/** // Run all injects first
* Unbind form for (let property in injects) {
* if (injects.hasOwnProperty(property)) {
* @param {string} id Form Id counter++;
* //this.app.eventManager.addGroup(form.getId(), counter);
* @since 1.0.0 const result = injects[property](form, form.getId());
*/
jsOMS.UI.Component.Form.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') { if (result === false) {
this.forms[id].unbind(); return;
this.forms.splice(findex, 1); }
} else {
return true; jsOMS.Log.Logger.instance.warning('Invalid property.');
}
return false;
};
/**
* Submit form
*
* Calls injections first befor executing the actual form submit
*
* @param {Object} form Form object
*
* @since 1.0.0
*/
jsOMS.UI.Component.Form.prototype.submit = function (form)
{
/* Handle injects */
const self = this,
injects = form.getSubmitInjects();
let counter = 0;
// todo: test if attach necessary (maybe already attached in event manager)
// Register normal form behavior
this.app.eventManager.attach(form.getId(), function ()
{
self.submitForm(form);
});
// Run all injects first
for (let property in injects) {
if (injects.hasOwnProperty(property)) {
counter++;
//this.app.eventManager.addGroup(form.getId(), counter);
const result = injects[property](form, form.getId());
if (result === false) {
return;
} }
} else {
jsOMS.Log.Logger.instance.warning('Invalid property.');
} }
}
this.app.eventManager.trigger(form.getId()); this.app.eventManager.trigger(form.getId());
}; };
/** /**
* Submit form data * Submit form data
* *
* Submits the main form data * Submits the main form data
* *
* @param {Object} form Form object * @param {Object} form Form object
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Component.Form.prototype.submitForm = function (form) submitForm (form)
{
if (!form.isValid()) {
jsOMS.Log.Logger.instance.debug('Form "' + form.getId() + '" has invalid values.');
return;
}
if (form.getMethod() !== jsOMS.Message.Request.RequestMethod.GET
&& Math.floor(Date.now()) - form.getLastSubmit() < 500
) {
return;
}
form.updateLastSubmit();
/* Handle default submit */
const request = new jsOMS.Message.Request.Request(),
self = this;
request.setData(form.getData());
request.setType(jsOMS.Message.Response.ResponseType.JSON);
request.setUri(form.getAction());
request.setMethod(form.getMethod());
request.setRequestHeader('Content-Type', 'application/json');
request.setSuccess(function (xhr)
{ {
console.log(xhr.response); if (!form.isValid()) {
jsOMS.Log.Logger.instance.debug('Form "' + form.getId() + '" has invalid values.');
return;
}
try { if (form.getMethod() !== jsOMS.Message.Request.RequestMethod.GET
const o = JSON.parse(xhr.response), && Math.floor(Date.now()) - form.getLastSubmit() < 500
response = new jsOMS.Message.Response.Response(o); ) {
let successInject = null; return;
}
if (typeof o.status !== 'undefined') { form.updateLastSubmit();
self.app.notifyManager.send(
new jsOMS.Message.Notification.NotificationMessage(o.status, o.title, o.message), jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION /* Handle default submit */
const request = new jsOMS.Message.Request.Request(),
self = this;
request.setData(form.getData());
request.setType(jsOMS.Message.Response.ResponseType.JSON);
request.setUri(form.getAction());
request.setMethod(form.getMethod());
request.setRequestHeader('Content-Type', 'application/json');
request.setSuccess(function (xhr)
{
console.log(xhr.response);
try {
const o = JSON.parse(xhr.response),
response = new jsOMS.Message.Response.Response(o);
let successInject = null;
if (typeof o.status !== 'undefined') {
self.app.notifyManager.send(
new jsOMS.Message.Notification.NotificationMessage(o.status, o.title, o.message), jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION
);
}
if ((successInject = form.getSuccess()) !== null) {
successInject(response);
}
} catch (e) {
console.log(e);
jsOMS.Log.Logger.instance.error('Invalid form response. \n'
+ 'URL: ' + form.getAction() + '\n'
+ 'Request: ' + JSON.stringify(form.getData()) + '\n'
+ 'Response: ' + xhr.response
); );
} }
});
if ((successInject = form.getSuccess()) !== null) { request.setResultCallback(0, function (xhr)
successInject(response); {
} else { self.app.notifyManager.send(
self.app.responseManager.run(response.get(0).type, response.get(0), request); new jsOMS.Message.Notification.NotificationMessage(
} jsOMS.Message.Notification.NotificationLevel.ERROR,
} catch (e) { 'Failure',
console.log(e); 'Some failure happend'
), jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION
jsOMS.Log.Logger.instance.error('Invalid form response. \n'
+ 'URL: ' + form.getAction() + '\n'
+ 'Request: ' + JSON.stringify(form.getData()) + '\n'
+ 'Response: ' + xhr.response
); );
} });
});
request.setResultCallback(0, function (xhr) request.send();
};
/**
* Count the bound forms
*
* @return {number}
*
* @since 1.0.0
*/
count ()
{ {
self.app.notifyManager.send( return this.forms.length;
new jsOMS.Message.Notification.NotificationMessage( };
jsOMS.Message.Notification.NotificationLevel.ERROR, }
'Failure',
'Some failure happend'
), jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION
);
});
request.send();
};
/**
* Count the bound forms
*
* @return {number}
*
* @since 1.0.0
*/
jsOMS.UI.Component.Form.prototype.count = function ()
{
return this.forms.length;
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,146 +13,148 @@
/** @namespace jsOMS.UI.Input*/ /** @namespace jsOMS.UI.Input*/
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input');
/** jsOMS.UI.Input = class {
* Unbind input element /**
* * Unbind input element
* @param {Object} input Input element *
* * @param {Object} input Input element
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.Input.unbind = function (input) */
{ static unbind = function (input)
this.app.inputManager.getKeyboardManager().unbind(input);
/** global: changeBind */
input.removeEventListener('change', changeBind, false);
};
/**
* Bind input elment
*
* @param {Object} input Input elment
*
* @since 1.0.0
*/
jsOMS.UI.Input.bindElement = function (input)
{
if (typeof input === 'undefined') {
throw 'Input element required'
}
const self = this;
input.addEventListener('change', function changeBind(event)
{ {
/* Handle remote datalist/autocomplete input element */ this.app.inputManager.getKeyboardManager().unbind(input);
let listId, list; /** global: changeBind */
if (typeof (listId = this.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') { input.removeEventListener('change', changeBind, false);
self.addRemoteDatalistOptions(this, list); };
/**
* Bind input elment
*
* @param {Object} input Input elment
*
* @since 1.0.0
*/
static bindElement = function (input)
{
if (typeof input === 'undefined') {
throw 'Input element required'
} }
/* Handle html defined functions */ const self = this;
let change;
if (typeof (change = this.getAttribute('data-change-func')) !== 'undefined') {
change(this);
}
/* Handle pre-defined dynamic change events */ input.addEventListener('change', function changeBind(event)
let ref;
if (typeof (ref = this.getAttribute('data-ref')) !== 'undefined') {
let e = document.getElementById(ref);
if (!e) {
return;
}
switch (e.tagName) {
case 'ul':
break;
case 'table':
break;
default:
}
}
});
let dataButton;
if (typeof (dataButton = input.getAttribute('data-button')) !== 'undefined') {
this.app.inputManager.getKeyboardManager().bind(input, 13, function ()
{ {
const db = document.getElementById(dataButton); /* Handle remote datalist/autocomplete input element */
let listId, list;
if (db) { if (typeof (listId = this.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') {
db.click(); self.addRemoteDatalistOptions(this, list);
} }
});
}
};
/** /* Handle html defined functions */
* Add remote datalist options let change;
* if (typeof (change = this.getAttribute('data-change-func')) !== 'undefined') {
* This only applies for datalists that have remote options change(this);
* }
* @param {Object} input Input elment
* @param {Object} datalist Datalist elment
*
* @since 1.0.0
*/
jsOMS.UI.Input.addRemoteDatalistOptions = function (input, datalist)
{
this.clearDatalistOptions(datalist);
const request = new jsOMS.Message.Request(); /* Handle pre-defined dynamic change events */
request.setData(input.value); let ref;
request.setType(jsOMS.Message.Response.ResponseType.JSON); if (typeof (ref = this.getAttribute('data-ref')) !== 'undefined') {
request.setUri(datalist.getAttribute('data-list-src')); let e = document.getElementById(ref);
request.setMethod(jsOMS.Message.Request.RequestMethod.POST);
request.setRequestHeader('Content-Type', 'application/json');
request.setSuccess(function (xhr)
{
try {
const o = JSON.parse(xhr.response),
response = new jsOMS.Message.Response(o),
responseLength = response.count();
let tempResponse = null,
success = null;
for (let k = 0; k < responseLength; ++k) { if (!e) {
tempResponse = response.getByIndex(k); return;
}
let option = null, switch (e.tagName) {
data = tempResponse.getData(), case 'ul':
length = data.length; break;
case 'table':
for (let i = 0; i < length; ++i) { break;
option = document.createElement('option'); default:
option.value = tempResponse.value;
option.text = tempResponse.text;
datalist.appendChild(option);
} }
} }
} catch (exception) { });
jsOMS.Log.Logger.instance.error('Invalid JSON object: ' + xhr, 'FormManager');
let dataButton;
if (typeof (dataButton = input.getAttribute('data-button')) !== 'undefined') {
this.app.inputManager.getKeyboardManager().bind(input, 13, function ()
{
const db = document.getElementById(dataButton);
if (db) {
db.click();
}
});
} }
}); };
request.send(); /**
}; * Add remote datalist options
*
* This only applies for datalists that have remote options
*
* @param {Object} input Input elment
* @param {Object} datalist Datalist elment
*
* @since 1.0.0
*/
static addRemoteDatalistOptions = function (input, datalist)
{
this.clearDatalistOptions(datalist);
/** const request = new jsOMS.Message.Request();
* Remove all datalist options from datalist request.setData(input.value);
* request.setType(jsOMS.Message.Response.ResponseType.JSON);
* @param {Object} datalist Datalist elment request.setUri(datalist.getAttribute('data-list-src'));
* request.setMethod(jsOMS.Message.Request.RequestMethod.POST);
* @since 1.0.0 request.setRequestHeader('Content-Type', 'application/json');
*/ request.setSuccess(function (xhr)
jsOMS.UI.Input.clearDatalistOptions = function (datalist) {
{ try {
const length = datalist.options.length; const o = JSON.parse(xhr.response),
response = new jsOMS.Message.Response(o),
responseLength = response.count();
let tempResponse = null,
success = null;
for (let i = 0; i < length; ++i) { for (let k = 0; k < responseLength; ++k) {
datalist.remove(0); tempResponse = response.getByIndex(k);
}
}; 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) {
jsOMS.Log.Logger.instance.error('Invalid JSON object: ' + xhr, 'FormManager');
}
});
request.send();
};
/**
* Remove all datalist options from datalist
*
* @param {Object} datalist Datalist elment
*
* @since 1.0.0
*/
static clearDatalistOptions = function (datalist)
{
const length = datalist.options.length;
for (let i = 0; i < length; ++i) {
datalist.remove(0);
}
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -12,70 +12,72 @@
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Component'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.Component');
/** jsOMS.UI.Component.Tab = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.Component.Tab = function (responseManager) */
{ constructor (responseManager)
this.responseManager = responseManager;
};
/**
* Bind & rebind UI elements.
*
* @param {string} [id] Element id
*
* @method
*
* @since 1.0.0
*/
jsOMS.UI.Component.Tab.prototype.bind = function (id)
{
if (typeof id !== 'undefined') {
const e = document.getElementById(id);
if (e) {
this.bindElement();
}
} else {
const tabs = document.querySelectorAll('.tabview'),
length = !tabs ? 0 : tabs.length;
for (let i = 0; i < length; ++i) {
this.bindElement(tabs[i]);
}
}
};
/**
* Bind & rebind UI element.
*
* @param {Object} [e] Element id
*
* @method
*
* @since 1.0.0
*/
jsOMS.UI.Component.Tab.prototype.bindElement = function (e)
{
const nodes = e.querySelectorAll('.tab-links a');
nodes.addEventListener('click', function (evt)
{ {
/* Change Tab */ this.responseManager = responseManager;
const attr = this.getAttribute('href').substring(1), };
cont = this.parentNode.parentNode.parentNode.children[1];
jsOMS.removeClass(jsOMS.getByClass(this.parentNode.parentNode, 'active'), 'active'); /**
jsOMS.addClass(this.parentNode, 'active'); * Bind & rebind UI elements.
jsOMS.removeClass(jsOMS.getByClass(cont, 'active'), 'active'); *
jsOMS.addClass(jsOMS.getByClass(cont, attr), 'active'); * @param {string} [id] Element id
*
* @method
*
* @since 1.0.0
*/
bind (id)
{
if (typeof id !== 'undefined') {
const e = document.getElementById(id);
/* Modify url */ if (e) {
this.bindElement();
}
} else {
const tabs = document.querySelectorAll('.tabview'),
length = !tabs ? 0 : tabs.length;
jsOMS.preventAll(evt); for (let i = 0; i < length; ++i) {
}); this.bindElement(tabs[i]);
}; }
}
};
/**
* Bind & rebind UI element.
*
* @param {Object} [e] Element id
*
* @method
*
* @since 1.0.0
*/
bindElement (e)
{
const nodes = e.querySelectorAll('.tab-links a');
nodes.addEventListener('click', function (evt)
{
/* Change Tab */
const attr = this.getAttribute('href').substring(1),
cont = this.parentNode.parentNode.parentNode.children[1];
jsOMS.removeClass(jsOMS.getByClass(this.parentNode.parentNode, 'active'), 'active');
jsOMS.addClass(this.parentNode, 'active');
jsOMS.removeClass(jsOMS.getByClass(cont, 'active'), 'active');
jsOMS.addClass(jsOMS.getByClass(cont, attr), 'active');
/* Modify url */
jsOMS.preventAll(evt);
});
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -12,53 +12,55 @@
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Component'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.Component');
/** jsOMS.UI.Component.Table = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.Component.Table = function (responseManager) */
{ constructor(responseManager)
this.responseManager = responseManager; {
}; this.responseManager = responseManager;
};
/** /**
* Bind & rebind UI elements. * Bind & rebind UI elements.
* *
* @param {string} [id] Element id * @param {string} [id] Element id
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Component.Table.prototype.bind = function (id) bind (id)
{ {
if (typeof id !== 'undefined') { if (typeof id !== 'undefined') {
const e = document.getElementById(id); const e = document.getElementById(id);
if (e) { if (e) {
this.bindElement(e); this.bindElement(e);
}
} else {
const tables = document.getElementsByTagName('table'),
length = !tables ? 0 : tables.length;
for (let i = 0; i < length; ++i) {
this.bindElement(tables[i]);
}
} }
} else { };
const tables = document.getElementsByTagName('table'),
length = !tables ? 0 : tables.length;
for (let i = 0; i < length; ++i) { /**
this.bindElement(tables[i]); * Bind & rebind UI element.
} *
} * @param {Object} [e] Element id
}; *
* @method
/** *
* Bind & rebind UI element. * @since 1.0.0
* */
* @param {Object} [e] Element id bindElement (e)
* {
* @method };
* }
* @since 1.0.0
*/
jsOMS.UI.Component.Table.prototype.bindElement = function (e)
{
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,115 +13,116 @@
/** @namespace jsOMS.UI.DragNDrop*/ /** @namespace jsOMS.UI.DragNDrop*/
jsOMS.Autoloader.defineNamespace('jsOMS.UI.DragNDrop'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.DragNDrop');
/** jsOMS.UI.DragNDrop = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.DragNDrop = function (app) */
{ constructor (app)
this.app = app; {
this.draggable = {}; this.app = app;
this.dragging = null; this.draggable = {};
}; this.dragging = null;
};
/** /**
* Unbind element * Unbind element
* *
* @param {Object} element DOM element * @param {Object} element DOM element
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.DragNDrop.prototype.unbind = function (element) unbind (element)
{ {
}; };
/** /**
* Bind element * Bind element
* *
* @param {Object} id DOM element * @param {Object} id DOM element
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.DragNDrop.prototype.bind = function (id) bind (id)
{ {
if (typeof id !== 'undefined') { if (typeof id !== 'undefined') {
this.bindElement(id); this.bindElement(id);
} else { } else {
const elements = document.querySelectorAll('[draggable]'), const elements = document.querySelectorAll('[draggable]'),
length = !elements ? 0 : elements.length; length = !elements ? 0 : elements.length;
for (let i = 0; i < length; ++i) { for (let i = 0; i < length; ++i) {
if (typeof elements[i].getAttribute('id') !== 'undefined' && elements[i].getAttribute('id') !== null) { if (typeof elements[i].getAttribute('id') !== 'undefined' && elements[i].getAttribute('id') !== null) {
this.bindElement(elements[i].getAttribute('id')); this.bindElement(elements[i].getAttribute('id'));
}
} }
} }
} };
};
/** /**
* Bind DOM elment * Bind DOM elment
* *
* @param {string} id DOM elment * @param {string} id DOM elment
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.DragNDrop.prototype.bindElement = function (id) bindElement (id)
{ {
const element = document.getElementById(id), const element = document.getElementById(id),
self = this; self = this;
if (!element) { if (!element) {
return;
}
element.addEventListener('dragstart', function(e) {
if (self.dragging === null) {
self.dragging = this;
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/html', this.innerHTML);
}
}, false);
element.addEventListener('dragenter', function(e) {
// todo: highlight
}, false);
element.addEventListener('dragover', function(e) {
e.preventDefault();
e.dataTransfer.dropEffect = 'move';
}, false);
element.addEventListener('dragleave', function(e) {
e.preventDefault();
// todo: don't highlight
}, false);
element.addEventListener('dragend', function(e) {
e.preventDefault();
// todo: reset all changes
}, false);
//element.addEventListener('drag', function(e) {});
element.addEventListener('drop', function(e) {
e.stopPropagation();
e.preventDefault();
if (self.dragging === this) {
return; return;
} }
self.dragging.innerHTML = this.innerHTML; element.addEventListener('dragstart', function(e) {
this.innerHTML = e.dataTransfer.getData('text/html'); if (self.dragging === null) {
self.dragging = this;
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/html', this.innerHTML);
}
}, false);
// todo: add to now destination element.addEventListener('dragenter', function(e) {
// todo: remove from old destination // todo: highlight
}, false);
self.dragging = null; element.addEventListener('dragover', function(e) {
}, false); e.preventDefault();
e.dataTransfer.dropEffect = 'move';
}, false);
element.addEventListener('dragleave', function(e) {
e.preventDefault();
// todo: don't highlight
}, false);
element.addEventListener('dragend', function(e) {
e.preventDefault();
// todo: reset all changes
}, false);
//element.addEventListener('drag', function(e) {});
element.addEventListener('drop', function(e) {
e.stopPropagation();
e.preventDefault();
if (self.dragging === this) {
return;
}
self.dragging.innerHTML = this.innerHTML;
this.innerHTML = e.dataTransfer.getData('text/html');
// todo: add to now destination
// todo: remove from old destination
self.dragging = null;
}, false);
}
} }
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,93 +13,94 @@
/** @namespace jsOMS.UI */ /** @namespace jsOMS.UI */
jsOMS.Autoloader.defineNamespace('jsOMS.UI'); jsOMS.Autoloader.defineNamespace('jsOMS.UI');
/** jsOMS.UI.GeneralUI = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.GeneralUI = function () */
{ constructor ()
{
this.visObs = null;
};
this.visObs = null; /**
}; * Bind button.
*
/** * @param {string} [id] Button id (optional)
* Bind button. *
* * @method
* @param {string} [id] Button id (optional) *
* * @since 1.0.0
* @method */
* bind (id)
* @since 1.0.0 {
*/ let e = null;
jsOMS.UI.GeneralUI.prototype.bind = function (id) if (typeof id !== 'undefined') {
{ e = document.getElementById(id);
let e = null;
if (typeof id !== 'undefined') {
e = document.getElementById(id);
}
this.bindHref(e);
this.bindLazyLoad(e);
};
/**
* Bind & rebind UI element.
*
* @param {Object} [e] Element id
*
* @method
*
* @since 1.0.0
*/
jsOMS.UI.GeneralUI.prototype.bindHref = function (e)
{
e = e !== null ? e.querySelectorAll('[data-href]') : document.querySelectorAll('[data-href]');
const length = e.length;
for (let i = 0; i < length; ++i) {
e[i].addEventListener('click', function(event) {
jsOMS.preventAll(event);
window.location = jsOMS.Uri.UriFactory.build(this.getAttribute('data-href'));
});
}
};
/**
* Bind & rebind UI element.
*
* @param {Object} [e] Element id
*
* @method
*
* @since 1.0.0
*/
jsOMS.UI.GeneralUI.prototype.bindLazyLoad = function (e)
{
e = e !== null ? e.querySelectorAll('[data-lazyload]') : document.querySelectorAll('[data-lazyload]');
const length = e.length;
/** global: IntersectionObserver */
if (!this.visObs && window.IntersectionObserver) {
this.visObs = new IntersectionObserver(function(eles, obs) {
eles.forEach(ele => {
if (ele.intersectionRatio > 0) {
obs.unobserve(ele.target);
ele.target.src = ele.target.dataset.lazyload;
delete ele.target.dataset.lazyload;
}
});
});
}
for (let i = 0; i < length; ++i) {
if (!this.visObs) {
e[i].src = e[i].dataset.lazyload;
delete e[i].dataset.lazyload;
} else {
this.visObs.observe(e[i]);
} }
}
}; this.bindHref(e);
this.bindLazyLoad(e);
};
/**
* Bind & rebind UI element.
*
* @param {Object} [e] Element id
*
* @method
*
* @since 1.0.0
*/
bindHref (e)
{
e = e !== null ? e.querySelectorAll('[data-href]') : document.querySelectorAll('[data-href]');
const length = e.length;
for (let i = 0; i < length; ++i) {
e[i].addEventListener('click', function(event) {
jsOMS.preventAll(event);
window.location = jsOMS.Uri.UriFactory.build(this.getAttribute('data-href'));
});
}
};
/**
* Bind & rebind UI element.
*
* @param {Object} [e] Element id
*
* @method
*
* @since 1.0.0
*/
bindLazyLoad (e)
{
e = e !== null ? e.querySelectorAll('[data-lazyload]') : document.querySelectorAll('[data-lazyload]');
const length = e.length;
/** global: IntersectionObserver */
if (!this.visObs && window.IntersectionObserver) {
this.visObs = new IntersectionObserver(function(eles, obs) {
eles.forEach(ele => {
if (ele.intersectionRatio > 0) {
obs.unobserve(ele.target);
ele.target.src = ele.target.dataset.lazyload;
delete ele.target.dataset.lazyload;
}
});
});
}
for (let i = 0; i < length; ++i) {
if (!this.visObs) {
e[i].src = e[i].dataset.lazyload;
delete e[i].dataset.lazyload;
} else {
this.visObs.observe(e[i]);
}
}
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,51 +13,53 @@
/** @namespace jsOMS.UI.Input */ /** @namespace jsOMS.UI.Input */
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input');
/** jsOMS.UI.Input.InputManager = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.Input.InputManager = function (app) */
{ constructor(app)
this.keyboardManager = new jsOMS.UI.Input.Keyboard.KeyboardManager(); {
this.mouseManager = new jsOMS.UI.Input.Mouse.MouseManager(); this.keyboardManager = new jsOMS.UI.Input.Keyboard.KeyboardManager();
this.voiceManager = new jsOMS.UI.Input.Voice.VoiceManager(app); this.mouseManager = new jsOMS.UI.Input.Mouse.MouseManager();
}; this.voiceManager = new jsOMS.UI.Input.Voice.VoiceManager(app);
};
/** /**
* Get keyboard manager. * Get keyboard manager.
* *
* @return {Object} * @return {Object}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Input.InputManager.prototype.getKeyboardManager = function () getKeyboardManager ()
{ {
return this.keyboardManager; return this.keyboardManager;
}; };
/** /**
* Get mouse manager. * Get mouse manager.
* *
* @return {Object} * @return {Object}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Input.InputManager.prototype.getMouseManager = function () getMouseManager ()
{ {
return this.mouseManager; return this.mouseManager;
}; };
/** /**
* Get voice manager. * Get voice manager.
* *
* @return {Object} * @return {Object}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Input.InputManager.prototype.getVoiceManager = function () getVoiceManager ()
{ {
return this.voiceManager; return this.voiceManager;
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,99 +13,101 @@
/** @namespace jsOMS.UI.Input.Keyboard */ /** @namespace jsOMS.UI.Input.Keyboard */
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Keyboard'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Keyboard');
/** jsOMS.UI.Input.Keyboard.KeyboardManager = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.Input.Keyboard.KeyboardManager = function () */
{ constructor ()
this.elements = {};
this.down = [];
};
/**
* Add input listener.
*
* @param {string} element Container id
* @param {Array} keys Keyboard keys
* @param {callback} callback Callback
*
* @since 1.0.0
*/
jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.add = function (element, keys, callback)
{
if (typeof this.elements[element] === 'undefined') {
this.elements[element] = [];
this.bind(element);
}
this.elements[element].push({keys: keys, callback: callback});
};
/**
* Bind container for keyboard input.
*
* @param {string} element Container id
*
* @since 1.0.0
*/
jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.bind = function (element)
{
const self = this;
// todo: implement keyboard for selected elements right now only global hotkeys possible
document.addEventListener('keydown', function keyBind(event)
{ {
self.down.push(event.keyCode); this.elements = {};
}); this.down = [];
};
document.addEventListener('keyup', function keyBind(event) /**
* Add input listener.
*
* @param {string} element Container id
* @param {Array} keys Keyboard keys
* @param {callback} callback Callback
*
* @since 1.0.0
*/
add (element, keys, callback)
{ {
if (self.down.length > 0) { if (typeof this.elements[element] === 'undefined') {
self.run(element, event); this.elements[element] = [];
self.down = [];
this.bind(element);
} }
});
};
/** this.elements[element].push({keys: keys, callback: callback});
* Execute callback based on key presses. };
*
* @param {string} element Container id
* @param {Object} event Key event
*
* @since 1.0.0
*/
jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.run = function (element, event)
{
if (typeof this.elements[element] === 'undefined') {
throw 'Unexpected elmenet!';
}
const actions = this.elements[element], /**
length = actions.length, * Bind container for keyboard input.
keyLength = this.down.length; *
let match = false; * @param {string} element Container id
*
* @since 1.0.0
*/
bind (element)
{
const self = this;
for (let i = 0; i < length; ++i) { // todo: implement keyboard for selected elements right now only global hotkeys possible
for (let j = 0; j < keyLength; ++j) { document.addEventListener('keydown', function keyBind(event)
if (actions[i].keys.indexOf(this.down[j]) === -1) { {
match = false; self.down.push(event.keyCode);
});
document.addEventListener('keyup', function keyBind(event)
{
if (self.down.length > 0) {
self.run(element, event);
self.down = [];
}
});
};
/**
* Execute callback based on key presses.
*
* @param {string} element Container id
* @param {Object} event Key event
*
* @since 1.0.0
*/
run (element, event)
{
if (typeof this.elements[element] === 'undefined') {
throw 'Unexpected elmenet!';
}
const actions = this.elements[element],
length = actions.length,
keyLength = this.down.length;
let match = false;
for (let i = 0; i < length; ++i) {
for (let j = 0; j < keyLength; ++j) {
if (actions[i].keys.indexOf(this.down[j]) === -1) {
match = false;
break;
}
match = true;
}
if (match) {
jsOMS.preventAll(event);
actions[i].callback();
break; break;
} }
match = true;
} }
};
if (match) { }
jsOMS.preventAll(event);
actions[i].callback();
break;
}
}
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,108 +13,110 @@
/** @namespace jsOMS.UI.Input.Mouse */ /** @namespace jsOMS.UI.Input.Mouse */
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Mouse'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Mouse');
/** jsOMS.UI.Input.Mouse.MouseManager = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.Input.Mouse.MouseManager = function () */
{ constructor ()
this.elements = {}; {
this.click = {time: 0}; this.elements = {};
}; this.click = {time: 0};
};
/** /**
* Add input listener. * Add input listener.
* *
* @param {string} element Container id * @param {string} element Container id
* @param {int} type Action type * @param {int} type Action type
* @param {int} button Button * @param {int} button Button
* @param {callback} callback Callback * @param {callback} callback Callback
* @param {bool} exact ??? todo: can't remember why this was important oO!!! * @param {bool} exact ??? todo: can't remember why this was important oO!!!
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Input.Mouse.MouseManager.prototype.add = function (element, type, button, callback, exact) add (element, type, button, callback, exact)
{ {
if (typeof this.elements[element] === 'undefined') { if (typeof this.elements[element] === 'undefined') {
this.elements[element] = []; this.elements[element] = [];
}
this.bind(element, type);
this.elements[element].push({callback: callback, type: type, button: button, exact: exact});
};
/**
* Add input listener.
*
* @param {string} element Element id
* @param {int} type Action type
*
* @since 1.0.0
*/
jsOMS.UI.Input.Mouse.MouseManager.prototype.bind = function (element, type)
{
const self = this,
e = document.getElementById(element);
if (!e) {
return;
}
if (type === jsOMS.UI.Input.Mouse.EventType.CONTEXT) {
e.addEventListener('contextmenu', function (event)
{
self.run(element, event);
}, false);
} else if (type === jsOMS.UI.Input.Mouse.EventType.LONGPRESS) {
e.addEventListener('mousedown', function (event)
{
self.click.time = new Date().getTime();
}, false);
e.addEventListener('mouseup', function (event)
{
const duration = new Date().getTime() - self.click.time;
if (duration > 650) {
self.run(element, event);
}
self.click.time = 0;
}, false);
} else if (type === jsOMS.UI.Input.Mouse.EventType.CLICK) {
e.addEventListener('click', function (event)
{
self.run(element, event);
}, false);
}
};
/**
* Run mouse input callback.
*
* @param {string} element Element id
* @param {Object} event Click event
*
* @since 1.0.0
*/
jsOMS.UI.Input.Mouse.MouseManager.prototype.run = function (element, event)
{
if (typeof this.elements[element] === 'undefined') {
throw 'Unexpected elmenet!';
}
const actions = this.elements[element],
length = actions.length;
for (let i = 0; i < length; ++i) {
if ((!actions[i].exact || event.target.getAttribute('id') === element)
&& actions[i].button === event.button
) {
jsOMS.preventAll(event);
actions[i].callback();
} }
}
}; this.bind(element, type);
this.elements[element].push({callback: callback, type: type, button: button, exact: exact});
};
/**
* Add input listener.
*
* @param {string} element Element id
* @param {int} type Action type
*
* @since 1.0.0
*/
bind (element, type)
{
const self = this,
e = document.getElementById(element);
if (!e) {
return;
}
if (type === jsOMS.UI.Input.Mouse.EventType.CONTEXT) {
e.addEventListener('contextmenu', function (event)
{
self.run(element, event);
}, false);
} else if (type === jsOMS.UI.Input.Mouse.EventType.LONGPRESS) {
e.addEventListener('mousedown', function (event)
{
self.click.time = new Date().getTime();
}, false);
e.addEventListener('mouseup', function (event)
{
const duration = new Date().getTime() - self.click.time;
if (duration > 650) {
self.run(element, event);
}
self.click.time = 0;
}, false);
} else if (type === jsOMS.UI.Input.Mouse.EventType.CLICK) {
e.addEventListener('click', function (event)
{
self.run(element, event);
}, false);
}
};
/**
* Run mouse input callback.
*
* @param {string} element Element id
* @param {Object} event Click event
*
* @since 1.0.0
*/
run (element, event)
{
if (typeof this.elements[element] === 'undefined') {
throw 'Unexpected elmenet!';
}
const actions = this.elements[element],
length = actions.length;
for (let i = 0; i < length; ++i) {
if ((!actions[i].exact || event.target.getAttribute('id') === element)
&& actions[i].button === event.button
) {
jsOMS.preventAll(event);
actions[i].callback();
}
}
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,113 +13,115 @@
/** @namespace jsOMS.UI.Input.Touch */ /** @namespace jsOMS.UI.Input.Touch */
jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Touch'); jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Touch');
/** jsOMS.UI.Input.Touch.TouchManager = class {
* @constructor /**
* * @constructor
* @param {Object} app Application *
* * @param {Object} app Application
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.Input.Touch.TouchManager = function (app) */
{ constructor (app)
this.app = app;
this.activeSwipe = {};
this.resetSwipe();
};
/**
* Reset swipe data.
*
* This is called in between swipes in order to reset previous swipe data.
*
* @since 1.0.0
*/
jsOMS.UI.Input.Touch.TouchManager.prototype.resetSwipe = function ()
{
this.activeSwipe = {'startX': null, 'startY': null, 'time': null};
};
/**
* Adding swipe functionality.
*
* Forwarding swipe to arrow keyes.
*
* @since 1.0.0
*/
jsOMS.UI.Input.Touch.TouchManager.prototype.add = function (surface)
{
const e = document.getElementById(surface),
self = this;
if (!e) {
return;
}
e.addEventListener('touchstart', function (event)
{ {
const touch = this.changedTouches[0]; this.app = app;
this.activeSwipe = {};
this.resetSwipe();
};
self.activeSwipe.startX = touch.pageX; /**
self.activeSwipe.startY = touch.pageY; * Reset swipe data.
self.activeSwipe.time = new Date().getTime(); *
* This is called in between swipes in order to reset previous swipe data.
jsOMS.preventAll(event); *
}); * @since 1.0.0
*/
e.addEventListener('touchmove', function (event) resetSwipe ()
{ {
jsOMS.preventAll(event); this.activeSwipe = {'startX': null, 'startY': null, 'time': null};
}); };
e.addEventListener('touchend', function (event) /**
* Adding swipe functionality.
*
* Forwarding swipe to arrow keyes.
*
* @since 1.0.0
*/
add (surface)
{ {
const touch = this.changedTouches[0], const e = document.getElementById(surface),
distX = touch.pageX - self.activeSwipe.startX, self = this;
distY = touch.pageY - self.activeSwipe.startY,
elapsedTime = new Date().getTime() - self.activeSwipe.time;
self.resetSwipe(); if (!e) {
// todo: only prevent all if success return;
jsOMS.preventAll(event);
if (elapsedTime > 300 && distY < 3 && distX < 3) {
let rightClick = MouseEvent('click',
{
bubbles: true,
cancelable: true,
view: window,
screenX: touch.pageX,
screenY: touch.pageY,
clientX: touch.pageX,
clientY: touch.pageY,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
button: 2,
relatedTarget: null
}
);
document.dispatchEvent(rightClick);
} else if (elapsedTime < 500) {
/** global: Event */
const e = new Event('keyup');
if (distY > 100) {
e.keyCode = 38;
document.dispatchEvent(e);
} else if (distX > 100) {
e.keyCode = 39;
document.dispatchEvent(e);
} else if (distY < -100) {
e.keyCode = 40;
document.dispatchEvent(e);
} else if (distX < -100) {
e.keyCode = 37;
document.dispatchEvent(e);
}
} }
});
}; e.addEventListener('touchstart', function (event)
{
const touch = this.changedTouches[0];
self.activeSwipe.startX = touch.pageX;
self.activeSwipe.startY = touch.pageY;
self.activeSwipe.time = new Date().getTime();
jsOMS.preventAll(event);
});
e.addEventListener('touchmove', function (event)
{
jsOMS.preventAll(event);
});
e.addEventListener('touchend', function (event)
{
const touch = this.changedTouches[0],
distX = touch.pageX - self.activeSwipe.startX,
distY = touch.pageY - self.activeSwipe.startY,
elapsedTime = new Date().getTime() - self.activeSwipe.time;
self.resetSwipe();
// todo: only prevent all if success
jsOMS.preventAll(event);
if (elapsedTime > 300 && distY < 3 && distX < 3) {
let rightClick = MouseEvent('click',
{
bubbles: true,
cancelable: true,
view: window,
screenX: touch.pageX,
screenY: touch.pageY,
clientX: touch.pageX,
clientY: touch.pageY,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false,
button: 2,
relatedTarget: null
}
);
document.dispatchEvent(rightClick);
} else if (elapsedTime < 500) {
/** global: Event */
const e = new Event('keyup');
if (distY > 100) {
e.keyCode = 38;
document.dispatchEvent(e);
} else if (distX > 100) {
e.keyCode = 39;
document.dispatchEvent(e);
} else if (distY < -100) {
e.keyCode = 40;
document.dispatchEvent(e);
} else if (distX < -100) {
e.keyCode = 37;
document.dispatchEvent(e);
}
}
});
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -26,97 +26,99 @@
/** global: SpeechRecognitionEvent */ /** global: SpeechRecognitionEvent */
var SpeechRecognitionEvent = typeof SpeechRecognitionEvent !== 'undefined' ? SpeechRecognitionEvent : typeof webkitSpeechRecognitionEvent !== 'undefined' ? webkitSpeechRecognitionEvent : null; var SpeechRecognitionEvent = typeof SpeechRecognitionEvent !== 'undefined' ? SpeechRecognitionEvent : typeof webkitSpeechRecognitionEvent !== 'undefined' ? webkitSpeechRecognitionEvent : null;
/** jsOMS.UI.Input.Voice.ReadManager = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.Input.Voice.ReadManager = function (lang = 'en-US') */
{ constructor (lang = 'en-US')
this.pitch = 1; {
this.rate = 1; this.pitch = 1;
this.lang = lang; this.rate = 1;
this.voices = []; this.lang = lang;
this.voice = null; this.voices = [];
this.voice = null;
if (SpeechRecognition !== null) { if (SpeechRecognition !== null) {
this.voices = window.speechSynthesis.getVoices(); this.voices = window.speechSynthesis.getVoices();
this.voice = this.voices[0]; this.voice = this.voices[0];
} }
}; };
/** /**
* Read text. * Read text.
* *
* @param {string} text Text to read * @param {string} text Text to read
* *
* @return {void} * @return {void}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Input.Voice.ReadManager.prototype.read = function(text) read (text)
{ {
/** global: SpeechSynthesisUtterance */ /** global: SpeechSynthesisUtterance */
let utter = new SpeechSynthesisUtterance(text); let utter = new SpeechSynthesisUtterance(text);
utter.lang = this.lang; utter.lang = this.lang;
utter.voice = this.voice; utter.voice = this.voice;
utter.pitch = this.pitch; utter.pitch = this.pitch;
utter.rate = this.rate; utter.rate = this.rate;
window.speechSynthesis.speak(utter); window.speechSynthesis.speak(utter);
}; };
/** /**
* Set Language. * Set Language.
* *
* @param {string} lang Language id (e.g. en-US) * @param {string} lang Language id (e.g. en-US)
* *
* @return {void} * @return {void}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Input.Voice.ReadManager.prototype.setLanguage = function(lang) setLanguage (lang)
{ {
this.lang = lang; this.lang = lang;
}; };
/** /**
* Set pitch. * Set pitch.
* *
* @param {int} pitch Pitch * @param {int} pitch Pitch
* *
* @return {void} * @return {void}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Input.Voice.ReadManager.prototype.setPitch = function(pitch) setPitch (pitch)
{ {
this.pitch = pitch; this.pitch = pitch;
}; };
/** /**
* Set rate. * Set rate.
* *
* @param {int} rate Rate * @param {int} rate Rate
* *
* @return {void} * @return {void}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Input.Voice.ReadManager.prototype.setRate = function(rate) setRate (rate)
{ {
this.rate = rate; this.rate = rate;
}; };
/** /**
* Get supported voices. * Get supported voices.
* *
* @return {Array} * @return {Array}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Input.Voice.ReadManager.prototype.getVoices = function() getVoices ()
{ {
return this.voices; return this.voices;
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -26,146 +26,148 @@
/** global: SpeechRecognitionEvent */ /** global: SpeechRecognitionEvent */
var SpeechRecognitionEvent = typeof SpeechRecognitionEvent !== 'undefined' ? SpeechRecognitionEvent : typeof webkitSpeechRecognitionEvent !== 'undefined' ? webkitSpeechRecognitionEvent : null; var SpeechRecognitionEvent = typeof SpeechRecognitionEvent !== 'undefined' ? SpeechRecognitionEvent : typeof webkitSpeechRecognitionEvent !== 'undefined' ? webkitSpeechRecognitionEvent : null;
/** jsOMS.UI.Input.Voice.VoiceManager = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.Input.Voice.VoiceManager = function (app, commands = {}, lang = 'en-US') */
{ constructor(app, commands = {}, lang = 'en-US')
this.app = app;
this.commands = commands;
this.lang = lang;
this.recognition = null;
this.speechRecognitionList = null;
if (SpeechRecognition !== null) {
this.recognition = new SpeechRecognition();
this.speechRecognitionList = new SpeechGrammarList();
}
};
/**
* Setup or re-initialize voice manager.
*
* @method
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.VoiceManager.prototype.setup = function()
{
if (SpeechRecognition === null) {
return;
}
const self = this;
this.recognition.lang = this.lang;
this.recognition.interimResults = false;
this.recognition.maxAlternatives = 1;
this.recognition.continuous = true;
this.recognition.lang = this.lang;
if (typeof this.commands !== 'undefined') {
this.speechRecognitionList.addFromString(this.getCommandsString(), 1);
this.recognition.grammars = this.speechRecognitionList;
}
this.recognition.onstart = function() {};
this.recognition.onresult = function(event)
{ {
let result = jsOMS.trim(event.results[event.resultIndex][0].transcript); this.app = app;
this.commands = commands;
this.lang = lang;
this.recognition = null;
this.speechRecognitionList = null;
if (self.commands.hasOwnProperty(result)) { if (SpeechRecognition !== null) {
self.commands[result](); this.recognition = new SpeechRecognition();
this.speechRecognitionList = new SpeechGrammarList();
} }
}; };
this.recognition.onspeechend = function() /**
* Setup or re-initialize voice manager.
*
* @method
*
* @since 1.0.0
*/
setup()
{ {
if (SpeechRecognition === null) {
return;
}
const self = this;
this.recognition.lang = this.lang;
this.recognition.interimResults = false;
this.recognition.maxAlternatives = 1;
this.recognition.continuous = true;
this.recognition.lang = this.lang;
if (typeof this.commands !== 'undefined') {
this.speechRecognitionList.addFromString(this.getCommandsString(), 1);
this.recognition.grammars = this.speechRecognitionList;
}
this.recognition.onstart = function() {};
this.recognition.onresult = function(event)
{
let result = jsOMS.trim(event.results[event.resultIndex][0].transcript);
if (self.commands.hasOwnProperty(result)) {
self.commands[result]();
}
};
this.recognition.onspeechend = function()
{
};
this.recognition.onnomatch = function(event)
{
jsOMS.Log.Logger.instance.warning('Couldn\'t recognize speech');
};
this.recognition.onerror = function(event)
{
jsOMS.Log.Logger.instance.warning('Error during speech recognition: ' + event.error);
};
}; };
this.recognition.onnomatch = function(event) /**
* Create commands/grammar string from commands
*
* @return {string}
*
* @since 1.0.0
*/
getCommandsString()
{ {
jsOMS.Log.Logger.instance.warning('Couldn\'t recognize speech'); return '#JSGF V1.0; grammar phrase; public <phrase> = ' + Object.keys(this.commands).join(' | ') + ' ;';
}; };
this.recognition.onerror = function(event) /**
* Set language
*
* @param {string} lang Language code (e.g. en-US)
*
* @return {void}
*
* @since 1.0.0
*/
setLanguage(lang)
{ {
jsOMS.Log.Logger.instance.warning('Error during speech recognition: ' + event.error); // todo: eventually restart
this.recognition.lang = lang;
}; };
};
/** /**
* Create commands/grammar string from commands * Add command/grammar and callback.
* *
* @return {string} * @param {string} command Command id
* * @param {callback} callback Callback for command
* @since 1.0.0 *
*/ * @return {void}
jsOMS.UI.Input.Voice.VoiceManager.prototype.getCommandsString = function() *
{ * @since 1.0.0
return '#JSGF V1.0; grammar phrase; public <phrase> = ' + Object.keys(this.commands).join(' | ') + ' ;'; */
}; add(command, callback)
{
this.commands[command] = callback;
};
/** /**
* Set language * Start voice listener.
* *
* @param {string} lang Language code (e.g. en-US) * @return {void}
* *
* @return {void} * @since 1.0.0
* */
* @since 1.0.0 start()
*/ {
jsOMS.UI.Input.Voice.VoiceManager.prototype.setLanguage = function(lang) if (SpeechRecognition === null) {
{ return;
// todo: eventually restart }
this.recognition.lang = lang;
};
/** this.recognition.start();
* Add command/grammar and callback. };
*
* @param {string} command Command id
* @param {callback} callback Callback for command
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.VoiceManager.prototype.add = function(command, callback)
{
this.commands[command] = callback;
};
/** /**
* Start voice listener. * Stop voice listener.
* *
* @return {void} * @return {void}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.Input.Voice.VoiceManager.prototype.start = function() stop()
{ {
if (SpeechRecognition === null) { if (SpeechRecognition === null) {
return; return;
} }
this.recognition.start(); this.recognition.stop();
}; };
}
/**
* Stop voice listener.
*
* @return {void}
*
* @since 1.0.0
*/
jsOMS.UI.Input.Voice.VoiceManager.prototype.stop = function()
{
if (SpeechRecognition === null) {
return;
}
this.recognition.stop();
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,168 +13,170 @@
/** @namespace jsOMS.UI */ /** @namespace jsOMS.UI */
jsOMS.Autoloader.defineNamespace('jsOMS.UI'); jsOMS.Autoloader.defineNamespace('jsOMS.UI');
/** jsOMS.UI.UIManager = class {
* @constructor /**
* * @constructor
* @param {Object} app Application object *
* * @param {Object} app Application object
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.UI.UIManager = function (app) */
{ constructor(app)
this.app = app; {
this.formManager = new jsOMS.UI.Component.Form(this.app); this.app = app;
this.tabManager = new jsOMS.UI.Component.Tab(this.app.responseManager); this.formManager = new jsOMS.UI.Component.Form(this.app);
this.tableManager = new jsOMS.UI.Component.Table(this.app.responseManager); this.tabManager = new jsOMS.UI.Component.Tab(this.app.responseManager);
this.actionManager = new jsOMS.UI.ActionManager(this.app); this.tableManager = new jsOMS.UI.Component.Table(this.app.responseManager);
this.dragNDrop = new jsOMS.UI.DragNDrop(this.app); this.actionManager = new jsOMS.UI.ActionManager(this.app);
this.generalUI = new jsOMS.UI.GeneralUI(); this.dragNDrop = new jsOMS.UI.DragNDrop(this.app);
this.generalUI = new jsOMS.UI.GeneralUI();
const self = this; const self = this;
/** global: MutationObserver */ /** global: MutationObserver */
this.domObserver = new MutationObserver(function(mutations) { this.domObserver = new MutationObserver(function(mutations) {
const length = mutations.length; const length = mutations.length;
for(let i = 0; i < length; i++) { for(let i = 0; i < length; i++) {
self.app.eventManager.trigger(mutations[i].target.id + '-' + mutations[i].type, 0, mutations[i]); self.app.eventManager.trigger(mutations[i].target.id + '-' + mutations[i].type, 0, mutations[i]);
}
});
};
/**
* Bind & rebind UI elements.
*
* @param {string} [id] Element id
*
* @method
*
* @since 1.0.0
*/
bind(id)
{
if (typeof id === 'undefined') {
this.formManager.bind();
this.tabManager.bind();
this.tableManager.bind();
this.actionManager.bind();
this.dragNDrop.bind();
this.generalUI.bind();
} else {
const tag = document.getElementById(id);
this.generalUI.bind(tag);
if(!tag) {
return;
}
switch (tag.tagName) {
case 'form':
this.formManager.bind(id);
break;
case 'table':
this.tableManager.bind(id);
break;
default:
this.actionManager.bind(tag);
}
} }
}); };
};
/** /**
* Bind & rebind UI elements. * Get tab manager.
* *
* @param {string} [id] Element id * @return {Object}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.UIManager.prototype.bind = function (id) getFormManager()
{ {
if (typeof id === 'undefined') { return this.formManager;
this.formManager.bind(); };
this.tabManager.bind();
this.tableManager.bind();
this.actionManager.bind();
this.dragNDrop.bind();
this.generalUI.bind();
} else {
const tag = document.getElementById(id);
this.generalUI.bind(tag);
if(!tag) { /**
return; * Get action manager.
} *
* @return {Object}
*
* @method
*
* @since 1.0.0
*/
getActionManager()
{
return this.actionManager;
};
switch (tag.tagName) { /**
case 'form': * Get drag and drop manager.
this.formManager.bind(id); *
break; * @return {Object}
case 'table': *
this.tableManager.bind(id); * @method
break; *
default: * @since 1.0.0
this.actionManager.bind(tag); */
} getDragNDrop()
} {
}; return this.dragNDrop;
};
/** /**
* Get tab manager. * Get tab manager.
* *
* @return {Object} * @return {Object}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.UIManager.prototype.getFormManager = function () getTabManager()
{ {
return this.formManager; return this.tabManager;
}; };
/** /**
* Get action manager. * Get table manager.
* *
* @return {Object} * @return {Object}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.UIManager.prototype.getActionManager = function () getTableManager()
{ {
return this.actionManager; return this.tabManager;
}; };
/** /**
* Get drag and drop manager. * Get DOM observer
* *
* @return {Object} * @return {Object}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.UIManager.prototype.getDragNDrop = function () getDOMObserver()
{ {
return this.dragNDrop; return this.domObserver;
}; };
/** /**
* Get tab manager. * Get general UI
* *
* @return {Object} * @return {Object}
* *
* @method * @method
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.UI.UIManager.prototype.getTabManager = function () getGeneralUI()
{ {
return this.tabManager; return this.generalUI;
}; };
}
/**
* Get table manager.
*
* @return {Object}
*
* @method
*
* @since 1.0.0
*/
jsOMS.UI.UIManager.prototype.getTableManager = function ()
{
return this.tabManager;
};
/**
* Get DOM observer
*
* @return {Object}
*
* @method
*
* @since 1.0.0
*/
jsOMS.UI.UIManager.prototype.getDOMObserver = function ()
{
return this.domObserver;
};
/**
* Get general UI
*
* @return {Object}
*
* @method
*
* @since 1.0.0
*/
jsOMS.UI.UIManager.prototype.getGeneralUI = function ()
{
return this.generalUI;
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -15,342 +15,344 @@
/** @namespace jsOMS.Uri.UriFactory */ /** @namespace jsOMS.Uri.UriFactory */
jsOMS.Autoloader.defineNamespace('jsOMS.Uri.Http'); jsOMS.Autoloader.defineNamespace('jsOMS.Uri.Http');
/** jsOMS.Uri.Http = class {
* @constructor /**
* * @constructor
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Uri.Http = function (uri) */
{ constructor(uri)
this.uri = ''; {
this.scheme = ''; this.uri = '';
this.host = ''; this.scheme = '';
this.port = ''; this.host = '';
this.user = ''; this.port = '';
this.pass = ''; this.user = '';
this.query = null; this.pass = '';
this.queryString = ''; this.query = null;
this.fragment = ''; this.queryString = '';
this.base = ''; this.fragment = '';
this.root = '/'; this.base = '';
this.root = '/';
this.set(uri); this.set(uri);
}; };
/** /**
* Parse uri * Parse uri
* *
* @param {string} str Url to parse * @param {string} str Url to parse
* @param {string} [mode] Parsing mode * @param {string} [mode] Parsing mode
* *
* @return {Object} * @return {Object}
* *
* @throws {Error} * @throws {Error}
* *
* @function * @function
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Uri.Http.parseUrl = function (str, mode = 'php') static parseUrl (str, mode = 'php')
{ {
const key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', const key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port',
'relative', 'path', 'directory', 'file', 'query', 'fragment' 'relative', 'path', 'directory', 'file', 'query', 'fragment'
], ],
parser = { parser = {
php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this) loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this)
}; };
if (!parser.hasOwnProperty(mode)) { if (!parser.hasOwnProperty(mode)) {
throw new Error('Unexpected parsing mode.', 'UriFactory', 52); throw new Error('Unexpected parsing mode.', 'UriFactory', 52);
}
const m = parser[mode].exec(str),
uri = {};
let i = 14;
while (i--) {
if (m[i]) {
uri[key[i]] = m[i];
} }
}
delete uri.source; const m = parser[mode].exec(str),
uri = {};
let i = 14;
return uri; while (i--) {
}; if (m[i]) {
uri[key[i]] = m[i];
/**
* 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
*/
jsOMS.Uri.Http.getUriQueryParameter = function (query, name)
{
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
const regex = new RegExp("[\\?&]*" + name + "=([^&#]*)"),
results = regex.exec(query);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
/**
* Get all uri query parameters.
*
* @param {string} query Uri query
*
* @return {Object}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.Http.getAllUriQueryParameters = function (query)
{
const params = {};
let keyValPairs = [],
pairNum = null;
if (query.length) {
keyValPairs = query.split('&');
for (pairNum in keyValPairs) {
if (!keyValPairs.hasOwnProperty(pairNum)) {
continue;
} }
const key = keyValPairs[pairNum].split('=')[0];
if (!key.length) {
continue;
}
if (typeof params[key] === 'undefined') {
params[key] = [];
}
params[key].push(keyValPairs[pairNum].split('=')[1]);
} }
}
return params; delete uri.source;
};
/** return uri;
* Set uri. };
*
* @param {string} uri Uri string
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.Http.prototype.set = function (uri)
{
this.uri = uri;
const parsed = jsOMS.Uri.Http.parseUrl(this.uri, 'php'); /**
* 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
*/
static getUriQueryParameter (query, name)
{
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
this.scheme = parsed['scheme']; const regex = new RegExp("[\\?&]*" + name + "=([^&#]*)"),
this.host = parsed['host']; results = regex.exec(query);
this.port = parsed['port'];
this.user = parsed['user'];
this.pass = parsed['pass'];
this.path = parsed['path'];
if (this.path.endsWith('.php')) { return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
this.path = this.path.substr(0, -4); };
}
this.queryString = typeof parsed['query'] !== 'undefined' ? parsed['query'] : []; /**
* Get all uri query parameters.
*
* @param {string} query Uri query
*
* @return {Object}
*
* @method
*
* @since 1.0.0
*/
static getAllUriQueryParameters (query)
{
const params = {};
let keyValPairs = [],
pairNum = null;
if (this.queryString !== null) { if (query.length) {
this.query = jsOMS.Uri.Http.getAllUriQueryParameters(this.queryString); keyValPairs = query.split('&');
}
this.fragment = typeof parsed['fragment'] !== 'undefined' ? parsed['fragment'] : ''; for (pairNum in keyValPairs) {
this.base = this.scheme + '://' + this.host + this.root; if (!keyValPairs.hasOwnProperty(pairNum)) {
}; continue;
}
/** const key = keyValPairs[pairNum].split('=')[0];
* Set root path.
*
* @param {string} rootPath Uri root path
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.Http.prototype.setRootPath = function(rootPath)
{
this.root = rootPath;
this.set(this.uri);
};
/** if (!key.length) {
* Get Uri base continue;
* }
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.Http.prototype.getBase = function()
{
return this.base;
};
/** if (typeof params[key] === 'undefined') {
* Get Uri scheme params[key] = [];
* }
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.Http.prototype.getScheme = function()
{
return this.scheme;
};
/** params[key].push(keyValPairs[pairNum].split('=')[1]);
* Get Uri host }
* }
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.Http.prototype.getHost = function()
{
return this.host;
};
/** return params;
* Get Uri port };
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.Http.prototype.getPort = function()
{
return this.port;
};
/** /**
* Get Uri user * Set uri.
* *
* @return {string} * @param {string} uri Uri string
* *
* @method * @return {void}
* *
* @since 1.0.0 * @method
*/ *
jsOMS.Uri.Http.prototype.getUser = function() * @since 1.0.0
{ */
return this.user; set (uri)
}; {
this.uri = uri;
/** const parsed = jsOMS.Uri.Http.parseUrl(this.uri, 'php');
* Get Uri pass
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.Http.prototype.getPass = function()
{
return this.pass;
};
/** this.scheme = parsed['scheme'];
* Get Uri query this.host = parsed['host'];
* this.port = parsed['port'];
* @return {string} this.user = parsed['user'];
* this.pass = parsed['pass'];
* @method this.path = parsed['path'];
*
* @since 1.0.0
*/
jsOMS.Uri.Http.prototype.getQuery = function()
{
return this.queryString;
};
/** if (this.path.endsWith('.php')) {
* Get Uri this.path = this.path.substr(0, -4);
* }
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.Http.prototype.getUri = function()
{
return this.uri;
};
/** this.queryString = typeof parsed['query'] !== 'undefined' ? parsed['query'] : [];
* Get Uri fragment
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.Http.prototype.getFragment = function()
{
return this.fragment;
};
/** if (this.queryString !== null) {
* Get Uri path this.query = jsOMS.Uri.Http.getAllUriQueryParameters(this.queryString);
* }
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.Http.prototype.getPath = function()
{
return this.path;
};
/** this.fragment = typeof parsed['fragment'] !== 'undefined' ? parsed['fragment'] : '';
* Get Uri path offset this.base = this.scheme + '://' + this.host + this.root;
* };
* @return {int}
* /**
* @method * Set root path.
* *
* @since 1.0.0 * @param {string} rootPath Uri root path
*/ *
jsOMS.Uri.Http.prototype.getPathOffset = function() * @return {void}
{ *
return jsOMS.substr_count(this.root, '/') - 1; * @method
}; *
* @since 1.0.0
*/
setRootPath(rootPath)
{
this.root = rootPath;
this.set(this.uri);
};
/**
* Get Uri base
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getBase()
{
return this.base;
};
/**
* Get Uri scheme
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getScheme()
{
return this.scheme;
};
/**
* Get Uri host
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getHost()
{
return this.host;
};
/**
* Get Uri port
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getPort()
{
return this.port;
};
/**
* Get Uri user
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getUser()
{
return this.user;
};
/**
* Get Uri pass
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getPass()
{
return this.pass;
};
/**
* Get Uri query
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getQuery()
{
return this.queryString;
};
/**
* Get Uri
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getUri()
{
return this.uri;
};
/**
* Get Uri fragment
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getFragment()
{
return this.fragment;
};
/**
* Get Uri path
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
getPath()
{
return this.path;
};
/**
* Get Uri path offset
*
* @return {int}
*
* @method
*
* @since 1.0.0
*/
getPathOffset()
{
return jsOMS.substr_count(this.root, '/') - 1;
};
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -13,6 +13,248 @@
/** @namespace jsOMS.Uri.UriFactory */ /** @namespace jsOMS.Uri.UriFactory */
jsOMS.Autoloader.defineNamespace('jsOMS.Uri.UriFactory'); jsOMS.Autoloader.defineNamespace('jsOMS.Uri.UriFactory');
jsOMS.Uri.UriFactory = class {
/**
* Set uri query
*
* @param {string} key Query key
* @param {string} value Query value
* @param {boolean} [overwrite] Overwrite if already exists?
*
* @return {boolean}
*
* @function
*
* @since 1.0.0
*/
static setQuery (key, value, overwrite)
{
overwrite = typeof overwrite !== 'undefined' ? overwrite : true;
if (overwrite || !jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) {
jsOMS.Uri.UriFactory.uri[key] = value;
return true;
}
return false;
};
/**
* Get query
*
* @param {string} key
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
static getQuery (key)
{
if (!jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) {
return '';
}
return jsOMS.Uri.UriFactory.uri[key];
};
/**
* Clear all uri components
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
static clearAll ()
{
jsOMS.Uri.UriFactory.uri = {};
return true;
};
/**
* Clear uri component
*
* @param {string} key Uri key for component
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
static clear (key)
{
if (jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) {
delete jsOMS.Uri.UriFactory.uri[key];
return true;
}
return false;
};
/**
* Clear uri components that follow a certain pattern
*
* @param {string} pattern Uri key pattern to remove
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
static clearLike (pattern)
{
let success = false;
const regexp = new RegExp(pattern);
for (let key in jsOMS.Uri.UriFactory.uri) {
if (jsOMS.Uri.UriFactory.uri.hasOwnProperty(key) && regexp.test(key)) {
delete jsOMS.Uri.UriFactory.uri[key];
success = true;
}
}
return success;
};
/**
* Remove multiple definitions of the same parameter
*
* The parameters will be recognized from right to left since it's easier to push at the end.
*
* @param {string} url Url
*
* @return {string}
*
* @function
*
* @since 1.0.0
*/
static unique (url)
{
const parts = url.split('?');
if (parts.length >= 2) {
let full = parts[1],
pars = full.split('&'),
comps = {},
spl = null,
length = pars.length;
for (let i = 0; i < length; ++i) {
spl = pars[i].split('=');
comps[spl[0]] = spl[1];
}
pars = [];
for (let a in comps) {
if (comps.hasOwnProperty(a)) {
pars.push(a + '=' + comps[a]);
}
}
url = parts[0] + '?' + pars.join('&');
}
return url;
};
/**
* Build uri
*
* # = DOM id
* . = DOM class
* / = Current path
* ? = Current query
* @ =
* $ = Other data
* % = Current url
*
* @param {string} uri Raw uri
* @param {Object} [toMatch] Key/value pair to replace in raw
*
* @function
*
* @since 1.0.0
*/
static build (uri, toMatch)
{
const current = jsOMS.Uri.Http.parseUrl(window.location.href);
let parsed = uri.replace(new RegExp('\{[\/#\?%@\.\$][a-zA-Z0-9\-]*\}', 'g'), function (match)
{
match = match.substr(1, match.length - 2);
if (typeof toMatch !== 'undefined' && toMatch.hasOwnProperty(match)) {
return toMatch[match];
} else if (typeof jsOMS.Uri.UriFactory.uri[match] !== 'undefined') {
return jsOMS.Uri.UriFactory.uri[match];
} else if (match.indexOf('#') === 0) {
const e = document.getElementById(match.substr(1));
if (e) {
return e.value;
}
return '';
} else if (match.indexOf('?') === 0) {
return jsOMS.Uri.Http.getUriQueryParameter(current.query, match.substr(1));
} else if (match.indexOf('/') === 0) {
// todo: second match should return second path
return 'ERROR PATH';
} else if (match === '%') {
return window.location.href;
} else {
return match;
}
});
if (parsed.indexOf('?') === -1) {
parsed = parsed.replace('&', '?');
}
parsed = jsOMS.Uri.UriFactory.unique(parsed);
return parsed;
};
/**
* Set uri builder components.
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
static setupUriBuilder (uri)
{
jsOMS.Uri.UriFactory.setQuery('/scheme', uri.getScheme());
jsOMS.Uri.UriFactory.setQuery('/host', uri.getHost());
jsOMS.Uri.UriFactory.setQuery('/base', jsOMS.rtrim(uri.getBase(), '/'));
jsOMS.Uri.UriFactory.setQuery('?', uri.getQuery());
jsOMS.Uri.UriFactory.setQuery('%', uri.getUri());
jsOMS.Uri.UriFactory.setQuery('#', uri.getFragment());
jsOMS.Uri.UriFactory.setQuery('/', uri.getPath());
jsOMS.Uri.UriFactory.setQuery(':user', uri.getUser());
jsOMS.Uri.UriFactory.setQuery(':pass', uri.getPass());
const query = uri.getQuery();
for (let key in query) {
if (query.hasOwnProperty(key)) {
jsOMS.Uri.UriFactory.setQuery('?' + key, query[key]);
}
}
};
}
/** /**
* Uri values * Uri values
* *
@ -20,244 +262,4 @@
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Uri.UriFactory.uri = {}; jsOMS.Uri.UriFactory.uri = {};
/**
* Set uri query
*
* @param {string} key Query key
* @param {string} value Query value
* @param {boolean} [overwrite] Overwrite if already exists?
*
* @return {boolean}
*
* @function
*
* @since 1.0.0
*/
jsOMS.Uri.UriFactory.setQuery = function (key, value, overwrite)
{
overwrite = typeof overwrite !== 'undefined' ? overwrite : true;
if (overwrite || !jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) {
jsOMS.Uri.UriFactory.uri[key] = value;
return true;
}
return false;
};
/**
* Get query
*
* @param {string} key
*
* @return {string}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.UriFactory.getQuery = function (key)
{
if (!jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) {
return '';
}
return jsOMS.Uri.UriFactory.uri[key];
};
/**
* Clear all uri components
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.UriFactory.clearAll = function()
{
jsOMS.Uri.UriFactory.uri = {};
return true;
};
/**
* Clear uri component
*
* @param {string} key Uri key for component
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.UriFactory.clear = function(key)
{
if (jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) {
delete jsOMS.Uri.UriFactory.uri[key];
return true;
}
return false;
};
/**
* Clear uri components that follow a certain pattern
*
* @param {string} pattern Uri key pattern to remove
*
* @return {boolean}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.UriFactory.clearLike = function(pattern)
{
let success = false;
const regexp = new RegExp(pattern);
for (let key in jsOMS.Uri.UriFactory.uri) {
if (jsOMS.Uri.UriFactory.uri.hasOwnProperty(key) && regexp.test(key)) {
delete jsOMS.Uri.UriFactory.uri[key];
success = true;
}
}
return success;
};
/**
* Remove multiple definitions of the same parameter
*
* The parameters will be recognized from right to left since it's easier to push at the end.
*
* @param {string} url Url
*
* @return {string}
*
* @function
*
* @since 1.0.0
*/
jsOMS.Uri.UriFactory.unique = function (url)
{
const parts = url.split('?');
if (parts.length >= 2) {
let full = parts[1],
pars = full.split('&'),
comps = {},
spl = null,
length = pars.length;
for (let i = 0; i < length; ++i) {
spl = pars[i].split('=');
comps[spl[0]] = spl[1];
}
pars = [];
for (let a in comps) {
if (comps.hasOwnProperty(a)) {
pars.push(a + '=' + comps[a]);
}
}
url = parts[0] + '?' + pars.join('&');
}
return url;
};
/**
* Build uri
*
* # = DOM id
* . = DOM class
* / = Current path
* ? = Current query
* @ =
* $ = Other data
* % = Current url
*
* @param {string} uri Raw uri
* @param {Object} [toMatch] Key/value pair to replace in raw
*
* @function
*
* @since 1.0.0
*/
jsOMS.Uri.UriFactory.build = function (uri, toMatch)
{
const current = jsOMS.Uri.Http.parseUrl(window.location.href);
let parsed = uri.replace(new RegExp('\{[\/#\?%@\.\$][a-zA-Z0-9\-]*\}', 'g'), function (match)
{
match = match.substr(1, match.length - 2);
if (typeof toMatch !== 'undefined' && toMatch.hasOwnProperty(match)) {
return toMatch[match];
} else if (typeof jsOMS.Uri.UriFactory.uri[match] !== 'undefined') {
return jsOMS.Uri.UriFactory.uri[match];
} else if (match.indexOf('#') === 0) {
const e = document.getElementById(match.substr(1));
if (e) {
return e.value;
}
return '';
} else if (match.indexOf('?') === 0) {
return jsOMS.Uri.Http.getUriQueryParameter(current.query, match.substr(1));
} else if (match.indexOf('/') === 0) {
// todo: second match should return second path
return 'ERROR PATH';
} else if (match === '%') {
return window.location.href;
} else {
return match;
}
});
if (parsed.indexOf('?') === -1) {
parsed = parsed.replace('&', '?');
}
parsed = jsOMS.Uri.UriFactory.unique(parsed);
return parsed;
};
/**
* Set uri builder components.
*
* @return {void}
*
* @method
*
* @since 1.0.0
*/
jsOMS.Uri.UriFactory.setupUriBuilder = function (uri)
{
jsOMS.Uri.UriFactory.setQuery('/scheme', uri.getScheme());
jsOMS.Uri.UriFactory.setQuery('/host', uri.getHost());
jsOMS.Uri.UriFactory.setQuery('/base', jsOMS.rtrim(uri.getBase(), '/'));
jsOMS.Uri.UriFactory.setQuery('?', uri.getQuery());
jsOMS.Uri.UriFactory.setQuery('%', uri.getUri());
jsOMS.Uri.UriFactory.setQuery('#', uri.getFragment());
jsOMS.Uri.UriFactory.setQuery('/', uri.getPath());
jsOMS.Uri.UriFactory.setQuery(':user', uri.getUser());
jsOMS.Uri.UriFactory.setQuery(':pass', uri.getPass());
const query = uri.getQuery();
for (let key in query) {
if (query.hasOwnProperty(key)) {
jsOMS.Uri.UriFactory.setQuery('?' + key, query[key]);
}
}
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -16,364 +16,366 @@
/** @namespace jsOMS.Views */ /** @namespace jsOMS.Views */
jsOMS.Autoloader.defineNamespace('jsOMS.Views'); jsOMS.Autoloader.defineNamespace('jsOMS.Views');
/** jsOMS.Views.FormView = class {
* @constructor /**
* * @constructor
* @param {string} id Form id *
* * @param {string} id Form id
* @since 1.0.0 *
*/ * @since 1.0.0
jsOMS.Views.FormView = function (id) */
{ constructor (id)
this.id = id; {
this.id = id;
this.initializeMembers(); this.initializeMembers();
this.bind(); this.bind();
this.success = null; this.success = null;
this.lastSubmit = 0; this.lastSubmit = 0;
}; };
/** /**
* Initialize members * Initialize members
* *
* Pulled out since this is used in a cleanup process * Pulled out since this is used in a cleanup process
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Views.FormView.prototype.initializeMembers = function () initializeMembers ()
{ {
this.submitInjects = []; this.submitInjects = [];
this.method = 'POST'; this.method = 'POST';
this.action = ''; this.action = '';
}; };
/** /**
* Get method * Get method
* *
* @return {string} * @return {string}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Views.FormView.prototype.getMethod = function () getMethod ()
{ {
return this.method; return this.method;
}; };
/** /**
* Get action * Get action
* *
* @return {string} * @return {string}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Views.FormView.prototype.getAction = function () getAction ()
{ {
return this.action; return this.action;
}; };
jsOMS.Views.FormView.prototype.getLastSubmit = function () getLastSubmit ()
{ {
return this.lastSubmit; return this.lastSubmit;
}; };
jsOMS.Views.FormView.prototype.updateLastSubmit = function () updateLastSubmit ()
{ {
this.lastSubmit = Math.floor(Date.now()); this.lastSubmit = Math.floor(Date.now());
}; };
/** /**
* Get submit elements * Get submit elements
* *
* @return {Object} * @return {Object}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Views.FormView.prototype.getSubmit = function () getSubmit ()
{ {
return document.querySelectorAll('#' + this.id + ' input[type=submit], button[form=' + this.id + '][type=submit]'); return document.querySelectorAll('#' + this.id + ' input[type=submit], button[form=' + this.id + '][type=submit]');
}; };
/** /**
* Get success callback * Get success callback
* *
* @return {callback} * @return {callback}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Views.FormView.prototype.getSuccess = function () getSuccess ()
{ {
return this.success; return this.success;
}; };
/** /**
* Set success callback * Set success callback
* *
* @param {callback} callback Callback * @param {callback} callback Callback
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Views.FormView.prototype.setSuccess = function (callback) setSuccess (callback)
{ {
this.success = callback; this.success = callback;
}; };
/** /**
* Inject submit with post callback * Inject submit with post callback
* *
* @param {callback} callback Callback * @param {callback} callback Callback
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Views.FormView.prototype.injectSubmit = function (callback) injectSubmit (callback)
{ {
this.submitInjects.push(callback); this.submitInjects.push(callback);
}; };
/** /**
* Get form elements * Get form elements
* *
* @return {Array} * @return {Array}
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Views.FormView.prototype.getFormElements = function () getFormElements ()
{ {
const form = document.getElementById(this.id); const form = document.getElementById(this.id);
if (!form) { if (!form) {
return []; return [];
}
const selects = form.getElementsByTagName('select'),
textareas = form.getElementsByTagName('textarea'),
inputs = form.getElementsByTagName('input'),
canvas = form.getElementsByTagName('canvas'),
external = document.querySelectorAll('[form=' + this.id + ']');
return this.getUniqueFormElements(
Array.prototype.slice.call(inputs).concat(
Array.prototype.slice.call(selects),
Array.prototype.slice.call(textareas),
Array.prototype.slice.call(external)
)
);
};
/**
* Get unique form elements
*
* @param {Array} arr Form element array
*
* @return {Array}
*
* @since 1.0.0
*/
jsOMS.Views.FormView.prototype.getUniqueFormElements = function (arr)
{
let seen = {};
return arr.filter(function(item) {
return seen.hasOwnProperty(item.name) ? false : (seen[item.name] = true);
});
};
/**
* Get form data
*
* @return {Object}
*
* @since 1.0.0
*/
jsOMS.Views.FormView.prototype.getData = function ()
{
const data = {},
elements = this.getFormElements(),
length = elements.length;
let value = null;
for (let i = 0; i < length; ++i) {
if (elements[i].tagName.toLowerCase() === 'canvas') {
value = elements[i].toDataURL('image/png');
} else {
value = elements[i].value;
} }
data[jsOMS.Views.FormView.getElementId(elements[i])] = value; const selects = form.getElementsByTagName('select'),
} textareas = form.getElementsByTagName('textarea'),
inputs = form.getElementsByTagName('input'),
canvas = form.getElementsByTagName('canvas'),
external = document.querySelectorAll('[form=' + this.id + ']');
return data; return this.getUniqueFormElements(
}; Array.prototype.slice.call(inputs).concat(
Array.prototype.slice.call(selects),
Array.prototype.slice.call(textareas),
Array.prototype.slice.call(external)
)
);
};
/** /**
* Get form id * Get unique form elements
* *
* @return {string} * @param {Array} arr Form element array
* *
* @since 1.0.0 * @return {Array}
*/ *
jsOMS.Views.FormView.prototype.getId = function () * @since 1.0.0
{ */
return this.id; getUniqueFormElements (arr)
}; {
let seen = {};
/** return arr.filter(function(item) {
* Validate form return seen.hasOwnProperty(item.name) ? false : (seen[item.name] = true);
* });
* @return {boolean} };
*
* @since 1.0.0 /**
*/ * Get form data
jsOMS.Views.FormView.prototype.isValid = function () *
{ * @return {Object}
const elements = this.getFormElements(), *
length = elements.length; * @since 1.0.0
*/
getData ()
{
const data = {},
elements = this.getFormElements(),
length = elements.length;
let value = null;
try {
for (let i = 0; i < length; ++i) { for (let i = 0; i < length; ++i) {
if ((elements[i].required && elements[i].value === '') if (elements[i].tagName.toLowerCase() === 'canvas') {
|| (typeof elements[i].pattern !== 'undefined' value = elements[i].toDataURL('image/png');
&& elements[i].pattern !== '' } else {
&& !(new RegExp(elements[i].pattern)).test(elements[i].value)) value = elements[i].value;
) { }
return false;
data[jsOMS.Views.FormView.getElementId(elements[i])] = value;
}
return data;
};
/**
* Get form id
*
* @return {string}
*
* @since 1.0.0
*/
getId ()
{
return this.id;
};
/**
* Validate form
*
* @return {boolean}
*
* @since 1.0.0
*/
isValid ()
{
const elements = this.getFormElements(),
length = elements.length;
try {
for (let i = 0; i < length; ++i) {
if ((elements[i].required && elements[i].value === '')
|| (typeof elements[i].pattern !== 'undefined'
&& elements[i].pattern !== ''
&& !(new RegExp(elements[i].pattern)).test(elements[i].value))
) {
return false;
}
}
} catch (e) {
jsOMS.Log.Logger.instance.error(e);
}
return true;
};
/**
* Get form element
*
* @return {Object}
*
* @since 1.0.0
*/
getElement ()
{
return document.getElementById(this.getId());
};
/**
* Get form element id
*
* @return {string}
*
* @since 1.0.0
*/
static getElementId (e)
{
let id = e.getAttribute('name');
if (!id) {
id = e.getAttribute('id');
} else {
return id;
}
if (!id) {
id = e.getAttribute('type');
} else {
return id;
}
return id;
};
/**
* Get submit injects
*
* @return {Object}
*
* @since 1.0.0
*/
getSubmitInjects ()
{
return this.submitInjects;
};
/**
* Bind form
*
* @since 1.0.0
*/
bind ()
{
this.clean();
const e = document.getElementById(this.id);
if (!e) {
return;
}
this.method = e.attributes['method'].value;
this.action = e.action;
const elements = this.getFormElements(),
length = elements.length;
for (let 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;
default:
} }
} }
} catch (e) { };
jsOMS.Log.Logger.instance.error(e);
}
return true; /**
}; * Unbind form
*
* @since 1.0.0
*/
unbind ()
{
const elements = this.getFormElements(),
length = elements.length;
/** for (let i = 0; i < length; ++i) {
* Get form element switch (elements[i].tagName) {
* case 'input':
* @return {Object} jsOMS.UI.Input.unbind(elements[i]);
* break;
* @since 1.0.0 case 'select':
*/ this.bindSelect(elements[i]);
jsOMS.Views.FormView.prototype.getElement = function () break;
{ case 'textarea':
return document.getElementById(this.getId()); this.bindTextarea(elements[i]);
}; break;
case 'button':
/** this.bindButton(elements[i]);
* Get form element id break;
* default:
* @return {string} }
*
* @since 1.0.0
*/
jsOMS.Views.FormView.getElementId = function (e)
{
let id = e.getAttribute('name');
if (!id) {
id = e.getAttribute('id');
} else {
return id;
}
if (!id) {
id = e.getAttribute('type');
} else {
return id;
}
return id;
};
/**
* Get submit injects
*
* @return {Object}
*
* @since 1.0.0
*/
jsOMS.Views.FormView.prototype.getSubmitInjects = function ()
{
return this.submitInjects;
};
/**
* Bind form
*
* @since 1.0.0
*/
jsOMS.Views.FormView.prototype.bind = function ()
{
this.clean();
const e = document.getElementById(this.id);
if (!e) {
return;
}
this.method = e.attributes['method'].value;
this.action = e.action;
const elements = this.getFormElements(),
length = elements.length;
for (let 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;
default:
} }
} };
};
/** /**
* Unbind form * Clean form
* *
* @since 1.0.0 * @since 1.0.0
*/ */
jsOMS.Views.FormView.prototype.unbind = function () clean ()
{ {
const elements = this.getFormElements(), this.unbind();
length = elements.length; this.initializeMembers();
};
for (let 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;
default:
}
}
};
/**
* Clean form
*
* @since 1.0.0
*/
jsOMS.Views.FormView.prototype.clean = function ()
{
this.unbind();
this.initializeMembers();
};
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -1,38 +1,40 @@
(function (jsOMS) { (function (jsOMS) {
"use strict"; "use strict";
jsOMS.TableView = function () { jsOMS.TableView = class {
this.table = null; constructor () {
}; this.table = null;
};
/** /**
* None, Pagination, Infinite * None, Pagination, Infinite
*/ */
jsOMS.TableView.prototype.setExtensible = function () { setExtensible () {
}; };
jsOMS.TableView.prototype.add = function (element) { add (element) {
}; };
jsOMS.TableView.prototype.addCollection = function (collection) { addCollection (collection) {
}; };
jsOMS.TableView.prototype.remove = function (id) { remove (id) {
}; };
jsOMS.TableView.prototype.get = function (id) { get (id) {
}; };
jsOMS.TableView.prototype.filter = function (id) { filter (id) {
}; };
jsOMS.TableView.prototype.request = function (filter) { request (filter) {
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));

View File

@ -1,32 +1,34 @@
(function (jsOMS) { (function (jsOMS) {
"use strict"; "use strict";
jsOMS.ViewAbstract = function () jsOMS.ViewAbstract = class {
{ constructor ()
this.element = null; {
this.data = []; this.element = null;
}; this.data = [];
};
jsOMS.ViewAbstract.prototype.bind = function (node) bind (node)
{ {
this.element = node; this.element = node;
}; };
jsOMS.ViewAbstract.prototype.addData = function(id, data, overwrite) addData(id, data, overwrite)
{ {
overwrite = typeof overwrite !== 'undefined' ? overwrite : false; overwrite = typeof overwrite !== 'undefined' ? overwrite : false;
if (typeof this.data[id] === 'undefined' || overwrite) { if (typeof this.data[id] === 'undefined' || overwrite) {
this.data[id] = data; this.data[id] = data;
return true; return true;
} }
return false; return false;
}; };
jsOMS.ViewAbstract.prototype.getData = function(id) getData(id)
{ {
return typeof this.data[id] !== 'undefined' ? this.data[id] : undefined; return typeof this.data[id] !== 'undefined' ? this.data[id] : undefined;
}; };
}
}(window.jsOMS = window.jsOMS || {})); }(window.jsOMS = window.jsOMS || {}));