Skip to content

Commit 9a246a1

Browse files
sorengnathanwoulfe
andauthored
Implement icon parameter for doctype editor (#11008)
* fix: implement icon parameter for doctype editor issue #10108 * fix: move color from icon to class attribute * fix: removed defined colors, defaulting to the standard dark grey (ie "no color picked" in icon picker) * cleaned up unused dependencies, double quotes to single, removed unused 'color' param from the create methods, and use shorthand object creation in createDocType (if the key has the same name as the variable passed as a prop, we only need to pass the key name) * fix comment Co-authored-by: Nathan Woulfe <[email protected]>
1 parent 674edd3 commit 9a246a1

File tree

3 files changed

+58
-35
lines changed

3 files changed

+58
-35
lines changed

src/Umbraco.Web.UI.Client/src/views/documenttypes/create.controller.js

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* @description
77
* The controller for the doc type creation dialog
88
*/
9-
function DocumentTypesCreateController($scope, $location, navigationService, contentTypeResource, formHelper, appState, notificationsService, localizationService, iconHelper) {
9+
function DocumentTypesCreateController($scope, $location, navigationService, contentTypeResource, formHelper, appState) {
1010

1111
$scope.model = {
12-
allowCreateFolder: $scope.currentNode.parentId === null || $scope.currentNode.nodeType === "container",
13-
folderName: "",
12+
allowCreateFolder: $scope.currentNode.parentId === null || $scope.currentNode.nodeType === 'container',
13+
folderName: '',
1414
creatingFolder: false
1515
};
1616

@@ -31,18 +31,18 @@ function DocumentTypesCreateController($scope, $location, navigationService, con
3131

3232
navigationService.hideMenu();
3333

34-
var currPath = node.path ? node.path : "-1";
34+
var currPath = node.path ? node.path : '-1';
3535

3636
navigationService.syncTree({
37-
tree: "documenttypes",
38-
path: currPath + "," + folderId,
37+
tree: 'documenttypes',
38+
path: currPath + ',' + folderId,
3939
forceReload: true,
4040
activate: true
4141
});
4242

4343
formHelper.resetForm({ scope: $scope, formCtrl: $scope.createFolderForm });
4444

45-
var section = appState.getSectionState("currentSection");
45+
var section = appState.getSectionState('currentSection');
4646

4747
}, function (err) {
4848

@@ -51,39 +51,54 @@ function DocumentTypesCreateController($scope, $location, navigationService, con
5151

5252
});
5353
}
54-
};
54+
};
55+
56+
function createDocType(config) {
57+
58+
$location.search('create', null);
59+
$location.search('notemplate', null);
60+
$location.search('iscomposition', null);
61+
$location.search('iselement', null);
62+
$location.search('icon', null);
63+
64+
var icon = null;
65+
66+
if (config.icon != undefined && config.icon != null) {
67+
icon = config.icon;
68+
if (config.color) {
69+
icon += ' ' + config.color;
70+
}
71+
}
72+
73+
$location
74+
.path('/settings/documenttypes/edit/' + node.id)
75+
.search('create', 'true')
76+
.search('notemplate', config.notemplate ? 'true' : null)
77+
.search('iscomposition', config.iscomposition ? 'true' : null)
78+
.search('iselement', config.iselement ? 'true' : null)
79+
.search('icon', icon);
80+
81+
navigationService.hideMenu();
82+
}
83+
5584

