]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
add node/HostsView
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 13 Sep 2018 12:55:54 +0000 (14:55 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 14 Sep 2018 09:51:31 +0000 (11:51 +0200)
to show/edit /etc/hosts

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Makefile
node/HostsView.js [new file with mode: 0644]

index ad820a27180ccbfa1aefaee9e8a28e5194ba9ce8..20dba60bd2ff8bcb986d25fd78f1779f1053f7c5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -45,6 +45,7 @@ JSSRC=                                        \
        node/NetworkEdit.js             \
        node/NetworkView.js             \
        node/DNSEdit.js                 \
+       node/HostsView.js               \
        node/DNSView.js                 \
        node/Tasks.js                   \
        node/ServiceView.js             \
diff --git a/node/HostsView.js b/node/HostsView.js
new file mode 100644 (file)
index 0000000..2978324
--- /dev/null
@@ -0,0 +1,95 @@
+Ext.define('Proxmox.node.HostsView', {
+    extend: 'Ext.panel.Panel',
+    xtype: 'proxmoxNodeHostsView',
+
+    reload: function() {
+       var me = this;
+       me.store.load();
+    },
+
+    tbar: [
+       {
+           text: gettext('Save'),
+           disabled: true,
+           itemId: 'savebtn',
+           handler: function() {
+               var me = this.up('panel');
+               Proxmox.Utils.API2Request({
+                   params: {
+                       digest: me.digest,
+                       data: me.down('#hostsfield').getValue()
+                   },
+                   method: 'POST',
+                   url: '/nodes/' + me.nodename + '/hosts',
+                   waitMsgTarget: me,
+                   success: function(response, opts) {
+                       me.reload();
+                   },
+                   failure: function(response, opts) {
+                       Ext.Msg.alert('Error', response.htmlStatus);
+                   }
+               });
+           }
+       },
+       {
+           text: gettext('Revert'),
+           disabled: true,
+           itemId: 'resetbtn',
+           handler: function() {
+               var me = this.up('panel');
+               me.down('#hostsfield').reset();
+           }
+       }
+    ],
+
+           layout: 'fit',
+
+    items: [
+       {
+           xtype: 'textarea',
+           itemId: 'hostsfield',
+           fieldStyle: {
+               'font-family': 'monospace',
+               'white-space': 'pre'
+           },
+           listeners: {
+               dirtychange: function(ta, dirty) {
+                   var me = this.up('panel');
+                   me.down('#savebtn').setDisabled(!dirty);
+                   me.down('#resetbtn').setDisabled(!dirty);
+               }
+           }
+       }
+    ],
+
+    initComponent : function() {
+       var me = this;
+
+       if (!me.nodename) {
+           throw "no node name specified";
+       }
+
+       me.store = Ext.create('Ext.data.Store', {
+           proxy: {
+               type: 'proxmox',
+               url: "/api2/json/nodes/" + me.nodename + "/hosts",
+           }
+       });
+
+       me.callParent();
+
+       Proxmox.Utils.monStoreErrors(me, me.store);
+
+       me.mon(me.store, 'load', function(store, records, success) {
+           if (!success || records.length < 1) {
+               return;
+           }
+           me.digest = records[0].data.digest;
+           var data = records[0].data.data;
+           me.down('#hostsfield').setValue(data);
+           me.down('#hostsfield').resetOriginalValue();
+       });
+
+       me.reload();
+    }
+});