From 8f274c26917162bb222f4b53730dabda3591eafe Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Tue, 15 Oct 2013 16:18:40 +0200 Subject: [PATCH] Add CKeditor to the agenda item text field --- openslides/agenda/forms.py | 7 +- openslides/agenda/templates/agenda/edit.html | 18 +++++ openslides/agenda/templates/agenda/view.html | 2 +- .../motion/templates/motion/motion_form.html | 8 ++ .../static/javascript/ckeditor-config.js | 73 +++++++++---------- 5 files changed, 66 insertions(+), 42 deletions(-) diff --git a/openslides/agenda/forms.py b/openslides/agenda/forms.py index 947ec41b5..6c1833065 100644 --- a/openslides/agenda/forms.py +++ b/openslides/agenda/forms.py @@ -16,16 +16,19 @@ from django import forms from django.utils.translation import ugettext_lazy from mptt.forms import TreeNodeChoiceField -from openslides.utils.forms import CssClassMixin +from openslides.utils.forms import CssClassMixin, CleanHtmlFormMixin from openslides.utils.person.forms import PersonFormField from .models import Item, Speaker -class ItemForm(CssClassMixin, forms.ModelForm): +class ItemForm(CleanHtmlFormMixin, CssClassMixin, forms.ModelForm): """ Form to create of update an item. """ + + clean_html_fields = ('text', ) + parent = TreeNodeChoiceField( queryset=Item.objects.all(), label=ugettext_lazy("Parent item"), required=False) diff --git a/openslides/agenda/templates/agenda/edit.html b/openslides/agenda/templates/agenda/edit.html index 4d26f393f..d49316b33 100644 --- a/openslides/agenda/templates/agenda/edit.html +++ b/openslides/agenda/templates/agenda/edit.html @@ -2,6 +2,7 @@ {% load i18n %} {% load tags %} +{% load staticfiles %} {% block title %} {% if item %} @@ -12,6 +13,23 @@ – {{ block.super }} {% endblock %} +{% block header %} + {{ block.super }} + +{% endblock %} + +{% block javascript %} + {{ block.super }} + + + +{% endblock %} + {% block content %}

{% if item %} diff --git a/openslides/agenda/templates/agenda/view.html b/openslides/agenda/templates/agenda/view.html index 0903de6eb..0b033d77d 100644 --- a/openslides/agenda/templates/agenda/view.html +++ b/openslides/agenda/templates/agenda/view.html @@ -44,7 +44,7 @@

{% if not item.content_object %} - {{ item.text|safe|linebreaks }} + {{ item.text|safe }} {% else %} {% trans item.content_type.name %} {{ item.content_object }} {% endif %} diff --git a/openslides/motion/templates/motion/motion_form.html b/openslides/motion/templates/motion/motion_form.html index e3a5505f1..2732013db 100644 --- a/openslides/motion/templates/motion/motion_form.html +++ b/openslides/motion/templates/motion/motion_form.html @@ -5,12 +5,14 @@ {% load staticfiles %} {% block header %} + {{ block.super }} {% endblock %} {% block javascript %} + {{ block.super }} @@ -24,6 +26,12 @@ listItemLabelClass: 'bsmListItemLabel-custom', removeClass: 'bsmListItemRemove-custom' }); + + // Init CKeditor + $(function() { + CKEDITOR.replace('id_text', ck_options); + CKEDITOR.replace('id_reason', ck_options); + }); {% endblock %} diff --git a/openslides/static/javascript/ckeditor-config.js b/openslides/static/javascript/ckeditor-config.js index a51057f85..aebd1462c 100644 --- a/openslides/static/javascript/ckeditor-config.js +++ b/openslides/static/javascript/ckeditor-config.js @@ -1,49 +1,44 @@ /* * Configuration file for the CKeditor */ -$(function() { - var ck_options = { +var ck_options = { - // Using a custom CSS file allows us to specifically style elements entered - // using the editor. Using the CSS prefix class .ckeditor_html prevents these - // styles from meddling with the main layout + // Using a custom CSS file allows us to specifically style elements entered + // using the editor. Using the CSS prefix class .ckeditor_html prevents these + // styles from meddling with the main layout - contentsCss: "/static/styles/ckeditor.css", - bodyClass: "ckeditor_html", + contentsCss: "/static/styles/ckeditor.css", + bodyClass: "ckeditor_html", - allowedContent: - 'h1 h2 h3 pre blockquote b i u strike;' + + allowedContent: + 'h1 h2 h3 pre blockquote b i u strike;' + - // A workaround for the problem described in http://dev.ckeditor.com/ticket/10192 - // Hopefully, the problem will be solved in the final version of CKEditor 4.1 - // If so, then {margin-left} can be removed - 'p{margin-left};' + + // A workaround for the problem described in http://dev.ckeditor.com/ticket/10192 + // Hopefully, the problem will be solved in the final version of CKEditor 4.1 + // If so, then {margin-left} can be removed + 'p{margin-left};' + - 'a[!href];' + - 'table tr th td caption;' + - 'ol ul li;' + - 'span{!font-family};' + - 'span{!color};', - removePlugins: "save, print, preview, pagebreak, templates, showblocks, magicline", + 'a[!href];' + + 'table tr th td caption;' + + 'ol ul li;' + + 'span{!font-family};' + + 'span{!color};', + removePlugins: "save, print, preview, pagebreak, templates, showblocks, magicline", - // Not part of the standard package of CKEditor - // http://ckeditor.com/addon/insertpre - extraPlugins: "insertpre", + // Not part of the standard package of CKEditor + // http://ckeditor.com/addon/insertpre + extraPlugins: "insertpre", - toolbar_Full: [ - { name: 'document', items : [ 'Source','-','Save','DocProps','Preview','Print','-','Templates' ] }, - { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] }, - { name: 'editing', items : [ 'Find','Replace','-','SpellChecker', 'Scayt' ] }, - { name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] }, - { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] }, - { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Pre','InsertPre','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }, - { name: 'links', items : [ 'Link','Unlink','Anchor' ] }, - { name: 'styles', items : [ 'Format','FontSize' ] }, - { name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] } - ], - toolbar: 'Full' - }; - - CKEDITOR.replace('id_text', ck_options); - CKEDITOR.replace('id_reason', ck_options); -}); + toolbar_Full: [ + { name: 'document', items : [ 'Source','-','Save','DocProps','Preview','Print','-','Templates' ] }, + { name: 'clipboard', items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] }, + { name: 'editing', items : [ 'Find','Replace','-','SpellChecker', 'Scayt' ] }, + { name: 'forms', items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] }, + { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] }, + { name: 'paragraph', items : [ 'NumberedList','BulletedList','-','Pre','InsertPre','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] }, + { name: 'links', items : [ 'Link','Unlink','Anchor' ] }, + { name: 'styles', items : [ 'Format','FontSize' ] }, + { name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About' ] } + ], + toolbar: 'Full' +};