diff --git a/src/Umbraco.Core/Constants-Applications.cs b/src/Umbraco.Core/Constants-Applications.cs index e238c70d45..175fa826d5 100644 --- a/src/Umbraco.Core/Constants-Applications.cs +++ b/src/Umbraco.Core/Constants-Applications.cs @@ -92,12 +92,7 @@ /// alias for the dictionary tree. /// public const string Dictionary = "dictionary"; - - /// - /// The dictionary obsolete. - /// - public const string DictionaryObsolete = "dictionary-obsolete"; - + public const string Stylesheets = "stylesheets"; /// @@ -140,4 +135,4 @@ } -} \ No newline at end of file +} diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/dictionary.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/dictionary.resource.js index 2b673b1e76..416c575724 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/dictionary.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/dictionary.resource.js @@ -3,7 +3,7 @@ * @name umbraco.resources.dictionaryResource * @description Loads in data for dictionary items **/ -function dictionaryResource($q, $http, umbRequestHelper, umbDataFormatter) { +function dictionaryResource($q, $http, $location, umbRequestHelper, umbDataFormatter) { /** * @ngdoc method @@ -146,12 +146,41 @@ function dictionaryResource($q, $http, umbRequestHelper, umbDataFormatter) { "Failed to get list"); } + /** + * @ngdoc method + * @name umbraco.resources.dictionaryResource#getSection + * @methodOf umbraco.resources.dictionaryResource + * + * @description + * Gets the current section that the dictionary tree is in (only settings and translation are allowed currently) + * + * ##usage + *
+         * var section = dictionaryResource.getSection();
+         * 
+ * + * @returns string. + * + **/ + function getSection() { + var section = $location.$$path; + if (section.startsWith("/")) { + section = section.substring(1, section.length); + } + var firstSlash = section.indexOf("/"); + if (firstSlash !== -1) { + section = section.substring(0, firstSlash); + } + return section; + } + var resource = { deleteById: deleteById, create: create, getById: getById, save: save, - getList : getList + getList : getList, + getSection: getSection }; return resource; @@ -159,4 +188,4 @@ function dictionaryResource($q, $http, umbRequestHelper, umbDataFormatter) { } -angular.module("umbraco.resources").factory("dictionaryResource", dictionaryResource); \ No newline at end of file +angular.module("umbraco.resources").factory("dictionaryResource", dictionaryResource); diff --git a/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.create.controller.js b/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.create.controller.js index d55c26bc37..cd92053aea 100644 --- a/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.create.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.create.controller.js @@ -7,37 +7,38 @@ * The controller for creating dictionary items */ function DictionaryCreateController($scope, $location, dictionaryResource, navigationService, notificationsService, formHelper) { - vm = this; + var vm = this; - vm.itemKey = ''; + vm.itemKey = ""; - function createItem() { + function createItem() { - var node = $scope.dialogOptions.currentNode; + var node = $scope.dialogOptions.currentNode; - dictionaryResource.create(node.id, vm.itemKey).then(function(data) { - navigationService.hideMenu(); + dictionaryResource.create(node.id, vm.itemKey).then(function (data) { + navigationService.hideMenu(); - // set new item as active in tree - var currPath = node.path ? node.path : "-1"; - navigationService.syncTree({ tree: "dictionary", path: currPath + "," + data, forceReload: true, activate: true }); + // set new item as active in tree + var currPath = node.path ? node.path : "-1"; + navigationService.syncTree({ tree: "dictionary", path: currPath + "," + data, forceReload: true, activate: true }); - // reset form state - formHelper.resetForm({ scope: $scope }); + // reset form state + formHelper.resetForm({ scope: $scope }); - // navigate to edit view - $location.path("/settings/dictionary/edit/" + data); + // navigate to edit view + var section = dictionaryResource.getSection(); + $location.path("/" + section + "/dictionary/edit/" + data); - - },function(err) { - if (err.data && err.data.message) { - notificationsService.error(err.data.message); - navigationService.hideMenu(); - } - }); - } - vm.createItem = createItem; + }, function (err) { + if (err.data && err.data.message) { + notificationsService.error(err.data.message); + navigationService.hideMenu(); + } + }); + } + + vm.createItem = createItem; } -angular.module("umbraco").controller("Umbraco.Editors.Dictionary.CreateController", DictionaryCreateController); \ No newline at end of file +angular.module("umbraco").controller("Umbraco.Editors.Dictionary.CreateController", DictionaryCreateController); diff --git a/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.delete.controller.js b/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.delete.controller.js index e91f57429f..56aa80d5f0 100644 --- a/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.delete.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.delete.controller.js @@ -7,43 +7,44 @@ * The controller for deleting dictionary items */ function DictionaryDeleteController($scope, $location, dictionaryResource, treeService, navigationService) { - vm = this; + var vm = this; - function cancel() { - navigationService.hideDialog(); - } + function cancel() { + navigationService.hideDialog(); + } - function performDelete() { - // stop from firing again on double-click - if ($scope.busy) { return false; } + function performDelete() { + // stop from firing again on double-click + if ($scope.busy) { return false; } - //mark it for deletion (used in the UI) - $scope.currentNode.loading = true; - $scope.busy = true; + //mark it for deletion (used in the UI) + $scope.currentNode.loading = true; + $scope.busy = true; - dictionaryResource.deleteById($scope.currentNode.id).then(function () { - $scope.currentNode.loading = false; + dictionaryResource.deleteById($scope.currentNode.id).then(function () { + $scope.currentNode.loading = false; - // get the parent id - var parentId = $scope.currentNode.parentId; + // get the parent id + var parentId = $scope.currentNode.parentId; - treeService.removeNode($scope.currentNode); + treeService.removeNode($scope.currentNode); - navigationService.hideMenu(); + navigationService.hideMenu(); - if (parentId !== "-1") { - // set the view of the parent item - $location.path("/settings/dictionary/edit/" + parentId); - } else { - // we have no parent, so redirect to section - $location.path("/settings/"); - } - - }); - } + var section = dictionaryResource.getSection(); + if (parentId !== "-1") { + // set the view of the parent item + $location.path("/" + section + "/dictionary/edit/" + parentId); + } else { + // we have no parent, so redirect to section + $location.path("/" + section + "/"); + } - vm.cancel = cancel; - vm.performDelete = performDelete; + }); + } + + vm.cancel = cancel; + vm.performDelete = performDelete; } -angular.module("umbraco").controller("Umbraco.Editors.Dictionary.DeleteController", DictionaryDeleteController); \ No newline at end of file +angular.module("umbraco").controller("Umbraco.Editors.Dictionary.DeleteController", DictionaryDeleteController); diff --git a/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionairy.edit.controller.js b/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.edit.controller.js similarity index 92% rename from src/Umbraco.Web.UI.Client/src/views/dictionary/dictionairy.edit.controller.js rename to src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.edit.controller.js index cdb9411342..1b9d5c3f4c 100644 --- a/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionairy.edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.edit.controller.js @@ -7,7 +7,7 @@ * The controller for editing dictionary items */ function DictionaryEditController($scope, $routeParams, dictionaryResource, treeService, navigationService, appState, editorState, contentEditingHelper, formHelper, notificationsService, localizationService) { - vm = this; + var vm = this; //setup scope vars vm.nameDirty = false; @@ -17,7 +17,7 @@ function DictionaryEditController($scope, $routeParams, dictionaryResource, tree vm.page.menu = {}; vm.page.menu.currentSection = appState.getSectionState("currentSection"); vm.page.menu.currentNode = null; - vm.description = ''; + vm.description = ""; function loadDictionary() { @@ -42,8 +42,8 @@ function DictionaryEditController($scope, $routeParams, dictionaryResource, tree } function bindDictionary(data) { - localizationService.localize('dictionaryItem_description').then(function (value) { - vm.description = value.replace('%0%', data.name); + localizationService.localize("dictionaryItem_description").then(function (value) { + vm.description = value.replace("%0%", data.name); }); // create data for umb-property displaying @@ -104,7 +104,7 @@ function DictionaryEditController($scope, $routeParams, dictionaryResource, tree $scope.$watch("vm.content.name", function (newVal, oldVal) { //when the value changes, we need to set the name dirty - if (newVal && (newVal !== oldVal) && typeof(oldVal) !== 'undefined') { + if (newVal && (newVal !== oldVal) && typeof(oldVal) !== "undefined") { vm.nameDirty = true; } }); @@ -112,4 +112,4 @@ function DictionaryEditController($scope, $routeParams, dictionaryResource, tree onInit(); } -angular.module("umbraco").controller("Umbraco.Editors.Dictionary.EditController", DictionaryEditController); \ No newline at end of file +angular.module("umbraco").controller("Umbraco.Editors.Dictionary.EditController", DictionaryEditController); diff --git a/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.list.controller.js b/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.list.controller.js index 69c1a4be75..8fa91459aa 100644 --- a/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.list.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/dictionary/dictionary.list.controller.js @@ -7,8 +7,8 @@ * The controller for listting dictionary items */ function DictionaryListController($scope, $location, dictionaryResource, localizationService) { - vm = this; - vm.title = 'Dictionary overview'; + var vm = this; + vm.title = "Dictionary overview"; vm.loading = false; vm.items = []; @@ -26,13 +26,14 @@ function DictionaryListController($scope, $location, dictionaryResource, localiz } function clickItem(id) { - $location.path("/settings/dictionary/edit/" + id); + var section = dictionaryResource.getSection(); + $location.path("/" + section + "/dictionary/edit/" + id); } vm.clickItem = clickItem; function onInit() { - localizationService.localize('dictionaryItem_overviewTitle').then(function (value) { + localizationService.localize("dictionaryItem_overviewTitle").then(function (value) { vm.title = value; }); @@ -43,4 +44,4 @@ function DictionaryListController($scope, $location, dictionaryResource, localiz } -angular.module("umbraco").controller("Umbraco.Editors.Dictionary.ListController", DictionaryListController); \ No newline at end of file +angular.module("umbraco").controller("Umbraco.Editors.Dictionary.ListController", DictionaryListController); diff --git a/src/Umbraco.Web.UI/config/trees.Release.config b/src/Umbraco.Web.UI/config/trees.Release.config index c0205c7db4..e4be139d22 100644 --- a/src/Umbraco.Web.UI/config/trees.Release.config +++ b/src/Umbraco.Web.UI/config/trees.Release.config @@ -16,8 +16,9 @@ - + + @@ -44,4 +45,4 @@ - \ No newline at end of file + diff --git a/src/Umbraco.Web.UI/config/trees.config b/src/Umbraco.Web.UI/config/trees.config index cf2c4091d2..eca46ed65c 100644 --- a/src/Umbraco.Web.UI/config/trees.config +++ b/src/Umbraco.Web.UI/config/trees.config @@ -14,8 +14,7 @@ - - + @@ -24,21 +23,22 @@ - - - - - - - - - - - + + + + + + + + + + + + - \ No newline at end of file + diff --git a/src/Umbraco.Web.UI/config/umbracoSettings.config b/src/Umbraco.Web.UI/config/umbracoSettings.config index 658eb07f0a..221b82aba0 100644 --- a/src/Umbraco.Web.UI/config/umbracoSettings.config +++ b/src/Umbraco.Web.UI/config/umbracoSettings.config @@ -14,7 +14,7 @@ - umbracoWidth + umbracoWidth umbracoHeight umbracoBytes umbracoExtension diff --git a/src/Umbraco.Web/Editors/DictionaryController.cs b/src/Umbraco.Web/Editors/DictionaryController.cs index f2ff66e5bf..4679a01412 100644 --- a/src/Umbraco.Web/Editors/DictionaryController.cs +++ b/src/Umbraco.Web/Editors/DictionaryController.cs @@ -1,23 +1,21 @@ -namespace Umbraco.Web.Editors +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Http; +using System.Web.Http; +using AutoMapper; +using Umbraco.Core.Models; +using Umbraco.Web.Models.ContentEditing; +using Umbraco.Web.Mvc; +using Umbraco.Web.UI; +using Umbraco.Web.WebApi; +using Umbraco.Web.WebApi.Filters; +using Constants = Umbraco.Core.Constants; +using Notification = Umbraco.Web.Models.ContentEditing.Notification; + +namespace Umbraco.Web.Editors { - using System; - using System.Collections.Generic; - using System.Configuration; - using System.Net; - using System.Net.Http; - using System.Web.Http; - - using AutoMapper; - - using Umbraco.Core.Models; - using Umbraco.Web.Models.ContentEditing; - using Umbraco.Web.Mvc; - using Umbraco.Web.UI; - using Umbraco.Web.WebApi; - using Umbraco.Web.WebApi.Filters; - - using Constants = Umbraco.Core.Constants; - + /// /// /// The API controller used for editing dictionary items /// @@ -39,15 +37,14 @@ [HttpPost] public HttpResponseMessage DeleteById(int id) { - var foundDictionary = this.Services.LocalizationService.GetDictionaryItemById(id); + var foundDictionary = Services.LocalizationService.GetDictionaryItemById(id); + if (foundDictionary == null) - { throw new HttpResponseException(HttpStatusCode.NotFound); - } + + Services.LocalizationService.Delete(foundDictionary, Security.CurrentUser.Id); - this.Services.LocalizationService.Delete(foundDictionary, Security.CurrentUser.Id); - - return this.Request.CreateResponse(HttpStatusCode.OK); + return Request.CreateResponse(HttpStatusCode.OK); } /// @@ -66,19 +63,16 @@ public HttpResponseMessage Create(int parentId, string key) { if (string.IsNullOrEmpty(key)) - { - - return this.Request + return Request .CreateNotificationValidationErrorResponse("Key can not be empty;"); // TODO translate - } - if (this.Services.LocalizationService.DictionaryItemExists(key)) + if (Services.LocalizationService.DictionaryItemExists(key)) { - var message = this.Services.TextService.Localize( + var message = Services.TextService.Localize( "dictionaryItem/changeKeyError", - this.Security.CurrentUser.GetUserCulture(this.Services.TextService), + Security.CurrentUser.GetUserCulture(Services.TextService), new Dictionary { { "0", key } }); - return this.Request.CreateNotificationValidationErrorResponse(message); + return Request.CreateNotificationValidationErrorResponse(message); } try @@ -86,22 +80,20 @@ Guid? parentGuid = null; if (parentId > 0) - { - parentGuid = this.Services.LocalizationService.GetDictionaryItemById(parentId).Key; - } + parentGuid = Services.LocalizationService.GetDictionaryItemById(parentId).Key; - var item = this.Services.LocalizationService.CreateDictionaryItemWithIdentity( + var item = Services.LocalizationService.CreateDictionaryItemWithIdentity( key, parentGuid, string.Empty); - return this.Request.CreateResponse(HttpStatusCode.OK, item.Id); + return Request.CreateResponse(HttpStatusCode.OK, item.Id); } catch (Exception exception) { - this.Logger.Error(this.GetType(), "Error creating dictionary", exception); - return this.Request.CreateNotificationValidationErrorResponse("Error creating dictionary item"); + Logger.Error(GetType(), "Error creating dictionary", exception); + return Request.CreateNotificationValidationErrorResponse("Error creating dictionary item"); } } @@ -119,12 +111,10 @@ /// public DictionaryDisplay GetById(int id) { - var dictionary = this.Services.LocalizationService.GetDictionaryItemById(id); + var dictionary = Services.LocalizationService.GetDictionaryItemById(id); if (dictionary == null) - { throw new HttpResponseException(HttpStatusCode.NotFound); - } return Mapper.Map(dictionary); } @@ -141,54 +131,55 @@ public DictionaryDisplay PostSave(DictionarySave dictionary) { var dictionaryItem = - this.Services.LocalizationService.GetDictionaryItemById(int.Parse(dictionary.Id.ToString())); + Services.LocalizationService.GetDictionaryItemById(int.Parse(dictionary.Id.ToString())); - if (dictionaryItem != null) + if (dictionaryItem == null) + throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Dictionary item does not exist")); + + var userCulture = Security.CurrentUser.GetUserCulture(Services.TextService); + + if (dictionary.NameIsDirty) { - var userCulture = this.Security.CurrentUser.GetUserCulture(this.Services.TextService); + // if the name (key) has changed, we need to check if the new key does not exist + var dictionaryByKey = Services.LocalizationService.GetDictionaryItemByKey(dictionary.Name); - if (dictionary.NameIsDirty) + if (dictionaryByKey != null && dictionaryItem.Id != dictionaryByKey.Id) { - // if the name (key) has changed, we need to check if the new key does not exist - var dictionaryByKey = this.Services.LocalizationService.GetDictionaryItemByKey(dictionary.Name); - if (dictionaryByKey != null && dictionaryItem.Id != dictionaryByKey.Id) - { - - var message = this.Services.TextService.Localize( - "dictionaryItem/changeKeyError", - userCulture, - new Dictionary { { "0", dictionary.Name } }); - this.ModelState.AddModelError("Name", message); - throw new HttpResponseException(this.Request.CreateValidationErrorResponse(ModelState)); - } - - dictionaryItem.ItemKey = dictionary.Name; + var message = Services.TextService.Localize( + "dictionaryItem/changeKeyError", + userCulture, + new Dictionary { { "0", dictionary.Name } }); + ModelState.AddModelError("Name", message); + throw new HttpResponseException(Request.CreateValidationErrorResponse(ModelState)); } - foreach (var translation in dictionary.Translations) - { - this.Services.LocalizationService.AddOrUpdateDictionaryValue(dictionaryItem, this.Services.LocalizationService.GetLanguageById(translation.LanguageId), translation.Translation); - } - - try - { - this.Services.LocalizationService.Save(dictionaryItem); - - var model = Mapper.Map(dictionaryItem); - - model.Notifications.Add(new Models.ContentEditing.Notification(this.Services.TextService.Localize("speechBubbles/dictionaryItemSaved", userCulture), string.Empty, SpeechBubbleIcon.Success)); - - return model; - } - catch (Exception e) - { - this.Logger.Error(this.GetType(), "Error saving dictionary", e); - throw new HttpResponseException(this.Request.CreateNotificationValidationErrorResponse("Something went wrong saving dictionary")); - } + dictionaryItem.ItemKey = dictionary.Name; } - throw new HttpResponseException(this.Request.CreateNotificationValidationErrorResponse("Dictionary item does not exist")); + foreach (var translation in dictionary.Translations) + { + Services.LocalizationService.AddOrUpdateDictionaryValue(dictionaryItem, + Services.LocalizationService.GetLanguageById(translation.LanguageId), translation.Translation); + } + + try + { + Services.LocalizationService.Save(dictionaryItem); + + var model = Mapper.Map(dictionaryItem); + + model.Notifications.Add(new Notification( + Services.TextService.Localize("speechBubbles/dictionaryItemSaved", userCulture), string.Empty, + SpeechBubbleIcon.Success)); + + return model; + } + catch (Exception e) + { + Logger.Error(GetType(), "Error saving dictionary", e); + throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("Something went wrong saving dictionary")); + } } /// @@ -201,15 +192,15 @@ { var list = new List(); - var level = 0; + const int level = 0; - foreach (var dictionaryItem in this.Services.LocalizationService.GetRootDictionaryItems()) + foreach (var dictionaryItem in Services.LocalizationService.GetRootDictionaryItems()) { var item = Mapper.Map(dictionaryItem); item.Level = 0; list.Add(item); - this.GetChildItemsForList(dictionaryItem, level + 1, list); + GetChildItemsForList(dictionaryItem, level + 1, list); } return list; @@ -229,14 +220,14 @@ /// private void GetChildItemsForList(IDictionaryItem dictionaryItem, int level, List list) { - foreach (var childItem in this.Services.LocalizationService.GetDictionaryItemChildren( + foreach (var childItem in Services.LocalizationService.GetDictionaryItemChildren( dictionaryItem.Key)) { var item = Mapper.Map(childItem); item.Level = level; list.Add(item); - this.GetChildItemsForList(childItem, level + 1, list); + GetChildItemsForList(childItem, level + 1, list); } } } diff --git a/src/Umbraco.Web/Models/ContentEditing/DictionaryDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/DictionaryDisplay.cs index 94f680d492..bb93c72ac7 100644 --- a/src/Umbraco.Web/Models/ContentEditing/DictionaryDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/DictionaryDisplay.cs @@ -1,9 +1,9 @@ -namespace Umbraco.Web.Models.ContentEditing -{ - using System; - using System.Collections.Generic; - using System.Runtime.Serialization; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +namespace Umbraco.Web.Models.ContentEditing +{ /// /// The dictionary display model /// @@ -19,6 +19,7 @@ this.Translations = new List(); } + /// /// /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. /// diff --git a/src/Umbraco.Web/Models/ContentEditing/DictionaryOverviewDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/DictionaryOverviewDisplay.cs index 687474d5df..7941b0ac44 100644 --- a/src/Umbraco.Web/Models/ContentEditing/DictionaryOverviewDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/DictionaryOverviewDisplay.cs @@ -1,8 +1,8 @@ -namespace Umbraco.Web.Models.ContentEditing -{ - using System.Collections.Generic; - using System.Runtime.Serialization; +using System.Collections.Generic; +using System.Runtime.Serialization; +namespace Umbraco.Web.Models.ContentEditing +{ /// /// The dictionary overview display. /// @@ -14,7 +14,7 @@ /// public DictionaryOverviewDisplay() { - this.Translations = new List(); + Translations = new List(); } /// diff --git a/src/Umbraco.Web/Models/ContentEditing/DictionaryOverviewTranslationDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/DictionaryOverviewTranslationDisplay.cs index 8e28915ab1..9f08617921 100644 --- a/src/Umbraco.Web/Models/ContentEditing/DictionaryOverviewTranslationDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/DictionaryOverviewTranslationDisplay.cs @@ -1,7 +1,7 @@ -namespace Umbraco.Web.Models.ContentEditing -{ - using System.Runtime.Serialization; +using System.Runtime.Serialization; +namespace Umbraco.Web.Models.ContentEditing +{ /// /// The dictionary translation overview display. /// diff --git a/src/Umbraco.Web/Models/ContentEditing/DictionarySave.cs b/src/Umbraco.Web/Models/ContentEditing/DictionarySave.cs index 19f4362799..e54d1fab45 100644 --- a/src/Umbraco.Web/Models/ContentEditing/DictionarySave.cs +++ b/src/Umbraco.Web/Models/ContentEditing/DictionarySave.cs @@ -1,9 +1,9 @@ -namespace Umbraco.Web.Models.ContentEditing -{ - using System; - using System.Collections.Generic; - using System.Runtime.Serialization; +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +namespace Umbraco.Web.Models.ContentEditing +{ /// /// Dictionary Save model /// diff --git a/src/Umbraco.Web/Models/ContentEditing/DictionaryTranslationDisplay.cs b/src/Umbraco.Web/Models/ContentEditing/DictionaryTranslationDisplay.cs index a1e0c3c5d0..2437de6ffd 100644 --- a/src/Umbraco.Web/Models/ContentEditing/DictionaryTranslationDisplay.cs +++ b/src/Umbraco.Web/Models/ContentEditing/DictionaryTranslationDisplay.cs @@ -1,7 +1,8 @@ -namespace Umbraco.Web.Models.ContentEditing -{ - using System.Runtime.Serialization; +using System.Runtime.Serialization; +namespace Umbraco.Web.Models.ContentEditing +{ + /// /// /// The dictionary translation display model /// diff --git a/src/Umbraco.Web/Models/ContentEditing/DictionaryTranslationSave.cs b/src/Umbraco.Web/Models/ContentEditing/DictionaryTranslationSave.cs index 1e8585e600..a0ab02768c 100644 --- a/src/Umbraco.Web/Models/ContentEditing/DictionaryTranslationSave.cs +++ b/src/Umbraco.Web/Models/ContentEditing/DictionaryTranslationSave.cs @@ -1,7 +1,7 @@ +using System.Runtime.Serialization; + namespace Umbraco.Web.Models.ContentEditing { - using System.Runtime.Serialization; - /// /// The dictionary translation save model /// @@ -26,4 +26,4 @@ namespace Umbraco.Web.Models.ContentEditing [DataMember(Name = "languageId")] public int LanguageId { get; set; } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Web/Models/Mapping/DictionaryModelMapper.cs b/src/Umbraco.Web/Models/Mapping/DictionaryModelMapper.cs index 93c7f12378..4fe05d9039 100644 --- a/src/Umbraco.Web/Models/Mapping/DictionaryModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/DictionaryModelMapper.cs @@ -1,17 +1,16 @@ -namespace Umbraco.Web.Models.Mapping +using AutoMapper; +using System; +using System.Collections.Generic; +using System.Linq; +using Umbraco.Core; +using Umbraco.Core.Models; +using Umbraco.Core.Models.Mapping; +using Umbraco.Core.Services; +using Umbraco.Web.Models.ContentEditing; + +namespace Umbraco.Web.Models.Mapping { - using System; - using System.Collections.Generic; - using System.Linq; - - using AutoMapper; - - using Umbraco.Core; - using Umbraco.Core.Models; - using Umbraco.Core.Models.Mapping; - using Umbraco.Core.Services; - using Umbraco.Web.Models.ContentEditing; - + /// /// /// The dictionary model mapper. /// @@ -42,9 +41,8 @@ // TODO check if there is a better way if (src.ParentId.HasValue) { - var ids = new List(); + var ids = new List { -1 }; - ids.Add(-1); var parentIds = new List(); @@ -95,7 +93,7 @@ var translation = src.Translations.FirstOrDefault(x => x.LanguageId == langId); dest.Translations.Add( - new DictionaryOverviewTranslationDisplay() + new DictionaryOverviewTranslationDisplay { DisplayName = lang.CultureInfo.DisplayName, HasTranslation = translation != null && string.IsNullOrEmpty(translation.Value) == false @@ -104,8 +102,6 @@ }); } - - /// /// Goes up the dictoinary tree to get all parent ids /// @@ -122,15 +118,13 @@ { var dictionary = localizationService.GetDictionaryItemById(parentId); - if (dictionary != null) - { - ids.Add(dictionary.Id); + if (dictionary == null) + return; - if (dictionary.ParentId.HasValue) - { - this.GetParentId(dictionary.ParentId.Value, localizationService, ids); - } - } + ids.Add(dictionary.Id); + + if (dictionary.ParentId.HasValue) + GetParentId(dictionary.ParentId.Value, localizationService, ids); } } } diff --git a/src/Umbraco.Web/Trees/DictionaryTreeController.cs b/src/Umbraco.Web/Trees/DictionaryTreeBaseController.cs similarity index 50% rename from src/Umbraco.Web/Trees/DictionaryTreeController.cs rename to src/Umbraco.Web/Trees/DictionaryTreeBaseController.cs index d09ac5668e..d56f0a1b13 100644 --- a/src/Umbraco.Web/Trees/DictionaryTreeController.cs +++ b/src/Umbraco.Web/Trees/DictionaryTreeBaseController.cs @@ -1,38 +1,15 @@ -namespace Umbraco.Web.Trees +using System; +using System.Linq; +using System.Net.Http.Formatting; +using umbraco.BusinessLogic.Actions; +using Umbraco.Core; +using Umbraco.Core.Services; +using Umbraco.Web.Models.Trees; + +namespace Umbraco.Web.Trees { - using System; - using System.Linq; - using System.Net.Http.Formatting; - - using global::umbraco; - using global::umbraco.BusinessLogic.Actions; - - using Umbraco.Core; - using Umbraco.Core.Services; - using Umbraco.Web.Models.Trees; - using Umbraco.Web.WebApi.Filters; - - [UmbracoTreeAuthorize(Constants.Trees.Dictionary)] - [Tree(Constants.Applications.Settings, Constants.Trees.Dictionary, null, sortOrder: 3)] - [Mvc.PluginController("UmbracoTrees")] - [CoreTree] - [LegacyBaseTree(typeof(loadDictionary))] - public class DictionaryTreeController : TreeController + public class DictionaryTreeBaseController : TreeController { - /// - /// Helper method to create a root model for a tree - /// - /// - protected override TreeNode CreateRootNode(FormDataCollection queryStrings) - { - var root = base.CreateRootNode(queryStrings); - - // this will load in a custom UI instead of the dashboard for the root node - root.RoutePath = string.Format("{0}/{1}/{2}", Constants.Applications.Settings, Constants.Trees.Dictionary, "list"); - - return root; - } - /// /// The method called to render the contents of the tree structure /// @@ -48,42 +25,37 @@ { var intId = id.TryConvertTo(); if (intId == false) - { throw new InvalidOperationException("Id must be an integer"); - } var nodes = new TreeNodeCollection(); if (id == Constants.System.Root.ToInvariantString()) { nodes.AddRange( - this.Services.LocalizationService.GetRootDictionaryItems().Select( - x => this.CreateTreeNode( + Services.LocalizationService.GetRootDictionaryItems().Select( + x => CreateTreeNode( x.Id.ToInvariantString(), id, queryStrings, x.ItemKey, "icon-book-alt", - true))); + Services.LocalizationService.GetDictionaryItemChildren(x.Key).Any()))); } else { // maybe we should use the guid as url param to avoid the extra call for getting dictionary item - var parentDictionary = this.Services.LocalizationService.GetDictionaryItemById(intId.Result); - + var parentDictionary = Services.LocalizationService.GetDictionaryItemById(intId.Result); if (parentDictionary == null) - { return nodes; - } - nodes.AddRange(this.Services.LocalizationService.GetDictionaryItemChildren(parentDictionary.Key).ToList().OrderByDescending(item => item.Key).Select( - x => this.CreateTreeNode( + nodes.AddRange(Services.LocalizationService.GetDictionaryItemChildren(parentDictionary.Key).ToList().OrderByDescending(item => item.Key).Select( + x => CreateTreeNode( x.Id.ToInvariantString(), id, queryStrings, x.ItemKey, "icon-book-alt", - true))); + Services.LocalizationService.GetDictionaryItemChildren(x.Key).Any()))); } return nodes; @@ -101,14 +73,14 @@ { var menu = new MenuItemCollection(); - menu.Items.Add(this.Services.TextService.Localize(string.Format("actions/{0}", ActionNew.Instance.Alias))); + menu.Items.Add(Services.TextService.Localize($"actions/{ActionNew.Instance.Alias}")); if (id != Constants.System.Root.ToInvariantString()) - { - menu.Items.Add(this.Services.TextService.Localize(string.Format("actions/{0}", ActionDelete.Instance.Alias)), true); - } + menu.Items.Add(Services.TextService.Localize( + $"actions/{ActionDelete.Instance.Alias}"), true); - menu.Items.Add(this.Services.TextService.Localize(string.Format("actions/{0}", ActionRefresh.Instance.Alias)), true); + menu.Items.Add(Services.TextService.Localize( + $"actions/{ActionRefresh.Instance.Alias}"), true); return menu; } diff --git a/src/Umbraco.Web/Trees/SettingsDictionaryTreeController.cs b/src/Umbraco.Web/Trees/SettingsDictionaryTreeController.cs new file mode 100644 index 0000000000..edde759d49 --- /dev/null +++ b/src/Umbraco.Web/Trees/SettingsDictionaryTreeController.cs @@ -0,0 +1,24 @@ +using System.Net.Http.Formatting; +using Umbraco.Core; +using Umbraco.Web.Models.Trees; +using Umbraco.Web.WebApi.Filters; + +namespace Umbraco.Web.Trees +{ + [UmbracoTreeAuthorize(Constants.Trees.Dictionary)] + [Tree(Constants.Applications.Settings, Constants.Trees.Dictionary, null, sortOrder: 3)] + [Mvc.PluginController("UmbracoTrees")] + [CoreTree] + public class SettingsDictionaryTreeController : DictionaryTreeBaseController + { + protected override TreeNode CreateRootNode(FormDataCollection queryStrings) + { + var root = base.CreateRootNode(queryStrings); + + // this will load in a custom UI instead of the dashboard for the root node + root.RoutePath = $"{Constants.Applications.Settings}/{Constants.Trees.Dictionary}/list"; + + return root; + } + } +} diff --git a/src/Umbraco.Web/Trees/TranslationDictionaryTreeController.cs b/src/Umbraco.Web/Trees/TranslationDictionaryTreeController.cs new file mode 100644 index 0000000000..11658994a3 --- /dev/null +++ b/src/Umbraco.Web/Trees/TranslationDictionaryTreeController.cs @@ -0,0 +1,24 @@ +using System.Net.Http.Formatting; +using Umbraco.Core; +using Umbraco.Web.Models.Trees; +using Umbraco.Web.WebApi.Filters; + +namespace Umbraco.Web.Trees +{ + [UmbracoTreeAuthorize(Constants.Trees.Dictionary)] + [Tree(Constants.Applications.Translation, Constants.Trees.Dictionary, null, sortOrder: 3)] + [Mvc.PluginController("UmbracoTrees")] + [CoreTree] + public class TranslationDictionaryTreeController : DictionaryTreeBaseController + { + protected override TreeNode CreateRootNode(FormDataCollection queryStrings) + { + var root = base.CreateRootNode(queryStrings); + + // this will load in a custom UI instead of the dashboard for the root node + root.RoutePath = $"{Constants.Applications.Translation}/{Constants.Trees.Dictionary}/list"; + + return root; + } + } +} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 33795b283e..f25e553f35 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -528,12 +528,14 @@ + + + - @@ -1621,13 +1623,6 @@ DictionaryItemList.aspx - - EditDictionaryItem.aspx - ASPXCodeBehind - - - EditDictionaryItem.aspx - editLanguage.aspx ASPXCodeBehind @@ -1714,7 +1709,6 @@ - @@ -1929,9 +1923,6 @@ Designer - - ASPXCodeBehind - diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadDictionary.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadDictionary.cs deleted file mode 100644 index 2e58341a41..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadDictionary.cs +++ /dev/null @@ -1,99 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Data; -using System.Linq; -using System.IO; -using System.Text; -using System.Web; -using System.Xml; -using System.Configuration; -using umbraco.BasePages; -using umbraco.BusinessLogic; -using umbraco.businesslogic; -using umbraco.cms.businesslogic; -using umbraco.cms.businesslogic.cache; -using umbraco.cms.businesslogic.contentitem; -using umbraco.cms.businesslogic.datatype; -using umbraco.cms.businesslogic.language; -using umbraco.cms.businesslogic.media; -using umbraco.cms.businesslogic.member; -using umbraco.cms.businesslogic.property; -using umbraco.cms.businesslogic.web; -using umbraco.interfaces; -using umbraco.DataLayer; -using umbraco.BusinessLogic.Utils; -using umbraco.cms.presentation.Trees; -using umbraco.BusinessLogic.Actions; -using Umbraco.Core; - - -namespace umbraco -{ - [Tree(Constants.Applications.Settings, Constants.Trees.DictionaryObsolete, "Dictionary", action: "openDictionary()", sortOrder: 3)] - public class loadDictionary : BaseTree - { - public loadDictionary(string application) : base(application) { } - - protected override void CreateRootNode(ref XmlTreeNode rootNode) - { - rootNode.NodeType = "init" + TreeAlias; - rootNode.NodeID = "init"; - rootNode.Action = "javascript:openDictionary()"; - } - - protected override void CreateAllowedActions(ref List actions) - { - actions.Clear(); - actions.Add(ActionNew.Instance); - actions.Add(ActionDelete.Instance); - actions.Add(ContextMenuSeperator.Instance); - actions.Add(ActionRefresh.Instance); - } - - public override void RenderJS(ref StringBuilder Javascript) - { - Javascript.Append( - @" - function openDictionary() { - UmbClientMgr.contentFrame('settings/DictionaryItemList.aspx'); - } - function openDictionaryItem(id) { - UmbClientMgr.contentFrame('settings/editDictionaryItem.aspx?id=' + id); - }"); - } - - public override void Render(ref XmlTree tree) - { - - Dictionary.DictionaryItem[] tmp; - if (this.id == this.StartNodeID) - tmp = Dictionary.getTopMostItems; - else - tmp = new Dictionary.DictionaryItem(this.id).Children; - - foreach (Dictionary.DictionaryItem di in tmp.OrderBy(a => a.key)) - { - XmlTreeNode xNode = XmlTreeNode.Create(this); - xNode.NodeID = di.id.ToString(); //dictionary_ + id.. - xNode.Text = di.key; - xNode.Action = string.Format("javascript:openDictionaryItem({0});", di.id); - xNode.Icon = "icon-book-alt"; - xNode.NodeType = "DictionaryItem"; //this shouldn't be like this, it should be this.TreeAlias but the ui.config file points to this name. - xNode.Source = this.GetTreeServiceUrl(di.id); - xNode.HasChildren = di.hasChildren; - - OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty); - if (xNode != null) - { - tree.Add(xNode); - OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty); - } - - } - } - - - } - -} diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx deleted file mode 100644 index 09af30fd00..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx +++ /dev/null @@ -1,15 +0,0 @@ -<%@ Register Namespace="umbraco" TagPrefix="umb" Assembly="umbraco" %> -<%@ Register TagPrefix="cc1" Namespace="umbraco.uicontrols" Assembly="controls" %> - -<%@ Page Language="c#" MasterPageFile="../masterpages/umbracoPage.Master" ValidateRequest="false" - CodeBehind="EditDictionaryItem.aspx.cs" AutoEventWireup="True" Inherits="umbraco.settings.EditDictionaryItem" %> - - - - - - diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs deleted file mode 100644 index c5fa46832b..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.cs +++ /dev/null @@ -1,184 +0,0 @@ -using System; -using System.Web.UI; -using System.Web.UI.WebControls; -using umbraco.BusinessLogic; -using umbraco.cms.businesslogic; -using umbraco.cms.presentation.Trees; -using Umbraco.Core; - -namespace umbraco.settings -{ - /// - /// Summary description for EditDictionaryItem. - /// - [WebformsPageTreeAuthorize(Constants.Trees.Dictionary)] - public partial class EditDictionaryItem : BasePages.UmbracoEnsuredPage - { - - protected LiteralControl keyTxt = new LiteralControl(); - protected uicontrols.TabView tbv = new uicontrols.TabView(); - private System.Collections.ArrayList languageFields = new System.Collections.ArrayList(); - private cms.businesslogic.Dictionary.DictionaryItem currentItem; - protected TextBox boxChangeKey; - protected Label labelChangeKey; - protected Literal txt; - protected User currentUser; - - protected void Page_Load(object sender, System.EventArgs e) - { - currentItem = new cms.businesslogic.Dictionary.DictionaryItem(int.Parse(Request.QueryString["id"])); - currentUser = getUser(); - - // Put user code to initialize the page here - Panel1.hasMenu = true; - Panel1.Text = ui.Text("editdictionary") + ": " + currentItem.key; - - var save = Panel1.Menu.NewButton(); - save.Text = ui.Text("save"); - save.Click += save_Click; - save.ToolTip = ui.Text("save"); - save.ID = "save"; - save.ButtonType = uicontrols.MenuButtonType.Primary; - - uicontrols.Pane p = new uicontrols.Pane(); - - boxChangeKey = new TextBox - { - ID = "changeKey-" + currentItem.id, - CssClass = "umbEditorTextField", - Text = currentItem.key - }; - - labelChangeKey = new Label - { - ID = "changeKeyLabel", - CssClass = "text-error" - }; - - p.addProperty(new Literal - { - Text = "

" + ui.Text("dictionaryItem", "changeKey", currentUser) + "

" - }); - p.addProperty(boxChangeKey); - p.addProperty(labelChangeKey); - - - txt = new Literal(); - txt.Text = "

" + ui.Text("dictionaryItem", "description", currentItem.key, currentUser) + "


"; - p.addProperty(txt); - - foreach (cms.businesslogic.language.Language l in cms.businesslogic.language.Language.getAll) - { - - TextBox languageBox = new TextBox(); - languageBox.TextMode = TextBoxMode.MultiLine; - languageBox.ID = l.id.ToString(); - languageBox.CssClass = "umbEditorTextFieldMultiple"; - - if (!IsPostBack) - languageBox.Text = currentItem.Value(l.id); - - languageFields.Add(languageBox); - p.addProperty(l.FriendlyName, languageBox); - - } - - - if (!IsPostBack) - { - var path = BuildPath(currentItem); - ClientTools - .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) - .SyncTree(path, false); - } - - Panel1.Controls.Add(p); - } - - private string BuildPath(cms.businesslogic.Dictionary.DictionaryItem current) - { - var parentPath = current.IsTopMostItem() ? "" : BuildPath(current.Parent) + ","; - return parentPath + current.id; - } - - void save_Click(object sender, EventArgs e) - { - foreach (TextBox t in languageFields) - { - //check for null but allow empty string! - // http://issues.umbraco.org/issue/U4-1931 - if (t.Text != null) - { - currentItem.setValue(int.Parse(t.ID), t.Text); - } - } - - labelChangeKey.Text = ""; // reset error text - var newKey = boxChangeKey.Text; - if (string.IsNullOrWhiteSpace(newKey) == false && newKey != currentItem.key) - { - // key already exists, save but inform - if (Dictionary.DictionaryItem.hasKey(newKey) == true) - { - labelChangeKey.Text = ui.Text("dictionaryItem", "changeKeyError", newKey, currentUser); - boxChangeKey.Text = currentItem.key; // reset key - } - else - { - // set the new key - currentItem.setKey(newKey); - - // update the title with the new key - Panel1.title.InnerHtml = ui.Text("editdictionary") + ": " + newKey; - - // sync the content tree - var path = BuildPath(currentItem); - ClientTools.SyncTree(path, true); - } - } - txt.Text = "

" + ui.Text("dictionaryItem", "description", currentItem.key, currentUser) + "


"; - ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "dictionaryItemSaved"), ""); - } - - #region Web Form Designer generated code - - override protected void OnInit(EventArgs e) - { - InitializeComponent(); - base.OnInit(e); - } - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - } - - #endregion - - - private class languageTextbox : TextBox - { - - private int _languageid; - - public int languageid - { - set { _languageid = value; } - get { return _languageid; } - } - - public languageTextbox(int languageId) : base() - { - this.TextMode = TextBoxMode.MultiLine; - this.Rows = 10; - this.Columns = 40; - this.Attributes.Add("style", "margin: 3px; width: 98%;"); - - this.languageid = languageId; - } - } - } -} diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.designer.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.designer.cs deleted file mode 100644 index 15921e7445..0000000000 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/settings/EditDictionaryItem.aspx.designer.cs +++ /dev/null @@ -1,24 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace umbraco.settings { - - - public partial class EditDictionaryItem { - - /// - /// Panel1 control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::umbraco.uicontrols.UmbracoPanel Panel1; - } -}