From b1f3e8d8efbc35dab533bcbb50af207add98ac10 Mon Sep 17 00:00:00 2001 From: Shannon Date: Fri, 23 Aug 2013 18:38:33 +1000 Subject: [PATCH] Drop down list seems to be working with pre-values :) --- .../views/propertyeditors/dropdown/dropdown.controller.js | 4 +++- .../src/views/propertyeditors/dropdown/dropdown.html | 3 +-- src/Umbraco.Web/PropertyEditors/DropDownPreValueEditor.cs | 7 +++---- src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs | 7 +++++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/dropdown/dropdown.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/dropdown/dropdown.controller.js index 579da61857..ce75a5ab04 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/dropdown/dropdown.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/dropdown/dropdown.controller.js @@ -8,12 +8,14 @@ angular.module("umbraco").controller("Umbraco.Editors.DropdownController", keyName: "alias", valueName: "name" }; - + //map the user config angular.extend(config, $scope.model.config); //map back to the model $scope.model.config = config; + $scope.selectExpression = "e." + config.keyName + " as e." + config.valueName + " for e in model.config.items"; + //now we need to format the items in the array because we always want to have a dictionary for (var i = 0; i < $scope.model.config.items.length; i++) { if (angular.isString($scope.model.config.items[i])) { diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/dropdown/dropdown.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/dropdown/dropdown.html index 5249d017e2..a4e7079c1b 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/dropdown/dropdown.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/dropdown/dropdown.html @@ -1,7 +1,6 @@
+ ng-options="{{selectExpression}}">
\ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/DropDownPreValueEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownPreValueEditor.cs index 7d04f1ad9a..1db5cc9c3d 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownPreValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownPreValueEditor.cs @@ -14,7 +14,7 @@ namespace Umbraco.Web.PropertyEditors { /// - /// The editor is expecting a json array for a field with a key named "temp" so we need to format the persisted values + /// The editor is expecting a json array for a field with a key named "items" so we need to format the persisted values /// to this format to be used in the editor. /// /// @@ -24,9 +24,8 @@ namespace Umbraco.Web.PropertyEditors { var dictionary = PreValueCollection.AsDictionary(persistedPreVals); var arrayOfVals = dictionary.Select(item => item.Value).ToList(); - //var json = JsonConvert.SerializeObject(arrayOfVals); - return new Dictionary { { "temp", arrayOfVals } }; + return new Dictionary { { "items", arrayOfVals } }; } /// @@ -42,7 +41,7 @@ namespace Umbraco.Web.PropertyEditors /// public override IDictionary FormatDataForPersistence(IDictionary editorValue, PreValueCollection currentValue) { - var val = editorValue["temp"] as JArray; + var val = editorValue["items"] as JArray; var result = new Dictionary(); if (val == null) diff --git a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs index f668dcd9cf..6f8a8429a6 100644 --- a/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/DropDownPropertyEditor.cs @@ -17,10 +17,13 @@ namespace Umbraco.Web.PropertyEditors new PreValueField { Description = "Add and remove values for the drop down list", - //we're going to call this 'temp' because we are going to override the + //we're going to call this 'items' because we are going to override the //serialization of the pre-values to ensure that each one gets saved with it's own key //(new db row per pre-value, thus to maintain backwards compatibility) - Key = "temp", + + //It's also important to note that by default the dropdown angular controller is expecting the + // config options to come in with a property called 'items' + Key = "items", Name = ui.Text("editdatatype", "addPrevalue"), View = "Views/PropertyEditors/dropdown/dropdown.prevalue.html" }