merge
authorcavaliet
Mon, 28 Nov 2011 12:19:56 +0100
changeset 47 34718ebfb3c0
parent 46 6f643fc1de26 (diff)
parent 43 54f204bceb28 (current diff)
child 48 16b5fd8d5405
merge
Controller/WikiTagController.php
Resources/public/js/wikiTag.js
--- a/Controller/WikiTagController.php	Sun Nov 27 22:36:21 2011 +0100
+++ b/Controller/WikiTagController.php	Mon Nov 28 12:19:56 2011 +0100
@@ -90,10 +90,17 @@
      * Display a list of ordered tag for a document
      * @param integer $id_doc
      */
-    public function documentTagsAction($id_doc)
+    public function documentTagsAction($id_doc, $profile_name="")
     {
+        // Management of profiles for the list of displayed columns and reorder tag button
+        $profile_array = $this->container->getParameter("wiki_tag.document_list_profile");
+        $columns_array = null;
+        if($profile_array!=null && $profile_name!=null && $profile_name!=""){
+            $columns_array = $profile_array[$profile_name];
+        }
+        
         $ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
-        return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc));
+        return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'profile_name' => $profile_name, 'columns' => $columns_array));
     }
 
     /**
@@ -397,7 +404,7 @@
     public function renderDocTags($id_doc)
     {
         $ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
-        return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc));
+        return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'columns' => null));
     }
 
 
@@ -530,7 +537,7 @@
         $id_moved_tag = $this->getRequest()->request->get('tag_id');
         $moved_tag = $this->getDoctrine()->getRepository('WikiTagBundle:Tag')->findOneBy(array('id' => $id_moved_tag));
         // We update the tag label and its wikipedia info with the original label.
-        $this->updateTagWithNewLabel($moved_tag, $moved_tag->getOriginalLabel());
+        return $this->updateTagWithNewLabel($moved_tag, $moved_tag->getOriginalLabel());
         
         // We render the tag list.
         $num_page = $this->getRequest()->request->get('num_page');
@@ -551,9 +558,7 @@
                 // We get the Wikipedia informations for the sent label
                 $tag_label_normalized = WikiTagUtils::normalizeTag($label);
                 $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
-                
                 $tag->setWikipediaInfo($wp_response);
-
                 // Save datas.
                 $em = $this->getDoctrine()->getEntityManager();
                 $em->persist($tag);
@@ -615,7 +620,7 @@
         // We add the search string if necessary
         if($searched!=""){
             // We replace "*" by "%", and doctrine wants ' to be ''.
-            $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("'", "''", str_replace("*", "%", $searched))."'")));
+            $qb->where($qb->expr()->orx($qb->expr()->like('t.normalizedLabel', "'".str_replace("'", "''", str_replace("*", "%", str_replace("+", " ", $searched)))."'")));
         }
         //return $qb->getDql();
         
--- a/DependencyInjection/Configuration.php	Sun Nov 27 22:36:21 2011 +0100
+++ b/DependencyInjection/Configuration.php	Mon Nov 28 12:19:56 2011 +0100
@@ -58,6 +58,13 @@
                     ->useAttributeAsKey('name')
                     ->prototype('variable')
                     ->end()
+                ->end()
+                ->arrayNode('document_list_profile')
+                    ->treatNullLike(array())
+                    ->useAttributeAsKey('name')
+                    ->prototype('variable')
+                    ->end()
+                ->end()
             ->end();
         
         return $treeBuilder;
--- a/DependencyInjection/WikiTagExtension.php	Sun Nov 27 22:36:21 2011 +0100
+++ b/DependencyInjection/WikiTagExtension.php	Mon Nov 28 12:19:56 2011 +0100
@@ -46,5 +46,6 @@
         $container->setParameter("wiki_tag.fields_all", $fields);
         $container->setParameter("wiki_tag.route_for_documents_by_tag", $config['route_for_documents_by_tag']);
         $container->setParameter("wiki_tag.reactive_selectors", $config['reactive_selectors']);
+        $container->setParameter("wiki_tag.document_list_profile", $config['document_list_profile']);
     }
 }
--- a/Resources/public/css/wikiTag.css	Sun Nov 27 22:36:21 2011 +0100
+++ b/Resources/public/css/wikiTag.css	Mon Nov 28 12:19:56 2011 +0100
@@ -94,6 +94,9 @@
     float: none;
     position: absolute;
 }
+.wikitag_context_static {
+    width: 300px;
+}
 /* These styles can be changed. */
 .wikitag_context_change {
     width: 260px;
@@ -103,5 +106,20 @@
 .wikitag_context_change input {
     width: 250px;
 }
+.wikitag_context_result {
+    width: 500px !important;
+}
+.wikitag_context_result_item {
+    text-indent:-5px;
+}
+.wikitag_context_result_title {
+    font-weight: bold;
+}
+.wikitag_context_result_snippet {
+    font-size: 11.5px;
+}
+.searchmatch {
+    color: #0000ff;
+}
 
 
--- a/Resources/public/js/wikiTag.js	Sun Nov 27 22:36:21 2011 +0100
+++ b/Resources/public/js/wikiTag.js	Mon Nov 28 12:19:56 2011 +0100
@@ -31,8 +31,9 @@
     	tooltip   : "Cliquer pour éditer...",
     	onblur    : "submit",
     	submitdata: {
-            csrfmiddlewaretoken:global_csrf_token, 
+            csrfmiddlewaretoken:global_csrf_token,
             wikitag_document_id:$('#wikitag_document_id').val(),
+            wikitag_document_profile:$('#wikitag_document_profile').val(),
             num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined),
             nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined),
             sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined),
