]> git.proxmox.com Git - proxmox-widget-toolkit.git/blob - node/HostsView.js
add node/HostsView
[proxmox-widget-toolkit.git] / node / HostsView.js
1 Ext.define('Proxmox.node.HostsView', {
2 extend: 'Ext.panel.Panel',
3 xtype: 'proxmoxNodeHostsView',
4
5 reload: function() {
6 var me = this;
7 me.store.load();
8 },
9
10 tbar: [
11 {
12 text: gettext('Save'),
13 disabled: true,
14 itemId: 'savebtn',
15 handler: function() {
16 var me = this.up('panel');
17 Proxmox.Utils.API2Request({
18 params: {
19 digest: me.digest,
20 data: me.down('#hostsfield').getValue()
21 },
22 method: 'POST',
23 url: '/nodes/' + me.nodename + '/hosts',
24 waitMsgTarget: me,
25 success: function(response, opts) {
26 me.reload();
27 },
28 failure: function(response, opts) {
29 Ext.Msg.alert('Error', response.htmlStatus);
30 }
31 });
32 }
33 },
34 {
35 text: gettext('Revert'),
36 disabled: true,
37 itemId: 'resetbtn',
38 handler: function() {
39 var me = this.up('panel');
40 me.down('#hostsfield').reset();
41 }
42 }
43 ],
44
45 layout: 'fit',
46
47 items: [
48 {
49 xtype: 'textarea',
50 itemId: 'hostsfield',
51 fieldStyle: {
52 'font-family': 'monospace',
53 'white-space': 'pre'
54 },
55 listeners: {
56 dirtychange: function(ta, dirty) {
57 var me = this.up('panel');
58 me.down('#savebtn').setDisabled(!dirty);
59 me.down('#resetbtn').setDisabled(!dirty);
60 }
61 }
62 }
63 ],
64
65 initComponent : function() {
66 var me = this;
67
68 if (!me.nodename) {
69 throw "no node name specified";
70 }
71
72 me.store = Ext.create('Ext.data.Store', {
73 proxy: {
74 type: 'proxmox',
75 url: "/api2/json/nodes/" + me.nodename + "/hosts",
76 }
77 });
78
79 me.callParent();
80
81 Proxmox.Utils.monStoreErrors(me, me.store);
82
83 me.mon(me.store, 'load', function(store, records, success) {
84 if (!success || records.length < 1) {
85 return;
86 }
87 me.digest = records[0].data.digest;
88 var data = records[0].data.data;
89 me.down('#hostsfield').setValue(data);
90 me.down('#hostsfield').resetOriginalValue();
91 });
92
93 me.reload();
94 }
95 });