summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/source
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2013-10-24 19:16:20 +0200
committerFabio Bas <ctrlaltca@gmail.com>2013-11-26 11:42:46 +0100
commitf34d86fc59349c9a8e7ecd3f6b571ea89f8d7295 (patch)
tree6dda4c90fa4a58b4f35eef7f67fe83bb2c723bec /framework/Web/Javascripts/source
parentdd49f04ffd14333bdc6d0fed9faed7f67bb0441f (diff)
More ajax-related porting
Initial implementation of ajax error handling Fixed ajax modifications of select and checkboxes Partially ported TJavascriptLogger (used in tests)
Diffstat (limited to 'framework/Web/Javascripts/source')
-rw-r--r--framework/Web/Javascripts/source/prado/activecontrols/ajax3.js129
-rw-r--r--framework/Web/Javascripts/source/prado/controls/controls.js2
-rw-r--r--framework/Web/Javascripts/source/prado/logger/logger.js57
-rw-r--r--framework/Web/Javascripts/source/prado/prado.js8
4 files changed, 82 insertions, 114 deletions
diff --git a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js
index 37941fd4..38bc4b7f 100644
--- a/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js
+++ b/framework/Web/Javascripts/source/prado/activecontrols/ajax3.js
@@ -239,6 +239,24 @@ 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)
@@ -249,18 +267,51 @@ Prado.CallbackRequest = jQuery.klass(Prado.PostBack, {
},
+ /**
+ * Uncaught exceptions during callback response.
+ */
exceptionHandler: function(e)
{
if (this.options.onException)
this.options.onException(this,null);
+ var msg = "";
+ jQuery.each(e, function(item)
+ {
+ msg += item.key+": "+item.value+"\n";
+ })
+ 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.length; i++)
+ {
+ msg += " #"+i+" "+trace[i].file;
+ msg += "("+trace[i].line+"): ";
+ msg += trace[i]["class"]+"->"+trace[i]["function"]+"()"+"\n";
+ }
+ msg += e.version+" "+e.time+"\n";
+ return msg;
+ },
+
+ /**
+ * Callback OnSuccess event,logs reponse and data to console.
+ */
successHandler: function(data, textStatus, request)
{
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)
@@ -692,84 +743,6 @@ Prado.CallbackRequest.addPostLoaders = function(ids)
// },
// /**
-// * Respond to Prado Callback request exceptions.
-// */
-// Exception :
-// {
-// /**
-// * Server returns 500 exception. Just log it.
-// */
-// "on500" : function(request, transport, data)
-// {
-// var e = request.getHeaderData(Prado.CallbackRequest.ERROR_HEADER);
-// if (e)
-// Logger.error("Callback Server Error "+e.code, this.formatException(e));
-// else
-// Logger.error("Callback Server Error Unknown",'');
-// },
-
-// /**
-// * Callback OnComplete event,logs reponse and data to console.
-// */
-// 'on200' : function(request, transport, data)
-// {
-// if(transport.status < 500)
-// {
-// var msg = 'HTTP '+transport.status+" with response : \n";
-// if(transport.responseText.trim().length >0)
-// {
-// var f = RegExp('(<!--X-PRADO[^>]+-->)([\\s\\S\\w\\W]*)(<!--//X-PRADO[^>]+-->)',"m");
-// msg += transport.responseText.replace(f,'') + "\n";
-// }
-// if(typeof(data)!="undefined" && data != null)
-// msg += "Data : \n"+inspect(data)+"\n";
-// data = request.getBodyDataPart(Prado.CallbackRequest.ACTION_HEADER);
-// if(data && data.length > 0)
-// {
-// msg += "Actions : \n";
-// data.each(function(action)
-// {
-// msg += inspect(action)+"\n";
-// });
-// }
-// Logger.info(msg);
-// }
-// },
-
-// /**
-// * Uncaught exceptions during callback response.
-// */
-// onException : function(request,e)
-// {
-// var msg = "";
-// $H(e).each(function(item)
-// {
-// msg += item.key+": "+item.value+"\n";
-// })
-// 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.length; i++)
-// {
-// msg += " #"+i+" "+trace[i].file;
-// msg += "("+trace[i].line+"): ";
-// msg += trace[i]["class"]+"->"+trace[i]["function"]+"()"+"\n";
-// }
-// msg += e.version+" "+e.time+"\n";
-// return msg;
-// }
-// },
-
-// /**
// * Dispatch a normal request, no timeouts or aborting of requests.
// */
// dispatchNormalRequest : function(callback)
diff --git a/framework/Web/Javascripts/source/prado/controls/controls.js b/framework/Web/Javascripts/source/prado/controls/controls.js
index 354bb5f5..8914db3c 100644
--- a/framework/Web/Javascripts/source/prado/controls/controls.js
+++ b/framework/Web/Javascripts/source/prado/controls/controls.js
@@ -269,7 +269,7 @@ Prado.WebUI.PostBackControl = jQuery.klass(Prado.WebUI.Control, {
onPostBack : function(options, event)
{
- Prado.PostBack(options, event);
+ new Prado.PostBack(options, event);
}
});
diff --git a/framework/Web/Javascripts/source/prado/logger/logger.js b/framework/Web/Javascripts/source/prado/logger/logger.js
index c5cea3ca..fde772ce 100644
--- a/framework/Web/Javascripts/source/prado/logger/logger.js
+++ b/framework/Web/Javascripts/source/prado/logger/logger.js
@@ -13,8 +13,7 @@ Use it all you want. Just remember to give me some credit :)
// Custom Event
// ------------
-CustomEvent = jQuery.klass();
-CustomEvent.prototype = {
+CustomEvent = jQuery.klass({
initialize : function() {
this.listeners = []
},
@@ -54,7 +53,7 @@ CustomEvent.prototype = {
return indexes
}
-};
+});
// ------
// Cookie
@@ -179,16 +178,14 @@ Logger = {
}
};
-LogEntry = jQuery.klass()
-LogEntry.prototype = {
+LogEntry = jQuery.klass({
initialize : function(message, tag) {
this.message = message
this.tag = tag
}
-};
+});
-LogConsole = jQuery.klass();
-LogConsole.prototype = {
+LogConsole = jQuery.klass({
// Properties
// ----------
@@ -207,7 +204,7 @@ LogConsole.prototype = {
// I hate writing javascript in HTML... but what's a better alternative
this.logElement = document.createElement('div')
document.body.appendChild(this.logElement)
- Element.hide(this.logElement)
+ jQuery(this.logElement).hide();
this.logElement.style.position = "absolute"
this.logElement.style.left = '0px'
@@ -247,8 +244,8 @@ LogConsole.prototype = {
this.tagFilterElement.value = this.tagPattern
this.tagFilterElement.setAttribute('autocomplete', 'off') // So Firefox doesn't flip out
- Event.observe(this.tagFilterElement, 'keyup', this.updateTags.bind(this))
- Event.observe(this.tagFilterElement, 'click', function() {this.tagFilterElement.select()}.bind(this))
+ jQuery(this.tagFilterElement).on('keyup', this.updateTags.bind(this));
+ jQuery(this.tagFilterElement).on('click', function() {this.tagFilterElement.select()}.bind(this));
// Add outputElement
this.outputElement = document.createElement('div')
@@ -271,8 +268,8 @@ LogConsole.prototype = {
this.inputElement.value = 'Type command here'
this.inputElement.setAttribute('autocomplete', 'off') // So Firefox doesn't flip out
- Event.observe(this.inputElement, 'keyup', this.handleInput.bind(this))
- Event.observe(this.inputElement, 'click', function() {this.inputElement.select()}.bind(this))
+ jQuery(this.inputElement).on('keyup', this.handleInput.bind(this));
+ jQuery(this.inputElement).on('click', function() {this.inputElement.select()}.bind(this));
if(document.all && !window.opera)
{
@@ -284,9 +281,9 @@ LogConsole.prototype = {
this.logElement.style.bottom="0px";
}
var self=this;
- Event.observe(document, 'keydown', function(e)
+ jQuery(document).on('keydown', function(e)
{
- if((e.altKey==true) && Event.keyCode(e) == toggleKey ) //Alt+J | Ctrl+J
+ if((e.altKey==true) && e.keyCode == toggleKey ) //Alt+J | Ctrl+J
self.toggle();
});
@@ -301,7 +298,7 @@ LogConsole.prototype = {
// Feed all errors into the logger (For some unknown reason I can only get this to work
// with an inline event declaration)
- Event.observe(window, 'error', function(msg, url, lineNumber) {Logger.error("Error in (" + (url || location) + ") on line "+lineNumber+"", msg)})
+ jQuery(window).on('error', function(msg, url, lineNumber) {Logger.error("Error in (" + (url || location) + ") on line "+lineNumber+"", msg)});
// Allow acess key link
var accessElement = document.createElement('span')
@@ -315,27 +312,27 @@ LogConsole.prototype = {
toggle : function() {
if (this.logElement.style.display == 'none') {
- this.show()
+ this.show();
}
else {
- this.hide()
+ this.hide();
}
},
show : function() {
- Element.show(this.logElement)
+ jQuery(this.logElement).show();
this.outputElement.scrollTop = this.outputElement.scrollHeight // Scroll to bottom when toggled
if(document.all && !window.opera)
this.repositionWindow();
Cookie.set('ConsoleVisible', 'true')
- this.inputElement.select()
+ this.inputElement.select();
this.hidden = false;
},
hide : function() {
this.hidden = true;
- Element.hide(this.logElement)
- Cookie.set('ConsoleVisible', 'false')
+ jQuery(this.logElement).hide();
+ Cookie.set('ConsoleVisible', 'false');
},
output : function(message, style) {
@@ -349,7 +346,7 @@ LogConsole.prototype = {
if (this.outputCount % 2 == 0) style += ";background-color:#101010"
message = message || "undefined"
- message = message.toString().escapeHTML()
+ message = message.toString().replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
this.outputElement.innerHTML += "<pre style='" + style + "'>" + message + "</pre>"
@@ -408,7 +405,7 @@ LogConsole.prototype = {
},
handleInput : function(e) {
- if (e.keyCode == Event.KEY_RETURN ) {
+ if (e.keyCode == 13 ) {
var command = this.inputElement.value
switch(command) {
@@ -438,14 +435,14 @@ LogConsole.prototype = {
this.commandIndex = 0
this.inputElement.value = ""
}
- else if (e.keyCode == Event.KEY_UP && this.commandHistory.length > 0) {
+ else if (e.keyCode == 38 && this.commandHistory.length > 0) {
this.inputElement.value = this.commandHistory[this.commandIndex]
if (this.commandIndex < this.commandHistory.length - 1) {
this.commandIndex += 1
}
}
- else if (e.keyCode == Event.KEY_DOWN && this.commandHistory.length > 0) {
+ else if (e.keyCode == 40 && this.commandHistory.length > 0) {
if (this.commandIndex > 0) {
this.commandIndex -= 1
}
@@ -456,7 +453,7 @@ LogConsole.prototype = {
this.commandIndex = 0
}
}
-};
+});
// -------------------------
@@ -697,8 +694,7 @@ Prado.Inspector =
{
this.d.body.removeChild(this.d.getElementById("so_mContainer"));
this.d.body.removeChild(this.d.getElementById("so_mStyle"));
- if(typeof Event != "undefined")
- Event.stopObserving(this.d, "keydown", this.dKeyDownEvent);
+ jQuery(this.d).unbind("keydown", this.dKeyDownEvent);
this.types = new Array();
this.objs = new Array();
this.hidden = new Array();
@@ -718,8 +714,7 @@ Prado.Inspector =
sObj.type="text/css";
sObj.innerHTML = this.style;
this.dKeyDownEvent = this.handleKeyEvent.bind(this);
- if(typeof Event != "undefined")
- Event.observe(this.d, "keydown", this.dKeyDownEvent);
+ jQuery(this.d).on("keydown", this.dKeyDownEvent);
this.parseJS(obj);
this.buildTree();
diff --git a/framework/Web/Javascripts/source/prado/prado.js b/framework/Web/Javascripts/source/prado/prado.js
index 14f13858..59dde88b 100644
--- a/framework/Web/Javascripts/source/prado/prado.js
+++ b/framework/Web/Javascripts/source/prado/prado.js
@@ -74,10 +74,10 @@ Prado.PostBack = jQuery.klass(
return event.preventDefault();
}
- if(options['PostBackUrl'] && options['PostBackUrl'].length > 0)
- form.action = options['PostBackUrl'];
+ if(this.options['PostBackUrl'] && this.options['PostBackUrl'].length > 0)
+ form.action = this.options['PostBackUrl'];
- if(options['TrackFocus'])
+ if(this.options['TrackFocus'])
{
var lastFocus = $('PRADO_LASTFOCUS');
if(lastFocus)
@@ -86,7 +86,7 @@ Prado.PostBack = jQuery.klass(
if(active)
lastFocus.value = active.id;
else
- lastFocus.value = options['EventTarget'];
+ lastFocus.value = this.options['EventTarget'];
}
}