mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-01-11 17:58:41 +00:00
ui fixes
This commit is contained in:
parent
2bfe821351
commit
1cd50ff438
|
|
@ -269,6 +269,7 @@ export class EventManager
|
||||||
attach (group, callback, remove = false, reset = false)
|
attach (group, callback, remove = false, reset = false)
|
||||||
{
|
{
|
||||||
if (!Object.prototype.hasOwnProperty.call(this.callbacks, group)) {
|
if (!Object.prototype.hasOwnProperty.call(this.callbacks, group)) {
|
||||||
|
// @question Consider to make this a struct?
|
||||||
this.callbacks[group] = { remove: remove, reset: reset, callbacks: [], lastRun: 0 };
|
this.callbacks[group] = { remove: remove, reset: reset, callbacks: [], lastRun: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,12 @@ export function domChangeAttribute (action, callback, id)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (action.type) {
|
switch (action.subtype) {
|
||||||
case 'remove':
|
case 'remove':
|
||||||
const old = fill[i].getAttribute(action.attr);
|
const old = fill[i].getAttribute(action.attr);
|
||||||
|
|
||||||
if (old.match(new RegExp('(\\s|^)' + action.value + '(\\s|$)')) !== null) {
|
if (old !== null && old.match(new RegExp('(\\s|^)' + action.value + '(\\s|$)')) !== null) {
|
||||||
const reg = new RegExp('(\\s|^)' + cls);
|
const reg = new RegExp('(\\s|^)' + action.value);
|
||||||
|
|
||||||
fill[i].setAttribute(action.attr, old.replace(reg, '').trim());
|
fill[i].setAttribute(action.attr, old.replace(reg, '').trim());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { GeneralUI } from "../../../UI/GeneralUI";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get value from dom.
|
* Get value from dom.
|
||||||
*
|
*
|
||||||
|
|
@ -29,16 +31,11 @@ export function domGetValue (action, callback, id)
|
||||||
? e[i].getAttribute('name')
|
? e[i].getAttribute('name')
|
||||||
: e[i].getAttribute('id');
|
: e[i].getAttribute('id');
|
||||||
|
|
||||||
if (e[i].tagName.toLowerCase() === 'input'
|
if (e[i].tagName.toLowerCase() === 'form') {
|
||||||
|| e[i].tagName.toLowerCase() === 'selects'
|
|
||||||
|| e[i].tagName.toLowerCase() === 'button'
|
|
||||||
) {
|
|
||||||
value[eId] = e[i].getAttribute('value');
|
|
||||||
} else if (e[i].tagName.toLowerCase() === 'form') {
|
|
||||||
value = window.omsApp.uiManager.getFormManager().get(eId).getData();
|
value = window.omsApp.uiManager.getFormManager().get(eId).getData();
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
value[eId] = e[i].getAttribute('data-id');
|
value[eId] = GeneralUI.getValueFromDataSource(e[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
46
Model/Action/Event/If.js
Normal file
46
Model/Action/Event/If.js
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
import { jsOMS } from '../../../Utils/oLib.js';
|
||||||
|
/**
|
||||||
|
* Prevent UI action.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
* @param {string} id Action element
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
export function ifAction (action, callback, id)
|
||||||
|
{
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const conditions = action.conditions;
|
||||||
|
const data = Object.values(action.data)[0];
|
||||||
|
|
||||||
|
for (const i in conditions) {
|
||||||
|
if (conditions[i].comp === '==' && data === conditions[i].value) {
|
||||||
|
action.key = conditions[i].jump - 1;
|
||||||
|
break;
|
||||||
|
} else if (conditions[i].comp === '!=' && data !== conditions[i].value) {
|
||||||
|
action.key = conditions[i].jump - 1;
|
||||||
|
break;
|
||||||
|
} else if(conditions[i].comp === '>' && data > conditions[i].value) {
|
||||||
|
action.key = conditions[i].jump - 1;
|
||||||
|
break;
|
||||||
|
} else if (conditions[i].comp === '<' && data < conditions[i].value) {
|
||||||
|
action.key = conditions[i].jump - 1;
|
||||||
|
break;
|
||||||
|
} else if (conditions[i].comp === '>=' && data >= conditions[i].value) {
|
||||||
|
action.key = conditions[i].jump - 1;
|
||||||
|
break;
|
||||||
|
} else if (conditions[i].comp === '<=' && data <= conditions[i].value) {
|
||||||
|
action.key = conditions[i].jump - 1;
|
||||||
|
break;
|
||||||
|
} else if (conditions[i].comp === '') {
|
||||||
|
// empty comparison => else statement
|
||||||
|
|
||||||
|
action.key = conditions[i].jump - 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
};
|
||||||
17
Model/Action/Event/Jump.js
Normal file
17
Model/Action/Event/Jump.js
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { jsOMS } from '../../../Utils/oLib.js';
|
||||||
|
/**
|
||||||
|
* Prevent UI action.
|
||||||
|
*
|
||||||
|
* @param {Object} action Action data
|
||||||
|
* @param {function} callback Callback
|
||||||
|
* @param {string} id Action element
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
export function jumpAction (action, callback, id)
|
||||||
|
{
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
action.key = action.jump - 1;
|
||||||
|
callback();
|
||||||
|
};
|
||||||
|
|
@ -41,8 +41,44 @@ export class UIStateManager
|
||||||
const length = !elements ? 0 : elements.length;
|
const length = !elements ? 0 : elements.length;
|
||||||
|
|
||||||
for (let i = 0; i < length; ++i) {
|
for (let i = 0; i < length; ++i) {
|
||||||
|
this.loadState(elements[i]);
|
||||||
this.bindElement(elements[i]);
|
this.bindElement(elements[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @performance This is a stupid fix to fix view changes during the first loadState
|
||||||
|
// E.g. scroll position depends on other UI elements
|
||||||
|
for (let i = 0; i < length; ++i) {
|
||||||
|
this.loadState(elements[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadState (element)
|
||||||
|
{
|
||||||
|
if (!element) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let state = JSON.parse(window.localStorage.getItem('ui-state-' + element.id));
|
||||||
|
state = state !== null ? state : {};
|
||||||
|
|
||||||
|
switch (element.tagName.toLowerCase()) {
|
||||||
|
case 'input':
|
||||||
|
if ((state === '1' && !element.checked)
|
||||||
|
|| (state === '0' && element.checked)
|
||||||
|
) {
|
||||||
|
element.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'div':
|
||||||
|
element.scrollLeft = state.x;
|
||||||
|
element.scrollTop = state.y;
|
||||||
|
|
||||||
|
element.scrollTo({ top: state.y, left: state.x });
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -60,37 +96,31 @@ export class UIStateManager
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let state = JSON.parse(window.localStorage.getItem('ui-state-' + element.id));
|
|
||||||
state = state !== null ? state : {};
|
|
||||||
|
|
||||||
switch (element.tagName.toLowerCase()) {
|
switch (element.tagName.toLowerCase()) {
|
||||||
case 'input':
|
case 'input':
|
||||||
if ((state === '1' && !element.checked)
|
|
||||||
|| (state === '0' && element.checked)
|
|
||||||
) {
|
|
||||||
element.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
element.addEventListener('change', function (event) {
|
element.addEventListener('change', function (event) {
|
||||||
if (this.getAttribute('type') === 'checkbox'
|
if (this.getAttribute('type') === 'checkbox'
|
||||||
|| this.getAttribute('type') === 'radio'
|
|| this.getAttribute('type') === 'radio'
|
||||||
) {
|
) {
|
||||||
window.localStorage.setItem('ui-state-' + this.id, JSON.stringify(this.checked ? '1' : '0'));
|
window.localStorage.setItem(
|
||||||
|
'ui-state-' + this.id,
|
||||||
|
JSON.stringify(this.checked ? '1' : '0')
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
window.localStorage.setItem('ui-state-' + this.id, JSON.stringify(this.value));
|
window.localStorage.setItem(
|
||||||
|
'ui-state-' + this.id,
|
||||||
|
JSON.stringify(this.value)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 'div':
|
case 'div':
|
||||||
// @todo this is not working, WHY? state is correct, but element.scrollTop is just ignored?!
|
|
||||||
element.scrollLeft = state.x;
|
|
||||||
element.scrollTop = state.y;
|
|
||||||
|
|
||||||
element.scrollTo({ top: state.y, left: state.x });
|
|
||||||
|
|
||||||
element.addEventListener('scroll', function () {
|
element.addEventListener('scroll', function () {
|
||||||
window.localStorage.setItem('ui-state-' + this.id, JSON.stringify({ x: this.scrollLeft, y: this.scrollTop }));
|
window.localStorage.setItem(
|
||||||
|
'ui-state-' + this.id,
|
||||||
|
JSON.stringify({ x: this.scrollLeft, y: this.scrollTop })
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user