From 952534ca6db69072fd9db8aab1940727e26bfcca Mon Sep 17 00:00:00 2001 From: "Partica, Cristian" Date: Fri, 1 Jul 2016 16:38:45 -0500 Subject: [PATCH 1/5] MAGETWO-54779: [GitHub] Image size for Product Watermarks can't be set #5270 - adding custom validation for AAAxBBB type of inputs in validation rules with translation --- app/code/Magento/Catalog/i18n/en_US.csv | 1 + .../ui_component/design_config_form.xml | 9 ++- .../web/component/image-size-field.js | 57 +++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js diff --git a/app/code/Magento/Catalog/i18n/en_US.csv b/app/code/Magento/Catalog/i18n/en_US.csv index 0745c98d7169a..6b8a2bc607d6b 100644 --- a/app/code/Magento/Catalog/i18n/en_US.csv +++ b/app/code/Magento/Catalog/i18n/en_US.csv @@ -700,6 +700,7 @@ Image,Image "Allowed file types: jpeg, gif, png.","Allowed file types: jpeg, gif, png." "Image Opacity","Image Opacity" "Example format: 200x300.","Example format: 200x300." +"The value is not within the specified format eg: 200x300","The value is not within the specified format eg: 200x300" "Image Position","Image Position" Small,Small "Attribute Label","Attribute Label" diff --git a/app/code/Magento/Catalog/view/adminhtml/ui_component/design_config_form.xml b/app/code/Magento/Catalog/view/adminhtml/ui_component/design_config_form.xml index dc8ced173bc54..9852ad74121c8 100644 --- a/app/code/Magento/Catalog/view/adminhtml/ui_component/design_config_form.xml +++ b/app/code/Magento/Catalog/view/adminhtml/ui_component/design_config_form.xml @@ -55,12 +55,13 @@ + Magento_Catalog/component/image-size-field Image Size text input watermark_image_size - true + true Example format: 200x300. @@ -118,12 +119,13 @@ + Magento_Catalog/component/image-size-field Image Size text input watermark_thumbnail_size - true + true Example format: 200x300. @@ -181,12 +183,13 @@ + Magento_Catalog/component/image-size-field Image Size text input watermark_small_image_size - true + true Example format: 200x300. diff --git a/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js b/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js new file mode 100644 index 0000000000000..9f4c05214ac8b --- /dev/null +++ b/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js @@ -0,0 +1,57 @@ +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'jquery', + 'underscore', + 'Magento_Ui/js/lib/validation/utils', + 'Magento_Ui/js/form/element/abstract', + 'Magento_Ui/js/lib/validation/validator' +], function ($, _, utils, Abstract, validator) { + 'use strict'; + + validator.addRule( + 'validate-image-size-range', + function (value) { + var numValue, + dataAttrRange = /^(\d+)x(\d+)?$/, + result = false, + m; + + if (utils.isEmptyNoTrim(value)) { + return true; + } + numValue = utils.parseNumber(value); + + if (isNaN(numValue)) { + return false; + } + + m = dataAttrRange.exec(value); + + if (m) { + if (m.length === 3) { + result = m[1] && m[2]; + } + } + + return result; + }, + $.mage.__('The value is not within the specified format eg: 200x300') + ); + + return Abstract.extend({ + + /** + * Checks for relevant value + * + * @param {*} value + * @returns {Boolean} + */ + isRangeCorrect: function (value) { + return validator('validate-image-size-range', value); + } + }); +}); From e4fb73ea6a67cd4c110a591d6e69dbb195a89809 Mon Sep 17 00:00:00 2001 From: Cristian Partica Date: Tue, 23 Aug 2016 14:49:18 -0500 Subject: [PATCH 2/5] MAGETWO-54779: [GitHub] Image size for Product Watermarks can't be set #5270 - modifying js file for simplicity as per code review --- .../web/component/image-size-field.js | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js b/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js index 9f4c05214ac8b..37f9ef8f997e7 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js +++ b/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js @@ -5,39 +5,25 @@ define([ 'jquery', - 'underscore', 'Magento_Ui/js/lib/validation/utils', 'Magento_Ui/js/form/element/abstract', 'Magento_Ui/js/lib/validation/validator' -], function ($, _, utils, Abstract, validator) { +], function ($, utils, Abstract, validator) { 'use strict'; validator.addRule( 'validate-image-size-range', function (value) { - var numValue, - dataAttrRange = /^(\d+)x(\d+)?$/, - result = false, + var dataAttrRange = /^(\d+)x(\d+)$/, m; if (utils.isEmptyNoTrim(value)) { return true; } - numValue = utils.parseNumber(value); - - if (isNaN(numValue)) { - return false; - } m = dataAttrRange.exec(value); - if (m) { - if (m.length === 3) { - result = m[1] && m[2]; - } - } - - return result; + return m && m.length === 3 && m[1] > 0 && m[2] > 0; }, $.mage.__('The value is not within the specified format eg: 200x300') ); From e62316b4db2cfb87291ef887241c5247aa461849 Mon Sep 17 00:00:00 2001 From: Cristian Partica Date: Tue, 23 Aug 2016 14:56:35 -0500 Subject: [PATCH 3/5] MAGETWO-54779: [GitHub] Image size for Product Watermarks can't be set #5270 - modifying js file for simplicity as per code review --- .../view/adminhtml/web/component/image-size-field.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js b/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js index 37f9ef8f997e7..d44dd454fc1da 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js +++ b/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js @@ -23,7 +23,7 @@ define([ m = dataAttrRange.exec(value); - return m && m.length === 3 && m[1] > 0 && m[2] > 0; + return !!(m && m[1] > 0 && m[2] > 0); }, $.mage.__('The value is not within the specified format eg: 200x300') ); @@ -33,11 +33,10 @@ define([ /** * Checks for relevant value * - * @param {*} value * @returns {Boolean} */ - isRangeCorrect: function (value) { - return validator('validate-image-size-range', value); + isRangeCorrect: function () { + return validator('validate-image-size-range', this.value()).passed; } }); }); From 6625e8c5484f3e469dbcc0c0719836fa5d0e896c Mon Sep 17 00:00:00 2001 From: Cristian Partica Date: Tue, 23 Aug 2016 15:22:01 -0500 Subject: [PATCH 4/5] MAGETWO-54779: [GitHub] Image size for Product Watermarks can't be set #5270 - fixing error phrase --- app/code/Magento/Catalog/i18n/en_US.csv | 2 +- .../Catalog/view/adminhtml/web/component/image-size-field.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/i18n/en_US.csv b/app/code/Magento/Catalog/i18n/en_US.csv index 6b8a2bc607d6b..a1f1b2e5beb6b 100644 --- a/app/code/Magento/Catalog/i18n/en_US.csv +++ b/app/code/Magento/Catalog/i18n/en_US.csv @@ -700,7 +700,7 @@ Image,Image "Allowed file types: jpeg, gif, png.","Allowed file types: jpeg, gif, png." "Image Opacity","Image Opacity" "Example format: 200x300.","Example format: 200x300." -"The value is not within the specified format eg: 200x300","The value is not within the specified format eg: 200x300" +"This value does not follow the specified format (for example, 200X300).","This value does not follow the specified format (for example, 200X300)." "Image Position","Image Position" Small,Small "Attribute Label","Attribute Label" diff --git a/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js b/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js index d44dd454fc1da..b330ccfd8c125 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js +++ b/app/code/Magento/Catalog/view/adminhtml/web/component/image-size-field.js @@ -25,7 +25,7 @@ define([ return !!(m && m[1] > 0 && m[2] > 0); }, - $.mage.__('The value is not within the specified format eg: 200x300') + $.mage.__('This value does not follow the specified format (for example, 200X300).') ); return Abstract.extend({ From 6ae23bcd7c082dd0c8b8d812fdd78cf44ca4058f Mon Sep 17 00:00:00 2001 From: Cristian Partica Date: Wed, 24 Aug 2016 17:54:01 -0500 Subject: [PATCH 5/5] MAGETWO-54779: [GitHub] Image size for Product Watermarks can't be set #5270 - fixing field for swatches image --- .../view/adminhtml/ui_component/design_config_form.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Swatches/view/adminhtml/ui_component/design_config_form.xml b/app/code/Magento/Swatches/view/adminhtml/ui_component/design_config_form.xml index 1b5ec69e5d5c2..0891fb3518376 100644 --- a/app/code/Magento/Swatches/view/adminhtml/ui_component/design_config_form.xml +++ b/app/code/Magento/Swatches/view/adminhtml/ui_component/design_config_form.xml @@ -48,12 +48,13 @@ + Magento_Catalog/component/image-size-field Image Size text input watermark_swatch_image_size - true + true Example format: 200x300.