Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit 0e034a7

Browse files
committed
added default values, and caching of content type info for non-preview previews.
1 parent cede3bb commit 0e034a7

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.controllers.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.GridEditors.DocTypeGridEditor", [
22

33
"$scope",
4+
"$rootScope",
45
"$timeout",
56
"editorState",
67
'assetsService',
@@ -9,7 +10,7 @@
910
"localizationService",
1011
"editorService",
1112

12-
function ($scope, $timeout, editorState, assetsService, dtgeResources, umbRequestHelper, localizationService, editorService) {
13+
function ($scope, $rootScope, $timeout, editorState, assetsService, dtgeResources, umbRequestHelper, localizationService, editorService) {
1314

1415
var overlayOptions = {
1516
view: umbRequestHelper.convertVirtualToAbsolutePath(
@@ -27,6 +28,9 @@
2728

2829
$scope.icon = "icon-item-arrangement";
2930

31+
// init cached content types if it doesnt exist.
32+
if (!$rootScope.dtgeContentTypes) $rootScope.dtgeContentTypes = {};
33+
3034
// localize strings
3135
localizationService.localizeMany(["docTypeGridEditor_insertItem", "docTypeGridEditor_editItem", "docTypeGridEditor_selectContentType", "blueprints_selectBlueprint"]).then(function (data) {
3236
overlayOptions.titles.insertItem = data[0];
@@ -36,24 +40,45 @@
3640
});
3741

3842
$scope.setValue = function (data, callback) {
43+
$scope.title = $scope.control.editor.name;
44+
$scope.icon = $scope.control.editor.icon;
3945
$scope.control.value = data;
46+
4047
if (!("id" in $scope.control.value) || $scope.control.value.id == "") {
4148
$scope.control.value.id = guid();
4249
}
4350
if ("name" in $scope.control.value.value && $scope.control.value.value.name) {
4451
$scope.title = $scope.control.value.value.name;
4552
}
4653
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+
}
5271
}
5372
if (callback)
5473
callback();
5574
};
5675

76+
$scope.setTitleAndDescription = function (contentType) {
77+
$scope.title = contentType.title;
78+
$scope.description = contentType.description;
79+
$scope.icon = contentType.icon;
80+
};
81+
5782
$scope.setDocType = function () {
5883

5984
overlayOptions.editorName = $scope.control.editor.name;

0 commit comments

Comments
 (0)