📄 astman.js.svn-base
字号:
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;) { 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 = {}; category.fieldbyname = { }; category.fields = []; } ASTGUI.selectbox.append(box,"New Entry", ""); 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; ASTGUI.selectbox.append_option(box,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])) { try{ box.options.add(box.options[box.selectedIndex], y); }catch(e){ box.remove(box.selectedIndex); box.add(tmp_newopt, y); } break; } } } else box.remove(box.selectedIndex); opt.parameters="action=updateconfig&srcfilename=" + encodeURIComponent(box.config_file) + "&dstfilename=" + encodeURIComponent(box.config_file) + uri; temp = new Ajax.Request(box.engine.url, opt); } } else { if (box.widgets['name']) { /* Check for conflict in the name */ if (box.widgets['name'].value.length) { if (box.widgets['name'].value != cattmp.catname) { if (box.stored_config.catbyname[box.widgets['name'].value]) { gui_alert("Sorry, an entry named " + box.widgets['name'].value + " already exists!"); return; } } } else { gui_alert("Sorry, a " + box.callbacks.identifier + " must be specified!"); return; } } var treq; if(isIE){ treq = box.engine.fields2changes(box.widgets, box.stored_config, cattmp, true); }else{ uri = box.engine.fields2changes(box.widgets, box.stored_config, cattmp); } if (uri.length || (isIE && !!treq['act_1']) ) { if (box.callbacks.format) { tmp = box.callbacks.format(box.stored_config.catbyname[cattmp.catname]); box.options[box.selectedIndex].value = cattmp.catname; box.options[box.selectedIndex].core_name = cattmp.catname; if (tmp) { box.options[box.selectedIndex].innerHTML = tmp; for (var y = 0; y < box.options.length + 1; y++) { if (!box.options[y] || do_compare(box, box.options[box.selectedIndex], box.options[y])) { try{ box.options.add(box.options[box.selectedIndex], y); }catch(err){ var new_option = box.ownerDocument.createElement('option') ; new_option.text = box.options[box.selectedIndex].text ; new_option.value = box.options[box.selectedIndex].value ; new_option.core_name = box.options[box.selectedIndex].core_name ; box.remove(box.selectedIndex); box.add( new_option , y); } break; } } } else{ box.remove(box.selectedIndex); } } } if (uri.length) { opt.parameters="action=updateconfig&srcfilename=" + encodeURIComponent(box.config_file) + "&dstfilename=" + encodeURIComponent(box.config_file) + uri; temp = new Ajax.Request(box.engine.url, opt); } if ( isIE && !!treq['act_1'] ) { var pre_uri = "action=updateconfig&srcfilename=" + encodeURIComponent(box.config_file) + "&dstfilename=" + encodeURIComponent(box.config_file); var start_sqreqs = function(st){ var f = treq[ 'act_' + st ]; if(f){ makerequest("","",pre_uri + f, start_sqreqs(st-1)); }else{ opt.onSuccess(); } }; var e = 0; for (var r in treq) { if( treq.hasOwnProperty(r) ){ e++; }} start_sqreqs(e); } if(!uri || (isIE && !treq['act_1']) ){ if (!box.callbacks.savechanges || !box.callbacks.savechanges()) { gui_feedback('No changes made!','green'); } if (box.widgets['save']){ box.widgets['save'].disabled = true; } if (box.widgets['cancel']){ box.widgets['cancel'].disabled = true; } } }}function ast_true(s){ if ( s == 'yes' || s == 'true' || s == 'y' || s == 't' || s == '1' || s == 'on' ){ return true; }else{ return false; }}function build_action(action, count, cat, name, value, match){ var s=""; var cnt = "" + count; while(cnt.length < 6) cnt = "0" + cnt; s += "&Action-" + cnt + "=" + encodeURIComponent(action); s += "&Cat-" + cnt + "=" + encodeURIComponent(cat); s += "&Var-" + cnt + "=" + encodeURIComponent(name); s += "&Value-" + cnt + "=" + encodeURIComponent(value); if (match) s += "&Match-" + cnt + "=" + encodeURIComponent(match); return s;}function check_pattern(pattern, text){ if(typeof text != "undefined"){ if (text.search(pattern) == -1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -