Move tag specific JavaScript to the tags app

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-04-14 01:55:05 -04:00
parent 3bcadd047b
commit 33f84ec327
5 changed files with 30 additions and 22 deletions

View File

@@ -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)
===================

View File

@@ -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
--------

View File

@@ -52,22 +52,6 @@ class MayanApp {
});
}
static tagSelectionTemplate (tag, container) {
var $tag = $(
'<span class="label label-tag" style="background: ' + tag.element.dataset.color + ';"> ' + tag.text + '</span>'
);
container[0].style.background = tag.element.dataset.color;
return $tag;
}
static tagResultTemplate (tag) {
if (!tag.element) { return ''; }
var $tag = $(
'<span class="label label-tag" style="background: ' + tag.element.dataset.color + ';"> ' + tag.text + '</span>'
);
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 () {

View File

@@ -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)

View File

@@ -0,0 +1,25 @@
'use strict';
var tagSelectionTemplate = function (tag, container) {
var $tag = $(
'<span class="label label-tag" style="background: ' + tag.element.dataset.color + ';"> ' + tag.text + '</span>'
);
container[0].style.background = tag.element.dataset.color;
return $tag;
}
var tagResultTemplate = function (tag) {
if (!tag.element) { return ''; }
var $tag = $(
'<span class="label label-tag" style="background: ' + tag.element.dataset.color + ';"> ' + tag.text + '</span>'
);
return $tag;
}
jQuery(document).ready(function() {
$('.select2-tags').select2({
templateSelection: tagSelectionTemplate,
templateResult: tagResultTemplate,
width: '100%'
});
});