Remove wp link button activated. Some js function gathered.
--- a/web/hdabo/static/hdabo/js/hdabo.js Tue Jun 14 14:38:37 2011 +0200
+++ b/web/hdabo/static/hdabo/js/hdabo.js Tue Jun 14 15:28:11 2011 +0200
@@ -5,12 +5,6 @@
$(".up,.down").click(function(){
tag_up_down(this);
});
- // Remove tag for a datasheet's list
- $(".remove_tag_from_list").click(function(){
- if(confirm("Confirmez-vous la suppression du tag \"" + $(this).attr('alt') + "\" de la liste courante ?")){
- remove_tag_from_list(this);
- }
- });
//activate_wp_cb
$(".activate_wp_cb").click(function(e){
new_checked = $(this).is(':checked');
@@ -29,9 +23,20 @@
}
});
+ // Tag simple operations : remove tag from list, reset wp info, remove wp link
+ $(".remove_tag_from_list").click(function(){
+ if(confirm("Confirmez-vous la suppression du tag \"" + $(this).attr('alt') + "\" de la liste courante ?")){
+ update_tag(this);
+ }
+ });
$(".reset_wp_info").click(function(e){
if(confirm("Confirmez-vous le rétablissement du label original de ce tag ?")){
- reset_wp_info(this);
+ update_tag(this);
+ }
+ });
+ $(".remove_wp_link").click(function(e){
+ if(confirm("Confirmez-vous le suppression du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?")){
+ update_tag(this);
}
});
@@ -63,36 +68,12 @@
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
- $("#ok_search").show();
}
});
$("#ok_search").click(function(){
if($("#wp_search").val()!=""){
- $("#ok_search").html("<img src='"+static_url+"hdabo/img/indicator.gif'>");
- var url = add_tag_url;
- $.ajax({
- url: url,
- type: 'POST',
- data: {csrfmiddlewaretoken:global_csrf_token,
- datasheet_id:$('#datasheet_id').val(),
- value:$("#wp_search").val()
- },
- // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
- //dataType: 'json',
- success: function(msg, textStatus, XMLHttpRequest) {
- $('#tag_table_container').html(msg);
- init_tags_events();
- // And scroll to the bottom
- $("html").animate({ scrollTop: $(document).height() }, 500);
- },
- complete: function(){
- // We empty the input and hide the ok button
- $("#wp_search").val("");
- $("#ok_search").hide();
- $("#ok_search").html("<b>OK</b>");
- }
- });
+ add_tag($("#wp_search").val());
}
});
@@ -144,6 +125,7 @@
}
}
});
+
}
function validate_wp_link(cb)
@@ -168,30 +150,20 @@
});
}
-function remove_tag_from_list(btn)
+function update_tag(btn)
{
- var url = remove_tag_from_list_url;
- var id_tag = $(btn).attr('id');
- $.ajax({
- url: url,
- type: 'POST',
- data: {csrfmiddlewaretoken:global_csrf_token,
- datasheet_id:$('#datasheet_id').val(),
- tag_id:id_tag
- },
- // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
- //dataType: 'json',
- success: function(msg, textStatus, XMLHttpRequest) {
- $('#tag_table_container').html(msg);
- init_tags_events();
- }
- });
-}
-
-function remove_tag_from_list(btn)
-{
- var url = remove_tag_from_list_url;
- var id_tag = $(btn).attr('id');
+ if ($(btn).is(".remove_tag_from_list")) {
+ var url = remove_tag_from_list_url;
+ var id_tag = $(btn).attr('id');
+ }
+ else if ($(btn).is(".reset_wp_info")) {
+ var url = reset_wp_info_url;
+ var id_tag = $(btn).html();
+ }
+ else if ($(btn).is(".remove_wp_link")) {
+ var url = remove_wp_link_url;
+ var id_tag = $(btn).attr('id');
+ }
$.ajax({
url: url,
type: 'POST',
@@ -237,21 +209,29 @@
});
}
-function reset_wp_info(cell)
+function add_tag(tag_label)
{
- var tag_id = $(cell).html()
-
- $.ajax({
- url: reset_wp_info_url,
- type: 'POST',
- data: {
- csrfmiddlewaretoken:global_csrf_token,
- datasheet_id:$('#datasheet_id').val(),
- tag_id:tag_id
- },
+ $("#ok_search").html("<img src='"+static_url+"hdabo/img/indicator.gif'>");
+ var url = add_tag_url;
+ $.ajax({
+ url: url,
+ type: 'POST',
+ data: {csrfmiddlewaretoken:global_csrf_token,
+ datasheet_id:$('#datasheet_id').val(),
+ value:tag_label
+ },
+ // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
+ //dataType: 'json',
success: function(msg, textStatus, XMLHttpRequest) {
$('#tag_table_container').html(msg);
init_tags_events();
+ // And scroll to the bottom
+ $("html").animate({ scrollTop: $(document).height() }, 500);
+ },
+ complete: function(){
+ // We empty the input and hide the ok button
+ $("#wp_search").val("");
+ $("#ok_search").html("<b>OK</b>");
}
- });
-}
\ No newline at end of file
+ });
+}
--- a/web/hdabo/templates/list_for_orga.html Tue Jun 14 14:38:37 2011 +0200
+++ b/web/hdabo/templates/list_for_orga.html Tue Jun 14 15:28:11 2011 +0200
@@ -20,6 +20,7 @@
var modify_tag_url = "{% url hdabo.views.modify_tag %}";
var reset_wp_info_url = "{% url hdabo.views.reset_wikipedia_info %}";
var add_tag_url = "{% url hdabo.views.add_tag %}";
+ var remove_wp_link_url = "{% url hdabo.views.remove_wp_link %}";
$(document).ready(function(){
init_tags_events();
--- a/web/hdabo/templates/partial/one_sheet.html Tue Jun 14 14:38:37 2011 +0200
+++ b/web/hdabo/templates/partial/one_sheet.html Tue Jun 14 15:28:11 2011 +0200
@@ -27,7 +27,7 @@
{% endif %}
{% if valid != "2" %}
<span style="float:right;">Ajouter un tag : <input type="text" name="wp_search" id="wp_search" />
- <span id="ok_search" style='display:none' /><b>OK</b></span>
+ <span id="ok_search" /><b>OK</b></span>
</span>
{% endif %}
</p>
--- a/web/hdabo/templates/partial/tag_table.html Tue Jun 14 14:38:37 2011 +0200
+++ b/web/hdabo/templates/partial/tag_table.html Tue Jun 14 15:28:11 2011 +0200
@@ -41,7 +41,7 @@
<option value="discipline">Discipline artistique</option>
</select></td>
<td class="text_centered"><input type="checkbox" class="activate_wp_cb" id="{{t.tag.id}}" alt="{{t.tag.label}}" {% if t.tag.wikipedia_activated %}checked{% endif %} /></td>
- <td class="text_centered"><img src="{{STATIC_URL}}hdabo/img/red_cross.png" class="remove_wp_link" id="{{t.tag.id}}" /></td>
+ <td class="text_centered"><img src="{{STATIC_URL}}hdabo/img/red_cross.png" class="remove_wp_link" id="{{t.tag.id}}" alt="{{t.tag.label}}" /></td>
<td>{{t.tag.alias}}</td>
<td class="text_centered"><img src="{{STATIC_URL}}hdabo/img/tag_remove.png" class="remove_tag_from_list" id="{{t.tag.id}}" alt="{{t.tag.label}}" /></td></tr>
{% endfor %}
--- a/web/hdabo/urls.py Tue Jun 14 14:38:37 2011 +0200
+++ b/web/hdabo/urls.py Tue Jun 14 15:28:11 2011 +0200
@@ -26,4 +26,5 @@
url(r'^modifytag$', 'hdabo.views.modify_tag'),
url(r'^resetwpinfo$', 'hdabo.views.reset_wikipedia_info'),
url(r'^addtag$', 'hdabo.views.add_tag'),
+ url(r'^removewplink$', 'hdabo.views.remove_wp_link'),
)
--- a/web/hdabo/views.py Tue Jun 14 14:38:37 2011 +0200
+++ b/web/hdabo/views.py Tue Jun 14 15:28:11 2011 +0200
@@ -189,7 +189,7 @@
#@login_required
def reset_wikipedia_info(request):
- tag_id = request.POST["tag_id"]
+ tag_id = request.POST["tag_id"]
ds_id = request.POST["datasheet_id"]
tag = Tag.objects.get(id=tag_id)
@@ -239,3 +239,16 @@
return get_tag_table(request=request, ds_id=ds_id, valid=0)
+
+#@login_required
+def remove_wp_link(request=None):
+ ds_id = request.POST["datasheet_id"]
+ tag_id = request.POST["tag_id"]
+ tag = Tag.objects.filter(id=tag_id)[0]
+ tag.wikipedia_activated = False
+ tag.wikipedia_url = None
+ tag.wikipedia_pageid = None
+ tag.url_status = 0;
+ tag.save()
+
+ return get_tag_table(request=request, ds_id=ds_id, valid=0)