From 1e4177766ba9e04105e5d83a090273074b90504c Mon Sep 17 00:00:00 2001 From: eric Date: Mon, 21 Sep 2015 15:01:45 -0400 Subject: [PATCH] Enable subject editing on editions --- frontend/forms.py | 7 ++++- frontend/templates/new_edition.html | 48 +++++++++++++++++++++-------- frontend/views.py | 10 ------ 3 files changed, 41 insertions(+), 24 deletions(-) diff --git a/frontend/forms.py b/frontend/forms.py index 654b65c0..c854b0aa 100644 --- a/frontend/forms.py +++ b/frontend/forms.py @@ -86,7 +86,12 @@ bisac_headings = BisacHeading.objects.all() class EditionForm(forms.ModelForm): add_author = forms.CharField(max_length=500, required=False) add_author_relation = forms.ChoiceField(choices=CREATOR_RELATIONS, initial=('aut', 'Author')) - add_subject = forms.CharField(max_length=200, required=False) + add_subject = AutoCompleteSelectField( + SubjectLookup, + widget=AutoCompleteSelectWidget(SubjectLookup,allow_new=True), + label='Keyword', + required =False + ) bisac = forms.ModelChoiceField( bisac_headings, required=False ) publisher_name = AutoCompleteSelectField( diff --git a/frontend/templates/new_edition.html b/frontend/templates/new_edition.html index a195bf98..69dcfa66 100644 --- a/frontend/templates/new_edition.html +++ b/frontend/templates/new_edition.html @@ -51,7 +51,31 @@ ul.fancytree-container { return true; }); - }); + $j().ready(function(){ + var contentblock = $j('#content-block'); + contentblock.on("click", "span.deletebutton", function () { + var kw = $j(this).attr('data'); + var li = $j(this).parent(); + + // perform action + jQuery.post('{% url 'kw_edit' edition.work.id %}', {'remove_kw': kw, 'csrfmiddlewaretoken': '{{ csrf_token }}' }, function(data) { + li.html('kw removed'); + }); + }); + // this is the id of the submit button + + $j('#add_subject_submit').click(function(event) { + data= $j('#id_add_subject_0').attr('value') + if (data == 'xxbadform'){ + alert("bad keyword"); + } else { + $j('#kw_list').append('
  • ' + data + 'x
  • ') + }; // data will be the added kw. + }); + + }); +}); + {{ form.media.js }} @@ -72,7 +96,7 @@ ul.fancytree-container { {% if admin %}

    Title and ISBN 13 are required; the rest is optional, though a cover image is strongly recommended.

    -
    + {% csrf_token %} {{ form.work }} {{ form.non_field_errors }} @@ -124,28 +148,26 @@ ul.fancytree-container { {% endif %} )

    Publication Date (four-digit year): {{ form.publication_date.errors }}{{ form.publication_date }}

    - - {% comment %} - this has been removed since there's no point in exposing subject functionality when we're not doing anything with it -- will just confuse people. -

    Subjects: -