[pmg-devel] [PATCH pmg-gui v3 2/3] add render_filetype

Dominik Csapak d.csapak at proxmox.com
Thu Oct 10 11:22:03 CEST 2019


this will be used to show the icon in the attachment list

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 js/Utils.js | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/js/Utils.js b/js/Utils.js
index 2d8a1d0..0479dff 100644
--- a/js/Utils.js
+++ b/js/Utils.js
@@ -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);
-- 
2.20.1




More information about the pmg-devel mailing list