]> git.proxmox.com Git - pve-manager.git/commitdiff
disable template/upload button, fixes #483
authorDominik Csapak <d.csapak@proxmox.com>
Fri, 11 Mar 2016 10:48:18 +0000 (11:48 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 11 Mar 2016 15:29:14 +0000 (16:29 +0100)
with this patch, the upload/template buttons
are disabled, when the selected storage
has the respective contents disabled

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
www/manager/storage/ContentView.js

index 265fab9fd45f1ee06a29b5cf59be06a72430931e..2cd9bcb3299ba8d8494ad04359170184e584c5d1 100644 (file)
@@ -184,10 +184,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',
@@ -355,10 +356,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,
@@ -422,28 +456,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') + ':', ' ',
                {
@@ -492,6 +506,41 @@ 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.internalId === '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() {