[icinga-checkins] icinga.org: icinga-web/mfriedrich/fixes: * Comment API accepts records

git at icinga.org git at icinga.org
Tue Nov 15 13:36:49 CET 2011


Module: icinga-web
Branch: mfriedrich/fixes
Commit: 8b8654abab20705cc269a7584254e84e8f190388
URL:    https://git.icinga.org/?p=icinga-web.git;a=commit;h=8b8654abab20705cc269a7584254e84e8f190388

Author: Marius Hein <marius.hein at netways.de>
Date:   Fri Nov 11 14:18:19 2011 +0100

* Comment API accepts records
* Some fixes (refs #1941)

---

 app/modules/Api/lib/js/Command/Sender.js           |   39 +++++++++++++++++++-
 app/modules/Api/lib/js/Command/Type/Abstract.js    |   30 +++++++++++++++-
 .../Api/lib/js/Command/Type/AcknowledgeProblem.js  |   19 +---------
 app/modules/Api/lib/js/Command/Type/AddComment.js  |   20 +---------
 .../Cronks/lib/js/Cronks/Tackle/Command/Form.js    |    9 +++--
 app/modules/Cronks/lib/js/Cronks/Tackle/Cronk.js   |   10 +++---
 6 files changed, 79 insertions(+), 48 deletions(-)

diff --git a/app/modules/Api/lib/js/Command/Sender.js b/app/modules/Api/lib/js/Command/Sender.js
index e10e6e8..6dee1e1 100644
--- a/app/modules/Api/lib/js/Command/Sender.js
+++ b/app/modules/Api/lib/js/Command/Sender.js
@@ -11,6 +11,12 @@ Ext.ns('Icinga.Api.Command');
         data: {},
         command: null,
         autoReset: true,
+        
+        recordTargetMap : {
+        	HOST_NAME : 'host',
+        	SERVICE_NAME : 'service',
+        	INSTANCE_NAME : 'instance'
+        },
 
         constructor: function (config) {
             config = config || {};
@@ -58,11 +64,40 @@ Ext.ns('Icinga.Api.Command');
             this.target = [];
             this.data = {};
         },
-
+        
+        /**
+         * If you added records to the targets this method
+         * converts record data based on a map to "real"
+         * target values
+         */
+        prepareTargets : function(targets) {
+        	var outTargets = [];
+        	
+        	Ext.each(targets, function(o, index) {
+        		// Hack to detect a record
+        		if (Ext.isObject(o) && Ext.isObject(o.data)) {
+        			var tmp = {};
+        			Ext.iterate(this.recordTargetMap, function(k, v) {
+        				if (Ext.isEmpty(o.data[k]) === false) {
+        					tmp[v] = o.data[k];
+        				}
+        			}, this);
+        			outTargets.push(tmp);
+        		} else {
+        			outTargets.push(o);
+        		}
+        	}, this);
+        	
+        	return outTargets;
+        },
+        
         send: function () {
+        	
+        	var targets = this.prepareTargets(this.targets);
+        	
             var data = {
                 command: this.command,
-                target: this.targets,
+                target: targets,
                 data: this.data
             };
 
diff --git a/app/modules/Api/lib/js/Command/Type/Abstract.js b/app/modules/Api/lib/js/Command/Type/Abstract.js
index fd32fa3..65f84c3 100644
--- a/app/modules/Api/lib/js/Command/Type/Abstract.js
+++ b/app/modules/Api/lib/js/Command/Type/Abstract.js
@@ -66,13 +66,37 @@ Ext.ns('Icinga.Api.Command.Type');
             this.registerHandlers();
 
             var aOptions = Ext.apply({}, this.initialConfig);
-
+            
+            this.errorLabel = new Ext.form.Label({
+                html :'',
+                anchor: '100% 10%'
+            });
+            
             this.formAction = new Icinga.Api.Command.FormAction(this.getForm(), aOptions);
+            
+            this.on('actionfailed', this.onActionFailed, this);
 
             this.buildForm(this.command);
         },
+        
+        onActionFailed : function(form, action) {
+            var json = null;
+            
+            try {
+                json = Ext.decode(action.response.responseText);
+            } catch(e) {
+                json = {error: _('Unknown error, check your logs')};
+            }
+            
+            this.errorLabel.update("<div style='float:left;width:16px;height:16px' class='icinga-icon-exclamation-red'></div><span style='color:red'>"+json.error+"</span>");
+        },
 
         buildForm: function (o) {
+        	
+        	/**
+        	 * Just a information for the user that he
+        	 * doesn't need to take further actions
+        	 */
         	if (this.countRealFields() === 0) {
         		this.add({
         			xtype : 'panel',
@@ -81,6 +105,10 @@ Ext.ns('Icinga.Api.Command.Type');
         		});
         	}
         	
+        	if (this.errorLabel) {
+        		this.add(this.errorLabel);
+        	}
+        	
         	this.doLayout();
         },
 
diff --git a/app/modules/Api/lib/js/Command/Type/AcknowledgeProblem.js b/app/modules/Api/lib/js/Command/Type/AcknowledgeProblem.js
index e4094e3..677d711 100644
--- a/app/modules/Api/lib/js/Command/Type/AcknowledgeProblem.js
+++ b/app/modules/Api/lib/js/Command/Type/AcknowledgeProblem.js
@@ -7,11 +7,6 @@ Ext.ns('Icinga.Api.Command.Type');
     Icinga.Api.Command.Type.AcknowledgeProblem = Ext.extend(Icinga.Api.Command.Type.Abstract, {
         layout: 'form',
         buildForm: function() {
-            var errorLabel = new Ext.form.Label({
-                
-                html :'',
-                anchor: '100% 10%'
-            })
             this.add([
             {
                 xtype: 'checkbox',
@@ -47,19 +42,7 @@ Ext.ns('Icinga.Api.Command.Type');
                 name: 'comment',
                 anchor: '100% 60%',
                 height: 300
-            },errorLabel
-            ]);
-            this.formAction.failure = function(rawResponse) {
-                var json = {error: _('Unknown error, check your logs')};
-                try {
-                    json = Ext.decode(rawResponse.responseText);
-                } catch(e) {
-                    json = {error: _('Unknown error, check your logs')};
-                }
-                errorLabel.update("<div style='float:left;width:16px;height:16px' class='icinga-icon-exclamation-red'></div><span style='color:red'>"+json.error+"</span>")
-                this.failureType = Ext.form.Action.SERVER_INVALID;
-                this.form.afterAction(this, false);
-            }
+            }]);
             
             Icinga.Api.Command.Type.AcknowledgeProblem.superclass.buildForm.call(this);
         }
