rbrindley: branch 2.0 r4623 - /branches/2.0/config/js/
SVN commits to the Asterisk-GUI project
asterisk-gui-commits at lists.digium.com
Thu Mar 12 10:07:45 CDT 2009
Author: rbrindley
Date: Thu Mar 12 10:07:42 2009
New Revision: 4623
URL: http://svn.digium.com/svn-view/asterisk-gui?view=rev&rev=4623
Log:
- merged latest and greatest from astman_revamp branch
- includes: pbx2.js bug fixes, and pbx.time_intervals integration into timeintervals page
Modified:
branches/2.0/config/js/astman.js
branches/2.0/config/js/pbx2.js
branches/2.0/config/js/timeintervals.js
branches/2.0/config/js/users.js
Modified: branches/2.0/config/js/astman.js
URL: http://svn.digium.com/svn-view/asterisk-gui/branches/2.0/config/js/astman.js?view=diff&rev=4623&r1=4622&r2=4623
==============================================================================
--- branches/2.0/config/js/astman.js (original)
+++ branches/2.0/config/js/astman.js Thu Mar 12 10:07:42 2009
@@ -1561,7 +1561,7 @@
//ASTGUI.miscFunctions.GotoIftime_in_humanReadable( '08:00-17:00,mon-fri,*,*' ) ; // returns a human readable form as ' 8 AM to 5 PM on Monday through Friday'
var WEEKDAYS = {mon: 'Monday', tue: 'Tuesdays', wed: 'Wednesday', thu: 'Thursday', fri: 'Friday', sat:'Saturday', sun:'Sunday'};
- var PIECES = gotoiftime_str.split(',') ;
+ var PIECES = gotoiftime_str.contains(',') ? gotoiftime_str.split(',') : gotoiftime_str.split('|') ;
var toreturn = [];
if( PIECES[0] != '*' ){
toreturn.push( ASTGUI.miscFunctions.asteriskTime_to_AMPM(PIECES[0].split('-')[0]) + ' to ' + ASTGUI.miscFunctions.asteriskTime_to_AMPM(PIECES[0].split('-')[1]) );
Modified: branches/2.0/config/js/pbx2.js
URL: http://svn.digium.com/svn-view/asterisk-gui/branches/2.0/config/js/pbx2.js?view=diff&rev=4623&r1=4622&r2=4623
==============================================================================
--- branches/2.0/config/js/pbx2.js (original)
+++ branches/2.0/config/js/pbx2.js Thu Mar 12 10:07:42 2009
@@ -56,8 +56,8 @@
var ext_conf = new listOfSynActions('extensions.conf');
if (!sessionData.pbxinfo.callingRules.hasOwnProperty(name)) {
- ext_conf.new_action('delcat', name '', ''); /* for good measure :) */
- ext_conf.new_action('newcat', name '', '');
+ ext_conf.new_action('delcat', name, '', ''); /* for good measure :) */
+ ext_conf.new_action('newcat', name, '', '');
sessionData.pbxinfo.callingRules[name] = [];
}
@@ -95,7 +95,7 @@
}
var ext_conf = new listOfSynActions('extensions.conf');
- ext_conf.new_action('update', name, 'exten', edition.lChop('exten='), current.lChop('exten=');
+ ext_conf.new_action('update', name, 'exten', edition.lChop('exten='), current.lChop('exten='));
var resp = ext_conf.callActions();
if (!resp.contains('Response: Success')) {
@@ -203,7 +203,7 @@
var options = line.afterChar('=');
var params = options.betweenXY('|',')');
- if (params.contains('a') && params.contains('A')) [
+ if (params.contains('a') && params.contains('A')) {
exten = ASTGUI.parseContextLine.getArgs(line)[0];
}
@@ -307,7 +307,7 @@
cxt.each(function(line) {
if (!line.beginsWith('exten=')) {
- continue;
+ return;
}
var exten = ASTGUI.parseContextLine.getExten(line);
@@ -346,7 +346,7 @@
if (!name) {
top.log.error('pbx.time_intervals.add: name is empty.');
return false;
- } else if (typeof interval !== 'undefined') {
+ } else if (typeof interval === 'undefined') {
top.log.error('pbx.time_intervals.add: interval is undefined.');
return false;
}
@@ -370,7 +370,7 @@
if (!this.validate.time(interval.time)) {
top.log.error('pbx.time_intervals.add: invalid time.');
return false;
- } else if (!this.validate.weekdays(interval.weekdays)) {
+ } else if (!this.validate.weekday(interval.weekdays)) {
top.log.error('pbx.time_intervals.add: invalid days of the week.');
return false;
} else if (!this.validate.day(interval.days)) {
@@ -388,9 +388,10 @@
+ interval.months.toString();
/* update extensions.conf */
- var ext_conf = new listOfActions('extensions.conf');
-
- var resp = ext_cont.new_action('update', 'globals', name, value);
+ var ext_conf = new listOfSynActions('extensions.conf');
+ ext_conf.new_action('update', 'globals', ASTGUI.contexts.TimeIntervalPrefix + name, value);
+
+ var resp = ext_conf.callActions();
if (!resp.contains('Response: Success')) {
top.log.error('pbx.time_intervals.add: error updating extensions.conf');
return false;
@@ -398,6 +399,94 @@
/* TODO: add new time interval to gui cache */
+ ASTGUI.feedback({ msg: 'Created time interval!', showfor: 3, color: 'green', bgcolor: '#ffffff'});
+ return true;
+};
+
+/**
+ * Edit a Time Interval.
+ * @param oldname Old Name of the Interval.
+ * @param newname New Name of the Interval.
+ * @param interval contains: time, weekdays, days, months
+ * @return boolean on success.
+ */
+pbx.time_intervals.edit = function(oldname, newname, interval) {
+ /* check the basics */
+ if (!name) {
+ top.log.error('pbx.time_intervals.add: name is empty.');
+ return false;
+ } else if (typeof interval !== 'undefined') {
+ top.log.error('pbx.time_intervals.add: interval is undefined.');
+ return false;
+ }
+
+ /* validate the name */
+ if (newname.contains(' ')) {
+ top.log.error('pbx.time_intervals.add: name contains spaces.');
+ return false;
+ }
+
+ /* set defaults. can't loop through members, that assumes they exist. */
+ interval.time = interval.time || '*';
+ interval.weekdays = interval.weekdays || '*';
+ interval.days = interval.days || '*';
+ interval.months = interval.months || '*';
+
+ /* validate all the args */
+ if (!this.validate.time(interval.time)) {
+ top.log.error('pbx.time_intervals.add: invalid time.');
+ return false;
+ } else if (!this.validate.weekday(interval.weekdays)) {
+ top.log.error('pbx.time_intervals.add: invalid days of the week.');
+ return false;
+ } else if (!this.validate.day(interval.days)) {
+ top.log.error('pbx.time_intervals.add: invalid day.');
+ return false;
+ } else if (!this.validate.month(interval.months)) {
+ top.log.error('pbx.time_intervals.add: invalid month.');
+ return false;
+ }
+
+ /* create the time interval string */
+ var value = interval.time.toString() + top.session.delimiter
+ + interval.weekdays.toString() + top.session.delimiter
+ + interval.days.toString() + top.session.delimiter
+ + interval.months.toString();
+
+ /* update extensions.conf */
+ var actions = new listOfSynActions('extensions.conf');
+ actions.new_action('delete', 'globals', ASTGUI.contexts.TimeIntervalPrefix + oldname, '', '');
+
+ var exten_conf = config2json({filename:'extensions.conf', usf:0});
+ for (var cxt in exten_conf) {
+ if (!exten_conf.hasOwnProperty(cxt)) {
+ continue;
+ }
+
+ if (cxt.beginsWith(ASTGUI.contexts.TrunkDIDPrefix) && !cxt.contains('_' + ASTGUI.contexts.TimeInteralPrefix)) {
+ var lines = exten_conf[cxt];
+ lines.each(function(line) {
+ if (line.beginsWith('include=') && line.contains(ASTGUI.contexts.TrunkDIDPrefix) && (line.contains(oldname + ',${') || line.contains(oldname + '|${'))) {
+ actions.new_action('update', cxt, 'include', line.afterChar('=').replaceXY(oldname, newname), line.afterChar('='));
+ }
+ });
+ }
+
+ if (cxt.beginsWith(ASTGUI.contexts.TrunkDIDPrefix) && cxt.endsWith(oldname)) {
+ actions.new_action('renamecat', cxt, '', cxt.replace(oldname, newname));
+ }
+ }
+
+ actions.new_action('update', 'globals', ASTGUI.contexts.TimeIntervalPrefix + newname, value);
+ var resp = actions.callActions();
+ if (!resp.contains('Response: Success')) {
+ top.log.error('pbx.time_intervals.add: error updating extensions.conf');
+ return false;
+ }
+
+ /* TODO: add new time interval to gui cache */
+
+ ASTGUI.feedback({ msg: 'Updated time interval!', showfor: 3, color: 'green', bgcolor: '#ffffff'});
return true;
};
@@ -531,7 +620,7 @@
* Trunks object.
*/
pbx.trunks = {
- trunk_types = ['analog', 'bri', 'iax', 'pri', 'provider', 'sip']
+ trunk_types: ['analog', 'bri', 'iax', 'pri', 'provider', 'sip']
};
/**
@@ -733,7 +822,7 @@
* @param trunk.
* @return provider type.
*/
-pbx.trunks.getProviderType = function(trunk) [
+pbx.trunks.getProviderType = function(trunk) {
if (!sessionData.pbxinfo.trunks.providers.hasOwnProperty(trunk)) {
top.log.error('pbx.trunks.getProviderType: ' + trunk + ' is not a provider.');
return '';
Modified: branches/2.0/config/js/timeintervals.js
URL: http://svn.digium.com/svn-view/asterisk-gui/branches/2.0/config/js/timeintervals.js?view=diff&rev=4623&r1=4622&r2=4623
==============================================================================
--- branches/2.0/config/js/timeintervals.js (original)
+++ branches/2.0/config/js/timeintervals.js Thu Mar 12 10:07:42 2009
@@ -44,85 +44,77 @@
},
update_TI : function(){ // ti_miscFunctions.update_TI();
- var tmp_thisTIName = ASTGUI.getFieldValue('edit_ti_name');
- if( isNewTI ){
- for ( var i in TI_LIST){ if( TI_LIST.hasOwnProperty(i) ){
- if ( i.toLowerCase() == tmp_thisTIName.toLowerCase() ){
- ASTGUI.highlightField('edit_ti_name', "A Time Interval already exists by this name !");
- return;
- }
- }}
- }else{
- for ( var i in TI_LIST ){ if( TI_LIST.hasOwnProperty(i) ){
- if ( EDIT_TI.toLowerCase() != tmp_thisTIName.toLowerCase() && i.toLowerCase() == tmp_thisTIName.toLowerCase() ){
- ASTGUI.highlightField ( 'edit_ti_name', "A Time Interval already exists by this name !" ) ;
- return;
- }
- }}
- }
-
-
- var ti_name = ASTGUI.contexts.TimeIntervalPrefix + tmp_thisTIName ;
- var ti_time_str = ''; // tmp_timerange + tmp_daysofweek + tmp_daysofmonth + tmp_months
- if( _$('edit_ti_entireday').checked ){
- var tmp_timerange = '*' ;
- }else{
- var tmp_timerange = ASTGUI.miscFunctions.AMPM_to_asteriskTime( _$('edit_ti_starttime').value ) + '-' + ASTGUI.miscFunctions.AMPM_to_asteriskTime( _$('edit_ti_endtime').value ) ;
- }
-
- if( _$('ti_type_byDayofWeek').checked ){
- var tmp_daysofweek = _$('edit_ti_dayofweek_start').value + '-' + _$('edit_ti_dayofweek_end').value ;
- var tmp_daysofmonth = '*' ;
- var tmp_months = '*';
- }else{
- var tmp_daysofweek = '*' ;
- }
-
- if( _$('ti_type_byGroupofDates').checked ){
- var tmp_daysofmonth = _$('edit_ti_from_date').value ;
-
- if ( ! ti_miscFunctions.check_ifDatesAreValid(tmp_daysofmonth) ) {
- ASTGUI.highlightField('edit_ti_from_date', "Invalid Date range !");
- return;
- }
-
- var tmp_months = _$('edit_ti_month').value ;
- }
-
- ti_time_str = tmp_timerange + parent.session.delimiter + tmp_daysofweek + parent.session.delimiter + tmp_daysofmonth + parent.session.delimiter + tmp_months ;
-
- var u = new listOfActions('extensions.conf') ;
- if( isNewTI == false ){
- var OLD_TI = ASTGUI.contexts.TimeIntervalPrefix + EDIT_TI; // timeinterval_'edit_ti'
- u.new_action( 'delete' , 'globals' , OLD_TI , '','' ) ;
- ////////////////////////////////////
- var EXT_CNF = config2json({filename:'extensions.conf', usf:0 }) ;
- for( var ct in EXT_CNF){ if( EXT_CNF.hasOwnProperty(ct) ){
- // update any lines in any [DID_Trunkx] that are like "include = DID_trunkx_timeinterval_'a', ..."
- if( ct.beginsWith(ASTGUI.contexts.TrunkDIDPrefix) && !ct.contains( '_' + ASTGUI.contexts.TimeIntervalPrefix ) ){
- var this_trunk_mainDID = EXT_CNF[ct] ;
- this_trunk_mainDID.each(function(this_line){
- if( this_line.beginsWith('include=') && this_line.contains(ASTGUI.contexts.TrunkDIDPrefix) && this_line.contains( OLD_TI + parent.session.delimiter + '${' ) ){
- u.new_action( 'update' , ct , 'include' , this_line.afterChar('=').replaceXY(OLD_TI,ti_name) , this_line.afterChar('=') ) ;
- }
- });
- }
- // rename any contexts that are like [DID_trunkx_timeinterval_a]
- if( ct.beginsWith(ASTGUI.contexts.TrunkDIDPrefix) && ct.endsWith( OLD_TI ) ){
- u.new_action( 'renamecat', ct , "", ct.replace(OLD_TI, ti_name)) ;
- }
- }}
- }
-
- u.new_action( 'update' , 'globals' , ti_name , ti_time_str );
- u.callActions( function(){
- if( isNewTI == false ){
- ASTGUI.feedback( { msg:"Updated time interval !", showfor: 3, color:'green', bgcolor:'#FFFFFF' } );
- }else{
- ASTGUI.feedback( { msg:"created time interval '" + tmp_thisTIName + "' !", showfor: 3, color:'green', bgcolor:'#FFFFFF' } );
- }
- window.location.reload();
- });
+ var newname = $('#edit_ti_name').val();
+
+ if (newname === '') {
+ ASTGUI.highlightField('edit_ti_name', 'Time Interval name is empty');
+ }
+
+ for (var ti in TI_LIST) {
+ if (!TI_LIST.hasOwnProperty(ti)) {
+ continue;
+ }
+
+ if (isNewTI && ti.toLowerCase() === newname.toLowerCase()) {
+ ASTGUI.highlightField('edit_ti_name', 'A Time Interval already exists by this name!');
+ return;
+ }
+
+ if (!isNewTI && EDIT_TI.toLowerCase() !== newname.toLowerCase() && ti.toLowerCase() === newname.toLowerCase()) {
+ ASTGUI.highlightField('edit_ti_name', 'A Time Interval already exists by this name!');
+ return;
+ }
+ }
+
+ var interval = {};
+ interval.time = '*';
+ interval.weekdays = '*';
+ interval.days = '*';
+ interval.months = '*';
+
+ /* if 'Entire Day' isn't checked */
+ if (!$('#edit_ti_entireday:checked').length) {
+ var start = $('#edit_ti_starttime').val();
+ var end = $('#edit_ti_endtime').val();
+
+ var starttime = ASTGUI.miscFunctions.AMPM_to_asteriskTime(start) || '00:00';
+ var endtime = ASTGUI.miscFunctions.AMPM_to_asteriskTime(end) || '24:00';
+
+ if (starttime !== '00:00' || endtime !== '24:00') {
+ interval.time = starttime + '-' + endttime;
+ }
+ }
+
+ if (!$('#edit_ti_byDayofWeek:selected').length) {
+ interval.weekdays = $('#edit_ti_dayofweek_start').val() + '-' + $('#edit_ti_dayofweek_end').val();
+ }
+
+ if ($('#ti_type_byGroupofDates:selected').length) {
+ interval.days = $('#edit_ti_from_date').val();
+
+ if (!interval.days.valiDate()) {
+ ASTGUI.highlightField('edit_ti_from_date', 'Invalid Date Range!');
+ return;
+ }
+
+ interval.months = $('#edit_ti_month').val();
+ }
+
+ if (isNewTI) {
+ var resp = parent.pbx.time_intervals.add(newname, interval);
+ } else {
+ var resp = parent.pbx.time_intervals.edit(EDIT_TI, newname, interval);
+ }
+
+ if (!resp) {
+ top.log.error('Error updating Time Interval');
+ ASTGUI.feedback({ msg: 'ERROR UPDATING!', showfor: 3, color: 'red', bgcolor: '#ffffff'});
+ return;
+ }
+
+ ASTGUI.feedback({ msg: "Created time interval '" + newname + "'!", showfor: 3, color:'green', bgcolor:'#FFFFFF'});
+ window.location.reload();
+
},
delete_TI : function(a){ // ti_miscFunctions.delete_TI
Modified: branches/2.0/config/js/users.js
URL: http://svn.digium.com/svn-view/asterisk-gui/branches/2.0/config/js/users.js?view=diff&rev=4623&r1=4622&r2=4623
==============================================================================
--- branches/2.0/config/js/users.js (original)
+++ branches/2.0/config/js/users.js Thu Mar 12 10:07:42 2009
@@ -462,7 +462,7 @@
};
var newuser_settings = ASTGUI.toCustomObject( { fullname : ASTGUI.getFieldValue('edit_fullname'), registersip: 'no', host: 'dynamic', callgroup : '1' } );
parent.ASTGUI.dialog.waitWhile(' Saving... ');
- parent.pbx.users.add( NU_EXT, newuser_settings, cb);
+ top.pbx.users.add( NU_EXT, newuser_settings, cb);
return;
}else{
///////////////////
More information about the asterisk-gui-commits
mailing list