|
1 |
| -/** |
| 1 | +/** |
2 | 2 | * @ngdoc controller
|
3 | 3 | * @name Umbraco.Editors.Dictionary.EditController
|
4 | 4 | * @function
|
|
7 | 7 | * The controller for editing dictionary items
|
8 | 8 | */
|
9 | 9 | function DictionaryEditController($scope, $routeParams, $location, dictionaryResource, navigationService, appState, editorState, contentEditingHelper, formHelper, notificationsService, localizationService) {
|
10 |
| - |
11 |
| - var vm = this; |
12 |
| - |
13 |
| - //setup scope vars |
14 |
| - vm.nameDirty = false; |
15 |
| - vm.header = {}; |
16 |
| - vm.header.editorfor = "template_insertDictionaryItem"; |
17 |
| - vm.header.setPageTitle = true; |
18 |
| - |
19 |
| - vm.page = {}; |
20 |
| - vm.page.loading = false; |
21 |
| - vm.page.nameLocked = false; |
22 |
| - vm.page.menu = {}; |
23 |
| - vm.page.menu.currentSection = appState.getSectionState("currentSection"); |
24 |
| - vm.page.menu.currentNode = null; |
25 |
| - vm.description = ""; |
26 |
| - vm.showBackButton = true; |
27 |
| - vm.maxlength = 1000; |
28 |
| - |
29 |
| - vm.save = saveDictionary; |
30 |
| - vm.back = back; |
31 |
| - vm.change = change; |
32 |
| - |
33 |
| - function loadDictionary() { |
34 |
| - |
35 |
| - vm.page.loading = true; |
36 |
| - |
37 |
| - //we are editing so get the content item from the server |
38 |
| - dictionaryResource.getById($routeParams.id) |
39 |
| - .then(function (data) { |
40 |
| - bindDictionary(data); |
41 |
| - vm.page.loading = false; |
42 |
| - }); |
43 |
| - } |
44 | 10 |
|
45 |
| - function createTranslationProperty(translation) { |
46 |
| - return { |
47 |
| - alias: translation.isoCode, |
48 |
| - label: translation.displayName, |
49 |
| - hideLabel : false |
50 |
| - } |
| 11 | + var vm = this; |
| 12 | + |
| 13 | + //setup scope vars |
| 14 | + vm.nameDirty = false; |
| 15 | + vm.header = {}; |
| 16 | + vm.header.editorfor = "template_insertDictionaryItem"; |
| 17 | + vm.header.setPageTitle = true; |
| 18 | + |
| 19 | + vm.page = {}; |
| 20 | + vm.page.navigation = {}; |
| 21 | + vm.page.loading = false; |
| 22 | + vm.page.nameLocked = false; |
| 23 | + vm.page.menu = {}; |
| 24 | + vm.page.menu.currentSection = appState.getSectionState("currentSection"); |
| 25 | + vm.page.menu.currentNode = null; |
| 26 | + vm.description = ""; |
| 27 | + vm.showBackButton = true; |
| 28 | + vm.maxlength = 1000; |
| 29 | + |
| 30 | + vm.save = saveDictionary; |
| 31 | + vm.back = back; |
| 32 | + vm.change = change; |
| 33 | + |
| 34 | + function loadDictionary() { |
| 35 | + |
| 36 | + vm.page.loading = true; |
| 37 | + |
| 38 | + //we are editing so get the content item from the server |
| 39 | + dictionaryResource.getById($routeParams.id) |
| 40 | + .then(function (data) { |
| 41 | + bindDictionary(data); |
| 42 | + vm.page.navigation = data.apps; |
| 43 | + data.apps[0].active = true; |
| 44 | + vm.page.loading = false; |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + function createTranslationProperty(translation) { |
| 49 | + return { |
| 50 | + alias: translation.isoCode, |
| 51 | + label: translation.displayName, |
| 52 | + hideLabel: false |
51 | 53 | }
|
| 54 | + } |
52 | 55 |
|
53 |
| - function bindDictionary(data) { |
54 |
| - localizationService.localize("dictionaryItem_description").then(function (value) { |
55 |
| - vm.description = value.replace("%0%", data.name); |
56 |
| - }); |
| 56 | + function bindDictionary(data) { |
| 57 | + localizationService.localize("dictionaryItem_description").then(function (value) { |
| 58 | + vm.description = value.replace("%0%", data.name); |
| 59 | + }); |
57 | 60 |
|
58 |
| - // create data for umb-property displaying |
59 |
| - for (var i = 0; i < data.translations.length; i++) { |
60 |
| - data.translations[i].property = createTranslationProperty(data.translations[i]); |
61 |
| - change(data.translations[i]); |
62 |
| - } |
| 61 | + // create data for umb-property displaying |
| 62 | + for (var i = 0; i < data.translations.length; i++) { |
| 63 | + data.translations[i].property = createTranslationProperty(data.translations[i]); |
| 64 | + change(data.translations[i]); |
| 65 | + } |
63 | 66 |
|
64 |
| - contentEditingHelper.handleSuccessfulSave({ |
65 |
| - scope: $scope, |
66 |
| - savedContent: data |
67 |
| - }); |
| 67 | + contentEditingHelper.handleSuccessfulSave({ |
| 68 | + scope: $scope, |
| 69 | + savedContent: data |
| 70 | + }); |
68 | 71 |
|
69 |
| - // set content |
70 |
| - vm.content = data; |
| 72 | + // set content |
| 73 | + vm.content = data; |
71 | 74 |
|
72 |
| - //share state |
73 |
| - editorState.set(vm.content); |
| 75 | + //share state |
| 76 | + editorState.set(vm.content); |
74 | 77 |
|
75 |
| - navigationService.syncTree({ tree: "dictionary", path: data.path, forceReload: true }).then(function (syncArgs) { |
76 |
| - vm.page.menu.currentNode = syncArgs.node; |
77 |
| - }); |
78 |
| - } |
| 78 | + navigationService.syncTree({ tree: "dictionary", path: data.path, forceReload: true }).then(function (syncArgs) { |
| 79 | + vm.page.menu.currentNode = syncArgs.node; |
| 80 | + }); |
| 81 | + } |
79 | 82 |
|
80 |
| - function onInit() { |
81 |
| - loadDictionary(); |
82 |
| - } |
| 83 | + function onInit() { |
| 84 | + loadDictionary(); |
| 85 | + } |
| 86 | + |
| 87 | + function saveDictionary() { |
| 88 | + if (formHelper.submitForm({ scope: $scope, statusMessage: "Saving..." })) { |
83 | 89 |
|
84 |
| - function saveDictionary() { |
85 |
| - if (formHelper.submitForm({ scope: $scope, statusMessage: "Saving..." })) { |
| 90 | + vm.page.saveButtonState = "busy"; |
86 | 91 |
|
87 |
| - vm.page.saveButtonState = "busy"; |
| 92 | + dictionaryResource.save(vm.content, vm.nameDirty) |
| 93 | + .then(function (data) { |
88 | 94 |
|
89 |
| - dictionaryResource.save(vm.content, vm.nameDirty) |
90 |
| - .then(function (data) { |
| 95 | + formHelper.resetForm({ scope: $scope }); |
91 | 96 |
|
92 |
| - formHelper.resetForm({ scope: $scope }); |
| 97 | + bindDictionary(data); |
93 | 98 |
|
94 |
| - bindDictionary(data); |
| 99 | + vm.page.saveButtonState = "success"; |
| 100 | + }, |
| 101 | + function (err) { |
95 | 102 |
|
96 |
| - vm.page.saveButtonState = "success"; |
97 |
| - }, |
98 |
| - function (err) { |
| 103 | + formHelper.resetForm({ scope: $scope, hasErrors: true }); |
99 | 104 |
|
100 |
| - formHelper.resetForm({ scope: $scope, hasErrors: true }); |
| 105 | + contentEditingHelper.handleSaveError({ |
| 106 | + err: err |
| 107 | + }); |
101 | 108 |
|
102 |
| - contentEditingHelper.handleSaveError({ |
103 |
| - err: err |
104 |
| - }); |
105 |
| - |
106 |
| - notificationsService.error(err.data.message); |
| 109 | + notificationsService.error(err.data.message); |
107 | 110 |
|
108 |
| - vm.page.saveButtonState = "error"; |
109 |
| - }); |
110 |
| - } |
111 |
| - } |
112 |
| - |
113 |
| - function back() { |
114 |
| - $location.path(vm.page.menu.currentSection + "/dictionary/list"); |
| 111 | + vm.page.saveButtonState = "error"; |
| 112 | + }); |
115 | 113 | }
|
| 114 | + } |
116 | 115 |
|
117 |
| - function change(translation) { |
118 |
| - if (translation.translation) { |
119 |
| - var charsCount = translation.translation.length; |
120 |
| - translation.nearMaxLimit = charsCount > Math.max(vm.maxlength * .8, vm.maxlength - 50); |
121 |
| - } |
| 116 | + function back() { |
| 117 | + $location.path(vm.page.menu.currentSection + "/dictionary/list"); |
| 118 | + } |
| 119 | + |
| 120 | + function change(translation) { |
| 121 | + if (translation.translation) { |
| 122 | + var charsCount = translation.translation.length; |
| 123 | + translation.nearMaxLimit = charsCount > Math.max(vm.maxlength * .8, vm.maxlength - 50); |
122 | 124 | }
|
| 125 | + } |
123 | 126 |
|
124 |
| - $scope.$watch("vm.content.name", function (newVal, oldVal) { |
125 |
| - //when the value changes, we need to set the name dirty |
126 |
| - if (newVal && (newVal !== oldVal) && typeof(oldVal) !== "undefined") { |
127 |
| - vm.nameDirty = true; |
128 |
| - } |
129 |
| - }); |
| 127 | + $scope.$watch("vm.content.name", function (newVal, oldVal) { |
| 128 | + //when the value changes, we need to set the name dirty |
| 129 | + if (newVal && (newVal !== oldVal) && typeof (oldVal) !== "undefined") { |
| 130 | + vm.nameDirty = true; |
| 131 | + } |
| 132 | + }); |
130 | 133 |
|
131 |
| - onInit(); |
| 134 | + onInit(); |
132 | 135 | }
|
133 | 136 |
|
134 | 137 | angular.module("umbraco").controller("Umbraco.Editors.Dictionary.EditController", DictionaryEditController);
|
0 commit comments