From a0ba293c121978284c43f8bbf49493c31480cbe1 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 29 Aug 2017 06:25:25 +0200 Subject: [PATCH] add RRDTypeSelector class Mostly copied from pve-manager. - added gettext translations - changed class and state name --- Makefile | 1 + form/RRDTypeSelector.js | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 form/RRDTypeSelector.js diff --git a/Makefile b/Makefile index 8d8a96c..0b3ad30 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,7 @@ JSSRC= \ form/Checkbox.js \ form/KVComboBox.js \ form/ComboGrid.js \ + form/RRDTypeSelector.js \ button/Button.js \ grid/ObjectGrid.js \ grid/PendingObjectGrid.js \ diff --git a/form/RRDTypeSelector.js b/form/RRDTypeSelector.js new file mode 100644 index 0000000..9eb9475 --- /dev/null +++ b/form/RRDTypeSelector.js @@ -0,0 +1,58 @@ +Ext.define('Proxmox.form.RRDTypeSelector', { + extend: 'Ext.form.field.ComboBox', + alias: ['widget.proxmoxRRDTypeSelector'], + + displayField: 'text', + valueField: 'id', + editable: false, + queryMode: 'local', + value: 'hour', + stateEvents: [ 'select' ], + stateful: true, + stateId: 'proxmoxRRDTypeSelection', + store: { + type: 'array', + fields: [ 'id', 'timeframe', 'cf', 'text' ], + data : [ + [ 'hour', 'hour', 'AVERAGE', + gettext('Hour') + ' (' + gettext('average') +')' ], + [ 'hourmax', 'hour', 'MAX', + gettext('Hour') + ' (' + gettext('maximum') + ')' ], + [ 'day', 'day', 'AVERAGE', + gettext('Day') + ' (' + gettext('average') + ')' ], + [ 'daymax', 'day', 'MAX', + gettext('Day') + ' (' + gettext('maximum') + ')' ], + [ 'week', 'week', 'AVERAGE', + gettext('Week') + ' (' + gettext('average') + ')' ], + [ 'weekmax', 'week', 'MAX', + gettext('Week') + ' (' + gettext('maximum') + ')' ], + [ 'month', 'month', 'AVERAGE', + gettext('Month') + ' (' + gettext('average') + ')' ], + [ 'monthmax', 'month', 'MAX', + gettext('Month') + ' (' + gettext('maximum') + ')' ], + [ 'year', 'year', 'AVERAGE', + gettext('Year') + ' (' + gettext('average') + ')' ], + [ 'yearmax', 'year', 'MAX', + gettext('Year') + ' (' + gettext('maximum') + ')' ] + ] + }, + // save current selection in the state Provider so RRDView can read it + getState: function() { + var ind = this.getStore().findExact('id', this.getValue()); + var rec = this.getStore().getAt(ind); + if (!rec) { + return; + } + return { + id: rec.data.id, + timeframe: rec.data.timeframe, + cf: rec.data.cf + }; + }, + // set selection based on last saved state + applyState : function(state) { + if (state && state.id) { + this.setValue(state.id); + } + } +});