style fixes and form impl.

This commit is contained in:
Dennis Eichhorn 2022-04-01 18:31:07 +02:00
parent 1937a2161d
commit 4d7d0ceb7c
226 changed files with 2108 additions and 4863 deletions

View File

@ -8,12 +8,12 @@
*/
(function (jsOMS)
{
"use strict";
'use strict';
/** @namespace jsOMS.ThreeD.Loader.ObjLoader */
jsOMS.Autoloader.defineNamespace('jsOMS.ThreeD.Loader.ObjLoader');
jsOMS.ThreeD.Loader.ObjLoader = function(manager) {
jsOMS.ThreeD.Loader.ObjLoader = function (manager) {
/** global: THREE */
this.manager = (manager !== undefined) ? manager : THREE.DefaultLoadingManager;
this.materials = null;
@ -32,26 +32,26 @@
};
};
jsOMS.ThreeD.Loader.ObjLoader.prototype.setPath = function(path)
jsOMS.ThreeD.Loader.ObjLoader.prototype.setPath = function (path)
{
this.path = path;
};
jsOMS.ThreeD.Loader.ObjLoader.prototype.setMaterials = function(materials)
jsOMS.ThreeD.Loader.ObjLoader.prototype.setMaterials = function (materials)
{
this.materials = materials;
};
jsOMS.ThreeD.Loader.ObjLoader.prototype.load = function(uri, onLoad, onProgress, onError)
jsOMS.ThreeD.Loader.ObjLoader.prototype.load = function (uri, onLoad, onProgress, onError)
{
let self = this,
loader = new THREE.FileLoader(this.manager);
loader.setPath(this.path);
loader.load(uri, function(text) { onLoad(self.parse(text))}, onProgress, onError);
loader.load(uri, function (text) { onLoad(self.parse(text))}, onProgress, onError);
};
jsOMS.ThreeD.Loader.ObjLoader.prototype.createParserState = function()
jsOMS.ThreeD.Loader.ObjLoader.prototype.createParserState = function ()
{
let state = {
objects : [],
@ -84,7 +84,7 @@
},
materials : [],
smooth : true,
startMaterial : function(name, libraries) {
startMaterial : function (name, libraries) {
let previous = this._finalize(false);
if (previous && (previous.inherited || previous.groupCount <= 0)) {
@ -101,7 +101,7 @@
groupCount : -1,
inherited : false,
clone : function(index) {
clone : function (index) {
const cloned = {
index : (typeof index === 'number' ? index : this.index),
name : this.name,
@ -122,7 +122,7 @@
return material;
},
currentMaterial : function() {
currentMaterial : function () {
if (this.materials.length > 0) {
return this.materials[this.materials.length - 1];
}
@ -130,7 +130,7 @@
return undefined;
},
_finalize : function(end) {
_finalize : function (end) {
let lastMultiMaterial = this.currentMaterial();
if (lastMultiMaterial && lastMultiMaterial.groupEnd === -1) {
@ -166,7 +166,7 @@
this.objects.push(this.object);
},
finalize : function() {
finalize : function () {
if (this.object && typeof this.object._finalize === 'function') {
this.object._finalize(true);
}
@ -310,7 +310,7 @@
return state;
};
jsOMS.ThreeD.Loader.ObjLoader.prototype.parse = function(text)
jsOMS.ThreeD.Loader.ObjLoader.prototype.parse = function (text)
{
let state = this.createParserState();

View File

@ -15,13 +15,14 @@ export class Account
*/
constructor ()
{
/** @type {number} id Account id */
this.id = 0;
};
/**
* Get id.
*
* @return {int}
* @return {number}
*
* @since 1.0.0
*/
@ -29,4 +30,4 @@ export class Account
{
return this.id;
};
};
};

View File

@ -1,3 +1,5 @@
import { Account } from './Account.js';
/**
* Account Manager.
*
@ -15,13 +17,14 @@ export class AccountManager
*/
constructor ()
{
/** @type {Account[]} accounts Accounts */
this.accounts = [];
};
/**
* Add account.
*
* @param {Object} account Account
* @param {Account} account Account
*
* @return {void}
*
@ -35,9 +38,9 @@ export class AccountManager
/**
* Remove account.
*
* @param {int} id Account id
* @param {number} id Account id
*
* @return {void}
* @return {boolean}
*
* @since 1.0.0
*/
@ -55,9 +58,9 @@ export class AccountManager
/**
* Get account by id.
*
* @param {int} id Account id
* @param {number} id Account id
*
* @return {null|Object}
* @return {null|Account}
*
* @since 1.0.0
*/

View File

@ -8,7 +8,7 @@
*/
(function (jsOMS)
{
"use strict";
'use strict';
/** @namespace jsOMS.Animation.Animation */
jsOMS.Autoloader.defineNamespace('jsOMS.Animation.Animation');
@ -24,12 +24,12 @@
*/
jsOMS.Animation.Animation.requestAnimationFrame = (function ()
{
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback)
return window.requestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.oRequestAnimationFrame
|| window.msRequestAnimationFrame
|| function (callback)
{
window.setTimeout(callback, 1000 / 60);
};

View File

@ -8,7 +8,7 @@
*/
(function (jsOMS)
{
"use strict";
'use strict';
/** @namespace jsOMS.Animation.Canvas */
jsOMS.Autoloader.defineNamespace('jsOMS.Animation.Canvas');
@ -28,13 +28,13 @@
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
*
* @return {int}
* @return {number}
*
* @method
*
@ -48,8 +48,8 @@
/**
* Set particle position
*
* @param {int} posX Position x
* @param {int} posY Position y
* @param {number} posX Position x
* @param {number} posY Position y
*
* @return {void}
*
@ -74,7 +74,7 @@
*/
getPosition ()
{
return {x: this.posX, y: this.posY};
return { x: this.posX, y: this.posY };
};
/**
@ -106,7 +106,7 @@
*/
getVelocity ()
{
return {x: this.velX, y: this.velY};
return { x: this.velX, y: this.velY };
};
/**
@ -127,5 +127,5 @@
ctx.arc(this.posX, this.posY, this.radius, 0, Math.PI * 2, false);
ctx.fill();
};
}
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -8,7 +8,7 @@
*/
(function (jsOMS)
{
"use strict";
'use strict';
/** @namespace jsOMS.Animation.Canvas */
jsOMS.Autoloader.defineNamespace('jsOMS.Animation.Canvas');
@ -103,10 +103,10 @@
*/
updateParticles ()
{
let particle,
pos,
vel,
radius;
let particle;
let pos;
let vel;
let radius;
const length = this.particles.length;
@ -155,14 +155,14 @@
*/
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);
const pos1 = p1.getPosition();
const pos2 = p2.getPosition();
const dx = pos1.x - pos2.x;
const dy = pos1.y - pos2.y;
const dist = Math.sqrt(dx * dx + dy * dy);
let vel1 = p1.getVelocity(),
vel2 = p2.getVelocity();
const vel1 = p1.getVelocity();
const vel2 = p2.getVelocity();
// Draw line if particles are close
if (dist <= this.maxDistance) {
@ -174,8 +174,8 @@
this.ctx.closePath();
// Accelerate based on distance (no acceleration yet)
let ax = dx / this.gravitation,
ay = dy / this.gravitation;
const ax = dx / this.gravitation;
const ay = dy / this.gravitation;
vel1.x -= ax;
vel1.y -= ay;
@ -186,5 +186,5 @@
p2.setVelocity(vel2.x, vel2.y);
}
};
}
}(window.jsOMS = window.jsOMS || {}));
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -15,7 +15,9 @@ export class AssetManager
*/
constructor ()
{
/** @type {string[]} assets */
this.assets = {};
this.registerLoadedAssets();
};
@ -28,8 +30,8 @@ export class AssetManager
*/
registerLoadedAssets ()
{
const scripts = document.getElementsByTagName('script'),
length = !scripts ? 0 : scripts.length;
const scripts = document.getElementsByTagName('script');
const length = !scripts ? 0 : scripts.length;
this.assets = {};
@ -41,16 +43,17 @@ export class AssetManager
/**
* Load asset.
*
* @param {string} path Asset path
* @param {string} filetype Filetype of the asset
* @param {requestCallback} [callback] Callback after load
* @param {string} path Asset path
* @param {string} filetype Filetype of the asset
* @param {function} callback Callback after load
*
* @return {string|boolean}
* @return {boolean|number}
*
* @since 1.0.0
*/
load (path, filetype, callback)
{
/** @type {number} hash */
let hash;
if (!this.assets[(hash = jsOMS.hash(path))]) {
@ -92,7 +95,7 @@ export class AssetManager
}
if (callback) {
fileref.onreadystatechange ()
fileref.onreadystatechange = function ()
{
if (this.readyState === 'complete') {
callback();
@ -113,12 +116,13 @@ export class AssetManager
*
* @param {string} key Key of the asset
*
* @return {null|string}
* @return {null|number}
*
* @since 1.0.0
*/
get (key)
{
/** @type {number} key */
key = jsOMS.hash(key);
if (this.assets[key]) {
@ -139,6 +143,7 @@ export class AssetManager
*/
remove (key)
{
/** @type {number} key */
key = jsOMS.hash(key);
if (typeof this.assets[key] !== 'undefined') {
@ -150,4 +155,3 @@ export class AssetManager
return false;
};
};

View File

@ -1,6 +1,7 @@
import { Request } from '../../Message/Request/Request.js';
import { RequestMethod } from '../../Message/Request/RequestMethod.js';
import { RequestType } from '../../Message/Request/RequestType.js';
import { Account } from '../Account/Account.js';
import { Request } from '../Message/Request/Request.js';
import { RequestMethod } from '../Message/Request/RequestMethod.js';
import { RequestType } from '../Message/Request/RequestType.js';
/**
* Auth class.
@ -21,14 +22,17 @@ export class Auth
*/
constructor (uri)
{
/** @type {Account} account */
this.account = null;
this.uri = uri;
/** @type {string} uri */
this.uri = uri;
};
/**
* Set account for authentication.
*
* @param {Object} account Account
* @param {Account} account Account
*
* @since 1.0.0
*/
@ -40,7 +44,7 @@ export class Auth
/**
* Get account.
*
* @return {Object}
* @return {Account}
*
* @since 1.0.0
*/
@ -64,6 +68,8 @@ export class Auth
authRequest.setMethod(RequestMethod.POST);
authRequest.setResponseType(RequestType.JSON);
authRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
/** @type {XMLHttpRequest} xhr */
authRequest.setSuccess(function (xhr)
{
this.loginResult(xhr);
@ -87,6 +93,8 @@ export class Auth
/**
* Handle login result.
*
* @param {XMLHttpRequest} xhr Request
*
* @return {void}
*
* @since 1.0.0

View File

@ -15,8 +15,13 @@ import { AssetManager } from './Asset/AssetManager.js';
*/
export const Autoloader = {};
Autoloader.loaded = [];
Autoloader.namespaced = [];
/** @type {string[]} Autoloader.loaded */
Autoloader.loaded = [];
/** @type {string[]} Autoloader.namespaced */
Autoloader.namespaced = [];
/** @type {AssetManager} Autoloader.assetLoader */
Autoloader.assetLoader = new AssetManager();
/**
@ -31,7 +36,7 @@ Autoloader.assetLoader = new AssetManager();
Autoloader.defineNamespace = function (namespace)
{
if (Autoloader.namespaced.indexOf(namespace) === -1) {
let paths = namespace.split('.');
const paths = namespace.split('.');
paths.splice(0, 1);
const length = paths.length;
@ -58,8 +63,8 @@ Autoloader.defineNamespace = function (namespace)
*/
Autoloader.initPreloaded = function ()
{
const scripts = document.getElementsByTagName('script'),
length = !scripts ? 0 : scripts.length;
const scripts = document.getElementsByTagName('script');
const length = !scripts ? 0 : scripts.length;
for (let i = 0; i < length; ++i) {
/** global: URL */

View File

@ -1,25 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.AreaChart = function (id)
{
this.chart = new jsOMS.Chart.LineChart(id);
this.chart.getChart().subtype = 'area';
};
jsOMS.Chart.AreaChart.prototype.getChart = function ()
{
return this.chart.getChart();
};
jsOMS.Chart.AreaChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.AreaChart.prototype.draw = function ()
{
return this.chart.draw();
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,6 +0,0 @@
(function (jsOMS) {
"use strict";
jsOMS.Chart.TextElement = function() {
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,204 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.BarChart = function (id)
{
this.chart = new jsOMS.Chart.ChartAbstract(id);
// Setting default chart values
this.chart.margin = {top: 5, right: 0, bottom: 0, left: 0};
/** global: d3 */
this.chart.color = d3.scale.category10();
this.chart.axis = {
x: {
visible: true,
label: {
visible: true,
text: 'X-Axis',
position: "center",
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
},
y: {
visible: true,
label: {
visible: true,
text: 'Y-Axis',
position: 'center',
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
}
};
this.chart.grid = {
x: {
visible: false
},
y: {
visible: true
}
};
this.chart.dataSettings.marker.visible = false;
this.chart.subtype = 'stacked';
};
jsOMS.Chart.BarChart.prototype.getChart = function ()
{
return this.chart;
};
jsOMS.Chart.BarChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.BarChart.prototype.draw = function ()
{
let rect, svg, x, xAxis1, xAxis2, y, yAxis1, yAxis2, xGrid, yGrid, zoom, self = this;
if (this.chart.subtype === 'grouped') {
this.chart.axis.y.max = d3.max(this.chart.dataset, function (layer)
{
return d3.max(layer.points, function (d)
{
return d.y;
});
});
} else {
this.chart.axis.y.max = d3.max(this.chart.dataset, function (layer)
{
return d3.max(layer.points, function (d)
{
return d.y0 + d.y;
});
});
}
this.chart.calculateDimension();
x = this.chart.createXScale('linear');
y = this.chart.createYScale('ordinal');
xAxis1 = this.chart.createXAxis(x);
yAxis1 = this.chart.createYAxis(y);
xGrid = this.chart.createXGrid(x);
yGrid = this.chart.createYGrid(y);
x.domain([0, this.chart.axis.y.max + 1]);
y.domain(d3.range(this.chart.dataset[0].points.length)).rangeRoundBands([0, this.chart.dimension.height - this.chart.margin.top - this.chart.margin.bottom], .1);
svg = this.chart.chartSelect.append("svg")
.attr("width", this.chart.dimension.width)
.attr("height", this.chart.dimension.height)
.append("g").attr("transform", "translate("
+ (this.chart.margin.left) + ","
+ (this.chart.margin.top) + ")");
this.chart.drawGrid(svg, xGrid, yGrid);
let dataPoint = null,
dataPointEnter = null,
temp = this.drawData(svg, x, y, dataPointEnter, dataPoint);
dataPointEnter = temp[0];
dataPoint = temp[1];
this.chart.drawMarker(svg, x, y, dataPointEnter, dataPoint);
this.chart.drawLegend(svg, dataPointEnter, dataPoint);
this.chart.drawText(svg);
this.chart.drawAxis(svg, xAxis1, yAxis1);
if (this.chart.shouldRedraw) {
this.redraw();
}
};
jsOMS.Chart.BarChart.prototype.redraw = function ()
{
this.chart.shouldRedraw = false;
this.chart.chartSelect.select("*").remove();
this.draw();
};
jsOMS.Chart.BarChart.prototype.drawData = function (svg, x, y, dataPointEnter, dataPoint)
{
const self = this;
let rect;
dataPoint = svg.selectAll(".dataPoint").data(this.chart.dataset, function (c)
{
return c.id;
});
dataPointEnter = dataPoint.enter().append("g").attr("class", "dataPoint")
.style("fill", function (d)
{
return self.chart.color(d.name);
});
rect = dataPointEnter.selectAll("rect")
.data(function (d)
{
return d.points;
})
.enter().append("rect")
.attr("y", function (d)
{
return y(d.x);
})
.attr("x", 0)
.attr("width", 0)
.attr("height", y.rangeBand());
if (this.chart.subtype === 'stacked') {
rect.transition()
.delay(function (d, i)
{
return i * 10;
})
.attr("x", function (d)
{
return x(d.y0);
})
.attr("width", function (d)
{
return x(d.y);
});
} else {
rect.transition()
.duration(500)
.delay(function (d, i)
{
return i * 10;
})
.attr("y", function (d, i, j)
{
return y(d.x) + y.rangeBand() / self.chart.dataset.length * j;
})
.attr("height", y.rangeBand() / self.chart.dataset.length)
.transition()
.attr("x", 0)
.attr("width", function (d)
{
return x(d.y);
});
}
return [dataPointEnter, dataPoint];
};
}(window.jsOMS = window.jsOMS || {}));

View File

View File

@ -1,155 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.CalendarChart = function (id)
{
this.chart = new jsOMS.Chart.ChartAbstract(id);
// Setting default chart values
this.chart.margin = {top: 5, right: 0, bottom: 0, left: 0};
/** global: d3 */
this.chart.color = d3.scale.quantize()
.domain([-.05, .05])
.range(d3.range(11).map(function(d) { return "q" + d + "-11"; }));
this.chart.subtype = 'calendar';
};
jsOMS.Chart.CalendarChart.prototype.getChart = function ()
{
return this.chart;
};
jsOMS.Chart.CalendarChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.CalendarChart.prototype.draw = function ()
{
let percent = d3.format(".1%"),
format = d3.time.format("%Y-%m-%d"),
svg, self = this;
this.chart.calculateDimension();
this.chart.cellSize = Math.min(this.chart.dimension.width / (12 * 5), this.chart.dimension.height / (8));
document.getElementById(this.chart.chartId)
.style.height = (this.chart.dimension.height * this.chart.dataset.length) + 'px';
svg = this.chart.chartSelect.selectAll('svg').data(this.chart.dataset).enter().append("svg")
.attr("width", this.chart.dimension.width)
.attr("height", this.chart.dimension.height)
.attr("class", "RdYlGn")
.append("g")
.attr("transform", "translate("
+ ((this.chart.dimension.width - this.chart.cellSize * 53) / 2)
+ "," + (this.chart.dimension.height - this.chart.cellSize * 7 - 1) + ")");
svg.append("text")
.attr("transform", "translate(-6," + this.chart.cellSize * 3.5 + ")rotate(-90)")
.style("text-anchor", "middle")
.text(function(d) { return d.name; });
let rect = svg.selectAll(".day")
.data(function(d) { return d3.time.days(new Date(parseInt(d.name), 0, 1), new Date(parseInt(d.name) + 1, 0, 1)); })
.enter().append("rect")
.attr("class", "day")
.attr("width", this.chart.cellSize)
.attr("height", this.chart.cellSize)
.attr("x", function(d) { return d3.time.weekOfYear(d) * self.chart.cellSize; })
.attr("y", function(d) { return d.getDay() * self.chart.cellSize; })
.datum(format);
rect.append("title")
.text(function(d) { });
svg.selectAll(".month")
.data(function(d) { return d3.time.months(new Date(parseInt(d.name), 0, 1), new Date(parseInt(d.name) + 1, 0, 1)); })
.enter().append("path")
.attr("class", "month")
.attr("d", function(t0) {
let t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0),
d0 = t0.getDay(), w0 = d3.time.weekOfYear(t0),
d1 = t1.getDay(), w1 = d3.time.weekOfYear(t1);
return "M" + (w0 + 1) * self.chart.cellSize + "," + d0 * self.chart.cellSize
+ "H" + w0 * self.chart.cellSize + "V" + 7 * self.chart.cellSize
+ "H" + w1 * self.chart.cellSize + "V" + (d1 + 1) * self.chart.cellSize
+ "H" + (w1 + 1) * self.chart.cellSize + "V" + 0
+ "H" + (w0 + 1) * self.chart.cellSize + "Z";
});
rect.filter(function(d) {
let year = d.split('-')[0],
length = self.chart.dataset.length;
for (let i = 0; i < length; ++i) {
if (self.chart.dataset[i].name != year) {
continue;
}
let dataLength = self.chart.dataset[i].points.length;
for (let j = 0; j < dataLength; ++j) {
if (self.chart.dataset[i].points[j].x === d) {
return true;
}
}
return false;
}
return false;
})
.attr("class", function(d) {
let year = d.split('-')[0],
length = self.chart.dataset.length;
for (let i = 0; i < length; ++i) {
if (self.chart.dataset[i].name != year) {
continue;
}
let dataLength = self.chart.dataset[i].points.length;
for (let j = 0; j < dataLength; ++j) {
if (self.chart.dataset[i].points[j].x === d) {
return "day " + self.chart.color(self.chart.dataset[i].points[j].y);
}
}
throw "Should not happen";
}
})
.select("title")
.text(function(d) {
let year = d.split('-')[0],
length = self.chart.dataset.length;
for (let i = 0; i < length; ++i) {
if (self.chart.dataset[i].name != year) {
continue;
}
let dataLength = self.chart.dataset[i].points.length;
for (let j = 0; j < dataLength; ++j) {
if (self.chart.dataset[i].points[j].x === d) {
return d + ": " + self.chart.dataset[i].points[j].y;
}
}
throw "Should not happen";
}
});
};
jsOMS.Chart.CalendarChart.prototype.redraw = function ()
{
this.chart.shouldRedraw = false;
this.chart.chartSelect.select("*").remove();
this.draw();
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,154 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.CandlestickChart = function (id)
{
this.chart = new jsOMS.Chart.ChartAbstract(id);
// Setting default chart values
this.chart.margin = {top: 5, right: 0, bottom: 0, left: 0};
/** global: d3 */
this.chart.color = d3.scale.category10();
this.chart.axis = {
x: {
visible: true,
label: {
visible: true,
text: 'X-Axis',
position: "center",
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
},
y: {
visible: true,
label: {
visible: true,
text: 'Y-Axis',
position: 'center',
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
},
y0: {
min: 0,
max: 0
}
};
this.chart.grid = {
x: {
visible: true
},
y: {
visible: true
}
};
this.chart.subtype = 'candlestick';
};
jsOMS.Chart.CandlestickChart.prototype.getChart = function ()
{
return this.chart;
};
jsOMS.Chart.CandlestickChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.CandlestickChart.prototype.draw = function ()
{
let bar, svg, x, xAxis1, xAxis2, y, yAxis1, yAxis2, xGrid, yGrid, zoom,
self = this,
mm = 50;
this.chart.calculateDimension();
x = this.chart.createXScale('linear');
y = this.chart.createYScale('linear');
xAxis1 = this.chart.createXAxis(x);
yAxis1 = this.chart.createYAxis(y);
xGrid = this.chart.createXGrid(x);
yGrid = this.chart.createYGrid(y);
x.domain([this.chart.axis.x.min - 1, this.chart.axis.x.max + 1]);
y.domain([this.chart.axis.y0.min - 1, this.chart.axis.y.max + 1]);
svg = this.chart.chartSelect.append("svg")
.attr("width", this.chart.dimension.width)
.attr("height", this.chart.dimension.height)
.append("g").attr("transform", "translate("
+ (this.chart.margin.left) + ","
+ (this.chart.margin.top) + ")");
this.chart.drawGrid(svg, xGrid, yGrid);
if (this.chart.subtype === 'candlestick') {
svg.selectAll("rect")
.data(this.chart.dataset[0].points)
.enter().append("svg:rect")
.attr("x", function(d) { return x(d.x) - 0.5 * mm / 2; })
.attr("y", function(d) { return y(Math.max(d.open, d.close)); })
.attr("height", function(d) { return Math.max(1, y(Math.min(d.open, d.close)) - y(Math.max(d.open, d.close)));})
.attr("width", function(d) { return 0.5 * mm; })
.attr("fill",function(d) { return d.open > d.close ? "red" : "green"; });
} else {
let datapoint = svg.selectAll("rect")
.data(this.chart.dataset[0].points)
.enter();
datapoint.append("svg:rect")
.attr("x", function(d) { return x(d.x) - 0.25 * mm / 2; })
.attr("y", function(d) {return y(d.open);})
.attr("height", function(d) { return 1;})
.attr("width", function(d) { return 0.25 * mm / 2; })
.attr("fill",function(d) { return d.open > d.close ? "red" : "green"; });
datapoint.append("svg:rect")
.attr("x", function(d) { return x(d.x); })
.attr("y", function(d) {return y(d.close);})
.attr("height", function(d) { return 1;})
.attr("width", function(d) { return 0.25 * mm / 2; })
.attr("fill",function(d) { return d.open > d.close ? "red" : "green"; });
}
svg.selectAll("line.stem")
.data(this.chart.dataset[0].points)
.enter().append("svg:line")
.attr("class", "stem")
.attr("x1", function(d) { return x(d.x);})
.attr("x2", function(d) { return x(d.x);})
.attr("y1", function(d) { return y(d.y);})
.attr("y2", function(d) { return y(d.y0); })
.attr("stroke", function(d){ return d.open > d.close ? "red" : "green"; });
this.chart.drawText(svg);
this.chart.drawAxis(svg, xAxis1, yAxis1);
if (this.chart.shouldRedraw) {
this.redraw();
}
};
jsOMS.Chart.CandlestickChart.prototype.redraw = function ()
{
this.chart.shouldRedraw = false;
this.chart.chartSelect.select("*").remove();
this.draw();
};
}(window.jsOMS = window.jsOMS || {}));

6
Chart/Chart.js vendored
View File

@ -1,6 +0,0 @@
(function (jsOMS) {
"use strict";
jsOMS.Chart.TextElement = function() {
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,642 +0,0 @@
(function (jsOMS)
{
"use strict";
/** @namespace jsOMS.Chart */
jsOMS.Autoloader.defineNamespace('jsOMS.Chart');
jsOMS.Chart.ChartAbstract = function (id)
{
/** global: d3 */
this.chartId = id;
this.chartSelect = d3.select('#' + this.chartId);
this.title = {
visible: true,
text: "",
anchor: "middle",
position: "center"
};
this.subtitle = {
visible: true,
text: "",
anchor: "middle",
position: "center"
};
this.footer = {
visible: true,
text: "",
anchor: "end",
position: "right"
};
this.legend = {
visible: true
};
this.color = d3.scale.category10();
this.dataset = [];
this.dataSettings = {
style: {
strokewidth: 3,
padding: 0
},
marker: {
visible: true,
type: 'circle'
},
info: {
visible: true
},
extremum: {
visible: false
},
values: {
visible: false
},
dataset: true, /* show dataset below */
interpolate: "linear" /* splines interpolation? */
};
this.dimension = {width: 0, height: 0};
this.margin = {top: 0, right: 0, bottom: 0, left: 0};
this.axis = {};
this.grid = {};
this.subtype = '';
this.clean();
};
jsOMS.Chart.ChartAbstract.prototype.calculateHorizontalPosition = function (position)
{
let x = 0;
if (position === 'center') {
x = (
this.dimension.width
- this.margin.right
- this.margin.left
) / 2;
} else if (position === 'left') {
x = 0;
} else if (position === 'right') {
x = this.dimension.width - this.margin.right - this.margin.left;
}
return x;
};
jsOMS.Chart.ChartAbstract.prototype.calculateVerticalPosition = function (position)
{
let y = 0;
if (position === 'center') {
y = -(this.dimension.height
- this.margin.top
- this.margin.bottom
) / 2;
} else if (position === 'bottom') {
y = -(this.dimension.height
- this.margin.top
- this.margin.bottom
);
} else if (position === 'top') {
y = -this.margin.top;
}
return y;
};
jsOMS.Chart.ChartAbstract.prototype.setColor = function (color)
{
this.color = color;
};
jsOMS.Chart.ChartAbstract.prototype.getColor = function ()
{
return this.color;
};
jsOMS.Chart.ChartAbstract.prototype.setAxis = function (id, axis)
{
this.axis[id] = jsOMS.merge(this.axis[id], axis);
// Setting axis dimensions in case dataset existss
if (Object.keys(this.dataset).length > 0) {
this.axis[id].max = d3.max(this.dataset, function (m)
{
return d3.max(m.points, function (d)
{
return d[id];
});
});
}
};
jsOMS.Chart.ChartAbstract.prototype.setMargin = function (top, right, bottom, left)
{
this.margin = {top: top, right: right, bottom: bottom, left: left};
};
jsOMS.Chart.ChartAbstract.prototype.setDimension = function (width, height)
{
this.dimension = {width: width, height: height};
};
jsOMS.Chart.ChartAbstract.prototype.getDimension = function ()
{
return this.dimension;
};
jsOMS.Chart.ChartAbstract.prototype.setDimensionRelative = function (relative)
{
this.relative = relative;
};
jsOMS.Chart.ChartAbstract.prototype.setTitle = function (title)
{
this.title = jsOMS.merge(this.title, title);
};
jsOMS.Chart.ChartAbstract.prototype.getTitle = function ()
{
return this.title;
};
jsOMS.Chart.ChartAbstract.prototype.setSubtitle = function (subtitle)
{
this.subtitle = subtitle;
};
jsOMS.Chart.ChartAbstract.prototype.getSubtitle = function ()
{
return this.subtitle;
};
jsOMS.Chart.ChartAbstract.prototype.setFooter = function (footer)
{
this.footer = footer;
};
jsOMS.Chart.ChartAbstract.prototype.getFooter = function ()
{
return this.footer;
};
jsOMS.Chart.ChartAbstract.prototype.setSubtype = function (subtype)
{
this.subtype = subtype;
};
jsOMS.Chart.ChartAbstract.prototype.getSubtype = function ()
{
return this.subtype;
};
jsOMS.Chart.ChartAbstract.prototype.setLegend = function (legend)
{
this.legend = jsOMS.merge(this.legend, legend);
};
jsOMS.Chart.ChartAbstract.prototype.getLegend = function ()
{
if (!this.legend) {
this.legend = new jsOMS.Chart.ChartAbstractLegend();
}
return this.legend;
};
jsOMS.Chart.ChartAbstract.prototype.addDataset = function (dataset)
{
this.dataset.push(dataset);
this.findAxisDomain();
};
jsOMS.Chart.ChartAbstract.prototype.setData = function (data)
{
this.dataset = data;
this.findAxisDomain();
};
jsOMS.Chart.ChartAbstract.prototype.findAxisDomain = function ()
{
for (const id in this.axis) {
if (!this.axis.hasOwnProperty(id)) {
continue;
}
this.axis[id].max = d3.max(this.dataset, function (m)
{
return d3.max(m.points, function (d)
{
return d[id];
});
});
this.axis[id].min = d3.min(this.dataset, function (d)
{
return d3.min(d.points, function (t)
{
return t[id];
});
});
}
};
jsOMS.Chart.ChartAbstract.prototype.getData = function ()
{
return this.dataset;
};
jsOMS.Chart.ChartAbstract.prototype.drawLegend = function (svg, dataPointEnter, dataPoint)
{
const self = this;
if (typeof this.legend !== 'undefined' && this.legend.visible) {
dataPointEnter.append("text").attr('class', 'dataPoint-name');
dataPoint.select("text.dataPoint-name").attr("x",
this.dimension.width
- this.margin.right
- this.margin.left + 20
).attr("y", function (d, i)
{
return i * 20 + 10 - 1;
}).attr("dy", ".35em").text(function (d)
{
return d.name;
});
dataPointEnter.append('circle').attr('class', 'dataPoint-dot');
dataPoint.select('circle.dataPoint-dot').attr('cx',
this.dimension.width
- this.margin.right
- this.margin.left + 10
).attr('cy', function (d, i)
{
return i * 20 + 10;
}).attr('r', 4).style('stroke', function (d)
{
return self.color(d.name);
});
dataPoint.exit().remove();
let tlength = this.chartSelect.select('.dataPoint-name').node().getComputedTextLength();
// Adding margin for legend
if (this.margin.right < tlength) {
this.margin.right = tlength + 30;
this.shouldRedraw = true;
}
} else if (this.margin.right > 10) {
this.margin.right = 10;
this.shouldRedraw = true;
}
};
jsOMS.Chart.ChartAbstract.prototype.drawMarker = function (svg, x, y, dataPointEnter, dataPoint)
{
const self = this;
let temp;
if (this.dataSettings.marker.visible) {
temp = dataPointEnter.append('g').attr('class', 'dots').attr('clip-path', 'url(#clipper1)').selectAll('circle').data(function (d)
{
return d.points;
}).enter().append('circle').attr('class', 'dot');
dataPoint.select('.dots').style('stroke', function (d)
{
return self.color(d.name);
}).selectAll('circle').transition().duration(500).attr('cy', function (d)
{
return y(d.y);
}).attr('cx', function (d)
{
return x(d.x);
}).attr('r', 4);
}
if (this.dataSettings.info.visible && this.dataSettings.marker.visible) {
temp = dataPointEnter.append('g').attr('class', 'dots');
let div = this.chartSelect.append("div").attr("class", "charttooltip").style("opacity", 0);
div.html(self.axis.x.label.text + ': ' + 100 + "<br/>" + self.axis.y.label.text + ': ' + 100);
temp.on("mouseover", function (d) {
let dim = div.node().getBoundingClientRect();
let pos = this.getBoundingClientRect();
div.transition()
.duration(200)
.style("opacity", .9);
div.html(self.axis.x.label.text + ': ' + d.x + "<br/>" + self.axis.y.label.text + ': ' + d.y)
.style("left", (x(d.x) + dim.width / 2) + "px")
.style("top", (y(d.y) + dim.height) + "px");
})
.on("mouseout", function (d) {
div.transition()
.duration(500)
.style("opacity", 0);
});
}
};
jsOMS.Chart.ChartAbstract.prototype.drawText = function (svg)
{
let temp, pos = 0, topmargin = 0;
/* No subtitle without title */
if (typeof this.subtitle !== 'undefined' && this.subtitle.text !== '' && this.subtitle.visible && typeof this.title !== 'undefined' && this.title.text !== '' && this.title.visible) {
pos = this.calculateHorizontalPosition(this.subtitle.position);
temp = svg.append("text")
.attr("class", "subtitle")
.attr('y', this.position.title.top)
.attr('x', pos)
.style("text-anchor", this.subtitle.anchor)
.text(this.subtitle.text);
topmargin = 10;
/* only add margin if subtitle exists */
if (!this.defined.text.subtitle) {
this.position.subtitle.top = temp.node().getBoundingClientRect().height / 2;
this.margin.top += temp.node().getBoundingClientRect().height / 2 + topmargin;
this.defined.text.subtitle = true;
this.shouldRedraw = true;
}
}
if (typeof this.title !== 'undefined' && this.title.text !== '' && this.title.visible) {
pos = this.calculateHorizontalPosition(this.title.position);
temp = svg.append("text")
.attr("class", "title")
.attr('y', -this.position.subtitle.top - topmargin)
.attr('x', pos)
.style("text-anchor", this.title.anchor)
.text(this.title.text);
if (!this.defined.text.title) {
this.position.title.top = 0;
this.margin.top += (temp.node().getBoundingClientRect().height) / 2 + this.position.subtitle.top / 2;
this.defined.text.title = true;
this.shouldRedraw = true;
}
}
if (typeof this.footer !== 'undefined' && this.footer.text !== '' && this.footer.visible) {
let spacer = 0;
// if no x axis available an element less will be drawn and the footer
// will be out of bounds.
if (typeof this.axis.x === 'undefined') {
spacer = -this.margin.top;
}
pos = this.calculateHorizontalPosition(this.footer.position);
temp = svg.append("text")
.attr("class", "footer")
.attr('y', this.dimension.height
- this.margin.bottom + spacer + this.position.footer.top)
.attr('x', pos)
.style("text-anchor", this.footer.anchor)
.text(this.footer.text);
if (!this.defined.text.footer) {
this.position.footer.top = temp.node().getBoundingClientRect().height;
this.margin.bottom += temp.node().getBoundingClientRect().height + 10;
this.defined.text.footer = true;
this.shouldRedraw = true;
}
}
};
jsOMS.Chart.ChartAbstract.prototype.drawAxis = function (svg, xAxis1, yAxis1)
{
// draw clipper
let defs = svg.append('svg').attr('width', 0).attr('height', 0).append('defs'), pos = 0, temp;
defs.append('clipPath').attr('id', 'clipper1').append('rect').attr('x', 0).attr('y', 0)
.attr('width',
this.dimension.width
- this.margin.right
- this.margin.left
)
.attr('height',
this.dimension.height
- this.margin.top
- this.margin.bottom
);
if (typeof this.axis.x !== 'undefined' && this.axis.x.visible) {
temp = svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + (
this.dimension.height
- this.margin.top
- this.margin.bottom
) + ")")
.call(xAxis1);
if (this.axis.x.label.visible) {
pos = this.calculateHorizontalPosition(this.axis.x.label.position);
temp.append("text")
.attr('y', 45)
.attr('x', pos)
.style("text-anchor", this.axis.x.label.anchor)
.text(this.axis.x.label.text);
}
if (!this.defined.axis.x) {
this.margin.bottom += 50;
this.defined.axis.x = true;
this.shouldRedraw = true;
}
}
if (typeof this.axis.y !== 'undefined' && this.axis.y.visible) {
temp = svg.append("g")
.attr("class", "y axis")
.attr("transform", "translate(0,0)")
.call(yAxis1);
if (this.axis.y.label.visible) {
pos = this.calculateVerticalPosition(this.axis.y.label.position);
temp.append("text")
.attr("transform", "rotate(-90)")
.attr("y", -this.margin.left + 10)
.attr('x', pos)
.style("text-anchor", this.axis.y.label.anchor)
.text(this.axis.y.label.text);
}
if (!this.defined.axis.y) {
this.margin.left += svg.select('.y.axis .tick').node().getBoundingClientRect().width + 25;
this.defined.axis.y = true;
this.shouldRedraw = true;
}
}
if (typeof this.axis.x2 !== 'undefined') {
}
if (typeof this.axis.y2 !== 'undefined') {
}
};
jsOMS.Chart.ChartAbstract.prototype.drawGrid = function (svg, xGrid, yGrid)
{
if (typeof this.grid.x !== 'undefined' && this.grid.x.visible) {
svg.append("g")
.attr("class", "x grid")
.attr("transform", "translate(0," + (this.dimension.height - this.margin.top - this.margin.bottom) + ")")
.call(xGrid);
}
if (typeof this.grid.y !== 'undefined' && this.grid.y.visible) {
svg.append("g")
.attr("class", "y grid")
.call(yGrid);
}
};
jsOMS.Chart.ChartAbstract.prototype.createXScale = function (type)
{
if (type === 'ordinal') {
return d3.scale.ordinal().rangeRoundBands([
0,
this.dimension.width
- this.margin.right
- this.margin.left
], 0.3);
} else {
return d3.scale.linear().range([
0,
this.dimension.width
- this.margin.right
- this.margin.left
]);
}
};
jsOMS.Chart.ChartAbstract.prototype.createYScale = function (type)
{
if (type === 'ordinal') {
return d3.scale.ordinal().rangeRoundBands([
0,
this.dimension.height
- this.margin.top
- this.margin.bottom
], 0.3);
} else {
return d3.scale.linear().range([
this.dimension.height
- this.margin.top
- this.margin.bottom,
10
]);
}
};
jsOMS.Chart.ChartAbstract.prototype.createXAxis = function (x) {
const self = this;
return d3.svg.axis().scale(x).tickFormat(function (d)
{
return self.axis.x.tick.prefix + d;
}).orient("bottom").outerTickSize(self.axis.x.tick.size)
.innerTickSize(self.axis.x.tick.size).tickPadding(7);
};
jsOMS.Chart.ChartAbstract.prototype.createYAxis = function (y) {
const self = this;
return d3.svg.axis().scale(y).tickFormat(function (d)
{
return self.axis.y.tick.prefix + d;
}).orient("left").outerTickSize(this.axis.y.tick.size)
.innerTickSize(this.axis.y.tick.size).tickPadding(7);
};
jsOMS.Chart.ChartAbstract.prototype.createXGrid = function (x) {
return d3.svg.axis()
.scale(x)
.orient("bottom")
//.ticks(0)
.tickSize(
-(this.dimension.height
- this.margin.top - 10
- this.margin.bottom), 0, 0)
.tickFormat("");
};
jsOMS.Chart.ChartAbstract.prototype.createYGrid = function (y) {
return d3.svg.axis()
.scale(y)
.orient("left")
//.ticks(0)
.tickSize(
-this.dimension.width
+ this.margin.right
+ this.margin.left, 0, 0)
.tickFormat("");
};
jsOMS.Chart.ChartAbstract.prototype.calculateDimension = function ()
{
let box = this.chartSelect.node().getBoundingClientRect();
this.dimension = {
width: box.width,
height: box.height
};
};
jsOMS.Chart.ChartAbstract.prototype.clean = function ()
{
this.margin = {top: 0, right: 0, bottom: 0, left: 0};
this.dimension = {width: 0, height: 0};
this.position = {
title: {
top: 0,
left: 0
},
subtitle: {
top: 0,
left: 0
},
footer: {
top: 0,
left: 0
},
zoompanel: {
top: 0,
left: 0
}
};
this.shouldRedraw = false;
this.defined = {
axis: {
x: false,
y: false
},
text: {
title: false,
subtitle: false,
footer: false
},
legend: false
};
this.chartSelect.select("*").remove();
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,49 +0,0 @@
(function (jsOMS) {
"use strict";
jsOMS.Chart.Legend = function () {
this.position = {x: 0, y: 0};
this.relative = true;
this.horizontal = false;
this.visible = true;
this.labels = []; // {title, color, marker}
};
jsOMS.Chart.Legend.prototype.addLabel = function(label) {
this.labels.push(label);
};
jsOMS.Chart.Legend.prototype.setVisibility = function(visibility) {
this.visible = visibility;
};
jsOMS.Chart.Legend.prototype.getVisibility = function() {
return this.visible;
};
jsOMS.Chart.Legend.prototype.setPosition = function(position) {
this.position = position;
};
jsOMS.Chart.Legend.prototype.getPosition = function() {
return this.position;
};
jsOMS.Chart.Legend.prototype.setRelative = function(relative) {
this.relative = relative;
};
jsOMS.Chart.Legend.prototype.isRelative = function() {
return this.relative;
};
jsOMS.Chart.Legend.prototype.setHorizontal = function(horizontal) {
this.horizontal = horizontal;
};
jsOMS.Chart.Legend.prototype.isHorizontal = function() {
return this.horizontal;
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,6 +0,0 @@
(function (jsOMS) {
"use strict";
jsOMS.Chart.TextElement = function() {
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,258 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.ColumnChart = function (id)
{
this.chart = new jsOMS.Chart.ChartAbstract(id);
// Setting default chart values
this.chart.margin = {top: 5, right: 0, bottom: 0, left: 0};
/** global: d3 */
this.chart.color = d3.scale.category10();
this.chart.axis = {
x: {
visible: true,
label: {
visible: true,
text: 'X-Axis',
position: "center",
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
},
y: {
visible: true,
label: {
visible: true,
text: 'Y-Axis',
position: 'center',
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
}
};
this.chart.grid = {
x: {
visible: false
},
y: {
visible: true
}
};
this.chart.dataSettings.marker.visible = false;
this.chart.subtype = 'stacked';
};
jsOMS.Chart.ColumnChart.prototype.getChart = function ()
{
return this.chart;
};
jsOMS.Chart.ColumnChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.ColumnChart.prototype.draw = function ()
{
let rect, svg, x, xAxis1, xAxis2, y, yAxis1, yAxis2, xGrid, yGrid, zoom, self = this;
if (this.chart.subtype === 'grouped') {
this.chart.axis.y.max = d3.max(this.chart.dataset, function (layer)
{
return d3.max(layer.points, function (d)
{
return d.y;
});
});
} else {
this.chart.axis.y.max = d3.max(this.chart.dataset, function (layer)
{
return d3.max(layer.points, function (d)
{
return d.y0 + d.y;
});
});
}
this.chart.calculateDimension();
x = this.chart.createXScale('ordinal');
y = this.chart.createYScale('linear');
xAxis1 = this.chart.createXAxis(x);
yAxis1 = this.chart.createYAxis(y);
xGrid = this.chart.createXGrid(x);
yGrid = this.chart.createYGrid(y);
x.domain(d3.range(this.chart.dataset[0].points.length)).rangeRoundBands([0, this.chart.dimension.width - this.chart.margin.right - this.chart.margin.left], .1);
y.domain([0, this.chart.axis.y.max + 1]);
svg = this.chart.chartSelect.append("svg")
.attr("width", this.chart.dimension.width)
.attr("height", this.chart.dimension.height)
.append("g").attr("transform", "translate("
+ (this.chart.margin.left) + ","
+ (this.chart.margin.top) + ")");
this.chart.drawGrid(svg, xGrid, yGrid);
let dataPoint = null,
dataPointEnter = null,
temp = this.drawData(svg, x, y, dataPointEnter, dataPoint);
dataPointEnter = temp[0];
dataPoint = temp[1];
this.chart.drawMarker(svg, x, y, dataPointEnter, dataPoint);
this.chart.drawLegend(svg, dataPointEnter, dataPoint);
this.chart.drawText(svg);
this.chart.drawAxis(svg, xAxis1, yAxis1);
if (this.chart.shouldRedraw) {
this.redraw();
}
};
jsOMS.Chart.ColumnChart.prototype.redraw = function ()
{
this.chart.shouldRedraw = false;
this.chart.chartSelect.select("*").remove();
this.draw();
};
jsOMS.Chart.ColumnChart.prototype.drawData = function (svg, x, y, dataPointEnter, dataPoint)
{
const self = this;
let rect;
dataPoint = svg.selectAll(".dataPoint").data(this.chart.dataset, function (c)
{
return c.id;
});
dataPointEnter = dataPoint.enter().append("g").attr("class", "dataPoint")
.style("fill", function (d)
{
return self.chart.color(d.name);
});
rect = dataPointEnter.selectAll("rect")
.data(function (d)
{
return d.points;
})
.enter().append("rect")
.attr("x", function (d)
{
return x(d.x);
})
.attr("y", this.chart.dimension.height - this.chart.margin.top - this.chart.margin.bottom)
.attr("width", x.rangeBand())
.attr("height", 0);
if (this.chart.subtype === 'stacked') {
rect.transition()
.delay(function (d, i)
{
return i * 10;
})
.attr("y", function (d)
{
return y(d.y0 + d.y);
})
.attr("height", function (d)
{
return y(d.y0) - y(d.y0 + d.y);
});
} else {
rect.transition()
.duration(500)
.delay(function (d, i)
{
return i * 10;
})
.attr("x", function (d, i, j)
{
return x(d.x) + x.rangeBand() / self.chart.dataset.length * j;
})
.attr("width", x.rangeBand() / self.chart.dataset.length)
.transition()
.attr("y", function (d)
{
return y(d.y);
})
.attr("height", function (d)
{
return self.chart.dimension.height - self.chart.margin.top - self.chart.margin.bottom - y(d.y);
});
}
return [dataPointEnter, dataPoint];
};
jsOMS.Chart.ColumnChart.prototype.transitionGrouped = function (x, y, rect, yMin, yMax)
{
y.domain([yMin, yMax]);
rect.transition()
.duration(500)
.delay(function (d, i)
{
return i * 10;
})
.attr("x", function (d, i, j)
{
return x(d.x) + x.rangeBand() / n * j;
})
.attr("width", x.rangeBand() / n)
.transition()
.attr("y", function (d)
{
return y(d.y);
})
.attr("height", function (d)
{
return self.chart.dimension.height - self.chart.margin.top - self.chart.margin.bottom - y(d.y);
});
};
jsOMS.Chart.ColumnChart.prototype.transitionStacked = function (x, y, rect, yMin, yMax)
{
y.domain([yMin, yMax]);
rect.transition()
.duration(500)
.delay(function (d, i)
{
return i * 10;
})
.attr("y", function (d)
{
return y(d.y0 + d.y);
})
.attr("height", function (d)
{
return y(d.y0) - y(d.y0 + d.y);
})
.transition()
.attr("x", function (d)
{
return x(d.x);
})
.attr("width", x.rangeBand());
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,26 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.DiffAreaChart = function (id)
{
this.chart = new jsOMS.Chart.LineChart(id);
this.chart.getChart().dataSettings.marker.visible = false;
this.chart.getChart().subtype = 'diffarea';
};
jsOMS.Chart.DiffAreaChart.prototype.getChart = function ()
{
return this.chart.getChart();
};
jsOMS.Chart.DiffAreaChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.DiffAreaChart.prototype.draw = function ()
{
return this.chart.draw();
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,28 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.DonutChart = function (id)
{
this.chart = new jsOMS.Chart.PieChart(id);
// Setting default chart values
this.chart.getChart().dataSettings.style.strokewidth = 0.3;
this.chart.getChart().subtype = 'donut';
};
jsOMS.Chart.DonutChart.prototype.getChart = function ()
{
return this.chart.getChart();
};
jsOMS.Chart.DonutChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.DonutChart.prototype.draw = function ()
{
this.chart.draw();
};
}(window.jsOMS = window.jsOMS || {}));

View File

View File

View File

@ -1,25 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.GroupedBarChart = function (id)
{
this.chart = new jsOMS.Chart.BarChart(id);
this.chart.getChart().subtype = 'grouped';
};
jsOMS.Chart.GroupedBarChart.prototype.getChart = function ()
{
return this.chart.getChart();
};
jsOMS.Chart.GroupedBarChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.GroupedBarChart.prototype.draw = function ()
{
this.chart.draw();
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,25 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.GroupedColumnChart = function (id)
{
this.chart = new jsOMS.Chart.ColumnChart(id);
this.chart.getChart().subtype = 'grouped';
};
jsOMS.Chart.GroupedColumnChart.prototype.getChart = function ()
{
return this.chart.getChart();
};
jsOMS.Chart.GroupedColumnChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.GroupedColumnChart.prototype.draw = function ()
{
this.chart.draw();
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,265 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.LineChart = function (id)
{
this.chart = new jsOMS.Chart.ChartAbstract(id);
// Setting default chart values
this.chart.margin = {top: 5, right: 0, bottom: 0, left: 0};
/** global: d3 */
this.chart.color = d3.scale.category10();
this.chart.axis = {
x: {
visible: true,
label: {
visible: true,
text: 'X-Axis',
position: "center",
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
},
y: {
visible: true,
label: {
visible: true,
text: 'Y-Axis',
position: 'center',
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
},
y0: {
visible: false,
min: 0,
max: 0
}
};
this.chart.grid = {
x: {
visible: true
},
y: {
visible: true
}
};
this.chart.subtype = 'line';
};
jsOMS.Chart.LineChart.prototype.getChart = function ()
{
return this.chart;
};
jsOMS.Chart.LineChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.LineChart.prototype.draw = function ()
{
let line, svg, x, xAxis1, xAxis2, y, yAxis1, yAxis2, xGrid, yGrid, zoom, self = this;
this.chart.calculateDimension();
x = this.chart.createXScale('linear');
y = this.chart.createYScale('linear');
xAxis1 = this.chart.createXAxis(x);
yAxis1 = this.chart.createYAxis(y);
xGrid = this.chart.createXGrid(x);
yGrid = this.chart.createYGrid(y);
x.domain([this.chart.axis.x.min, this.chart.axis.x.max + 1]);
y.domain([this.chart.axis.y.min - 1, this.chart.axis.y.max + 1]);
if (this.chart.subtype === 'area') {
line = d3.svg.area().interpolate(this.chart.dataSettings.interpolate).x(function (d)
{
return x(d.x);
}).y0(this.chart.getDimension().height).y1(function (d)
{
return y(d.y);
});
} else if (this.chart.subtype === 'diffarea') {
y.domain([this.chart.axis.y0.min - 1, this.chart.axis.y.max + 1]);
line = d3.svg.area().interpolate(this.chart.dataSettings.interpolate).x(function (d)
{
return x(d.x);
}).y0(function (d) {
return y(d.y0);
}).y1(function (d)
{
return y(d.y);
});
} else if (this.chart.subtype === 'stacked') {
line = d3.svg.area().interpolate(this.chart.dataSettings.interpolate).x(function (d)
{
return x(d.x);
}).y0(function (d)
{
return y(d.y0);
}).y1(function (d)
{
return y(d.y + d.y0);
});
} else if (this.chart.subtype === 'line') {
line = d3.svg.line().interpolate(this.chart.dataSettings.interpolate).x(function (d)
{
return x(d.x);
}).y(function (d)
{
return y(d.y);
});
} else {
return;
}
zoom = d3.behavior.zoom().x(x).scaleExtent([1, 2]).on('zoom', function ()
{
let tx, ty;
tx = d3.event.translate[0];
ty = d3.event.translate[1];
tx = Math.min(1,
Math.max(tx,
self.chart.dimension.width
- self.chart.margin.right
- self.chart.margin.left
- Math.round(x(self.chart.axis.y.max) - x(1)),
self.chart.dimension.width
- self.chart.margin.right
- self.chart.margin.left
- Math.round(x(self.chart.axis.y.max) - x(1)) * d3.event.scale));
zoom.translate([tx, ty]);
svg.select('.x.axis').call(xAxis1);
svg.select('.x.grid').call(xGrid);
svg.selectAll('.line').attr("d", function (d)
{
return line(d.points);
}).style("stroke", function (d)
{
return self.chart.color(d.name);
});
if (self.chart.subtype === 'stacked') {
return svg.selectAll('circle.dot').attr('cy', function (d)
{
return y(d.y + d.y0);
}).attr('cx', function (d)
{
return x(d.x);
}).attr('r', 4);
} else {
return svg.selectAll('circle.dot').attr('cy', function (d)
{
return y(d.y);
}).attr('cx', function (d)
{
return x(d.x);
}).attr('r', 4);
}
});
svg = this.chart.chartSelect.append("svg")
.attr("width", this.chart.dimension.width)
.attr("height", this.chart.dimension.height)
.append("g").attr("transform", "translate("
+ (this.chart.margin.left) + ","
+ (this.chart.margin.top) + ")");
this.chart.drawGrid(svg, xGrid, yGrid);
this.drawZoomPanel(svg, zoom);
zoom.scaleExtent([1, Number.MAX_VALUE]);
//svg.selectAll('.x.grid').transition().duration(500).call(xGrid);
//svg.selectAll('.x.axis').transition().duration(500).call(xAxis1);
//svg.selectAll('.y.axis').transition().duration(500).call(yAxis1);
let dataPoint = null,
dataPointEnter = null,
temp = this.drawData(svg, line, dataPointEnter, dataPoint);
dataPointEnter = temp[0];
dataPoint = temp[1];
this.chart.drawMarker(svg, x, y, dataPointEnter, dataPoint);
this.chart.drawLegend(svg, dataPointEnter, dataPoint);
this.chart.drawText(svg);
this.chart.drawAxis(svg, xAxis1, yAxis1);
if (this.chart.shouldRedraw) {
this.redraw();
}
return zoom.x(x);
};
jsOMS.Chart.LineChart.prototype.redraw = function ()
{
this.chart.shouldRedraw = false;
this.chart.chartSelect.select("*").remove();
this.draw();
};
jsOMS.Chart.LineChart.prototype.drawData = function (svg, line, dataPointEnter, dataPoint)
{
const self = this;
dataPoint = svg.selectAll(".dataPoint").data(this.chart.dataset, function (c)
{
return c.id;
});
dataPointEnter = dataPoint.enter().append("g").attr("class", "dataPoint");
dataPointEnter.append("path").attr('clip-path', 'url(#clipper1)').attr("class", self.chart.subtype);
dataPoint.select('path').style("stroke-width", this.chart.dataSettings.style.strokewidth).transition().duration(500).attr("d", function (d)
{
return line(d.points);
}).style("stroke", function (d)
{
return self.chart.color(d.name);
}).style("fill", function (d)
{
if (self.chart.subtype === 'area' || self.chart.subtype === 'stacked') {
return self.chart.color(d.name);
}
});
return [dataPointEnter, dataPoint];
};
jsOMS.Chart.LineChart.prototype.drawZoomPanel = function (svg, zoom)
{
this.chart.position.zoompanel.top = 10;
svg.append("rect")
.attr('class', 'zoom-panel')
.attr('y', this.chart.position.zoompanel.top)
.attr("width",
this.chart.dimension.width
- this.chart.margin.right
- this.chart.margin.left
)
.attr("height",
this.chart.dimension.height
- this.chart.margin.top
- this.chart.margin.bottom - this.chart.position.zoompanel.top
).call(zoom);
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,25 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.OhlcChart = function (id)
{
this.chart = new jsOMS.Chart.CandlestickChart(id);
this.chart.getChart().subtype = 'ohlc';
};
jsOMS.Chart.OhlcChart.prototype.getChart = function ()
{
return this.chart.getChart();
};
jsOMS.Chart.OhlcChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.OhlcChart.prototype.draw = function ()
{
return this.chart.draw();
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,104 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.PieChart = function (id)
{
this.chart = new jsOMS.Chart.ChartAbstract(id);
// Setting default chart values
this.chart.margin = {top: 5, right: 0, bottom: 0, left: 0};
/** global: d3 */
this.chart.color = d3.scale.category10();
this.chart.dataSettings.style.strokewidth = 1;
this.chart.dataSettings.style.padding = 3;
this.chart.subtype = 'pie';
};
jsOMS.Chart.PieChart.prototype.getChart = function ()
{
return this.chart;
};
jsOMS.Chart.PieChart.prototype.draw = function ()
{
let svg, arc;
this.chart.calculateDimension();
svg = this.chart.chartSelect.append("svg")
.attr("width", this.chart.dimension.width)
.attr("height", this.chart.dimension.height)
.append("g").attr("transform", "translate("
+ (this.chart.margin.left) + ","
+ (this.chart.margin.top) + ")");
let dataPoint = null,
dataPointEnter = null,
temp = this.drawData(svg, dataPointEnter, dataPoint);
dataPointEnter = temp[0];
dataPoint = temp[1];
this.chart.drawLegend(svg, dataPointEnter, dataPoint);
this.chart.drawText(svg);
if (this.chart.shouldRedraw) {
this.redraw();
}
};
jsOMS.Chart.PieChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.PieChart.prototype.redraw = function ()
{
this.chart.shouldRedraw = false;
this.chart.chartSelect.select("*").remove();
this.draw();
};
jsOMS.Chart.PieChart.prototype.drawData = function (svg, dataPointEnter, dataPoint)
{
const self = this;
let pie = d3.layout.pie()
.sort(null)
.value(function (d)
{
return d.value;
}),
radius = (
Math.min(this.chart.dimension.width, this.chart.dimension.height) / 2
- Math.max(this.chart.margin.right + this.chart.margin.left,
this.chart.margin.top + this.chart.margin.bottom)
),
innerRadius = radius - radius * self.chart.dataSettings.style.strokewidth,
arc = d3.svg.arc()
.outerRadius(function() { return radius; })
.innerRadius(function() { return innerRadius; });
dataPoint = svg.selectAll(".dataPoint").data(this.chart.dataset);
dataPoint.enter().append("g").attr("class", "dataPoint");
dataPointEnter = dataPoint.selectAll("path")
.data(function (d)
{
return pie(d.points);
}).enter().append('path')
.attr("transform", "translate("
+ ((this.chart.dimension.width - this.chart.margin.left - this.chart.margin.right) / 2 ) + ","
+ ((this.chart.dimension.height - this.chart.margin.bottom - this.chart.margin.top) / 2) + ")")
.attr('fill', function (d)
{
return self.chart.color(d.data.name);
})
.attr('d', arc)
.style('stroke', '#fff')
.style('stroke-width', this.chart.dataSettings.style.padding);
return [dataPointEnter, dataPoint];
};
}(window.jsOMS = window.jsOMS || {}));

View File

View File

View File

@ -1,204 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.PyramidChart = function (id)
{
this.chart = new jsOMS.Chart.ChartAbstract(id);
// Setting default chart values
this.chart.margin = {top: 5, right: 0, bottom: 0, left: 0};
/** global: d3 */
this.chart.color = d3.scale.category10();
this.chart.axis = {
x: {
visible: true,
label: {
visible: true,
text: 'X-Axis',
position: "center",
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
},
y: {
visible: true,
label: {
visible: true,
text: 'Y-Axis',
position: 'center',
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
}
};
this.chart.grid = {
x: {
visible: false
},
y: {
visible: true
}
};
this.chart.subtype = 'waterfall';
};
jsOMS.Chart.PyramidChart.prototype.getChart = function ()
{
return this.chart;
};
jsOMS.Chart.PyramidChart.prototype.setData = function (data)
{
let dataset = [{id: 1, name: 'Dataset', points: []}],
length = data.length,
add = 0;
for (let i = 0; i < length - 1; ++i) {
dataset[0].points[i] = { name: data[i].name, y0: add, y: data[i].value + add };
add += data[i].value;
}
dataset[0].points[length - 1] = { name: data[length - 1].name, y0: 0, y: add };
this.chart.setData(dataset);
};
jsOMS.Chart.PyramidChart.prototype.draw = function ()
{
let bar, svg, x, xAxis1, xAxis2, y, yAxis1, yAxis2, xGrid, yGrid, zoom,
self = this,
box = this.chart.chartSelect.node().getBoundingClientRect();
this.chart.dimension = {
width: box.width,
height: box.height
};
x = d3.scale.ordinal().rangeRoundBands([
0,
this.chart.dimension.width
- this.chart.margin.right
- this.chart.margin.left
], 0.3);
y = d3.scale.linear().range([
this.chart.dimension.height
- this.chart.margin.top
- this.chart.margin.bottom,
10
]);
xAxis1 = d3.svg.axis().scale(x).tickFormat(function (d)
{
return self.chart.axis.x.tick.prefix + d;
}).orient("bottom").outerTickSize(this.chart.axis.x.tick.size)
.innerTickSize(this.chart.axis.x.tick.size).tickPadding(7);
yAxis1 = d3.svg.axis().scale(y).tickFormat(function (d)
{
return self.chart.axis.y.tick.prefix + d;
}).orient("left").outerTickSize(this.chart.axis.y.tick.size)
.innerTickSize(this.chart.axis.y.tick.size).tickPadding(7);
xGrid = d3.svg.axis()
.scale(x)
.orient("bottom")
//.ticks(0)
.tickSize(
-(this.chart.dimension.height
- this.chart.margin.top - 10
- this.chart.margin.bottom), 0, 0)
.tickFormat("");
yGrid = d3.svg.axis()
.scale(y)
.orient("left")
//.ticks(0)
.tickSize(
-this.chart.dimension.width
+ this.chart.margin.right
+ this.chart.margin.left, 0, 0)
.tickFormat("");
x.domain(this.chart.dataset[0].points.map(function(d) { return d.name; }));
y.domain([0, d3.max(this.chart.dataset[0].points, function(d) { return d.y * 1.05; })]);
svg = this.chart.chartSelect.append("svg")
.attr("width", this.chart.dimension.width)
.attr("height", this.chart.dimension.height)
.append("g").attr("transform", "translate("
+ (this.chart.margin.left) + ","
+ (this.chart.margin.top) + ")");
this.chart.drawGrid(svg, xGrid, yGrid);
let dataPoint = null,
dataPointEnter = null,
temp = this.drawData(svg, x, y, dataPointEnter, dataPoint);
dataPointEnter = temp[0];
dataPoint = temp[1];
this.chart.drawText(svg);
this.chart.drawAxis(svg, xAxis1, yAxis1);
if (this.chart.shouldRedraw) {
this.redraw();
}
};
jsOMS.Chart.PyramidChart.prototype.redraw = function ()
{
this.chart.shouldRedraw = false;
this.chart.chartSelect.select("*").remove();
this.draw();
};
jsOMS.Chart.PyramidChart.prototype.drawData = function (svg, x, y, dataPointEnter, dataPoint)
{
const self = this;
dataPoint = svg.selectAll(".dataPoint").data(this.chart.dataset[0].points, function (c)
{
return c.name;
});
dataPointEnter = dataPoint.enter().append("g")
.attr("class", function(d) { return "dataPoint " + (d.y < d.y0 ? 'negative' : 'positive'); })
.attr("transform", function(d) { return "translate(" + x(d.name) + ",0)"; });
dataPointEnter.append("rect")
.attr("y", function(d) { return y( Math.max(d.y0, d.y) ); })
.attr("height", function(d) { return Math.abs( y(d.y0) - y(d.y) ); })
.attr("width", x.rangeBand());
dataPointEnter.append("text")
.attr("x", x.rangeBand() / 2)
.attr("y", function(d) { return y(d.y) + 5; })
.attr("dy", function(d) { return ((d.y < d.y0) ? '-' : '') + ".75em" })
.text(function(d) { return d.y - d.y0; });
dataPointEnter.filter(function(d) { return d.class != "total" }).append("line")
.attr("class", "connector")
.attr("x1", x.rangeBand() + 5 )
.attr("y1", function(d) { return y(d.y) } )
.attr("x2", x.rangeBand() / ( 1 - 5) - 5 )
.attr("y2", function(d) { return y(d.y) } );
return [dataPointEnter, dataPoint];
};
}(window.jsOMS = window.jsOMS || {}));

View File

View File

@ -1,143 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.ScatterplotChart = function (id)
{
this.chart = new jsOMS.Chart.ChartAbstract(id);
// Setting default chart values
this.chart.margin = {top: 5, right: 0, bottom: 0, left: 0};
/** global: d3 */
this.chart.color = d3.scale.category10();
this.chart.axis = {
x: {
visible: true,
label: {
visible: true,
text: 'X-Axis',
position: "center",
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
},
y: {
visible: true,
label: {
visible: true,
text: 'Y-Axis',
position: 'center',
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
}
};
this.chart.grid = {
x: {
visible: true
},
y: {
visible: true
}
};
this.chart.subtype = 'scatterplot';
};
jsOMS.Chart.ScatterplotChart.prototype.getChart = function ()
{
return this.chart;
};
jsOMS.Chart.ScatterplotChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.ScatterplotChart.prototype.draw = function ()
{
let bar, svg, x, xAxis1, xAxis2, y, yAxis1, yAxis2, xGrid, yGrid, zoom, self = this;
this.chart.calculateDimension('linear');
x = this.chart.createXScale('linear');
y = this.chart.createYScale('linear');
xAxis1 = this.chart.createXAxis(x);
yAxis1 = this.chart.createYAxis(y);
xGrid = this.chart.createXGrid(x);
yGrid = this.chart.createYGrid(y);
x.domain([this.chart.axis.x.min, this.chart.axis.x.max + 1]);
y.domain([this.chart.axis.y.min - 1, this.chart.axis.y.max + 1]);
svg = this.chart.chartSelect.append("svg")
.attr("width", this.chart.dimension.width)
.attr("height", this.chart.dimension.height)
.append("g").attr("transform", "translate("
+ (this.chart.margin.left) + ","
+ (this.chart.margin.top) + ")");
this.chart.drawGrid(svg, xGrid, yGrid);
let dataPoint = null,
dataPointEnter = null,
temp = this.drawData(svg, x, y, dataPointEnter, dataPoint);
dataPointEnter = temp[0];
dataPoint = temp[1];
this.chart.drawLegend(svg, dataPointEnter, dataPoint);
this.chart.drawText(svg);
this.chart.drawAxis(svg, xAxis1, yAxis1);
if (this.chart.shouldRedraw) {
this.redraw();
}
};
jsOMS.Chart.ScatterplotChart.prototype.redraw = function ()
{
this.chart.shouldRedraw = false;
this.chart.chartSelect.select("*").remove();
this.draw();
};
jsOMS.Chart.ScatterplotChart.prototype.drawData = function (svg, x, y, dataPointEnter, dataPoint)
{
const self = this;
dataPoint = svg.selectAll(".dataPoint").data(this.chart.dataset, function (c)
{
return c.id;
});
dataPointEnter = dataPoint.enter().append("g")
.attr("class", "dataPoint")
.style("fill", function(d) { return self.chart.color(d.name); });
dataPointEnter.selectAll("circle")
.data(function (d)
{
return d.points;
})
.enter().append("circle")
.attr("class", "dataPoint")
.attr("r", function(d) { return d.y0; })
.attr("cx", function(d) { return x(d.x); })
.attr("cy", function(d) { return y(d.y); });
return [dataPointEnter, dataPoint];
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,26 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.StackedAreaChart = function (id)
{
this.chart = new jsOMS.Chart.LineChart(id);
this.chart.getChart().dataSettings.marker.visible = false;
this.chart.getChart().subtype = 'stacked';
};
jsOMS.Chart.StackedAreaChart.prototype.getChart = function ()
{
return this.chart.getChart();
};
jsOMS.Chart.StackedAreaChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.StackedAreaChart.prototype.draw = function ()
{
return this.chart.draw();
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,25 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.StackedBarChart = function (id)
{
this.chart = new jsOMS.Chart.BarChart(id);
this.chart.getChart().subtype = 'stacked';
};
jsOMS.Chart.StackedBarChart.prototype.getChart = function ()
{
return this.chart.getChart();
};
jsOMS.Chart.StackedBarChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.StackedBarChart.prototype.draw = function ()
{
this.chart.draw();
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,25 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.StackedColumnChart = function (id)
{
this.chart = new jsOMS.Chart.ColumnChart(id);
this.chart.getChart().subtype = 'stacked';
};
jsOMS.Chart.StackedColumnChart.prototype.getChart = function ()
{
return this.chart.getChart();
};
jsOMS.Chart.StackedColumnChart.prototype.setData = function (data)
{
this.chart.setData(data);
};
jsOMS.Chart.StackedColumnChart.prototype.draw = function ()
{
this.chart.draw();
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,6 +0,0 @@
(function (jsOMS) {
"use strict";
jsOMS.Chart.TextElement = function() {
};
}(window.jsOMS = window.jsOMS || {}));

View File

View File

@ -1,154 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.VWaterfallChart = function (id)
{
this.chart = new jsOMS.Chart.ChartAbstract(id);
// Setting default chart values
this.chart.margin = {top: 5, right: 0, bottom: 0, left: 0};
/** global: d3 */
this.chart.color = d3.scale.category10();
this.chart.axis = {
x: {
visible: true,
label: {
visible: true,
text: 'X-Axis',
position: "center",
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
},
y: {
visible: true,
label: {
visible: true,
text: 'Y-Axis',
position: 'center',
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
}
};
this.chart.grid = {
x: {
visible: false
},
y: {
visible: true
}
};
this.chart.subtype = 'vwaterfall';
};
jsOMS.Chart.VWaterfallChart.prototype.getChart = function ()
{
return this.chart;
};
jsOMS.Chart.VWaterfallChart.prototype.setData = function (data)
{
let dataset = [{id: 1, name: 'Dataset', points: []}],
length = data.length,
add = 0;
for (let i = 0; i < length - 1; ++i) {
dataset[0].points[i] = { name: data[i].name, y0: add, y: data[i].value + add };
add += data[i].value;
}
dataset[0].points[length - 1] = { name: data[length - 1].name, y0: 0, y: add };
this.chart.setData(dataset);
};
jsOMS.Chart.VWaterfallChart.prototype.draw = function ()
{
let bar, svg, x, xAxis1, xAxis2, y, yAxis1, yAxis2, xGrid, yGrid, zoom, self = this;
this.chart.calculateDimension();
x = this.chart.createXScale('linear');
y = this.chart.createYScale('ordinal');
xAxis1 = this.chart.createXAxis(x);
yAxis1 = this.chart.createYAxis(y);
xGrid = this.chart.createXGrid(x);
yGrid = this.chart.createYGrid(y);
x.domain([0, d3.max(this.chart.dataset[0].points, function(d) { return d.y * 1.05; })]);
y.domain(this.chart.dataset[0].points.map(function(d) { return d.name; }));
svg = this.chart.chartSelect.append("svg")
.attr("width", this.chart.dimension.width)
.attr("height", this.chart.dimension.height)
.append("g").attr("transform", "translate("
+ (this.chart.margin.left) + ","
+ (this.chart.margin.top) + ")");
this.chart.drawGrid(svg, xGrid, yGrid);
let dataPoint = null,
dataPointEnter = null,
temp = this.drawData(svg, x, y, dataPointEnter, dataPoint);
dataPointEnter = temp[0];
dataPoint = temp[1];
this.chart.drawText(svg);
this.chart.drawAxis(svg, xAxis1, yAxis1);
if (this.chart.shouldRedraw) {
this.redraw();
}
};
jsOMS.Chart.VWaterfallChart.prototype.redraw = function ()
{
this.chart.shouldRedraw = false;
this.chart.chartSelect.select("*").remove();
this.draw();
};
jsOMS.Chart.VWaterfallChart.prototype.drawData = function (svg, x, y, dataPointEnter, dataPoint)
{
const self = this;
dataPoint = svg.selectAll(".dataPoint").data(this.chart.dataset[0].points, function (c)
{
return c.name;
});
dataPointEnter = dataPoint.enter().append("g")
.attr("class", function(d) { return "dataPoint " + (d.y < d.y0 ? 'negative' : 'positive'); })
.attr("transform", function(d) { return "translate(0," + y(d.name) + ")"; });
dataPointEnter.append("rect")
.attr("x", function(d) { return x( Math.min(d.y0, d.y) ); })
.attr("width", function(d) { return Math.abs( x(d.y0) - x(d.y) ); })
.attr("height", y.rangeBand());
dataPointEnter.filter(function(d) { return d.class != "total" }).append("line")
.attr("class", "connector")
.attr("x1", y.rangeBand() + 5 )
.attr("y1", function(d) { return x(d.y) } )
.attr("x2", y.rangeBand() / ( 1 - 5) - 5 )
.attr("y2", function(d) { return x(d.y) } );
return [dataPointEnter, dataPoint];
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,160 +0,0 @@
(function (jsOMS)
{
"use strict";
jsOMS.Chart.WaterfallChart = function (id)
{
this.chart = new jsOMS.Chart.ChartAbstract(id);
// Setting default chart values
this.chart.margin = {top: 5, right: 0, bottom: 0, left: 0};
/** global: d3 */
this.chart.color = d3.scale.category10();
this.chart.axis = {
x: {
visible: true,
label: {
visible: true,
text: 'X-Axis',
position: "center",
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
},
y: {
visible: true,
label: {
visible: true,
text: 'Y-Axis',
position: 'center',
anchor: 'middle'
},
tick: {
prefix: '',
orientation: 'bottom',
size: 7
},
min: 0,
max: 0
}
};
this.chart.grid = {
x: {
visible: false
},
y: {
visible: true
}
};
this.chart.subtype = 'waterfall';
};
jsOMS.Chart.WaterfallChart.prototype.getChart = function ()
{
return this.chart;
};
jsOMS.Chart.WaterfallChart.prototype.setData = function (data)
{
let dataset = [{id: 1, name: 'Dataset', points: []}],
length = data.length,
add = 0;
for (let i = 0; i < length - 1; ++i) {
dataset[0].points[i] = { name: data[i].name, y0: add, y: data[i].value + add };
add += data[i].value;
}
dataset[0].points[length - 1] = { name: data[length - 1].name, y0: 0, y: add };
this.chart.setData(dataset);
};
jsOMS.Chart.WaterfallChart.prototype.draw = function ()
{
let bar, svg, x, xAxis1, xAxis2, y, yAxis1, yAxis2, xGrid, yGrid, zoom, self = this;
this.chart.calculateDimension();
x = this.chart.createXScale('ordinal');
y = this.chart.createYScale('linear');
xAxis1 = this.chart.createXAxis(x);
yAxis1 = this.chart.createYAxis(y);
xGrid = this.chart.createXGrid(x);
yGrid = this.chart.createYGrid(y);
x.domain(this.chart.dataset[0].points.map(function(d) { return d.name; }));
y.domain([0, d3.max(this.chart.dataset[0].points, function(d) { return d.y * 1.05; })]);
svg = this.chart.chartSelect.append("svg")
.attr("width", this.chart.dimension.width)
.attr("height", this.chart.dimension.height)
.append("g").attr("transform", "translate("
+ (this.chart.margin.left) + ","
+ (this.chart.margin.top) + ")");
this.chart.drawGrid(svg, xGrid, yGrid);
let dataPoint = null,
dataPointEnter = null,
temp = this.drawData(svg, x, y, dataPointEnter, dataPoint);
dataPointEnter = temp[0];
dataPoint = temp[1];
this.chart.drawText(svg);
this.chart.drawAxis(svg, xAxis1, yAxis1);
if (this.chart.shouldRedraw) {
this.redraw();
}
};
jsOMS.Chart.WaterfallChart.prototype.redraw = function ()
{
this.chart.shouldRedraw = false;
this.chart.chartSelect.select("*").remove();
this.draw();
};
jsOMS.Chart.WaterfallChart.prototype.drawData = function (svg, x, y, dataPointEnter, dataPoint)
{
const self = this;
dataPoint = svg.selectAll(".dataPoint").data(this.chart.dataset[0].points, function (c)
{
return c.name;
});
dataPointEnter = dataPoint.enter().append("g")
.attr("class", function(d) { return "dataPoint " + (d.y < d.y0 ? 'negative' : 'positive'); })
.attr("transform", function(d) { return "translate(" + x(d.name) + ",0)"; });
dataPointEnter.append("rect")
.attr("y", function(d) { return y( Math.max(d.y0, d.y) ); })
.attr("height", function(d) { return Math.abs( y(d.y0) - y(d.y) ); })
.attr("width", x.rangeBand());
dataPointEnter.append("text")
.attr("x", x.rangeBand() / 2)
.attr("y", function(d) { return y(d.y) + 5; })
.attr("dy", function(d) { return ((d.y < d.y0) ? '-' : '') + ".75em" })
.text(function(d) { return d.y - d.y0; });
dataPointEnter.filter(function(d) { return d.class != "total" }).append("line")
.attr("class", "connector")
.attr("x1", x.rangeBand() + 5 )
.attr("y1", function(d) { return y(d.y) } )
.attr("x2", x.rangeBand() / ( 1 - 5) - 5 )
.attr("y2", function(d) { return y(d.y) } );
return [dataPointEnter, dataPoint];
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -24,9 +24,9 @@ export class Options
/**
* Set option.
*
* @param {int|string} key Option key
* @param {boolean|int|float|string|Array} value Option value
* @param {boolean} [overwrite] Overwrite value
* @param {number|string} key Option key
* @param {boolean|number|string|Object} value Option value
* @param {boolean} [overwrite] Overwrite value
*
* @return {boolean}
*
@ -46,9 +46,9 @@ export class Options
/**
* Get option.
*
* @param {int|string} key Option key
* @param {number|string} key Option key
*
* @return {boolean|int|float|string|Array}
* @return {null|boolean|number|string|Object}
*
* @since 1.0.0
*/
@ -64,7 +64,7 @@ export class Options
/**
* Remove option.
*
* @param {int|string} key Option key
* @param {number|string} key Option key
*
* @return {boolean}
*

View File

@ -24,7 +24,7 @@ export class LocalStorage
*
* @since 1.0.0
*/
static available()
static available ()
{
try {
return 'localStorage' in window && window.localStorage !== null;

View File

@ -1,6 +0,0 @@
export class Dispatcher
{
constructor ()
{
};
};

View File

@ -19,8 +19,13 @@ export class EventManager
*/
constructor ()
{
this.logger = Logger.getInstance();
this.groups = {};
/** @type {Logger} logger */
this.logger = Logger.getInstance();
/** @type {Object.<string, string>} groups */
this.groups = {};
/** @type {Object.<string, function>} callbacks */
this.callbacks = {};
};
@ -29,8 +34,8 @@ export class EventManager
*
* Adding the same event overwrites the existing one as "waiting"
*
* @param {string|int} group Group id
* @param {string|int} id Event id
* @param {string|number} group Group id
* @param {string|number} id Event id
*
* @return {void}
*
@ -48,7 +53,7 @@ export class EventManager
/**
* Resets the group status
*
* @param {string|int} group Group id
* @param {string|number} group Group id
*
* @return {void}
*
@ -57,7 +62,7 @@ export class EventManager
reset (group)
{
for (const id in this.groups[group]) {
if (this.groups[group].hasOwnProperty(id)) {
if (Object.prototype.hasOwnProperty.call(this.groups[group], id)) {
this.groups[group][id] = false;
}
}
@ -66,7 +71,7 @@ export class EventManager
/**
* Does group have outstanding events
*
* @param {string|int} group Group id
* @param {string|number} group Group id
*
* @return {boolean}
*
@ -79,7 +84,7 @@ export class EventManager
}
for (const id in this.groups[group]) {
if (!this.groups[group].hasOwnProperty(id) || !this.groups[group][id]) {
if (!Object.prototype.hasOwnProperty.call(this.groups[group], id) || !this.groups[group][id]) {
return true;
}
}
@ -90,9 +95,9 @@ export class EventManager
/**
* Trigger event based on regex for group and/or id
*
* @param {string|int} group Group id (can be regex)
* @param {string|int} [id] Event id (can be regex)
* @param {Object} [data] Data for event
* @param {string|number} group Group id (can be regex)
* @param {string|number} [id] Event id (can be regex)
* @param {null|Object} [data] Data for event
*
* @return {boolean}
*
@ -146,16 +151,16 @@ export class EventManager
}
return triggerValue;
}
};
/**
* 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
* @param {string|number} group Group id
* @param {string|number} [id] Event id
* @param {null|Object} [data] Data for event
*
* @return {boolean}
*
@ -198,7 +203,7 @@ export class EventManager
/**
* Detach event
*
* @param {string|int} group Group id
* @param {string|number} group Group id
*
* @return {void}
*
@ -212,15 +217,15 @@ export class EventManager
/**
* Detach callback
*
* @param {string|int} group Group id
* @param {string|number} group Group id
*
* @return {void}
* @return {boolean}
*
* @since 1.0.0
*/
detachCallback(group)
detachCallback (group)
{
if (this.callbacks.hasOwnProperty(group)) {
if (Object.prototype.hasOwnProperty.call(this.callbacks, group)) {
delete this.callbacks[group];
return true;
@ -232,15 +237,15 @@ export class EventManager
/**
* Detach group
*
* @param {string|int} group Group id
* @param {string|number} group Group id
*
* @return {void}
* @return {boolean}
*
* @since 1.0.0
*/
detachGroup(group)
detachGroup (group)
{
if (this.groups.hasOwnProperty(group)) {
if (Object.prototype.hasOwnProperty.call(this.groups, group)) {
delete this.groups[group];
return true;
@ -252,10 +257,10 @@ export class EventManager
/**
* 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
* @param {string|number} 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}
*
@ -263,8 +268,8 @@ export class EventManager
*/
attach (group, callback, remove = false, reset = false)
{
if (!this.callbacks.hasOwnProperty(group)) {
this.callbacks[group] = {remove: remove, reset: reset, callbacks: [], lastRun: 0};
if (!Object.prototype.hasOwnProperty.call(this.callbacks, group)) {
this.callbacks[group] = { remove: remove, reset: reset, callbacks: [], lastRun: 0 };
}
this.callbacks[group].callbacks.push(callback);
@ -275,7 +280,7 @@ export class EventManager
/**
* Is a certain group allready attached
*
* @param {string|int} group Group id
* @param {string|number} group Group id
*
* @return {boolean}
*
@ -283,13 +288,13 @@ export class EventManager
*/
isAttached (group)
{
return this.callbacks.hasOwnProperty(group);
return Object.prototype.hasOwnProperty.call(this.callbacks, group);
};
/**
* Count events
*
* @return {int}
* @return {number}
*
* @since 1.0.0
*/
@ -297,4 +302,4 @@ export class EventManager
{
return Object.keys(this.callbacks).length;
};
};
};

View File

View File

@ -14,17 +14,22 @@ export class Logger
/**
* @constructor
*
* @param {boolean} verbose Verbose logging
* @param {boolean} ui Ui logging
* @param {boolean} remote Remote logging
* @param {boolean} [verbose] Verbose logging
* @param {boolean} [ui] Ui logging
* @param {boolean} [remote] Remote logging
*
* @since 1.0.0
*/
constructor (verbose = true, ui = true, remote = false)
{
/** @type {boolean} verbose */
this.verbose = verbose;
this.ui = ui;
this.remote = remote;
/** @type {boolean} ui */
this.ui = ui;
/** @type {boolean} remote */
this.remote = remote;
};
/**
@ -34,7 +39,7 @@ export class Logger
* @param {boolean} [ui] Ui logging
* @param {boolean} [remote] Remote logging
*
* @return {Object}
* @return {Logger}
*
* @since 1.0.0
*/
@ -63,7 +68,7 @@ export class Logger
message = typeof message === 'undefined' ? Logger.MSG_FULL : message;
for (const replace in context) {
if (context.hasOwnProperty(replace) && typeof message === 'string') {
if (Object.prototype.hasOwnProperty.call(context, replace) && typeof message === 'string') {
message = message.replace('{' + replace + '}', context[replace]);
}
}
@ -123,19 +128,30 @@ export class Logger
}
};
/**
* Create ui log message
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
* @param {string} level Log level
*
* @return {void}
*
* @since 1.0.0
*/
writeUi (message, context, level)
{
/** global: Notification */
if (Notification.permission !== 'granted' && Notification.permission !== 'denied') {
Notification.requestPermission().then(function(permission) { });
Notification.requestPermission().then(function (permission) { });
}
/** global: Notification */
const notification = new Notification('Logger', {body: this.interpolate(message, context, level)});
const notification = new Notification('Logger', { body: this.interpolate(message, context, level) });
setTimeout(notification.close.bind(notification), 4000);
};
/**
* Create local log message
* Create local log message in console
*
* @param {string} message Message to display
* @param {Object} [context] Context to put into message
@ -186,7 +202,7 @@ export class Logger
*/
writeRemote (message, context, level)
{
let request = new Request();
const request = new Request();
request.setData(context);
request.setType(jsOMS.Message.Response.Response.ResponseType.JSON);
request.setUri('/{/lang}/api/log');

View File

@ -7,29 +7,29 @@
* @since 1.0.0
*/
(function (jsOMS) {
"use strict";
'use strict';
/**
* Evaluate math formula
*
* @param {string} equation Equation
*
* @return {null|int|float}
* @return {null|number}
*
* @since 1.0.0
*/
jsOMS.mathEvaluate = function(equation)
jsOMS.mathEvaluate = function (equation)
{
const stack = [],
postfix = jsOMS.shuntingYard(equation);
length = postfix.length;
const stack = [];
const postfix = jsOMS.shuntingYard(equation);
const length = postfix.length;
for (let i = 0; i < length; ++i) {
if (!isNaN(parseFloat(postfix[i])) && isFinite(postfix[i])) {
stack.push(postfix[i]);
} else {
let a = jsOMS.parseValue(stack.pop());
let b = jsOMS.parseValue(stack.pop());
const a = jsOMS.parseValue(stack.pop());
const b = jsOMS.parseValue(stack.pop());
if (postfix[i] === '+') {
stack.push(a + b);
@ -55,14 +55,14 @@
*
* @param {string} value Value to parse
*
* @return {int|float}
* @return {number}
*
* @since 1.0.0
*/
jsOMS.parseValue = function(value)
jsOMS.parseValue = function (value)
{
return typeof value === 'string' ? (value.indexOf('.') === -1 ? parseInt(value) : parseFloat(value)) : value;
}
};
/**
* Perform shunting yard
@ -73,20 +73,20 @@
*
* @since 1.0.0
*/
jsOMS.shuntingYard = function(equation)
jsOMS.shuntingYard = function (equation)
{
const stack = [];
const operators = {
'^': {precedence: 4, order: 1},
'*': {precedence: 3, order: -1},
'/': {precedence: 3, order: -1},
'+': {precedence: 2, order: -1},
'-': {precedence: 2, order: -1},
'^': { precedence: 4, order: 1 },
'*': { precedence: 3, order: -1 },
'/': { precedence: 3, order: -1 },
'+': { precedence: 2, order: -1 },
'-': { precedence: 2, order: -1 }
};
let output = [];
const output = [];
equation = equation.replace(/\s+/g, '');
equation = equation.split(/([\+\-\*\/\^\(\)])/).filter(function (n) { return n !== '' });
equation = equation.split(/([\+\-\*\/\^\(\)])/).filter(function (n) { return n !== ''; });
const length = equation.length;
let token;
@ -97,8 +97,8 @@
if (!isNaN(parseFloat(token)) && isFinite(token)) {
output.push(token);
} else if ('^*/+-'.indexOf(token) !== -1) {
let o1 = token;
let o2 = stack[stack.length - 1];
const o1 = token;
let o2 = stack[stack.length - 1];
while ('^*/+-'.indexOf(o2) !== -1
&& ((operators[o1].order === -1 && operators[o1].precedence <= operators[o2].precedence)
@ -126,6 +126,4 @@
return output;
};
}(window.jsOMS = window.jsOMS || {}));
}(window.jsOMS = window.jsOMS || {}));

View File

@ -2,4 +2,4 @@
// take images every x ms
// call calback on canvas to check image
// stop if match or manual stop
// return callback result
// return callback result

View File

@ -1,3 +1,5 @@
import { NotificationMessage } from '../NotificationMessage.js';
/**
* App notification.
*
@ -15,13 +17,14 @@ export class AppNotification
*/
constructor ()
{
/** @type {number} status */
this.status = 0;
};
/**
* Set notification status.
*
* @param {int} status Notification status
* @param {number} status Notification status
*
* @return {void}
*
@ -35,7 +38,7 @@ export class AppNotification
/**
* Create notification
*
* @param {Object} msg Notification
* @param {NotificationMessage} msg Notification
*
* @return {void}
*
@ -52,7 +55,7 @@ export class AppNotification
const output = document.importNode(tpl.content, true);
output.querySelector('.log-msg').classList.add('log-msg-status-' + msg.status);
output.querySelector('.log-msg-content').innerHTML = msg.message;
output.querySelector('.close').addEventListener('click', function() {
output.querySelector('.close').addEventListener('click', function () {
this.parentNode.remove();
});

View File

@ -1,3 +1,5 @@
import { NotificationMessage } from '../NotificationMessage.js';
/**
* Browser notification.
*
@ -13,15 +15,16 @@ export class BrowserNotification
*
* @since 1.0.0
*/
constructor()
constructor ()
{
/** @type {number} status */
this.status = 0;
};
/**
* Set notification status.
*
* @param {int} status Notification status
* @param {number} status Notification status
*
* @return {void}
*
@ -43,14 +46,14 @@ export class BrowserNotification
{
/** global: Notification */
if (Notification.permission !== 'granted' && Notification.permission !== 'denied') {
Notification.requestPermission().then(function(permission) { });
Notification.requestPermission().then(function (permission) { });
}
};
/**
* Create notification
*
* @param {Object} msg Notification
* @param {NotificationMessage} msg Notification
*
* @return {void}
*
@ -59,10 +62,10 @@ export class BrowserNotification
send (msg)
{
/** global: Notification */
if (Notification.permission === "granted") {
if (Notification.permission === 'granted') {
const notification = new Notification(msg.title, { body: msg.message, vibrate: [msg.vibrate ? 200 : 0] });
setTimeout(notification.close.bind(notification), 5000);
}
};
};
};

View File

@ -17,9 +17,12 @@ export class NotificationManager
*
* @since 1.0.0
*/
constructor()
constructor ()
{
this.appNotifier = new AppNotification();
/** @type {AppNotification} appNotifier */
this.appNotifier = new AppNotification();
/** @type {BrowserNotification} appNotifier */
this.browserNotifier = new BrowserNotification();
};
@ -27,7 +30,7 @@ export class NotificationManager
* Create notification.
*
* @param {Object} message Message object
* @param {int} type Notification type
* @param {number} type Notification type
*
* @return {void}
*
@ -45,7 +48,7 @@ export class NotificationManager
/**
* Get the app notification manager.
*
* @return {Object}
* @return {AppNotification}
*
* @since 1.0.0
*/
@ -57,7 +60,7 @@ export class NotificationManager
/**
* Get the browser notification manager.
*
* @return {Object}
* @return {BrowserNotification}
*
* @since 1.0.0
*/
@ -65,4 +68,4 @@ export class NotificationManager
{
return this.browserNotifier;
};
};
};

View File

@ -1,29 +1,39 @@
/**
* App notification.
*
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @since 1.0.0
*/
export class NotificationMessage
{
/**
* @constructor
*
* @param {string} status Message status
* @param {string} title Message title
* @param {string} message Message content
* @param {bool} [vibrate] Vibrate
*
* @since 1.0.0
*/
constructor(status, title, message, vibrate = false, isSticky = false)
{
this.status = status;
this.title = title;
this.message = message;
this.vibrate = vibrate
this.isSticky = isSticky
};
};
/**
* App notification message.
*
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @since 1.0.0
*/
export class NotificationMessage
{
/**
* @constructor
*
* @param {string} status Message status
* @param {string} title Message title
* @param {string} message Message content
* @param {boolean} [vibrate] Vibrate
* @param {boolean} [isSticky] Should remain in the ui until manually removed
*
* @since 1.0.0
*/
constructor (status, title, message, vibrate = false, isSticky = false)
{
/** @type {number} status */
this.status = status;
/** @type {string} title */
this.title = title;
/** @type {string} message */
this.message = message;
/** @type {boolean} vibrate */
this.vibrate = vibrate;
/** @type {boolean} isSticky */
this.isSticky = isSticky;
};
};

View File

@ -23,7 +23,7 @@ export const OSType = Object.freeze({
MAC_OS_X: 'macintosh', /* Mac OS X */
MAC_OS_X_2: 'mac os x', /* Mac OS X */
MAC_OS_9: 'mac_powerpc', /* Mac OS 9 */
LINUX : 'linux', /* Linux */
LINUX: 'linux', /* Linux */
UBUNTU: 'ubuntu', /* Ubuntu */
IPHONE: 'iphone', /* IPhone */
IPOD: 'ipod', /* IPod */

View File

@ -18,45 +18,60 @@ export class Request
/**
* @constructor
*
* @param {string} uri Request uri
* @param {string} method Request method/verb
* @param {string} type Request content type
* @param {null|string} [uri] Request uri
* @param {null|string} [method] Request method/verb
* @param {null|string} [type] Request content type
*
* @since 1.0.0
*/
constructor (uri = null, method, type)
constructor (uri = null, method = null, type = null)
{
this.uri = uri;
this.method = typeof method !== 'undefined' ? method : RequestMethod.GET;
this.requestHeader = [];
this.result = {};
this.type = typeof type !== 'undefined' ? type : RequestType.JSON;
this.data = {};
/** @type {null|string} uri */
this.uri = uri;
/** @type {string} method */
this.method = method !== null ? method : RequestMethod.GET;
/** @type {Object} requestHeader */
this.requestHeader = {};
/** @type {Object} result */
this.result = {};
/** @type {string} type */
this.type = type !== null ? type : RequestType.JSON;
/** @type {Object} data */
this.data = {};
this.requestHeader['Content-Type'] = this.setContentTypeBasedOnType(this.type);
if (this.type === RequestType.FORM_DATA) {
delete this.requestHeader['Content-Type'];
}
this.result[0] = function(xhr)
/** @type {XMLHttpRequest} xhr */
this.result[0] = function (xhr)
{
Logger.getInstance().info('Unhandled response from "' + xhr.responseURL + '" with response data "' + xhr.response + '"');
};
/** global: XMLHttpRequest */
// global: XMLHttpRequest
/** @type {XMLHttpRequest} xhr */
this.xhr = new XMLHttpRequest();
};
/**
* Defines the request content type based on the type
*
* @param {string} type Request type
*
* @return {string}
*
* @since 1.0.0
*/
setContentTypeBasedOnType(type)
setContentTypeBasedOnType (type)
{
switch(type) {
switch (type) {
case RequestType.JSON:
return 'application/json';
case RequestType.URL_ENCODE:
@ -77,7 +92,7 @@ export class Request
*
* @since 1.0.0
*/
static getBrowser()
static getBrowser ()
{
/** global: InstallTrigger */
/** global: navigator */
@ -87,7 +102,7 @@ export class Request
return BrowserType.FIREFOX;
} else if (Object.toString.call(window.HTMLElement).indexOf('Constructor') > 0) {
return BrowserType.SAFARI;
} else if (/*@cc_on!@*/false || !!document.documentMode) {
} else if ( /* @cc_on!@ */false || !!document.documentMode) {
return BrowserType.IE;
} else if (!!window.StyleMedia) {
return BrowserType.EDGE;
@ -110,10 +125,10 @@ export class Request
*
* @since 1.0.0
*/
static getOS()
static getOS ()
{
for (const os in OSType) {
if (OSType.hasOwnProperty(os)) {
if (Object.prototype.hasOwnProperty.call(OSType, os)) {
/** global: navigator */
if (navigator.appVersion.toLowerCase().indexOf(OSType[os]) !== -1) {
return OSType[os];
@ -127,15 +142,13 @@ export class Request
/**
* Set request method.
*
* EnumRequestMethod
*
* @param {string} method Method type
*
* @return {void}
*
* @since 1.0.0
*/
setMethod(method)
setMethod (method)
{
this.method = method;
};
@ -149,7 +162,7 @@ export class Request
*
* @since 1.0.0
*/
getMethod()
getMethod ()
{
return this.method;
};
@ -157,15 +170,13 @@ export class Request
/**
* Set response type.
*
* EnumResponseType
*
* @param {string} type Method type
*
* @return {void}
*
* @since 1.0.0
*/
setResponseType(type)
setResponseType (type)
{
this.xhr.responseType = type;
};
@ -173,13 +184,11 @@ export class Request
/**
* Get response type.
*
* EnumResponseType
*
* @return {string}
*
* @since 1.0.0
*/
getResponseType()
getResponseType ()
{
return this.responseType;
};
@ -194,7 +203,7 @@ export class Request
*
* @since 1.0.0
*/
setRequestHeader(type, header)
setRequestHeader (type, header)
{
this.requestHeader[type] = header;
@ -206,11 +215,11 @@ export class Request
/**
* Get request header.
*
* @return {Array}
* @return {Object}
*
* @since 1.0.0
*/
getRequestHeader()
getRequestHeader ()
{
return this.requestHeader;
};
@ -224,7 +233,7 @@ export class Request
*
* @since 1.0.0
*/
setUri(uri)
setUri (uri)
{
this.uri = uri;
};
@ -232,11 +241,11 @@ export class Request
/**
* Get request uri.
*
* @return {string}
* @return {null|string}
*
* @since 1.0.0
*/
getUri()
getUri ()
{
return this.uri;
};
@ -244,13 +253,13 @@ export class Request
/**
* Set success callback.
*
* @param {requestCallback} callback - Success callback
* @param {function} callback - Success callback
*
* @return {void}
*
* @since 1.0.0
*/
setSuccess(callback)
setSuccess (callback)
{
this.result[200] = callback;
};
@ -258,14 +267,14 @@ export class Request
/**
* Set result callback.
*
* @param {int} status Http response status
* @param {number} status Http response status
* @param {function} callback Callback
*
* @return {void}
*
* @since 1.0.0
*/
setResultCallback(status, callback)
setResultCallback (status, callback)
{
this.result[status] = callback;
};
@ -273,13 +282,13 @@ export class Request
/**
* Set request data.
*
* @param {Array} data Request data
* @param {Object} data Request data
*
* @return {void}
*
* @since 1.0.0
*/
setData(data)
setData (data)
{
this.data = data;
};
@ -287,11 +296,11 @@ export class Request
/**
* Get request data.
*
* @return {Array}
* @return {Object}
*
* @since 1.0.0
*/
getData()
getData ()
{
return this.data;
};
@ -299,15 +308,13 @@ export class Request
/**
* Set request type.
*
* EnumRequestType
*
* @param {string} type Method type
*
* @return {void}
*
* @since 1.0.0
*/
setType(type)
setType (type)
{
this.type = type;
this.requestHeader['Content-Type'] = this.setContentTypeBasedOnType(this.type);
@ -320,13 +327,11 @@ export class Request
/**
* Get request type.
*
* EnumRequestType
*
* @return {string}
*
* @since 1.0.0
*/
getType()
getType ()
{
return this.type;
};
@ -334,30 +339,32 @@ export class Request
/**
* Create query from object.
*
* @param {Object} obj Object to turn into uri query
*
* @return {string}
*
* @since 1.0.0
*/
queryfy(obj)
queryfy (obj)
{
const str = [];
for (const p in obj) {
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
if (Object.prototype.hasOwnProperty.call(obj, p)) {
str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
}
}
return str.join("&");
return str.join('&');
};
/**
* Get request data.
* Send request.
*
* @return {Array}
* @return {void}
*
* @since 1.0.0
*/
send()
send ()
{
if (this.uri === '') {
return;
@ -369,7 +376,7 @@ export class Request
this.xhr.open(this.method, UriFactory.build(this.uri));
for (const p in this.requestHeader) {
if (this.requestHeader.hasOwnProperty(p) && this.requestHeader[p] !== '') {
if (Object.prototype.hasOwnProperty.call(this.requestHeader, p) && this.requestHeader[p] !== '') {
this.xhr.setRequestHeader(p, this.requestHeader[p]);
}
}
@ -378,7 +385,7 @@ export class Request
console.log(UriFactory.build(this.uri));
console.log(this.xhr);
this.xhr.onreadystatechange = function()
this.xhr.onreadystatechange = function ()
{
switch (self.xhr.readyState) {
case 4:

View File

@ -13,33 +13,34 @@ export class Response
/**
* @constructor
*
* @param {mixed} data Response data
* @param {Object} data Response data
*
* @since 1.0.0
*/
constructor (data)
{
/** @type {Object} responses */
this.responses = data;
};
/**
* Get response by id.
*
* @param {string} id Response id
* @param {null|string} [id] Response id
*
* @return {mixed}
* @return {any}
*
* @since 1.0.0
*/
get (id)
get (id = null)
{
return typeof id === 'undefined' ? this.responses : this.responses[id];
return id === null ? this.responses : this.responses[id];
};
/**
* Count the amount of responses.
*
* @return {int}
* @return {number}
*
* @since 1.0.0
*/
@ -47,4 +48,4 @@ export class Response
{
return this.responses.length;
};
};
};

View File

@ -1,3 +1,5 @@
import { Request } from '../Request/Request.js';
/**
* Response manager class.
*
@ -15,8 +17,9 @@ export class ResponseManager
*
* @since 1.0.0
*/
constructor()
constructor ()
{
/** @type {Object} messages */
this.messages = {};
};
@ -25,15 +28,15 @@ export class ResponseManager
*
* This allows the response handler to generally handle responses and also handle specific requests if defined.
*
* @param {string} key Response key
* @param {requestCallback} message Callback for message
* @param {string} [request] Request id in order to only handle a specific request
* @param {string} key Response key
* @param {function} message Callback for message
* @param {null|string} [request] Request id in order to only handle a specific request
*
* @return {void}
*
* @since 1.0.0
*/
add(key, message, request)
add (key, message, request = null)
{
request = typeof request !== 'undefined' ? request : 'any';
if (typeof this.messages[key] === 'undefined') {
@ -48,17 +51,20 @@ export class ResponseManager
*
* Tries to execute a request specific callback or otherwise a general callback if defined.
*
* @param {string} key Response key
* @param {Array|Object} data Date to use in callback
* @param {jsOMS.Message.Request.Request} [request] Request id for request specific execution
* @param {string} key Response key
* @param {Object} data Date to use in callback
* @param {null|Request} [request] Request id for request specific execution
*
* @return {void}
*
* @since 1.0.0
*/
run(key, data, request)
run (key, data, request = null)
{
if (typeof request !== 'undefined' && typeof this.messages[key] !== 'undefined' && typeof this.messages[key][request] !== 'undefined') {
if (request !== null
&& typeof this.messages[key] !== 'undefined'
&& typeof this.messages[key][request] !== 'undefined'
) {
this.messages[key][request](data);
} else if (typeof this.messages[key] !== 'undefined') {
this.messages[key].any(data);

View File

@ -9,9 +9,13 @@
*/
export function domClickAction (action, callback, id)
{
"use strict";
'use strict';
const click = action.base === 'self' ? (action.selector === '' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector);
const click = action.base === 'self'
? (action.selector === ''
? [document.getElementById(id)]
: document.getElementById(id).querySelectorAll(action.selector))
: document.querySelectorAll(action.selector);
if (!click) {
return;
@ -22,4 +26,4 @@ export function domClickAction (action, callback, id)
}
callback();
};
};

View File

@ -8,10 +8,10 @@
*/
export function datalistAppend (action, callback)
{
"use strict";
'use strict';
const datalist = document.getElementById(action.id),
dataLength = action.data.length;
const datalist = document.getElementById(action.id);
const dataLength = action.data.length;
let option;

View File

@ -8,7 +8,7 @@
*/
export function datalistClear (action, callback)
{
"use strict";
'use strict';
const e = document.getElementById(action.id);

View File

@ -8,7 +8,7 @@
*/
export function focusAction (action, callback)
{
"use strict";
'use strict';
const focus = document.getElementById(action.id);
@ -19,4 +19,4 @@ export function focusAction (action, callback)
focus.focus();
callback();
};
};

View File

@ -9,7 +9,7 @@
*/
export function formSubmitAction (action, callback, id)
{
"use strict";
'use strict';
const submit = action.base === 'self' ? (action.selector === '' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector);
@ -24,4 +24,4 @@ export function formSubmitAction (action, callback, id)
}
callback();
};
};

View File

@ -9,22 +9,32 @@
*/
export function domGetValue (action, callback, id)
{
"use strict";
'use strict';
const e = action.base === 'self'
? (action.selector === '' || typeof action.selector === 'undefined'
? [document.getElementById(id)]
: document.getElementById(id).querySelectorAll(action.selector))
: document.querySelectorAll(action.selector);
const e = action.base === 'self' ? (action.selector === '' || typeof action.selector === 'undefined' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector);
let value = {};
for (const i in e) {
/** global: HTMLElement */
if (!e.hasOwnProperty(i) || !(e[i] instanceof HTMLElement)) {
if (!Object.prototype.hasOwnProperty.call(e, i) || !(e[i] instanceof HTMLElement)) {
continue;
}
let eId = (typeof e[i].getAttribute('name') !== 'undefined' && e[i].getAttribute('name') !== '' && e[i].getAttribute('name') !== null) ? e[i].getAttribute('name') : e[i].getAttribute('id');
const eId = (typeof e[i].getAttribute('name') !== 'undefined' && e[i].getAttribute('name') !== '' && e[i].getAttribute('name') !== null)
? e[i].getAttribute('name')
: e[i].getAttribute('id');
if (e[i].tagName === 'INPUT' || e[i].tagName === 'SELECTS' || e[i].tagName === 'BUTTON') {
if (e[i].tagName.toLowerCase() === 'input'
|| e[i].tagName.toLowerCase() === 'selects'
|| e[i].tagName.toLowerCase() === 'button'
) {
value[eId] = e[i].getAttribute('value');
} else if (e[i].tagName === 'FORM') {
} else if (e[i].tagName.toLowerCase() === 'form') {
value = window.omsApp.uiManager.getFormManager().get(eId).getData();
break;
} else {
@ -33,4 +43,4 @@ export function domGetValue (action, callback, id)
}
callback(value);
};
};

View File

@ -8,7 +8,7 @@
*/
export function hideAction (action, callback)
{
"use strict";
'use strict';
const hide = document.getElementById(action.id);
@ -20,4 +20,4 @@ export function hideAction (action, callback)
jsOMS.addClass(hide, 'vh');
callback();
};
};

View File

@ -9,13 +9,17 @@
*/
export function popupButtonAction (action, callback, id)
{
"use strict";
'use strict';
const popup = action.base === 'self' ? (action.selector === '' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector);
const popup = action.base === 'self'
? (action.selector === ''
? [document.getElementById(id)]
: document.getElementById(id).querySelectorAll(action.selector))
: document.querySelectorAll(action.selector);
for (const i in popup) {
/** global: HTMLElement */
if (!popup.hasOwnProperty(i) || !popup[i] || !(popup[i] instanceof HTMLElement)) {
if (!Object.prototype.hasOwnProperty.call(popup, i) || !popup[i] || !(popup[i] instanceof HTMLElement)) {
continue;
}
@ -27,7 +31,7 @@ export function popupButtonAction (action, callback, id)
}
for (const j in clone) {
if (!clone.hasOwnProperty(j) || !(clone[j] instanceof HTMLElement)) {
if (!Object.prototype.hasOwnProperty.call(clone, j) || !(clone[j] instanceof HTMLElement)) {
continue;
}
@ -36,7 +40,7 @@ export function popupButtonAction (action, callback, id)
document.body.insertBefore(clone, document.body.firstChild);
let e = document.getElementById(popup[i].id.substr(0, popup[i].id.length - 4));
const e = document.getElementById(popup[i].id.substr(0, popup[i].id.length - 4));
if (!e) {
continue;

View File

@ -9,7 +9,7 @@
*/
export function reloadButtonAction (action, callback, id)
{
"use strict";
'use strict';
setTimeout(function () {
document.location.reload(true);

View File

@ -9,14 +9,19 @@
*/
export function removeButtonAction (action, callback, id)
{
"use strict";
'use strict';
const e = action.base === 'self'
? (action.selector === '' || typeof action.selector === 'undefined'
? [document.getElementById(id)]
: document.getElementById(id).querySelectorAll(action.selector))
: document.querySelectorAll(action.selector);
const e = action.base === 'self' ? (action.selector === '' || typeof action.selector === 'undefined' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector);
const dim = document.getElementById('dim');
for (const i in e) {
/** global: HTMLElement */
if (!e.hasOwnProperty(i) || !e[i] || !(e[i] instanceof HTMLElement)) {
if (!Object.prototype.hasOwnProperty.call(e, i) || !e[i] || !(e[i] instanceof HTMLElement)) {
continue;
}

View File

@ -9,13 +9,17 @@
*/
export function domRemoveValue (action, callback, id)
{
"use strict";
'use strict';
const e = action.base === 'self' ? (action.selector === '' || typeof action.selector === 'undefined' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector);
const e = action.base === 'self'
? (action.selector === '' || typeof action.selector === 'undefined'
? [document.getElementById(id)]
: document.getElementById(id).querySelectorAll(action.selector))
: document.querySelectorAll(action.selector);
for (const i in e) {
/** global: HTMLElement */
if (!e.hasOwnProperty(i) || !(e[i] instanceof HTMLElement)) {
if (!Object.prototype.hasOwnProperty.call(e, i) || !(e[i] instanceof HTMLElement)) {
continue;
}
@ -35,4 +39,4 @@ export function domRemoveValue (action, callback, id)
}
callback();
};
};

View File

@ -9,15 +9,14 @@
*/
export function domSetValue (action, callback, id)
{
"use strict";
'use strict';
let dataPath = action['value'],
path = '',
tempDataValue = '',
values = [],
replaceText = '',
start = 0,
end = 0;
let dataPath = action.value;
let path = '';
let tempDataValue = '';
let replaceText = '';
let start = 0;
let end = 0;
while ((start = dataPath.indexOf('{', start)) !== -1) {
end = dataPath.indexOf('}', start);
@ -31,11 +30,15 @@ export function domSetValue (action, callback, id)
dataPath = dataPath.replace(new RegExp(replaceText.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), tempDataValue);
}
const fill = action.base === 'self' ? (action.selector === '' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector);
const fill = action.base === 'self'
? (action.selector === ''
? [document.getElementById(id)]
: document.getElementById(id).querySelectorAll(action.selector))
: document.querySelectorAll(action.selector);
for (const i in fill) {
/** global: HTMLElement */
if (!fill.hasOwnProperty(i) || !(fill[i] instanceof HTMLElement)) {
if (!Object.prototype.hasOwnProperty.call(fill, i) || !(fill[i] instanceof HTMLElement)) {
continue;
}
@ -65,4 +68,4 @@ export function domSetValue (action, callback, id)
}
callback(action.data);
};
};

View File

@ -9,7 +9,7 @@
*/
export function showAction (action, callback, id)
{
"use strict";
'use strict';
const show = document.getElementById(action.id);
@ -21,4 +21,4 @@ export function showAction (action, callback, id)
jsOMS.removeClass(show, 'vh');
callback();
};
};

View File

@ -8,15 +8,17 @@
*/
export function tableAppend (action, callback)
{
"use strict";
'use strict';
const table = document.getElementById(action.id),
tbody = table !== null && typeof table !== 'undefined' ? table.getElementsByTagName('tbody')[0] : null,
headers = table !== null && typeof table !== 'undefined' ? table.getElementsByTagName('thead')[0].getElementsByTagName('th') : null,
dataLength = action.data.length,
headerLength = headers !== null && typeof headers !== 'undefined' ? headers.length : 0;
const table = document.getElementById(action.id);
const tbody = table !== null && typeof table !== 'undefined' ? table.getElementsByTagName('tbody')[0] : null;
const headers = table !== null && typeof table !== 'undefined' ? table.getElementsByTagName('thead')[0].getElementsByTagName('th') : null;
const dataLength = action.data.length;
const headerLength = headers !== null && typeof headers !== 'undefined' ? headers.length : 0;
let row, cell, text, rawText;
let row;
let cell;
let rawText;
for (let i = 0; i < dataLength; ++i) {
if (tbody === null) {

View File

@ -8,7 +8,7 @@
*/
export function tableClear (action, callback)
{
"use strict";
'use strict';
const e = document.getElementById(action.id).getElementsByTagName('tbody')[0];

View File

@ -9,11 +9,11 @@
*/
export function preventEvent (action, callback, id)
{
"use strict";
'use strict';
console.log('prevented');
jsOMS.preventAll(action.data);
callback();
};
};

View File

@ -1,26 +1,26 @@
import { NotificationMessage } from '../../../Message/Notification/NotificationMessage.js';
import { NotificationType } from '../../../Message/Notification/NotificationType.js';
/**
* Log.
*
* @param {Object} action Action data
* @param {function} callback Callback
* @param {string} id Action element
*
* @since 1.0.0
*/
export function logAction (action, callback, id)
{
"use strict";
window.omsApp.notifyManager.send(
new NotificationMessage(
action.data.status,
action.data.title,
action.data.message
), NotificationType.APP_NOTIFICATION
);
callback();
};
import { NotificationMessage } from '../../../Message/Notification/NotificationMessage.js';
import { NotificationType } from '../../../Message/Notification/NotificationType.js';
/**
* Log.
*
* @param {Object} action Action data
* @param {function} callback Callback
* @param {string} id Action element
*
* @since 1.0.0
*/
export function logAction (action, callback, id)
{
'use strict';
window.omsApp.notifyManager.send(
new NotificationMessage(
action.data.status,
action.data.title,
action.data.message
), NotificationType.APP_NOTIFICATION
);
callback();
};

View File

@ -10,12 +10,12 @@ import { Request } from '../../../Message/Request/Request.js';
*/
export function requestAction (action, callback)
{
"use strict";
'use strict';
/** global: jsOMS */
const request = new Request(action.uri, action.method, action.request_type);
request.setSuccess(function(xhr) {
request.setSuccess(function (xhr) {
console.log(xhr.responseText);
callback(JSON.parse(xhr.responseText));
});

View File

@ -8,19 +8,20 @@
*/
export function dataCollectionAction (action, callback)
{
"use strict";
'use strict';
let elements, data = {};
let elements;
const data = {};
for (const selector in action.collect) {
if (!action.collect.hasOwnProperty(selector)) {
if (!Object.prototype.hasOwnProperty.call(action.collect, selector)) {
continue;
}
elements = document.querySelectorAll(action.collect[selector]);
for (const e in elements) {
if (!elements.hasOwnProperty(e)) {
if (!Object.prototype.hasOwnProperty.call(elements, e)) {
continue;
}

View File

@ -9,14 +9,14 @@
const timerActionDelay = {};
export function timerAction (action, callback, data)
{
"use strict";
'use strict';
if (timerActionDelay[action.id]) {
clearTimeout(timerActionDelay[action.id]);
delete timerActionDelay[action.id]
delete timerActionDelay[action.id];
}
timerActionDelay[action.id] = setTimeout(function() {
timerActionDelay[action.id] = setTimeout(function () {
delete timerActionDelay[action.id];
callback(data);
}, action.delay);

View File

@ -8,10 +8,10 @@
*/
export function validateKeypress (action, callback)
{
"use strict";
'use strict';
const invertValidate = action.pressed.startsWith('!'),
keyPressCheck = invertValidate ? action.pressed.split('!') : action.pressed.split('|');
const invertValidate = action.pressed.startsWith('!');
const keyPressCheck = invertValidate ? action.pressed.split('!') : action.pressed.split('|');
if (typeof action.data.keyCode !== 'undefined'
&& ((!invertValidate && keyPressCheck.indexOf(action.data.keyCode.toString()) !== -1)

View File

@ -24,4 +24,4 @@ export function domAction (data)
* identifier: #element or .elements or query
* anim: someclass
* delay: 0
*/
*/

View File

@ -16,7 +16,7 @@ export function formValidationMessage (data) {
while (eEles.length > 0) {
eEles[0].parentNode.removeChild(eEles[0]);
}
};
/**
* @param {{msg:string}} error Error data
@ -28,8 +28,8 @@ export function formValidationMessage (data) {
return;
}
const msgEle = document.createElement('i'),
msg = document.createTextNode(error.msg);
const msgEle = document.createElement('i');
const msg = document.createTextNode(error.msg);
msgEle.id = 'i-' + error.id;
msgEle.class = 'i-' + data.form;

View File

@ -9,11 +9,11 @@ export function notifyMessage (data)
{
setTimeout(function ()
{
const notify = document.createElement('div'),
h = document.createElement('h1'),
inner = document.createElement('div'),
title = document.createTextNode(data.title),
content = document.createTextNode(data.msg);
const notify = document.createElement('div');
const h = document.createElement('h1');
const inner = document.createElement('div');
const title = document.createTextNode(data.title);
const content = document.createTextNode(data.msg);
notify.id = 'notify';
notify.class = data.level;

View File

@ -13,4 +13,3 @@ export const EnumNotifyType = Object.freeze({
ERROR: 3,
FATAL: 4
});

View File

@ -16,7 +16,7 @@ export class ModuleManager
*
* @since 1.0.0
*/
constructor(app)
constructor (app)
{
this.modules = {};
this.app = app;
@ -39,4 +39,4 @@ export class ModuleManager
return this.modules[module];
};
};
};

View File

@ -1,18 +0,0 @@
(function (jsOMS) {
"use strict";
jsOMS.Autoloader.defineNamespace('jsOMS.Route');
jsOMS.Route.Route = class {
constructor ()
{
this.routes = null;
};
add (path, callback, exact)
{
exact = typeof exact !== 'undefined' ? exact : true;
};
}
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,5 +1,5 @@
(function (jsOMS) {
"use strict";
'use strict';
jsOMS.Client = function (ip, port, protocol) {
this.port = port;
@ -9,38 +9,38 @@
this.messages = [];
};
jsOMS.Client.prototype.setMessage = function(id, callback) {
jsOMS.Client.prototype.setMessage = function (id, callback) {
this.messages[id] = callback;
};
jsOMS.Client.prototype.setIp = function(ip) {
jsOMS.Client.prototype.setIp = function (ip) {
this.ip = ip;
};
jsOMS.Client.prototype.setPort = function(port) {
jsOMS.Client.prototype.setPort = function (port) {
this.port = port;
};
jsOMS.Client.prototype.setProtocol = function(protocol) {
jsOMS.Client.prototype.setProtocol = function (protocol) {
this.protocol = protocol;
};
jsOMS.Client.prototype.connect = function() {
jsOMS.Client.prototype.connect = function () {
var self = this;
this.connection = new WebSocket(this.ip, this.protocol);
this.connection.onmessage = function(event) {
this.connection.onmessage = function (event) {
var msg = JSON.parse(event.data);
self.messages[msg.type](msg);
};
};
jsOMS.Client.prototype.send = function(msg) {
jsOMS.Client.prototype.send = function (msg) {
this.connection.send(JSON.stringify(msg));
};
jsOMS.Client.prototype.close = function() {
jsOMS.Client.prototype.close = function () {
this.connection.close();
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -1,21 +0,0 @@
/**
* Cell.
*
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @since 1.0.0
*/
(function (jsOMS)
{
"use strict";
/** @namespace jsOMS.Spreadsheet */
jsOMS.Autoloader.defineNamespace('jsOMS.Spreadsheet');
jsOMS.Spreadsheet.Cell = function(id, raw)
{
this.id = id;
this.raw = raw;
this.formatting = raw.formatting;
};
}(window.jsOMS = window.jsOMS || {}));

View File

View File

@ -1,50 +0,0 @@
/**
* Spreadsheet view.
*
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @since 1.0.0
*/
(function (jsOMS)
{
"use strict";
/** @namespace jsOMS.Spreadsheet */
jsOMS.Autoloader.defineNamespace('jsOMS.Spreadsheet');
jsOMS.Spreadsheet.Spreadsheet = function(id, dataset, options)
{
this.spreadsheet = document.getElementById(id);
this.title = '';
this.sheets = [];
this.columns = true;
this.rows = true;
this.dataset = [];
this.compiledData = [];
this.scroll = {h: false, v: false};
};
jsOMS.SpreadSheet.prototype.draw = function()
{
let col = 0,
row = 0,
cRows = this.dataset.length(),
cCols = 0;
j = 0,
this.compiledData = this.dataset;
for (let i = 0; i < cRows; ++i) {
cCols = this.compiledData[i].length();
for (j = 0; j < cCols; ++j) {
this.compiledData[i][j] = Functions.evaluate(this.compiledData[i][j], compiledData);
this.drawCell(this.compiledData[i][j]);
}
}
};
jsOMS.SpreadSheet.prototype.drawCell = function()
{
};
}(window.jsOMS = window.jsOMS || {}));

View File

@ -34,7 +34,7 @@ export class ActionManager
*
* @since 1.0.0
*/
constructor(app)
constructor (app)
{
this.logger = Logger.getInstance();
this.app = app;
@ -44,16 +44,16 @@ export class ActionManager
/**
* Bind element.
*
* @param {string} [id] Element id (optional)
* @param {null|string} [id] Element id (optional)
*
* @return {void}
*
* @since 1.0.0
*/
bind(id)
bind (id = null)
{
const uiElements = typeof id === 'undefined' ? document.querySelectorAll('[data-action]') : (typeof id.length !== 'undefined' ? id : [id]),
length = uiElements.length;
const uiElements = id == null ? document.querySelectorAll('[data-action]') : (typeof id.length !== 'undefined' ? id : [id]);
const length = uiElements.length;
for (let i = 0; i < length; ++i) {
if (uiElements[i] !== null && uiElements[i].hasAttribute('data-action')) {
@ -79,21 +79,22 @@ export class ActionManager
return;
}
const listeners = JSON.parse(e.getAttribute('data-action')),
listenerLength = listeners.length,
self = this;
const listeners = JSON.parse(e.getAttribute('data-action'));
const listenerLength = listeners.length;
const self = this;
// For every action an event is registered
for (let i = 0; i < listenerLength; ++i) {
let c = [e], hasSelector = false;
let c = [e];
let hasSelector = false;
// the selector must be a child of e!!!
if (listeners[i].hasOwnProperty('selector')) {
if (Object.prototype.hasOwnProperty.call(listeners[i], 'selector')) {
c = document.querySelectorAll(listeners[i].selector);
hasSelector = true;
}
let childLength = c.length;
const childLength = c.length;
for (let j = 0; j < childLength; ++j) {
this.bindListener(c[j].id, listeners[i]);
}
@ -108,7 +109,7 @@ export class ActionManager
const observeConfig = { childList: false, attributes: true, subtree: false };
if (hasSelector) {
this.app.eventManager.attach(e.id + '-childList', function(data) {
this.app.eventManager.attach(e.id + '-childList', function (data) {
const length = data.addedNodes.length;
for (let j = 0; j < length; ++j) {
@ -124,7 +125,7 @@ export class ActionManager
observeConfig.subtree = true;
}
this.app.eventManager.attach(e.id + '-attributes', function(data) {});
this.app.eventManager.attach(e.id + '-attributes', function (data) {});
this.app.uiManager.getDOMObserver().observe(e, observeConfig);
}
};
@ -141,8 +142,8 @@ export class ActionManager
*/
bindListener (id, listener, removable = false)
{
const self = this,
actionLength = listener.action.length;
const self = this;
const actionLength = listener.action.length;
for (let j = 1; j < actionLength; ++j) {
if (typeof id === 'undefined' || typeof listener.key === 'undefined') {
@ -187,7 +188,7 @@ export class ActionManager
{
const self = this;
if (!this.actions.hasOwnProperty(action.type)) {
if (!Object.prototype.hasOwnProperty.call(this.actions, action.type)) {
this.logger.warning('Undefined action ' + action.type);
return;
}
@ -214,4 +215,4 @@ export class ActionManager
{
this.actions[name] = callback;
};
};
};

View File

@ -1,4 +1,5 @@
import { Request } from '../../Message/Request/Request.js';
import { EventManager } from '../../Event/EventManager.js';
/**
* Advanced input class.
@ -13,14 +14,20 @@ export class AdvancedInput
/**
* @constructor
*
* @param {Object} e Element to bind
* @param {Element} e Element to bind
* @param {EventManager} eventManager Event manager
* @param {Object} observer Observer
*
* @since 1.0.0
*/
constructor (e, eventManager, observer)
{
this.id = e.id;
this.inputComponent = e;
/** @type {string} id */
this.id = e.id;
/** @type {Element} e */
this.inputComponent = e;
this.inputField = this.inputComponent.getElementsByClassName('input')[0];
this.dropdownElement = document.getElementById(this.id + '-popup');
this.tagElement = document.getElementById(this.id + '-tags');
@ -31,23 +38,23 @@ export class AdvancedInput
this.src = this.inputField.getAttribute('data-src');
const self = this;
this.inputField.addEventListener('focusout', function(e) {
this.inputField.addEventListener('focusout', function (e) {
/**
* @todo Karaka/Modules#63
* If you click anything outside of the input element the dropdown list closes.
* This is also true if you click something inside of the dropdown list e.g. sort/filter etc.
* This might be fixable by changing the focus from the input element to the dropdown element and keep the dropdown element visible if it has focus.
*/
if (e.relatedTarget === null ||
e.relatedTarget.parentElement === null ||
e.relatedTarget.parentElement.parentElement === null ||
!jsOMS.hasClass(e.relatedTarget.parentElement.parentElement.parentElement, 'popup')
if (e.relatedTarget === null
|| e.relatedTarget.parentElement === null
|| e.relatedTarget.parentElement.parentElement === null
|| !jsOMS.hasClass(e.relatedTarget.parentElement.parentElement.parentElement, 'popup')
) {
jsOMS.removeClass(self.dropdownElement, 'active');
}
});
this.inputField.addEventListener('keydown', function(e) {
this.inputField.addEventListener('keydown', function (e) {
if (e.keyCode === 13 || e.keyCode === 40) {
jsOMS.preventAll(e);
}
@ -58,15 +65,15 @@ export class AdvancedInput
jsOMS.preventAll(e);
} else {
// handle change delay
self.inputTimeDelay({id: self.id, delay: 300}, self.changeCallback, self, e);
self.inputTimeDelay({ id: self.id, delay: 300 }, self.changeCallback, self, e);
}
});
this.inputField.addEventListener('focusin', function(e) {
this.inputField.addEventListener('focusin', function (e) {
jsOMS.addClass(self.dropdownElement, 'active');
});
this.dropdownElement.addEventListener('keydown', function(e) {
this.dropdownElement.addEventListener('keydown', function (e) {
jsOMS.preventAll(e);
/**
@ -99,12 +106,12 @@ export class AdvancedInput
}
});
this.dropdownElement.addEventListener('focusout', function(e) {
this.dropdownElement.addEventListener('focusout', function (e) {
self.clearDataListSelection(self);
jsOMS.removeClass(self.dropdownElement, 'active');
});
this.dropdownElement.addEventListener('click', function(e) {
this.dropdownElement.addEventListener('click', function (e) {
if (document.activeElement.tagName.toLowerCase() !== 'tr') {
return;
}
@ -115,7 +122,7 @@ export class AdvancedInput
});
observer.observe(this.tagElement, { childList: true, attributes: false, subtree: false });
eventManager.attach(this.id + '-tags-childList', function(data) {
eventManager.attach(this.id + '-tags-childList', function (data) {
const removes = data.target.querySelectorAll('.fa-times');
const removesLength = removes === null ? 0 : removes.length;
@ -123,7 +130,7 @@ export class AdvancedInput
return;
}
removes[removesLength - 1].addEventListener('click', function(e) {
removes[removesLength - 1].addEventListener('click', function (e) {
if (e.target.parentNode.parentNode === null) {
return;
}
@ -131,7 +138,6 @@ export class AdvancedInput
e.target.parentNode.parentNode.removeChild(e.target.parentNode);
});
});
};
/**
@ -139,14 +145,14 @@ export class AdvancedInput
*
* This method adds remote results to the dropdown list for selecting
*
* @param {Object} self This reference
* @param {Object} data Response data
* @param {AdvancedInput} self This reference
* @param {Object} data Response data
*
* @return {void}
*
* @since 1.0.0
*/
remoteCallback(self, data)
remoteCallback (self, data)
{
console.log(data);
data = JSON.parse(data.response)[0];
@ -189,7 +195,7 @@ export class AdvancedInput
newRow.firstElementChild.setAttribute('data-data', JSON.stringify(data[i]));
self.dataListBody.appendChild(newRow);
self.dataListBody.lastElementChild.addEventListener('focusout', function(e) {
self.dataListBody.lastElementChild.addEventListener('focusout', function (e) {
if (e.relatedTarget === null) {
return;
}
@ -209,13 +215,13 @@ export class AdvancedInput
/**
* Callback for input field content change
*
* @param {Object} self This reference
* @param {AdvancedInput} self This reference
*
* @return {void}
*
* @since 1.0.0
*/
changeCallback(self)
changeCallback (self)
{
// if remote data
if (typeof self.src !== 'undefined' && self.src !== '') {
@ -228,13 +234,13 @@ export class AdvancedInput
/**
* Select element in dropdown (only mark it as selected)
*
* @param {Object} e Element to select in dropdown
* @param {Element} e Element to select in dropdown
*
* @return {void}
*
* @since 1.0.0
*/
selectOption(e)
selectOption (e)
{
e.focus();
@ -249,19 +255,18 @@ export class AdvancedInput
/**
* Clear all selected/marked options in dropdown
*
* @param {Object} self This reference
* @param {AdvancedInput} self This reference
*
* @return {void}
*
* @since 1.0.0
*/
clearDataListSelection(self)
clearDataListSelection (self)
{
const list = self.dataListBody.getElementsByTagName('tr'),
length = list.length;
const list = self.dataListBody.getElementsByTagName('tr');
const length = list.length;
for (let i = 0; i < length; ++i) {
/**
* @todo Karaka/jsOMS#70
* Implement external styles for selections instead of inline css
@ -276,14 +281,14 @@ export class AdvancedInput
*
* This can add the selected dropdown elements to a table, badge list etc. depending on the template structure.
*
* @param {Object} self This reference
* @param {Element} e Element
* @param {AdvancedInput} self This reference
* @param {Element} e Element
*
* @return {void}
*
* @since 1.0.0
*/
addToResultList(self, e) {
addToResultList (self, e) {
const data = JSON.parse(e.getAttribute('data-data'));
if (self.inputField.getAttribute('data-autocomplete') === 'true') {
@ -350,7 +355,7 @@ export class AdvancedInput
// allow limit
if (self.tagElement.childElementCount >= self.tagElement.getAttribute('data-limit')
&& self.tagElement.getAttribute('data-limit') != 0
&& self.tagElement.getAttribute('data-limit') !== '0'
) {
self.tagElement.removeChild(self.tagElement.firstElementChild);
}
@ -370,27 +375,27 @@ export class AdvancedInput
*
* After waiting for a delay a callback can be triggered.
*
* @param {Object} action Action type
* @param {function} callback Callback to be triggered
* @param {Object} self This reference (passed to callback)
* @param {Object} data Data (passed to callback)
* @param {Object} action Action type
* @param {function} callback Callback to be triggered
* @param {AdvancedInput} self This reference (passed to callback)
* @param {Object} data Data (passed to callback)
*
* @return {void}
*
* @since 1.0.0
*/
inputTimeDelay(action, callback, self, data)
inputTimeDelay (action, callback, self, data)
{
if (AdvancedInput.timerDelay[action.id]) {
clearTimeout(AdvancedInput.timerDelay[action.id]);
delete AdvancedInput.timerDelay[action.id]
delete AdvancedInput.timerDelay[action.id];
}
AdvancedInput.timerDelay[action.id] = setTimeout(function() {
AdvancedInput.timerDelay[action.id] = setTimeout(function () {
delete AdvancedInput.timerDelay[action.id];
callback(self, data);
}, action.delay);
};
};
AdvancedInput.timerDelay = {};
AdvancedInput.timerDelay = {};

View File

@ -24,7 +24,7 @@ export class AdvancedSelect
*
* @since 1.0.0
*/
constructor(e) {
constructor (e) {
this.id = e.id;
this.selectComponent = e;
this.selectField = this.selectComponent.getElementsByClassName('input')[0];
@ -44,10 +44,10 @@ export class AdvancedSelect
* This is also true if you click something inside of the dropdown list e.g. sort/filter etc.
* This might be fixable by changing the focus from the input element to the dropdown element and keep the dropdown element visible if it has focus.
*/
if (e.relatedTarget === null ||
e.relatedTarget.parentElement === null ||
e.relatedTarget.parentElement.parentElement === null ||
!jsOMS.hasClass(e.relatedTarget.parentElement.parentElement.parentElement, 'popup')
if (e.relatedTarget === null
|| e.relatedTarget.parentElement === null
|| e.relatedTarget.parentElement.parentElement === null
|| !jsOMS.hasClass(e.relatedTarget.parentElement.parentElement.parentElement, 'popup')
) {
jsOMS.removeClass(self.dropdownElement, 'active');
}
@ -132,7 +132,7 @@ export class AdvancedSelect
*
* @since 1.0.0
*/
remoteCallback(self, data) {
remoteCallback (self, data) {
console.log(data);
data = JSON.parse(data.response)[0];
const dataLength = data.length;
@ -197,7 +197,7 @@ export class AdvancedSelect
*
* @since 1.0.0
*/
changeCallback(self) {
changeCallback (self) {
// if remote data
if (typeof self.src !== 'undefined' && self.src !== '') {
const request = new Request(self.src);
@ -215,7 +215,7 @@ export class AdvancedSelect
*
* @since 1.0.0
*/
selectOption(e) {
selectOption (e) {
e.focus();
/**
* @todo Karaka/jsOMS#70
@ -234,9 +234,9 @@ export class AdvancedSelect
*
* @since 1.0.0
*/
clearDataListSelection(self) {
const list = self.dataListBody.getElementsByTagName('tr'),
length = list.length;
clearDataListSelection (self) {
const list = self.dataListBody.getElementsByTagName('tr');
const length = list.length;
for (let i = 0; i < length; ++i) {
/**
@ -259,7 +259,7 @@ export class AdvancedSelect
*
* @since 1.0.0
*/
addToResultList(self) {
addToResultList (self) {
if (self.inputField.getAttribute('data-autocomplete') === 'true') {
self.inputField.value = document.activeElement.querySelectorAll('[data-tpl-value="' + self.inputField.getAttribute('data-value') + '"]')[0].getAttribute('data-value');
}
@ -309,7 +309,7 @@ export class AdvancedSelect
// allow limit
if (self.tagElement.childElementCount >= self.tagElement.getAttribute('data-limit')
&& self.tagElement.getAttribute('data-limit') != 0
&& self.tagElement.getAttribute('data-limit') !== '0'
) {
self.tagElement.removeChild(self.tagElement.firstElementChild);
}
@ -338,10 +338,10 @@ export class AdvancedSelect
*
* @since 1.0.0
*/
inputTimeDelay(action, callback, self, data) {
inputTimeDelay (action, callback, self, data) {
if (AdvancedSelect.timerDelay[action.id]) {
clearTimeout(AdvancedSelect.timerDelay[action.id]);
delete AdvancedSelect.timerDelay[action.id]
delete AdvancedSelect.timerDelay[action.id];
}
AdvancedSelect.timerDelay[action.id] = setTimeout(function () {
@ -351,4 +351,4 @@ export class AdvancedSelect
};
};
AdvancedSelect.timerDelay = {};
AdvancedSelect.timerDelay = {};

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,7 @@
import { Request } from '../../Message/Request/Request.js';
import { Response } from '../../Message/Response/Response.js';
import { RequestMethod } from '../../Message/Request/RequestMethod.js';
import { ResponseType } from '../../Message/Response/ResponseType.js';
/**
* Form manager class.
@ -23,32 +26,32 @@ export class Input
/**
* Unbind input element
*
* @param {Object} input Input element
* @param {Element} input Input element
*
* @return {void}
*
* @since 1.0.0
*/
static unbind(input)
static unbind (input)
{
this.app.inputManager.getKeyboardManager().unbind(input);
/** global: changeBind */
input.removeEventListener('change', changeBind, false);
// input.removeEventListener('change', changeBind, false);
};
/**
* Bind input element
*
* @param {Object} input Input element
* @param {Element} input Input element
*
* @return {void}
*
* @since 1.0.0
*/
static bindElement(input)
static bindElement (input = null)
{
if (typeof input === 'undefined') {
throw 'Input element required';
if (input === null) {
throw new Error('Input element required');
}
const type = input.type;
@ -56,7 +59,7 @@ export class Input
const removeContentButton = input.parentNode.querySelector('.fa-times');
if (removeContentButton !== null
&& type !== 'submit' && type !== 'button') {
removeContentButton.addEventListener('click', function() {
removeContentButton.addEventListener('click', function () {
input.value = '';
input.focus();
});
@ -68,14 +71,14 @@ export class Input
*
* This only applies for datalists that have remote options
*
* @param {Object} input Input element
* @param {Object} datalist Datalist element
* @param {Element} input Input element
* @param {Element} datalist Datalist element
*
* @return {void}
*
* @since 1.0.0
*/
static addRemoteDatalistOptions(input, datalist)
static addRemoteDatalistOptions (input, datalist)
{
this.clearDatalistOptions(datalist);
@ -88,18 +91,18 @@ export class Input
request.setSuccess(function (xhr)
{
try {
const o = JSON.parse(xhr.response),
response = new Response(o),
responseLength = response.count();
let tempResponse = null,
success = null;
const o = JSON.parse(xhr.response);
const response = new Response(o);
const responseLength = response.count();
let tempResponse = null;
let success = null;
for (let k = 0; k < responseLength; ++k) {
tempResponse = response.getByIndex(k);
let option = null,
data = tempResponse.getData(),
length = data.length;
let option = null;
const data = tempResponse.getData();
const length = data.length;
for (let i = 0; i < length; ++i) {
option = document.createElement('option');
@ -120,13 +123,13 @@ export class Input
/**
* Remove all datalist options from datalist
*
* @param {Object} datalist Datalist element
* @param {Element} datalist Datalist element
*
* @return {void}
*
* @since 1.0.0
*/
static clearDatalistOptions(datalist)
static clearDatalistOptions (datalist)
{
const length = datalist.options.length;

View File

@ -14,6 +14,8 @@ export class Tab
/**
* @constructor
*
* @param {Object} app Application
*
* @since 1.0.0
*/
constructor (app)
@ -24,15 +26,15 @@ export class Tab
/**
* Bind & rebind UI elements.
*
* @param {string} [id] Element id
* @param {null|string} [id] Element id
*
* @return {void}
*
* @since 1.0.0
*/
bind (id)
bind (id = null)
{
if (typeof id !== 'undefined') {
if (id !== null) {
const e = document.getElementById(id);
if (e) {
@ -51,7 +53,7 @@ export class Tab
/**
* Bind & rebind UI element.
*
* @param {Object} e Element
* @param {Element} e Element
*
* @return {void}
*
@ -59,8 +61,8 @@ export class Tab
*/
bindElement (e)
{
const nodes = e.querySelectorAll('.tab-links li'),
length = nodes.length;
const nodes = e.querySelectorAll('.tab-links li');
const length = nodes.length;
for (let i = 0; i < length; ++i) {
nodes[i].addEventListener('click', function (evt)
@ -71,8 +73,8 @@ export class Tab
/* Remove selected tab */
const oldActive = this.parentNode.getElementsByClassName('active');
if (oldActive.length > 0) {
let fragments = fragmentString.split('&');
const index = fragments.indexOf(oldActive[0].getElementsByTagName('label')[0].getAttribute('for'));
const fragments = fragmentString.split('&');
const index = fragments.indexOf(oldActive[0].getElementsByTagName('label')[0].getAttribute('for'));
if (index > -1) {
fragments.splice(index, 1);
@ -84,13 +86,13 @@ export class Tab
jsOMS.removeClass(oldActive[0], 'active');
}
let fragments = fragmentString.split('&');
const index = fragments.indexOf(this.getElementsByTagName('label')[0].getAttribute('for'));
const fragments = fragmentString.split('&');
const index = fragments.indexOf(this.getElementsByTagName('label')[0].getAttribute('for'));
/**
if (index > -1) {
fragments.splice(index, 1);
}*/
} */
// find old active and remove it
fragmentString = fragments.join('&');
@ -116,21 +118,21 @@ export class Tab
*
* This allows to link a specific open tab to a user or make it a bookmark
*
* @param {Object} e Element
* @param {Element} e Element
*
* @return {void}
*
* @since 1.0.0
*/
activateTabUri(e)
activateTabUri (e)
{
const fragmentString = window.location.href.includes('#') ? HttpUri.parseUrl(window.location.href).fragment : '';
const fragments = fragmentString.split('&'),
fragLength = fragments.length;
const fragments = fragmentString.split('&');
const fragLength = fragments.length;
if (fragLength > 0 && fragmentString !== '') {
for (let i = 0; i < fragLength; ++i) {
let label = e.querySelectorAll('label[for="' + fragments[i] + '"]')[0];
const label = e.querySelectorAll('label[for="' + fragments[i] + '"]')[0];
if (typeof label !== 'undefined') {
label.click();
}

View File

@ -41,7 +41,7 @@ export class Table
*
* @since 1.0.0
*/
constructor(app)
constructor (app)
{
this.app = app;
@ -53,22 +53,22 @@ export class Table
/**
* Bind & rebind UI elements.
*
* @param {string} [id] Element id
* @param {null|string} [id] Element id
*
* @return {void}
*
* @since 1.0.0
*/
bind (id)
bind (id = null)
{
if (typeof id !== 'undefined' && typeof this.ignore[id] === 'undefined') {
if (id !== null && typeof this.ignore[id] === 'undefined') {
this.bindTable(id);
} else {
const tables = document.getElementsByTagName('table'),
length = !tables ? 0 : tables.length;
const tables = document.getElementsByTagName('table');
const length = !tables ? 0 : tables.length;
for (let i = 0; i < length; ++i) {
let tableId = tables[i].getAttribute('id');
const tableId = tables[i].getAttribute('id');
if (typeof tableId !== 'undefined' && tableId !== null && typeof this.ignore[tableId] === 'undefined') {
this.bindTable(tableId);
}
@ -138,12 +138,6 @@ export class Table
this.bindSorting(sorting[i], id);
}
const order = this.tables[id].getSortableRows();
length = order.length;
for (let i = 0; i < length; ++i) {
this.bindReorder(order[i], id);
}
const filters = this.tables[id].getFilter();
length = filters.length;
for (let i = 0; i < length; ++i) {
@ -169,7 +163,7 @@ export class Table
*
* @since 1.0.0
*/
bindExport(exports)
bindExport (exports)
{
const button = exports.getExport();
@ -190,7 +184,7 @@ export class Table
});
};
/**
/**
* Bind column visibility
*
* @param {Element} header Header
@ -199,7 +193,7 @@ export class Table
*
* @since 1.0.0
*/
bindColumnVisibility(header)
bindColumnVisibility (header)
{
header.addEventListener('contextmenu', function (event) {
jsOMS.preventAll(event);
@ -219,9 +213,9 @@ export class Table
const menu = document.getElementById('table-context-menu');
const columns = header.querySelectorAll('td');
let length = columns.length;
const length = columns.length;
let baseMenuLine = menu.getElementsByClassName('context-line')[0].cloneNode(true);
const baseMenuLine = menu.getElementsByClassName('context-line')[0].cloneNode(true);
for (let i = 0; i < length; ++i) {
if (typeof columns[i].firstChild === 'undefined'
@ -256,14 +250,14 @@ export class Table
menu.getElementsByTagName('ul')[0].removeChild(menu.getElementsByClassName('context-line')[0]);
const rect = tpl.parentElement.getBoundingClientRect();
menu.style.top = (event.clientY - rect.top) + "px";
menu.style.left = (event.clientX - rect.left) + "px";
menu.style.top = (event.clientY - rect.top) + 'px';
menu.style.left = (event.clientX - rect.left) + 'px';
document.addEventListener('click', Table.hideMenuClickHandler);
});
};
static hideMenuClickHandler(event)
static hideMenuClickHandler (event)
{
const menu = document.getElementById('table-context-menu');
const isClickedOutside = !menu.contains(event.target);
@ -274,59 +268,34 @@ export class Table
}
};
/**
* Swaps the row on click.
*
* @param {Element} sorting Swap button
* @param {Object} id Element id
*
* @return {void}
*
* @since 1.0.0
*/
bindReorder(sorting, id)
{
sorting.addEventListener('click', function (event)
{
jsOMS.preventAll(event);
const table = document.getElementById(id),
rows = table.getElementsByTagName('tbody')[0].rows,
rowLength = rows.length,
rowId = this.closest('tr').rowIndex - 1,
orderType = jsOMS.hasClass(this, 'order-up') ? 1 : -1;
if (orderType === 1 && rowId > 0) {
rows[rowId].parentNode.insertBefore(rows[rowId], rows[rowId - 1]);
} else if (orderType === -1 && rowId < rowLength) {
rows[rowId].parentNode.insertBefore(rows[rowId], rows[rowId + 2]);
}
});
};
/**
* Sorts the table.
*
* @param {Element} sorting Sort button
* @param {Object} id Table id
* @param {string} id Table id
*
* @return {void}
*
* @since 1.0.0
*/
bindSorting(sorting, id)
bindSorting (sorting, id)
{
sorting.addEventListener('click', function (event)
{
const table = document.getElementById(id),
rows = table.getElementsByTagName('tbody')[0].rows,
rowLength = rows.length,
cellId = this.closest('td').cellIndex,
sortType = jsOMS.hasClass(this, 'sort-asc') ? 1 : -1;
const table = document.getElementById(id);
const rows = table.getElementsByTagName('tbody')[0].rows;
const rowLength = rows.length;
const cellId = this.closest('td').cellIndex;
const sortType = jsOMS.hasClass(this, 'sort-asc') ? 1 : -1;
let j, i, row1, row2, content1, content2,
order = false,
shouldSwitch = false;
let j;
let i;
let row1;
let row2;
let content1;
let content2;
let order = false;
let shouldSwitch = false;
const columnName = this.closest('td').getAttribute('data-name');
@ -346,10 +315,11 @@ export class Table
row1 = rows[j].getElementsByTagName('td')[cellId];
content1 = row1.getAttribute('data-content') !== null ? row1.getAttribute('data-content').toLowerCase() : row1.textContent.toLowerCase();
content1 = !isNaN(content1)
? parseFloat(content1)
: (!isNaN(new Date(content1))
? new Date(content1)
: content1);
? parseFloat(content1)
: (!isNaN(new Date(content1))
? new Date(content1)
: content1
);
for (i = j + 1; i < rowLength; ++i) {
row2 = rows[i].getElementsByTagName('td')[cellId];
@ -386,13 +356,13 @@ export class Table
* Filters the table.
*
* @param {Element} filtering Filter button
* @param {Object} id Table id
* @param {string} id Table id
*
* @return {void}
*
* @since 1.0.0
*/
bindFiltering(filtering, id)
bindFiltering (filtering, id)
{
filtering.addEventListener('click', function (event)
{
@ -404,13 +374,13 @@ export class Table
* Checkbox select.
*
* @param {Element} checkbox Filter button
* @param {Object} id Table id
* @param {string} id Table id
*
* @return {void}
*
* @since 1.0.0
*/
bindCheckbox(checkbox, id)
bindCheckbox (checkbox, id)
{
checkbox.addEventListener('click', function (event)
{
@ -452,7 +422,7 @@ export class Table
request.send();
};
static emptyTable(table)
static emptyTable (table)
{
const rows = table.getElementsByTagName('tr');
const length = rows.length;
@ -462,7 +432,7 @@ export class Table
}
};
static addToTable(table, data)
static addToTable (table, data)
{
const dataLength = data.length;

View File

@ -22,38 +22,25 @@ export class DragNDrop
this.dragging = null;
};
/**
* Unbind element
*
* @param {Object} element DOM element
*
* @return {void}
*
* @since 1.0.0
*/
unbind (element)
{
};
/**
* Bind element
*
* @param {Object} [element] DOM element
* @param {null|Element} element DOM element
*
* @return {void}
*
* @since 1.0.0
*/
bind (element)
bind (element = null)
{
if (typeof element !== 'undefined') {
if (element !== null) {
this.bindElement(element);
} else {
const elements = document.querySelectorAll('[draggable]'),
length = !elements ? 0 : elements.length;
const elements = document.querySelectorAll('.dragcontainer');
const length = !elements ? 0 : elements.length;
for (let i = 0; i < length; ++i) {
this.bindElement(elements[i]);
this.bindElement(elements[i]);
}
}
};
@ -61,7 +48,7 @@ export class DragNDrop
/**
* Bind DOM element
*
* @param {string} id DOM element
* @param {Element} element DOM element
*
* @return {void}
*
@ -75,21 +62,23 @@ export class DragNDrop
return;
}
element.addEventListener('dragstart', function(e) {
element.addEventListener('dragstart', function (e) {
if (self.dragging === null) {
self.dragging = this;
self.dragging = e.target;
e.dataTransfer.effectAllowed = 'move';
e.dataTransfer.setData('text/html', this.innerHTML);
e.dataTransfer.setData('text/html', e.target.innerHTML);
}
}, false);
element.addEventListener('dragenter', function(e) {
const rowIndex = Array.from(this.parentElement.children).indexOf(this);
const dragIndex = Array.from(self.dragging.parentElement.children).indexOf(self.dragging);
element.addEventListener('dragenter', function (e) {
const thisElement = e.target.closest('.dragcontainer ' + this.children[this.children.length - 1].tagName);
const oldPlaceholder = this.parentNode.querySelector('.drag-placeholder');
const rowIndex = Array.from(this.children).indexOf(thisElement);
const dragIndex = Array.from(self.dragging.children).indexOf(self.dragging);
const oldPlaceholder = this.querySelector('.drag-placeholder');
if (oldPlaceholder !== null) {
this.parentNode.removeChild(oldPlaceholder);
this.removeChild(oldPlaceholder);
}
const placeholder = document.createElement(self.dragging.tagName);
@ -105,39 +94,39 @@ export class DragNDrop
jsOMS.addClass(placeholder, 'drag-placeholder');
if (dragIndex < rowIndex) {
this.parentNode.insertBefore(placeholder, this.nextSibling);
this.insertBefore(placeholder, thisElement.nextSibling);
} else {
this.parentNode.insertBefore(placeholder, this);
this.insertBefore(placeholder, thisElement);
}
}, false);
element.addEventListener('dragover', function(e) {
element.addEventListener('dragover', function (e) {
e.preventDefault();
e.dataTransfer.dropEffect = 'move';
}, false);
element.addEventListener('dragleave', function(e) {
element.addEventListener('dragleave', function (e) {
e.preventDefault();
}, false);
element.addEventListener('dragend', function(e) {
element.addEventListener('dragend', function (e) {
e.preventDefault();
const oldPlaceholder = this.parentNode.querySelector('.drag-placeholder');
const oldPlaceholder = this.querySelector('.drag-placeholder');
if (oldPlaceholder === null) {
return;
}
this.parentNode.insertBefore(self.dragging, oldPlaceholder);
this.parentNode.removeChild(oldPlaceholder);
this.insertBefore(self.dragging, oldPlaceholder);
this.removeChild(oldPlaceholder);
self.dragging = null;
}, false);
element.addEventListener('drop', function(e) {
element.addEventListener('drop', function (e) {
e.stopPropagation();
e.preventDefault();
}, false);
}
};
};

View File

@ -21,23 +21,25 @@ export class GeneralUI
*/
constructor (app)
{
/** @type {null|IntersectionObserver} visObs */
this.visObs = null;
this.app = app;
this.app = app;
};
/**
* Bind button.
*
* @param {string} [id] Button id (optional)
* @param {null|string} [id] Button id (optional)
*
* @return {void}
*
* @since 1.0.0
*/
bind (id)
bind (id = null)
{
let e = null;
if (typeof id !== 'undefined' && id !== null) {
if (id !== null) {
e = document.getElementById(id);
}
@ -50,15 +52,18 @@ export class GeneralUI
/**
* Bind & rebind UI element.
*
* @param {Object} [e] Element
* @param {null|Element} [e] Element
*
* @return {void}
*
* @since 1.0.0
*/
bindHref (e)
bindHref (e = null)
{
e = e !== null ? e.querySelectorAll('[data-href], [href]') : document.querySelectorAll('[data-href], [href]');
e = e !== null
? e.querySelectorAll('[data-href], [href]')
: document.querySelectorAll('[data-href], [href]');
const length = e.length;
for (let i = 0; i < length; ++i) {
@ -67,7 +72,7 @@ export class GeneralUI
}
// @todo: implement middle mouse click
e[i].addEventListener('click', function(event) {
e[i].addEventListener('click', function (event) {
if ((event.target.parentElement !== this
&& event.target.parentElement.getElementsByTagName('input').length > 0)
|| (event.target.getElementsByTagName('input').length > 0)
@ -99,15 +104,18 @@ export class GeneralUI
/**
* Bind & rebind UI element.
*
* @param {Object} [e] Element id
* @param {null|Element} [e] Element id
*
* @return {void}
*
* @since 1.0.0
*/
bindIframe (e)
bindIframe (e = null)
{
e = e !== null ? e : document.getElementsByTagName('iframe');
e = e !== null
? e
: document.getElementsByTagName('iframe');
const length = e.length;
for (let i = 0; i < length; ++i) {
@ -115,29 +123,32 @@ export class GeneralUI
e[i].height = e[i].contentWindow.document.body.scrollHeight + 25;
}
e[i].addEventListener('load', function() {
e[i].addEventListener('load', function () {
this.height = this.contentWindow.document.body.scrollHeight + 25;
});
}
}
};
/**
* Bind & rebind UI element.
*
* @param {Object} [e] Element id
* @param {null|Element} [e] Element id
*
* @return {void}
*
* @since 1.0.0
*/
bindLazyLoad (e)
bindLazyLoad (e = null)
{
e = e !== null ? e.querySelectorAll('[data-lazyload]') : document.querySelectorAll('[data-lazyload]');
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) {
this.visObs = new IntersectionObserver(function (eles, obs) {
eles.forEach(ele => {
if (ele.intersectionRatio > 0) {
obs.unobserve(ele.target);
@ -161,15 +172,18 @@ export class GeneralUI
/**
* Bind & rebind UI element.
*
* @param {Object} [e] Element id
* @param {null|Element} [e] Element id
*
* @return {void}
*
* @since 1.0.0
*/
bindInput (e)
bindInput (e = null)
{
e = e !== null ? [e] : document.getElementsByClassName('advancedInput');
e = e !== null
? [e]
: document.getElementsByClassName('advancedInput');
const length = e.length;
for (let i = 0; i < length; ++i) {
@ -177,7 +191,17 @@ export class GeneralUI
}
};
static setValueOfElement(src, value)
/**
* Set the value for an elment
*
* @param {Element} src Element to change the value for
* @param {any} value Value to set
*
* @return {void}
*
* @since 1.0.0
*/
static setValueOfElement (src, value)
{
if (src.hasAttribute('data-value')) {
src.setAttribute('data-value', value);
@ -196,7 +220,7 @@ export class GeneralUI
src.innerHTML = jsOMS.htmlspecialchars_encode(value);
break;
case 'select':
case 'select': {
const optionLength = src.options.length;
for (let i = 0; i < optionLength; ++i) {
if (src.options[i].value === value) {
@ -207,29 +231,38 @@ export class GeneralUI
}
break;
}
case 'input':
if (src.type === 'radio') {
src.checked = false;
if (src.value === value) {
src.checked = true;
}
break;
} else if (src.type === 'checkbox') {
src.checked = false;
const values = value.split(',');
if (values.includes(src.value)) {
src.checked = true;
}
break;
}
break;
default:
src.value = jsOMS.htmlspecialchars_decode(value);
}
};
static setTextOfElement(src, value)
/**
* Set the text for an elment
*
* @param {Element} src Element to change the text for
* @param {string} value Text to set
*
* @return {void}
*
* @since 1.0.0
*/
static setTextOfElement (src, value)
{
switch (src.tagName.toLowerCase()) {
case 'select':
@ -252,7 +285,16 @@ export class GeneralUI
}
};
static getValueFromDataSource(src)
/**
* Get value from element
*
* @param {Element} src Element to get the value from
*
* @return {any}
*
* @since 1.0.0
*/
static getValueFromDataSource (src)
{
if (src.getAttribute('data-value') !== null) {
return src.getAttribute('data-value');
@ -268,11 +310,34 @@ export class GeneralUI
case 'h1':
return src.innerText.trim(' ');
default:
if (src.getAttribute('type') === 'radio') {
const checked = document.querySelector('input[type=radio][name="' + src.name + '"]:checked');
if (checked === null) {
return '';
}
src = checked;
} else if (src.getAttribute('type') === 'checkbox') {
if (!src.checked) {
return '';
}
}
return src.value;
}
};
static getTextFromDataSource(src)
/**
* Get text from element
*
* @param {Element} src Element to get the text from
*
* @return {string}
*
* @since 1.0.0
*/
static getTextFromDataSource (src)
{
switch (src.tagName.toLowerCase()) {
case 'td':
@ -286,9 +351,23 @@ export class GeneralUI
case 'select':
return src.options[src.selectedIndex].text;
case 'input':
if (src.getAttribute('type') === 'checkbox' || src.getAttribute('type') === 'radio') {
if (src.getAttribute('type') === 'radio') {
const checked = document.querySelector('input[type=radio][name="' + src.name + '"]:checked');
if (checked === null) {
return '';
}
return document.querySelector('label[for="' + checked.id + '"]').innerText.trim(' ');
} else if (src.getAttribute('type') === 'checkbox') {
if (!src.checked) {
return '';
}
return document.querySelector('label[for="' + src.id + '"]').innerText.trim(' ');
}
return src.value;
default:
return src.value;
}

Some files were not shown because too many files have changed in this diff Show More