From d44e0d8664e62bac8ebb5f2b68bb4526bba81cbe Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Wed, 23 Jan 2019 20:49:08 +0100 Subject: [PATCH 1/4] Set form dirty on color picker value change + update selected item label + clean up unused code (cherry picked from commit 2c40e46d56518cad69db6369e49591fc89316312) --- .../colorpicker/colorpicker.controller.js | 65 +++++++++---------- .../colorpicker/colorpicker.html | 3 +- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.controller.js index 9b3be511a4..15d8906ec0 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.controller.js @@ -1,4 +1,4 @@ -function ColorPickerController($scope) { +function ColorPickerController($scope, angularHelper) { //setup the default config var config = { @@ -77,29 +77,7 @@ function ColorPickerController($scope) { //now make the editor model the array $scope.model.config.items = items; } - - $scope.toggleItem = function (color) { - - var currentColor = ($scope.model.value && $scope.model.value.hasOwnProperty("value")) - ? $scope.model.value.value - : $scope.model.value; - - var newColor; - if (currentColor === color.value) { - // deselect - $scope.model.value = $scope.model.useLabel ? { value: "", label: "" } : ""; - newColor = ""; - } - else { - // select - $scope.model.value = $scope.model.useLabel ? { value: color.value, label: color.label } : color.value; - newColor = color.value; - } - - // this is required to re-validate - $scope.propertyForm.modelValue.$setViewValue(newColor); - }; - + // Method required by the valPropertyValidator directive (returns true if the property editor has at least one color selected) $scope.validateMandatory = function () { var isValid = !$scope.model.validation.mandatory || ( @@ -115,20 +93,35 @@ function ColorPickerController($scope) { } $scope.isConfigured = $scope.model.config && $scope.model.config.items && _.keys($scope.model.config.items).length > 0; - // A color is active if it matches the value and label of the model. - // If the model doesn't store the label, ignore the label during the comparison. - $scope.isActiveColor = function (color) { - - // no value - if (!$scope.model.value) - return false; - + $scope.onSelect = function (color) { // Complex color (value and label)? - if (!$scope.model.value.hasOwnProperty("value")) - return $scope.model.value === color.value; + if (!$scope.model.value.hasOwnProperty("value")) { + // did the value change? + if ($scope.model.value !== color) { + // yes, make sure to set dirty + angularHelper.getCurrentForm($scope).$setDirty(); + } + return; + } - return $scope.model.value.value === color.value && $scope.model.value.label === color.label; - }; + // did the value change? + if ($scope.model.value.value === color) { + // no, skip the rest + return; + } + + // yes, make sure to set dirty + angularHelper.getCurrentForm($scope).$setDirty(); + + // update the label according to the new color + var selectedItem = _.find($scope.model.config.items, function (item) { + return item.value === color; + }); + if (!selectedItem) { + return; + } + $scope.model.value.label = selectedItem.label; + } // Finds the color best matching the model's color, // and sets the model color to that one. This is useful when diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.html index b09d73cee2..0b6e8e7c59 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.html @@ -8,7 +8,8 @@ + use-label="model.useLabel" + on-select="onSelect(color)"> From 0d167c4f2df4ddd1ea11cec06eb478f3dc27c2be Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Wed, 23 Jan 2019 20:54:34 +0100 Subject: [PATCH 2/4] Fix callback (cherry picked from commit 99f0e6c05a80017e1fb3fdb4b3035ed628309f22) --- .../common/directives/components/umbcolorswatches.directive.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbcolorswatches.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbcolorswatches.directive.js index dc67cb464b..494fae9919 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbcolorswatches.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbcolorswatches.directive.js @@ -38,7 +38,7 @@ Use this directive to generate color swatches to pick from. scope.selectedColor = color; if (scope.onSelect) { - scope.onSelect(color); + scope.onSelect({color: color }); } }; } From 218995f9e0377396f6d46d0a32bb681938776728 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Tue, 29 Jan 2019 17:34:05 +0100 Subject: [PATCH 3/4] Set version to 7.13.2 --- src/SolutionInfo.cs | 4 ++-- src/Umbraco.Core/Configuration/UmbracoVersion.cs | 2 +- src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SolutionInfo.cs b/src/SolutionInfo.cs index 88380ddb5f..1d42b70d76 100644 --- a/src/SolutionInfo.cs +++ b/src/SolutionInfo.cs @@ -11,5 +11,5 @@ using System.Resources; [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyFileVersion("7.14.0")] -[assembly: AssemblyInformationalVersion("7.14.0")] +[assembly: AssemblyFileVersion("7.13.2")] +[assembly: AssemblyInformationalVersion("7.13.2")] diff --git a/src/Umbraco.Core/Configuration/UmbracoVersion.cs b/src/Umbraco.Core/Configuration/UmbracoVersion.cs index dc2283758b..6f434796b8 100644 --- a/src/Umbraco.Core/Configuration/UmbracoVersion.cs +++ b/src/Umbraco.Core/Configuration/UmbracoVersion.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Configuration { public class UmbracoVersion { - private static readonly Version Version = new Version("7.14.0"); + private static readonly Version Version = new Version("7.13.2"); /// /// Gets the current version of Umbraco. diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index fc24d2b40f..690628dfbc 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -1038,9 +1038,9 @@ xcopy "$(ProjectDir)"..\packages\SqlServerCE.4.0.0.1\x86\*.* "$(TargetDir)x86\" True True - 7140 + 7132 / - http://localhost:7140 + http://localhost:7132 False False From 19aae9ffdc2765121856ad7b432faa249f2ec37d Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Wed, 30 Jan 2019 16:12:50 +0100 Subject: [PATCH 4/4] Make sure the color picker label is stored on first select (#4325) (cherry picked from commit 4dd51f645a715b76c669f0d93070cdbdbd404d8e) --- .../colorpicker/colorpicker.controller.js | 70 ++++++------------- .../colorpicker/colorpicker.html | 2 +- 2 files changed, 24 insertions(+), 48 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.controller.js index 15d8906ec0..9b38be4791 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.controller.js @@ -12,32 +12,13 @@ function ColorPickerController($scope, angularHelper) { //map back to the model $scope.model.config = config; - function convertArrayToDictionaryArray(model) { - //now we need to format the items in the dictionary because we always want to have an array - var newItems = []; - for (var i = 0; i < model.length; i++) { - newItems.push({ id: model[i], sortOrder: 0, value: model[i] }); - } - - return newItems; - } - - - function convertObjectToDictionaryArray(model) { - //now we need to format the items in the dictionary because we always want to have an array - var newItems = []; - var vals = _.values($scope.model.config.items); - var keys = _.keys($scope.model.config.items); - - for (var i = 0; i < vals.length; i++) { - var label = vals[i].value ? vals[i].value : vals[i]; - newItems.push({ id: keys[i], sortOrder: vals[i].sortOrder, value: label }); - } - - return newItems; - } $scope.isConfigured = $scope.model.config && $scope.model.config.items && _.keys($scope.model.config.items).length > 0; + $scope.model.activeColor = { + value: "", + label: "" + }; + if ($scope.isConfigured) { for (var key in $scope.model.config.items) { @@ -94,33 +75,32 @@ function ColorPickerController($scope, angularHelper) { $scope.isConfigured = $scope.model.config && $scope.model.config.items && _.keys($scope.model.config.items).length > 0; $scope.onSelect = function (color) { - // Complex color (value and label)? - if (!$scope.model.value.hasOwnProperty("value")) { - // did the value change? - if ($scope.model.value !== color) { - // yes, make sure to set dirty - angularHelper.getCurrentForm($scope).$setDirty(); - } - return; - } - // did the value change? if ($scope.model.value.value === color) { - // no, skip the rest + // User clicked the currently selected color + // to remove the selection, they don't want + // to select any color after all. + // Unselect the color and mark as dirty + $scope.model.activeColor = null; + $scope.model.value = null; + angularHelper.getCurrentForm($scope).$setDirty(); + return; } - // yes, make sure to set dirty - angularHelper.getCurrentForm($scope).$setDirty(); - - // update the label according to the new color + // yes, update the model (label + value) according to the new color var selectedItem = _.find($scope.model.config.items, function (item) { return item.value === color; }); if (!selectedItem) { return; } - $scope.model.value.label = selectedItem.label; + $scope.model.value = { + label: selectedItem.label, + value: selectedItem.value + }; + // make sure to set dirty + angularHelper.getCurrentForm($scope).$setDirty(); } // Finds the color best matching the model's color, @@ -128,7 +108,7 @@ function ColorPickerController($scope, angularHelper) { // either the value or label was changed on the data type. function initActiveColor() { - // no value + // no value - initialize default value if (!$scope.model.value) return; @@ -137,10 +117,6 @@ function ColorPickerController($scope, angularHelper) { $scope.model.value = { value: $scope.model.value, label: $scope.model.value }; } - // Complex color (value and label)? - if (!$scope.model.value.hasOwnProperty("value")) - return; - var modelColor = $scope.model.value.value; var modelLabel = $scope.model.value.label; @@ -180,8 +156,8 @@ function ColorPickerController($scope, angularHelper) { // If a match was found, set it as the active color. if (foundItem) { - $scope.model.value.value = foundItem.value; - $scope.model.value.label = foundItem.label; + $scope.model.activeColor.value = foundItem.value; + $scope.model.activeColor.label = foundItem.label; } } diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.html index 0b6e8e7c59..9022de8444 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/colorpicker/colorpicker.html @@ -6,7 +6,7 @@