This repository has been archived by the owner on Oct 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
widget-root.js
102 lines (79 loc) · 2.04 KB
/
widget-root.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
/*
Loading Flow
------------
1. Add widget to a section for displaying
2. Widget is registered
3. addWidget in dashboard-core is called from the widget
4. Dashboard calls widget.init
5. widget.setData is called by widget.init
6. widget.ready is called by widget.init
7. widget.render is called by widget.init
8. widget.fetch is called by widget.render
9. widget.postRender is called by widget.render
10. widget.subscribe is called by widget.init
*/
window.widgetRoot = {
hideLink: false,
hideRefresh: false,
refreshOnStart: false,
initialized: false,
ready: function() {
this.render();
},
setData: function(data) {
this.data = data;
},
fetch: function() {
this.postFetch();
},
postFetch: function() { },
subscribe: function() { },
init: function(data) {
Dashboard.Utils.emit('widget|init|' + this.name);
if (data) {
this.setData(data);
}
this.shell = Dashboard.TEMPLATES.widget({
name: this.name,
title: this.title,
size: this.size,
hideLink: this.hideLink,
hideRefresh: this.hideRefresh,
customButtons: this.customButtons
});
this.initialized = true;
Dashboard.Utils.emit('widget|ready|' + this.name);
this.ready();
Dashboard.Utils.emit('widget|render|' + this.name);
this.subscribe();
// Tag the widget with appropriate service
if(data.service) {
$('#widget-shell-' + this.shell.id).data('service', data.service);
} else {
$('#widget-shell-' + this.shell.id).data('service', '_common');
}
},
render: function() {
Dashboard.render.widget(this.name, this.shell.tpl);
this.fetch();
$('#widget-' + this.shell.id).css({
'height': '240px',
'margin-bottom': '10px',
'overflow-x': 'hidden',
'width': '100%'
});
this.postRender();
$(document).trigger('WidgetInternalEvent', ['widget|rendered|' + this.name]);
},
_$: function(id) {
if (id !== undefined) {
return $('#widget-' + this.shell.id).find(id);
} else {
return $('#widget-' + this.shell.id);
}
},
postRender: function() { },
refresh: _.debounce(function() {
this.fetch();
}, 100),
};