]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
add RRDTypeSelector class
authorDietmar Maurer <dietmar@proxmox.com>
Tue, 29 Aug 2017 04:25:25 +0000 (06:25 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 29 Aug 2017 04:25:25 +0000 (06:25 +0200)
Mostly copied from pve-manager.

- added gettext translations
- changed class and state name

Makefile
form/RRDTypeSelector.js [new file with mode: 0644]

index 8d8a96cf1449adf15e49cff0b4fde3b0eb6dd9f6..0b3ad30f8caeae241c85f24336075653bc83fad6 100644 (file)
--- 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 (file)
index 0000000..9eb9475
--- /dev/null
@@ -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);
+       }
+    }
+});