Allowed optional long timeout on defualt/cancel/selector buttons.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 6 Jun 2010 20:12:26 +0000 (20:12 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 6 Jun 2010 20:12:26 +0000 (20:12 +0000)
includes/ui/ui_input.inc
js/behaviour.js
js/inserts.js

index 9ae6088227e020f591a946a4fef080235f3d8b39..391cd7fc5a4e0952b10ee5878ce842478e23f39e 100644 (file)
@@ -107,35 +107,43 @@ function hidden($name, $value=null, $echo=true)
                null  - button visible only in fallback mode; optional icon
         Ajax submit:
                true      - standard button; optional icon
-               'process' - displays progress bar during call; optional icon
+
                'default' - default form submit on Ctrl-Enter press; dflt ICON_OK icon
                'selector' - ditto with closing current popup editor window
                'cancel'  - cancel form entry on Escape press; dflt ICON_CANCEL
+               'process' - displays progress bar during call; optional icon
+
+       $atype can contain also multiply type selectors separated by space, 
+       however make sense only combination of 'process' and one of defualt/selector/cancel
 */
 function submit($name, $value, $echo=true, $title=false, $atype=false, $icon=false)
 {
        global $path_to_root;
 
        $aspect='';
-       if (!is_bool($atype)) // necessary: switch uses '=='
-         switch($atype) {
-               case 'process':
-                       $aspect = " aspect='process'"; break;
-               case 'selector':
-                       $aspect = " aspect='selector' rel = '$value'"; 
-                       $value = _("Select");
-                       if ($icon===false) $icon=ICON_SUBMIT; break;
-               case 'default':
-                       $aspect = " aspect='default'"; 
-                       if ($icon===false) $icon=ICON_SUBMIT; break;
-               case 'cancel':
-                       $aspect = " aspect='cancel'"; 
-                       if ($icon===false) $icon=ICON_ESCAPE; break;
-               case null: 
-                       $aspect = fallback_mode() ? 
-                               " aspect='fallback'" : " style='display:none;'"; break;
-        }
+       if ($atype === null) {
+               $aspect = fallback_mode() ? " aspect='fallback'" : " style='display:none;'";
+
+       } elseif (!is_bool($atype)) { // necessary: switch uses '=='
+
+               $aspect = "aspect='$atype' ";
+               $types = explode(' ', $atype);
 
+               foreach ($types as $type) {
+                       switch($type) {
+                               case 'selector':
+                                       $aspect = " aspect='selector' rel = '$value'"; 
+                                       $value = _("Select");
+                                       if ($icon===false) $icon=ICON_SUBMIT; break;
+
+                               case 'default':
+                                       if ($icon===false) $icon=ICON_SUBMIT; break;
+
+                               case 'cancel':
+                                       if ($icon===false) $icon=ICON_ESCAPE; break;
+                       }
+               }
+       }
        $submit_str = "<button class=\""
            .($atype ? 'ajaxsubmit' : 'inputsubmit')
                ."\" type=\"submit\""
index a5ed0480fa74a9b3845fe734b11c79f95672de0d..b225ca204f76609385c51aa0af0dc49f0e1213fa 100644 (file)
@@ -200,19 +200,19 @@ document.getElementsBySelector = function(selector) {
           checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
           break;
         case '~': // Match one of space seperated words 
-          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
+          checkFunction = function(e) { var a=e.getAttribute(attrName); return (a && a.match(new RegExp('\\b'+attrValue+'\\b'))); };
           break;
         case '|': // Match start with value followed by optional hyphen
-          checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
+          checkFunction = function(e) { var a=e.getAttribute(attrName); return (a && a.match(new RegExp('^'+attrValue+'-?'))); };
           break;
         case '^': // Match starts with value
-          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
+          checkFunction = function(e) { var a=e.getAttribute(attrName); return (a && a.indexOf(attrValue) == 0); };
           break;
         case '$': // Match ends with value - fails with "Warning" in Opera 7
-          checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
+          checkFunction = function(e) { var a=e.getAttribute(attrName); return (a && a.lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
           break;
-        case '*': // Match ends with value
-          checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
+        case '*': // Match contains value
+          checkFunction = function(e) { var a=e.getAttribute(attrName); return (a && a.indexOf(attrValue) > -1); };
           break;
         default :
           // Just test for existence of attribute
index d7fa75353de37f0865a5dfaf3e9a627b1f03552e..6d8b1ff71caad6a1284010a4d3941f02686edd27 100644 (file)
@@ -213,10 +213,11 @@ var inserts = {
        function(e) {
                    e.onclick = function() {
                            save_focus(e);
-                                       if (e.getAttribute('aspect') == 'process')
-                                               JsHttpRequest.request(this, null, 60000);
-                                       else
-                                               JsHttpRequest.request(this);
+                           var asp = e.getAttribute('aspect')
+                               if (asp && asp.indexOf('process') !== -1)
+                                       JsHttpRequest.request(this, null, 60000);
+                               else
+                                       JsHttpRequest.request(this);
                                return false;
                    }
        },
@@ -258,7 +259,7 @@ var inserts = {
                                }
                        }
        },
-       'button[aspect=selector], input[aspect=selector]': function(e) {
+       'button[aspect*selector], input[aspect*selector]': function(e) {
                e.onclick = function() {
                        passBack(this.getAttribute('rel'));
                        return false;
@@ -277,7 +278,7 @@ var inserts = {
        'a.printlink':  function(l) {
                l.onclick = function() {
                    save_focus(this);
-                       JsHttpRequest.request(this);
+                       JsHttpRequest.request(this, null, 60000);
                        return false;
                }
        },
@@ -386,13 +387,19 @@ function setHotKeys() {
                                for (var i=0; i<form.elements.length; i++){
                                        var el = form.elements[i];
                                        var asp = el.getAttribute('aspect');
-                                       if (el.className!='editbutton' && asp=='selector' && (key==13 || key==27)) {
+                                       
+
+                                       if (el.className!='editbutton' && (asp && asp.indexOf('selector') !== -1) && (key==13 || key==27)) {
                                                passBack(key==13 ? el.getAttribute('rel') : false);
                                                ev.returnValue = false;
                                                return false;
                                        }
-                                       if ((asp=='default' && key==13)||(asp=='cancel' && key==27)) {
-                                               JsHttpRequest.request(el);
+                                       if (((asp && asp.indexOf('default') !== -1) && key==13)||((asp && asp.indexOf('cancel') !== -1) && key==27)) {
+
+                                               if (asp.indexOf('process') !== -1)
+                                                       JsHttpRequest.request(el, null, 60000);
+                                               else
+                                                       JsHttpRequest.request(el);
                                                ev.returnValue = false;
                                                return false;
                                        }