5685
// Disabling logic for creating document type with template if disableTemplates is set to true
5786
if (!disableTemplates) {
58-
$scope.createDocType = function () {
59-
$location.search('create', null);
60-
$location.search('notemplate', null);
61-
$location.path("/settings/documenttypes/edit/" + node.id).search("create", "true");
62-
navigationService.hideMenu();
87+
$scope.createDocType = function (icon) {
88+
createDocType({ icon });
6389
};
6490
}
6591

66-
$scope.createComponent = function () {
67-
$location.search('create', null);
68-
$location.search('notemplate', null);
69-
$location.path("/settings/documenttypes/edit/" + node.id).search("create", "true").search("notemplate", "true");
70-
navigationService.hideMenu();
92+
$scope.createComponent = function (icon) {
93+
createDocType({ notemplate: true, icon });
7194
};
7295

73-
$scope.createComposition = function () {
74-
$location.search('create', null);
75-
$location.search('notemplate', null);
76-
$location.search('iscomposition', null);
77-
$location.path("/settings/documenttypes/edit/" + node.id).search("create", "true").search("notemplate", "true").search("iscomposition", "true");
78-
navigationService.hideMenu();
96+
$scope.createComposition = function (icon) {
97+
createDocType({ iscomposition: true, iselement: true, icon });
7998
};
8099

81-
$scope.createElement = function () {
82-
$location.search('create', null);
83-
$location.search('notemplate', null);
84-
$location.search('iselement', null);
85-
$location.path("/settings/documenttypes/edit/" + node.id).search("create", "true").search("notemplate", "true").search("iselement", "true");
86-
navigationService.hideMenu();
100+
$scope.createElement = function (icon) {
101+
createDocType({ iselement: true, icon });
87102
};
88103

89104
$scope.close = function() {
@@ -92,4 +107,4 @@ function DocumentTypesCreateController($scope, $location, navigationService, con
92107
};
93108
}
94109

95-
angular.module('umbraco').controller("Umbraco.Editors.DocumentTypes.CreateController", DocumentTypesCreateController);
110+
angular.module('umbraco').controller('Umbraco.Editors.DocumentTypes.CreateController', DocumentTypesCreateController);

src/Umbraco.Web.UI.Client/src/views/documenttypes/create.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ <h5><localize key="create_createUnder">Create an item under</localize> {{current
55

66
<ul class="umb-actions umb-actions-child">
77
<li data-element="action-documentType" class="umb-action" ng-hide="model.disableTemplates">
8-
<button type="button" ng-click="createDocType()" class="umb-action-link umb-outline btn-reset" umb-auto-focus>
8+
<button type="button" ng-click="createDocType('icon-document')" class="umb-action-link umb-outline btn-reset" umb-auto-focus>
99
<umb-icon icon="icon-document" class="icon large"></umb-icon>
1010
<span class="menu-label">
1111
<localize key="create_documentTypeWithTemplate">Document Type with Template</localize>
@@ -14,7 +14,7 @@ <h5><localize key="create_createUnder">Create an item under</localize> {{current
1414
</button>
1515
</li>
1616
<li data-element="action-documentTypeWithoutTemplate" class="umb-action">
17-
<button type="button" ng-click="createComponent()" class="umb-action-link umb-outline btn-reset">
17+
<button type="button" ng-click="createComponent('icon-item-arrangement')" class="umb-action-link umb-outline btn-reset">
1818
<umb-icon icon="icon-item-arrangement" class="icon large"></umb-icon>
1919
<span class="menu-label">
2020
<localize key="create_documentType">Document Type</localize>
@@ -23,7 +23,7 @@ <h5><localize key="create_createUnder">Create an item under</localize> {{current
2323
</button>
2424
</li>
2525
<li data-element="action-documentTypeWithIsElementTypeChecked" class="umb-action">
26-
<button type="button" ng-click="createElement()" class="umb-action-link umb-outline btn-reset">
26+
<button type="button" ng-click="createElement('icon-science')" class="umb-action-link umb-outline btn-reset">
2727
<umb-icon icon="icon-science" class="icon large"></umb-icon>
2828
<span class="menu-label">
2929
<localize key="create_elementType">Element Type</localize>
@@ -32,7 +32,7 @@ <h5><localize key="create_createUnder">Create an item under</localize> {{current
3232
</button>
3333
</li>
3434
<li data-element="action-documentTypeWithoutTemplateForComposition" class="umb-action">
35-
<button type="button" ng-click="createComposition()" class="umb-action-link umb-outline btn-reset">
35+
<button type="button" ng-click="createComposition('icon-defrag')" class="umb-action-link umb-outline btn-reset">
3636
<umb-icon icon="icon-defrag" class="icon large"></umb-icon>
3737
<span class="menu-label">
3838
<localize key="create_composition">Composition</localize>

src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
var create = $routeParams.create;
2323
var noTemplate = $routeParams.notemplate;
2424
var isElement = $routeParams.iselement;
25+
var icon = $routeParams.icon;
2526
var allowVaryByCulture = $routeParams.culturevary;
2627
var infiniteMode = $scope.model && $scope.model.infiniteMode;
2728
var documentTypeIcon = "";
@@ -72,6 +73,7 @@
7273
if (create && !documentTypeId) documentTypeId = -1;
7374
noTemplate = $scope.model.notemplate || $scope.model.noTemplate;
7475
isElement = $scope.model.isElement;
76+
icon = $scope.model.icon;
7577
allowVaryByCulture = $scope.model.allowVaryByCulture;
7678
vm.submitButtonKey = "buttons_saveAndClose";
7779
vm.generateModelsKey = "buttons_generateModelsAndClose";
@@ -415,6 +417,12 @@
415417
if (isElement) {
416418
contentType.isElement = true;
417419
}
420+
421+
// set icon if one is provided
422+
if (icon !== null) {
423+
contentType.icon = icon;
424+
}
425+
418426
// set vary by culture checkbox by default
419427
if (allowVaryByCulture) {
420428
contentType.allowCultureVariant = true;

0 commit comments

Comments
 (0)