@@ -87,8 +88,9 @@
     	tooltip   : "Cliquer pour éditer...",
     	onblur    : "submit",
     	submitdata: {
-            csrfmiddlewaretoken:global_csrf_token, 
+            csrfmiddlewaretoken:global_csrf_token,
             wikitag_document_id:$('#wikitag_document_id').val(),
+            wikitag_document_profile:$('#wikitag_document_profile').val(),
             num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined),
             nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined),
             sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined),
@@ -111,6 +113,7 @@
     	submitdata: {
             csrfmiddlewaretoken:global_csrf_token,
             wikitag_document_id:$('#wikitag_document_id').val(),
+            wikitag_document_profile:$('#wikitag_document_profile').val(),
             num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined),
             nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined),
             sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined),
@@ -138,6 +141,7 @@
                         type: 'POST',
                         data: {csrfmiddlewaretoken:global_csrf_token, 
                                wikitag_document_id:$('#wikitag_document_id').val(),
+                               wikitag_document_profile:$('#wikitag_document_profile').val(),
                                new_order:new_order,
                                old_order:old_order
                                },
@@ -216,87 +220,97 @@
 
 function wikitag_init_search_context_events()
 {
-	// We implement the behaviour on text select. Kolich is just an object name, it could be anything
-	if(!window.Kolich){
-	    Kolich = {};
-	}
-	Kolich.Selector = {};
-	Kolich.Selector.getSelected = function(){
-	    var t = '';
-	    if(window.getSelection){
-	        t = window.getSelection();
-	    }else if(document.getSelection){
-	        t = document.getSelection();
-	    }else if(document.selection){
-	        t = document.selection.createRange().text;
-	    }
-	    return t;
-	};
-	Kolich.Selector.mouseup = function(e){
-	  var st = Kolich.Selector.getSelected();
-	  if(st!=''){
-	    // Behaviour after the text was selected
-	    $("#wikitag_context_div").offset({left:e.pageX+10,top:e.pageY});
-	    $("#wikitag_context_div").show();
-	    $("#wikitag_context_div #wikitag_wp_search_context").val(st);
-	    $("#wikitag_context_div #wikitag_wp_search_context").autocomplete("search");
-	  }
-	};
-	$(document).ready(function(){
-		for(c in reactive_selectors){
-    		$(reactive_selectors[c]).bind("mouseup", Kolich.Selector.mouseup);
-    	}
-	});
-	
-	// Function to close the context window
-	$("#wikitag_context_close").click(function(e){
-	    $("#wikitag_context_div #wikitag_wp_search_context").autocomplete("close");
-	    $("#wikitag_context_div").offset({left:0,top:0});
-	    $("#wikitag_context_div").hide();
-	});
-	
-	// Wikipedia search management (new tag)
-	$("#wikitag_wp_search_context").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
-	                    };
-	                }));
-	            }
-	        });
-	    },
-	    select: function(event, ui) { 
-	        // Since the event still did not update wp_search's val, we force it.
-	        $("#wikitag_wp_search_context").val(ui.item.label);
-	        add_tag($("#wikitag_wp_search_context").val());
-	        $("#wikitag_context_close").click();
-	    },
-	    minLength: 2,
-	    open: function() {
-	        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
-	    },
-	    close: function() {
-	        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
-	    }
-	});
-	$('#wikitag_wp_search_context').keyup(function(e){
-	    if((e.keyCode==13) && ($("#wikitag_wp_search_context").val()!="")){
-	        add_tag($("#wikitag_wp_search_context").val());
-	    }
-	});
+    // We implement the behaviour on text select. Kolich is just an object name, it could be anything
+    if(!window.Kolich){
+        Kolich = {};
+    }
+    Kolich.Selector = {};
+    Kolich.Selector.getSelected = function(){
+        var t = '';
+        if(window.getSelection){
+            t = window.getSelection();
+        }else if(document.getSelection){
+            t = document.getSelection();
+        }else if(document.selection){
+            t = document.selection.createRange().text;
+        }
+        return t;
+    };
+    Kolich.Selector.mouseup = function(e){
+      var st = Kolich.Selector.getSelected();
+      if(st!=''){
+        // Behaviour after the text was selected
+        $("#wikitag_context_div").offset({left:e.pageX+10,top:e.pageY});
+        $("#wikitag_context_div").show();
+        $("#wikitag_context_div #wikitag_wp_search_context").val(st);
+        $("#wikitag_context_div #wikitag_wp_search_context").autocomplete("search");
+      }
+    };
+    $(document).ready(function(){
+        for(c in reactive_selectors){
+            $(reactive_selectors[c]).bind("mouseup", Kolich.Selector.mouseup);
+        }
+    });
+    
+    // Function to close the context window
+    $("#wikitag_context_close").click(function(e){
+        $("#wikitag_context_div #wikitag_wp_search_context").autocomplete("close");
+        $("#wikitag_context_div").offset({left:0,top:0});
+        $("#wikitag_context_div").hide();
+    });
+    
+    // Wikipedia search management (new tag)
+    $("#wikitag_wp_search_context").autocomplete({
+        source: function( request, response ) {
+            $.ajax({
+                url: "http://fr.wikipedia.org/w/api.php",
+                dataType: "jsonp",
+                data: {
+                    action: "query",
+                    limit: "20",
+                    list: "search",
+                    format: "json",
+                    srsearch: request.term
+                },
+                success: function( data ) {
+                    response( $.map( data["query"]["search"], function( item ) {
+                    	console.log(item);
+                        return {
+                            label: item["title"],
+                            snippet: item["snippet"],
+                            value: item["title"]
+                        };
+                    }));
+                }
+            });
+        },
+        select: function(event, ui) { 
+            // Since the event still did not update wp_search's val, we force it.
+            $("#wikitag_wp_search_context").val(ui.item.label);
+            add_tag($("#wikitag_wp_search_context").val());
+            $("#wikitag_context_close").click();
+        },
+        minLength: 2,
+        open: function() {
+            $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
+            // We force width to something not too large
+            $( this ).autocomplete("widget").addClass("wikitag_context_result");
+        },
+        close: function() {
+            $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
+        }
+    });
+    $("#wikitag_wp_search_context").data("autocomplete")._renderItem = function( ul, item ) {
+        return $( "<li></li>" )
+        .data( "item.autocomplete", item )
+        .append( '<a class="wikitag_context_result_item"><span class="wikitag_context_result_title">'+ item.label + '</span> : <span class="wikitag_context_result_snippet">' + item.snippet + '</span></a>' )
+        .appendTo( ul );
+    };
+    $('#wikitag_wp_search_context').keyup(function(e){
+        if((e.keyCode==13) && ($("#wikitag_wp_search_context").val()!="")){
+            add_tag($("#wikitag_wp_search_context").val());
+        }
+    });
 }
 
 function wikitag_update_tag(btn)
