Datasheet validation, better repartition of js function, hand cursor on buttons.
authorcavaliet
Wed, 15 Jun 2011 16:41:28 +0200
changeset 34 26368d096723
parent 32 ffd77b2b939f
child 35 a8b97ccf8b85
Datasheet validation, better repartition of js function, hand cursor on buttons.
web/hdabo/static/hdabo/css/style.css
web/hdabo/static/hdabo/js/hdabo.js
web/hdabo/templates/all_tags.html
web/hdabo/templates/list_for_orga.html
web/hdabo/templates/partial/one_sheet.html
web/hdabo/urls.py
web/hdabo/views.py
--- a/web/hdabo/static/hdabo/css/style.css	Tue Jun 14 18:26:52 2011 +0200
+++ b/web/hdabo/static/hdabo/css/style.css	Wed Jun 15 16:41:28 2011 +0200
@@ -361,6 +361,10 @@
 .text_centered {
 	text-align: center;
 }
+.hand_cursor, .reset_wp_info, .updown_td, .remove_wp_link, .remove_tag_from_list {
+	cursor: pointer;
+}
+
 
 /* styles for the 4 types of STATUS*/
 .null_result {
--- a/web/hdabo/static/hdabo/js/hdabo.js	Tue Jun 14 18:26:52 2011 +0200
+++ b/web/hdabo/static/hdabo/js/hdabo.js	Wed Jun 15 16:41:28 2011 +0200
@@ -40,50 +40,13 @@
         }
     });
     
-    $("#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").click(function(){
-        if($("#wp_search").val()!=""){
-            add_tag($("#wp_search").val());
-        }
-    });
-    
+    // Wikipedia search management (autocompletion, save changes and new tag)
     $.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",
@@ -127,10 +90,70 @@
 			},
 			close: function() {
 				$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
-			}    		
+			}
     	}
     });
+}
+
+function init_datasheet_events()
+{
+    // Wikipedia search management (autocompletion, save changes and new tag)
+    $("#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").click(function(){
+        if($("#wp_search").val()!=""){
+            add_tag($("#wp_search").val());
+        }
+    });
     
+    // Validate sheet management : the radiobutton name has is "'gr_validated' + datasheet.hda_id"
+    $("#validated").click(function(e){
+        e.preventDefault();
+        // We count the number of tags. It has to be between 5 and 25
+        var nb_tags = $('#tag_table tr').length - 1;
+        if(nb_tags<5 || nb_tags>25){
+            alert("Cette fiche n'est pas validable : elle doit contenir entre 5 et 25 tags.");
+        }
+        else{
+            if(confirm("Confirmez-vous la validation de cette fiche ? Elle contient " + nb_tags + " tags.")){
+                window.location = validate_datasheet_url + "/" + $('#datasheet_id').val() + "/true";
+            }
+        }
+    });
+    $("#not_validated").click(function(e){
+        e.preventDefault();
+        if(confirm("Confirmez-vous l'invalidation de cette fiche ?")){
+            window.location = validate_datasheet_url + "/" + $('#datasheet_id').val() + "/false";
+        }
+    });
 }
 
 function update_tag(btn)
--- a/web/hdabo/templates/all_tags.html	Tue Jun 14 18:26:52 2011 +0200
+++ b/web/hdabo/templates/all_tags.html	Wed Jun 15 16:41:28 2011 +0200
@@ -65,10 +65,10 @@
     {% include "partial/all_tags_table.html" %}
     </div>
     <div id="count_nav_bottom">
