]> 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 be9ac1d2f5c65a063a5c11a57daf668be3fac7e5..328a146b3483c9770ac6bfd5cd9641fad4c2c703 100644 (file)
@@ -790,6 +790,7 @@ Ext.define('PMG.Utils', {
                    slideBackAnimation: 'easeOut',
                    iconCls: 'fa fa-check',
                    shadow: true,
+                   align: 'br',
                });
 
                if (Ext.isFunction(callback)) {
@@ -857,3 +858,56 @@ Ext.define('PMG.Utils', {
        });
     },
 });
+
+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),
+       );
+    },
+});