[icinga-checkins] icinga.org: icinga-web/master: * Finished BatchCommand, added isStandaloneComponent config to CommandPanel

git at icinga.org git at icinga.org
Tue Nov 15 12:05:22 CET 2011


Module: icinga-web
Branch: master
Commit: 7076644273cf037551344a86da8c4eb4c0a20509
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=7076644273cf037551344a86da8c4eb4c0a20509

Author: Jannis Mosshammer <jannis.mosshammer at netways.de>
Date:   Fri Nov 11 23:35:50 2011 +0100

* Finished BatchCommand, added isStandaloneComponent config to CommandPanel

---

 .../js/Cronks/Tackle/Command/BatchCommandWindow.js |   74 ++++++++++++++++----
 .../Cronks/lib/js/Cronks/Tackle/Command/Form.js    |    5 +-
 .../Cronks/lib/js/Cronks/Tackle/Command/Panel.js   |   15 ++++-
 3 files changed, 75 insertions(+), 19 deletions(-)

diff --git a/app/modules/Cronks/lib/js/Cronks/Tackle/Command/BatchCommandWindow.js b/app/modules/Cronks/lib/js/Cronks/Tackle/Command/BatchCommandWindow.js
index 6468dd5..160e100 100644
--- a/app/modules/Cronks/lib/js/Cronks/Tackle/Command/BatchCommandWindow.js
+++ b/app/modules/Cronks/lib/js/Cronks/Tackle/Command/BatchCommandWindow.js
@@ -6,14 +6,16 @@ Ext.ns('Icinga.Cronks.Tackle.Command').BatchCommandWindow = Ext.extend(Ext.Windo
     
     constructor: function(cfg) {
         cfg = cfg || {};
-        cfg.buttons = this.buttons;
+
         cfg.width = Ext.getBody().getWidth()*0.7;
         cfg.height = Ext.getBody().getHeight()*0.9;
         this.setInitialValues();
         this.id = Ext.id();
         this.buildPreviewGrid(cfg);
         this.buildView(cfg);
+        cfg.buttons = this.getSubmitButtons();
         Ext.Window.prototype.constructor.call(this, cfg);
+        
     },
 
     setInitialValues: function() {
@@ -113,15 +115,29 @@ Ext.ns('Icinga.Cronks.Tackle.Command').BatchCommandWindow = Ext.extend(Ext.Windo
 
         var svcCommands = new Icinga.Cronks.Tackle.Command.Panel({
             type: 'service',
-            title: 'Service commands'
+            title: 'Service commands',
+            isStandaloneComponent: false,
+            listeners: {
+                render: function(cmp) {
+                    cmp.dataview.on("click",function() {this.submitBtn.setDisabled(false);},this);
+                },
+                scope:this
+            }
         });
         var hostCommands = new Icinga.Cronks.Tackle.Command.Panel({
             type: 'host',
-            title: 'Host commands'
+            title: 'Host commands',
+            isStandaloneComponent: false,
+            listeners: {
+                render: function(cmp) {
+                    cmp.dataview.on("click",function() {this.submitBtn.setDisabled(false);},this);
+                },
+                scope:this
+            }
         });
 
         cfg.items = [new Ext.TabPanel({
-            region: 'north',
+            region: 'south',
             activeTab: 0,
             items: [
                 hostCommands,
@@ -146,7 +162,7 @@ Ext.ns('Icinga.Cronks.Tackle.Command').BatchCommandWindow = Ext.extend(Ext.Windo
                 },
                 scope:this
             },
-            height: 200
+            height: 300
         }),{
             title: _('Filter command recipients'),
             region: 'west',
@@ -518,16 +534,44 @@ Ext.ns('Icinga.Cronks.Tackle.Command').BatchCommandWindow = Ext.extend(Ext.Windo
         }];
     },
 
-    buttons: [{
-        text: _('Send commands'),
-        iconCls: 'icinga-icon-accept'
-    },{
-        text: _('Cancel'),
-        iconCls: 'icinga-icon-cancel',
-        handler: function(cmp) {
-            cmp.ownerCt.ownerCt.close();
-        }
-    }]
+    getSubmitButtons: function() {
+       this.submitBtn = new Ext.Button({
+            text: _('Send commands'),
+            iconCls: 'icinga-icon-accept',
+            disabled:true,
+            handler: function(cmp) {
+                var count = this.recipientStore.getTotalCount();
+                Ext.Msg.confirm(
+                    _("Submitting commands to multiple targets"),
+                    _("This command will be send to "+count+" "+this.type+"s, proceed?"),
+                    function(btn) {
+                        if(btn != "yes")
+                            return false;
+                        var targets = [];
+                        this.recipientStore.each(function(record) {
+                            targets.push({
+                                host : record.get('HOST_NAME'),
+                                service : record.get('SERVICE_NAME'),
+                                instance: record.get('INSTANCE_NAME')
+                            });
+                        },this);
+                        this.findByType('tabpanel')[0].getActiveTab().submit(targets);
+                    },
+                    this
+                );
+            },
+            scope:this
+        });
+        return [this.submitBtn,{
+            text: _('Cancel'),
+            iconCls: 'icinga-icon-cancel',
+            handler: function(cmp) {
+                cmp.ownerCt.ownerCt.close();
+            },
+            scope:this
+        }];
+
+    }
 
 
 
diff --git a/app/modules/Cronks/lib/js/Cronks/Tackle/Command/Form.js b/app/modules/Cronks/lib/js/Cronks/Tackle/Command/Form.js
index 40c703a..9a534fc 100644
--- a/app/modules/Cronks/lib/js/Cronks/Tackle/Command/Form.js
+++ b/app/modules/Cronks/lib/js/Cronks/Tackle/Command/Form.js
@@ -8,6 +8,7 @@ Icinga.Cronks.Tackle.Command.Form = Ext.extend(Ext.Panel, {
 	autoScroll : true,
 	
 	constructor : function(config) {
+        Ext.apply(this,config);
 		Icinga.Cronks.Tackle.Command.Form.superclass.constructor.call(this, config);
 	},
 	
@@ -28,8 +29,8 @@ Icinga.Cronks.Tackle.Command.Form = Ext.extend(Ext.Panel, {
 		this.removeAll();
 		
 		this.form = this.formBuilder.build(commandName, {
-            renderSubmit: true,
-            targets: [this.target]
+            renderSubmit: this.standalone,
+            targets: Ext.isArray(this.target) ? this.target : [this.target]
 		});
 		
 		this.add(this.form);
diff --git a/app/modules/Cronks/lib/js/Cronks/Tackle/Command/Panel.js b/app/modules/Cronks/lib/js/Cronks/Tackle/Command/Panel.js
index 1f153c7..0b677c2 100644
--- a/app/modules/Cronks/lib/js/Cronks/Tackle/Command/Panel.js
+++ b/app/modules/Cronks/lib/js/Cronks/Tackle/Command/Panel.js
@@ -26,7 +26,10 @@ Icinga.Cronks.Tackle.Command.Panel = Ext.extend(Ext.Panel, {
 				}
 			}
 		});
-		
+        if(typeof config.standalone === "undefined")
+            this.isStandaloneComponent = true; // show buttons
+        else
+            this.isStandaloneComponent = config.standalone;
 		Icinga.Cronks.Tackle.Command.Panel.superclass.constructor.call(this, config);
 	},
 	
@@ -52,6 +55,7 @@ Icinga.Cronks.Tackle.Command.Panel = Ext.extend(Ext.Panel, {
 		this.dataview.on('click', this.onCommandClick, this);
 		
 		this.form = new Icinga.Cronks.Tackle.Command.Form({
+            standalone: this.isStandaloneComponent,
 			flex : 1
 		});
 		
@@ -59,7 +63,14 @@ Icinga.Cronks.Tackle.Command.Panel = Ext.extend(Ext.Panel, {
 		
 		this.doLayout();
 	},
-	
+
+    submit: function(targets) {
+         var fPanel = this.form.form;
+         var form = fPanel.getForm();
+         fPanel.formAction.setTargets(targets);
+         form.doAction(fPanel.formAction);
+    },
+
 	onCommandClick : function(dataView, index, node, e) {
 		var record = this.store.getAt(index);
 		this.form.rebuildFormForCommand(record.data.definition);





More information about the icinga-checkins mailing list