From 4bd334e403dc7500559cfb5a9d80db11f1ab0b82 Mon Sep 17 00:00:00 2001 From: Pablo Vazquez Date: Wed, 2 Nov 2016 16:16:13 +0100 Subject: [PATCH] Add button to 'Add Attachment to Description' --- src/scripts/file_upload.js | 9 +++++++++ src/templates/_macros/_node_edit_form.jade | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/scripts/file_upload.js b/src/scripts/file_upload.js index 4bb52e73..fd1e38c3 100644 --- a/src/scripts/file_upload.js +++ b/src/scripts/file_upload.js @@ -155,6 +155,15 @@ $(function () { }) .on('file-upload:activated', on_file_upload_activated) .on('file-upload:finished', on_file_upload_finished) + .on('click', '.js-append-attachment', function(e) { + e.preventDefault(); + + // Append widget @[slug-name] to the post's description + // Note: Heavily connected to HTML in _node_edit_form.jade + var slug = $(this).parent().find("input[id*='slug']").val(); + var widget = '@[' + slug + ']\n'; + document.getElementById('description').value += widget; + }) ; function inject_project_id_into_url(index, element) { diff --git a/src/templates/_macros/_node_edit_form.jade b/src/templates/_macros/_node_edit_form.jade index 2fdd7ff4..2ca89cfd 100644 --- a/src/templates/_macros/_node_edit_form.jade +++ b/src/templates/_macros/_node_edit_form.jade @@ -15,6 +15,14 @@ | {% for subfield in file %} | {{ render_field(subfield) }} + + | {% if subfield.name.endswith('slug') %} + button.fieldlist-action-button.js-append-attachment( + type="button") + i.pi-plus + | Append to Description + | {% endif %} + | {% endfor %} | {% endfor %}