From 1b4cc91ec8f493df03c07640f0377bbd1766ca7b Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 31 Mar 2016 01:23:58 +0100 Subject: [PATCH 1/2] Added WYSIWYG editor. Works for notes & description, fails miserably for items :( --- RIGS/templates/RIGS/event_form.html | 20 ++++++++++++++------ RIGS/templates/RIGS/item_modal.html | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/RIGS/templates/RIGS/event_form.html b/RIGS/templates/RIGS/event_form.html index 282f3669..28e6be28 100644 --- a/RIGS/templates/RIGS/event_form.html +++ b/RIGS/templates/RIGS/event_form.html @@ -8,11 +8,13 @@ {% block css %} + {% endblock %} {% block preload_js %} + {% endblock %} {% block js %} @@ -40,6 +42,15 @@ } $(document).ready(function () { + + $(".md-enabled").each(function(index){ + editor = new SimpleMDE({ + element: $(".md-enabled")[index], + toolbar: ["bold", "italic", "strikethrough", "|", "unordered-list", "ordered-list", "|", "link", "|", "preview", "guide"], + status: false, + }); + }); + {% if not object.pk and not form.errors %} $('.form-hws').slideUp(function () { @@ -225,11 +236,8 @@
Event Description
- - -
- {% render_field form.description class+="form-control" %} +
+ {% render_field form.description class+="form-control md-enabled" %}
@@ -424,7 +432,7 @@
- {% render_field form.notes class+="form-control" %} + {% render_field form.notes class+="form-control md-enabled" %}
{% include "RIGS/item_table.html" %} diff --git a/RIGS/templates/RIGS/item_modal.html b/RIGS/templates/RIGS/item_modal.html index 6991c585..ddf20d59 100644 --- a/RIGS/templates/RIGS/item_modal.html +++ b/RIGS/templates/RIGS/item_modal.html @@ -27,7 +27,7 @@
-
From 02c615a08ce7c38c0fe43c895173645f76910fdb Mon Sep 17 00:00:00 2001 From: David Taylor Date: Sat, 2 Apr 2016 02:42:37 +0100 Subject: [PATCH 2/2] Fixed for event items. Will probably fail tests because selenium can't type in simpleMDE :( --- RIGS/static/js/interaction.js | 10 ++++++++++ RIGS/templates/RIGS/event_form.html | 14 ++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/RIGS/static/js/interaction.js b/RIGS/static/js/interaction.js index dffcf6bc..bc329724 100644 --- a/RIGS/static/js/interaction.js +++ b/RIGS/static/js/interaction.js @@ -36,6 +36,16 @@ function updatePrices() { $('#total').text(parseFloat(sum + vat).toFixed(2)); } +function setupMDE(selector) { + editor = new SimpleMDE({ + element: $(selector)[0], + forceSync: true, + toolbar: ["bold", "italic", "strikethrough", "|", "unordered-list", "ordered-list", "|", "link", "|", "preview", "guide"], + status: true, + }); + $(selector).data('mde_editor',editor); +} + $('#item-table').on('click', '.item-delete', function () { delete objectitems[$(this).data('pk')] $('#item-' + $(this).data('pk')).remove(); diff --git a/RIGS/templates/RIGS/event_form.html b/RIGS/templates/RIGS/event_form.html index 28e6be28..2ea1a931 100644 --- a/RIGS/templates/RIGS/event_form.html +++ b/RIGS/templates/RIGS/event_form.html @@ -43,12 +43,14 @@ $(document).ready(function () { - $(".md-enabled").each(function(index){ - editor = new SimpleMDE({ - element: $(".md-enabled")[index], - toolbar: ["bold", "italic", "strikethrough", "|", "unordered-list", "ordered-list", "|", "link", "|", "preview", "guide"], - status: false, - }); + setupMDE('#id_description'); + setupMDE('#id_notes'); + setupMDE('#item_description'); + + $('#itemModal').on('shown.bs.modal', function (e) { + $('#item_description').data('mde_editor').value( + $('#item_description').val() + ); }); {% if not object.pk and not form.errors %}