Bug 22660: Add system pref to allow switching of editors in News Tool
authorLucas Gass <lucas@bywatersolutions.com>
Fri, 8 May 2020 22:57:40 +0000 (22:57 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 30 Jul 2020 15:44:27 +0000 (17:44 +0200)
This patch adds a system preference called 'NewsToolEditor' which allows for the choice between TinyMCE and CodeMirror in the News Feature.

TEST PLAN:
1. Apply patch and run updatedatabase
2. Go to Tools > News and make a new entry or edit an existing News item.
3. When you initially load you should gte the TinyMCE editor (WYSIWYG)
4. Search for the NewsToolEditor system preference and switch to CodeMirror.
5. Reload your News item and now you should see the CodeMirror editor.
6. Try saving content with both and maki sure it works.
7. Try adding some different HTML tags in CodeMirror mode, saving, and making sure it looks right when you switch back to TinyMCE

Signed-off-by: Owen Leonard <oleonard@myacpl.org>

Signed-off-by: Lisette Scheer <lisetteslatah@gmail.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

installer/data/mysql/atomicupdate/bug_22660_add_NewsToolEditor_system_preference.perl [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/tools.pref
koha-tmpl/intranet-tmpl/prog/en/modules/tools/koha-news.tt

diff --git a/installer/data/mysql/atomicupdate/bug_22660_add_NewsToolEditor_system_preference.perl b/installer/data/mysql/atomicupdate/bug_22660_add_NewsToolEditor_system_preference.perl
new file mode 100644 (file)
index 0000000..88e1416
--- /dev/null
@@ -0,0 +1,6 @@
+$DBversion = 'XXX'; # will be replaced by the RM
+if( CheckVersion( $DBversion ) ) {
+    $dbh->do( "INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES('NewsToolEditor','tinymce', 'Choose tool for editing News','tinymce|codemirror','Choice')" );
+
+    NewVersion( $DBversion, 22660, "Adds NewsToolEditor system preference");
+}
index 758a591..5fcb9b1 100644 (file)
@@ -330,6 +330,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('minPasswordLength','8',NULL,'Specify the minimum length of a patron/staff password','free'),
 ('NewItemsDefaultLocation','','','If set, all new items will have a location of the given Location Code ( Authorized Value type LOC )',''),
 ('NewsAuthorDisplay','none','none|opac|staff|both','Display the author name for news items.','Choice'),
+('NewsToolEditor','tinymce','tinymce|codemirror','Choose tool for editing News.', 'Choice'),
 ('noissuescharge','5','','Define maximum amount withstanding before check outs are blocked','Integer'),
 ('NoIssuesChargeGuarantees','','','Define maximum amount withstanding before check outs are blocked','Integer'),
 ('noItemTypeImages','0',NULL,'If ON, disables itemtype images in the staff interface','YesNo'),
index 1d4f296..77a40f1 100644 (file)
@@ -36,7 +36,13 @@ Tools:
                   opac: "OPAC only"
                   staff: "Staff client only"
                   both: "Both OPAC and staff client"
-            -
+        -
+            - Use
+            - pref: NewsToolEditor
+              choices:
+                  tinymce: "TinyMCE (WYSIWYG)"
+                  codemirror: "CodeMirror"
+            - when editing News.
     Upload:
         -
             - Automatically delete temporary uploads older than
index a42aea5..80d6d68 100644 (file)
@@ -4,6 +4,12 @@
 [% USE Branches %]
 [% SET footerjs = 1 %]
 [% INCLUDE 'doc-head-open.inc' %]
+[% Asset.css("lib/codemirror/codemirror.css") | $raw %]
+<style>
+.CodeMirror {
+    resize: vertical;
+}
+</style>
 <title>Koha &rsaquo; Tools &rsaquo; News</title>
 [% INCLUDE 'doc-head-close.inc' %]
 [% IF ( opac_news_count ) %]
@@ -206,6 +212,8 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %]</div>
 [% MACRO jsinclude BLOCK %]
     [% INCLUDE 'calendar.inc' %]
     [% Asset.js("js/tools-menu.js") | $raw %]
+    [% Asset.js("lib/d3c3/d3.min.js") | $raw %]
+    [% Asset.js("lib/d3c3/c3.min.js") | $raw %]
     [% IF ( opac_news_count ) %]
         [% INCLUDE 'datatables.inc' %]
         <script>
@@ -292,9 +300,17 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %]</div>
             });
         </script>
     [% END %]
+    [% Asset.js( "lib/codemirror/codemirror.min.js" ) | $raw %]
     [% Asset.js("lib/tiny_mce/tinymce.min.js") | $raw %]
     [% INCLUDE 'str/tinymce_i18n.inc' %]
     <script>
+        [% IF Koha.Preference('NewsToolEditor') == 'codemirror' %]
+        var editor = CodeMirror.fromTextArea(document.getElementById('content'), {
+            lineNumbers: true,
+            mode: "text/html",
+            lineWrapping: true
+        });
+        [% ELSE %]
         tinyMCE.init({
             verify_html: false,
             force_br_newlines : false,
@@ -311,6 +327,7 @@ Edit news item[% ELSE %]Add news item[% END %][% ELSE %]News[% END %]</div>
                 "table | bullist numlist | undo redo | removeformat | emoticons charmap | forecolor backcolor | code visualaid help"
             ],
         });
+        [% END %]
     </script>
 [% END %]