@@ -324,6 +338,7 @@
         type: 'POST',
         data: {csrfmiddlewaretoken:global_csrf_token, 
                wikitag_document_id:$('#wikitag_document_id').val(),
+               wikitag_document_profile:$('#wikitag_document_profile').val(),
                num_page:(('num_page' in getUrlVars()) ? getUrlVars()['num_page'] : undefined),
                nb_by_page:(('nb_by_page' in getUrlVars()) ? getUrlVars()['nb_by_page'] : undefined),
                sort:((('sort' in getUrlVars()) && (typeof(getUrlVars()['sort'])=="string")) ? getUrlVars()['sort'] : undefined),
@@ -361,6 +376,7 @@
         type: 'POST',
         data: {csrfmiddlewaretoken:global_csrf_token, 
                wikitag_document_id:$('#wikitag_document_id').val(),
+               wikitag_document_profile:$('#wikitag_document_profile').val(),
                tag_id:id_tag,
                move:mv,
                tag_pos:pos_tag
@@ -383,6 +399,7 @@
         type: 'POST',
         data: {csrfmiddlewaretoken:global_csrf_token,
                wikitag_document_id:$('#wikitag_document_id').val(),
+               wikitag_document_profile:$('#wikitag_document_profile').val(),
                value:tag_label
                },
         // bug with jquery >= 1.5, "json" adds a callback so we don't specify dataType
@@ -414,7 +431,8 @@
 		type: 'POST',
 		data: {
 			csrfmiddlewaretoken:global_csrf_token,
-            wikitag_document_id:$('#wikitag_document_id').val()
+            wikitag_document_id:$('#wikitag_document_id').val(),
+            wikitag_document_profile:$('#wikitag_document_profile').val()
 		},
         success: function(msg, textStatus, XMLHttpRequest) {
             $('#wikitag_table_container').html(msg);
--- a/Resources/views/WikiTag/documentTags.html.twig	Sun Nov 27 22:36:21 2011 +0100
+++ b/Resources/views/WikiTag/documentTags.html.twig	Mon Nov 28 12:19:56 2011 +0100
@@ -6,6 +6,7 @@
       <span>Ajouter un tag : <input type="text" name="wikitag_wp_search" id="wikitag_wp_search" size="35" /> <span id="wikitag_ok_search" class="wikitag_hand_cursor"><b>OK</b></span></span>
     </div>
     <input type="hidden" name="wikitag_document_id" value="{{ doc_id }}" id="wikitag_document_id" />
+    <input type="hidden" name="wikitag_document_profile" value="{{ profile_name }}" id="wikitag_document_profile" />
 </div>
 <div id="wikitag_table_container" style="float:left; width: 100%">
   {% include 'WikiTagBundle:WikiTag:tagTable.html.twig' %}
--- a/Resources/views/WikiTag/tagTable.html.twig	Sun Nov 27 22:36:21 2011 +0100
+++ b/Resources/views/WikiTag/tagTable.html.twig	Mon Nov 28 12:19:56 2011 +0100
@@ -1,23 +1,54 @@
 {# partial display document's tags (table only) #}
   <table id="wikitag_table">
     <tr class="nodrop nodrag">
+  {% if columns is null or "order" in columns %}
     <th>#</th>
+  {% endif %}
+  {% if columns is null or "move_up_down" in columns %}
     <th><img src="{{ asset('bundles/wikitag/images/arrow_up_down.png') }}"/></th>
+  {% endif %}
+  {% if columns is null or "id" in columns %}
     <th>id</th>
+  {% endif %}
+  {% if columns is null or "label" in columns %}
     <th>label</th>
+  {% endif %}
+  {% if columns is null or "wikipedia_link" in columns %}
     <th class="wikitag_text_centered">Lien W</th>
+  {% endif %}
+  {% if columns is null or "wikipedia_permalink" in columns %}
     <th class="wikitag_text_centered">pLien W</th>
+  {% endif %}
+  {% if columns is null or "dbpedia_link" in columns %}
     <th class="wikitag_text_centered">Lien D</th>
+  {% endif %}
+  {% if columns is null or "category" in columns %}
     <th>Catégorie</th>
+  {% endif %}
+  {% if columns is null or "remove_wikipedia_link" in columns %}
     <th class="wikitag_large_25 wikitag_text_centered">Supprimer<br/>le lien W</th>
+  {% endif %}
+  {% if columns is null or "alias" in columns %}
     <th>Alias</th>
+  {% endif %}
+  {% if columns is null or "remove_tag_from_list" in columns %}
     <th class="wikitag_large_25 wikitag_text_centered">Retirer le tag</th></tr>
+  {% endif %}
     {% for t in ordered_tags %}
         <tr class="imageline {{ cycle(['wikitag_oddline', 'wikitag_evenline'], loop.index) }}" id="{{loop.index}}">
+      {% if columns is null or "order" in columns %}
         <td>{{loop.index}}</td>
+      {% endif  %}
+      {% if columns is null or "move_up_down" in columns %}
         <td class="wikitag_updown_td wikitag_text_centered"><img src="{{ asset('bundles/wikitag/images/arrow_up_down.png') }}" class="updown" alt="updown" id={{t.tag.id}} pos="{{loop.index0}}"></td>
+      {% endif  %}
+      {% if columns is null or "id" in columns %}
         <td>{{t.tag.id}}</td>
+      {% endif  %}
+      {% if columns is null or "label" in columns %}
         <td class="wikitag_{{t.tag.urlstatustext}} wikipediatag" id="{{t.tag.id}}" >{{t.tag.label}}</td>
+      {% endif  %}
+      {% if columns is null or "wikipedia_link" in columns %}
         <td class="wikitag_text_centered">
             {% if t.tag.wikipediaurl and t.tag.wikipediaurl != ""  %}
             <a href="{{t.tag.wikipediaurl}}" target="_blank"><img src="{{ asset('bundles/wikitag/images/arrow_right.png') }}" ></a>
@@ -25,6 +56,8 @@
             <a href="http://fr.wikipedia.org/w/index.php?search={{t.tag.label}}" target="_blank"><img src="{{ asset('bundles/wikitag/images/wikipedia_search.png') }}" ></a>
             {% endif %}
         </td>
+      {% endif  %}
+      {% if columns is null or "wikipedia_permalink" in columns %}
         <td class="wikitag_text_centered">
             {% if t.wikipediarevisionid  %}
             <a href="{{t.wikipediaversionpermalink}}" target="_blank"><img src="{{ asset('bundles/wikitag/images/clock_arrow.png') }}" ></a>
@@ -32,6 +65,8 @@
             &nbsp;
             {% endif %}
         </td>
+      {% endif  %}
+      {% if columns is null or "dbpedia_link" in columns %}
         <td class="wikitag_text_centered">
             {% if t.tag.dbpediauri and t.tag.dbpediauri != ""  %}
             <a href="{{t.tag.dbpediauri}}" target="_blank"><img src="{{ asset('bundles/wikitag/images/arrow_green_right.png') }}" ></a>
@@ -39,9 +74,18 @@
             &nbsp;
             {% endif %}
         </td>
+      {% endif  %}
+      {% if columns is null or "category" in columns %}
         <td class="wikitag_category" id="{{t.tag.id}}">{% if t.tag.category %}{{ t.tag.category.label }}{% endif %}</td>
+      {% endif  %}
+      {% if columns is null or "remove_wikipedia_link" in columns %}
         <td class="wikitag_text_centered"><img src="{{ asset('bundles/wikitag/images/red_cross.png') }}" class="wikitag_remove_wp_link" id="{{t.tag.id}}" alt="{{t.tag.label}}" /></td>
+      {% endif  %}
+      {% if columns is null or "alias" in columns %}
         <td>{% if t.tag.alias %}{{t.tag.alias}}{% endif %}</td>
+      {% endif  %}
+      {% if columns is null or "remove_tag_from_list" in columns %}
         <td class="wikitag_text_centered"><img src="{{ asset('bundles/wikitag/images/tag_remove.png') }}" class="wikitag_remove_tag_from_list" id="{{t.tag.id}}" alt="{{t.tag.label}}" /></td></tr>
+      {% endif  %}
     {% endfor %}
   </table>