Add tag feature finished. Full page templates good placed.
authorcavaliet
Tue, 14 Jun 2011 12:58:53 +0200
changeset 26 699957597026
parent 24 8f84b9bbd22d
child 27 056c19e37eab
Add tag feature finished. Full page templates good placed.
web/hdabo/static/hdabo/js/hdabo.js
web/hdabo/templates/hdabo_base.html
web/hdabo/templates/list_for_orga.html
web/hdabo/templates/organisation_list.html
web/hdabo/templates/partial/list_for_orga.html
web/hdabo/templates/partial/one_sheet.html
web/hdabo/templates/partial/organisation_list.html
web/hdabo/urls.py
web/hdabo/views.py
--- a/web/hdabo/static/hdabo/js/hdabo.js	Tue Jun 14 01:51:26 2011 +0200
+++ b/web/hdabo/static/hdabo/js/hdabo.js	Tue Jun 14 12:58:53 2011 +0200
@@ -1,172 +1,232 @@
-// -*- coding: utf-8 -*-
-function init_tags_events()
-{
-    // Up and down management for tag table lines
-    $(".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');
-        if(new_checked){
-            question = "Confirmez-vous l'activation du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?";
-        } else {
-            question = "Confirmez-vous la désactivation du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?";
-        }
-        if(confirm(question)){
-            validate_wp_link(this);
-        }
-        else{
-            // Since the click event is dispatched after the checked changed, we change the checked changed if confirm is false.
-            e.preventDefault(); // unvalidates user's click
-            $(this).attr('checked', !new_checked);
-        }
-    });
-    
-    
-    $.editable.addInputType('autocomplete', {
-    	element : $.editable.types.text.element,
-    	plugin : function(settings, original) {
-    		$('input', this).autocomplete(settings.autocomplete);
-    	}
-    });
-    
-    $(".wikipediatag").editable(modify_tag_url, { 
-    	indicator : "<img src='"+static_url+"hdabo/img/indicator.gif'>",
-    	type      : "autocomplete",
-    	tooltip   : "Cliquer pour éditer...",
-    	onblur    : "submit",
-    	submitdata: {csrfmiddlewaretoken:global_csrf_token, datasheet_id:$('#datasheet_id').val()},
-    	callback  : function(value, settings) {
-            $('#tag_table_container').html(value);
-            init_tags_events();
-    	},
-    	autocomplete : {
-			source: function( request, response ) {
-				$.ajax({
-					url: "http://fr.wikipedia.org/w/api.php",
-					dataType: "jsonp",
-					data: {
-						action: "opensearch",
-						limit: "20",
-						namespace: "0",
-						format: "json",
-						search: request.term
-					},
-					success: function( data ) {
-						response( $.map( data[1], function( item ) {
-							return {
-								label: item,
-								value: item
-							}
-						}));
-					}
-				});
-			},
-			minLength: 2,
-			open: function() {
-				$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
-			},
-			close: function() {
-				$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
-			}    		
-    	}
-    });
-}
-
-function validate_wp_link(cb)
-{
-    var url = validate_wp_link_url;
-    var id_tag = $(cb).attr('id');
-    new_checked = $(cb).is(':checked');
-    $.ajax({
-        url: url,
-        type: 'POST',
-        data: {csrfmiddlewaretoken:global_csrf_token,
-               datasheet_id:$('#datasheet_id').val(),
-               tag_id:id_tag,
-               activated:new_checked
-               },
-        // 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');
-    $.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');
-    $.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 tag_up_down(arrow)
-{
-    if ($(arrow).is(".up")) {
-        mv = "u";
-    } else {
-        mv = "d";
-    }
-    var url = tag_up_down_url;
-    var id_tag = $(arrow).attr('id');
-    // This indicates the position (from 0) of the tag in the list. NB : it is different from the TagSheet.order in the database.
-    var pos_tag = $(arrow).attr('pos');
-    $.ajax({
-        url: url,
-        type: 'POST',
-        data: {csrfmiddlewaretoken:global_csrf_token, 
-               datasheet_id:$('#datasheet_id').val(),
-               tag_id:id_tag,
-               move:mv,
-               tag_pos:pos_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();
-        }
-    });
+// -*- coding: utf-8 -*-
+function init_tags_events()
+{
+    // Up and down management for tag table lines
+    $(".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');
+        if(new_checked){
+            question = "Confirmez-vous l'activation du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?";
+        } else {
+            question = "Confirmez-vous la désactivation du lien Wikipédia pour le tag \"" + $(this).attr('alt') + "\" ?";
+        }
+        if(confirm(question)){
+            validate_wp_link(this);
+        }
+        else{
+            // Since the click event is dispatched after the checked changed, we change the checked changed if confirm is false.
+            e.preventDefault(); // unvalidates user's click
+            $(this).attr('checked', !new_checked);
+        }
+    });
+    
+    $("#wp_search").autocomplete({
+        source: function( request, response ) {
+            $.ajax({
+                url: "http://fr.wikipedia.org/w/api.php",
+                dataType: "jsonp",
+                data: {
+                    action: "opensearch",
+                    limit: "20",
+                    namespace: "0",
+                    format: "json",
+                    search: request.term
+                },
+                success: function( data ) {
+                    response( $.map( data[1], function( item ) {
+                        return {
+                            label: item,
+                            value: item
+                        }
+                    }));
+                }
+            });
+        },
+        minLength: 2,
+        open: function() {
+            $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
+        },
+        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>");
+                }
+            });
+        }
+    });
+    
+    $.editable.addInputType('autocomplete', {
+    	element : $.editable.types.text.element,
+    	plugin : function(settings, original) {
+    		$('input', this).autocomplete(settings.autocomplete);
+    	}
+    });
+    
+    $(".wikipediatag").editable(modify_tag_url, { 
+    	indicator : "<img src='"+static_url+"hdabo/img/indicator.gif'>",
+    	type      : "autocomplete",
+    	tooltip   : "Cliquer pour éditer...",
+    	onblur    : "submit",
+    	submitdata: {csrfmiddlewaretoken:global_csrf_token, datasheet_id:$('#datasheet_id').val()},
+    	callback  : function(value, settings) {
+            $('#tag_table_container').html(value);
+            init_tags_events();
+    	},
+    	autocomplete : {
+			source: function( request, response ) {
+				$.ajax({
+					url: "http://fr.wikipedia.org/w/api.php",
+					dataType: "jsonp",
+					data: {
+						action: "opensearch",
+						limit: "20",
+						namespace: "0",
+						format: "json",
+						search: request.term
+					},
+					success: function( data ) {
+						response( $.map( data[1], function( item ) {
+							return {
+								label: item,
+								value: item
+							}
+						}));
+					}
+				});
+			},
+			minLength: 2,
+			open: function() {
+				$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
+			},
+			close: function() {
+				$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
+			}    		
+    	}
+    });
+}
+
+function validate_wp_link(cb)
+{
+    var url = validate_wp_link_url;
+    var id_tag = $(cb).attr('id');
+    new_checked = $(cb).is(':checked');
+    $.ajax({
+        url: url,
+        type: 'POST',
+        data: {csrfmiddlewaretoken:global_csrf_token,
+               datasheet_id:$('#datasheet_id').val(),
+               tag_id:id_tag,
+               activated:new_checked
+               },
+        // 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');
+    $.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');
+    $.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 tag_up_down(arrow)
+{
+    if ($(arrow).is(".up")) {
+        mv = "u";
+    } else {
+        mv = "d";
+    }
+    var url = tag_up_down_url;
+    var id_tag = $(arrow).attr('id');
+    // This indicates the position (from 0) of the tag in the list. NB : it is different from the TagSheet.order in the database.
+    var pos_tag = $(arrow).attr('pos');
+    $.ajax({
+        url: url,
+        type: 'POST',
+        data: {csrfmiddlewaretoken:global_csrf_token, 
+               datasheet_id:$('#datasheet_id').val(),
+               tag_id:id_tag,
+               move:mv,
+               tag_pos:pos_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();
+        }
+    });
 }
\ No newline at end of file
--- a/web/hdabo/templates/hdabo_base.html	Tue Jun 14 01:51:26 2011 +0200
+++ b/web/hdabo/templates/hdabo_base.html	Tue Jun 14 12:58:53 2011 +0200
@@ -1,79 +1,80 @@
-{% load i18n %}
-{% comment %}{% load logintag %}{% endcomment %}
-{% comment %}{% load navigation %}{% endcomment %}
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{{LANGUAGE_CODE}}" lang="{{LANGUAGE_CODE}}">
-<head>
-{% block head %}
-	<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
-    <meta http-equiv="content-language" content="{{LANGUAGE_CODE}}" />
-    <link rel="SHORTCUT ICON" href="{{STATIC_URL}}hdabo/img/favicon.ico" />
-    <title>{% block title %}HDA-BO{% endblock %}</title>
-    {% block js_import %}
-    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.min.js"></script>
-    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.nyroModal.min.js"></script>
-    <!--[if IE 6]>
-    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.nyroModal-ie6.min.js"></script>
-    <![endif]-->
-    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.qtip.min.js"></script>
-    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.validate.js" ></script>
-    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/hdabo.js"></script>
-    {% endblock %}
-    
-    {% block css_declaration %}
-    <style type="text/css">
-		.rounded {
-			behavior:url("{{STATIC_URL}}hdabo/css/border-radius.htc");
-		}
-	</style>
-	{% endblock %}
-    
-    {% block css_import %}
-    
-    <link rel="stylesheet" href="{{STATIC_URL}}hdabo/css/style.css" type="text/css"/>
-    <link rel="stylesheet" href="{{STATIC_URL}}hdabo/css/nyroModal.css" type="text/css"/>
-    {% endblock %}
-    
-    {% block js_declaration %}
-    {% endblock %}
-    
-{% endblock %}
-</head>
-<body>
-{% block body %}
-<div class="container">
-<div id="header">      
-    {% block header %}
-    <div id="header_left">
-    	<p><a href="{% url hdabo.views.home %}">HDA<span class="hda_blue">BO</span></a></p>
-    </div>
-    {% endblock %}
-</div>
-<div id="content" class="span-24 last">
-    <div id="toolbar">
-    {% block toolbar %}
-    <p><a href="{% url hdabo.views.home %}">home</a></p>
-    {% endblock %}
-    </div>
-    <div id="inner_content">
-    {% block content %}
-    {% endblock %}
-    </div>      
-</div>
-<div id="footer" class="span-24 last">
-    {% block footer %}
-    <div class="footer_img">
-    <a href="http://www.iri.centrepompidou.fr" target="_blank"><img src="{{STATIC_URL}}hdabo/img/logo_IRI_footer.png" alt="Logo IRI" /></a>
-    </div>
-    <div style="float: right; text-align: right;" class="small" id="copyright_version">
-        <div>©2011 <a style="text-decoration: none; color: #4F5155;" href="http://www.iri.centrepompidou.fr" target="_blank">IRI</a></div>
-        <div id="versionwrapper"><span class="version" id="version">{{VERSION}}</span></div>
-    </div>
-    {% endblock %}
-</div>
-</div>
-{% endblock %}
-</body>
-</html>
+{% load i18n %}
+{% comment %}{% load logintag %}{% endcomment %}
+{% comment %}{% load navigation %}{% endcomment %}
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{{LANGUAGE_CODE}}" lang="{{LANGUAGE_CODE}}">
+<head>
+{% block head %}
+	<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
+    <meta http-equiv="content-language" content="{{LANGUAGE_CODE}}" />
+    <link rel="SHORTCUT ICON" href="{{STATIC_URL}}hdabo/img/favicon.ico" />
+    <title>{% block title %}HDA-BO{% endblock %}</title>
+    {% block js_import %}
+    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/hdabo.js"></script>
+    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.min.js"></script>
+    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.nyroModal.min.js"></script>
+    <!--[if IE 6]>
+    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.nyroModal-ie6.min.js"></script>
+    <![endif]-->
+    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.qtip.min.js"></script>
+    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.validate.js" ></script>
+    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.textchange.min.js" ></script>
+    {% endblock %}
+    
+    {% block css_declaration %}
+    <style type="text/css">
+		.rounded {
+			behavior:url("{{STATIC_URL}}hdabo/css/border-radius.htc");
+		}
+	</style>
+	{% endblock %}
+    
+    {% block css_import %}
+    
+    <link rel="stylesheet" href="{{STATIC_URL}}hdabo/css/style.css" type="text/css"/>
+    <link rel="stylesheet" href="{{STATIC_URL}}hdabo/css/nyroModal.css" type="text/css"/>
+    {% endblock %}
+    
+    {% block js_declaration %}
+    {% endblock %}
+    
+{% endblock %}
+</head>
+<body>
+{% block body %}
+<div class="container">
+<div id="header">      
+    {% block header %}
+    <div id="header_left">
+    	<p><a href="{% url hdabo.views.home %}">HDA<span class="hda_blue">BO</span></a></p>
+    </div>
+    {% endblock %}
+</div>
+<div id="content" class="span-24 last">
+    <div id="toolbar">
+    {% block toolbar %}
+    <p><a href="{% url hdabo.views.home %}">home</a></p>
+    {% endblock %}
+    </div>
+    <div id="inner_content">
+    {% block content %}
+    {% endblock %}
+    </div>      
+</div>
+<div id="footer" class="span-24 last">
+    {% block footer %}
+    <div class="footer_img">
+    <a href="http://www.iri.centrepompidou.fr" target="_blank"><img src="{{STATIC_URL}}hdabo/img/logo_IRI_footer.png" alt="Logo IRI" /></a>
+    </div>
+    <div style="float: right; text-align: right;" class="small" id="copyright_version">
+        <div>©2011 <a style="text-decoration: none; color: #4F5155;" href="http://www.iri.centrepompidou.fr" target="_blank">IRI</a></div>
+        <div id="versionwrapper"><span class="version" id="version">{{VERSION}}</span></div>
+    </div>
+    {% endblock %}
+</div>
+</div>
+{% endblock %}
+</body>
+</html>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/hdabo/templates/list_for_orga.html	Tue Jun 14 12:58:53 2011 +0200
@@ -0,0 +1,78 @@
+{% extends "hdabo_base.html" %}
+    {% block title %}HDA - BO : Fiches pour {{ orga_name }}{% endblock %}
+
+    {% block js_import %}
+    {{block.super}}
+    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery-ui.min.js"></script>
+    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.jeditable.js"></script>
+    {% endblock %}
+    
+    {% block js_declaration %}
+    {{block.super}}
+    {% if valid != "2" %}
+    <script type="text/javascript">
+    
+    var global_csrf_token = "{{ csrf_token }}";
+    var static_url = "{{STATIC_URL}}";
+    var tag_up_down_url = "{% url hdabo.views.tag_up_down %}";
+    var remove_tag_from_list_url = "{% url hdabo.views.remove_tag_from_list %}";
+    var validate_wp_link_url = "{% url hdabo.views.validate_wp_link %}";
+    var modify_tag_url = "{% url hdabo.views.modify_tag %}";
+    var add_tag_url = "{% url hdabo.views.add_tag %}";
+    
+    $(document).ready(function(){
+        init_tags_events();
+    });
+    </script>
+    {% endif %}
+    {% endblock %}
+
+    {% block css_import %}
+    {{block.super}}
+    <link rel="stylesheet" href="{{STATIC_URL}}hdabo/css/smoothness/jquery-ui-1.8.13.custom.css" type="text/css"/>
+    {% endblock %}
+
+    {% block css_declaration %}
+    {{block.super}}
+    <style type="text/css">
+    .ui-autocomplete {
+        max-height: 100px;
+        overflow-y: auto;
+        /* prevent horizontal scrollbar */
+        overflow-x: hidden;
+        /* add padding to account for vertical scrollbar */
+        padding-right: 20px;
+    }
+    </style>
+    {% endblock %}
+    
+    
+    {% block content %}
+    {{block.super}}
+    <p>Fiche(s) pour l'organisation <b>{{ orga_name }}</b> : {{nb_sheets}} fiche(s)</p>
+    {% if valid != "2" %}
+    <div id="count_nav_top">
+        <p><a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=0 %}">&lt;&lt;</a>&nbsp;&nbsp;
+           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=prev_index %}">&lt;</a>&nbsp;&nbsp;
+           {{displayed_index}}/{{nb_sheets}}&nbsp;&nbsp;
+           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=next_index %}">&gt;</a>&nbsp;&nbsp;
+           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=last_index %}">&gt;&gt;</a></p>
+    </div>
+    {% endif %}
+    <table>
+    {% for ds in datasheets %}
+    <tr class="imageline {% cycle 'hdaboevenline' 'hdabooddline' %}"><td>
+    {% include "partial/one_sheet.html" %}
+    </td></tr>
+    {% endfor %}
+    </table>
+    {% if valid != "2" %}
+    <div id="count_nav_bottom">
+        <p><a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=0 %}">&lt;&lt;</a>&nbsp;&nbsp;
+           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=prev_index %}">&lt;</a>&nbsp;&nbsp;
+           {{displayed_index}}/{{nb_sheets}}&nbsp;&nbsp;
+           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=next_index %}">&gt;</a>&nbsp;&nbsp;
+           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=last_index %}">&gt;&gt;</a></p>
+    </div>
+    {% endif %}
+    {% endblock %}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/hdabo/templates/organisation_list.html	Tue Jun 14 12:58:53 2011 +0200
@@ -0,0 +1,32 @@
+{% extends "hdabo_base.html" %}
+    {% block title %}HDA-BO : Liste des organisations{% endblock %}
+    
+    {% block content %}
+    {{block.super}}
+    <p>Afficher les fiches non validées pour les lieux suivants :</p>
+    <table>
+    <tr>
+        <th class="contenttitle">Nom</th>
+        <th class="contenttitle">Fiches non validées</th>
+        <th class="contenttitle">Fiches validées</th>
+        <th class="contenttitle">Toutes les fiches</th>
+    </tr>
+    {% for item in organisations %}
+    <tr class="imageline {% cycle 'hdabooddline' 'hdaboevenline'%}">
+        <td class="contenttitle">{{ item.organisation.name|default:"_" }} (<a href="{{item.organisation.website}}" target="_blank">lien</a>)</td>
+        <td class="contenttitle">
+        {% if item.nb_unval > 0 %}
+        <a class="contenttitlelink" href="{% url hdabo.views.list_for_orga orga_id=item.organisation.id valid=0 %}">{{item.nb_unval}}</a>
+        {% else %}0{% endif %}</td>
+        <td class="contenttitle">
+        {% if item.nb_val > 0 %}
+        <a class="contenttitlelink" href="{% url hdabo.views.list_for_orga orga_id=item.organisation.id valid=1 %}">{{item.nb_val}}</a>
+        {% else %}0{% endif %}</td>
+        <td class="contenttitle">
+        {% if item.nb_all > 0 %}
+        <a class="contenttitlelink" href="{% url hdabo.views.list_for_orga orga_id=item.organisation.id valid=2 %}">{{item.nb_all}}</a>
+        {% else %}0{% endif %}</td>
+    </tr>
+    {% endfor %}
+    </table>
+    {% endblock %}
--- a/web/hdabo/templates/partial/list_for_orga.html	Tue Jun 14 01:51:26 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,77 +0,0 @@
-{% extends "hdabo_base.html" %}
-    {% block title %}HDA - BO : Fiches pour {{ orga_name }}{% endblock %}
-
-    {% block js_import %}
-    {{block.super}}
-    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery-ui.min.js"></script>
-    <script type="text/javascript" src="{{STATIC_URL}}hdabo/js/jquery.jeditable.js"></script>
-    {% endblock %}
-    
-    {% block js_declaration %}
-    {{block.super}}
-    {% if valid != "2" %}
-    <script type="text/javascript">
-    
-    var global_csrf_token = "{{ csrf_token }}";
-    var static_url = "{{STATIC_URL}}";
-    var tag_up_down_url = "{% url hdabo.views.tag_up_down %}";
-    var remove_tag_from_list_url = "{% url hdabo.views.remove_tag_from_list %}";
-    var validate_wp_link_url = "{% url hdabo.views.validate_wp_link %}";
-    var modify_tag_url = "{% url hdabo.views.modify_tag %}";
-    
-    $(document).ready(function(){
-        init_tags_events();
-    });
-    </script>
-    {% endif %}
-    {% endblock %}
-
-    {% block css_import %}
-    {{block.super}}
-    <link rel="stylesheet" href="{{STATIC_URL}}hdabo/css/smoothness/jquery-ui-1.8.13.custom.css" type="text/css"/>
-    {% endblock %}
-
-    {% block css_declaration %}
-    {{block.super}}
-    <style type="text/css">
-    .ui-autocomplete {
-        max-height: 100px;
-        overflow-y: auto;
-        /* prevent horizontal scrollbar */
-        overflow-x: hidden;
-        /* add padding to account for vertical scrollbar */
-        padding-right: 20px;
-    }
-    </style>
-    {% endblock %}
-    
-    
-    {% block content %}
-    {{block.super}}
-    <p>Fiche(s) pour l'organisation <b>{{ orga_name }}</b> : {{nb_sheets}} fiche(s)</p>
-    {% if valid != "2" %}
-    <div id="count_nav_top">
-        <p><a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=0 %}">&lt;&lt;</a>&nbsp;&nbsp;
-           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=prev_index %}">&lt;</a>&nbsp;&nbsp;
-           {{displayed_index}}/{{nb_sheets}}&nbsp;&nbsp;
-           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=next_index %}">&gt;</a>&nbsp;&nbsp;
-           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=last_index %}">&gt;&gt;</a></p>
-    </div>
-    {% endif %}
-    <table>
-    {% for ds in datasheets %}
-    <tr class="imageline {% cycle 'hdaboevenline' 'hdabooddline' %}"><td>
-    {% include "partial/one_sheet.html" %}
-    </td></tr>
-    {% endfor %}
-    </table>
-    {% if valid != "2" %}
-    <div id="count_nav_bottom">
-        <p><a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=0 %}">&lt;&lt;</a>&nbsp;&nbsp;
-           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=prev_index %}">&lt;</a>&nbsp;&nbsp;
-           {{displayed_index}}/{{nb_sheets}}&nbsp;&nbsp;
-           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=next_index %}">&gt;</a>&nbsp;&nbsp;
-           <a href="{% url hdabo.views.list_for_orga orga_id=orga_id, valid=valid, start_index=last_index %}">&gt;&gt;</a></p>
-    </div>
-    {% endif %}
-    {% endblock %}
--- a/web/hdabo/templates/partial/one_sheet.html	Tue Jun 14 01:51:26 2011 +0200
+++ b/web/hdabo/templates/partial/one_sheet.html	Tue Jun 14 12:58:53 2011 +0200
@@ -25,6 +25,11 @@
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; par : <input type="text" name="validator" value="{{ds.validated}}"/>
         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; le {{ds.validation_date}}
         {% 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>
+        {% endif %}
         </p>
         {% csrf_token %}
         <input type="hidden" name="datasheet_id" value="{{ds.id}}" id="datasheet_id" />
--- a/web/hdabo/templates/partial/organisation_list.html	Tue Jun 14 01:51:26 2011 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-{% extends "hdabo_base.html" %}
-    {% block title %}HDA-BO : Liste des organisations{% endblock %}
-    
-    {% block content %}
-    {{block.super}}
-    <p>Afficher les fiches non validées pour les lieux suivants :</p>
-    <table>
-    <tr>
-        <th class="contenttitle">Nom</th>
-        <th class="contenttitle">Fiches non validées</th>
-        <th class="contenttitle">Fiches validées</th>
-        <th class="contenttitle">Toutes les fiches</th>
-    </tr>
-    {% for item in organisations %}
-    <tr class="imageline {% cycle 'hdabooddline' 'hdaboevenline'%}">
-        <td class="contenttitle">{{ item.organisation.name|default:"_" }} (<a href="{{item.organisation.website}}" target="_blank">lien</a>)</td>
-        <td class="contenttitle">
-        {% if item.nb_unval > 0 %}
-        <a class="contenttitlelink" href="{% url hdabo.views.list_for_orga orga_id=item.organisation.id valid=0 %}">{{item.nb_unval}}</a>
-        {% else %}0{% endif %}</td>
-        <td class="contenttitle">
-        {% if item.nb_val > 0 %}
-        <a class="contenttitlelink" href="{% url hdabo.views.list_for_orga orga_id=item.organisation.id valid=1 %}">{{item.nb_val}}</a>
-        {% else %}0{% endif %}</td>
-        <td class="contenttitle">
-        {% if item.nb_all > 0 %}
-        <a class="contenttitlelink" href="{% url hdabo.views.list_for_orga orga_id=item.organisation.id valid=2 %}">{{item.nb_all}}</a>
-        {% else %}0{% endif %}</td>
-    </tr>
-    {% endfor %}
-    </table>
-    {% endblock %}
--- a/web/hdabo/urls.py	Tue Jun 14 01:51:26 2011 +0200
+++ b/web/hdabo/urls.py	Tue Jun 14 12:58:53 2011 +0200
@@ -24,4 +24,5 @@
     url(r'^removetagfromlist$', 'hdabo.views.remove_tag_from_list'),
     url(r'^validatelink$', 'hdabo.views.validate_wp_link'),
     url(r'^modifytag$', 'hdabo.views.modify_tag'),
+    url(r'^addtag$', 'hdabo.views.add_tag'),
 )