diff --git a/app/modules/Api/lib/js/Command/Type/AddComment.js b/app/modules/Api/lib/js/Command/Type/AddComment.js
index 8a75005..1c5c17c 100644
--- a/app/modules/Api/lib/js/Command/Type/AddComment.js
+++ b/app/modules/Api/lib/js/Command/Type/AddComment.js
@@ -8,11 +8,7 @@ Ext.ns('Icinga.Api.Command.Type');
         layout: 'form',
         border: false,
         buildForm: function() {
-            var errorLabel = new Ext.form.Label({
-                
-                html :'',
-                anchor: '100% 10%'
-            })
+            
             this.add([{
                 xtype: 'checkbox',
                 boxLabel: _('Create persistent comment (i.e. stays after icinga restart)'),
@@ -31,19 +27,7 @@ Ext.ns('Icinga.Api.Command.Type');
                 allowBlank : false,
                 name: 'comment',
                 anchor: '100% 80%'
-            },errorLabel
-            ]);
-            this.formAction.failure = function(rawResponse) {
-                var json = {error: _('Unknown error, check your logs')};
-                try {
-                    json = Ext.decode(rawResponse.responseText);
-                } catch(e) {
-                    json = {error: _('Unknown error, check your logs')};
-                }
-                errorLabel.update("<div style='float:left;width:16px;height:16px' class='icinga-icon-exclamation-red'></div><span style='color:red'>"+json.error+"</span>")
-                this.failureType = Ext.form.Action.SERVER_INVALID;
-                this.form.afterAction(this, false);
-            }
+            }]);
             
             Icinga.Api.Command.Type.AddComment.superclass.buildForm.call(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..1f261b8 100644
--- a/app/modules/Cronks/lib/js/Cronks/Tackle/Command/Form.js
+++ b/app/modules/Cronks/lib/js/Cronks/Tackle/Command/Form.js
@@ -4,7 +4,7 @@ Icinga.Cronks.Tackle.Command.Form = Ext.extend(Ext.Panel, {
 	title : _('Commands'),
 	
 	formBuilder : null,
-	target : {},
+	record : {},
 	autoScroll : true,
 	
 	constructor : function(config) {
@@ -17,8 +17,9 @@ Icinga.Cronks.Tackle.Command.Form = Ext.extend(Ext.Panel, {
 		this.formBuilder = new Icinga.Api.Command.FormBuilder();
 	},
 	
-	setTargetData : function(target) {
-		this.target = target;
+	setRecord : function(record) {
+		this.record = record;
+		alert("SET");
 	},
 	
 	rebuildFormForCommand : function(commandName) {
@@ -29,7 +30,7 @@ Icinga.Cronks.Tackle.Command.Form = Ext.extend(Ext.Panel, {
 		
 		this.form = this.formBuilder.build(commandName, {
             renderSubmit: true,
-            targets: [this.target]
+            targets: [this.record]
 		});
 		
 		this.add(this.form);
diff --git a/app/modules/Cronks/lib/js/Cronks/Tackle/Cronk.js b/app/modules/Cronks/lib/js/Cronks/Tackle/Cronk.js
index a00d3bc..01c64b9 100644
--- a/app/modules/Cronks/lib/js/Cronks/Tackle/Cronk.js
+++ b/app/modules/Cronks/lib/js/Cronks/Tackle/Cronk.js
@@ -90,7 +90,9 @@ Ext.ns('Icinga.Cronks.Tackle');
                 }
 
                 this.infoTabs.setActiveTab(this.tabItems.host.head);
+                
                 this.tabItems.host.head.loadDataForObjectId(record.data.HOST_OBJECT_ID);
+                
                 this.tabItems.host.comments.grid.recordUpdated(record);
 
                 this.tabItems.host.comments.form.setObjectData({
@@ -100,6 +102,8 @@ Ext.ns('Icinga.Cronks.Tackle');
                     objectInstance : record.data.INSTANCE_NAME
                 });
                 
+                this.tabItems.host.commands.form.setRecord(record);
+                
                 if (this.collapsibleFrame.collapsed === true) {
                     this.collapsibleFrame.expand(true);
                 }
@@ -128,11 +132,7 @@ Ext.ns('Icinga.Cronks.Tackle');
                     objectInstance : record.data.INSTANCE_NAME
                 });
                 
-                this.tabCommands.form.setTargetData({
-                	host_name : record.data.HOST_NAME,
-                    service_name : record.data.SERVICE_NAME,
-                    instance : record.data.INSTANCE_NAME
-                });
+                this.tabItems.service.commands.form.setRecord(record);
                 
                 if (this.collapsibleFrame.collapsed === true) {
                     this.collapsibleFrame.expand(true);





More information about the icinga-checkins mailing list