]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/Utils.js
utils: align notification toast to bottom-right again
[pmg-gui.git] / js / Utils.js
index fa394ca21f27208e61be3f26f0b037d33534d9d3..328a146b3483c9770ac6bfd5cd9641fad4c2c703 100644 (file)
@@ -8,6 +8,33 @@ Ext.define('PMG.Utils', {
 
     // this singleton contains miscellaneous utilities
 
+    // use in panels with object spread (...) operator, for example:
+    // ...PMG.Utils.onlineHelpTool('sysadmin_certificate_management'),
+    onlineHelpTool: function(blockid) {
+       let info = Proxmox.Utils.get_help_info(blockid);
+       if (info === undefined) {
+           info = Proxmox.Utils.get_help_info('pmg_documentation_index');
+           if (info === undefined) {
+               throw "get_help_info failed"; // should not happen
+           }
+       }
+
+       let docsURI = window.location.origin + info.link;
+       let title = info.title || gettext('Help');
+       if (info.subtitle) {
+           title += ' - ' + info.subtitle;
+       }
+       return {
+           tools: [
+               {
+                   type: 'help',
+                   tooltip: title,
+                   handler: () => window.open(docsURI),
+               },
+           ],
+       };
+    },
+
     senderText: gettext('Sender'),
     receiverText: gettext('Receiver'),
     scoreText: gettext('Score'),
@@ -762,6 +789,8 @@ Ext.define('PMG.Utils', {
                    slideBackDuration: 250,
                    slideBackAnimation: 'easeOut',
                    iconCls: 'fa fa-check',
+                   shadow: true,
+                   align: 'br',
                });
 
                if (Ext.isFunction(callback)) {
@@ -808,11 +837,8 @@ Ext.define('PMG.Utils', {
        var from = Ext.htmlEncode(rec.data.from);
        var sender = Ext.htmlEncode(rec.data.sender);
        if (sender) {
-           /*jslint confusion: true*/
-           /*format is a string above*/
            from = Ext.String.format(gettext("{0} on behalf of {1}"),
                                     sender, from);
-           /*jslint confusion: false*/
        }
        return '<small>' + from + '</small><br>' + subject;
     },
@@ -821,5 +847,67 @@ Ext.define('PMG.Utils', {
        var me = this;
 
        // do whatever you want here
+       Proxmox.Utils.override_task_descriptions({
+           applycustomscores: ['', gettext('Apply custom SpamAssassin scores')],
+           avupdate: ['', gettext('ClamAV update')],
+           backup: ['', gettext('Backup')],
+           clustercreate: ['', gettext('Create Cluster')],
+           clusterjoin: ['', gettext('Join Cluster')],
+           restore: ['', gettext('Restore')],
+           saupdate: ['', gettext('SpamAssassin update')],
+       });
+    },
+});
+
+Ext.define('PMG.Async', {
+    singleton: true,
+
+    // Returns a Promise which executes a quarantine action when awaited.
+    // Shows a Toast message box once completed, if batchNumber and batchTotal
+    // are set, they will be included into the title of that toast.
+    doQAction: function(action, ids, batchNumber, batchTotal) {
+       if (!Ext.isArray(ids)) {
+           ids = [ids];
+       }
+       return Proxmox.Async.api2({
+           url: '/quarantine/content/',
+           params: {
+               action: action,
+               id: ids.join(';'),
+           },
+           method: 'POST',
+       }).then(
+           response => {
+               let count = ids.length;
+               let fmt = count > 1
+                   ? gettext("Action '{0}' for '{1}' items successful")
+                   : gettext("Action '{0}' successful")
+                   ;
+               let message = Ext.String.format(fmt, action, count);
+               let titleFmt = batchNumber !== undefined && batchTotal > 1
+                   ? gettext("{0} ({1}/{2}) successful")
+                   : gettext("{0} successful")
+                   ;
+               let title = Ext.String.format(
+                   titleFmt,
+                   Ext.String.capitalize(action),
+                   batchNumber,
+                   batchTotal,
+               );
+
+               Ext.toast({
+                   html: message,
+                   title: title,
+                   minWidth: 200,
+                   hideDuration: 250,
+                   slideBackDuration: 250,
+                   slideBackAnimation: 'easeOut',
+                   iconCls: 'fa fa-check',
+                   shadow: true,
+                   align: 'br',
+               });
+           },
+           response => Proxmox.Utils.alertResponseFailure(response),
+       );
     },
 });