[pve-devel] [PATCH] firewall autodisable GUI update

Alen Grizonic a.grizonic at proxmox.com
Mon Jun 29 18:16:52 CEST 2015


Signed-off-by: Alen Grizonic <a.grizonic at proxmox.com>
---
 www/manager/grid/FirewallOptions.js | 80 ++++++++++++++++++++++++++++++++++++-
 www/manager/window/Edit.js          |  2 +
 2 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/www/manager/grid/FirewallOptions.js b/www/manager/grid/FirewallOptions.js
index f94be6c..3157478 100644
--- a/www/manager/grid/FirewallOptions.js
+++ b/www/manager/grid/FirewallOptions.js
@@ -25,6 +25,78 @@ Ext.define('PVE.FirewallOptions', {
 
 	var rows = {};
 
+        var submit_twice = function(enable) {
+
+	    var me = this;
+
+            var form = me.formPanel.getForm();
+
+            var values = me.getValues();
+
+            if ((values.enable == 1) && (enable != 2)) {
+                values.enable = 2;
+            } else if (enable == 2) {
+                values.enable = 1;
+            }
+
+            Ext.Object.each(values, function(name, val) {
+                if (values.hasOwnProperty(name)) {
+                    if (Ext.isArray(val) && !val.length) {
+                        values[name] = '';
+                    }
+                }
+            });
+
+            if (me.digest) {
+                if (values.enable == 2) {
+                    me.digest = "";
+                } else {
+                    values.digest = me.digest;
+                }
+            }
+
+            if (me.backgroundDelay) {
+                values.background_delay = me.backgroundDelay;
+            }
+
+            var url =  me.url;
+            if (me.method === 'DELETE') {
+                url = url + "?" + Ext.Object.toQueryString(values);
+                values = undefined;
+            }
+
+            PVE.Utils.API2Request({
+                url: url,
+                waitMsgTarget: me,
+                method: me.method || (me.backgroundDelay ? 'POST' : 'PUT'),
+                params: values,
+                failure: function(response, options) {
+                    if (me.onFailedHook) {
+                        me.onFailedHook(response);
+                    } else {
+                        if (response.result && response.result.errors) {
+                            form.markInvalid(response.result.errors);
+                        }
+                        Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+                    }
+                },
+                success: function(response, options) {
+                    me.close();
+                    if ((me.backgroundDelay || me.showProgress) &&
+                        response.result.data) {
+                        var upid = response.result.data;
+                        var win = Ext.create('PVE.window.TaskProgress', {
+                            upid: upid
+                        });
+                        win.show();
+                    }
+                    if (values.enable == 2) {
+                        submit_twice.call(me, 2);
+                    }
+                }
+            });
+        };
+
 	var add_boolean_row = function(name, text, defaultValue, labelWidth) {
 	    rows[name] = {
 		header: text,
@@ -41,8 +113,12 @@ Ext.define('PVE.FirewallOptions', {
 			checked: defaultValue ? true : false,
 			name: name,
 			uncheckedValue: 0,
-			fieldLabel: text
-		    }
+                        fieldLabel: text,
+                    },
+                    onFailedHook: function() {
+                        confirm ("Connection lost: Disabling firewall (in 60 seconds).") ;
+                    },
+                    submit: submit_twice
 		}
 	    };
 	};
diff --git a/www/manager/window/Edit.js b/www/manager/window/Edit.js
index 3e69da9..5d52a65 100644
--- a/www/manager/window/Edit.js
+++ b/www/manager/window/Edit.js
@@ -24,6 +24,8 @@ Ext.define('PVE.window.Edit', {
 
     showProgress: false,
 
+    onFailerHook: undefined,
+
     isValid: function() {
 	var me = this;
 
-- 
2.1.4





More information about the pve-devel mailing list