All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.asset.ajaxjs-ui.js.widgets.admin.allConfig.js Maven / Gradle / Ivy

Go to download

AJAXJS Web aims to full-stack, not only the server-side framework, but also integrates the front-end library. It'€™s written in HTML5 + Java, a successor to the JVM platform, efficient, secure, stable, cross-platform and many other advantages, but it abandoned the traditional enterprise architecture brought about by the large and bloated, emphasizing the lightweight, and fast, very suitable for the Internet fast application.

There is a newer version: 1.3.0
Show newest version


var tree = aj('.tree');

function isMap(v) {
	return typeof v == 'object' && v != null;
}

var stack = [];
function it(json, fn, parentEl) {
	stack.push(json);
	var ul = document.createElement('ul');
	ul.style.paddingLeft = (stack.length * 10) + "px";

	// 折叠
	if (stack.length != 1) {
		ul.className = 'subTree';
		ul.style.height = '0';
	}

	for ( var i in json) {
		var el = json[i];

		var li = document.createElement('li');
		if (isMap(el)) {
			var div = document.createElement('div'); // parentNode
			div.className = 'parentNode';
			div.innerHTML = '+' + i;
			div.onclick = toggle;
			li.appendChild(div);
			// debugger;
			it(el, fn, li);
		} else {
			var namespaces = getParentStack(stack); // 另外设一个 stack?
			if (namespaces)
				namespaces += '.' + i;
			else
				namespaces = i;
			
			try {
				var scheme = eval('jsonScheme.' + namespaces);
				var tip = makeTip(scheme);
			} catch (e) {
				// 有时 jsonScheme 没有对应的
				var scheme = {
					ui : 'input_text'
				};
				var tip = '';
			}

			var html = '
'; if(!scheme){ // 没有说明,忽略 continue; } switch (scheme.ui) { case 'textarea': html += ''; break; case 'htmlEditor': // html += document.querySelector('.tpl').value; break; case 'checkbox': html += renderCheckbox(scheme, namespaces, tip, el); break; case 'radio': html += renderRadio(scheme, namespaces, tip, el); break; case 'select': html += renderSelect(scheme, namespaces, tip, el); break; case 'input_text': default: html += ''; } html += ('
'+ (scheme.name || '') + ' ' + i); li.innerHTML = html; // if (scheme.ui == 'htmlEditor') // initHtmlEditor(li, el, namespaces); fn(i, el); } ul.appendChild(li); } stack.pop(); parentEl.appendChild(ul); } function getRealValue(v) { switch(v) { case 'null': case 'true': case 'false': return eval(v); } if((Number(v) + "") == v) return Number(v); return v; } function isChecked(value, itemValue) { return (value & itemValue) == itemValue; } // 获取完整的父节点路径 function getParentStack(stack) { var names = []; var last; for (var i = stack.length; i > 0; i--) { last = stack[i]; if (last) { var map = stack[i - 1]; for ( var j in map) { if (map[j] == last) { names.push(j); } } } } return names.reverse().join('.'); } // 根据元数据生成说明 function makeTip(scheme) { if (!scheme || !scheme.name || !scheme.tip) return ''; var html = scheme.name.bold(); html += '
' + scheme.tip; return html; } function toggle(e) { var div = e.target; var ul = div.parentNode.$('ul'); if (ul.style.height == '0px') { div.innerHTML = div.innerHTML.replace('+', '-'); ul.style.height = ul.scrollHeight + 'px'; setTimeout(function() { ul.style.height = 'auto'; // a ticky }, 500); } else { div.innerHTML = div.innerHTML.replace('-', '+'); ul.style.height = '0px'; } } it(configJson, function(item, v) { }, tree); // 遍历每个函数 function getList(formEl, fn) { var list = []; function add(el) { list.push(el); } var forEach = [].forEach; forEach.call(formEl.querySelectorAll('input'), add); forEach.call(formEl.querySelectorAll('select'), add); // forEach.call(formEl.querySelectorAll('input[type=password]'), add); forEach.call(formEl.querySelectorAll('textarea'), add); list.forEach(fn); } var isIn = false; function everyInput(input) { input.onfocus = function(e) { // debugger; var el = e.currentTarget; isIn = true; var tipsNote = el.dataset.note;// el.getAttribute('data-note'); if (tipsNote) { var tipsNoteEl = document.querySelector('.tipsNote'); tipsNoteEl.querySelector('span').innerHTML = tipsNote; // tipsNoteEl.style.left = el.offsetLeft + el.offsetWidth + 30 + // 'px'; tipsNoteEl.style.top = (el.offsetTop - 10) + 'px'; tipsNoteEl.classList.remove('hide'); } } input.onblur = function(e) { setTimeout(function() { if (!isIn) document.querySelector('.tipsNote').classList.add('hide'); }, 5000); isIn = false; } } getList(tree, everyInput); // 保存原 form 表单数据 var oldData; setTimeout(function() { oldData = {}; new FormData(document.querySelector('form')).forEach(function(value, key) { oldData[key] = value; }); }, 200); function getDiffent() { var needsTo8421 = [ 'user.login.loginType', 'user.login.passWordLoginType']; // 写死 for (var i = 0, j = needsTo8421.length; i < j; i++) code8421(needsTo8421[i]); var htmlEditorTextareas = document.querySelectorAll('.htmlEditorTextarea'); //debugger; for (var i = 0, j = htmlEditorTextareas.length; i < j; i++) { var htmlEditorTextarea = htmlEditorTextareas[i]; htmlEditorTextarea.value = htmlEditorTextareas[0].previousElementSibling.contentWindow.document.body.innerHTML; } var different = {}; var formData = new FormData(document.querySelector('form')); formData.forEach(function(value, key) { if (oldData[key] != value) { different[key] = value; } }); return different; } function save() { var data = getDiffent(); console.log(data); if (Object.keys(data).length) { ajaxjs.xhr.post('?', function(json) { if (json && json.isOk) aj.alert.show('修改配置成功!'); }, data); } else{ aj.alert.show('没任何修改'); } } function code8421(key) { var arr = document.querySelectorAll('input[data-name="' + key + '"]'); var total = 0; for (var i = 0, j = arr.length; i < j; i++) { if (arr[i].checked) { total += Number(arr[i].value); } } document.querySelector('input[name="' + key + '"]').value = total; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy