adminview.js
6.87 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/*
*
* ADOBE CONFIDENTIAL
* __________________
*
* Copyright 2014 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 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.
*/
define('screens/player/ui/adminview', [
'underscore',
'jquery',
'./baseview',
'./adminview-system',
'./adminview-registration',
'./adminview-channels',
'./adminview-configuration',
'./adminview-cache',
'screens/player/runtime/admin',
'screens/player/shared/serviceadmin',
'screens/player/store/store',
'screens/player/firmware/preferences/preferences'
], function(_, $, BaseView, SystemView, RegistrationView, ChannelsView, ConfigView, CacheView, Admin, ServiceAdmin, Store, Preferences) {
'use strict';
var DEFAULT_OPTIONS = {
longPressDuration: 1000,
enableHiddenTrigger: false
};
var AdminView = BaseView.extend(/** @lends AdminView.prototype */{
template: function() {
return '<div class="aem-ScreensPlayer-admin-inner">' +
'<div class="aem-ScreensPlayer-admin-header">Adobe Experience Manager Screens</div>' +
'<hr>' +
'<ul class="aem-ScreensPlayer-admin-menu"></ul>' +
'<div class="aem-ScreensPlayer-admin-content"></div>' +
'<div class="aem-ScreensPlayer-admin-close"></div>' +
'</div>';
},
className: 'aem-ScreensPlayer-admin',
events: {
'click .aem-ScreensPlayer-admin-close': '_close',
'click li': '_select'
},
/**
* @classdesc View that renders the admin menu
* @class AdminView
* @extends BaseView
*
* @param {Object} [options] An object of configurable options.
*/
constructor: function(options) {
var self = this;
this._initOptions(options, DEFAULT_OPTIONS);
AdminView.__super__.constructor.apply(this, arguments);
this._views = {
'system': {
view: new SystemView(),
title: 'System Information'
},
'registration': {
view: new RegistrationView(),
title: 'Device Registration'
},
'channels': {
view: new ChannelsView({
}),
title: 'Channels'
},
'cache': {
view: new CacheView(),
title: 'Content Cache'
},
'config': {
view: new ConfigView(),
title: 'Configuration'
}
};
$('body').append(this.render().$el);
ServiceAdmin.onServiceHighestRankedStart(Store.serviceName, function(store) {
store.subscribe(self._handlePreferenceChange.bind(self), Preferences.NAMESPACE);
store.subscribe(self._handleAdminStateChange.bind(self), Admin.NAMESPACE);
// make sure handlers are called
store.requestState();
});
},
_handlePreferenceChange: function(preferences) {
if (preferences) {
this.options.enableHiddenTrigger = preferences.enableAdminUI !== false;
}
},
_handleAdminStateChange: function(adminui) {
if (adminui) {
if (adminui.visible === 'show') {
this.show();
this.selectView(adminui.tabName);
} else if (adminui.visible === 'hide') {
this.hide();
}
}
},
_buildTrigger: function() {
var $trigger = $(document.createElement('button')).addClass('aem-ScreensPlayer-admin-trigger');
$('body').append($trigger);
// Long-press on the button should toggle the OSD
$trigger.on('mousedown touchstart pointerdown', function(ev) {
if (this.options.enableHiddenTrigger && !this.longPressTimer) { // Don't react if disabled and avoid duplicate calls
this.longPressTimer = setTimeout(function() {
clearTimeout(this.longPressTimer);
this.longPressTimer = null;
var adminSvc = ServiceAdmin.getService(Admin.serviceName);
adminSvc.show();
}.bind(this), this.options.longPressDuration);
}
}.bind(this));
$trigger.on('mouseup touchend pointerup', function(ev) {
if (this.longPressTimer) {
clearTimeout(this.longPressTimer);
this.longPressTimer = null;
}
}.bind(this));
return $trigger;
},
render: function() {
// prevent re-render
if (this.setRendered(true)) {
return this;
}
this.$el.append(this.template());
this._buildTrigger();
var $menu = this._$menu = this.$el.find('.aem-ScreensPlayer-admin-menu');
var $content = this._$content = this.$el.find('.aem-ScreensPlayer-admin-content');
_.each(this._views, function(v, name) {
var $view = v.$el = v.view.render().$el;
$content.append($view);
$view.hide();
v.$menu = $('<li data-name="' + name + '"/>').html(v.title);
$menu.append(v.$menu);
});
this.selectView('system');
return this;
},
selectView: function(name) {
var view = this._views[name];
if (!view) {
return;
}
this._$menu.find('li').removeClass('active');
view.$menu.addClass('active');
this._$content.children().trigger('hide');
this._$content.children().hide();
view.$el.trigger('show');
view.$el.show();
},
_select: function(e) {
var $li = $(e.currentTarget);
var name = $li.data('name');
var adminService = ServiceAdmin.getService(Admin.serviceName);
adminService.show(name);
},
_close: function(e) {
var adminSvc = ServiceAdmin.getService(Admin.serviceName);
adminSvc.hide();
}
});
// return module exports
return AdminView;
});