Skip to content

Commit 48b5c4e

Browse files
committed
Don't show deleted nodes in backoffice, fixes #51
1 parent 6096d22 commit 48b5c4e

File tree

1 file changed

+51
-37
lines changed

1 file changed

+51
-37
lines changed

src/RJP.MultiUrlPicker/App_Plugins/RJP.MultiUrlPicker/MultiUrlPicker.js

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(function(angular, _) {
22
'use strict';
33

4-
angular.module("umbraco").controller("RJP.MultiUrlPickerController", function($scope, dialogService, iconHelper, entityResource) {
4+
angular.module("umbraco").controller("RJP.MultiUrlPickerController", function($scope, $q, dialogService, iconHelper, entityResource) {
55
var documentIds = [];
66
var mediaIds = [];
77

@@ -12,26 +12,64 @@
1212

1313
if( $scope.model.value ) {
1414
_.each($scope.model.value, function( item, i ) {
15-
$scope.renderModel.push(new Link(item));
1615
if( item.id ) {
1716
(item.isMedia ? mediaIds : documentIds).push( item.id );
1817
}
1918
});
2019
}
2120

22-
var setIcon = function( nodes ) {
23-
if( _.isArray( nodes ) ) {
24-
_.each( nodes, setIcon );
25-
} else {
26-
var item = _.find( $scope.renderModel, function( item ) {
27-
return +item.id === nodes.id;
28-
});
29-
item.icon = iconHelper.convertFromLegacyIcon( nodes.icon );
30-
}
21+
var setIcon = function( node ) {
22+
var item = _.find( $scope.renderModel, function( item ) {
23+
return +item.id === node.id;
24+
});
25+
item.icon = iconHelper.convertFromLegacyIcon( node.icon );
3126
};
3227

33-
entityResource.getByIds( documentIds, 'Document' ).then( setIcon );
34-
entityResource.getByIds( mediaIds, 'Media' ).then( setIcon );
28+
$q.all([
29+
entityResource.getByIds(documentIds, 'Document'),
30+
entityResource.getByIds(mediaIds, 'Media')
31+
]).then(function (result) {
32+
var entities = result[0].concat(result[1]);
33+
34+
_.each($scope.model.value, function (item) {
35+
if (item.id) {
36+
var entity = _.find(entities, function (e) {
37+
return e.id == item.id;
38+
});
39+
40+
if (entity) {
41+
item.icon = iconHelper.convertFromLegacyIcon(entity.icon);
42+
$scope.renderModel.push(new Link(item));
43+
}
44+
} else {
45+
$scope.renderModel.push(new Link(item));
46+
}
47+
});
48+
49+
$scope.$watch(
50+
function () {
51+
return $scope.renderModel.length;
52+
},
53+
function (newVal) {
54+
if ($scope.renderModel.length) {
55+
$scope.model.value = $scope.renderModel;
56+
} else {
57+
$scope.model.value = null;
58+
}
59+
60+
if ($scope.cfg.minNumberOfItems && +$scope.cfg.minNumberOfItems > $scope.renderModel.length) {
61+
$scope.multiUrlPickerForm.minCount.$setValidity('minCount', false);
62+
} else {
63+
$scope.multiUrlPickerForm.minCount.$setValidity('minCount', true);
64+
}
65+
if ($scope.cfg.maxNumberOfItems && +$scope.cfg.maxNumberOfItems < $scope.renderModel.length) {
66+
$scope.multiUrlPickerForm.maxCount.$setValidity('maxCount', false);
67+
} else {
68+
$scope.multiUrlPickerForm.maxCount.$setValidity('maxCount', true);
69+
}
70+
}
71+
);
72+
});
3573

3674
if ( $scope.model.config ) {
3775
$scope.cfg = angular.extend( $scope.cfg, $scope.model.config );
@@ -74,30 +112,6 @@
74112
$scope.model.value = $scope.renderModel;
75113
};
76114

77-
$scope.$watch(
78-
function() {
79-
return $scope.renderModel.length;
80-
},
81-
function(newVal) {
82-
if( $scope.renderModel.length ) {
83-
$scope.model.value = $scope.renderModel;
84-
} else {
85-
$scope.model.value = null;
86-
}
87-
88-
if( $scope.cfg.minNumberOfItems && +$scope.cfg.minNumberOfItems > $scope.renderModel.length ) {
89-
$scope.multiUrlPickerForm.minCount.$setValidity( 'minCount', false );
90-
} else {
91-
$scope.multiUrlPickerForm.minCount.$setValidity( 'minCount', true );
92-
}
93-
if( $scope.cfg.maxNumberOfItems && +$scope.cfg.maxNumberOfItems < $scope.renderModel.length ) {
94-
$scope.multiUrlPickerForm.maxCount.$setValidity( 'maxCount', false );
95-
} else {
96-
$scope.multiUrlPickerForm.maxCount.$setValidity( 'maxCount', true );
97-
}
98-
}
99-
);
100-
101115
$scope.$on("formSubmitting", function(ev, args) {
102116
if( $scope.renderModel.length ) {
103117
$scope.model.value = $scope.renderModel;

0 commit comments

Comments
 (0)