mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-28 10:14:13 +00:00
refactor(input) mv client -> client/modules/config
This commit is contained in:
parent
ba72727fba
commit
7e98ad725d
3 changed files with 7 additions and 7 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
/* global CloudCmd, DOM, io */
|
||||
|
||||
require('../../css/config.css');
|
||||
require('../../../css/config.css');
|
||||
|
||||
const rendy = require('rendy/legacy');
|
||||
const currify = require('currify/legacy');
|
||||
|
|
@ -13,12 +13,12 @@ const tryToCatch = require('try-to-catch/legacy');
|
|||
const load = require('load.js');
|
||||
const createElement = require('@cloudcmd/create-element');
|
||||
|
||||
const input = require('../input');
|
||||
const Images = require('../dom/images');
|
||||
const Events = require('../dom/events');
|
||||
const Files = require('../dom/files');
|
||||
const input = require('./input');
|
||||
const Images = require('../../dom/images');
|
||||
const Events = require('../../dom/events');
|
||||
const Files = require('../../dom/files');
|
||||
|
||||
const {getTitle} = require('../../common/cloudfunc');
|
||||
const {getTitle} = require('../../../common/cloudfunc');
|
||||
const {Dialog, setTitle} = DOM;
|
||||
|
||||
const Name = 'Config';
|
||||
81
client/modules/config/input.js
Normal file
81
client/modules/config/input.js
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
'use strict';
|
||||
|
||||
const currify = require('currify/legacy');
|
||||
|
||||
const isType = currify((type, object, name) => {
|
||||
return typeof object[name] === type;
|
||||
});
|
||||
|
||||
const isBool = isType('boolean');
|
||||
|
||||
module.exports.getElementByName = getElementByName;
|
||||
|
||||
function getElementByName(selector, element) {
|
||||
const str = `[data-name="js-${selector}"]`;
|
||||
|
||||
return element
|
||||
.querySelector(str);
|
||||
}
|
||||
|
||||
module.exports.getName = (element) => {
|
||||
const name = element
|
||||
.getAttribute('data-name')
|
||||
.replace(/^js-/, '');
|
||||
|
||||
return name;
|
||||
};
|
||||
|
||||
module.exports.convert = (config) => {
|
||||
const result = {
|
||||
...config,
|
||||
};
|
||||
const array = Object.keys(config);
|
||||
|
||||
const filtered = array.filter(isBool(config));
|
||||
|
||||
for (const name of filtered) {
|
||||
const item = config[name];
|
||||
result[name] = setState(item);
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
function setState(state) {
|
||||
if (state)
|
||||
return ' checked';
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
module.exports.getValue = (name, element) => {
|
||||
const el = getElementByName(name, element);
|
||||
const {type} = el;
|
||||
|
||||
switch(type) {
|
||||
case 'checkbox':
|
||||
return el.checked;
|
||||
|
||||
case 'number':
|
||||
return Number(el.value);
|
||||
|
||||
default:
|
||||
return el.value;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.setValue = (name, value, element) => {
|
||||
const el = getElementByName(name, element);
|
||||
const {type} = el;
|
||||
|
||||
switch(type) {
|
||||
case 'checkbox':
|
||||
el.checked = value;
|
||||
break;
|
||||
|
||||
default:
|
||||
el.value = value;
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue