X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2Fresources%2Fwebform.js;h=11c5682f33455cc4885a7697d79d361ad1630cfd;hb=26e133c6499135531a32a75bf3bdc6876000f14d;hp=998b503193295c0bca079d469228300ff99f734e;hpb=3d357ffc844536f1ac9b2a36d4b4e3b224aceb6b;p=mono.git diff --git a/mcs/class/System.Web/resources/webform.js b/mcs/class/System.Web/resources/webform.js index 998b5031932..11c5682f334 100644 --- a/mcs/class/System.Web/resources/webform.js +++ b/mcs/class/System.Web/resources/webform.js @@ -4,6 +4,7 @@ * Authors: * Chris Toshok (toshok@ximian.com) * Lluis Sanchez Gual (lluis@novell.com) + * Igor Zelmanovich (igorz@mainsoft.com) * * (c) 2005 Novell, Inc. (http://www.novell.com) * @@ -27,18 +28,19 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +function WebForm_Initialize(webForm) { -function WebForm_AutoFocus (id) +webForm.WebForm_AutoFocus = function (id) { - var x = WebForm_GetElementById (id); + var x = this.WebForm_GetElementById (id); - if (x && (!WebForm_CanFocus(x))) { - x = WebForm_FindFirstFocusableChild(x); + if (x && (!this.WebForm_CanFocus(x))) { + x = this.WebForm_FindFirstFocusableChild(x); } if (x) { x.focus(); } } -function WebForm_CanFocus(element) { +webForm.WebForm_CanFocus = function (element) { if (!element || !(element.tagName) || element.disabled) { return false; } @@ -53,7 +55,7 @@ function WebForm_CanFocus(element) { tagName == "a"); } -function WebForm_FindFirstFocusableChild(element) { +webForm.WebForm_FindFirstFocusableChild = function (element) { if (!element || !(element.tagName)) { return null; } @@ -65,12 +67,12 @@ function WebForm_FindFirstFocusableChild(element) { if (children) { for (var i = 0; i < children.length; i++) { try { - if (WebForm_CanFocus(children[i])) { + if (this.WebForm_CanFocus(children[i])) { return children[i]; } else { - var focused = WebForm_FindFirstFocusableChild(children[i]); - if (WebForm_CanFocus(focused)) { + var focused = this.WebForm_FindFirstFocusableChild(children[i]); + if (this.WebForm_CanFocus(focused)) { return focused; } } @@ -81,65 +83,179 @@ function WebForm_FindFirstFocusableChild(element) { return null; } -function wasControlEnabled (id) +webForm.WebForm_ReEnableControls = function () { - if (typeof (__enabledControlArray) == 'undefined') + if (typeof(this._form.__enabledControlArray) != 'undefined' && this._form.__enabledControlArray != null) + __enabledControlArray = this._form.__enabledControlArray; + + if (typeof(__enabledControlArray) == 'undefined' || __enabledControlArray == null) return false; + + this._form.__disabledControlArray = new Array(); + for (var i = 0; i < __enabledControlArray.length; i++) { + var c = this.WebForm_GetElementById (__enabledControlArray[i]); + if ((typeof(c) != "undefined") && (c != null) && (c.disabled == true)) { + c.disabled = false; + this._form.__disabledControlArray[this._form.__disabledControlArray.length] = c; + } + } + setTimeout((this._instanceVariableName ? this._instanceVariableName + "." : "") + "WebForm_ReDisableControls ()", 0); + return true; +} - for (var i = 0; i < __enabledControlArray.length; i ++) { - if (id == __enabledControlArray[i]) - return true; +webForm.WebForm_ReDisableControls = function () +{ + for (var i = 0; i < this._form.__disabledControlArray.length; i++) { + this._form.__disabledControlArray[i].disabled = true; } +} - return false; +// This function is only used in the context of TARGET_J2EE for portlets +webForm.PortalWebForm_DoPostback = function (id, par, url, apb, pval, tf, csubm, vg) +{ + if (url != null) { + if (url.indexOf ("vmw.action.page=") == 0) { + this._form.__NEXTVMWACTIONPAGE.value = url.substring ("vmw.action.page=".length); + url = this._form.action; + } + else if (url.indexOf ("vmw.render.page=") == 0) + { + this._form.__NEXTVMWRENDERPAGE.value = url.substring ("vmw.render.page=".length); + this._form.submit (); + return; + } + } + return this.WebForm_DoPostback (id, par, url, apb, pval, tf, csubm, vg); } +webForm.WebForm_DoPostback = function (id, par, url, apb, pval, tf, csubm, vg) +{ + var validationResult = true; + if (pval && typeof(this.Page_ClientValidate) == "function") + validationResult = this.Page_ClientValidate(vg); -function WebForm_ReEnableControls (currForm) + if (validationResult) { + if ((typeof(url) != "undefined") && (url != null) && (url.length > 0)) + this._form.action = url; + if (tf) { + var lastFocus = this._form.elements["__LASTFOCUS"]; + if ((typeof(lastFocus) != "undefined") && (lastFocus != null)) + lastFocus.value = id; + } + } + if (csubm) + this.__doPostBack (id, par); +} + +webForm.WebForm_DoCallback = function (id, arg, callback, ctx, errorCallback, useAsync) { - currForm = currForm || theForm; - if (typeof (currForm) == 'undefined') - return; + var qs = this.WebForm_getFormData () + "__CALLBACKTARGET=" + id + "&__CALLBACKARGUMENT=" + encodeURIComponent(arg); + + if (this._form["__EVENTVALIDATION"]) + qs += "&__EVENTVALIDATION=" + encodeURIComponent(this._form["__EVENTVALIDATION"].value); + + var This = this; + this.WebForm_httpPost (this._form.serverURL || document.URL, qs, function (httpPost) { This.WebForm_ClientCallback (httpPost, ctx, callback, errorCallback); }); +} - for (var i = 0; i < currForm.childNodes.length; i ++) { - var node = currForm.childNodes[i]; - if (node.disabled && wasControlEnabled (node.id)) - node.disabled = false; +webForm.WebForm_ClientCallback = function (httpPost, ctx, callback, errorCallback) +{ + var doc = httpPost.responseText; + if (doc.charAt(0) == "e") { + if ((typeof(errorCallback) != "undefined") && (errorCallback != null)) + errorCallback(doc.substring(1), ctx); + } else { + var separatorIndex = doc.indexOf("|"); + if (separatorIndex != -1) { + var validationFieldLength = parseInt(doc.substring(0, separatorIndex)); + if (!isNaN(validationFieldLength)) { + var validationField = doc.substring(separatorIndex + 1, separatorIndex + validationFieldLength + 1); + if (validationField != "") { + var validationFieldElement = this._form["__EVENTVALIDATION"]; + if (!validationFieldElement) { + validationFieldElement = document.createElement("INPUT"); + validationFieldElement.type = "hidden"; + validationFieldElement.name = "__EVENTVALIDATION"; + validationFieldElement.id = validationFieldElement.name; + this._form.appendChild(validationFieldElement); + } + validationFieldElement.value = validationField; + } + if ((typeof(callback) != "undefined") && (callback != null)) + callback (doc.substring(separatorIndex + validationFieldLength + 1), ctx); + } + } else { + if ((typeof(callback) != "undefined") && (callback != null)) + callback (doc, ctx); + } } } -function WebForm_DoPostback (ctrl, par, url, apb, pval, tf, csubm, vg) +webForm.WebForm_getFormData = function () { - if (pval && typeof(Page_ClientValidate) == "function" && !Page_ClientValidate(vg)) - return; - - var form = WebForm_GetFormFromCtrl (ctrl); - if (url != null) - form.action = url; - - if (csubm) - __doPostBack (ctrl, par); + var qs = ""; + var len = this._form.elements.length; + for (n=0; n