📄 astman.js
字号:
box.remove(index); if (tmp.length > 1) { res = box.callbacks.format(cfg.catbyname[tmp[0]], tmp[1]); insert_option(box, res, tmp[0] + "]" + tmp[1], cfg.catbyname[tmp[0]].subfields[tmp[1]]['name']); } else { res = box.callbacks.format(cfg.catbyname[v]); insert_option(box, res, cfg.catbyname[v].name, cfg.categories[x].name); }}function update_box(box) { var x,y,z; var res; var oldselect = box.value; cfg = box.stored_config; while (box.options.length) box.remove(0); for (x=0;x<cfg.catcnt;x++) { if (box.callbacks.eachline) { if (box.callbacks.includecats) { res = box.callbacks.format(cfg.categories[x]); insert_option(box,res,cfg.categories[x].name,cfg.categories[x].name); } for (y=0;cfg.categories[x].names[y];y++) { cfg.categories[x].subfields[y] = new Object; res = box.callbacks.format(cfg.categories[x], y); insert_option(box,res,cfg.categories[x].name + "]" + y,cfg.categories[x].subfields[y]['name']); } } else { res = box.callbacks.format(cfg.categories[x]); insert_option(box,res,cfg.categories[x].name,cfg.categories[x].name); } } box.oldselect = -1; box.selectedIndex = -1; box.value = null; for (x=0;x<box.options.length;x++) { if (box.options[x].value == oldselect) box.selectedIndex = x; } select_item(box);}function select_item(box, errmsg) { var category; var tmp; if (!errmsg) errmsg = "Discard changes?"; if ((box.widgets['save'] && !box.widgets['save'].disabled)) { if (!confirm(errmsg)) { box.selectedIndex = box.oldselect; return false; } } tmp = box.value.split(']'); if (box.oldselect && (box.oldselect > -1)) { if ((tmp.length > 1) && (box.stored_config.catbyname[tmp[0]].subfields[tmp[1]].name == "")) { box.remove(box.oldselect); box.oldselect = -1; box.stored_config.catbyname[tmp[0]].subfields.splice(tmp[1], 1); box.stored_config.catbyname[tmp[0]].names.splice(tmp[1], 1); try{ box.stored_config.catbyname[tmp[0]].values.splice(tmp[1], 1); } catch(err){ } } else if (box.options[box.oldselect].value == "") { box.remove(box.oldselect); box.oldselect = -1; box.stored_config.catbyname[""] = null; box.stored_config.categories[--box.stored_config.catcnt] = null; } else if (box.options[box.oldselect].text == "New Entry") { box.remove(box.oldselect); box.oldselect = -1; } } if (tmp.length > 1) { category = box.stored_config.catbyname[tmp[0]].subfields[tmp[1]]; } else { category = box.stored_config.catbyname[box.value]; } box.engine.cat2fields(box.widgets, category); if (box.widgets['delete']) { if (category) box.widgets['delete'].disabled = false; else box.widgets['delete'].disabled = true; } box.oldselect = box.selectedIndex; if (box.widgets['new']) box.widgets['new'].disabled = false; if (box.widgets['newitem']) box.widgets['newitem'].disabled = false; if (box.callbacks.postselect) box.callbacks.postselect(box, box.value); return true;};function cancel_item(box) { var tmp = box.options[box.selectedIndex].value.split(']'); if (tmp.length > 1) { if (box.stored_config.catbyname[tmp[0]].subfields[tmp[1]].name.length < 1) { if (select_item(box,"Discard new entry?")){ gui_feedback("New Entry cancelled!",'default') ; box.selectedIndex = -1; } } else { if (select_item(box)) gui_feedback("Changes cancelled!",'default') ; } } else { if (box.options[box.selectedIndex].value == "") { if (select_item(box,"Discard new entry?")){ gui_feedback("New Entry cancelled!",'default') ; //box.selectedIndex = -1; if (box.callbacks.cancelnewcategory) box.callbacks.cancelnewcategory(); } } else { if (select_item(box)) { gui_feedback("Changes cancelled!",'default') ; if (box.callbacks.cancelchanges) box.callbacks.cancelchanges(); } } }}function first_free_exten(box, start) { var x = start; var y; for (;;) { for (y=0;y<box.options.length;y++) { if (box.options[y].core_name == x) break; } if (y >= box.options.length) break; x++; } return x;}function action_issuccess(responseText) { if ( responseText.indexOf("Response: Success") == -1 ){ return false; }else{ return true; }}function action_errmsg (responseText){ var tmp = responseText.split("Message:"); return tmp[1];}function delete_item(box, value, noconfirm) { var opt = { method: 'get', asynchronous: true, onSuccess: function(t) { // if(action_issuccess(t.responseText) ){ if (box.callbacks.oncategorydelete) box.callbacks.oncategorydelete(value); gui_feedback('Deleted','default'); if (box.callbacks.delchanges) box.callbacks.delchanges(box, box.delvalue, box.delcat);// }else{// alert( action_errmsg (t.responseText) );// } }, onFailure: function(t) { gui_alert("Config Error: " + t.status + ": " + t.statusText); } }; var tmp, tmp2, uri; var x,y; var updatebox = 0; var subcat, subname, suborig; if (!noconfirm) { if( box.options[box.selectedIndex].text == "New Entry" && box.widgets['cancel'] ){ box.widgets['cancel'].click(); return true; } if (!confirm("Delete entry?")) { return false; } } if (!value) { updatebox = 1; value = box.value; } box.delvalue = value; tmp = value.split(']'); if (tmp.length > 1) { var oldname; box.delcat = box.stored_config.catbyname[tmp[0]].subfields[tmp[1]]; oldname = box.stored_config.catbyname[tmp[0]].subfields[tmp[1]].name; subname = box.stored_config.catbyname[tmp[0]].names[tmp[1]]; suborig = box.stored_config.catbyname[tmp[0]].fields[tmp[1]]; box.stored_config.catbyname[tmp[0]].subfields.splice(tmp[1], 1); box.stored_config.catbyname[tmp[0]].names.splice(tmp[1], 1); box.stored_config.catbyname[tmp[0]].fields.splice(tmp[1], 1); for (x=0;x<box.options.length;x++) { tmp2 = box.options[x].value.split(']'); /* Renumber remaining line numbers */ if ((tmp2.length > 1) && (tmp2[0] == tmp[0])) { if (tmp2[1] > tmp[1]) { var newname = tmp2[0] + "]" + String(Number(tmp2[1]) - 1); box.options[x].value = newname; } } } if (updatebox && oldname == "") { gui_feedback('Deleted','default'); } else { uri = build_action('delete', 0, tmp[0], subname, "", suborig); opt.parameters="action=updateconfig&srcfilename=" + encodeURIComponent(box.config_file) + "&dstfilename=" + encodeURIComponent(box.config_file) + uri; tmp = new Ajax.Request(box.engine.url, opt); } } else { for (x=0;x<box.stored_config.catcnt;) { if (box.stored_config.categories[x] == box.stored_config.catbyname[value]) { box.stored_config.categories.splice(x, 1); } else x++; } for (;y<box.stored_config.catcnt;y++) { box.stored_config.categories[y] = null; } delete box.stored_config.catbyname[value]; --box.stored_config.catcnt; if (updatebox && box.options[box.selectedIndex].value == "") { gui_feedback('Deleted','default'); } else { uri = build_action('delcat', 0, value, "", ""); opt.parameters="action=updateconfig&srcfilename=" + encodeURIComponent(box.config_file) + "&dstfilename=" + encodeURIComponent(box.config_file) + uri; tmp = new Ajax.Request(box.engine.url, opt); } } if (updatebox) { box.remove(box.selectedIndex); for (x=0;x<box.options.length;) { var tmp = box.options[x].value.split(']'); if (tmp.length > 1) { if (tmp[0] == value) { box.remove(x); } else x++; } else x++; } box.oldselect = -1; box.selectedIndex = -1; box.value = null; select_item(box); }};function new_item(box) { var category = null; var name = null; if (box.widgets['save'] && box.widgets['save'].disabled == false){ if (!confirm( "Discard changes?")) { box.selectedIndex = box.oldselect; return false; } } if (box.callbacks.newcategory) { category = box.callbacks.newcategory(); } if (!category) { category = new Object; category.fieldbyname = { }; category.fields = new Array; } var newoption = box.ownerDocument.createElement("option"); newoption.text = "New Entry"; newoption.value = ""; box.options.add(newoption); box.selectedIndex = box.options.length - 1; box.oldselect = box.options.length - 1; box.stored_config.catbyname[""] = category; box.stored_config.categories[box.stored_config.catcnt++] = category; name = category.name; category.name = ''; box.engine.cat2fields(box.widgets, category); if (box.widgets['new']) box.widgets['new'].disabled = true; if (box.widgets['newitem']) box.widgets['newitem'].disabled = true; if (box.widgets['save']) box.widgets['save'].disabled = false; if (box.widgets['delete']) box.widgets['delete'].disabled = false; if (box.widgets['cancel']) box.widgets['cancel'].disabled = false; gui_feedback('Creating new entry!','green'); if (box.widgets['name']){ box.widgets['name'].value = name; //box.widgets['name'].focus(); }}function new_subitem(box) { var name = null; var tmp; var pos; var subname, subitem, subcat; var category; var newoption = box.ownerDocument.createElement("option"); newoption.text = "New Entry"; if (box.callbacks.newsubitem) { tmp = box.callbacks.newsubitem(); if (tmp) { subcat = tmp[0]; subname = tmp[1]; subitem = tmp[2]; } } if (!subitem) { subitem = new Object; } if (!subcat) subcat = box.current_category; if (!subcat || !subcat.length || !subname || !subname.length) return; box.options.add(newoption); box.selectedIndex = box.options.length - 1; box.oldselect = box.options.length - 1; category = box.stored_config.catbyname[subcat]; pos = category.names.length; category.subfields[pos] = subitem; category.names[pos] = subname; category.fields[pos] = null; newoption.value = subcat + "]" + pos; newoption.core_name = category.subfields[pos].name; box.value = newoption.value; name = subitem.name; subitem.name = ''; box.engine.cat2fields(box.widgets, subitem); if (box.widgets['new']) box.widgets['new'].disabled = true; if (box.widgets['newitem']) box.widgets['newitem'].disabled = true; if (box.widgets['save']) box.widgets['save'].disabled = false; if (box.widgets['delete']) box.widgets['delete'].disabled = false; if (box.widgets['cancel']) box.widgets['cancel'].disabled = false; gui_feedback('Creating new entry!','green'); if (box.widgets['name']) box.widgets['name'].value = name;}function apply_uri(box, uri){ var opt = { method: 'get', asynchronous: true, onSuccess: function() { if (box.widgets['save']) box.widgets['save'].disabled = true; if (box.widgets['new']) box.widgets['new'].disabled = false; if (box.widgets['newitem']) box.widgets['newitem'].disabled = false; if (box.widgets['cancel']) box.widgets['cancel'].disabled = true; gui_feedback('Configuration saved!','blue'); if (box.callbacks.savechanges) box.callbacks.savechanges(); }, onFailure: function(t) { gui_alert("Config Error: " + t.status + ": " + t.statusText); } }; var tmp; opt.parameters="action=updateconfig&srcfilename=" + encodeURIComponent(box.config_file) + "&dstfilename=" + encodeURIComponent(box.config_file) + uri; tmp = new Ajax.Request(box.engine.url, opt);}function save_item(box) { if (box.callbacks.beforeSaving){ // like for field validations etc. var tmp = box.callbacks.beforeSaving(); if ( tmp == false ) return false; } var opt = { method: 'get', asynchronous: true, onSuccess: function() { if (box.widgets['save']) box.widgets['save'].disabled = true; if (box.widgets['new']) box.widgets['new'].disabled = false; if (box.widgets['newitem']) box.widgets['newitem'].disabled = false; if (box.widgets['cancel']) box.widgets['cancel'].disabled = true; gui_feedback('Configuration saved!','blue'); if (box.callbacks.savechanges) box.callbacks.savechanges(); }, onFailure: function(t) { gui_alert("Config Error: " + t.status + ": " + t.statusText); } }; var uri = "" ; var tmp; var temp; var newval; var cattmp = new Object; cattmp.catname = box.value; if (box.callbacks.checkparams) { if (box.callbacks.checkparams(box)) return; } tmp = box.value.split(']'); if (tmp.length > 1) { box.engine.fields2changes(box.widgets, box.stored_config, cattmp); newval = box.callbacks.fields2val(box, box.stored_config.catbyname[tmp[0]].subfields[tmp[1]]); if (newval != box.stored_config.catbyname[tmp[0]].fields[tmp[1]]) { if (box.stored_config.catbyname[tmp[0]].fields[tmp[1]]) { uri = build_action('update', 0, tmp[0], box.stored_config.catbyname[tmp[0]].names[tmp[1]], newval, box.stored_config.catbyname[tmp[0]].fields[tmp[1]]); } else { if (box.stored_config.catbyname[tmp[0]].subfields[tmp[1]]['>']) uri = build_action('append', 0, tmp[0], box.stored_config.catbyname[tmp[0]].names[tmp[1]], newval, 'object'); else uri = build_action('append', 0, tmp[0], box.stored_config.catbyname[tmp[0]].names[tmp[1]], newval); } box.stored_config.catbyname[tmp[0]].fields[tmp[1]] = newval; box.options[box.selectedIndex].core_name = box.stored_config.catbyname[tmp[0]].subfields[tmp[1]]['name']; tmp = box.callbacks.format(box.stored_config.catbyname[tmp[0]], tmp[1]); if (tmp) { box.options[box.selectedIndex].innerHTML = tmp; var tmp_newopt = box.ownerDocument.createElement('option'); tmp_newopt.text = box.options[box.selectedIndex].innerHTML ; tmp_newopt.value = box.options[box.selectedIndex].value; for (var y = 0; y < box.options.length + 1; y++) { if (!box.options[y] || do_compare(box, box.options[box.selectedIndex], box.options[y])) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -