From 81f4e1e0979a800b626154e838297dd757fe834f Mon Sep 17 00:00:00 2001 From: Jordan Wright Date: Mon, 15 Feb 2016 20:41:07 -0600 Subject: [PATCH] Added ability to copy templates. Fixes #156 --- static/js/app/templates.js | 59 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/static/js/app/templates.js b/static/js/app/templates.js index b3e7245a..14906a11 100644 --- a/static/js/app/templates.js +++ b/static/js/app/templates.js @@ -165,6 +165,55 @@ function edit(idx) { }) } +function copy(idx) { + $("#modalSubmit").unbind('click').click(function() { + save(-1) + }) + $("#attachmentUpload").unbind('click').click(function() { + this.value = null + }) + $("#html_editor").ckeditor() + $("#attachmentsTable").show() + attachmentsTable = $('#attachmentsTable').DataTable({ + destroy: true, + "order": [ + [1, "asc"] + ], + columnDefs: [{ + orderable: false, + targets: "no-sort" + }, { + sClass: "datatable_hidden", + targets: [3, 4] + }] + }); + var template = { + attachments: [] + } + template = templates[idx] + $("#name").val("Copy of " + template.name) + $("#subject").val(template.subject) + $("#html_editor").val(template.html) + $("#text_editor").val(template.text) + $.each(template.attachments, function(i, file) { + var icon = icons[file.type] || "fa-file-o" + // Add the record to the modal + attachmentsTable.row.add([ + '', + file.name, + '', + file.content, + file.type || "application/octet-stream" + ]).draw() + }) + // Handle Deletion + $("#attachmentsTable").unbind('click').on("click", "span>i.fa-trash-o", function() { + attachmentsTable.row($(this).parents('tr')) + .remove() + .draw(); + }) +} + function importEmail() { raw = $("#email_content").val() if (!raw) { @@ -211,14 +260,18 @@ function load() { templateTable.row.add([ template.name, moment(template.modified_date).format('MMMM Do YYYY, h:mm:ss a'), - "
\ - \ + \ +
" ]).draw() }) + $('[data-toggle="tooltip"]').tooltip() } else { $("#emptyMessage").show() }