[pve-devel] [PATCH] implement JsonObjectPending

Alexandre Derumier aderumier at odiso.com
Wed Dec 31 09:57:49 CET 2014


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 www/manager/Makefile                         |    1 +
 www/manager/data/ObjectStore2.js             |    8 ++--
 www/manager/data/reader/JsonObjectPending.js |   60 ++++++++++++++++++++++++++
 3 files changed, 65 insertions(+), 4 deletions(-)
 create mode 100644 www/manager/data/reader/JsonObjectPending.js

diff --git a/www/manager/Makefile b/www/manager/Makefile
index b5f6ba6..ebcd659 100644
--- a/www/manager/Makefile
+++ b/www/manager/Makefile
@@ -14,6 +14,7 @@ JSSRC= 				                 	\
 	VNCConsole.js					\
 	data/TimezoneStore.js				\
 	data/reader/JsonObject.js			\
+	data/reader/JsonObjectPending.js		\
 	data/PVEProxy.js				\
 	data/UpdateQueue.js				\
 	data/UpdateStore.js				\
diff --git a/www/manager/data/ObjectStore2.js b/www/manager/data/ObjectStore2.js
index 0946f03..f4832a5 100644
--- a/www/manager/data/ObjectStore2.js
+++ b/www/manager/data/ObjectStore2.js
@@ -16,10 +16,10 @@ Ext.define('PVE.data.ObjectStore2',  {
                 type: 'pve',
 		url: config.url,
 		extraParams: config.extraParams,
-//                reader: {
-//		    type: 'jsonobject',
-//		    rows: config.rows
-//		}
+                reader: {
+		    type: 'jsonobjectpending',
+		    rows: config.rows
+		}
             }
         });
 
diff --git a/www/manager/data/reader/JsonObjectPending.js b/www/manager/data/reader/JsonObjectPending.js
new file mode 100644
index 0000000..8e87d44
--- /dev/null
+++ b/www/manager/data/reader/JsonObjectPending.js
@@ -0,0 +1,60 @@
+Ext.define('PVE.data.reader.JsonObjectPending', {
+    extend: 'Ext.data.reader.Json',
+    alias : 'reader.jsonobjectpending',
+    
+    root: 'data',
+ 
+    constructor: function(config) {
+        var me = this;
+
+        Ext.apply(me, config || {});
+
+	me.callParent([config]);
+    },
+
+    getResponseData: function(response) {
+	var me = this;
+
+        var data = [];
+        try {
+            var result = Ext.decode(response.responseText);
+            var root = me.getRoot(result);
+            var org_root = root;
+
+            if (Ext.isArray(org_root)) {
+                if (org_root.length == 1) {
+                    root = org_root[0];
+                } else {
+                    root = {};
+                }
+            }
+
+	    if (me.rows) {
+		Ext.Object.each(me.rows, function(key, rowdef) {
+		    if (Ext.isDefined(root[key])) {
+			data.push({key: key, value: root[key]["value"], pending: root[key]["pending"], delete: root[key]["delete"]});
+		    } else if (Ext.isDefined(rowdef.defaultValue)) {
+			data.push({key: key, value: rowdef.defaultValue, pending: undefined, delete: undefined});
+		    } else if (rowdef.required) {
+			data.push({key: key, value: undefined, pending: undefined, delete: undefined});
+		    }
+		});
+	    } else {
+		Ext.Object.each(root, function(key, value) {
+		    data.push({key: key, value: value, pending: root[key]["pending"], delete: root[key]["delete"]});
+		});
+	    }
+
+	}
+        catch (ex) {
+            Ext.Error.raise({
+                response: response,
+                json: response.responseText,
+                parseError: ex,
+                msg: 'Unable to parse the JSON returned by the server: ' + ex.toString()
+            });
+        }
+	return data;
+    }
+});
+
-- 
1.7.10.4




More information about the pve-devel mailing list