From c7fd3e1167b6f2fa7746edbd0fb8f8c1694c61f9 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Thu, 24 Mar 2016 11:54:39 +0100 Subject: Added TReCaptcha2 and wrote doc; fix #560 --- .../source/prado/validator/validation3.js | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'framework/Web/Javascripts') 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 -- cgit v1.2.3