From 3cf341e92a5f4417dfb1ef229e484f74f521c1aa Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 13 Sep 2018 14:55:54 +0200 Subject: [PATCH] add node/HostsView to show/edit /etc/hosts Signed-off-by: Dominik Csapak --- Makefile | 1 + node/HostsView.js | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 node/HostsView.js diff --git a/Makefile b/Makefile index ad820a2..20dba60 100644 --- 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 index 0000000..2978324 --- /dev/null +++ b/node/HostsView.js @@ -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(); + } +}); -- 2.39.2