forked from Alfresco/Aikau
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dashlet.js
343 lines (321 loc) · 12 KB
/
Dashlet.js
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*jshint maxlen:false*/
/**
* Copyright (C) 2005-2016 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* A dashlet for use on a dashboard. It can be used in JSON page models if configured with
* a widgets definition. Otherwise it can be extended to define specific views.
*
* By passing in certain pre-supported classes to the additionalCssClasses config property, it's
* possible add padding to the body. The current available padding classes are smallpad (4px
* padding), mediumpad (10px padding - recommended) and largepad (16px padding).
*
* @example <caption>Sample configuration</caption>
* {
* name: "alfresco/dashlets/Dashlet",
* id: "MY_DASHLET",
* config: {
* additionalCssClasses: "mediumpad",
* bodyHeight: 300, // Specify the initial height of the body
* componentId: "component.valid-dashlet", // A valid component ID (for Share height persistence)
* pubSubScope: "DASHLET_SCOPE_",
* title: "My Dashlet",
* widgetsForTitleBarActions: [
* {
* name: "alfresco/html/Label",
* config: {
* label: "Title-bar actions"
* }
* }
* ],
* widgetsForToolbar: [
* {
* name: "alfresco/html/Label",
* config: {
* label: "Toolbar"
* }
* }
* ],
* widgetsForToolbar2: [
* {
* name: "alfresco/html/Label",
* config: {
* label: "Toolbar2"
* }
* }
* ],
* widgetsForBody: [
* {
* name: "alfresco/html/Label",
* config: {
* label: "Collaboratively administrate empowered markets via plug-and-play networks. Dynamically procrastinate B2C users after installed base *benefits. Dramatically visualize customer directed convergence without revolutionary ROI. Efficiently unleash cross-media information wit*hout *cross-media value. Quickly maximize timely deliverables for real-time schemas. Dramatically maintain clicks-and-mortar solutions without *functional solutions. Completely synergize resource sucking relationships via premier niche markets. Professionally cultivate one-to-one *customer service with robust ideas. Dynamically innovate resource-leveling customer service for state of the art customer service."
* }
* }
* ]
* }
* }
*
* @module alfresco/dashlets/Dashlet
* @extends external:dijit/_WidgetBase
* @extends module:alfresco/core/ResizeMixin
* @mixes external:dojo/_TemplatedMixin
* @mixes module:alfresco/core/Core
* @mixes module:alfresco/core/CoreWidgetProcessing*
* @mixes module:alfresco/services/_DashletServiceTopicMixin
* @author Erik Winlöf
* @author Martin Doyle
*/
define(["dojo/_base/declare",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dojo/text!./templates/Dashlet.html",
"alfresco/core/Core",
"alfresco/core/CoreWidgetProcessing",
"alfresco/core/ResizeMixin",
"alfresco/core/topics",
"alfresco/services/_DashletServiceTopicMixin",
"dojo/_base/lang",
"dojo/_base/array",
"dojo/dom-construct",
"dojo/dom-class",
"dojo/dom-style",
"jquery",
"jqueryui"
],
function(declare, _WidgetBase, _TemplatedMixin, template, AlfCore, CoreWidgetProcessing,
ResizeMixin, topics, _DashletServiceTopicMixin, lang, array, domConstruct, domClass, domStyle, $) {
return declare([_WidgetBase, _TemplatedMixin, AlfCore, CoreWidgetProcessing, ResizeMixin, _DashletServiceTopicMixin], {
/**
* Id that will be used to store properties for this dashlet
* i.e. the dashlet height when using the resizer.
*
* @instance
* @type {string}
*/
componentId: null,
/**
* The base css class to use for this widget
*
* @instance
* @type {string}
* @default
*/
baseClass: "alfresco-dashlets-Dashlet",
/**
* A second css class for sub classes of this widget to use to be able to target
* specifics in such dashlets.
*
* @instance
* @type {string}
* @default
*/
subClass: "",
/**
* The i18n scope to use for this widget
*
* @instance
* @type {string}
*/
i18nScope: "alfresco.dashlets.Dashlet",
/**
* An array of the i18n files to use with this widget.
*
* @instance
* @type {object[]}
* @default [{i18nFile: "./i18n/Dashlet.properties"}]
*/
i18nRequirements: [{
i18nFile: "./i18n/Dashlet.properties"
}],
/**
* An array of the CSS files to use with this widget.
*
* @instance cssRequirements {Array}
* @type {object[]}
* @default [{cssFile:"./css/Dashlet.css"}]
*/
cssRequirements: [{
cssFile: "./css/Dashlet.css"
}],
/**
* The HTML template to use for the widget.
* @instance
* @type {String}
*/
templateString: template,
/**
* Config that makes it possible to dynamically update the title.
* Should be supplied in the format of
* {
* titleConfig: {
* topic: "SOME_TOPIC",
* attribute: "path.to.topic.payload.attribute"
* }
* }
*
* If there is no attribute present the entire payload value will be used as the title.
*
* @instance
* @type {object}
*/
titleConfig: null,
/**
* Widgets to place as title bar actions.
*
* @instance
* @type {object[]}
*/
widgetsForTitleBarActions: null,
/**
* Widgets to place in the first toolbar
*
* @instance
* @type {object[]}
*/
widgetsForToolbar: null,
/**
* Widgets to place in the second toolbar
*
* @instance
* @type {object[]}
*/
widgetsForToolbar2: null,
/**
* Widgets to place in the body
*
* @instance
* @type {object[]}
*/
widgetsForBody: null,
/**
* Explicit height in pixels of the dashlet body
*
* @instance
* @type {number}
* @default
*/
bodyHeight: null,
/**
* Whether resizing of this dashlet is disabled
*
* @type {boolean}
* @default
*/
resizeDisabled: false,
/**
* Implements the widget life-cycle method to add drag-and-drop upload capabilities to the root DOM node.
* This allows files to be dragged and dropped from the operating system directly into the browser
* and uploaded to the location represented by the document list.
*
* @instance
*/
postCreate: function alfresco_dashlets_Dashlet__postCreate() {
this.processContainer(this.widgetsForTitleBarActions, this.titleBarActionsNode);
this.processContainer(this.widgetsForToolbar, this.toolbarNode);
this.processContainer(this.widgetsForToolbar2, this.toolbar2Node);
if (this.bodyHeight) {
domStyle.set(this.bodyNode, "height", this.bodyHeight + "px");
}
this.processContainer(this.widgetsForBody, this.bodyWidgetsNode);
if (this.componentId && !this.resizeDisabled) {
// Only make it resizable if a componentId has been provided, otherwise it will not be persisted correctly
$(this.bodyNode).resizable({
handles: {
"s": this.resizeNode
},
resize: lang.hitch(this, this.onResize),
stop: lang.hitch(this, this.onResizeEnd)
});
} else {
domClass.add(this.domNode, this.baseClass + "--no-resize");
}
},
/**
* Creates the widgets inside a container
*
* @instance
* @param widgets The widgets to create
* @param container The container to place the widgets in
*/
processContainer: function alfresco_dashlets_Dashlet__processContainer(widgets, container) {
var hasWidgets = widgets && widgets.length,
containerNode = container;
hasWidgets && this.processWidgets(lang.clone(widgets), container);
while (containerNode !== this.domNode) {
domClass[hasWidgets ? "add" : "remove"](containerNode, this.baseClass + "--has-widgets");
containerNode = containerNode.parentNode;
}
},
/**
* Make some of the i18n keys available for the template
*
* @instance
*/
postMixInProperties: function alfresco_dashlets_Dashlet__postMixInProperties() {
// construct our I18N labels ready for template
this.label = {};
array.forEach(["title"], lang.hitch(this, function(key) {
this.label[key] = this.message(key);
if (this.title) {
this.label[key] = this.title;
}
}));
this.alfSubscribe(this.storeDashletHeightTopic + "_FAILURE", lang.hitch(this, this.onHeightStorageError));
},
/**
* Handle errors that occur while storing the dashlet height
*
* @instance
* @param {Object} payload The payload from the publishing of the failure topic
* @fires module:alfresco/core/topics#DISPLAY_NOTIFICATION
*/
onHeightStorageError: function(payload) {
this.alfServicePublish(topics.DISPLAY_NOTIFICATION, {
message: "Error occurred while storing dashlet height"
}, true);
this.alfLog("error", "Error storing dashlet height:\n\"" + payload.response.message + "\"");
},
/**
* Handle resize events
*
* @instance
* @param {object} evt The resize event object
* @param {object} ui The data about the resize
*/
onResize: function alfresco_layout_AlfSideBarContainer__onResize( /*jshint unused:false*/ evt, /*jshint unused:false*/ ui) {
this.bodyHeight = this.bodyNode.clientHeight;
this.alfPublishResizeEvent(this.bodyNode);
},
/**
* Calls [resizeHandler]{@link module:alfresco/layout/AlfSideBarContainer#resizeHandler} and then
* saves the new width as a user preference.
*
* @instance
* @param {object} evt The resize event
* @param {object} ui The data about the resize
*/
onResizeEnd: function alfresco_layout_AlfSideBarContainer__onResizeEnd(evt, ui) {
this.onResize(evt, ui);
this.alfPublish(this.storeDashletHeightTopic, {
componentId: this.componentId,
alfResponseTopic: this.pubSubScope + this.storeDashletHeightTopic,
height: this.bodyHeight
}, true);
}
});
});