From eb36f30c1184fa08d96d57bd315db434cb7f6b47 Mon Sep 17 00:00:00 2001 From: Tom Fulton Date: Thu, 30 Jan 2014 22:10:15 -0700 Subject: [PATCH 01/11] Update PrevalueEditor to use DataTypes instead of Views --- Gruntfile.js | 1 - app/config/config.views.js | 38 ---------------------------- app/controllers/config.controller.js | 10 ++++---- app/resources/propertyeditor.js | 11 +++++--- app/views/archetype.config.html | 2 +- 5 files changed, 14 insertions(+), 48 deletions(-) delete mode 100644 app/config/config.views.js diff --git a/Gruntfile.js b/Gruntfile.js index df05808..213d089 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -104,7 +104,6 @@ module.exports = function(grunt) { build: { files: [ {expand: true, cwd: 'app/', src: ['package.manifest'], dest: '<%= dest %>', flatten: true}, - {expand: true, cwd: 'app/config/', src: ['config.views.js'], dest: '<%= dest %>/js', flatten: true}, {expand: true, cwd: 'app/views/', src: ['archetype.html', 'archetype.config.html'], dest: '<%= dest %>/views', flatten: true}, {expand: true, cwd: 'app/Umbraco/Umbraco.Archetype/bin/Debug/', src: ['Archetype.dll'], dest: '<%= dest %>/bin', flatten: true} ] diff --git a/app/config/config.views.js b/app/config/config.views.js deleted file mode 100644 index 4818a39..0000000 --- a/app/config/config.views.js +++ /dev/null @@ -1,38 +0,0 @@ -[ - { - "name": "Textstring", - "path": "/umbraco/views/propertyeditors/textbox/textbox.html" - }, - { - "name": "Content Picker", - "path": "/umbraco/views/propertyeditors/contentpicker/contentpicker.html" - }, - { - "name": "Boolean", - "path": "/umbraco/views/propertyeditors/boolean/boolean.html" - }, - { - "name": "Checkbox List", - "path": "/umbraco/views/propertyeditors/checkboxlist/checkboxlist.html" - }, - { - "name": "Radio Buttons", - "path": "/umbraco/views/propertyeditors/radiobuttons/radiobuttons.html" - }, - { - "name": "Date Picker", - "path": "/umbraco/views/propertyeditors/datepicker/datepicker.html" - }, - { - "name": "Dropdown", - "path": "/umbraco/views/propertyeditors/dropdown/dropdown.html" - }, - { - "name": "Textarea", - "path": "/umbraco/views/propertyeditors/textarea/textarea.html" - }, - { - "name": "RTE", - "path": "/umbraco/views/propertyeditors/rte/rte.html" - } -] diff --git a/app/controllers/config.controller.js b/app/controllers/config.controller.js index 8bd5bd9..d6358fd 100644 --- a/app/controllers/config.controller.js +++ b/app/controllers/config.controller.js @@ -4,19 +4,19 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio //console.log($scope.model.value); //define empty items - var newPropertyModel = '{"alias": "", "remove": false, "collapse": false, "label": "", "helpText": "", "view": "", "value": "", "config": ""}'; + var newPropertyModel = '{"alias": "", "remove": false, "collapse": false, "label": "", "helpText": "", "dataTypeId": "-88", "value": "", "config": ""}'; var newFieldsetModel = '{"alias": "", "remove": false, "collapse": false, "labelTemplate": "", "tooltip": "", "icon": "", "label": "", "headerText": "", "footerText": "", "properties": [' + newPropertyModel + ']}'; var defaultFieldsetConfigModel = JSON.parse('{"showAdvancedOptions": false, "hideFieldsetToolbar": false, "enableMultipleFieldsets": false, "hideFieldsetControls": false, "hideFieldsetLabels": false, "hidePropertyLabel": false, "maxFieldsets": null, "fieldsets": [' + newFieldsetModel + ']}'); - + //ini the model $scope.model.value = $scope.model.value || defaultFieldsetConfigModel; //ini the render model initConfigRenderModel(); - //get the available views - propertyEditorResource.getViews().then(function(data){ - $scope.availableViews = data; + //get the available datatypes + propertyEditorResource.getAllDataTypes().then(function(data) { + $scope.availableDataTypes = data; }); //config for the sorting diff --git a/app/resources/propertyeditor.js b/app/resources/propertyeditor.js index d24a34c..8357893 100644 --- a/app/resources/propertyeditor.js +++ b/app/resources/propertyeditor.js @@ -1,9 +1,14 @@ angular.module('umbraco').factory('propertyEditorResource', function($q, $http, umbRequestHelper){ return { - getViews: function() { + getAllDataTypes: function() { + // Hack - grab DataTypes from Tree API, as `dataTypeService.getAll()` isn't implemented yet return umbRequestHelper.resourcePromise( - $http.get("/App_Plugins/Archetype/js/config.views.js"), 'Failed to retreive config for views.' - ); + $http.get("/umbraco/backoffice/UmbracoTrees/DataTypeTree/GetNodes?id=-1&application=developer&tree=&isDialog=false"), 'Failed to retrieve datatypes from tree service' + ).then(function (data) { + return data.map(function(d) { + return { "id": d.id, "name": d.name } + }); + }); } }; }); \ No newline at end of file diff --git a/app/views/archetype.config.html b/app/views/archetype.config.html index c8695f8..2c6fd80 100644 --- a/app/views/archetype.config.html +++ b/app/views/archetype.config.html @@ -53,7 +53,7 @@
- +
From 548113a34a24302f569e206f14a5b64ce7fc2b40 Mon Sep 17 00:00:00 2001 From: Tom Fulton Date: Fri, 31 Jan 2014 00:35:41 -0700 Subject: [PATCH 02/11] Update editor to work with DataTypes instead of Views * Add helper methods for getting DataType info (ie, prevalues, property editor alias) * Add static mapping file of PropertyEditorAlias -> View, as can't seem to find a way to expose this from Umbraco (for now) * Load the view's config from the DataType's prevalues --- Gruntfile.js | 1 + app/config/propertyEditors.views.js | 142 ++++++++++++++++++++++++++++ app/directives/archetypeproperty.js | 28 +++++- app/resources/propertyeditor.js | 19 ++++ 4 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 app/config/propertyEditors.views.js diff --git a/Gruntfile.js b/Gruntfile.js index 213d089..c2bb320 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -105,6 +105,7 @@ module.exports = function(grunt) { files: [ {expand: true, cwd: 'app/', src: ['package.manifest'], dest: '<%= dest %>', flatten: true}, {expand: true, cwd: 'app/views/', src: ['archetype.html', 'archetype.config.html'], dest: '<%= dest %>/views', flatten: true}, + {expand: true, cwd: 'app/config/', src: ['propertyEditors.views.js'], dest: '<%= dest %>/js', flatten: true}, {expand: true, cwd: 'app/Umbraco/Umbraco.Archetype/bin/Debug/', src: ['Archetype.dll'], dest: '<%= dest %>/bin', flatten: true} ] }, diff --git a/app/config/propertyEditors.views.js b/app/config/propertyEditors.views.js new file mode 100644 index 0000000..4162523 --- /dev/null +++ b/app/config/propertyEditors.views.js @@ -0,0 +1,142 @@ +[ + { + "propertyEditorAlias": "Umbraco.CheckBoxList", + "view": "checkboxlist" + }, + { + "propertyEditorAlias": "Umbraco.ColorPickerAlias", + "view": "colorpicker" + }, + { + "propertyEditorAlias": "Umbraco.ContentPickerAlias", + "view": "contentpicker" + }, + { + "propertyEditorAlias": "Umbraco.Date", + "view": "datepicker" + }, + { + "propertyEditorAlias": "Umbraco.DateTime", + "view": "datepicker" + }, + { + "propertyEditorAlias": "Umbraco.DropDown", + "view": "dropdown" + }, + { + "propertyEditorAlias": "Umbraco.DropDownMultiple", + "view": "dropdown" + }, + { + "propertyEditorAlias": "Umbraco.DropDownMultiplePublishKeys", + "view": "dropdown" + }, + { + "propertyEditorAlias": "Umbraco.DropdownlistPublishingKeys", + "view": "dropdown" + }, + { + "propertyEditorAlias": "Umbraco.EmailAddress", + "view": "email" + }, + { + "propertyEditorAlias": "Umbraco.UploadField", + "view": "fileupload" + }, + { + "propertyEditorAlias": "Umbraco.FolderBrowser", + "view": "folderbrowser" + }, + { + "propertyEditorAlias": "Umbraco.Integer", + "view": "integer" + }, + { + "propertyEditorAlias": "Umbraco.NoEdit", + "view": "readonlyvalue" + }, + { + "propertyEditorAlias": "Umbraco.ListView", + "view": "listview" + }, + { + "propertyEditorAlias": "Umbraco.MacroContainer", + "view": "macrocontainer" + }, + { + "propertyEditorAlias": "Umbraco.MarkdownEditor", + "view": "markdowneditor" + }, + { + "propertyEditorAlias": "Umbraco.MediaPicker", + "view": "mediapicker" + }, + { + "propertyEditorAlias": "Umbraco.MemberGroupPicker", + "view": "membergrouppicker" + }, + { + "propertyEditorAlias": "Umbraco.MemberPicker", + "view": "memberpicker" + }, + { + "propertyEditorAlias": "Umbraco.MultiNodeTreePicker", + "view": "contentpicker" + }, + { + "propertyEditorAlias": "Umbraco.MultipleMediaPicker", + "view": "mediapicker" + }, + { + "propertyEditorAlias": "Umbraco.MultipleTextstring", + "view": "multipletextbox" + }, + { + "propertyEditorAlias": "Umbraco.RadioButtonList", + "view": "radiobuttons" + }, + { + "propertyEditorAlias": "Umbraco.RelatedLinks", + "view": "relatedlinks" + }, + { + "propertyEditorAlias": "Umbraco.TinyMCEv3", + "view": "rte" + }, + { + "propertyEditorAlias": "Umbraco.Slider", + "view": "slider" + }, + { + "propertyEditorAlias": "Umbraco.Tags", + "view": "tags" + }, + { + "propertyEditorAlias": "Umbraco.TextboxMultiple", + "view": "textarea" + }, + { + "propertyEditorAlias": "Umbraco.Textbox", + "view": "textbox" + }, + { + "propertyEditorAlias": "Umbraco.TrueFalse", + "view": "boolean" + }, + { + "propertyEditorAlias": "Umbraco.UserPicker", + "view": "entitypicker" + }, + { + "propertyEditorAlias": "Umbraco.NoEdit", + "view": "readonlyvalue" + }, + { + "propertyEditorAlias": "Umbraco.Textbox", + "view": "textbox" + }, + { + "propertyEditorAlias": "Imulus.Archetype", + "view": "/App_Plugins/Archetype/views/archetype.html" + } +] \ No newline at end of file diff --git a/app/directives/archetypeproperty.js b/app/directives/archetypeproperty.js index 3202746..af8dec0 100644 --- a/app/directives/archetypeproperty.js +++ b/app/directives/archetypeproperty.js @@ -1,4 +1,4 @@ -angular.module("umbraco").directive('archetypeProperty', function ($compile, $http) { +angular.module("umbraco").directive('archetypeProperty', function ($compile, $http, propertyEditorResource, umbPropEditorHelper) { function getFieldsetByAlias(fieldsets, alias) { @@ -43,21 +43,39 @@ } var linker = function (scope, element, attrs) { - var configFieldsetModel = getFieldsetByAlias(scope.archetypeConfig.fieldsets, scope.fieldset.alias); - - var view = configFieldsetModel.properties[scope.propertyConfigIndex].view; + var view = ""; var label = configFieldsetModel.properties[scope.propertyConfigIndex].label; + var dataTypeId = configFieldsetModel.properties[scope.propertyConfigIndex].dataTypeId; var config = configFieldsetModel.properties[scope.propertyConfigIndex].config; var alias = configFieldsetModel.properties[scope.propertyConfigIndex].alias; var defaultValue = configFieldsetModel.properties[scope.propertyConfigIndex].value; - + //try to convert the config to a JS object config = jsonOrString(config, scope.archetypeConfig.developerMode, "config"); //try to convert the defaultValue to a JS object defaultValue = jsonOrString(defaultValue, scope.archetypeConfig.developerMode, "defaultValue"); + //grab info for the selected datatype, prepare for view + propertyEditorResource.getDataType(dataTypeId).then(function (data) { + //transform preValues array into object expected by propertyeditor views + var configObj = {}; + _.each(data.preValues, function(p) { + configObj[p.key] = p.value; + }); + config = configObj; + + //determine the view to use [...] and load it + propertyEditorResource.getViewForPropertyEditor(data.selectedEditor).then(function(data) { + var pathToView = umbPropEditorHelper.getViewPath(data); + loadView(pathToView, config, defaultValue, alias, scope, element); + }); + }); + + } + + function loadView(view, config, defaultValue, alias, scope, element) { if (view) { $http.get(view).success(function (data) { diff --git a/app/resources/propertyeditor.js b/app/resources/propertyeditor.js index 8357893..b97fa88 100644 --- a/app/resources/propertyeditor.js +++ b/app/resources/propertyeditor.js @@ -9,6 +9,25 @@ angular.module('umbraco').factory('propertyEditorResource', function($q, $http, return { "id": d.id, "name": d.name } }); }); + }, + getDataType: function(id) { + return umbRequestHelper.resourcePromise( + $http.get("/umbraco/backoffice/UmbracoApi/DataType/GetById?id=" + id), 'Failed to retrieve datatype' + ); + }, + getViewForPropertyEditor: function(alias) { + return umbRequestHelper.resourcePromise( + $http.get("/App_plugins/Archetype/js/propertyEditors.views.js"), 'Failed to retrieve datatype mappings' + ).then(function (data) { + var result = _.find(data, function(d) { + return d.propertyEditorAlias === alias; + }); + + if (result != null) + return result.view; + + return ""; + }); } }; }); \ No newline at end of file From bc7025ec69fe16bb54f046ceffa4b1513e054d9c Mon Sep 17 00:00:00 2001 From: Tom Fulton Date: Fri, 31 Jan 2014 02:27:22 -0700 Subject: [PATCH 03/11] Send over a PropertyEditor's DefaultPreValues when building the property view * Add static mappings for DefaultPreValues to config file (for now - should be able to pull them out) * Merge in the DefaultPreValues to the Prevalues when building the config --- app/config/propertyEditors.views.js | 18 ++++++++++++------ app/directives/archetypeproperty.js | 16 +++++++++++++--- app/resources/propertyeditor.js | 4 ++-- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/config/propertyEditors.views.js b/app/config/propertyEditors.views.js index 4162523..ba99e59 100644 --- a/app/config/propertyEditors.views.js +++ b/app/config/propertyEditors.views.js @@ -13,11 +13,13 @@ }, { "propertyEditorAlias": "Umbraco.Date", - "view": "datepicker" + "view": "datepicker", + "defaultPreValues": [{ "format": "yyyy-MM-dd", "pickTime": false }] }, { "propertyEditorAlias": "Umbraco.DateTime", - "view": "datepicker" + "view": "datepicker", + "format": "yyyy-MM-dd hh:mm:ss" }, { "propertyEditorAlias": "Umbraco.DropDown", @@ -69,7 +71,8 @@ }, { "propertyEditorAlias": "Umbraco.MediaPicker", - "view": "mediapicker" + "view": "mediapicker", + "defaultPreValues": [{ "multiPicker": "0" }] }, { "propertyEditorAlias": "Umbraco.MemberGroupPicker", @@ -81,7 +84,8 @@ }, { "propertyEditorAlias": "Umbraco.MultiNodeTreePicker", - "view": "contentpicker" + "view": "contentpicker", + "defaultPreValues": [{ "multiPicker": "1" }] }, { "propertyEditorAlias": "Umbraco.MultipleMediaPicker", @@ -109,7 +113,8 @@ }, { "propertyEditorAlias": "Umbraco.Tags", - "view": "tags" + "view": "tags", + "defaultPreValues": [{ "group": "default" }] }, { "propertyEditorAlias": "Umbraco.TextboxMultiple", @@ -125,7 +130,8 @@ }, { "propertyEditorAlias": "Umbraco.UserPicker", - "view": "entitypicker" + "view": "entitypicker", + "defaultPreValues": [{ "entityType": "User" }] }, { "propertyEditorAlias": "Umbraco.NoEdit", diff --git a/app/directives/archetypeproperty.js b/app/directives/archetypeproperty.js index af8dec0..b3ca22b 100644 --- a/app/directives/archetypeproperty.js +++ b/app/directives/archetypeproperty.js @@ -67,9 +67,19 @@ angular.module("umbraco").directive('archetypeProperty', function ($compile, $ht config = configObj; //determine the view to use [...] and load it - propertyEditorResource.getViewForPropertyEditor(data.selectedEditor).then(function(data) { - var pathToView = umbPropEditorHelper.getViewPath(data); - loadView(pathToView, config, defaultValue, alias, scope, element); + propertyEditorResource.getPropertyEditorMapping(data.selectedEditor).then(function(propertyEditor) { + var pathToView = umbPropEditorHelper.getViewPath(propertyEditor.view); + + //load in the DefaultPreValues for the PropertyEditor, if any + var defaultConfigObj = {}; + if (propertyEditor.hasOwnProperty('defaultPreValues')) { + _.each(propertyEditor.defaultPreValues, function(p) { + _.extend(defaultConfigObj, p) + }); + } + var mergedConfig = _.extend(defaultConfigObj, config); + + loadView(pathToView, mergedConfig, defaultValue, alias, scope, element); }); }); diff --git a/app/resources/propertyeditor.js b/app/resources/propertyeditor.js index b97fa88..07a1289 100644 --- a/app/resources/propertyeditor.js +++ b/app/resources/propertyeditor.js @@ -15,7 +15,7 @@ angular.module('umbraco').factory('propertyEditorResource', function($q, $http, $http.get("/umbraco/backoffice/UmbracoApi/DataType/GetById?id=" + id), 'Failed to retrieve datatype' ); }, - getViewForPropertyEditor: function(alias) { + getPropertyEditorMapping: function(alias) { return umbRequestHelper.resourcePromise( $http.get("/App_plugins/Archetype/js/propertyEditors.views.js"), 'Failed to retrieve datatype mappings' ).then(function (data) { @@ -24,7 +24,7 @@ angular.module('umbraco').factory('propertyEditorResource', function($q, $http, }); if (result != null) - return result.view; + return result; return ""; }); From 852510fd70d555fa969ae928bfa9e0488046dc77 Mon Sep 17 00:00:00 2001 From: Kevin Giszewski Date: Fri, 31 Jan 2014 09:53:35 -0500 Subject: [PATCH 04/11] Avoid having the fieldset default to error when added --- app/controllers/controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/controller.js b/app/controllers/controller.js index e185504..9389104 100644 --- a/app/controllers/controller.js +++ b/app/controllers/controller.js @@ -214,7 +214,7 @@ //helper to add an empty fieldset to the render model function getEmptyRenderFieldset (fieldsetModel) { - return JSON.parse('{"alias": "' + fieldsetModel.alias + '", "remove": false, "properties": []}'); + return JSON.parse('{"alias": "' + fieldsetModel.alias + '", "remove": false, "isValid": true, "properties": []}'); } //helper for validation From 72a53b27110ad7a9031ff6ceeb7eee8637a73cd7 Mon Sep 17 00:00:00 2001 From: Kevin Giszewski Date: Fri, 31 Jan 2014 10:02:49 -0500 Subject: [PATCH 05/11] Fix issue when clicking on label - Was not focusing the proper fieldset --- app/less/archetype.less | 11 +++-------- app/views/archetype.html | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/less/archetype.less b/app/less/archetype.less index eb06cfc..980a997 100644 --- a/app/less/archetype.less +++ b/app/less/archetype.less @@ -38,8 +38,10 @@ } label{ - width: 75px; float: left; + width: 90%; + margin-bottom: 0; + padding: 0; } } @@ -53,13 +55,6 @@ border-radius: 0 0 0 5px; } -.archetypeEditor fieldset .archetypeFieldsetLabel label{ - float: left; - width: auto; - margin-bottom: 0; - padding: 0; -} - .archetypeEditor .multiPropertyTextbox{ margin-bottom: 3px; } diff --git a/app/views/archetype.html b/app/views/archetype.html index 1cba82e..b98b5f4 100644 --- a/app/views/archetype.html +++ b/app/views/archetype.html @@ -12,11 +12,11 @@
  • -
    +
    -