add keywords!

pull/1/head
eric 2015-01-15 14:34:43 -05:00
parent 4f0cc87b48
commit 073040d7ca
3 changed files with 26 additions and 5 deletions

View File

@ -42,6 +42,7 @@
var isSupporter = false;
{% endif %}
</script>
{% endblock %}
{% block topsection %}
@ -432,7 +433,7 @@
{% endif %}
{% if work.subjects.all.count > 0 %}
<h4>Keywords</h4>
<ul>
<ul id="kw_list">
{% for subject in work.subjects.all %}
<li itemprop="keywords">{{ subject.name }}
{% if user.is_staff or user in work.last_campaign.managers.all %}
@ -442,8 +443,9 @@
{% endfor %}
</ul>
{% if user.is_staff or user in work.last_campaign.managers.all %}
<form method="POST" action="{% url kw_edit work.id %}" id="kw_add_form">{% csrf_token %}
{{ kwform.add_kw }}<input type="submit" name="kw_add" value="add keyword" />
<form method="POST" id="kw_add_form">{% csrf_token %}
{{ kwform.add_kw }}<input type="hidden" name="kw_add" value="true"> <input type="submit" name="kw_add_fake" value="add keyword" id="kw_add_form_submit" />
</form>
{% endif %}
{% endif %}
{% endifequal %}

View File

@ -2194,9 +2194,9 @@ def kw_edit(request, work_id):
except models.Subject.DoesNotExist:
return HttpResponse('invalid subject')
work.subjects.add(subject)
return HttpResponse('added ' + add_kw.name )
return HttpResponse( add_kw.name )
else:
return HttpResponse('bad form ' )
return HttpResponse('xxbadform' )
else:
return HttpResponse(str(add_form))
return HttpResponse(str(add_form))

View File

@ -96,6 +96,25 @@ $j().ready(function() {
li.html('kw removed');
});
});
// this is the id of the submit button
$j('#kw_add_form_submit').click(function() {
var url = 'kw/';
$j.ajax({
type: 'POST',
url: url,
data: $j('#kw_add_form').serialize(),
success: function(data)
{
if (data == 'xxbadform'){alert("bad keyword");} else {
$j('#kw_list').append('<li>' + data + '<span class="deletebutton" data="' + data +'">x</span></li>')
}; // data will be the added kw.
}
});
return false; // avoid to execute the actual submit of the form.
});
});