--- a/Controller/WikiTagController.php Thu Nov 17 11:29:26 2011 +0100
+++ b/Controller/WikiTagController.php Thu Nov 17 11:37:05 2011 +0100
@@ -59,7 +59,20 @@
}
// ... so we create is json like {"":""},{"Créateur":"Créateur"},{"Datation":"Datation"},...
$categories = json_encode($ar);
- return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', array('categories' => $categories,'tags_list' => $tags_list));
+ return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', array('categories' => $categories, 'tags_list' => $tags_list));
+ }
+
+ /**
+ * Renders the little html to add the javascript for context search
+ */
+ public function addJavascriptForContextSearchAction($context_name)
+ {
+ // WARNING : PREREQUISITE : the request to add a tag needs the external document id,
+ // which is gotten by the jQuery call $('#wikitag_document_id').val() in the page.
+ // So the page holding this context search MUST have a input value with this id.
+ // We add the reactive selectors
+ $reactive_selectors = $this->container->getParameter("wiki_tag.reactive_selectors");
+ return $this->render('WikiTagBundle:WikiTag:javascriptForContextSearch.html.twig', array('reactive_selectors' => $reactive_selectors));
}
/**
@@ -151,7 +164,7 @@
$i = 0;
while($i<$nb_tags && $found==false){
$dt = $tags[$i];
- if(strtolower($dt->getTag()->getLabel())==strtolower($tag_label)){
+ if($dt->getTag()->getLabel()==$tag_label){
$found = true;
}
$i++;
@@ -161,7 +174,7 @@
return new Response(json_encode(array('error' => 'duplicate_tag', 'message' => sprintf("Le tag %s existe déjà pour cette fiche.", $tag_label))),400);
}
// We create the new tag or get the already existing tag. $tag, $revision_id, $created
- $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());// tag, revision_id, created = get_or_create_tag(tag_label)
+ $ar = WikiTagUtils::getOrCreateTag($tag_label, $this->getDoctrine());
$tag = $ar[0];
$revision_id = $ar[1];
$created = $ar[2];
@@ -188,9 +201,9 @@
$doc->setManualOrder(true);
// We save the datas
$em->flush();
- // We render the document's tags
- return $this->renderDocTags($id_doc);
}
+ // We render the document's tags
+ return $this->renderDocTags($id_doc);
}
--- a/DependencyInjection/Configuration.php Thu Nov 17 11:29:26 2011 +0100
+++ b/DependencyInjection/Configuration.php Thu Nov 17 11:37:05 2011 +0100
@@ -23,6 +23,7 @@
$rootNode
->children()
->scalarNode('route_for_documents_by_tag')->defaultNull()->end()
+ ->scalarNode('reactive_selectors')->defaultNull()->end()
->scalarNode('document_class')->isRequired()->end()
->scalarNode('document_id_column')->defaultValue('id')->end()
->end()
--- a/DependencyInjection/WikiTagExtension.php Thu Nov 17 11:29:26 2011 +0100
+++ b/DependencyInjection/WikiTagExtension.php Thu Nov 17 11:37:05 2011 +0100
@@ -45,5 +45,6 @@
$fields['tagsStr'] = array("type"=>"text");
$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']);
}
}
--- a/Resources/config/doctrine/DocumentTag.orm.yml Thu Nov 17 11:29:26 2011 +0100
+++ b/Resources/config/doctrine/DocumentTag.orm.yml Thu Nov 17 11:37:05 2011 +0100
@@ -20,6 +20,7 @@
wikipediaRevisionId:
type: bigint
column: wikipedia_revision_id
+ nullable: true
manyToOne:
tag:
targetEntity: Tag
--- a/Resources/public/css/wikiTag.css Thu Nov 17 11:29:26 2011 +0100
+++ b/Resources/public/css/wikiTag.css Thu Nov 17 11:37:05 2011 +0100
@@ -86,18 +86,15 @@
padding: 3px;
}
-/*
-
-#count_nav_top,
-#count_nav_bottom {
- text-align: right;
-}
-#count_nav_bottom p,
-#count_nav_top p {
- font-size: 12px;
- font-weight : bold;
+/* Styles for hidden context div, displayed on text selected */
+#wikitag_context_div {
+ width: 260px;
+ border: 2px;
+ background: #97fefd;
+ display: none;
+ float: none;
+ position: absolute;
}
-*/
--- a/Resources/public/js/wikiTag.js Thu Nov 17 11:29:26 2011 +0100
+++ b/Resources/public/js/wikiTag.js Thu Nov 17 11:37:05 2011 +0100
@@ -214,6 +214,91 @@
});
}
+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());
+ }
+ });
+}
+
function wikitag_update_tag(btn)
{
new_checked = false;
--- a/Resources/views/WikiTag/TagList.html.twig Thu Nov 17 11:29:26 2011 +0100
+++ b/Resources/views/WikiTag/TagList.html.twig Thu Nov 17 11:37:05 2011 +0100
@@ -21,9 +21,6 @@
<a href="?num_page={{last_page}}&nb_by_page={{nb_by_page}}&sort={{sort}}">>></a></p>
{% endif %}</p>
</div>
-{#<input type="hidden" name="num_page" value="{{num_page}}" id="num_page" />
-<input type="hidden" name="nb_by_page" value="{{nb_by_page}}" id="nb_by_page" />
-<input type="hidden" name="sort" value="{% if sort %}{{sort}}{% endif %}" id="sort" />#}
</form>
<div id="wikitag_table_container">
{% include "WikiTagBundle:WikiTag:TagListTable.html.twig" %}
--- a/Resources/views/WikiTag/documentTags.html.twig Thu Nov 17 11:29:26 2011 +0100
+++ b/Resources/views/WikiTag/documentTags.html.twig Thu Nov 17 11:37:05 2011 +0100
@@ -10,4 +10,8 @@
<div id="wikitag_table_container" style="float:left; width: 100%">
{% include 'WikiTagBundle:WikiTag:tagTable.html.twig' %}
</div>
+<div id="wikitag_context_div">
+<p>Choisissez le tag à ajouter<span style="float:right" class="wikitag_hand_cursor" id="wikitag_context_close" ><b>X</b></p>
+<p><input type="text" name="wikitag_wp_search_context" id="wikitag_wp_search_context" size="35" /></p>
+</div>
{% endblock %}
--- a/Resources/views/WikiTag/javascript.html.twig Thu Nov 17 11:29:26 2011 +0100
+++ b/Resources/views/WikiTag/javascript.html.twig Thu Nov 17 11:37:05 2011 +0100
@@ -27,7 +27,7 @@
var categories_list = '{{ categories|raw }}';
$(document).ready(function(){
- wikitag_init_tags_events();
- wikitag_init_datasheet_events();
+ wikitag_init_tags_events();
+ wikitag_init_datasheet_events();
});
</script>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/views/WikiTag/javascriptForContextSearch.html.twig Thu Nov 17 11:37:05 2011 +0100
@@ -0,0 +1,8 @@
+{# partial display to add the needed Javascript for context search #}
+{# We suppose the all the JS (jquery and stuffs and wikiTag.js) have already been loaded. See javascript.html.twig #}
+<script type="text/javascript">
+ var reactive_selectors = [{{ reactive_selectors|raw }}];
+ $(document).ready(function(){
+ wikitag_init_search_context_events();
+ });
+</script>
\ No newline at end of file
--- a/Utils/WikiTagUtils.php Thu Nov 17 11:29:26 2011 +0100
+++ b/Utils/WikiTagUtils.php Thu Nov 17 11:37:05 2011 +0100
@@ -38,6 +38,7 @@
}
}
}
+ $wp_request_done = false;
if($tag==null){
$tag = new Tag();
$tag->setLabel($tag_label_normalized);
@@ -47,11 +48,35 @@
}
else{
$created = false;
+ $match_exists = false;
+ // Even if a tag with the normalised label exists, IF this tag is not wikipedia semantised,
+ // we search if a wikipedia semantised version exists in the base
+ foreach ($tags as $t){
+ if($t->getUrlStatus()==Tag::$TAG_URL_STATUS_DICT['match']){
+ $tag = $t;
+ $match_exists = true;
+ break;
+ }
+ }
+ if($match_exists==false){
+ $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
+ $status = $wp_response['status'];
+ if($status==Tag::$TAG_URL_STATUS_DICT['match']){
+ $tag = new Tag();
+ $tag->setLabel($tag_label_normalized);
+ $tag->setOriginalLabel($tag_label);
+ $tag->setNormalizedLabel($tag_label_normalized);
+ $created = true;
+ $wp_request_done = true;
+ }
+ }
}
// We request Wikipedia if the tag is created
if($created==true){
- $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
+ if($wp_request_done==false){
+ $wp_response = WikiTagUtils::getWikipediaInfo($tag_label_normalized);
+ }
$new_label = $wp_response['new_label'];
$status = $wp_response['status'];
$url = $wp_response['wikipedia_url'];
@@ -83,7 +108,6 @@
else{
$wikipedia_revision_id = null;
}
- //return "coucou4";
return array($tag, $wikipedia_revision_id, $created);//, $wpReponse);
}