X-Git-Url: https://svn.cri.ensmp.fr/git/Plinn.git/blobdiff_plain/99afe0ce8700bf835ff7bbedf77bb46e58f996d8..32790bb004595659d409365e0e93e785a8b26cde:/skins/ajax_scripts/ajax_form_manager.js?ds=sidebyside diff --git a/skins/ajax_scripts/ajax_form_manager.js b/skins/ajax_scripts/ajax_form_manager.js index f9dace2..d91c440 100644 --- a/skins/ajax_scripts/ajax_form_manager.js +++ b/skins/ajax_scripts/ajax_form_manager.js @@ -4,9 +4,12 @@ // // +var FormManager; -function FormManager(form, responseTextDest, lazy) { - if (form.elements.namedItem("noAjax")) return; +(function(){ + +FormManager = function(form, responseTextDest, lazy) { + if (form.elements.namedItem("noAjax")) {return;} this.form = form; this.responseTextDest = responseTextDest; @@ -26,21 +29,20 @@ function FormManager(form, responseTextDest, lazy) { this.submitButton = null; if (this.lazy) { - this.fieldTagName; - this.liveFormField; - this.pendingEvent; this.form.onclick = function(evt){ thisManager.replaceElementByField(evt); thisManager.click(evt); }; - if (browser.isDOM2Event) + if (browser.isDOM2Event) { this.form.onfocus = this.form.onclick; - else if (browser.isIE6up) + } + else if (browser.isIE6up) { this.form.onfocusin = this.form.onclick; + } this.onResponseLoad = function(req){ thisManager.restoreField(req); }; - this.lazyListeners = new Array(); + this.lazyListeners = []; } -} +}; FormManager.prototype.submit = function(evt) { var form = this.form; @@ -50,16 +52,18 @@ FormManager.prototype.submit = function(evt) { if (!this.onBeforeSubmit) { var onBeforeSubmit = form.elements.namedItem("onBeforeSubmit"); if (onBeforeSubmit) { - if (onBeforeSubmit.length) + if (onBeforeSubmit.length) { onBeforeSubmit = onBeforeSubmit[0]; + } this.onBeforeSubmit = eval(onBeforeSubmit.value); bsMessage = this.onBeforeSubmit(thisManager, evt); } } - else + else { bsMessage = this.onBeforeSubmit(thisManager, evt); + } - if (bsMessage == 'cancelSubmit') { + if (bsMessage === 'cancelSubmit') { try {disableDefault(evt);} catch (e){} return; @@ -67,41 +71,48 @@ FormManager.prototype.submit = function(evt) { if (!this.onResponseLoad) { var onResponseLoad = form.elements.namedItem("onResponseLoad"); - if (onResponseLoad) + if (onResponseLoad) { this.onResponseLoad = eval(onResponseLoad.value); - else + } + else { this.onResponseLoad = this.loadResponse; + } } var submitButton = this.submitButton; var queryInfo = this.formData2QueryString(); - var query = queryInfo['query']; - this.hasFile = queryInfo['hasFile']; + var query = queryInfo.query; + this.hasFile = queryInfo.hasFile; if (!this.onAfterPopulate) { var onAfterPopulate = form.elements.namedItem("onAfterPopulate"); - if (onAfterPopulate) + if (onAfterPopulate) { this.onAfterPopulate = onAfterPopulate.value; - else + } + else { this.onAfterPopulate = function() {}; + } } if (submitButton) { query += submitButton.name + '=' + submitButton.value + '&'; } - if (window.AJAX_CONFIG && (AJAX_CONFIG & 1 == 1)) { - if (form.method.toLowerCase() == 'post') + if (window.AJAX_CONFIG && (AJAX_CONFIG & 1 === 1)) { + if (form.method.toLowerCase() === 'post') { this._post(query); - else - this._get(query) + } + else { + this._get(query); + } } - else + else { this._post(query); + } try {disableDefault(evt);} - catch (e){} + catch (e2){} }; FormManager.prototype._post = function(query) { @@ -117,11 +128,14 @@ FormManager.prototype._post = function(query) { break; case 4 : hideProgressImage(); - if (req.status == 200 || req.status == 204) + if (req.status === 200 || req.status === 204) { thisManager.onResponseLoad(req); - else + } + else { alert('Error: ' + req.status); - }; + } + break; + } }; var url = this.form.action; req.open("POST", url, true); @@ -132,14 +146,14 @@ FormManager.prototype._post = function(query) { FormManager.prototype._get = function(query) { // send form by browser location var url = this.form.action; - url += '?' + query + url += '?' + query; linkHandler.loadUrl(url); }; FormManager.prototype.click = function(evt) { var target = getTargetedObject(evt); - if(target.type == "submit" || target.type == "image") { + if(target.type === "submit" || target.type === "image") { this.submitButton = target; disablePropagation(evt); } @@ -149,9 +163,10 @@ FormManager.prototype.replaceElementByField = function(evt) { evt = getEventObject(evt); var ob = getTargetedObject(evt); var eventType = evt.type; - if (eventType == 'focus' || eventType == 'focusin') { - if (this.liveFormField && ob.tagName != 'INPUT') + if (eventType === 'focus' || eventType === 'focusin') { + if (this.liveFormField && ob.tagName !== 'INPUT') { this.pendingEvent = [ob, 'click']; + } return; } var fieldName = ob.getAttribute('id'); @@ -159,11 +174,15 @@ FormManager.prototype.replaceElementByField = function(evt) { this.fieldTagName = ob.tagName; var tabIndex = ob.tabIndex; var text; - if (ob.firstChild && ob.firstChild.className == 'hidden_value') + if (ob.firstChild && ob.firstChild.className === 'hidden_value') { text = ob.firstChild.innerHTML; - else + } + else { text = ob.innerHTML; + } disablePropagation(evt); + var parent; + thisManager = this; switch (ob.tagName) { case 'SPAN' : // create input element @@ -180,7 +199,7 @@ FormManager.prototype.replaceElementByField = function(evt) { //inputText.setAttribute("size", text.length); // replacement - var parent = ob.parentNode; + parent = ob.parentNode; parent.replaceChild(inputText, ob); inputText.focus(); @@ -189,7 +208,6 @@ FormManager.prototype.replaceElementByField = function(evt) { inputText.tabIndex = tabIndex; inputText.className = 'live_field'; this.liveFormField = inputText; - var thisManager = this; this.lazyListeners.push({'element': inputText, 'eventName' : 'blur', 'handler': function(){ thisManager.submit();}}); this.lazyListeners.push({'element': inputText, 'eventName' : 'keypress', 'handler': function(evt){ thisManager._fitField(evt);}}); this._addLazyListeners(); @@ -206,7 +224,7 @@ FormManager.prototype.replaceElementByField = function(evt) { ta.value = text; // replacement - var parent = ob.parentNode; + parent = ob.parentNode; parent.replaceChild(ta, ob); ta.focus(); @@ -214,27 +232,26 @@ FormManager.prototype.replaceElementByField = function(evt) { ta.setAttribute('name', fieldName); ta.tabIndex = tabIndex; this.liveFormField = ta; - var thisManager = this; this.lazyListeners.push({'element': ta, 'eventName' : 'blur', 'handler': function(){ thisManager.submit();}}); this._addLazyListeners(); break; - - - }; + } } }; FormManager.prototype._addLazyListeners = function() { - for (var i=0 ; i