summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2013-10-24 19:16:20 +0200
committerFabio Bas <ctrlaltca@gmail.com>2013-10-24 19:16:20 +0200
commit695087b624283799fa9a150fceab0eff97bf9c68 (patch)
tree8650a8a5dad1afdc7061e5ee5afb72865142dca5
parentb5f0dee968ff09e2d7e8a4082f8c217629a5283e (diff)
More ajax-related porting
Initial implementation of ajax error handling Fixed ajax modifications of select and checkboxes Partially ported TJavascriptLogger (used in tests)
-rw-r--r--framework/Web/Javascripts/packages.php2
-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
-rw-r--r--framework/Web/UI/ActiveControls/TCallbackClientScript.php5
-rw-r--r--framework/Web/UI/WebControls/TJavascriptLogger.php2
7 files changed, 89 insertions, 116 deletions
diff --git a/framework/Web/Javascripts/packages.php b/framework/Web/Javascripts/packages.php
index 4edfb362..64834157 100644
--- a/framework/Web/Javascripts/packages.php
+++ b/framework/Web/Javascripts/packages.php
@@ -113,9 +113,9 @@ $dependencies = array(
'validator' => array('jquery', 'prado', 'validator'),
'tabpanel' => array('jquery', 'prado', 'tabpanel'),
'ajax' => array('jquery', 'prado', 'ajax'),
+ 'logger' => array('jquery', 'prado', 'logger'),
'effects' => array('prototype', 'prado', 'effects'),
- 'logger' => array('prototype', 'prado', 'logger'),
'datepicker' => array('prototype', 'prado', 'datepicker'),
'colorpicker' => array('prototype', 'prado', 'colorpicker'),
'dragdrop' => array('prototype', 'prado', 'effects', 'ajax', 'dragdrop'),
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 d62d333c..e1e672ff 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'];
}
}
diff --git a/framework/Web/UI/ActiveControls/TCallbackClientScript.php b/framework/Web/UI/ActiveControls/TCallbackClientScript.php
index 2c9a01b9..15300727 100644
--- a/framework/Web/UI/ActiveControls/TCallbackClientScript.php
+++ b/framework/Web/UI/ActiveControls/TCallbackClientScript.php
@@ -153,6 +153,11 @@ class TCallbackClientScript extends TApplicationComponent
'Value', 'Index', 'Clear', 'Indices', 'Values', 'All', 'Invert');
$type = ($type===null) ? $this->getSelectionControlType($control) : $type;
$total = $this->getSelectionControlIsListType($control) ? $control->getItemCount() : 1;
+
+ // pass the ID to avoid getting the surrounding elements (ISurroundable)
+ if($control instanceof TControl)
+ $control = $control->getClientID();
+
$this->callClientFunction('Prado.Element.select',
array($control, $type.$method, $value, $total));
}
diff --git a/framework/Web/UI/WebControls/TJavascriptLogger.php b/framework/Web/UI/WebControls/TJavascriptLogger.php
index a2f1c1c2..2af8bda6 100644
--- a/framework/Web/UI/WebControls/TJavascriptLogger.php
+++ b/framework/Web/UI/WebControls/TJavascriptLogger.php
@@ -70,7 +70,7 @@ class TJavascriptLogger extends TWebControl
{
$key = strtolower($this->getToggleKey());
$code = isset(self::$_keyCodes[$key]) ? self::$_keyCodes[$key] : 74;
- $js = "var logConsole; Event.OnLoad(function() { logConsole = new LogConsole($code)}); ";
+ $js = "var logConsole; jQuery(function() { logConsole = new LogConsole($code)}); ";
$cs = $this->getPage()->getClientScript();
$cs->registerBeginScript($this->getClientID(),$js);
$cs->registerPradoScript('logger');