]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - Utils.js
add Realm model and RealmComboBox
[proxmox-widget-toolkit.git] / Utils.js
index aac877ae3bc1eb6039025524cef6f79a7311a970..22eddd2c3ef83b7c8e5badbf134be57a336cb22b 100644 (file)
--- a/Utils.js
+++ b/Utils.js
@@ -42,6 +42,7 @@ Ext.define('Proxmox.Utils', { utilities: {
     enabledText: gettext('Enabled'),
     disabledText: gettext('Disabled'),
     noneText: gettext('none'),
+    NoneText: gettext('None'),
     errorText: gettext('Error'),
     unknownText: gettext('Unknown'),
     defaultText: gettext('Default'),
@@ -57,27 +58,28 @@ Ext.define('Proxmox.Utils', { utilities: {
     groupText: gettext('Group'),
 
     language_map: {
-       zh_CN: 'Chinese (Simplified)',
-       zh_TW: 'Chinese (Traditional)',
+       ar: 'Arabic',
        ca: 'Catalan',
        da: 'Danish',
+       de: 'German',
        en: 'English',
+       es: 'Spanish',
        eu: 'Euskera (Basque)',
+       fa: 'Persian (Farsi)',
        fr: 'French',
-       de: 'German',
+       he: 'Hebrew',
        it: 'Italian',
-       es: 'Spanish',
        ja: 'Japanese',
        nb: 'Norwegian (Bokmal)',
        nn: 'Norwegian (Nynorsk)',
-       fa: 'Persian (Farsi)',
        pl: 'Polish',
        pt_BR: 'Portuguese (Brazil)',
        ru: 'Russian',
        sl: 'Slovenian',
        sv: 'Swedish',
        tr: 'Turkish',
-       he: 'Hebrew',
+       zh_CN: 'Chinese (Simplified)',
+       zh_TW: 'Chinese (Traditional)',
     },
 
     render_language: function (value) {
@@ -233,6 +235,23 @@ Ext.define('Proxmox.Utils', { utilities: {
        }
     },
 
+    getResponseErrorMessage: (err) => {
+       if (!err.statusText) {
+           return gettext('Connection error');
+       }
+       let msg = `${err.statusText} (${err.status})`;
+       if (err.response && err.response.responseText) {
+           let txt = err.response.responseText;
+           try {
+               let res = JSON.parse(txt)
+               for (let [key, value] of Object.entries(res.errors)) {
+                   msg += `<br>${key}: ${value}`;
+               }
+           } catch (e) { /* TODO? */ }
+       }
+       return msg;
+    },
+
     monStoreErrors: function(me, store, clearMaskBeforeLoad) {
        if (clearMaskBeforeLoad) {
            me.mon(store, 'beforeload', function(s, operation, eOpts) {
@@ -256,15 +275,8 @@ Ext.define('Proxmox.Utils', { utilities: {
                return;
            }
 
-           var msg;
-           /*jslint nomen: true */
-           var operation = request._operation;
-           var error = operation.getError();
-           if (error.statusText) {
-               msg = error.statusText + ' (' + error.status + ')';
-           } else {
-               msg = gettext('Connection error');
-           }
+           let error = request._operation.getError();
+           let msg = Proxmox.Utils.getResponseErrorMessage(error);
            Proxmox.Utils.setErrorMask(me, msg);
        });
     },
@@ -381,7 +393,7 @@ Ext.define('Proxmox.Utils', { utilities: {
                    Ext.Msg.show({
                        title: gettext('No valid subscription'),
                        icon: Ext.Msg.WARNING,
-                       msg: Proxmox.Utils.getNoSubKeyHtml(data.url),
+                       message: Proxmox.Utils.getNoSubKeyHtml(data.url),
                        buttons: Ext.Msg.OK,
                        callback: function(btn) {
                            if (btn !== 'ok') {
@@ -453,6 +465,8 @@ Ext.define('Proxmox.Utils', { utilities: {
        acmerefresh: [ 'ACME Account', gettext('Refresh') ],
        acmerenew: [ 'SRV', gettext('Renew Certificate') ],
        acmerevoke: [ 'SRV', gettext('Revoke Certificate') ],
+       'auth-realm-sync': [ gettext('Realm'), gettext('Sync') ],
+       'auth-realm-sync-test': [ gettext('Realm'), gettext('Sync Preview')],
        'move_volume': [ 'CT', gettext('Move Volume') ],
        clustercreate: [ '', gettext('Create Cluster') ],
        clusterjoin: [ '', gettext('Join Cluster') ],
@@ -494,11 +508,15 @@ Ext.define('Proxmox.Utils', { utilities: {
        vzmount: ['CT', gettext('Mount') ],
        vzumount: ['CT', gettext('Unmount') ],
        vzshutdown: ['CT', gettext('Shutdown') ],
+       vzreboot: ['CT', gettext('Reboot') ],
        vzsuspend: [ 'CT', gettext('Suspend') ],
        vzresume: [ 'CT', gettext('Resume') ],
+       push_file: ['CT', gettext('Push file')],
+       pull_file: ['CT', gettext('Pull file')],
        hamigrate: [ 'HA', gettext('Migrate') ],
        hastart: [ 'HA', gettext('Start') ],
        hastop: [ 'HA', gettext('Stop') ],
+       hashutdown: [ 'HA', gettext('Shutdown') ],
        srvstart: ['SRV', gettext('Start') ],
        srvstop: ['SRV', gettext('Stop') ],
        srvrestart: ['SRV', gettext('Restart') ],
@@ -585,17 +603,20 @@ Ext.define('Proxmox.Utils', { utilities: {
     parse_task_upid: function(upid) {
        var task = {};
 
-       var res = upid.match(/^UPID:(\S+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/);
+       var res = upid.match(/^UPID:([^\s:]+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):(([0-9A-Fa-f]{8,16}):)?([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/);
        if (!res) {
            throw "unable to parse upid '" + upid + "'";
        }
        task.node = res[1];
        task.pid = parseInt(res[2], 16);
        task.pstart = parseInt(res[3], 16);
-       task.starttime = parseInt(res[4], 16);
-       task.type = res[5];
-       task.id = res[6];
-       task.user = res[7];
+       if (res[5] !== undefined) {
+           task.task_id = parseInt(res[5], 16);
+       }
+       task.starttime = parseInt(res[6], 16);
+       task.type = res[7];
+       task.id = res[8];
+       task.user = res[9];
 
        task.desc = Proxmox.Utils.format_task_description(task.type, task.id);
 
@@ -689,5 +710,7 @@ Ext.define('Proxmox.Utils', { utilities: {
        me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$");
        me.HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$");
        me.IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$");
+        me.Vlan_match = new RegExp('^vlan(\\d+)');
+        me.VlanInterface_match = new RegExp('(\\w+)\\.(\\d+)');
     }
 });