|
1 | 1 | angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.GridEditors.DocTypeGridEditor", [
|
2 | 2 |
|
3 | 3 | "$scope",
|
| 4 | + "$rootScope", |
4 | 5 | "$timeout",
|
5 | 6 | "editorState",
|
6 | 7 | 'assetsService',
|
|
9 | 10 | "localizationService",
|
10 | 11 | "editorService",
|
11 | 12 |
|
12 |
| - function ($scope, $timeout, editorState, assetsService, dtgeResources, umbRequestHelper, localizationService, editorService) { |
| 13 | + function ($scope, $rootScope, $timeout, editorState, assetsService, dtgeResources, umbRequestHelper, localizationService, editorService) { |
13 | 14 |
|
14 | 15 | var overlayOptions = {
|
15 | 16 | view: umbRequestHelper.convertVirtualToAbsolutePath(
|
|
27 | 28 |
|
28 | 29 | $scope.icon = "icon-item-arrangement";
|
29 | 30 |
|
| 31 | + // init cached content types if it doesnt exist. |
| 32 | + if (!$rootScope.dtgeContentTypes) $rootScope.dtgeContentTypes = {}; |
| 33 | + |
30 | 34 | // localize strings
|
31 | 35 | localizationService.localizeMany(["docTypeGridEditor_insertItem", "docTypeGridEditor_editItem", "docTypeGridEditor_selectContentType", "blueprints_selectBlueprint"]).then(function (data) {
|
32 | 36 | overlayOptions.titles.insertItem = data[0];
|
|
36 | 40 | });
|
37 | 41 |
|
38 | 42 | $scope.setValue = function (data, callback) {
|
| 43 | + $scope.title = $scope.control.editor.name; |
| 44 | + $scope.icon = $scope.control.editor.icon; |
39 | 45 | $scope.control.value = data;
|
| 46 | + |
40 | 47 | if (!("id" in $scope.control.value) || $scope.control.value.id == "") {
|
41 | 48 | $scope.control.value.id = guid();
|
42 | 49 | }
|
43 | 50 | if ("name" in $scope.control.value.value && $scope.control.value.value.name) {
|
44 | 51 | $scope.title = $scope.control.value.value.name;
|
45 | 52 | }
|
46 | 53 | if ("dtgeContentTypeAlias" in $scope.control.value && $scope.control.value.dtgeContentTypeAlias) {
|
47 |
| - dtgeResources.getContentType($scope.control.value.dtgeContentTypeAlias).then(function (data2) { |
48 |
| - $scope.title = data2.title; |
49 |
| - $scope.description = data2.description; |
50 |
| - $scope.icon = data2.icon; |
51 |
| - }); |
| 54 | + if (!$rootScope.dtgeContentTypes[$scope.control.value.dtgeContentTypeAlias]) { |
| 55 | + |
| 56 | + dtgeResources.getContentType($scope.control.value.dtgeContentTypeAlias).then(function (data2) { |
| 57 | + var contentType = { |
| 58 | + title: data2.title, |
| 59 | + description: data2.description, |
| 60 | + icon: data2.icon |
| 61 | + }; |
| 62 | + |
| 63 | + // save to cached content types |
| 64 | + $rootScope.dtgeContentTypes[$scope.control.value.dtgeContentTypeAlias] = contentType; |
| 65 | + $scope.setTitleAndDescription(contentType); |
| 66 | + }); |
| 67 | + } |
| 68 | + else { |
| 69 | + $scope.setTitleAndDescription($rootScope.dtgeContentTypes[$scope.control.value.dtgeContentTypeAlias]); |
| 70 | + } |
52 | 71 | }
|
53 | 72 | if (callback)
|
54 | 73 | callback();
|
55 | 74 | };
|
56 | 75 |
|
| 76 | + $scope.setTitleAndDescription = function (contentType) { |
| 77 | + $scope.title = contentType.title; |
| 78 | + $scope.description = contentType.description; |
| 79 | + $scope.icon = contentType.icon; |
| 80 | + }; |
| 81 | + |
57 | 82 | $scope.setDocType = function () {
|
58 | 83 |
|
59 | 84 | overlayOptions.editorName = $scope.control.editor.name;
|
|
0 commit comments