summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts
diff options
context:
space:
mode:
authorFabio Bas <ctrlaltca@gmail.com>2016-03-24 11:54:39 +0100
committerFabio Bas <ctrlaltca@gmail.com>2016-03-24 11:54:39 +0100
commitc7fd3e1167b6f2fa7746edbd0fb8f8c1694c61f9 (patch)
treef67f61a6fd5a8ce4893663ab0c3a56d1df7aeae0 /framework/Web/Javascripts
parentaf129adce0014fc7c71e335804fef4148a057290 (diff)
Added TReCaptcha2 and wrote doc; fix #560
Diffstat (limited to 'framework/Web/Javascripts')
-rw-r--r--framework/Web/Javascripts/source/prado/validator/validation3.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/framework/Web/Javascripts/source/prado/validator/validation3.js b/framework/Web/Javascripts/source/prado/validator/validation3.js
index 24466599..6dcf02e9 100644
--- a/framework/Web/Javascripts/source/prado/validator/validation3.js
+++ b/framework/Web/Javascripts/source/prado/validator/validation3.js
@@ -1239,6 +1239,8 @@ Prado.WebUI.TBaseValidator = jQuery.klass(Prado.WebUI.Control,
case 'TActiveCheckBox':
case 'TActiveRadioButton':
return value;
+ case 'TReCaptcha2':
+ return document.getElementById(this.options.ResponseFieldName).value;
default:
if(this.isListControlType())
return value;
@@ -1994,3 +1996,83 @@ Prado.WebUI.TReCaptchaValidator = jQuery.klass(Prado.WebUI.TBaseValidator,
}
});
+/**
+ * Registry for TReCaptcha2 components
+ */
+Prado.WebUI.TReCaptcha2Instances = {};
+/**
+ * Render callback; called by google's js when loaded
+ */
+TReCaptcha2_onloadCallback = function()
+{
+ jQuery.each(Prado.WebUI.TReCaptcha2Instances, function(index, item) {
+ item.build();
+ });
+}
+
+/**
+ * TReCaptcha2 client-side control.
+ *
+ * @class Prado.WebUI.TReCaptcha2
+ * @extends Prado.WebUI.Control
+ */
+Prado.WebUI.TReCaptcha2 = jQuery.klass(Prado.WebUI.Control,
+{
+ onInit: function(options)
+ {
+ for (key in options) { this[key] = options[key]; }
+ this.options['callback'] = jQuery.proxy(this.callback,this);
+ this.options['expired-callback'] = jQuery.proxy(this.callbackExpired,this);
+
+ Prado.WebUI.TReCaptcha2Instances[this.element.id] = this;
+ },
+ build: function()
+ {
+ if (grecaptcha !== undefined) this.widgetId = grecaptcha.render(this.element, this.options);
+ },
+ callback: function(response)
+ {
+ var responseField = jQuery('#' + this.ID + ' textarea').attr('id');
+ var params = {
+ widgetId: this.widgetId,
+ response: response,
+ responseField: responseField,
+ onCallback: this.onCallback
+ };
+ var request = new Prado.CallbackRequest(this.EventTarget,this);
+ request.setCallbackParameter(params);
+ request.dispatch();
+ },
+ callbackExpired: function()
+ {
+ var responseField = jQuery('#' + this.ID + ' textarea').attr('id');
+ var params = {
+ responseField: responseField,
+ onCallbackExpired: this.onCallbackExpired
+ };
+ var request = new Prado.CallbackRequest(this.EventTarget,this);
+ request.setCallbackParameter(params);
+ request.dispatch();
+ }
+});
+
+/**
+ * TReCaptcha2Validator client-side control.
+ *
+ * @class Prado.WebUI.TReCaptcha2Validator
+ * @extends Prado.WebUI.TBaseValidator
+ */
+Prado.WebUI.TReCaptcha2Validator = jQuery.klass(Prado.WebUI.TBaseValidator,
+{
+ /**
+ * Evaluate validation state
+ * @function {boolean} ?
+ * @return True if the captcha has validate, False otherwise.
+ */
+ evaluateIsValid : function()
+ {
+ var a = this.getValidationValue();
+ var b = this.trim(this.options.InitialValue);
+ return(a != b);
+ }
+}); \ No newline at end of file