Upgrade jQuery to 1.5.1
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 25 Feb 2011 18:35:34 +0000 (19:35 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 25 Feb 2011 18:35:34 +0000 (19:35 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
Makefile
include/userset.inc.php
modules/api.php
templates/events/index.tpl

index e65111c..13b07fe 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -182,7 +182,7 @@ $(MEDAL_THUMBNAILS): $(subst /medals/thumb/,/medals/,$(@F))
 ##
 ## jquery
 ##
-JQUERY_VERSION=1.5
+JQUERY_VERSION=1.5.1
 JQUERY_PLUGINS=color form
 JQUERY_PLUGINS_PATHES=$(addprefix htdocs/javascript/jquery.,$(addsuffix .js,$(JQUERY_PLUGINS)))
 
index bafddd3..e6e636e 100644 (file)
@@ -355,5 +355,30 @@ class AddressesView implements PlView
     }
 }
 
+class JSonView implements PlView
+{
+    private $set;
+
+    public function __construct(PlSet $set, array $params)
+    {
+        $this->set = $set;
+    }
+
+    public function apply(PlPage $page)
+    {
+        $export = array();
+        $profiles = $this->set->get(new PlLimit());
+        while ($profile = $profiles->next()) {
+            $export[] = $profile->export();
+        }
+        $page->jsonAssign('profiles', $export);
+    }
+
+    public function args()
+    {
+        return $this->set->args();
+    }
+}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
index 1fa485f..5caedbf 100644 (file)
@@ -26,13 +26,14 @@ class ApiModule extends PlModule
         return array(
             // TODO(vzanotti): Extend the plat/al engine to support placeholders
             // in handler urls, for instance "api/1/user/%forlife/isRegistered".
-            'api/1/user' => $this->make_api_hook('user', AUTH_COOKIE, 'api_user_readonly'),
+            'api/1/user'   => $this->make_api_hook('user', AUTH_COOKIE, 'api_user_readonly'),
+            'api/1/search' => $this->make_api_hook('search', AUTH_COOKIE),
         );
     }
 
     // This handler supports the following URL patterns:
     //   /api/1/user/{forlife}/isRegistered
-    function handler_user(PlPage& $page, PlUser& $authUser, $payload, $user = null, $selector = null)
+    function handler_user(PlPage $page, PlUser $authUser, $payload, $user = null, $selector = null)
     {
         // Retrieve the PlUser referenced in the request. Note that this is the
         // target user, not the authenticated user.
@@ -48,6 +49,26 @@ class ApiModule extends PlModule
             return PL_NOT_FOUND;
         }
     }
+
+    function handler_search(PlPage $page, PlUser $authUser, $payload, $mode = 'quick')
+    {
+        if (!isset($payload['quick'])) {
+            $page->trigError('Malformed search query');
+            return PL_BAD_REQUEST;
+        }
+        Env::set('quick', $payload['quick']);
+        foreach (array('with_soundex', 'exact') as $key) {
+            if (isset($payload[$key])) {
+                Env::set($key, $payload[$key]);
+            }
+        }
+
+        require_once 'userset.inc.php';
+        $view = new QuickSearchSet();
+        $view->addMod('json', 'JSon', true, array('with_score' => true, 'starts_with' => $byletter));
+        $view->apply('api/1/search', $page, 'json');
+        return PL_JSON;
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
index 563f0d0..c151e9e 100644 (file)
@@ -208,6 +208,19 @@ Bienvenue {$smarty.session.user->displayName()}{if t($birthday)}
   </p>
 
   <p class="center">
+    <a id="blah">Blah  </a>
+
+    <script type="text/javascript">//<![CDATA[
+      {literal}
+      $($("#blah").click(function() {
+        $.xapi('1/search?token={/literal}{$smarty.session.xsrf_token}{literal}',
+               { 'quick': 'fruneau' },
+               function(data) { alert(JSON.stringify(data)); });
+        return false;
+      }));
+      {/literal}
+    //]]></script>
+
     {icon name=page_edit}&nbsp;
     <a href="events/submit">Proposer une information événementielle</a>&nbsp;&bull;
     <a href="nl/submit">Proposer un article pour la Lettre mensuelle</a>