-        <p><a href="{% url hdabo.views.all_tags %}">&lt;&lt;</a>&nbsp;&nbsp;
-           <a href="{% url hdabo.views.all_tags %}">&lt;</a>&nbsp;&nbsp;
-           bli/bla&nbsp;&nbsp;
-           <a href="{% url hdabo.views.all_tags %}">&gt;</a>&nbsp;&nbsp;
-           <a href="{% url hdabo.views.all_tags %}">&gt;&gt;</a></p>
+        <p><a href="{% url hdabo.views.all_tags num_page=1, nb_by_page=nb_by_page %}">&lt;&lt;</a>&nbsp;&nbsp;
+           <a href="{% url hdabo.views.all_tags num_page=prev_page, nb_by_page=nb_by_page %}">&lt;</a>&nbsp;&nbsp;
+           {{ num_page }}/{{ last_page }}&nbsp;&nbsp;
+           <a href="{% url hdabo.views.all_tags num_page=next_page, nb_by_page=nb_by_page %}">&gt;</a>&nbsp;&nbsp;
+           <a href="{% url hdabo.views.all_tags num_page=last_page, nb_by_page=nb_by_page %}">&gt;&gt;</a></p>
     </div>
     {% endblock %}
--- a/web/hdabo/templates/list_for_orga.html	Tue Jun 14 18:26:52 2011 +0200
+++ b/web/hdabo/templates/list_for_orga.html	Wed Jun 15 16:41:28 2011 +0200
@@ -21,9 +21,11 @@
     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 validate_datasheet_url = "{% url hdabo.views.validate_datasheet %}";
     
     $(document).ready(function(){
         init_tags_events();
+        init_datasheet_events();
     });
     </script>
     {% endif %}
@@ -51,7 +53,8 @@
     
     {% block content %}
     {{block.super}}
-    <p>Fiche(s) pour l'organisation <b>{{ orga_name }}</b> : {{nb_sheets}} fiche(s)</p>
+    <p>Fiche(s) {% if valid == "1" %}<b>validées</b>{% else %}{% if valid != "2" %}<b>non validées</b>{% endif %}{% endif %}
+    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/web/hdabo/templates/partial/one_sheet.html	Tue Jun 14 18:26:52 2011 +0200
+++ b/web/hdabo/templates/partial/one_sheet.html	Wed Jun 15 16:41:28 2011 +0200
@@ -19,14 +19,13 @@
         {# <p><b>original_modification_date</b><br/>{{ds.original_modification_date|date:"d/m/Y"}}</p> #}
     </div>
     <div class="right_sheet">
-        <p><input type="radio" name="gr_validated{{ds.hda_id}}" value="not_validated" {% if not ds.validated %}checked{% endif %} />En cours
-        <input type="radio" name="gr_validated{{ds.hda_id}}" value="validated" {% if ds.validated %}checked{% endif %} />Validé
+        <p><input type="radio" name="gr_validated{{ds.hda_id}}" id="not_validated" value="not_validated" {% if not ds.validated %}checked{% endif %} />En cours
+        <input type="radio" name="gr_validated{{ds.hda_id}}" id="validated" value="validated" {% if ds.validated %}checked{% endif %} />Validé
         {% if ds.validated %}
-        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; par : <input type="text" name="validator" value="{{ds.validated}}"/>
-        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; le {{ds.validation_date}}
+        &nbsp;&nbsp; par {{ds.validator}} le {{ds.validation_date|date:"d/m/Y"}}
         {% endif %}
         {% if valid != "2" %}
-        <span style="float:right;">Ajouter un tag : <input type="text" name="wp_search" id="wp_search" /><span id="ok_search" /><b>OK</b></span></span>
+        <span style="float:right;">Ajouter un tag : <input type="text" name="wp_search" id="wp_search" /> <span id="ok_search" class="hand_cursor"/><b>OK</b></span></span>
         {% endif %}
         </p>
         {% csrf_token %}
--- a/web/hdabo/urls.py	Tue Jun 14 18:26:52 2011 +0200
+++ b/web/hdabo/urls.py	Wed Jun 15 16:41:28 2011 +0200
@@ -16,13 +16,13 @@
     url(r'^admin/', include(admin.site.urls)),
     url(r'^search/', include('haystack.urls')),
     url(r'^$', 'hdabo.views.home', name='home'),
-    url(r'^list/(?P<orga_id>[\w-]+)$', 'hdabo.views.list_for_orga'),
-    url(r'^list/(?P<orga_id>[\w-]+)/(?P<valid>[\w-]+)/$', 'hdabo.views.list_for_orga'),
-    url(r'^list/(?P<orga_id>[\w-]+)/(?P<valid>[\w-]+)/(?P<start_index>[\w-]+)/$', 'hdabo.views.list_for_orga'),
-    url(r'^list/(?P<orga_id>[\w-]+)/(?P<valid>[\w-]+)/(?P<start_index>[\w-]+)/(?P<length>[\w-]+)/$', 'hdabo.views.list_for_orga'),
+    url(r'^list/(?P<orga_id>[\w-]+)$', 'hdabo.views.list_for_orga', name='list_for_orga'),
+    url(r'^list/(?P<orga_id>[\w-]+)/(?P<valid>[\w-]+)/$', 'hdabo.views.list_for_orga', name='list_for_orga'),
+    url(r'^list/(?P<orga_id>[\w-]+)/(?P<valid>[\w-]+)/(?P<start_index>[\w-]+)/$', 'hdabo.views.list_for_orga', name='list_for_orga'),
+    url(r'^list/(?P<orga_id>[\w-]+)/(?P<valid>[\w-]+)/(?P<start_index>[\w-]+)/(?P<length>[\w-]+)/$', 'hdabo.views.list_for_orga', name='list_for_orga'),
     url(r'^tagupdown$', 'hdabo.views.tag_up_down'),
     url(r'^removetagfromlist$', 'hdabo.views.remove_tag_from_list'),
-    url(r'^validatelink$', 'hdabo.views.validate_wp_link'),
+    url(r'^validatewplink$', 'hdabo.views.validate_wp_link'),
     url(r'^modifytag$', 'hdabo.views.modify_tag'),
     url(r'^resetwpinfo$', 'hdabo.views.reset_wikipedia_info'),
     url(r'^addtag$', 'hdabo.views.add_tag'),
@@ -30,4 +30,7 @@
     url(r'^alltags$', 'hdabo.views.all_tags'),
     url(r'^alltags/(?P<num_page>[\w-]+)$', 'hdabo.views.all_tags'),
     url(r'^alltags/(?P<num_page>[\w-]+)/(?P<nb_by_page>[\w-]+)/$', 'hdabo.views.all_tags'),
+    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'),
 )
