Skip to content

Commit 113a1a5

Browse files
authored
Merge pull request #24 from nathanwoulfe/block-editor-list
Block list editor changes
2 parents 23bb58e + 3f6067c commit 113a1a5

File tree

5 files changed

+59
-44
lines changed

5 files changed

+59
-44
lines changed

src/NestingContently/backoffice/app.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,32 @@
77
'nc.components'
88
])
99
.constant('ncStrings', {
10-
disabledClass: 'umb-nested-content__item--disabled',
11-
itemClass: '.umb-nested-content__item',
12-
editorName: 'NestingContently'
10+
editorName: 'NestingContently',
11+
nc: {
12+
disabledClass: 'umb-nested-content__item--disabled',
13+
itemClass: '.umb-nested-content__item',
14+
},
15+
bl: {
16+
disabledClass: 'umb-block-list__block--disabled',
17+
itemClass: '.umb-block-list__block',
18+
}
1319
});
1420

1521
angular.module('umbraco').requires.push('nc');
1622

23+
const ncPattern = /<div class="umb-nested-content__icons">/gmi;
24+
const blPattern = /<div class="umb-block-list__block--actions">/gmi;
25+
26+
const ncString = '$&<nc-toggle node="node" index="$index" type="nc"></nc-toggle>';
27+
const blString = '$&<nc-toggle node="vm.layout.$block" index="vm.index" type="bl"></nc-toggle>';
28+
1729
for (let q of angular.module('umbraco')._invokeQueue) {
18-
if (q[2][0] === 'nestedContentPropertyEditor') {
19-
const pattern = /<div class="umb-nested-content__icons">/gmi;
20-
q[2][1].template = q[2][1].template.replace(pattern, '$&<nc-toggle node="node" index="$index"></nc-toggle>');
30+
let queueItem = q[2][0];
31+
32+
if (queueItem === 'nestedContentPropertyEditor') {
33+
q[2][1].template = q[2][1].template.replace(ncPattern, ncString);
34+
} else if (queueItem === 'umbBlockListRow') {
35+
q[2][1].template = q[2][1].template.replace(blPattern, blString);
2136
}
2237
}
2338

src/NestingContently/backoffice/button.component.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,40 @@
44
function controller($element, $rootScope, locale, strings) {
55

66
let prop = {};
7-
let labels = {};
7+
let labels = {};
88
let disabled = false;
99

1010
locale.localizeMany(['actions_enable','actions_disable']).then(data => {
11-
labels.enable = data[0];
12-
labels.disable = data[1];
11+
let [enable, disable] = data;
12+
labels = { enable, disable };
1313
});
1414

15-
const setClass = fn => $element.closest(strings.itemClass)[0].classList[fn](strings.disabledClass);
15+
const setClass = fn => $element.closest(strings[this.type].itemClass)[0]
16+
.classList[fn](strings[this.type].disabledClass);
17+
1618
const setTitle = () => this.iconTitle = disabled ? labels.enable : labels.disable;
17-
const setDisabledClass = () => this.disabledClass = disabled ? strings.disabledClass : '';
1819

1920
this.toggle = () => {
2021
disabled = !disabled;
2122
prop.value = disabled ? '1' : '0';
2223

23-
$rootScope.$broadcast('ncDisabledToggle', { value: prop.value, key: this.node.key });
24+
if (this.type === 'nc') {
25+
$rootScope.$broadcast('ncDisabledToggle', { value: prop.value, key: this.node.key });
26+
}
2427

2528
setTitle();
26-
setDisabledClass();
2729
setClass('toggle');
2830
};
2931

3032
this.$onInit = () => {
3133
if (this.node) {
32-
const props = this.node.variants[0].tabs[0]
33-
.properties.filter(p => p.editor === strings.editorName);
34+
prop = (this.type === 'nc' ? this.node : this.node.content).variants[0].tabs[0]
35+
.properties.find(p => p.editor === strings.editorName);
3436

35-
if (props.length === 1) {
36-
prop = props[0];
37+
if (prop) {
3738
disabled = prop.value === '1';
3839

3940
setTitle();
40-
setDisabledClass();
4141

4242
if (disabled) {
4343
setClass('add');
@@ -52,19 +52,19 @@
5252
const template = `
5353
<button type="button" class="umb-nested-content__icon umb-nested-content__icon--disable"
5454
title="{{ $ctrl.iconTitle }}"
55-
ng-click="$ctrl.toggle(); $event.stopPropagation()"
56-
ng-class="$ctrl.disabledClass">
55+
ng-click="$ctrl.toggle(); $event.stopPropagation()">
5756
<i class="icon icon-power" aria-hidden="true"></i>
5857
<span class="sr-only">
59-
<localize key="general_disable">Disable</localize>
58+
{{ $ctrl.iconTitle }}
6059
</span>
6160
</button>`;
6261

6362
const component = {
6463
transclude: true,
6564
bindings: {
6665
node: '<',
67-
index: '<'
66+
index: '<',
67+
type: '@'
6868
},
6969
controller: controller,
7070
template: template

src/NestingContently/backoffice/editor.controller.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
(() => {
22
function nestingContently($scope, $element) {
3-
const propElm = $element[0].closest('.umb-nested-content-property-container');
3+
// get the closest nested content property, or generic umb property if no NC
4+
let propElm = $element[0].closest('.umb-nested-content-property-container');
5+
let isNc = propElm != null;
6+
7+
propElm = propElm || $element[0].closest('umb-property');
8+
49
if (propElm) {
510
propElm.style.display = 'none';
611
}
712

8-
// find the key for this NC panel, to use as a guard
9-
// when receiving the ncDisabledToggle event
10-
let ncScope = $scope.$parent.$parent;
11-
do {
12-
ncScope = ncScope.$parent;
13-
} while (!Object.prototype.hasOwnProperty.call(ncScope, 'ngModel'));
13+
// NestedContent needs events to work, due to binding craziness
14+
// BlockList does not, so we can guard this entire block
15+
if (isNc) {
16+
let scope = $scope.$parent.$parent;
17+
do {
18+
scope = scope.$parent;
19+
} while (!Object.prototype.hasOwnProperty.call(scope, 'ngModel'));
1420

15-
const key = ncScope.ngModel.key;
21+
const key = scope.ngModel.key;
1622

17-
$scope.$on('ncDisabledToggle', (e, data) => {
18-
if (key === data.key) {
19-
$scope.model.value = data.value;
20-
}
21-
});
23+
$scope.$on('ncDisabledToggle', (e, data) => {
24+
if (key === data.key) {
25+
$scope.model.value = data.value;
26+
}
27+
});
28+
}
2229
}
2330

2431
angular.module('umbraco').controller('nestingContentlyController', ['$scope', '$element', nestingContently]);
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
<div ng-controller="nestingContentlyController">
2-
{{ model.value }}
3-
</div>
1+
<div ng-controller="nestingContentlyController"></div>
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
.umb-nested-content__item--disabled nc-toggle .umb-nested-content__icon--disabled,
2-
.umb-nested-content__item--disabled nc-toggle .umb-nested-content__icon--disabled .icon-power,
3-
.umb-nested-content__icon--disabled {
4-
opacity:1;
5-
}
6-
1+
.umb-block-list__block--disabled,
72
.umb-nested-content__item--disabled {
83
opacity: 0.5;
94
}

0 commit comments

Comments
 (0)