rbrindley: branch rbrindley/astman_revamp r4607 - /team/rbrindley/astman_reva...
SVN commits to the Asterisk-GUI project
asterisk-gui-commits at lists.digium.com
Wed Mar 11 12:05:49 CDT 2009
Author: rbrindley
Date: Wed Mar 11 12:05:46 2009
New Revision: 4607
URL: http://svn.digium.com/svn-view/asterisk-gui?view=rev&rev=4607
Log:
- implemented pbx.time_intervals.validate.time, look at the switch fun!
Modified:
team/rbrindley/astman_revamp/config/js/pbx2.js
Modified: team/rbrindley/astman_revamp/config/js/pbx2.js
URL: http://svn.digium.com/svn-view/asterisk-gui/team/rbrindley/astman_revamp/config/js/pbx2.js?view=diff&rev=4607&r1=4606&r2=4607
==============================================================================
--- team/rbrindley/astman_revamp/config/js/pbx2.js (original)
+++ team/rbrindley/astman_revamp/config/js/pbx2.js Wed Mar 11 12:05:46 2009
@@ -334,6 +334,64 @@
*/
pbx.time_intervals = {};
+/**
+ * Validater object.
+ * Holds members funcs that validate various formats
+ * needed for time_intervals.
+ */
+pbx.time_intervals.validate = {};
+
+/**
+ * Validates Time format.
+ * @param time The time to be checked.
+ * @return boolean on valid format.
+ */
+pbx.time_intervals.validate.time = function (time) {
+ if (time === '*') {
+ /* this condition was separated from the switch
+ * because its the one condition that doesn't
+ * verify 00:00-00:00 format */
+ return true;
+ }
+
+ var splits = time.split('-');
+ var start = splits[0];
+ var end = splits[1];
+ splits = start.split(':');
+ var start_hr = splits[0];
+ var start_min = splits[1];
+ var i_start_hr = parseInt(start_hr, 10);
+ var i_start_min = parseInt(start_min, 10);
+ splits = end.split(':');
+ var end_hr = splits[0];
+ var end_min = splits[1];
+ var i_end_hr = parseInt(end_hr, 10);
+ var i_end_min = parseInt(end_min, 10);
+
+ switch(true) {
+ case (time === ''):
+ case (time.length !== 11):
+ case (start_hr.length !== 2):
+ case (start_min.length !== 2):
+ case (end_hr.length !== 2):
+ case (end_min.length !== 2):
+ case (i_start_hr < 0):
+ case (i_start_hr > 24):
+ case (i_start_min < 0):
+ case (i_start_min > 60):
+ case (i_end_hr < 0):
+ case (i_end_hr > 24):
+ case (i_end_min < 0):
+ case (i_end_min > 60):
+ case (i_start_hr*60 + i_start_min > i_end_hr*60 + i_end_min):
+ case (i_start_hr === 24 && i_start_min > 0):
+ case (i_end_hr === 24 && i_start_min > 0):
+ return false;
+ default:
+ return true;
+ }
+};
+
/*---------------------------------------------------------------------------*/
/**
* Trunks object.
More information about the asterisk-gui-commits
mailing list