keep elementTypes up to date through the EventService.
This commit is contained in:
@@ -16,10 +16,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
function BlockConfigurationController($scope, elementTypeResource, overlayService, localizationService, editorService) {
|
||||
function BlockConfigurationController($scope, elementTypeResource, overlayService, localizationService, editorService, eventsService) {
|
||||
|
||||
var unsubscribe = [];
|
||||
|
||||
var vm = this;
|
||||
|
||||
vm.openBlock = null;
|
||||
|
||||
function onInit() {
|
||||
@@ -38,6 +39,16 @@
|
||||
});
|
||||
}
|
||||
|
||||
function updateUsedElementTypes(event, args) {
|
||||
var key = args.documentType.key;
|
||||
for (var i = 0; i<vm.elementTypes.length; i++) {
|
||||
if (vm.elementTypes[i].key === key) {
|
||||
vm.elementTypes[i] = args.documentType;
|
||||
}
|
||||
}
|
||||
}
|
||||
unsubscribe.push(eventsService.on("editors.documentType.saved", updateUsedElementTypes));
|
||||
|
||||
vm.requestRemoveBlockByIndex = function (index) {
|
||||
localizationService.localizeMany(["general_delete", "blockEditor_confirmDeleteBlockMessage", "blockEditor_confirmDeleteBlockNotice"]).then(function (data) {
|
||||
var contentElementType = vm.getElementTypeByKey($scope.model.value[index].contentTypeKey);
|
||||
@@ -77,9 +88,11 @@
|
||||
};
|
||||
|
||||
vm.getElementTypeByKey = function(key) {
|
||||
return _.find(vm.elementTypes, function (type) {
|
||||
return type.key === key;
|
||||
});
|
||||
if (vm.elementTypes) {
|
||||
return vm.elementTypes.find(function (type) {
|
||||
return type.key === key;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
vm.openAddDialog = function ($event, entry) {
|
||||
@@ -193,7 +206,9 @@
|
||||
|
||||
};
|
||||
|
||||
|
||||
$scope.$on('$destroy', function () {
|
||||
unsubscribe.forEach(u => { u(); });
|
||||
});
|
||||
|
||||
onInit();
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function BlockConfigurationOverlayController($scope, overlayService, localizationService, editorService, elementTypeResource) {
|
||||
function BlockConfigurationOverlayController($scope, overlayService, localizationService, editorService, elementTypeResource, eventsService) {
|
||||
|
||||
var unsubscribe = [];
|
||||
|
||||
var vm = this;
|
||||
vm.block = $scope.model.block;
|
||||
@@ -20,11 +22,14 @@
|
||||
function loadElementTypes() {
|
||||
return elementTypeResource.getAll().then(function (elementTypes) {
|
||||
vm.elementTypes = elementTypes;
|
||||
|
||||
vm.contentPreview = vm.getElementTypeByKey(vm.block.contentTypeKey);
|
||||
vm.settingsPreview = vm.getElementTypeByKey(vm.block.settingsElementTypeKey);
|
||||
});
|
||||
}
|
||||
|
||||
vm.getElementTypeByKey = function(key) {
|
||||
return _.find(vm.elementTypes, function (type) {
|
||||
return vm.elementTypes.find(function (type) {
|
||||
return type.key === key;
|
||||
});
|
||||
};
|
||||
@@ -34,7 +39,6 @@
|
||||
const editor = {
|
||||
id: elementTypeId,
|
||||
submit: function (model) {
|
||||
loadElementTypes();
|
||||
editorService.close();
|
||||
},
|
||||
close: function () {
|
||||
@@ -50,9 +54,7 @@
|
||||
infiniteMode: true,
|
||||
isElement: true,
|
||||
submit: function (model) {
|
||||
loadElementTypes().then( function () {
|
||||
callback(model.documentTypeKey);
|
||||
});
|
||||
callback(model.documentTypeKey);
|
||||
editorService.close();
|
||||
},
|
||||
close: function () {
|
||||
@@ -123,6 +125,26 @@
|
||||
};
|
||||
|
||||
|
||||
function updateUsedElementTypes(event, args) {
|
||||
var key = args.documentType.key;
|
||||
for (var i = 0; i<vm.elementTypes.length; i++) {
|
||||
if (vm.elementTypes[i].key === key) {
|
||||
vm.elementTypes[i] = args.documentType;
|
||||
}
|
||||
}
|
||||
if (vm.contentPreview.key === key) {
|
||||
vm.contentPreview = args.documentType;
|
||||
$scope.$evalAsync();
|
||||
}
|
||||
if (vm.settingsPreview.key === key) {
|
||||
vm.settingsPreview = args.documentType;
|
||||
$scope.$evalAsync();
|
||||
}
|
||||
|
||||
}
|
||||
unsubscribe.push(eventsService.on("editors.documentType.saved", updateUsedElementTypes));
|
||||
|
||||
|
||||
vm.addViewForBlock = function(block) {
|
||||
localizationService.localize("blockEditor_headlineSelectView").then(function(localizedTitle) {
|
||||
|
||||
@@ -132,8 +154,10 @@
|
||||
treeAlias: "files",
|
||||
entityType: "file",
|
||||
isDialog: true,
|
||||
filter: function (i) {
|
||||
return !(i.name.indexOf(".html") !== -1);
|
||||
},
|
||||
select: function (node) {
|
||||
console.log(node)
|
||||
const filepath = decodeURIComponent(node.id.replace(/\+/g, " "));
|
||||
block.view = filepath;
|
||||
editorService.close();
|
||||
@@ -176,6 +200,9 @@
|
||||
treeAlias: "files",
|
||||
entityType: "file",
|
||||
isDialog: true,
|
||||
filter: function (i) {
|
||||
return !(i.name.indexOf(".css") !== -1);
|
||||
},
|
||||
select: function (node) {
|
||||
const filepath = decodeURIComponent(node.id.replace(/\+/g, " "));
|
||||
block.stylesheet = filepath;
|
||||
@@ -255,6 +282,10 @@
|
||||
}
|
||||
}
|
||||
|
||||
$scope.$on('$destroy', function () {
|
||||
unsubscribe.forEach(u => { u(); });
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
angular.module("umbraco").controller("Umbraco.PropertyEditors.BlockList.BlockConfigurationOverlayController", BlockConfigurationOverlayController);
|
||||
|
||||
@@ -107,8 +107,7 @@
|
||||
<label class="control-label"><localize key="blockEditor_labelContentElementType">Content ElementType</localize></label>
|
||||
<div class="controls">
|
||||
<div class="__settings-input --hasValue" ng-if="vm.block.contentTypeKey !== null" >
|
||||
{{ contentPreview = vm.getElementTypeByKey(vm.block.contentTypeKey); "" }}
|
||||
<umb-node-preview icon="contentPreview.icon" name="contentPreview.name"></umb-node-preview>
|
||||
<umb-node-preview icon="vm.contentPreview.icon" name="vm.contentPreview.name" alias="vm.contentPreview.alias"></umb-node-preview>
|
||||
<div class="__control-actions">
|
||||
<button type="button" class="btn-reset __control-actions-btn --open umb-outline" ng-click="vm.openElementType(vm.block.contentTypeKey)">
|
||||
<i class="icon icon-edit"></i>
|
||||
@@ -125,8 +124,7 @@
|
||||
<label class="control-label"><localize key="blockEditor_labelSettingsElementType">Settings Element Type</localize></label>
|
||||
<div class="controls">
|
||||
<div class="__settings-input --hasValue" ng-if="vm.block.settingsElementTypeKey !== null">
|
||||
{{ settingsPreview = vm.getElementTypeByKey(vm.block.settingsElementTypeKey); "" }}
|
||||
<umb-node-preview icon="settingsPreview.icon" name="settingsPreview.name"></umb-node-preview>
|
||||
<umb-node-preview icon="vm.settingsPreview.icon" name="vm.settingsPreview.name" alias="vm.settingsPreview.alias"></umb-node-preview>
|
||||
<div class="__control-actions">
|
||||
<button type="button" class="btn-reset __control-actions-btn --open umb-outline" ng-click="vm.openElementType(vm.block.settingsElementTypeKey)">
|
||||
<i class="icon icon-edit"></i>
|
||||
|
||||
Reference in New Issue
Block a user