]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - src/button/HelpButton.js
cleanly separate sources from package build, move to own folder
[proxmox-widget-toolkit.git] / src / button / HelpButton.js
1 /* help button pointing to an online documentation
2 for components contained in a modal window
3 */
4 Ext.define('Proxmox.button.Help', {
5 extend: 'Ext.button.Button',
6 xtype: 'proxmoxHelpButton',
7
8 text: gettext('Help'),
9
10 // make help button less flashy by styling it like toolbar buttons
11 iconCls: ' x-btn-icon-el-default-toolbar-small fa fa-question-circle',
12 cls: 'x-btn-default-toolbar-small proxmox-inline-button',
13
14 hidden: true,
15
16 listenToGlobalEvent: true,
17
18 controller: {
19 xclass: 'Ext.app.ViewController',
20 listen: {
21 global: {
22 proxmoxShowHelp: 'onProxmoxShowHelp',
23 proxmoxHideHelp: 'onProxmoxHideHelp',
24 },
25 },
26 onProxmoxShowHelp: function(helpLink) {
27 let view = this.getView();
28 if (view.listenToGlobalEvent === true) {
29 view.setOnlineHelp(helpLink);
30 view.show();
31 }
32 },
33 onProxmoxHideHelp: function() {
34 let view = this.getView();
35 if (view.listenToGlobalEvent === true) {
36 view.hide();
37 }
38 },
39 },
40
41 // this sets the link and the tooltip text
42 setOnlineHelp: function(blockid) {
43 let me = this;
44
45 let info = Proxmox.Utils.get_help_info(blockid);
46 if (info) {
47 me.onlineHelp = blockid;
48 let title = info.title;
49 if (info.subtitle) {
50 title += ' - ' + info.subtitle;
51 }
52 me.setTooltip(title);
53 }
54 },
55
56 // helper to set the onlineHelp via a config object
57 setHelpConfig: function(config) {
58 let me = this;
59 me.setOnlineHelp(config.onlineHelp);
60 },
61
62 handler: function() {
63 let me = this;
64 let docsURI;
65
66 if (me.onlineHelp) {
67 docsURI = Proxmox.Utils.get_help_link(me.onlineHelp);
68 }
69
70 if (docsURI) {
71 window.open(docsURI);
72 } else {
73 Ext.Msg.alert(gettext('Help'), gettext('No Help available'));
74 }
75 },
76
77 initComponent: function() {
78 let me = this;
79
80 me.callParent();
81
82 if (me.onlineHelp) {
83 me.setOnlineHelp(me.onlineHelp); // set tooltip
84 }
85 },
86 });