123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- /*global alert*/
- define([
- 'jquery',
- 'ko',
- 'Magento_Captcha/js/action/refresh'
- ], function ($, ko, refreshAction) {
- 'use strict';
- return function (captchaData) {
- return {
- formId: captchaData.formId,
- imageSource: ko.observable(captchaData.imageSrc),
- visibility: ko.observable(false),
- captchaValue: ko.observable(null),
- isRequired: ko.observable(captchaData.isRequired),
- isCaseSensitive: captchaData.isCaseSensitive,
- imageHeight: captchaData.imageHeight,
- refreshUrl: captchaData.refreshUrl,
- isLoading: ko.observable(false),
- timestamp: null,
- /**
- * @return {String}
- */
- getFormId: function () {
- return this.formId;
- },
- /**
- * @param {String} formId
- */
- setFormId: function (formId) {
- this.formId = formId;
- },
- /**
- * @return {Boolean}
- */
- getIsVisible: function () {
- return this.visibility();
- },
- /**
- * @param {Boolean} flag
- */
- setIsVisible: function (flag) {
- this.visibility(flag);
- },
- /**
- * @return {Boolean}
- */
- getIsRequired: function () {
- return this.isRequired();
- },
- /**
- * @param {Boolean} flag
- */
- setIsRequired: function (flag) {
- this.isRequired(flag);
- },
- /**
- * @return {Boolean}
- */
- getIsCaseSensitive: function () {
- return this.isCaseSensitive;
- },
- /**
- * @param {Boolean} flag
- */
- setIsCaseSensitive: function (flag) {
- this.isCaseSensitive = flag;
- },
- /**
- * @return {String|Number}
- */
- getImageHeight: function () {
- return this.imageHeight;
- },
- /**
- * @param {String|Number}height
- */
- setImageHeight: function (height) {
- this.imageHeight = height;
- },
- /**
- * @return {String}
- */
- getImageSource: function () {
- return this.imageSource;
- },
- /**
- * @param {String} imageSource
- */
- setImageSource: function (imageSource) {
- this.imageSource(imageSource);
- },
- /**
- * @return {String}
- */
- getRefreshUrl: function () {
- return this.refreshUrl;
- },
- /**
- * @param {String} url
- */
- setRefreshUrl: function (url) {
- this.refreshUrl = url;
- },
- /**
- * @return {*}
- */
- getCaptchaValue: function () {
- return this.captchaValue;
- },
- /**
- * @param {*} value
- */
- setCaptchaValue: function (value) {
- this.captchaValue(value);
- },
- /**
- * Refresh captcha.
- */
- refresh: function () {
- var refresh,
- self = this;
- this.isLoading(true);
- refresh = refreshAction(this.getRefreshUrl(), this.getFormId(), this.getImageSource());
- $.when(refresh).done(function () {
- self.isLoading(false);
- });
- }
- };
- };
- });
|