]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - button/HelpButton.js
refactor info/link extraction from onlinehelp to utils
[proxmox-widget-toolkit.git] / button / HelpButton.js
CommitLineData
a3489b10
DM
1/* help button pointing to an online documentation
2 for components contained in a modal window
3*/
4/*global
5 proxmoxOnlineHelpInfo
6*/
7Ext.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 // this sets the link and the tooltip text
45 setOnlineHelp:function(blockid) {
46 var me = this;
47
1098bee4 48 var info = Proxmox.Utils.get_help_info(blockid);
a3489b10
DM
49 if (info) {
50 me.onlineHelp = blockid;
51 var title = info.title;
52 if (info.subtitle) {
53 title += ' - ' + info.subtitle;
54 }
55 me.setTooltip(title);
56 }
57 },
58
59 // helper to set the onlineHelp via a config object
60 setHelpConfig: function(config) {
61 var me = this;
62 me.setOnlineHelp(config.onlineHelp);
63 },
64
65 handler: function() {
66 var me = this;
67 var docsURI;
68
69 if (me.onlineHelp) {
1098bee4 70 docsURI = Proxmox.Utils.get_help_link(me.onlineHelp);
a3489b10
DM
71 }
72
73 if (docsURI) {
74 window.open(docsURI);
75 } else {
76 Ext.Msg.alert(gettext('Help'), gettext('No Help available'));
77 }
78 },
79
80 initComponent: function() {
81 /*jslint confusion: true */
82 var me = this;
83
84 me.callParent();
85
86 if (me.onlineHelp) {
87 me.setOnlineHelp(me.onlineHelp); // set tooltip
88 }
89 }
90});