⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 astman.js

📁 asterisk 的图形管理界面
💻 JS
📖 第 1 页 / 共 4 页
字号:
						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;			}		}		uri = box.engine.fields2changes(box.widgets, box.stored_config, cattmp);		if (uri.length) {			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);				}			}			opt.parameters="action=updateconfig&srcfilename=" + encodeURIComponent(box.config_file) + "&dstfilename=" + encodeURIComponent(box.config_file) + uri;			temp = new Ajax.Request(box.engine.url, opt);		}	}	if (!uri.length) {		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)			return false;		else			return true;	}	return true;}function Astman() {	var me = this;	var channels = new Array;	var lastselect;	var selecttarget;	this.setURL = function(url) {		this.url = url;	};	this.setEventCallback = function(callback) {		this.eventcallback = callback;	};	this.setDebug = function(debug) {		this.debug = debug;	};	this.run_tool = function(tool, callback) {		var opt = {			method: 'get',			asynchronous: true,			onSuccess: function() { 				if (callback)					callback();			},			onFailure: function(t) {				gui_alert("Tool Error: " + t.status + ": " + t.statusText);			}		};		var tmp;		opt.parameters="action=originate&channel=" + encodeURIComponent("Local/executecommand@"+asterisk_guitools ) + "&Variable=command%3d"+ encodeURIComponent(tool) + "&application=noop&timeout=60000";		tmp = new Ajax.Request(this.url, opt);	}	this.clickChannel = function(ev) {		var target = ev.target;		// XXX This is icky, we statically use astmanEngine to call the callback XXX 		if (me.selecttarget)			me.restoreTarget(me.selecttarget);		while(!target.id || !target.id.length)			target=target.parentNode;		me.selecttarget = target.id;		target.className = "chanlistselected";		if(channelsCallback ){			channelsCallback (target.id);		}		//me.chancallback(target.id);	};	this.restoreTarget = function(targetname) {		var other;		target = $(targetname);		if (!target)			return;		if (target.previousSibling) {			other = target.previousSibling.previousSibling.className;		} else if (target.nextSibling) {			other = target.nextSibling.nextSibling.className;		}		if (other) {			if (other == "chanlisteven") 				target.className = "chanlistodd";			else				target.className = "chanlisteven";		} else			target.className = "chanlistodd";	};	this.channelUpdate = function(msg, channame) {		var fields = new Array("callerid", "calleridname", "context", "extension", "priority", "account", "state", "link", "uniqueid" );		if (!channame || !channame.length)			channame = msg.headers['channel'];		if (!channels[channame])			channels[channame] = new Array();					if (msg.headers.event) {			if (msg.headers.event == "Hangup") {				delete channels[channame];			} else if (msg.headers.event == "Link") {				var chan1 = msg.headers.channel1;				var chan2 = msg.headers.channel2;				if (chan1 && channels[chan1])					channels[chan1].link = chan2;				if (chan2 && channels[chan2])					channels[chan2].link = chan1;			} else if (msg.headers.event == "Unlink") {				var chan1 = msg.headers.channel1;				var chan2 = msg.headers.channel2;				if (chan1 && channels[chan1])					delete channels[chan1].link;				if (chan2 && channels[chan2])					delete channels[chan2].link;			} else if (msg.headers.event == "Rename") {				var oldname = msg.headers.oldname;				var newname = msg.headers.newname;				if (oldname && channels[oldname]) {					channels[newname] = channels[oldname];					delete channels[oldname];				}			} else {				channels[channame]['channel'] = channame;				for (x=0;x<fields.length;x++) {					if (msg.headers[fields[x]])						channels[channame][fields[x]] = msg.headers[fields[x]];				}			}		} else {			channels[channame]['channel'] = channame;			for (x=0;x<fields.length;x++) {				if (msg.headers[fields[x]])					channels[channame][fields[x]] = msg.headers[fields[x]];			}		}	};	this.channelClear = function() {		channels = new Array;	}	this.channelInfo = function(channame) {		return channels[channame];	};	this.channelTable = function(callback) {		var s, x;		var cclass, count=0;		var found = 0;		var foundactive = 0;		var fieldlist = new Array("channel", "callerid", "calleridname", "context", "extension", "priority");		me.chancallback = callback;		s = "<table class='chantable' align='center'>\n";		s = s + "\t<tr class='labels' id='labels'><td>Channel</td><td>State</td><td>Caller</td><td>Location</td><td>Link</td></tr>";		count=0;		for (x in channels) {			if (channels[x].channel) {				if (count % 2)					cclass = "chanlistodd";				else					cclass = "chanlisteven";				if (me.selecttarget && (me.selecttarget == x)) {					cclass = "chanlistselected";					foundactive = 1;				}				count++;				s = s + "\t<tr class='" + cclass + "' id='" + channels[x].channel + "' onClick='astmanEngine.clickChannel(event)'>";				s = s + "<td class='field_text'>" + channels[x].channel + "</td>";				if (channels[x].state)					s = s + "<td class='field_text'>" + channels[x].state + "</td>";				else					s = s + "<td class='field_text'><i class='light'>unknown</i></td>";				if (channels[x].calleridname && channels[x].callerid && channels[x].calleridname != "<unknown>") {					cid = channels[x].calleridname.escapeHTML() + " &lt;" + channels[x].callerid.escapeHTML() + "&gt;";				} else if (channels[x].calleridname && (channels[x].calleridname != "<unknown>")) {					cid = channels[x].calleridname.escapeHTML();				} else if (channels[x].callerid) {					cid = channels[x].callerid.escapeHTML();				} else {					cid = "<i class='light'>Unknown</i>";				}				s = s + "<td class='field_text'>" + cid + "</td>";				if (channels[x].extension) {					s = s + "<td class='field_text'>" + channels[x].extension + "@" + channels[x].context + ":" + channels[x].priority + "</td>";				} else {					s = s + "<td class='field_text'><i class='light'>None</i></td>";				}				if (channels[x].link) {					s = s + "<td class='field_text'>" + channels[x].link + "</td>";				} else {					s = s + "<td class='field_text'><i class='light'>None</i></td>";				}				s = s + "</tr>\n";				found++;			}		}		if (!found)			s += "<tr><td colspan=" + fieldlist.length + "><i class='light'>No active channels</i></td>\n";		s += "</table>\n";		if (!foundactive) {			me.selecttarget = null;		}		return s;	};	this.parseResponse = function(t, callback, userdata) {		var msgs = new Array();		var inmsg = 0;		var msgnum = 0;		var x,y;		var s = t.responseText;		var allheaders = s.split('\r\n');		if (me.debug) 			me.debug.value = "\n";		for (x=0;x<allheaders.length;x++) {			if (allheaders[x].length) {				var fields = allheaders[x].split(': ');				if (!inmsg) {					msgs[msgnum] = new Object();					msgs[msgnum].headers = {};					msgs[msgnum].names = new Array();					y=0;				}				msgs[msgnum].headers[fields[0].toLowerCase()] = fields[1];				msgs[msgnum].names[y++] = fields[0].toLowerCase();				if (me.debug)					me.debug.value = me.debug.value + "field " + fields[0] + "/" + fields[1] + "\n";				inmsg=1;			} else {				if (inmsg) {					if (me.debug)						me.debug.value = me.debug.value + " new message\n";					inmsg = 0;					msgnum++;				}			}		}		if (me.debug) {			me.debug.value = me.debug.value + "msgnum is " + msgnum + " and array length is " + msgs.length + "\n";			me.debug.value = me.debug.value + "length is " + msgs.length + "\n";			var x, y;			for (x=0;x<msgs.length;x++) {				for (y=0;y<msgs[x].names.length;y++)  {					me.debug.value = me.debug.value + "msg "+ (x + 1) + "/" + msgs[x].names[y] + "/" + msgs[x].headers[msgs[x].names[y]] + "\n";				}			}		}		callback(msgs, userdata);	};	this.fields2changes = function(widgets, config, cattmp) {		var thevalue;		var changes="";		var count = 0;		var override=0;		var tmp;		var cat;				tmp = cattmp.catname.split(']');		if (tmp.length > 1)			cat = config.catbyname[tmp[0]].subfields[tmp[1]];		else			cat = config.catbyname[cattmp.catname];				if (widgets['name']) {			if (cat.name != widgets['name'].value) {				if (cat.name.length) {					changes += build_action('renamecat', count++, cat.name, "", widgets['name'].value);				} else {					changes += build_action('newcat', count++, widgets['name'].value, "", "");					override = 1;				}				cat.name = widgets['name'].value;				if (cat.fieldbyname) {					config.catbyname[cattmp.catname] = null;					config.catbyname[cat.name] = cat;					cattmp.catname = cat.name;				}			}		}				for (var x in widgets) {  if( widgets.hasOwnProperty(x) ){			var src;			if ((x == 'save') || (x == 'cancel') || (x == 'name') || (x == 'new') || (x == 'newitem') || (x == 'delete'))				continue;			if (widgets[x].name)				src = widgets[x].name;			else				src = x;			if (widgets[x] && widgets[x].type) {				if (cat.fieldbyname) {					if (cat.fieldbyname[src])						thevalue = cat.fieldbyname[src];					else						thevalue = '';				} else if (cat[src])					thevalue = cat[src];				else					thevalue = '';				if (widgets[x].type == 'radio') {					if (widgets[x].checked) {						if (override || !thevalue.length || (widgets[x].value != thevalue)) {							if (cat.fieldbyname)								cat.fieldbyname[src] = widgets[x].value;							else								cat[src] = widgets[x].value;							if (cat.fieldbyname)								changes += build_action('update', count++, cat.name, src, cat.fieldbyname[src]);						}					}				} else if (widgets[x].type == 'checkbox') {					if (override || !thevalue.length || (widgets[x].checked != ast_true(thevalue))) {						if (widgets[x].checked) {							if (cat.fieldbyname)								cat.fieldbyname[src] = 'yes';							else								cat[src] = 'yes';						} else if (cat.fieldbyname)							cat.fieldbyname[src] = 'no';						else							cat[src] = 'no';						if (cat.fieldbyname)							changes += build_action('update', count++, cat.name, src, cat.fieldbyname[src]);					}				} else if (widgets[x].options && widgets[x].multiple && widgets[x].splitchar) {					var answers = new Array;					for (var y=0;y<widgets[x].options.length;y++) {						if (widgets[x].options[y].selected)							answers.push(widgets[x].options[y].value);					}					if (cat.fieldbyname) {						cat.fieldbyname[src] = answers.join(widgets[x].splitchar);						if (thevalue != cat.fieldbyname[src])							changes += build_action('update', count++, cat.name, src, cat.fieldbyname[src]);					} else						cat[src] = answers.join(widgets[x].splitchar);				} else if (override || (widgets[x].value != thevalue)) {					if (cat.fieldbyname) {						cat.fieldbyname[src] = widgets[x].value;						changes += build_action('update', count++, cat.name, src, cat.fieldbyname[src]);					} else						cat[src] = widgets[src].value;				}			}		}}		return changes;	};		this.cat2fields = function(widgets, cat) {		var thevalue;		var savewidget = widgets['save'];		var cancelwidget = widgets['cancel'];		if (savewidget) {			savewidget.activateSave = function(t) {				savewidget.disabled = false;				if (savewidget.cancelwidget) {					savewidget.cancelwidget.disabled = false;				}			};			savewidget.disabled = true;			if (cancelwidget) {				savewidget.cancelwidget = cancelwidget;				cancelwidget.disabled = true;			}		}		for (var x in widgets) { if( widgets.hasOwnProperty(x) ){			var src;			if ((x == 'save') || (x == 'cancel') || (x == 'new') || (x == 'newitem') || (x == 'delete'))				continue;			if (widgets[x].name)				src = widgets[x].name;			else				src = x;			if (!widgets[x])				continue;			if (widgets[x].options) {				var all;				if (!cat) {					if (widgets[x].options[0])						thevalue = widgets[x].options[0].value;					else						thevalue = '';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -