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

📄 astman.js

📁 asterisk 的图形管理界面
💻 JS
📖 第 1 页 / 共 4 页
字号:
				} else if (cat.fieldbyname) { 					if (cat.fieldbyname[src])						thevalue = cat.fieldbyname[src];				} else if (cat[x])					thevalue = cat[x];				if (widgets[x].splitchar) {					for (var z=0;z<widgets[x].options.length;z++)						widgets[x].options[z].selected = false;					if (thevalue) {						all = thevalue.split(widgets[x].splitchar);						for (var y=0;y<all.length;y++) {							for (var z=0;z<widgets[x].options.length;z++) {								if (widgets[x].options[z].value == all[y])									widgets[x].options[z].selected = true;							}						}					}				} else {					widgets[x].selectedIndex = -1;					widgets[x].value = thevalue;				}								if (cat)					widgets[x].disabled = false;				else					widgets[x].disabled = true;				if (savewidget) {					widgets[x].savewidget = savewidget;					add_event( widgets[x] , 'click', function() { this.oldvalue = this.value; return true; });					add_event( widgets[x] , 'change', function() { 						this.savewidget.activateSave(); 						if (this.altonchange){ this.altonchange();} 					});				}				if (widgets[x].altonchange)					widgets[x].altonchange();			} else if (widgets[x].type) {				if (!cat) {					thevalue = '';				} else if (x == 'name')					thevalue = cat.name;				else if (cat.fieldbyname) { 					if (cat.fieldbyname[src])						thevalue = cat.fieldbyname[src];					else						thevalue='';				} else if (cat[x])					thevalue = cat[x];				else					thevalue = '';				if (widgets[x].type == 'checkbox') {					dfalt = widgets[x].getAttribute('dfalt');					if( dfalt && thevalue=='' )							widgets[x].checked = ast_true(dfalt);					else 							widgets[x].checked = ast_true(thevalue);				} else if (widgets[x].type == 'radio') {					if (widgets[x].value == thevalue)						widgets[x].checked = true;					else						widgets[x].checked = false;				} else{					dfalt = widgets[x].getAttribute('dfalt');					if( dfalt && thevalue=='' )						widgets[x].value = dfalt;					else 						widgets[x].value = thevalue;				}				if (cat)					widgets[x].disabled = false;				else					widgets[x].disabled = true;				if (savewidget) {					widgets[x].savewidget = savewidget;					if ((widgets[x].type == 'checkbox') || (widgets[x].type == 'radio')) {						add_event( widgets[x] , 'click', function() { this.savewidget.activateSave(); if (this.altonclick){this.altonclick();} });						if (widgets[x].altonclick)							widgets[x].altonclick();					} else {						add_event( widgets[x] , 'keydown', function() { this.oldvalue = this.value; return true; });						add_event( widgets[x] , 'keyup', function() { 							if (this.oldvalue == this.value){return true;}							pattern = this.getAttribute('pattern');							if (pattern && check_pattern(pattern, this.oldvalue) && !check_pattern(pattern, this.value)) {								this.value = this.oldvalue;								gui_feedback('Invalid Character !','red');							} else{								gui_feedback('','default',10);								this.savewidget.activateSave();							}							return true;						});					}				}			} else if (widgets[x].src != null) {				if (!cat) {					thevalue = '';				} else if (x == 'name')					thevalue = cat.name;				else if (cat.fieldbyname) { 					if (cat.fieldbyname[src])						thevalue = cat.fieldbyname[src];					else						thevalue='';				} else if (cat[x])					thevalue = cat[x];				else					thevalue = '';				if (thevalue.length) {					widgets[x].src = thevalue;					widgets[x].style.visibility = 'inherit';				} else 					widgets[x].style.visibility = 'hidden';			} else if (widgets[x].innerHTML != null) {				if (!cat) {					thevalue = '';				} else if (x == 'name')					thevalue = cat.name;				else if (cat.fieldbyname) { 					if (cat.fieldbyname[src])						thevalue = cat.fieldbyname[src];					else						thevalue='';				} else if (cat[x])					thevalue = cat[x];				else					thevalue = '';				widgets[x].innerHTML = thevalue;			}		}}	};	this.doConfig = function(t, box) {		if( t[0].headers['message'] && t[0].headers['message'] == "Config file not found" ){			if( box.config_file == "zapscan.conf" || box.config_file == "contactinfo.conf" || box.config_file == "jingle.conf" || box.config_file == "providers.conf" ){				parent.astmanEngine.run_tool("/bin/touch /etc/asterisk/"+box.config_file, function(){ window.location.href = window.location.href ; } );				return ;			} else {				alert( "Asterisk says it cannot find a required config file (" + box.config_file + ") \n You will be now redirected to the main page !" );				parent.window.location.href = parent.window.location.href ;				return ;			}		}		var x,y=0;		var cfg = new Object;		var map;		var curcat;		var catcnt = -1;		var tmp, tmp2;		var res;		box.innerHTML = '';		cfg.categories = new Array;		cfg.catbyname = { };		cfg.names = new Array;		for (x=0;t[0].names[x];x++) {			map = t[0].names[x].split('-');			if (map[0] == 'category') {				catcnt++;				cfg.names[catcnt] = t[0].headers[t[0].names[x]];				cfg.categories[catcnt] = new Object;				cfg.categories[catcnt].fields = new Array;				cfg.categories[catcnt].fieldbyname = { };				cfg.categories[catcnt].names = new Array;				cfg.categories[catcnt].subfields = new Array;				cfg.categories[catcnt].name = t[0].headers[t[0].names[x]];				cfg.catbyname[t[0].headers[t[0].names[x]]] = cfg.categories[catcnt];				y=0;			} else if (map[0] == 'line') {				if (catcnt >= 0) {					tmp = t[0].headers[t[0].names[x]].split('=');					tmp2 = t[0].headers[t[0].names[x]].split('=');					tmp2.splice(0,1);					tmp[1] = tmp2.join('=');					cfg.categories[catcnt].fields[y] = tmp[1];					cfg.categories[catcnt].names[y] = tmp[0];					cfg.categories[catcnt].fieldbyname[tmp[0]] = tmp[1];					y++;				}			}		}		cfg.catcnt = catcnt + 1;		box.stored_config = cfg;		update_box(box);		if (box.size == 1)			box.selectedIndex = 0;		if (box.callbacks.loaded)			box.callbacks.loaded();	};	this.managerResponse = function(t) {		me.parseResponse(t, me.callback);	};	this.doEvents = function(msgs) {		me.eventcallback(msgs);	};	this.eventResponse = function(t) {		if( t.responseText.match("Message: Authentication Required") ){						parent.window.location.href = parent.window.location.href ;		}		var _nu = navigator.userAgent; 		if( _nu.indexOf("MSIE") != -1 || _nu.indexOf("Konqueror") != -1 || _nu.indexOf("Safari") != -1 || _nu.indexOf("Opera") != -1){			// Donot Poll events for non mozilla Browsers					}else{ 			me.parseResponse(t, me.doEvents);		}	};	this.gotConfig = function(t, box) {		me.parseResponse(t, me.doConfig, box);	};	this.sendRequest = function(request, callback) {		var tmp;		var opt = {			method: 'get',			asynchronous: true,			onSuccess: this.managerResponse,			onFailure: function(t) {				if( request == 'action=ping' && String(t.status) == '404' ){				 gui_alert("Error: " +" Make sure <I>enabled=yes</I> and <I>webenabled=yes</I> are set in manager.conf");				 setLoggedOn(0);				}else{				gui_alert("Error: " + t.status + ": " + t.statusText);				}			}		};		me.callback = callback;		opt.parameters = request;		tmp = new Ajax.Request(this.url, opt);	};	this.pollEvents = function() {		var tmp;		var opt = {			method: 'get',			asynchronous: true,			onSuccess: this.eventResponse,			onFailure: function(t) {				gui_alert("Event Error: " + t.status + ": " + t.statusText);			}		};		opt.parameters="action=waitevent";		tmp = new Ajax.Request(this.url, opt);	};	this.config2list = function(config,box,widgets,callbacks) {		var tmp;		var opt = {			method: 'get',			asynchronous: true,			onSuccess: function(t) {				me.gotConfig(t, box);			},			onFailure: function(t) {				gui_alert("Config Error: " + t.status + ": " + t.statusText);			}		};		if (!callbacks.identifier)			callbacks.identifier = "name";		opt.parameters = "action=getconfig&filename=" + encodeURIComponent(config);		box.config_file = config;		box.callbacks = callbacks;		box.widgets = widgets;		box.engine = me;		box.oldselect = -1;		box.selectitem = function(t) {			box.selectedIndex = t;			return select_item(this);		}		box.onchange = function() {			return select_item(this)		};		if (widgets['save']) {			widgets['save'].hostselectbox = box;			add_event( widgets['save'] , 'click', function() { save_item(this.hostselectbox); });		}		if (widgets['cancel']) {			widgets['cancel'].hostselectbox = box;			add_event( widgets['cancel'] , 'click', function() { cancel_item(this.hostselectbox); });		}		if (widgets['new']) {			widgets['new'].hostselectbox = box;			widgets['new'].disabled = false;			add_event( widgets['new'] , 'click', function() { new_item(this.hostselectbox); });		}		if (widgets['newitem']) {			widgets['newitem'].hostselectbox = box;			widgets['newitem'].disabled = false;			add_event( widgets['newitem'] , 'click', function() { new_subitem(this.hostselectbox); });		}		if (widgets['delete']) {			widgets['delete'].hostselectbox = box;			widgets['delete'].disabled = true;			add_event( widgets['delete'] , 'click', function() { delete_item(this.hostselectbox); });		}		tmp = new Ajax.Request(this.url, opt);	};};/* Extension handling below */	var specialcontext = "default";	Special = Class.create();	Special.prototype = {		initialize: function(name, macro, label) {			this.name = name;			this.macro = macro;			this.label = label;		}	};		Extension = Class.create();	Extension.prototype = {		initialize: function(priority, label, app, appdata) {			this.priority = priority;			this.label = label;			this.app = app;			this.appdata = appdata;		}	}		specials = new Array;	specials.push(		new Special("VoiceMailMain", null, "Check Voicemail"),		new Special("MeetMe", null, "Conference Bridge"),		new Special("Queue", null, "Call Queue")	);	function app2label(app) {		var appo;		if ((appo = findapp(app)))			return appo.label;		return "Custom";	};		function findapp(app) {		for (x=0;x<specials.length;x++) {			if (specials[x].name.toLowerCase() == app.toLowerCase())				return specials[x];		}		return null;	}		function format_extension(box, t, x, multipriority) {		var tmp;		var exten, app, rest, args, label, priority;		if ((t.names[x] != 'exten'))			return null;		tmp = t.fields[x].split(',');		priority = tmp[1];		// if it is a Voicemenu alias .. return "extension -- Voicemenu"		if ( tmp[2].match("Goto") && tmp[2].match("voicemenu-custom-" )  ){			t.subfields[x]['context'] = t.name;			t.subfields[x]['name'] = tmp[0];			t.subfields[x]['app'] = "Goto";			t.subfields[x]['label'] = "Voice Menu";			t.subfields[x]['args'] = "";			t.subfields[x]['priority'] = priority;			box.calcname = tmp[0];			box.calccontext = t.name;			box.calcpriority = priority;			if( sortbynames ){				return " Voice Menu ("  + tmp[0] + ")" ;			}else{				return tmp[0] + " -- Voice Menu"  ;			}		}		//		if (!multipriority && (tmp[1] != '1'))			return null;		exten = tmp[0];		tmp.splice(0,2);		rest = tmp.join(',');		tmp = rest.split('(');		if (!tmp[0])			return null;		app = tmp[0];		label = app2label(app);		tmp.splice(0,1);		args = tmp.join('(');				tmp = args.split(')');		if ((tmp.length > 1) && (!tmp[tmp.length-1].length))			tmp.splice(tmp.length-1, 1);		args = tmp.join(')');				t.subfields[x]['context'] = t.name;		t.subfields[x]['name'] = exten;		t.subfields[x]['app'] = app;		t.subfields[x]['label'] = label;		t.subfields[x]['args'] = args;		t.subfields[x]['priority'] = priority;				if (priority == 'n') {			if ((box.calcname == exten) && (box.calccontext == t.name))				box.calcpriority++;			else				box.calcpriority = 1;		}else if(priority != 's'){			box.calcpriority = priority;		}		t.subfields[x]['realpriority'] = box.calcpriority;		box.calcname = exten;		box.calccontext = t.name;		if( sortbynames ){			return label+" ("  + exten + ")" ;		}else{			return exten + " -- " + label;		}	}	function merge_users(e, u) { // read u and add into e according to sort order	merge_extensions(e, u);}function merge_extensions(u, e) { // read e and add into u according to sort order	var t = e.options.length ;	for( var f =0 ; f < t ; f++ ){		// take each element in e		var opt_new = e.ownerDocument.createElement('option');		opt_new.text = e.options[f].text ;		opt_new.value = 'reserved';		//if( navigator.userAgent.indexOf("Firefox") != -1 ){ opt_new.disabled = true; }		opt_new.style.color = "#ABABAB";		// Now decide where to add in u, and add it to u		var add = 0;		for ( var g=0; g < u.options.length  ; g++) {			if(	opt_new.text < u.options[g].text  ){ // add before this element in u 				add = 1;				try{					u.add(opt_new, u.options[g]);					break;				}catch(err){					u.add(opt_new, g);					break;				}			}		}		if ( add ==0 ){ try{ u.add(opt_new, null); } catch(err){ u.add(opt_new); }}	}}astmanEngine = new Astman();

⌨️ 快捷键说明

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