2016-12-28 14:46:42 +01:00
|
|
|
var attachments_ui = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
function delete_attachments(attachment) {
|
|
|
|
channel.del({url: '/json/attachments/' + attachment, idempotent: true});
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.set_up_attachments = function () {
|
|
|
|
// The settings page must be rendered before this function gets called.
|
|
|
|
|
2017-03-09 00:44:14 +01:00
|
|
|
var attachment_list_html = "";
|
2016-12-28 14:46:42 +01:00
|
|
|
_.each(page_params.attachments, function (attachment) {
|
2017-02-24 02:30:47 +01:00
|
|
|
_.each(attachment.messages, function (o) {
|
|
|
|
o.name = timerender.absolute_time(o.name);
|
|
|
|
});
|
|
|
|
|
2017-02-28 14:55:47 +01:00
|
|
|
var attachment_name_splitted = attachment.path_id.split(/\./);
|
|
|
|
|
|
|
|
if (attachment_name_splitted.length === 1) {
|
|
|
|
attachment.extension = "";
|
|
|
|
} else {
|
|
|
|
attachment.extension = attachment_name_splitted.pop();
|
|
|
|
}
|
|
|
|
|
2017-02-24 02:31:37 +01:00
|
|
|
attachment.large_ext_name = attachment.extension.length > 5;
|
|
|
|
|
2016-12-28 14:46:42 +01:00
|
|
|
var li = templates.render('attachment-item', {attachment: attachment});
|
2017-03-09 00:44:14 +01:00
|
|
|
attachment_list_html = attachment_list_html.concat(li);
|
2016-12-28 14:46:42 +01:00
|
|
|
});
|
|
|
|
|
2017-03-09 00:44:14 +01:00
|
|
|
$('#attachments_list').html(attachment_list_html);
|
|
|
|
|
2016-12-28 14:46:42 +01:00
|
|
|
$('#attachments_list').on('click', '.remove-attachment', function (event) {
|
|
|
|
var li = $(event.currentTarget).parents('li');
|
|
|
|
li.remove();
|
|
|
|
delete_attachments($(this).data('attachment'));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = attachments_ui;
|
|
|
|
}
|