From 40d43a392300505f45ff05f0b0343a08f4fbdb28 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 24 Feb 2017 07:45:09 +0100 Subject: [PATCH] PendingObjectGrid.js: import from pve-manager just changed the name --- Makefile | 1 + data/ProxmoxProxy.js | 6 +++ grid/PendingObjectGrid.js | 95 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 grid/PendingObjectGrid.js diff --git a/Makefile b/Makefile index 9d5c345..62c5f74 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ JSSRC= \ form/TextField.js \ form/Checkbox.js \ grid/ObjectGrid.js \ + grid/PendingObjectGrid.js \ panel/InputPanel.js \ panel/LogView.js \ window/Edit.js \ diff --git a/data/ProxmoxProxy.js b/data/ProxmoxProxy.js index d0e5a2a..b686b35 100644 --- a/data/ProxmoxProxy.js +++ b/data/ProxmoxProxy.js @@ -34,6 +34,12 @@ Ext.define('Proxmox.RestProxy', { idProperty: 'key' }); + Ext.define('KeyValuePendingDelete', { + extend: "Ext.data.Model", + fields: [ 'key', 'value', 'pending', 'delete' ], + idProperty: 'key' + }); + Ext.define('proxmox-tasks', { extend: 'Ext.data.Model', fields: [ diff --git a/grid/PendingObjectGrid.js b/grid/PendingObjectGrid.js new file mode 100644 index 0000000..0061c37 --- /dev/null +++ b/grid/PendingObjectGrid.js @@ -0,0 +1,95 @@ +Ext.define('Proxmox.grid.PendingObjectGrid', { + extend: 'Proxmox.grid.ObjectGrid', + alias: ['widget.proxmoxPendingObjectGrid'], + + getObjectValue: function(key, defaultValue, pending) { + var me = this; + var rec = me.store.getById(key); + if (rec) { + var value = (pending && Ext.isDefined(rec.data.pending) && (rec.data.pending !== '')) ? + rec.data.pending : rec.data.value; + + if (Ext.isDefined(value) && (value !== '')) { + return value; + } else { + return defaultValue; + } + } + return defaultValue; + }, + + hasPendingChanges: function(key) { + var me = this; + var rows = me.rows; + var rowdef = (rows && rows[key]) ? rows[key] : {}; + var keys = rowdef.multiKey || [ key ]; + var pending = false; + + Ext.Array.each(keys, function(k) { + var rec = me.store.getById(k); + if (rec && rec.data && Ext.isDefined(rec.data.pending) && (rec.data.pending !== '')) { + pending = true; + return false; // break + } + }); + + return pending; + }, + + renderValue: function(value, metaData, record, rowIndex, colIndex, store) { + var me = this; + var rows = me.rows; + var key = record.data.key; + var rowdef = (rows && rows[key]) ? rows[key] : {}; + var renderer = rowdef.renderer; + var current = ''; + var pendingdelete = ''; + var pending = ''; + + if (renderer) { + current = renderer(value, metaData, record, rowIndex, colIndex, store, false); + if (me.hasPendingChanges(key)) { + pending = renderer(record.data.pending, metaData, record, rowIndex, colIndex, store, true); + } + if (pending == current) { + pending = undefined; + } + } else { + current = value || ''; + pending = record.data.pending; + } + + if (record.data['delete']) { + pendingdelete = '
'+ current +'
'; + } + + if (pending || pendingdelete) { + return current + '
' + (pending || '') + pendingdelete + '
'; + } else { + return current; + } + }, + + initComponent : function() { + var me = this; + + var rows = me.rows; + + if (!me.rstore) { + if (!me.url) { + throw "no url specified"; + } + + me.rstore = Ext.create('Proxmox.data.ObjectStore', { + model: 'KeyValuePendingDelete', + readArray: true, + url: me.url, + interval: me.interval, + extraParams: me.extraParams, + rows: me.rows + }); + } + + me.callParent(); + } +});