summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/base
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Web/Javascripts/base')
-rw-r--r--framework/Web/Javascripts/base/ajax.js174
-rw-r--r--framework/Web/Javascripts/base/controls.js31
-rw-r--r--framework/Web/Javascripts/base/effects.js22
-rw-r--r--framework/Web/Javascripts/base/postback.js2
-rw-r--r--framework/Web/Javascripts/base/prado.js66
-rw-r--r--framework/Web/Javascripts/base/validation.js2
-rw-r--r--framework/Web/Javascripts/base/validators.js9
7 files changed, 208 insertions, 98 deletions
diff --git a/framework/Web/Javascripts/base/ajax.js b/framework/Web/Javascripts/base/ajax.js
index f1dd69c5..ccfb085d 100644
--- a/framework/Web/Javascripts/base/ajax.js
+++ b/framework/Web/Javascripts/base/ajax.js
@@ -53,17 +53,20 @@ Prado.AJAX.Request.prototype = Object.extend(Ajax.Request.prototype,
respondToReadyState: function(readyState) {
var event = Ajax.Request.Events[readyState];
var transport = this.transport, json = this.evalJSON();
+
+
if(event == 'Complete' && transport.status)
Ajax.Responders.dispatch('on' + transport.status, this, transport, json);
- if (event == 'Complete')
+ (this.options['on' + event] || Prototype.emptyFunction)(transport, json);
+ Ajax.Responders.dispatch('on' + event, this, transport, json);
+
+ if (event == 'Complete')
(this.options['on' + this.transport.status]
|| this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
|| Prototype.emptyFunction)(transport, json);
- (this.options['on' + event] || Prototype.emptyFunction)(transport, json);
- Ajax.Responders.dispatch('on' + event, this, transport, json);
-
+
/* Avoid memory leak in MSIE: clean up the oncomplete event handler */
if (event == 'Complete')
this.transport.onreadystatechange = Prototype.emptyFunction;
@@ -208,12 +211,10 @@ Prado.AJAX.RemoteObject.prototype =
__onSuccess : function(transport, json)
{
if(this.__handlers[this.__callback])
- this.__handlers[this.__callback](json, transport.responseText);
+ this.__handlers[this.__callback](json, transport.responseText);
}
};
-
-
/**
* Respond to Prado AJAX request exceptions.
*/
@@ -235,7 +236,7 @@ Prado.AJAX.Exception =
{
var msg = 'HTTP '+transport.status+" with response : \n";
msg += transport.responseText + "\n";
- msg += "Data : \n"+e;
+ msg += "Data : \n"+inspect(e);
Logger.warn(msg);
}
},
@@ -285,12 +286,14 @@ Prado.AJAX.Callback.prototype = Object.extend(new Prado.AJAX.RemoteObject(),
/**
* Create and request a new Prado callback service.
- * @param string the callback ID, must be of the form, <t>ClassName.ComponentID.MethodName</t>
+ * @param string|element the callback ID, must be of the form, <t>ClassName.ComponentID.MethodName</t>
* @param list options with list key onCallbackReturn, and more.
*
*/
initialize : function(ID, options)
{
+ if(!isString(ID) && typeof(ID.id) != "undefined")
+ ID = ID.id;
if(!isString(ID))
throw new Error('A Control ID must be specified');
this.baseInitialize(this, options);
@@ -307,7 +310,25 @@ Prado.AJAX.Callback.prototype = Object.extend(new Prado.AJAX.RemoteObject(),
var IDs = Prado.AJAX.Callback.IDs;
this.__service.post.data['__data'] = {};
for(var i = 0; i<IDs.length; i++)
- this.__service.post.data['__data'][IDs[i]] = $F(IDs[i]);
+ {
+ var id = IDs[i];
+ if(id.indexOf("[]") > -1)
+ this.__service.post.data['__data'][id] =
+ this.collectArrayPostData(id);
+ else if(isObject($(id)))
+ this.__service.post.data['__data'][id] = $F(id);
+ }
+ },
+
+ collectArrayPostData : function(name)
+ {
+ var elements = document.getElementsByName(name);
+ var data = [];
+ $A(elements).each(function(el)
+ {
+ if($F(el)) data.push($F(el));
+ });
+ return data;
},
/**
@@ -318,18 +339,134 @@ Prado.AJAX.Callback.prototype = Object.extend(new Prado.AJAX.RemoteObject(),
requestCallback : function()
{
this.collectPostData();
- return this.__call(Prado.AJAX.Callback.Server, 'handleCallback', this.options.params);
+ if(Prado.AJAX.Validate(this.options))
+ return this.__call(Prado.AJAX.Callback.Server, 'handleCallback', this.options.params);
},
-
+
/**
* On callback request return, call the onSuccess function.
*/
handleCallback : function(result, output)
{
- this.options.onSuccess(result, output);
+ if(typeof(result) != "undefined" && !isNull(result))
+ {
+ this.options.onSuccess(result['data'], output);
+ if(result['actions'])
+ result.actions.each(Prado.AJAX.Callback.Action.__run);
+ }
}
});
+/**
+ * Prase and evaluate Callback clien-side actions.
+ */
+Prado.AJAX.Callback.Action =
+{
+ __run : function(command)
+ {
+ for(var name in command)
+ {
+ //first parameter must be a valid element or begins with '@'
+ if(command[name][0] && ($(command[name][0]) || command[name][0].indexOf("[]") > -1))
+ {
+ name.toFunction().apply(this,command[name]);
+ }
+ }
+ }
+};
+
+
+/**
+ * Returns false if validation required and validates to false,
+ * returns true otherwise.
+ * @return boolean true if validation passes.
+ */
+Prado.AJAX.Validate = function(options)
+{
+ if(options.CausesValidation)
+ {
+ if(options.ValidatorGroup)
+ return Prado.AJAX.ValidateGroup1(options.ValidatorGroup);
+ else if(options.ValidationGroup)
+ return Prado.AJAX.ValidateGroup2(options.ValidationGroup);
+ else
+ return Prado.AJAX.ValidateOthers(options.ValidationForm);
+ }
+ else
+ return true;
+};
+
+/**
+ * Validate Validator Groups.
+ * @param string ValidatorGroup
+ * @return boolean true if valid, false otherwise
+ */
+Prado.AJAX.ValidateGroup1 = function(groupId)
+{
+ var groups = Prado.Validation.groups;
+ var group = null;
+ for(var i = 0; i < groups.length; i++)
+ {
+ if(groups[i].id == groupId)
+ {
+ group = groups[i];
+ Prado.Validation.groups[i].active = true;
+ Prado.Validation.CurrentTargetGroup = null;
+ Prado.Validation.IsGroupValidation = true;
+ }
+ else
+ {
+ Prado.Validation.groups[i].active = false;
+ }
+ }
+ if(group)
+ {
+ return Prado.Validation.IsValid(group.target.form);
+ }
+ return true;
+};
+
+/**
+ * Validate ValidationGroup
+ * @param string ValidationGroup
+ * @return boolean true if valid, false otherwise.
+ */
+Prado.AJAX.ValidateGroup2 = function(groupId)
+{
+ var groups = Prado.Validation.TargetGroups;
+ for(var id in groups)
+ {
+ if(groups[id] == groupId)
+ {
+ var target = $(id);
+ Prado.Validation.ActiveTarget = target;
+ Prado.Validation.CurrentTargetGroup = groupId;
+ Prado.Validation.IsGroupValidation = false;
+ return Prado.Validation.IsValid(target.form);
+ }
+ }
+ return true;
+};
+
+/**
+ * Validate the page
+ * @return boolean true if valid, false otherwise.
+ */
+Prado.AJAX.ValidateOthers = function(formId)
+{
+ if(Prado.Validation)
+ {
+ var form = $(formId);
+ form = form || document.forms[0];
+ Prado.Validation.ActiveTarget = form;
+ Prado.Validation.CurrentTargetGroup = null;
+ Prado.Validation.IsGroupValidation = false;
+ return Prado.Validation.IsValid(form);
+ }
+ return true;
+};
+
+
//Available callback service
Prado.AJAX.Callback.Server = '';
@@ -342,14 +479,17 @@ Prado.AJAX.Callback.IDs = [];
* @param string callback ID
* @param array parameters to pass to the callback service
*/
-Prado.Callback = function(ID, params, onSuccess)
+Prado.Callback = function(ID, params, onSuccess, options)
{
- var options =
+ var callback =
{
'params' : [params] || [],
- 'onSuccess' : onSuccess || Prototype.emptyFunction
+ 'onSuccess' : onSuccess || Prototype.emptyFunction,
+ 'CausesValidation' : true
};
+
+ Object.extend(callback, options || {});
- new Prado.AJAX.Callback(ID, options);
+ new Prado.AJAX.Callback(ID, callback);
return false;
} \ No newline at end of file
diff --git a/framework/Web/Javascripts/base/controls.js b/framework/Web/Javascripts/base/controls.js
index 6cb908ed..ad5b8abe 100644
--- a/framework/Web/Javascripts/base/controls.js
+++ b/framework/Web/Javascripts/base/controls.js
@@ -140,8 +140,9 @@ Prado.ActivePanel.Request.prototype =
{
if(this.options.update)
{
- var element = $(this.options.update)
- if(element) element.innerHTML = output;
+ if (!this.options.evalScripts)
+ output = output.stripScripts();
+ Element.update(this.options.update, output);
}
}
}
@@ -160,7 +161,7 @@ Prado.DropContainer.prototype = Object.extend(new Prado.ActivePanel.Request(),
{
onDrop : this.onDrop.bind(this),
evalScripts : true,
- onSuccess : options.onSuccess || this.update.bind(this)
+ onSuccess : options.onSuccess || this.onSuccess.bind(this)
});
Droppables.add(element, this.options);
},
@@ -168,12 +169,26 @@ Prado.DropContainer.prototype = Object.extend(new Prado.ActivePanel.Request(),
onDrop : function(draggable, droppable)
{
this.callback(draggable.id)
+ }
+});
+
+Prado.ActiveImageButton = Class.create();
+Prado.ActiveImageButton.prototype =
+{
+ initialize : function(element, options)
+ {
+ this.element = $(element);
+ this.options = options;
+ Event.observe(this.element, "click", this.click.bind(this));
},
- update : function(result, output)
+ click : function(e)
{
- this.onSuccess(result, output);
- if (this.options.evalScripts)
- Prado.AJAX.EvalScript(output);
+ var el = $('{$this->ClientID}');
+ var imagePos = Position.cumulativeOffset(this.element);
+ var clickedPos = [e.clientX, e.clientY];
+ var param = (clickedPos[0]-imagePos[0]+1)+","+(clickedPos[1]-imagePos[1]+1);
+ Prado.Callback(this.element, param, null, this.options);
+ Event.stop(e);
}
-}); \ No newline at end of file
+} \ No newline at end of file
diff --git a/framework/Web/Javascripts/base/effects.js b/framework/Web/Javascripts/base/effects.js
new file mode 100644
index 00000000..cc31d00e
--- /dev/null
+++ b/framework/Web/Javascripts/base/effects.js
@@ -0,0 +1,22 @@
+Prado.Effect =
+{
+ Highlight : function(element, duration)
+ {
+ new Effect.Highlight(element, {'duration':duration});
+ },
+
+ Scale : function(element, percent)
+ {
+ new Effect.Scale(element, percent);
+ },
+
+ MoveBy : function(element, toTop, toLeft)
+ {
+ new Effect.MoveBy(element, toTop, toLeft);
+ },
+
+ ScrollTo : function(element, duration)
+ {
+ new Effect.ScrollTo(element, {'duration':duration});
+ }
+} \ No newline at end of file
diff --git a/framework/Web/Javascripts/base/postback.js b/framework/Web/Javascripts/base/postback.js
index 2889c4ff..b7e095a4 100644
--- a/framework/Web/Javascripts/base/postback.js
+++ b/framework/Web/Javascripts/base/postback.js
@@ -13,7 +13,7 @@ Prado.doPostBack = function(formID, eventTarget, eventParameter, performValidati
if (performValidation)
{
//canSubmit = Prado.Validation.validate(validationGroup);
- canSubmit = Prado.Validation.OnSubmit();
+ canSubmit = Prado.Validation.OnSubmit(theForm);
}
if (canSubmit)
{
diff --git a/framework/Web/Javascripts/base/prado.js b/framework/Web/Javascripts/base/prado.js
index 3eded927..7dd14e19 100644
--- a/framework/Web/Javascripts/base/prado.js
+++ b/framework/Web/Javascripts/base/prado.js
@@ -1,65 +1 @@
-Prado = Class.create();
-
-Prado.version = '3.0a';
-
-Prado.Button = Class.create();
-
-Prado.Button.buttonFired = false;
-Prado.Button.fireButton = function(event, target)
-{
- if (!Prado.Button.buttonFired && event.keyCode == 13 && !(event.srcElement && (event.srcElement.tagName.toLowerCase() == "textarea")))
- {
- var defaultButton = document.getElementById ? document.getElementById(target) : document.all[target];
- if (defaultButton && typeof(defaultButton.click) != "undefined")
- {
- Prado.Button.buttonFired = true;
- defaultButton.click();
- event.cancelBubble = true;
- if (event.stopPropagation)
- event.stopPropagation();
- return false;
- }
- }
- return true;
-}
-
-Prado.TextBox = Class.create();
-
-/**
- * Returns FALSE when the "Enter" key is pressed AND when onchange
- * property is defined. The onchange function is called. However,
- * it does not call event listener functions.
- * @return boolean false if "Enter" and onchange property is defined, true otherwise.
- */
-Prado.TextBox.handleReturnKey = function(ev)
-{
- var kc = ev.keyCode != null ? ev.keyCode : ev.charCode;
- if(kc == Event.KEY_RETURN)
- {
- var target = Event.element(ev);
- if(target && isFunction(target.onchange))
- {
- target.onchange();
- Event.stop(ev);
- return false;
- }
- }
- return true;
-}
-
-/**
- * Creates a LinkButton and register the post back to the onclick event.
- */
-/* to finish when doPostback changes
-Prado.LinkButton = Class.create();
-Prado.LinkButton.prototype =
-{
- initialize : function(element, name)
- {
- Event.observe(element, 'click', function(e)
- {
- Prado.doPostback(element, name, '');
- Event.stop(e);
- });
- }
-}*/ \ No newline at end of file
+var Prado = { Version: 2.0 }; \ No newline at end of file
diff --git a/framework/Web/Javascripts/base/validation.js b/framework/Web/Javascripts/base/validation.js
index 4129ad70..ceebc2ba 100644
--- a/framework/Web/Javascripts/base/validation.js
+++ b/framework/Web/Javascripts/base/validation.js
@@ -193,7 +193,7 @@ Prado.Validation.groups = [];
/**
* Second type of grouping.
*/
-Prado.Validation.TargetGroups = [];
+Prado.Validation.TargetGroups = {};
/**
diff --git a/framework/Web/Javascripts/base/validators.js b/framework/Web/Javascripts/base/validators.js
index f281c87e..99d6b416 100644
--- a/framework/Web/Javascripts/base/validators.js
+++ b/framework/Web/Javascripts/base/validators.js
@@ -27,13 +27,10 @@ Prado.Validation.TEmailAddressValidator = Prado.Validation.TRegularExpressionVal
Prado.Validation.TCustomValidator = function()
{
- var trim = Prado.Validation.Util.trim;
- var value = isNull(this.control) ? '' : trim(Form.Element.getValue(this.control));
- var valid = true;
+ var value = isNull(this.control) ? null : $F(this.control);
var func = this.attr.clientvalidationfunction;
- if (isString(func) && func != "")
- eval("valid = (" + func + "(this, value) != false);");
- return valid;
+ eval("var validate = "+func);
+ return validate && isFunction(validate) ? validate(this, value) : true;
}
Prado.Validation.TRangeValidator = function()