diff --git a/HISTORY.rst b/HISTORY.rst index 87bfd7d018..13eb9d46c5 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -51,6 +51,7 @@ * Integrate django-autoadmin into the core apps. * Update middleware to new style classes. * Add server side invalid document template. +* Move tag specific JavaScript to the tags app. 3.1.11 (2019-04-XX) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index 9fc1531085..c8490ea427 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -75,6 +75,7 @@ Other changes * Integrate django-autoadmin into the core apps. * Update middleware to new style classes. * Add server side invalid document template. +* Move tag specific JavaScript to the tags app. Removals -------- diff --git a/mayan/apps/appearance/static/appearance/js/mayan_app.js b/mayan/apps/appearance/static/appearance/js/mayan_app.js index ad505332b6..9a04769c41 100644 --- a/mayan/apps/appearance/static/appearance/js/mayan_app.js +++ b/mayan/apps/appearance/static/appearance/js/mayan_app.js @@ -52,22 +52,6 @@ class MayanApp { }); } - static tagSelectionTemplate (tag, container) { - var $tag = $( - ' ' + tag.text + '' - ); - container[0].style.background = tag.element.dataset.color; - return $tag; - } - - static tagResultTemplate (tag) { - if (!tag.element) { return ''; } - var $tag = $( - ' ' + tag.text + '' - ); - return $tag; - } - // Instance methods callbackAJAXSpinnerUpdate () { @@ -283,12 +267,6 @@ class MayanApp { dropdownAutoWidth: true, width: '100%' }); - - $('.select2-tags').select2({ - templateSelection: MayanApp.tagSelectionTemplate, - templateResult: MayanApp.tagResultTemplate, - width: '100%' - }); } resizeFullHeight () { diff --git a/mayan/apps/tags/forms.py b/mayan/apps/tags/forms.py index 392de0d68f..7da1d6d848 100644 --- a/mayan/apps/tags/forms.py +++ b/mayan/apps/tags/forms.py @@ -15,6 +15,9 @@ logger = logging.getLogger(__name__) class TagMultipleSelectionForm(forms.Form): + class Media: + js = ('tags/js/tags_form.js',) + def __init__(self, *args, **kwargs): help_text = kwargs.pop('help_text', None) permission = kwargs.pop('permission', permission_tag_view) diff --git a/mayan/apps/tags/static/tags/js/tags_form.js b/mayan/apps/tags/static/tags/js/tags_form.js new file mode 100644 index 0000000000..b61d693e0b --- /dev/null +++ b/mayan/apps/tags/static/tags/js/tags_form.js @@ -0,0 +1,25 @@ +'use strict'; + +var tagSelectionTemplate = function (tag, container) { + var $tag = $( + ' ' + tag.text + '' + ); + container[0].style.background = tag.element.dataset.color; + return $tag; +} + +var tagResultTemplate = function (tag) { + if (!tag.element) { return ''; } + var $tag = $( + ' ' + tag.text + '' + ); + return $tag; +} + +jQuery(document).ready(function() { + $('.select2-tags').select2({ + templateSelection: tagSelectionTemplate, + templateResult: tagResultTemplate, + width: '100%' + }); +});