device-properties.js
3.08 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
/*
* 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, document, $, i18n, dcc) {
'use strict';
var PROPERTIES_DIALOG = '#screens-dcc-actions-deviceproperties-dialog';
var PROPERTIES_SELECTOR = '.screens-dashboard-DeviceInfoTile';
var BACKEND_ENDPOINT = '/profile_screens.json';
var ui = $(window).adaptTo('foundation-ui');
function startAsyncOperation(el) {
return Promise.resolve();
}
function updateProperties(endpoint, properties) {
return function() {
return $.ajax(endpoint, {
type: 'POST',
dataType: 'json',
data: properties
});
};
}
function reportError(err) {
ui.notify(null, err, 'error');
return Promise.resolve();
}
function hideDialog() {
$('.screens-dcc-actions-deviceproperties-dialog').get(0).hide();
return Promise.resolve();
}
function reloadUI() {
var content = $('.foundation-content').adaptTo('foundation-content');
content.refresh();
}
var handlePropertiesSubmit = function(ev) {
var $device = $('[data-device-path]');
var devicePath = $device.data('devicePath');
var props = $(PROPERTIES_DIALOG).serializeArray().reduce(function(res, param) {
if (!param.name.match(/^[_:]/)) {
res[param.name.split('/').pop()] = param.value;
}
return res;
}, {});
startAsyncOperation($(PROPERTIES_SELECTOR).get(0))
.then(updateProperties(devicePath + BACKEND_ENDPOINT, props))
.then(hideDialog)
.catch(reportError)
.then(reloadUI);
return false;
};
$(document).on('submit', PROPERTIES_DIALOG, handlePropertiesSubmit);
// Add cache busting parameter to the dialog src to make sure its data is updated after a modification
// Remove once GRANITE-14378 has been tackled
$(document).on('foundation-contentloaded', function(ev) {
if ($('.screens-DeviceDashboard').length) {
var $el = $('.screens-dcc-actions-Device-properties-activator');
if ($el.length) {
var action = $el.data('foundationCollectionAction');
action.data.src = action.data.src.replace(/\?.*/, '') + '?t=' + Date.now();
$el.data('foundationCollectionAction', action);
}
}
});
}(window, document, Granite.$, Granite.I18n, window.CQ.screens.dcc));