--- a/web/hdabo/views.py	Tue Jun 14 01:51:26 2011 +0200
+++ b/web/hdabo/views.py	Tue Jun 14 12:58:53 2011 +0200
@@ -1,5 +1,7 @@
 from django.conf import settings
 from django.contrib.auth.decorators import login_required #@UnusedImport
+from django.db.models import Max
+from django.http import HttpResponse
 from django.shortcuts import render_to_response
 from django.template import RequestContext
 from hdabo.wp_utils import query_wikipedia_title
@@ -22,7 +24,7 @@
         org_list.append({'organisation':orga, 'nb_all':nb_all, 'nb_val':nb_val, 'nb_unval':nb_unval})
     
     
-    return render_to_response("partial/organisation_list.html",
+    return render_to_response("organisation_list.html",
                               {'organisations':org_list},
                               context_instance=RequestContext(request))
 
@@ -70,7 +72,7 @@
     next_index = min(nb_sheets - 1, start_index + 1);
     last_index = max(nb_sheets - 1, 0);
     
-    return render_to_response("partial/list_for_orga.html",
+    return render_to_response("list_for_orga.html",
                               {'datasheets':datasheets, 'orga_name':orga_name,
                                'nb_sheets':nb_sheets, 'orga_id':orga_id, 'ordered_tags':ordered_tags,
                                'prev_index':prev_index, 'next_index':next_index, 'last_index':last_index,
@@ -174,3 +176,37 @@
     tag.save()
     
     return get_tag_table(request=request, ds_id=ds_id, valid=0)
+
+
+#@login_required
+def add_tag(request=None):
+    
+    ds_id = request.POST["datasheet_id"]
+    tag_label = request.POST["value"]
+    # We get the wikipedia references for the tag_label
+    site = wiki.Wiki(settings.WIKIPEDIA_API_URL) #@UndefinedVariable
+    new_label, status, url, pageid, response = query_wikipedia_title(site, tag_label) #@UnusedVariable
+    # We get or create the tag object
+    tag, created = Tag.objects.get_or_create(label=new_label)
+    # We save the datas
+    if new_label is not None:
+        tag.label = new_label
+        tag.original_label = new_label
+    if status is not None:
+        tag.url_status = status
+    if url is not None:
+        tag.wikipedia_url = url
+        tag.wikipedia_activated = True
+    if pageid is not None:
+        tag.wikipedia_pageid = pageid
+    tag.save()
+    # We put the tag at the bottom of the datasheet's tag list 
+    # if the tag is created or if the tag is not in the list
+    ds = Datasheet.objects.filter(id=ds_id)[0]
+    list_ts = TaggedSheet.objects.filter(datasheet=ds)
+    if created or len(list_ts.filter(tag=tag))==0 :
+        new_order = list_ts.aggregate(Max('order'))['order__max'] + 1
+        ts = TaggedSheet.objects.create(datasheet=ds, tag=tag, original_order=new_order, order=new_order)
+        ts.save()
+    
+    return get_tag_table(request=request, ds_id=ds_id, valid=0)