luci-base: add extra css class for map level tabs, don't track tab child count
[project/luci.git] / modules / luci-base / htdocs / luci-static / resources / cbi.js
index 8159a37..15645d9 100644 (file)
@@ -344,6 +344,47 @@ var cbi_validators = {
        'phonedigit': function()
        {
                return (this.match(/^[0-9\*#!\.]+$/) != null);
+       },
+        'timehhmmss': function()
+       {
+               return (this.match(/^[0-6][0-9]:[0-6][0-9]:[0-6][0-9]$/) != null);
+       },
+       'dateyyyymmdd': function()
+       {
+               if (this == null) {
+                       return false;
+               }
+               if (this.match(/^(\d\d\d\d)-(\d\d)-(\d\d)/)) {
+                       var year = RegExp.$1;
+                       var month = RegExp.$2;
+                       var day = RegExp.$2
+
+                       var days_in_month = [ 31, 28, 31, 30, 31, 30, 31, 31, 30 , 31, 30, 31 ];
+                       function is_leap_year(year) {
+                               return ((year % 4) == 0) && ((year % 100) != 0) || ((year % 400) == 0);
+                       }
+                       function get_days_in_month(month, year) {
+                               if ((month == 2) && is_leap_year(year)) {
+                                       return 29;
+                               } else {
+                                       return days_in_month[month];
+                               }
+                       }
+                       /* Firewall rules in the past don't make sense */
+                       if (year < 2015) {
+                               return false;
+                       }
+                       if ((month <= 0) || (month > 12)) {
+                               return false;
+                       }
+                       if ((day <= 0) || (day > get_days_in_month(month, year))) {
+                               return false;
+                       }
+                       return true;
+
+               } else {
+                       return false;
+               }
        }
 };
 
@@ -434,7 +475,7 @@ function cbi_d_update() {
                if (node && node.parentNode && !cbi_d_check(entry.deps)) {
                        node.parentNode.removeChild(node);
                        state = true;
-                       if( entry.parent )
+                       if( entry.parent && typeof(cbi_c[entry.parent]) == 'number')
                                cbi_c[entry.parent]--;
                } else if ((!node || !node.parentNode) && cbi_d_check(entry.deps)) {
                        if (!next) {
@@ -443,7 +484,7 @@ function cbi_d_update() {
                                next.parentNode.insertBefore(entry.node, next);
                        }
                        state = true;
-                       if( entry.parent )
+                       if( entry.parent && typeof(cbi_c[entry.parent]) == 'number' )
                                cbi_c[entry.parent]++;
                }
        }
@@ -894,7 +935,10 @@ function cbi_t_update() {
        for( var sid in cbi_t )
                for( var tid in cbi_t[sid] )
                {
-                       if( cbi_c[cbi_t[sid][tid].cid] == 0 ) {
+                       if (typeof(cbi_c[cbi_t[sid][tid].cid]) !== 'number') {
+                               continue;
+                       }
+                       else if( cbi_c[cbi_t[sid][tid].cid] == 0 ) {
                                cbi_t[sid][tid].tab.style.display = 'none';
                        }
                        else if( cbi_t[sid][tid].tab && cbi_t[sid][tid].tab.style.display == 'none' ) {