From 6c1a2b86907c8c2c4f9cf5bd5062fe7d160ff4a7 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Fri, 11 Mar 2016 11:48:19 +0100 Subject: [PATCH] disable template/upload button in manager6, fixes #483 also for manager6 Signed-off-by: Dominik Csapak --- www/manager6/storage/ContentView.js | 96 +++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 24 deletions(-) diff --git a/www/manager6/storage/ContentView.js b/www/manager6/storage/ContentView.js index 5ee33af1..96e7ce2b 100644 --- a/www/manager6/storage/ContentView.js +++ b/www/manager6/storage/ContentView.js @@ -183,10 +183,11 @@ Ext.define('PVE.storage.Upload', { items: [ { xtype: 'pveContentTypeSelector', - cts: ['iso', 'vztmpl'], + cts: me.contents, fieldLabel: gettext('Content'), name: 'content', - value: 'iso' + value: me.contents[0] || '', + allowBlank: false }, { xtype: 'filefield', @@ -357,10 +358,43 @@ Ext.define('PVE.storage.ContentView', { var reload = function() { store.load(); + me.statusStore.load(); }; PVE.Utils.monStoreErrors(me, store); + var templateButton = Ext.create('PVE.button.Button',{ + itemId: 'tmpl-btn', + text: gettext('Templates'), + handler: function() { + var win = Ext.create('PVE.storage.TemplateDownload', { + nodename: nodename, + storage: storage + }); + win.show(); + win.on('destroy', reload); + } + }); + + var uploadButton = Ext.create('PVE.button.Button', { + contents : ['iso','vztmpl'], + text: gettext('Upload'), + handler: function() { + var me = this; + var win = Ext.create('PVE.storage.Upload', { + nodename: nodename, + storage: storage, + contents: me.contents, + }); + win.show(); + win.on('destroy', reload); + } + }); + + me.statusStore = Ext.create('PVE.data.ObjectStore', { + url: '/api2/json/nodes/' + nodename + '/storage/' + storage + '/status', + }); + Ext.apply(me, { store: store, selModel: sm, @@ -424,28 +458,8 @@ Ext.define('PVE.storage.ContentView', { }); } }, - { - text: gettext('Templates'), - handler: function() { - var win = Ext.create('PVE.storage.TemplateDownload', { - nodename: nodename, - storage: storage - }); - win.show(); - win.on('destroy', reload); - } - }, - { - text: gettext('Upload'), - handler: function() { - var win = Ext.create('PVE.storage.Upload', { - nodename: nodename, - storage: storage - }); - win.show(); - win.on('destroy', reload); - } - }, + templateButton, + uploadButton, '->', gettext('Search') + ':', ' ', { @@ -494,6 +508,40 @@ Ext.define('PVE.storage.ContentView', { }); me.callParent(); + + // disable the buttons/restrict the upload window + // if templates or uploads are not allowed + me.statusStore.on('load', function(s,records,succes) { + if (me.destroyed) { // if the element is not there anymore, do nothing + return; + } + var availcontent = []; + Ext.Array.each(records, function(item){ + if (item.id === 'content') { + availcontent = item.data.value.split(','); + } + }); + var templ = false; + var upload = false; + var cts = []; + + Ext.Array.each(availcontent, function(content) { + if (content === 'vztmpl') { + templ = true; + cts.push('vztmpl'); + } else if (content === 'iso') { + upload = true; + cts.push('iso'); + } + }); + + if (templ !== upload) { + uploadButton.contents = cts; + } + + templateButton.setDisabled(!templ); + uploadButton.setDisabled(!upload && !templ); + }); } }, function() {