From e5879a4c70cfcb5caa18a097bb16092ad5bb7b85 Mon Sep 17 00:00:00 2001 From: perploug Date: Wed, 30 Oct 2013 10:54:23 +0100 Subject: [PATCH] Macro container --- src/Umbraco.Core/Constants-PropertyEditors.cs | 7 +- .../LegacyPropertyEditorIdToAliasConverter.cs | 3 +- src/Umbraco.Web.UI.Client/src/less/navs.less | 3 + .../macrocontainer.controller.js | 98 +++++++++++++++++++ .../macrocontainer/macrocontainer.html | 28 ++++++ src/Umbraco.Web.UI/Umbraco.Web.UI.csproj | 1 + .../MacroContainerPropertyEditor.cs | 23 +++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + 8 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/views/propertyeditors/macrocontainer/macrocontainer.controller.js create mode 100644 src/Umbraco.Web.UI.Client/src/views/propertyeditors/macrocontainer/macrocontainer.html create mode 100644 src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs diff --git a/src/Umbraco.Core/Constants-PropertyEditors.cs b/src/Umbraco.Core/Constants-PropertyEditors.cs index a6dc544a70..063bb7b27f 100644 --- a/src/Umbraco.Core/Constants-PropertyEditors.cs +++ b/src/Umbraco.Core/Constants-PropertyEditors.cs @@ -169,7 +169,12 @@ namespace Umbraco.Core /// [Obsolete("GUIDs are no longer used to reference Property Editors, use the Alias constant instead. This will be removed in future versions")] public const string MacroContainer = "474FCFF8-9D2D-11DE-ABC6-AD7A56D89593"; - + + /// + /// Alias for the Macro Container datatype. + /// + public const string MacroContainerAlias = "Umbraco.MacroContainer"; + /// /// Guid for the Media Picker datatype. /// diff --git a/src/Umbraco.Core/PropertyEditors/LegacyPropertyEditorIdToAliasConverter.cs b/src/Umbraco.Core/PropertyEditors/LegacyPropertyEditorIdToAliasConverter.cs index ff54057a4b..75144a5938 100644 --- a/src/Umbraco.Core/PropertyEditors/LegacyPropertyEditorIdToAliasConverter.cs +++ b/src/Umbraco.Core/PropertyEditors/LegacyPropertyEditorIdToAliasConverter.cs @@ -115,7 +115,8 @@ namespace Umbraco.Core.PropertyEditors CreateMap(Guid.Parse(Constants.PropertyEditors.DropdownlistPublishingKeys), Constants.PropertyEditors.DropdownlistPublishingKeysAlias); CreateMap(Guid.Parse(Constants.PropertyEditors.FolderBrowser), Constants.PropertyEditors.FolderBrowserAlias); CreateMap(Guid.Parse(Constants.PropertyEditors.Integer), Constants.PropertyEditors.IntegerAlias); - CreateMap(Guid.Parse(Constants.PropertyEditors.ListView), Constants.PropertyEditors.ListViewAlias); + CreateMap(Guid.Parse(Constants.PropertyEditors.ListView), Constants.PropertyEditors.ListViewAlias); + CreateMap(Guid.Parse(Constants.PropertyEditors.MacroContainer), Constants.PropertyEditors.MacroContainerAlias); CreateMap(Guid.Parse(Constants.PropertyEditors.MediaPicker), Constants.PropertyEditors.MediaPickerAlias); CreateMap(Guid.Parse(Constants.PropertyEditors.MemberPicker), Constants.PropertyEditors.MemberPickerAlias); CreateMap(Guid.Parse(Constants.PropertyEditors.MultiNodeTreePicker), Constants.PropertyEditors.MultiNodeTreePickerAlias); diff --git a/src/Umbraco.Web.UI.Client/src/less/navs.less b/src/Umbraco.Web.UI.Client/src/less/navs.less index 7671ab73d6..0e2e26a7a0 100644 --- a/src/Umbraco.Web.UI.Client/src/less/navs.less +++ b/src/Umbraco.Web.UI.Client/src/less/navs.less @@ -4,6 +4,7 @@ .list-icons li{ padding-left: 35px; + max-width: 300px } .list-icons li > i.icon{ @@ -11,6 +12,8 @@ padding-right: 7px; } +.icon.handle{color: @grayLight;} + // BASE CLASS // ---------- diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/macrocontainer/macrocontainer.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/macrocontainer/macrocontainer.controller.js new file mode 100644 index 0000000000..960fc3fd42 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/macrocontainer/macrocontainer.controller.js @@ -0,0 +1,98 @@ +//this controller simply tells the dialogs service to open a memberPicker window +//with a specified callback, this callback will receive an object with a selection on it +angular.module('umbraco') +.controller("Umbraco.PropertyEditors.MacroContainerController", + + function($scope, dialogService, entityResource, macroService, macroResource){ + $scope.renderModel = []; + + if($scope.model.value){ + var macros = $scope.model.value.split('>'); + angular.forEach(macros, function(syntax, key){ + + if(syntax && syntax.length > 10){ + //re-add the char we split on + syntax = syntax + ">"; + var parsed = macroService.parseMacroSyntax(syntax); + parsed.syntax = syntax; + collectDetails(parsed); + + $scope.renderModel.push(parsed); + } + }); + } + + + function collectDetails(macro){ + macro.details = ""; + if(macro.marcoParamsDictionary){ + + angular.forEach((macro.marcoParamsDictionary), function(value, key){ + macro.details += key + ": " + value + " "; + }); + } + } + + function openDialog(index){ + var dialogData = {}; + + if(index){ + var macro = $scope.renderModel[index]; + dialogData = {macroData: macro}; + } + + dialogService.macroPicker({ + scope: $scope, + dialogData : dialogData, + callback: function(data) { + + collectDetails(data); + + //update the raw syntax and the list... + if(index){ + $scope.renderModel[index] = data; + }else{ + $scope.renderModel.push(data); + } + } + }); + } + + + + $scope.edit =function(index){ + openDialog(index); + }; + + $scope.add =function(){ + openDialog(); + }; + + $scope.remove =function(index){ + $scope.renderModel.splice(index, 1); + $scope.macros.splice(index, 1); + $scope.model.value = trim($scope.macros.join(), ","); + }; + + $scope.clear = function() { + $scope.model.value = ""; + $scope.renderModel = []; + $scope.macros = []; + }; + + $scope.$on("formSubmitting", function (ev, args) { + var syntax = []; + angular.forEach($scope.renderModel, function(value, key){ + syntax.push(value.syntax); + }); + + $scope.model.value = syntax.join(""); + }); + + + function trim(str, chr) { + var rgxtrim = (!chr) ? new RegExp('^\\s+|\\s+$', 'g') : new RegExp('^'+chr+'+|'+chr+'+$', 'g'); + return str.replace(rgxtrim, ''); + } + +}); \ No newline at end of file diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/macrocontainer/macrocontainer.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/macrocontainer/macrocontainer.html new file mode 100644 index 0000000000..13adc94635 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/macrocontainer/macrocontainer.html @@ -0,0 +1,28 @@ +
+ + + + +
\ No newline at end of file diff --git a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj index c7a04073fd..356d938301 100644 --- a/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj +++ b/src/Umbraco.Web.UI/Umbraco.Web.UI.csproj @@ -672,6 +672,7 @@ tinyMceConfig.config + Designer scripting.config diff --git a/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs new file mode 100644 index 0000000000..2d7fd061b5 --- /dev/null +++ b/src/Umbraco.Web/PropertyEditors/MacroContainerPropertyEditor.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Umbraco.Core; +using Umbraco.Core.PropertyEditors; + + +namespace Umbraco.Web.PropertyEditors +{ + [PropertyEditor(Constants.PropertyEditors.MacroContainerAlias, "Macro container", "macrocontainer")] + public class MacroContainerPropertyEditor : PropertyEditor + { + protected override PropertyValueEditor CreateValueEditor() + { + //TODO: Need to add some validation to the ValueEditor to ensure that any media chosen actually exists! + + return base.CreateValueEditor(); + } + + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 6b756d6139..0b98ea3d80 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -344,6 +344,7 @@ +