mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-15 16:58:42 +00:00
Move models to framework
This commit is contained in:
parent
9e5f78c3ea
commit
c15a1573a2
26
Model/Action/Dom/Datalist/Append.js
Normal file
26
Model/Action/Dom/Datalist/Append.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {{title:string},{content:string},{level:int},{delay:int},{stay:int}} action Message data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const datalistAppend = function (action, callback)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const datalist = document.getElementById(action.id),
|
||||||
|
dataLength = action.data.length;
|
||||||
|
|
||||||
|
let option;
|
||||||
|
|
||||||
|
for (let i = 0; i < dataLength; i++) {
|
||||||
|
option = document.createElement('option');
|
||||||
|
option.value = action.data[i][action.text];
|
||||||
|
option.setAttribute('data-value', action.data[i][action.value]);
|
||||||
|
datalist.appendChild(option);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
20
Model/Action/Dom/Datalist/Clear.js
Normal file
20
Model/Action/Dom/Datalist/Clear.js
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {{title:string},{content:string},{level:int},{delay:int},{stay:int}} action Message data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const datalistClear = function (action, callback)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const e = document.getElementById(action.id);
|
||||||
|
|
||||||
|
while (e.firstChild) {
|
||||||
|
e.removeChild(e.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
14
Model/Action/Dom/Focus.js
Normal file
14
Model/Action/Dom/Focus.js
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
const focusAction = function (action, callback)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const focus = document.getElementById(action.id);
|
||||||
|
|
||||||
|
if (!focus) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
focus.focus();
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
33
Model/Action/Dom/GetValue.js
Normal file
33
Model/Action/Dom/GetValue.js
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
* @param {string} id Action element
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const domGetValue = function (action, callback, id)
|
||||||
|
{
|
||||||
|
"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);
|
||||||
|
let value = [];
|
||||||
|
|
||||||
|
for (let i in e) {
|
||||||
|
/** global: HTMLElement */
|
||||||
|
if (!e.hasOwnProperty(i) || !(e[i] instanceof HTMLElement)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let eId = (typeof e[i].name !== 'undefined' && e[i].name !== '') ? e[i].name : e[i].id;
|
||||||
|
|
||||||
|
if (e[i].tagName === 'INPUT' || e[i].tagName === 'SELECTS' || e[i].tagName === 'BUTTON') {
|
||||||
|
value[eId] = e[i].value;
|
||||||
|
} else {
|
||||||
|
value[eId] = e[i].getAttribute('data-id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(value);
|
||||||
|
};
|
||||||
15
Model/Action/Dom/Hide.js
Normal file
15
Model/Action/Dom/Hide.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
const hideAction = function (action, callback)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const hide = document.getElementById(action.id);
|
||||||
|
|
||||||
|
if (!hide) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** global: jsOMS */
|
||||||
|
jsOMS.addClass(hide, 'vh');
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
81
Model/Action/Dom/Popup.js
Normal file
81
Model/Action/Dom/Popup.js
Normal file
|
|
@ -0,0 +1,81 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
* @param {id} element Action element
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const popupButtonAction = function (action, callback, id)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const popup = action.base === 'self' ? (action.selector === '' ? [document.getElementById(id)] : document.getElementById(id).querySelectorAll(action.selector)) : document.querySelectorAll(action.selector);
|
||||||
|
|
||||||
|
for(let i in popup) {
|
||||||
|
/** global: HTMLElement */
|
||||||
|
if(!popup.hasOwnProperty(i) || !popup[i] || !(popup[i] instanceof HTMLElement)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const clone = document.importNode(popup[i].content, true);
|
||||||
|
const dim = document.getElementById('dim');
|
||||||
|
|
||||||
|
if(dim) {
|
||||||
|
document.getElementById('dim').classList.remove('vh');
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let j in clone) {
|
||||||
|
if(!clone.hasOwnProperty(j) || !(clone[j] instanceof HTMLElement)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
clone[j].innerHTML = clone[j].innerHTML.replace(/\{\$id\}/g, action.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
document.body.insertBefore(clone, document.body.firstChild);
|
||||||
|
|
||||||
|
let e = document.getElementById(popup[i].id.substr(0, popup[i].id.length - 4));
|
||||||
|
|
||||||
|
if(!e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.omsApp.uiManager.getActionManager().bind(e.querySelectorAll('[data-action]'));
|
||||||
|
|
||||||
|
e.classList.add('animated');
|
||||||
|
if (typeof action.aniIn !== 'undefined') {
|
||||||
|
e.classList.add(action.aniIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action.stay > 0) {
|
||||||
|
setTimeout(function ()
|
||||||
|
{
|
||||||
|
let out = 0;
|
||||||
|
if (typeof action.aniOut !== 'undefined') {
|
||||||
|
e.classList.remove(action.aniIn);
|
||||||
|
e.classList.add(action.aniOut);
|
||||||
|
out = 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(function ()
|
||||||
|
{
|
||||||
|
if (typeof action.aniOut !== 'undefined') {
|
||||||
|
e.classList.add(action.aniOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.parentElement.removeChild(e);
|
||||||
|
|
||||||
|
const dim = document.getElementById('dim');
|
||||||
|
|
||||||
|
if (dim) {
|
||||||
|
document.getElementById('dim').classList.add('vh');
|
||||||
|
}
|
||||||
|
}, out);
|
||||||
|
}, action.stay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
43
Model/Action/Dom/Remove.js
Normal file
43
Model/Action/Dom/Remove.js
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
* @param {string} id Action element
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const removeButtonAction = function (action, callback, id)
|
||||||
|
{
|
||||||
|
"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 dim = document.getElementById('dim');
|
||||||
|
|
||||||
|
for (let i in e) {
|
||||||
|
/** global: HTMLElement */
|
||||||
|
if (!e.hasOwnProperty(i) || !e[i] || !(e[i] instanceof HTMLElement)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof action.aniOut !== 'undefined') {
|
||||||
|
e[i].classList.add(action.aniOut);
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: here is a problem with removing elements. after removing the first element in a list the second one cannot be deleted. maybe this is because the action event gets removed for sister elements after one is deleted?
|
||||||
|
setTimeout(function ()
|
||||||
|
{
|
||||||
|
if (e[i].parentElement === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
e[i].parentElement.removeChild(e[i]);
|
||||||
|
|
||||||
|
if (dim) {
|
||||||
|
document.getElementById('dim').classList.add('vh');
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
38
Model/Action/Dom/RemoveValue.js
Normal file
38
Model/Action/Dom/RemoveValue.js
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
* @param {string} id Action element
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const domRemoveValue = function (action, callback, id)
|
||||||
|
{
|
||||||
|
"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);
|
||||||
|
|
||||||
|
for (let i in e) {
|
||||||
|
/** global: HTMLElement */
|
||||||
|
if (!e.hasOwnProperty(i) || !(e[i] instanceof HTMLElement)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e[i].value === action.data) {
|
||||||
|
e[i].value = '';
|
||||||
|
} else {
|
||||||
|
e[i].value = e[i].value.replace(', ' + action.data + ',', ',');
|
||||||
|
|
||||||
|
if (e[i].value.startsWith(action.data + ', ')) {
|
||||||
|
e[i].value = e[i].value.substring((action.data + ', ').length);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e[i].value.endsWith(', ' + action.data)) {
|
||||||
|
e[i].value = e[i].value.substring(0, e[i].value.length - (', ' + action.data).length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
68
Model/Action/Dom/SetValue.js
Normal file
68
Model/Action/Dom/SetValue.js
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
* @param {id} element Action element
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const domSetValue = function (action, callback, id)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
let dataPath = action['value'],
|
||||||
|
path = '',
|
||||||
|
tempDataValue = '',
|
||||||
|
values = [],
|
||||||
|
replaceText = '',
|
||||||
|
start = 0,
|
||||||
|
end = 0;
|
||||||
|
|
||||||
|
while ((start = dataPath.indexOf('{', start)) !== -1) {
|
||||||
|
end = dataPath.indexOf('}', start);
|
||||||
|
start++;
|
||||||
|
|
||||||
|
path = dataPath.substring(start, end);
|
||||||
|
/** global: jsOMS */
|
||||||
|
tempDataValue = jsOMS.getArray(path, action.data, '/');
|
||||||
|
|
||||||
|
replaceText = '{' + path + '}';
|
||||||
|
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);
|
||||||
|
|
||||||
|
for (let i in fill) {
|
||||||
|
/** global: HTMLElement */
|
||||||
|
if (!fill.hasOwnProperty(i) || !(fill[i] instanceof HTMLElement)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fill[i].tagName.toLowerCase() === 'div'
|
||||||
|
|| fill[i].tagName.toLowerCase() === 'span'
|
||||||
|
) {
|
||||||
|
if (!fill[i].innerHTML.includes(dataPath)) {
|
||||||
|
if (action.overwrite) {
|
||||||
|
fill[i].innerHTML = dataPath;
|
||||||
|
} else if (!action.overwrite) {
|
||||||
|
fill[i].innerHTML += dataPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (fill[i].value !== dataPath
|
||||||
|
&& !fill[i].value.includes(', ' + dataPath + ',')
|
||||||
|
&& !fill[i].value.endsWith(', ' + dataPath)
|
||||||
|
&& !fill[i].value.startsWith(dataPath + ',')
|
||||||
|
) {
|
||||||
|
if (action.overwrite) {
|
||||||
|
fill[i].value = dataPath;
|
||||||
|
} else {
|
||||||
|
fill[i].value += (fill[i].value !== '' ? ', ' : '') + dataPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(action.data);
|
||||||
|
};
|
||||||
15
Model/Action/Dom/Show.js
Normal file
15
Model/Action/Dom/Show.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
const showAction = function (action, callback)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const show = document.getElementById(action.id);
|
||||||
|
|
||||||
|
if (!show) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** global: jsOMS */
|
||||||
|
jsOMS.removeClass(show, 'vh');
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
45
Model/Action/Dom/Table/Append.js
Normal file
45
Model/Action/Dom/Table/Append.js
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const tableAppend = function (action, callback)
|
||||||
|
{
|
||||||
|
"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;
|
||||||
|
|
||||||
|
let row, cell, text, rawText;
|
||||||
|
|
||||||
|
for (let i = 0; i < dataLength; i++) {
|
||||||
|
if (tbody === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
row = tbody.insertRow(tbody.rows.length);
|
||||||
|
|
||||||
|
for (let j = 0; j < headerLength; j++) {
|
||||||
|
if (row === null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cell = row.insertCell(j);
|
||||||
|
rawText = action.data[i][headers[j].getAttribute('data-name')];
|
||||||
|
|
||||||
|
if (typeof rawText === 'undefined') {
|
||||||
|
rawText = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
cell.appendChild(document.createTextNode(rawText));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
20
Model/Action/Dom/Table/Clear.js
Normal file
20
Model/Action/Dom/Table/Clear.js
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {{title:string},{content:string},{level:int},{delay:int},{stay:int}} action Message data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const tableClear = function (action, callback)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const e = document.getElementById(action.id).getElementsByTagName('tbody')[0];
|
||||||
|
|
||||||
|
while (e.firstChild) {
|
||||||
|
e.removeChild(e.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
22
Model/Action/Message/Log.js
Normal file
22
Model/Action/Message/Log.js
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/**
|
||||||
|
* Log.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const logAction = function (action, callback)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
window.omsApp.notifyManager.send(
|
||||||
|
new jsOMS.Message.Notification.NotificationMessage(
|
||||||
|
action.data.status,
|
||||||
|
action.data.title,
|
||||||
|
action.data.message
|
||||||
|
), jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION
|
||||||
|
);
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
26
Model/Action/Message/Request.js
Normal file
26
Model/Action/Message/Request.js
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const requestAction = function (action, callback)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
/** global: jsOMS */
|
||||||
|
const request = new jsOMS.Message.Request.Request(action.uri, action.method, action.request_type);
|
||||||
|
|
||||||
|
request.setSuccess(function(xhr) {
|
||||||
|
console.log(xhr.responseText);
|
||||||
|
callback(JSON.parse(xhr.responseText));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (typeof action.data !== 'undefined') {
|
||||||
|
request.setData(action.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
request.send();
|
||||||
|
};
|
||||||
33
Model/Action/Utils/DataCollector.js
Normal file
33
Model/Action/Utils/DataCollector.js
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
* Collect data.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const dataCollectionAction = function (action, callback)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
let elements, data = {};
|
||||||
|
|
||||||
|
for (let selector in action.collect) {
|
||||||
|
if (!action.collect.hasOwnProperty(selector)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
elements = document.querySelectorAll(action.collect[selector]);
|
||||||
|
|
||||||
|
for (let e in elements) {
|
||||||
|
if(!elements.hasOwnProperty(e)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: different types of elements have differnt forms of storing values (input, textarea etc.)
|
||||||
|
data[selector].push(e.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback(data);
|
||||||
|
};
|
||||||
23
Model/Action/Utils/Timer.js
Normal file
23
Model/Action/Utils/Timer.js
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const timerActionDelay = {};
|
||||||
|
const timerAction = function (action, callback)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
if (timerActionDelay[action.id]) {
|
||||||
|
clearTimeout(timerActionDelay[action.id]);
|
||||||
|
delete timerActionDelay[action.id]
|
||||||
|
}
|
||||||
|
|
||||||
|
timerActionDelay[action.id] = setTimeout(function() {
|
||||||
|
delete timerActionDelay[action.id];
|
||||||
|
callback();
|
||||||
|
}, action.delay);
|
||||||
|
};
|
||||||
22
Model/Action/Validate/Keypress.js
Normal file
22
Model/Action/Validate/Keypress.js
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/**
|
||||||
|
* Validate Keypress.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const validateKeypress = function (action, callback)
|
||||||
|
{
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const invertValidate = action.pressed.startsWith('!'),
|
||||||
|
keyPressCheck = invertValidate ? action.pressed.split('!') : action.pressed.split('|');
|
||||||
|
|
||||||
|
if (typeof action.data.keyCode !== 'undefined'
|
||||||
|
&& ((!invertValidate && keyPressCheck.indexOf(action.data.keyCode.toString()) !== -1)
|
||||||
|
|| (invertValidate && keyPressCheck.indexOf(action.data.keyCode.toString()) === -1))
|
||||||
|
) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
};
|
||||||
0
Model/Message/Dom.js
Normal file
0
Model/Message/Dom.js
Normal file
27
Model/Message/DomAction.js
Normal file
27
Model/Message/DomAction.js
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
/**
|
||||||
|
* Perform DOM action.
|
||||||
|
*
|
||||||
|
* @param {{delay:int},{type:int}} data DOM action data
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const domAction = function (data)
|
||||||
|
{
|
||||||
|
/** global: jsOMS */
|
||||||
|
setTimeout(function ()
|
||||||
|
{
|
||||||
|
switch (data.type) {
|
||||||
|
case jsOMS.EnumDomActionType.SHOW:
|
||||||
|
break;
|
||||||
|
case jsOMS.EnumDomActionType.HIDE:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, parseInt(data.delay));
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show/Hide
|
||||||
|
* identifier: #element or .elements or query
|
||||||
|
* anim: someclass
|
||||||
|
* delay: 0
|
||||||
|
*/
|
||||||
15
Model/Message/DomActionType.js
Normal file
15
Model/Message/DomActionType.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
(function (jsOMS) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
jsOMS.EnumDomActionType = Object.freeze({
|
||||||
|
CREATE_BEFORE: 0,
|
||||||
|
CREATE_AFTER: 1,
|
||||||
|
DELETE: 2,
|
||||||
|
REPLACE: 3,
|
||||||
|
MODIFY: 4,
|
||||||
|
SHOW: 5,
|
||||||
|
HIDE: 6,
|
||||||
|
ACTIVATE: 7,
|
||||||
|
DEACTIVATE: 8
|
||||||
|
});
|
||||||
|
} (window.jsOMS = window.jsOMS || {}));
|
||||||
39
Model/Message/FormValidation.js
Normal file
39
Model/Message/FormValidation.js
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {{delay:int},{errors:string},{form:string}} data Message data
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const formValidationMessage = function (data) {
|
||||||
|
const form = document.getElementById(data.form);
|
||||||
|
|
||||||
|
if(!form) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const eEles = document.getElementsByClassName('i-' + data.form);
|
||||||
|
|
||||||
|
while (eEles.length > 0) {
|
||||||
|
eEles[0].parentNode.removeChild(eEles[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {{msg:string}} error Error data
|
||||||
|
*/
|
||||||
|
data.errors.forEach(function (error) {
|
||||||
|
const eEle = document.getElementById(error.id);
|
||||||
|
|
||||||
|
if (!eEle) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const msgEle = document.createElement('i'),
|
||||||
|
msg = document.createTextNode(error.msg);
|
||||||
|
|
||||||
|
msgEle.id = 'i-' + error.id;
|
||||||
|
msgEle.class = 'i-' + data.form;
|
||||||
|
msgEle.appendChild(msg);
|
||||||
|
eEle.parentNode.insertBefore(msgEle, eEle.nextSibling);
|
||||||
|
});
|
||||||
|
};
|
||||||
37
Model/Message/Notify.js
Normal file
37
Model/Message/Notify.js
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {{title:string},{content:string},{level:int},{delay:int},{stay:int}} data Message data
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const notifyMessage = function (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);
|
||||||
|
|
||||||
|
notify.id = 'notify';
|
||||||
|
notify.class = data.level;
|
||||||
|
h.appendChild(title);
|
||||||
|
inner.appendChild(content);
|
||||||
|
notify.appendChild(h);
|
||||||
|
notify.appendChild(inner);
|
||||||
|
document.body.appendChild(notify);
|
||||||
|
|
||||||
|
if (data.stay <= 0) {
|
||||||
|
data.stay = 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.stay > 0) {
|
||||||
|
setTimeout(function ()
|
||||||
|
{
|
||||||
|
notify.parentElement.removeChild(notify);
|
||||||
|
}, data.stay);
|
||||||
|
}
|
||||||
|
}, parseInt(data.delay));
|
||||||
|
};
|
||||||
11
Model/Message/NotifyType.js
Normal file
11
Model/Message/NotifyType.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
(function (jsOMS) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
jsOMS.EnumNotifyType = Object.freeze({
|
||||||
|
BINARY: 0,
|
||||||
|
INFO: 1,
|
||||||
|
WARNING: 2,
|
||||||
|
ERROR: 3,
|
||||||
|
FATAL: 4
|
||||||
|
});
|
||||||
|
}(window.jsOMS = window.jsOMS || {}));
|
||||||
15
Model/Message/Redirect.js
Normal file
15
Model/Message/Redirect.js
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {{delay:int},{url:string}} data Message data
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const redirectMessage = function (data)
|
||||||
|
{
|
||||||
|
setTimeout(function ()
|
||||||
|
{
|
||||||
|
/** global: jsOMS */
|
||||||
|
window.location = jsOMS.Uri.UriFactory.build(data.uri);
|
||||||
|
}, parseInt(data.delay));
|
||||||
|
};
|
||||||
12
Model/Message/Reload.js
Normal file
12
Model/Message/Reload.js
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
/**
|
||||||
|
* Set message.
|
||||||
|
*
|
||||||
|
* @param {{delay:int}} data Message data
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
const reloadMessage = function (data) {
|
||||||
|
setTimeout(function () {
|
||||||
|
document.location.reload(true);
|
||||||
|
}, parseInt(data.delay));
|
||||||
|
};
|
||||||
Loading…
Reference in New Issue
Block a user