]>
Commit | Line | Data |
---|---|---|
a3970d6c DC |
1 | Ext.define('PBS.TaskButton', { |
2 | extend: 'Ext.button.Button', | |
3 | alias: 'widget.pbsTaskButton', | |
4 | ||
5 | config: { | |
6 | badgeText: '0', | |
7 | badgeCls: '', | |
8 | }, | |
9 | ||
10 | iconCls: 'fa fa-list', | |
11 | userCls: 'pmx-has-badge', | |
12 | text: gettext('Tasks'), | |
13 | ||
14 | setText: function(value) { | |
15 | let me = this; | |
16 | me.realText = value; | |
17 | let badgeText = me.getBadgeText(); | |
18 | let badgeCls = me.getBadgeCls(); | |
19 | let text = `${value} <span class="pmx-button-badge ${badgeCls}">${badgeText}</span>`; | |
20 | return me.callParent([text]); | |
21 | }, | |
22 | ||
23 | getText: function() { | |
24 | let me = this; | |
25 | return me.realText; | |
26 | }, | |
27 | ||
28 | setBadgeText: function(value) { | |
29 | let me = this; | |
30 | me.badgeText = value.toString(); | |
31 | return me.setText(me.getText()); | |
32 | }, | |
33 | ||
34 | setBadgeCls: function(value) { | |
35 | let me = this; | |
36 | let res = me.callParent([value]); | |
37 | let badgeText = me.getBadgeText(); | |
38 | me.setBadgeText(badgeText); | |
39 | return res; | |
40 | }, | |
41 | ||
42 | handler: function() { | |
43 | let me = this; | |
44 | if (me.grid.isVisible()) { | |
45 | me.grid.setVisible(false); | |
46 | } else { | |
47 | me.grid.showBy(me, 'tr-br'); | |
48 | } | |
49 | }, | |
50 | ||
51 | initComponent: function() { | |
52 | let me = this; | |
53 | ||
54 | me.grid = Ext.create({ | |
55 | xtype: 'pbsRunningTasks', | |
56 | title: '', | |
57 | hideHeaders: false, | |
58 | floating: true, | |
59 | ||
60 | width: 600, | |
61 | ||
62 | bbar: [ | |
63 | '->', | |
64 | { | |
65 | xtype: 'button', | |
66 | text: gettext('Show All Tasks'), | |
67 | handler: function() { | |
68 | var mainview = me.up('mainview'); | |
69 | mainview.getController().redirectTo('pbsServerAdministration:tasks'); | |
70 | me.grid.hide(); | |
71 | }, | |
72 | }, | |
73 | ], | |
74 | ||
75 | listeners: { | |
76 | 'taskopened': function() { | |
77 | me.grid.hide(); | |
78 | }, | |
79 | }, | |
80 | }); | |
81 | me.callParent(); | |
82 | me.mon(me.grid.getStore().rstore, 'load', function(store, records, success) { | |
83 | if (!success) return; | |
84 | ||
85 | let count = records.length; | |
a0eb0cd3 | 86 | let text = count > 99 ? '99+' : count.toString(); |
a3970d6c DC |
87 | let cls = count > 0 ? 'active': ''; |
88 | me.setBadgeText(text); | |
89 | me.setBadgeCls(cls); | |
90 | }); | |
91 | }, | |
92 | }); |