First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
authorcavaliet
Tue, 15 Nov 2011 12:27:02 +0100
changeset 33 6c87166b819c
parent 32 38dcd2db04e4
child 35 92ddb5488eb4
First step to add context search to a page. Works fine but needs to be improved with several list of selectors.
Controller/WikiTagController.php
DependencyInjection/Configuration.php
DependencyInjection/WikiTagExtension.php
Resources/public/css/wikiTag.css
Resources/public/js/wikiTag.js
Resources/views/WikiTag/javascript.html.twig
Resources/views/WikiTag/javascriptForContextSearch.html.twig
--- a/Controller/WikiTagController.php	Thu Nov 10 12:40:22 2011 +0100
+++ b/Controller/WikiTagController.php	Tue Nov 15 12:27:02 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));
     }
 
     /**
--- a/DependencyInjection/Configuration.php	Thu Nov 10 12:40:22 2011 +0100
+++ b/DependencyInjection/Configuration.php	Tue Nov 15 12:27:02 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 10 12:40:22 2011 +0100
+++ b/DependencyInjection/WikiTagExtension.php	Tue Nov 15 12:27:02 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/public/css/wikiTag.css	Thu Nov 10 12:40:22 2011 +0100
+++ b/Resources/public/css/wikiTag.css	Tue Nov 15 12:27:02 2011 +0100
@@ -91,26 +91,10 @@
 #wikitag_context_div {
     width: 260px;
     border: 2px;
-    background: lightgreen;
+    background: #97fefd;
     display: none;
     float: none;
     position: absolute;
 }
 
 
-
-/*
-
-
-#count_nav_top,
-#count_nav_bottom {
-	text-align: right;
-}
-#count_nav_bottom p,
-#count_nav_top p {
-	font-size: 12px;
-	font-weight : bold;
-}
-
-
-*/
--- a/Resources/public/js/wikiTag.js	Thu Nov 10 12:40:22 2011 +0100
+++ b/Resources/public/js/wikiTag.js	Tue Nov 15 12:27:02 2011 +0100
@@ -243,7 +243,9 @@
 	  }
 	}
 	$(document).ready(function(){
-	    $(document).bind("mouseup", Kolich.Selector.mouseup);
+		for(c in reactive_selectors){
+    		$(reactive_selectors[c]).bind("mouseup", Kolich.Selector.mouseup);
+    	}
 	});
 	
 	// Function to close the context window
--- a/Resources/views/WikiTag/javascript.html.twig	Thu Nov 10 12:40:22 2011 +0100
+++ b/Resources/views/WikiTag/javascript.html.twig	Tue Nov 15 12:27:02 2011 +0100
@@ -29,10 +29,5 @@
     $(document).ready(function(){
         wikitag_init_tags_events();
         wikitag_init_datasheet_events();
-    	
-    {% if tags_list!=true %}
-        wikitag_init_search_context_events();        
- 	{% endif %}
-    	
     });
 </script>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Resources/views/WikiTag/javascriptForContextSearch.html.twig	Tue Nov 15 12:27:02 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