]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - button/HelpButton.js
1bf3f32a0426f38ea66b549ff9556ea551a76451
[proxmox-widget-toolkit.git] / button / HelpButton.js
1 /* help button pointing to an online documentation
2 for components contained in a modal window
3 */
4 /*global
5 proxmoxOnlineHelpInfo
6 */
7 Ext.define('Proxmox.button.Help', {
8 extend: 'Ext.button.Button',
9 xtype: 'proxmoxHelpButton',
10
11 text: gettext('Help'),
12
13 // make help button less flashy by styling it like toolbar buttons
14 iconCls: ' x-btn-icon-el-default-toolbar-small fa fa-question-circle',
15 cls: 'x-btn-default-toolbar-small proxmox-inline-button',
16
17 hidden: true,
18
19 listenToGlobalEvent: true,
20
21 controller: {
22 xclass: 'Ext.app.ViewController',
23 listen: {
24 global: {
25 proxmoxShowHelp: 'onProxmoxShowHelp',
26 proxmoxHideHelp: 'onProxmoxHideHelp'
27 }
28 },
29 onProxmoxShowHelp: function(helpLink) {
30 var me = this.getView();
31 if (me.listenToGlobalEvent === true) {
32 me.setOnlineHelp(helpLink);
33 me.show();
34 }
35 },
36 onProxmoxHideHelp: function() {
37 var me = this.getView();
38 if (me.listenToGlobalEvent === true) {
39 me.hide();
40 }
41 }
42 },
43
44 getOnlineHelpInfo: function (ref) {
45 var helpMap;
46 if (typeof proxmoxOnlineHelpInfo !== 'undefined') {
47 helpMap = proxmoxOnlineHelpInfo;
48 } else if (typeof pveOnlineHelpInfo !== 'undefined') {
49 // be backward compatible with older pve-doc-generators
50 helpMap = pveOnlineHelpInfo;
51 } else {
52 throw "no global OnlineHelpInfo map declared";
53 }
54
55 return helpMap[ref];
56 },
57
58 // this sets the link and the tooltip text
59 setOnlineHelp:function(blockid) {
60 var me = this;
61
62 var info = me.getOnlineHelpInfo(blockid);
63 if (info) {
64 me.onlineHelp = blockid;
65 var title = info.title;
66 if (info.subtitle) {
67 title += ' - ' + info.subtitle;
68 }
69 me.setTooltip(title);
70 }
71 },
72
73 // helper to set the onlineHelp via a config object
74 setHelpConfig: function(config) {
75 var me = this;
76 me.setOnlineHelp(config.onlineHelp);
77 },
78
79 handler: function() {
80 var me = this;
81 var docsURI;
82
83 if (me.onlineHelp) {
84 var info = me.getOnlineHelpInfo(me.onlineHelp);
85 if (info) {
86 docsURI = window.location.origin + info.link;
87 }
88 }
89
90 if (docsURI) {
91 window.open(docsURI);
92 } else {
93 Ext.Msg.alert(gettext('Help'), gettext('No Help available'));
94 }
95 },
96
97 initComponent: function() {
98 /*jslint confusion: true */
99 var me = this;
100
101 me.callParent();
102
103 if (me.onlineHelp) {
104 me.setOnlineHelp(me.onlineHelp); // set tooltip
105 }
106 }
107 });