# HG changeset patch # User cavaliet # Date 1308058091 -7200 # Node ID 142d0440c9aa73443e768200e333a1063df34a33 # Parent c21f88ad164d74795d847db9ebf2b68d39ac8788 Remove wp link button activated. Some js function gathered. diff -r c21f88ad164d -r 142d0440c9aa web/hdabo/static/hdabo/js/hdabo.js --- 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(""); - 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("OK"); - } - }); + 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(""); + 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("OK"); } - }); -} \ No newline at end of file + }); +} diff -r c21f88ad164d -r 142d0440c9aa web/hdabo/templates/list_for_orga.html --- 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(); diff -r c21f88ad164d -r 142d0440c9aa web/hdabo/templates/partial/one_sheet.html --- 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" %} Ajouter un tag : - + OK {% endif %}

diff -r c21f88ad164d -r 142d0440c9aa web/hdabo/templates/partial/tag_table.html --- 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 @@ - + {{t.tag.label}} {{t.tag.alias}} {{t.tag.label}} {% endfor %} diff -r c21f88ad164d -r 142d0440c9aa web/hdabo/urls.py --- 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'), ) diff -r c21f88ad164d -r 142d0440c9aa web/hdabo/views.py --- 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)