actions.js
5.41 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* ADOBE CONFIDENTIAL
*
* Copyright 2015 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, dcc) {
'use strict';
var ui = $(window).adaptTo('foundation-ui');
$(window).adaptTo('foundation-registry').register('foundation.collection.action.action', {
name: 'cq.screens.dcc.device.delete',
handler: function(name, el, config, collection, selections) {
var $title = $(selections[0]).find('.foundation-collection-item-title');
var deviceName = $title.attr('value') || $title.attr('title');
if (!deviceName) {
console.error('Fatal: Could not delete Device because Device Name could not be resolved.');
return;
}
function handlePrompt() {
ui.wait();
dcc.device.delete(deviceName).then(function() {
ui.clearWait();
$(collection).adaptTo('foundation-collection').reload();
}).catch(function(error) {
ui.clearWait();
ui.notify(i18n.get('Could not delete Device.'), error, 'error');
});
}
var PROMPT_HTML = '<p>' + i18n.get('You are going to delete the Device:') + '</p>' +
'<p><strong>' + deviceName + '</strong></p>';
// Let the user choose what to do next
ui.prompt(i18n.get('Delete Device'), PROMPT_HTML, 'default', [
{text: i18n.get('Cancel')},
{text: i18n.get('Delete'), warning: true, handler: handlePrompt}
]);
}
});
$(window).adaptTo('foundation-registry').register('foundation.collection.action.action', {
name: 'cq.screens.dcc.device.updateconfig',
handler: function(name, el, config, collection, selections) {
// Handle case when there is a selection
if (selections.length) {
var getDeviceId = function(tr) {
return tr.querySelector('.screens-Device-id').getAttribute('value');
};
var updateConfig = function(deviceId) {
return dcc.device.updateConfig(deviceId);
};
Promise.all(selections.map(getDeviceId).map(updateConfig))
.then(function() {
ui.notify(null, i18n.get('Update command sent to all devices.'), 'success');
})
.catch(function(error) {
ui.notify(null, error.message, 'error');
});
return;
}
// Handle case when there is no selection and we use the collection instead
var collectionId = collection.dataset.foundationCollectionId;
if (collectionId) {
dcc.device.bulkUpdateConfig(collectionId)
.then(function() {
ui.notify(null, i18n.get('Update command sent to all devices.'), 'success');
})
.catch(function(error) {
ui.notify(null, error.message, 'error');
});
}
}
});
$(window).adaptTo('foundation-registry').register('foundation.collection.action.action', {
name: 'cq.screens.dcc.device.unassign',
handler: function(name, el, config, collection, selections) {
function handlePrompt() {
ui.wait();
var devices = selections.map(function(item) {
return $(item).data('deviceId');
});
dcc.device.unassign(devices).then(function() {
ui.clearWait();
$(collection).adaptTo('foundation-collection').reload();
}).catch(function(error) {
ui.clearWait();
ui.notify(i18n.get('Could not unassign devices.'), error, 'error');
});
}
var message = '<p>';
if (selections.length === 1) {
message += i18n.get('You are going to remove the assignment for the following device:');
}
else {
message += i18n.get('You are going to remove the assignment for the following {0} devices:', selections.length);
}
message += '</p><p>';
selections.forEach(function(item) {
message += '<strong>' + $(item).find('.screens-Device-id').attr('title') + '</strong><br/>';
});
message + '</p>';
// Let the user choose what to do next
ui.prompt(i18n.get('Remove Device Assignment'), message, 'default', [
{text: i18n.get('Cancel')},
{text: i18n.get('Delete'), warning: true, handler: handlePrompt}
]);
}
});
}(window, Granite.$, Granite.I18n, window.CQ.screens.dcc));