Add alias update feature.
authorcavaliet
Wed, 15 Jun 2011 19:00:42 +0200
changeset 36 4e8129c9f858
parent 35 a8b97ccf8b85
child 38 e2d9295b126b
Add alias update feature.
web/hdabo/static/hdabo/js/hdabo.js
web/hdabo/templates/all_tags.html
web/hdabo/templates/list_for_orga.html
web/hdabo/templates/partial/all_tags_table.html
web/hdabo/templates/partial/tag_table.html
web/hdabo/urls.py
web/hdabo/views.py
--- a/web/hdabo/static/hdabo/js/hdabo.js	Wed Jun 15 16:43:39 2011 +0200
+++ b/web/hdabo/static/hdabo/js/hdabo.js	Wed Jun 15 19:00:42 2011 +0200
@@ -40,7 +40,7 @@
         }
     });
     
-    // Wikipedia search management (autocompletion, save changes and new tag)
+    // Wikipedia search management (autocompletion and save changes)
     $.editable.addInputType('autocomplete', {
     	element : $.editable.types.text.element,
     	plugin : function(settings, original) {
@@ -93,11 +93,30 @@
 			}
     	}
     });
+    
+    // Update alias management
+    $(".tag_alias").editable(update_tag_alias_url, {
+    	indicator : "<img src='"+static_url+"hdabo/img/indicator.gif'>",
+    	type      : "text",
+    	placeholder:"",
+    	tooltip   : "Cliquer pour éditer...",
+    	onblur    : "submit",
+    	submitdata: {
+            csrfmiddlewaretoken:global_csrf_token, 
+            datasheet_id:$('#datasheet_id').val(),
+            num_page:$('#num_page').val(),
+            nb_by_page:$('#nb_by_page').val()
+        },
+    	callback  : function(value, settings) {
+            $('#tag_table_container').html(value);
+            init_tags_events();
+    	}
+    });
 }
 
 function init_datasheet_events()
 {
-    // Wikipedia search management (autocompletion, save changes and new tag)
+    // Wikipedia search management (new tag)
     $("#wp_search").autocomplete({
         source: function( request, response ) {
             $.ajax({
--- a/web/hdabo/templates/all_tags.html	Wed Jun 15 16:43:39 2011 +0200
+++ b/web/hdabo/templates/all_tags.html	Wed Jun 15 19:00:42 2011 +0200
@@ -9,7 +9,6 @@
     
     {% block js_declaration %}
     {{block.super}}
-    {% if valid != "2" %}
     <script type="text/javascript">
     
     var global_csrf_token = "{{ csrf_token }}";
@@ -21,12 +20,12 @@
     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 %}";
+    var update_tag_alias_url = "{% url hdabo.views.update_tag_alias %}";
     
     $(document).ready(function(){
         init_tags_events();
     });
     </script>
-    {% endif %}
     {% endblock %}
 
     {% block css_import %}
--- a/web/hdabo/templates/list_for_orga.html	Wed Jun 15 16:43:39 2011 +0200
+++ b/web/hdabo/templates/list_for_orga.html	Wed Jun 15 19:00:42 2011 +0200
@@ -22,6 +22,7 @@
     var add_tag_url = "{% url hdabo.views.add_tag %}";
     var remove_wp_link_url = "{% url hdabo.views.remove_wp_link %}";
     var validate_datasheet_url = "{% url hdabo.views.validate_datasheet %}";
+    var update_tag_alias_url = "{% url hdabo.views.update_tag_alias %}";
     
     $(document).ready(function(){
         init_tags_events();
--- a/web/hdabo/templates/partial/all_tags_table.html	Wed Jun 15 16:43:39 2011 +0200
+++ b/web/hdabo/templates/partial/all_tags_table.html	Wed Jun 15 19:00:42 2011 +0200
@@ -29,7 +29,7 @@
             </select></td>
         <td class="text_centered"><input type="checkbox" class="activate_wp_cb" id="{{tag.id}}" alt="{{tag.label}}" {% if tag.wikipedia_activated %}checked{% endif %} /></td>
         <td class="text_centered"><img src="{{STATIC_URL}}hdabo/img/red_cross.png" class="remove_wp_link" id="{{tag.id}}" alt="{{tag.label}}" /></td>
-        <td>{{tag.alias}}</td></tr>
+        <td class="tag_alias" id="{{tag.id}}" >{% if tag.alias %}{{tag.alias}}{% endif %}</td></tr>
     {% endfor %}
     </table>
 {% endblock %}
--- a/web/hdabo/templates/partial/tag_table.html	Wed Jun 15 16:43:39 2011 +0200
+++ b/web/hdabo/templates/partial/tag_table.html	Wed Jun 15 19:00:42 2011 +0200
@@ -42,7 +42,7 @@
 				</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}}" alt="{{t.tag.label}}" /></td>
-            <td>{{t.tag.alias}}</td>
+            <td class="tag_alias" id="{{t.tag.id}}" >{% if t.tag.alias %}{{t.tag.alias}}{% endif %}</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 %}
     {% else %}
--- a/web/hdabo/urls.py	Wed Jun 15 16:43:39 2011 +0200
+++ b/web/hdabo/urls.py	Wed Jun 15 19:00:42 2011 +0200
@@ -33,4 +33,5 @@
     url(r'^validatedatasheet$', 'hdabo.views.validate_datasheet'),
     url(r'^validatedatasheet/(?P<ds_id>[\w-]+)$', 'hdabo.views.validate_datasheet'),
     url(r'^validatedatasheet/(?P<ds_id>[\w-]+)/(?P<valid>[\w-]+)/$', 'hdabo.views.validate_datasheet'),
+    url(r'^updatetagalias$', 'hdabo.views.update_tag_alias'),
 )
--- a/web/hdabo/views.py	Wed Jun 15 16:43:39 2011 +0200
+++ b/web/hdabo/views.py	Wed Jun 15 19:00:42 2011 +0200
@@ -274,7 +274,7 @@
     tag.wikipedia_url = None
     tag.wikipedia_pageid = None
     tag.wikipedia_activated = False
-        
+    
     process_tag(site, tag, 0)
     
     if u"datasheet_id" in request.POST :
@@ -367,4 +367,21 @@
     else :
         return redirect('home')
     
-    
\ No newline at end of file
+
+#@login_required
+def update_tag_alias(request):
+    # 2 cases : 
+    # - ordered tag for one datasheet : POST["datasheet_id"] is not null
+    # - all tags list : POST["datasheet_id"] is null and POST["num_page"] and POST["nb_by_page"] are not null
+    tag_id = request.POST["id"]
+    tag_alias = request.POST["value"]
+    tag = Tag.objects.get(id=tag_id)
+    tag.alias = tag_alias
+    tag.save()
+    
+    if u"datasheet_id" in request.POST :
+        return get_tag_table(request=request, ds_id=request.POST["datasheet_id"], valid=0)
+    else :
+        return get_all_tags_table(request=request, num_page=request.POST["num_page"], nb_by_page=request.POST["nb_by_page"])
+    
+        
\ No newline at end of file