]> git.proxmox.com Git - pmg-gui.git/blobdiff - js/Utils.js
add render_filetype
[pmg-gui.git] / js / Utils.js
index 2d8a1d0c16fd576dd47f53ff20609a0ff80acfe5..0479dff2b18e2ce299a1dd972391d749132bc539 100644 (file)
@@ -747,6 +747,38 @@ Ext.define('PMG.Utils', {
        /*jslint confusion: false*/
     },
 
+    render_filetype: function(value) {
+       let iconCls = 'fa-file-o';
+       let text = Proxmox.Utils.unknownText;
+
+       if (!value) {
+           return `<i class='fa ${iconCls}'></i> ${text}`;
+       }
+
+       text = value.toString().toLowerCase();
+       let type = text.split('/')[0];
+
+       switch (type) {
+           case 'audio':
+           case 'image':
+           case 'video':
+           case 'text':
+               iconCls = `fa-file-${type}-o`;
+               break;
+           case 'application':
+               let subtypes = ['excel', 'pdf', 'word', 'powerpoint'];
+               let found = subtypes.find(st => text.includes(st));
+               if (found !== undefined) {
+                   iconCls = `fa-file-${found}-o`;
+               }
+               break;
+           default:
+               break;
+       }
+
+       return `<i class='fa ${iconCls}'></i> ${text}`;
+    },
+
     sender_renderer: function(value, metaData, rec) {
        var subject = Ext.htmlEncode(value);
        var from = Ext.htmlEncode(rec.data.from);