]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
form: add Proxmox.form.field.ExpireDate
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 31 Mar 2020 12:50:34 +0000 (14:50 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 31 Mar 2020 16:13:20 +0000 (18:13 +0200)
Behaves like a 'datefield' but treats the 0/empty value as "never",
and sets all defaults for behaving like one would expect from a date
expire field.

This allows to replaces hacks (e.g. [0]) from our various expire date
fields, mostly in PVE/PMG user accounts, and also for the soon to be
applied API token gui.

[0]: https://git.proxmox.com/?p=pve-manager.git;a=blob;f=www/manager6/dc/UserEdit.js;h=40c4044fd9364c9bcb8787507068378ed9936f67;hb=806edfe19f049f07db2628c68e4e5702bbedd9d7#l159

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Makefile
form/ExpireDate.js [new file with mode: 0644]

index 7aa7f73211a0abeb8f541a1b6d78fc4cf63a7b6b..703b57093ab5ab18f9a69f4f9b558f75e3bbbf78 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,6 +15,7 @@ JSSRC=                                        \
        data/ObjectStore.js             \
        data/RRDStore.js                \
        data/TimezoneStore.js           \
        data/ObjectStore.js             \
        data/RRDStore.js                \
        data/TimezoneStore.js           \
+       form/ExpireDate.js              \
        form/IntegerField.js            \
        form/TextField.js               \
        form/DateTimeField.js           \
        form/IntegerField.js            \
        form/TextField.js               \
        form/DateTimeField.js           \
diff --git a/form/ExpireDate.js b/form/ExpireDate.js
new file mode 100644 (file)
index 0000000..61ff96f
--- /dev/null
@@ -0,0 +1,34 @@
+// treats 0 as "never expires"
+Ext.define('Proxmox.form.field.ExpireDate', {
+    extend: 'Ext.form.field.Date',
+    alias: ['widget.pmxExpireDate'],
+
+    name: 'expire',
+    fieldLabel: gettext('Expire'),
+    emptyText: 'never',
+    format: 'Y-m-d',
+    submitFormat: 'U',
+
+    getSubmitValue: function() {
+       let me = this;
+
+       let value = me.callParent();
+       if (!value) value = 0;
+
+       return value;
+    },
+
+    setValue: function(value) {
+       let me = this;
+
+       if (Ext.isDefined(value)) {
+           if (!value) {
+               value = null;
+           } else if (!Ext.isDate(value)) {
+               value = new Date(value * 1000);
+           }
+       }
+       me.callParent([value]);
+    },
+
+});