X-Git-Url: https://dev.renevier.net/?a=blobdiff_plain;f=public%2Fjs%2Futils.js;h=8936797b79db1080f973fde7d49764eeaa44a1be;hb=6633e95b89c1d1eba9b7b0e612becaf11b085d69;hp=aba7b1d1f7aa6ebd91187612b4afba17af77bbd2;hpb=40368091bccafc07d6a580c934b72e963a635b16;p=syj.git diff --git a/public/js/utils.js b/public/js/utils.js index aba7b1d..8936797 100644 --- a/public/js/utils.js +++ b/public/js/utils.js @@ -1,4 +1,4 @@ -/* This file is part of Syj, Copyright (c) 2010 Arnaud Renevier, +/* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier, and is published under the AGPL license. */ var CloseBtn = Class.create({ @@ -212,7 +212,8 @@ Ajax.Responders.register({ // wrapper around Form.request that sets up the submit listener, stops the // submit event, calls presubmit function, calls Form.request and calls a -// postsubmit function +// postsubmit function. If form has some visible and activated file inputs, +// execute presubmit, but do not send the file with ajax. Element.addMethods('form', { ajaxize : function(form, options) { var reqoptions; @@ -220,7 +221,6 @@ Element.addMethods('form', { options = Object.clone(options || {}); $(form).observe('submit', function(evt) { - evt.stop(); // cancel form submission reqoptions = Object.clone(options); delete(reqoptions.presubmit); @@ -229,10 +229,30 @@ Element.addMethods('form', { if (Object.isFunction(options.presubmit)) { if (options.presubmit(this) === false) { + evt.stop(); // cancel form submission return; } } + // get list of input file not disabled, and not hidden + if (this.getInputs('file').find(function(elt) { + if (elt.disabled) { + return false; + } + while (elt && $(elt).identify() !== this.identify()) { + if (!elt.visible()) { + return false; + } + elt = elt.parentNode; + } + return true; + }.bind(this))) { + // form has some file inputs. Do not manage on our own. + return; + } + + evt.stop(); // cancel form submission + var params = reqoptions.parameters, action = this.readAttribute('action') || ''; if (action.blank()) { @@ -395,7 +415,7 @@ Element.addMethods('div', { while (node) { nextNode = node.nextSibling; - if (node.nodeType === 3 || node.tagName.toLowerCase() === 'br') { + if (node.nodeType === 3 || node.tagName.toLowerCase() === 'br' || node.textContent || node.innerText) { div.removeChild(node); } node = nextNode; @@ -408,7 +428,7 @@ Element.addMethods('div', { var node = (div.ownerDocument || document).createTextNode(message); if ($A(div.childNodes).filter(function(node) { - return (node.nodeType === 3 || node.tagName.toLowerCase() === 'br'); + return (node.nodeType === 3 || node.tagName.toLowerCase() === 'br' || node.textContent || node.innerText); }).length) { div.insert(new Element('br')); } @@ -418,10 +438,16 @@ Element.addMethods('div', { }, setMessageStatus: function(div, status) { - return div.removeClassName('error'). - removeClassName('warn'). - removeClassName('info'). - removeClassName('success'). - addClassName(status); + $A(["error", "warn", "info", "success", "optional"]).each(function(clname) { + div.removeClassName(clname); + }); + if (typeof status === "string") { + div.addClassName(status); + } else { + $A(status).each(function(clname) { + div.addClassName(clname); + }); + } + return div; } });