--- a/web/hdabo/views.py	Tue Jun 14 18:26:52 2011 +0200
+++ b/web/hdabo/views.py	Wed Jun 15 16:41:28 2011 +0200
@@ -2,7 +2,7 @@
 from django.contrib.auth.decorators import login_required #@UnusedImport
 from django.core.paginator import Paginator
 from django.db.models import Max
-from django.shortcuts import render_to_response
+from django.shortcuts import render_to_response, redirect
 from django.template import RequestContext
 from hdabo.management.commands.querywikipedia import process_tag
 from hdabo.wp_utils import normalize_tag, query_wikipedia_title
@@ -53,6 +53,7 @@
         # And select the current one
         datasheets = [datasheets[start_index]]
     elif valid != "2":
+        valid = "0"
         # We count all the validated sheets
         datasheets = Datasheet.objects.filter(organisation=orga).filter(validated=False)
         nb_sheets = len(datasheets)
@@ -332,3 +333,33 @@
         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"])
+
+
+#@login_required
+def validate_datasheet(request=None, ds_id=None, valid=None):
+    # We set if valid is true of false, function of the url parameters
+    if valid == "1" or valid == "true" or not valid :
+        valid = True
+    else :
+        valid = False
+    # We validate or unvalidate the requester datasheet
+    ds = Datasheet.objects.get(id=ds_id)
+    if valid :
+        ds.validate(None)
+    else :
+        ds.unvalidate()
+    ds.save()
+    # If there are still some unvalidated/validated ds for the ds's orga, we display the first one
+    same_organisation_ds = Datasheet.objects.filter(organisation=ds.organisation).filter(validated=not valid)
+    if valid :
+        # We ask to display the unvalidated ds
+        valid_req = 0
+    else :
+        # We ask to display the validated ds
+        valid_req = 1
+    if len(same_organisation_ds)>0 :
+        return redirect('list_for_orga', orga_id=ds.organisation.id, valid=valid_req)
+    else :
+        return redirect('home')
+    
+    
\ No newline at end of file