cq.screens.dcc.unassignChannel.js
3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* ADOBE CONFIDENTIAL
*
* Copyright 2016 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*/
(function(window, $, i18n) {
'use strict';
// global actions for GraniteUI foundation
var ui = $(window).adaptTo('foundation-ui');
// deletes entries of a collection with the sling post servlet
$(window).adaptTo('foundation-registry').register('foundation.collection.action.action', {
name: 'cq.screens.dcc.unassignChannel',
handler: function(name, el, config, collection, selections) {
var displayPaths = selections.map(function(v) {
return v.dataset.foundationCollectionItemId;
});
if (!displayPaths.length) {
return;
}
var channelPath = collection.dataset.foundationCollectionId;
if (!channelPath) {
return;
}
function handlePrompt() {
ui.wait();
window.CQ.screens.dcc.channel.unassignFromDisplays(channelPath, displayPaths).then(function() {
ui.clearWait();
$(collection).adaptTo('foundation-collection').reload();
}, function(err) {
ui.clearWait();
ui.notify(i18n.get('Deletion failed'), err, 'error');
});
}
var message = $('<div/>');
var intro = $('<p/>').appendTo(message);
if (selections.length === 1) {
intro.text(Granite.I18n.get('You are going to remove the channel assignment from the following display:'));
} else {
intro.text(Granite.I18n.get('You are going to remove the channel assignment from the following {0} displays:', selections.length));
}
// Re-using the algorithm from Sites' delete operation
var list = [];
var maxCount = Math.min(selections.length, 12);
for (var i = 0; i < maxCount; i++) {
var title = $(selections[i]).find('.foundation-collection-item-title').text();
list.push($('<b/>').text(title).prop('outerHTML'));
}
if (selections.length > maxCount) {
list.push('…'); // … is ellipsis
}
$('<p/>').html(list.join('<br>')).appendTo(message);
// Let the user choose what to do next
ui.prompt(i18n.get('Remove Channel Assignments'), message.html(), 'notice', [
{text: i18n.get('Cancel')},
{text: i18n.get('Remove'), warning: true, handler: handlePrompt}
]);
}
});
}(window, Granite.$, Granite.I18n));