From a0ba7a2196cf4379c1772d36aeaf899b2cf47752 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Thu, 24 Oct 2013 23:45:36 +0200 Subject: More work on ajax --- editors/NotepadPlus/4.x/prado.api | 5 - .../source/prado/activecontrols/activecontrols3.js | 16 + .../source/prado/activecontrols/ajax3.js | 454 +++++++-------------- framework/Web/Javascripts/source/prado/prado.js | 33 +- .../UI/ActiveControls/TActiveControlAdapter.php | 20 - .../Web/UI/ActiveControls/TActiveImageButton.php | 12 - framework/Web/UI/ActiveControls/TActiveListBox.php | 6 - .../UI/ActiveControls/TCallbackClientScript.php | 5 - framework/Web/UI/TControl.php | 10 - framework/Web/UI/TPage.php | 26 -- framework/Web/UI/WebControls/TDatePicker.php | 8 - framework/Web/UI/WebControls/TRadioButton.php | 10 - tests/unit/Web/UI/TPageTest.php | 8 - 13 files changed, 175 insertions(+), 438 deletions(-) diff --git a/editors/NotepadPlus/4.x/prado.api b/editors/NotepadPlus/4.x/prado.api index 6a990ba4..b73c9a92 100644 --- a/editors/NotepadPlus/4.x/prado.api +++ b/editors/NotepadPlus/4.x/prado.api @@ -719,7 +719,6 @@ PostBackOptions PostBackParameter PostBackTarget PostBackValue -PostDataLoaders PostState Prado::autoload Prado::createComponent @@ -1326,7 +1325,6 @@ addMappedStatement addNode addParameterMap addParsedObject -addPostDataLoader addProperty addResultMap addResultMapGroupBy @@ -1336,7 +1334,6 @@ addStatesToTrack addStyleAttribute addStyleAttributes addSubMap -addToPostDataLoader addValue addedControl addedWizardStep @@ -2186,7 +2183,6 @@ registerHiddenField registerJavascriptPackages registerObject registerPostBackControl -registerPostDataLoader registerPradoScript registerRequiresPostData registerScriptFile @@ -2216,7 +2212,6 @@ renderCalendarMonthOptions renderCalendarSelections renderCalendarYearOptions renderCallback -renderCallbackClientScripts renderCallbackResponse renderChildren renderClientControlScript diff --git a/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js b/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js index a586c4d9..8f1fd3b8 100644 --- a/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js +++ b/framework/Web/Javascripts/source/prado/activecontrols/activecontrols3.js @@ -409,3 +409,19 @@ jQuery.extend(Prado.WebUI.TValueTriggeredCallback, Prado.WebUI.TActiveTableCell = jQuery.klass(Prado.WebUI.CallbackControl); Prado.WebUI.TActiveTableRow = jQuery.klass(Prado.WebUI.CallbackControl); + +Prado.WebUI.TActiveRatingList = jQuery.klass(Prado.WebUI.TRatingList, +{ + dispatchRequest : function(ev) + { + var requestOptions = jQuery.extend( + { + ID : this.options.ListID+"_c"+this.selectedIndex, + EventTarget : this.options.ListName+"$c"+this.selectedIndex + },this.options); + var request = new Prado.CallbackRequest(requestOptions.EventTarget, requestOptions); + if(request.dispatch()==false) + ev.stopPropagation(); + } + +}); diff --git a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js index 38bc4b7f..68b4a8be 100644 --- a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js +++ b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js @@ -47,10 +47,30 @@ Prado.CallbackRequestManager = /** * Hidden field list header name. */ - HIDDENFIELDLIST_HEADER : 'X-PRADO-HIDDENFIELDLIST' + HIDDENFIELDLIST_HEADER : 'X-PRADO-HIDDENFIELDLIST', + + /** + * Formats the exception message for display in console. + */ + formatException : function(e) + { + var msg = e.type + " with message \""+e.message+"\""; + msg += " in "+e.file+"("+e.line+")\n"; + msg += "Stack trace:\n"; + var trace = e.trace; + for(var i = 0; i"+trace[i]["function"]+"()"+"\n"; + } + msg += e.version+" "+e.time+"\n"; + return msg; + } }; -Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { +Prado.CallbackRequest = jQuery.klass(Prado.PostBack, +{ options : {}, data : '', @@ -77,6 +97,14 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { this.options.onUninitialized(this,null); }, + /** + * Sets the request options + * @return {Array} request options. + */ + setOptions: function(options) { + jQuery.extend(this.options, options || { }); + }, + getForm: function() { return jQuery('#PRADO_PAGESTATE').get(0).form; @@ -187,9 +215,20 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { this.options.data = this.getParameters(); this.options.url = this.getCallbackUrl(); - jQuery.ajax(this.options); + this.request = jQuery.ajax(this.options); }, + abort : function() + { + if(this.request != "undefined") + this.request.abort(); + }, + + /** + * Collects the form inputs, encode the parameters, and sets the callback + * target id. The resulting string is the request content body. + * @return string request body content containing post data. + */ getParameters : function() { var form = this.getForm(); @@ -200,7 +239,10 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { if(this.options.EventTarget) data[Prado.CallbackRequestManager.FIELD_CALLBACK_TARGET] = this.options.EventTarget; - return jQuery(form).serialize() + '&' + jQuery.param(data); + if(this.options.PostInputs != false) + return jQuery(form).serialize() + '&' + jQuery.param(data); + else + return jQuery.param(data); }, /** @@ -226,12 +268,6 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { return this.data.substring(start,end); } return null; - /*var f = RegExp('(?:)((?:.|\n|\r)+?)(?:)',"m"); - var result = this.data.match(f); - if(result && result.length >= 2) - return result[1]; - else - return null;*/ }, errorHandler: function(request, textStatus, errorThrown) @@ -239,24 +275,6 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { //null) are "timeout", "error", "abort", and "parsererror" if (this.options.onFailure) this.options.onFailure(this,null); - - if(request.status==500) - { - /** - * Server returns 500 exception. Just log it. - */ - var e = request.getResponseHeader(Prado.CallbackRequestManager.ERROR_HEADER); - if (e) - { - json = jQuery.parseJSON(e); - if(typeof(json) == "object") - Logger.error("Callback Server Error "+json.code, this.formatException(json)); - else - Logger.error("Callback Server Error Corrupted"); - } - else - Logger.error("Callback Server Error Unknown",''); - } }, completeHandler: function(request, textStatus) @@ -264,7 +282,6 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { //"success", "notmodified", "error", "timeout", "abort", or "parsererror" if (this.options.onComplete) this.options.onComplete(this,null); - }, /** @@ -283,25 +300,6 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { Logger.error('Uncaught Callback Client Exception:', msg); }, - /** - * Formats the exception message for display in console. - */ - formatException : function(e) - { - var msg = e.type + " with message \""+e.message+"\""; - msg += " in "+e.file+"("+e.line+")\n"; - msg += "Stack trace:\n"; - var trace = e.trace; - for(var i = 0; i"+trace[i]["function"]+"()"+"\n"; - } - msg += e.version+" "+e.time+"\n"; - return msg; - }, - /** * Callback OnSuccess event,logs reponse and data to console. */ @@ -310,50 +308,21 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { if (this.options.onSuccess) this.options.onSuccess(this,null); - Logger.info('HTTP '+request.status+" with response : \n"+data); - this.data = data; var redirectUrl = this.extractContent(Prado.CallbackRequestManager.REDIRECT_HEADER); if (redirectUrl) document.location.href = redirectUrl; -/* - if ((this.getHeader('Content-type') || '').match(/^text\/javascript/i)) - { - try - { - json = eval('(' + transport.responseText + ')'); - } - catch (e) - { - if(typeof(json) == "string") - json = Prado.CallbackRequest.decode(result); - } - } -*/ - try - { + + try { this.updatePageState(this, data); this.checkHiddenFields(this, data); var obj = this; this.loadAssets(this, data, function() { - try - { - //Ajax.Responders.dispatch('on' + transport.status, obj, transport, json); + try { obj.dispatchActions(obj, data); -/* - ( - obj.options['on' + obj.transport.status] - || - obj.options['on' + (obj.success() ? 'Success' : 'Failure')] - || - Prototype.emptyFunction - ) (obj, json); - */ - } - catch (e) - { - obj.exceptionHandler(e); + } catch (e) { + obj.exceptionHandler(e); } } ); @@ -414,10 +383,13 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { { json = jQuery.parseJSON(data); if(typeof(json) != "object") - Logger.warn("Invalid hidden field list:"+data); - else + { + if(typeof(Logger) != "undefined") + Logger.warn("Invalid hidden field list:"+data); + } else { for(var key in json) Prado.CallbackRequestManager.checkHiddenField(key,json[key]); + } } }, @@ -464,8 +436,10 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { { json = jQuery.parseJSON(data); if(typeof(json) != "object") - Logger.warn("Invalid script list:"+data); - else + { + if(typeof(Logger) != "undefined") + Logger.warn("Invalid script list:"+data); + } else { for(var key in json) if (/^\d+$/.test(key)) { @@ -473,6 +447,7 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { if (!Prado.ScriptManager.isAssetLoaded(url)) this.ScriptsToLoad.push(url); } + } } this.loadNextScript(); }, @@ -510,11 +485,14 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { { json = jQuery.parseJSON(data); if(typeof(json) != "object") - Logger.warn("Invalid stylesheet list:"+data); - else + { + if(typeof(Logger) != "undefined") + Logger.warn("Invalid stylesheet list:"+data); + } else { for(var key in json) if (/^\d+$/.test(key)) Prado.StyleSheetManager.createStyleSheetCode(json[key],null); + } } }, @@ -525,11 +503,14 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { { json = jQuery.parseJSON(data); if(typeof(json) != "object") - Logger.warn("Invalid stylesheet list:"+data); - else + { + if(typeof(Logger) != "undefined") + Logger.warn("Invalid stylesheet list:"+data); + } else { for(var key in json) if (/^\d+$/.test(key)) Prado.StyleSheetManager.ensureAssetIsLoaded(json[key],null); + } } }, @@ -542,8 +523,10 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { { json = jQuery.parseJSON(data); if(typeof(json) != "object") - Logger.warn("Invalid stylesheet list:"+data); - else + { + if(typeof(Logger) != "undefined") + Logger.warn("Invalid stylesheet list:"+data); + } else { for(var key in json) if (/^\d+$/.test(key)) { @@ -551,6 +534,7 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { if (!Prado.StyleSheetManager.isAssetLoaded(url)) this.StyleSheetsToLoad.push(url); } + } } this.loadNextStyleSheet(); }, @@ -569,9 +553,7 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { ) ) this.loadNextStyleSheet(); - } - else - { + } else { if (this.StyleSheetLoadFinishedCallback) { var cb = this.StyleSheetLoadFinishedCallback; @@ -591,10 +573,13 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { { json = jQuery.parseJSON(data); if(typeof(json) != "object") - Logger.warn("Invalid action:"+data); - else + { + if(typeof(Logger) != "undefined") + Logger.warn("Invalid action:"+data); + } else { for(var key in json) this.__run(this, json[key]); + } } }, @@ -605,107 +590,63 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, { { for(var method in command) { - try - { + try { method.toFunction().apply(request,command[method]); - } - catch(e) - { - if(typeof(Logger) != "undefined") - this.Exception.exceptionHandler(null,e); - else - debugger; + } catch(e) { + this.exceptionHandler(null,e); } } }, }); -Prado.CallbackRequest.addPostLoaders = function(ids) +//Add HTTP exception respones when logger is enabled. +jQuery(function() { - //dummy -}; - - - -// Prado.AjaxRequest = jQuery.klass(); -// Prado.AjaxRequest.prototype = { -// * Customize the response, dispatch onXXX response code events, and -// * tries to execute response actions (javascript statements). -// */ -// respondToReadyState : function(readyState) -// { -// var event = Ajax.Request.Events[readyState]; -// var transport = this.transport, json = this.getBodyDataPart(Prado.CallbackRequest.DATA_HEADER); - -// if (event == 'Complete') -// { - -// } - -// /* Avoid memory leak in MSIE: clean up the oncomplete event handler */ -// if (event == 'Complete') -// this.transport.onreadystatechange = Prototype.emptyFunction; -// }, - -// /** -// * Gets header data assuming JSON encoding. -// * @param string header name -// * @return object header data as javascript structures. -// */ -// getHeaderData : function(name) -// { -// return this.getJsonData(this.getHeader(name)); -// }, + if(typeof Logger != "undefined") + { + jQuery( document ).ajaxSuccess(function( event, request, settings ) { + Logger.info('HTTP '+request.status+" with response : \n"); -// getJsonData : function(json) -// { -// try -// { -// return eval('(' + json + ')'); -// } -// catch (e) -// { -// if(typeof(json) == "string") -// return Prado.CallbackRequest.decode(json); -// } -// }, + var tagStart = '