Merge branch 'xorg/master' into xorg/f/xnet-accounts
[platal.git] / htdocs / javascript / xorg.js
index e808504..4837da9 100644 (file)
@@ -132,16 +132,17 @@ function addSearchEngine()
             var s_img;
             var s_title;
             var s_url;
+            var href = this.attr('href');
 
             for (site in goodies[type].sites) {
                 entry = goodies[type].sites[site];
                 s_alt   = entry.alt || "";
                 s_img   = entry.img;
                 s_title = entry.title || "";
-                s_url   = entry.url_prefix.length > 0 ? entry.url_prefix + escape(this.href) : this.href;
+                s_url   = entry.url_prefix.length > 0 ? entry.url_prefix + escape(href) : href;
 
                 text += '<a href="' + s_url + '"><img src="' + s_img + '" title="' + s_title + '" alt="' + s_alt + '"></a><br />';
-                }
+            }
             text += '<a href="https://www.polytechnique.org/Xorg/Goodies">Plus de bonus</a> ...</div>';
 
             return this.overlib({
@@ -871,7 +872,7 @@ function sendTestEmail(token, hruid)
                 '<div class="identity">' +
                     '<div class="photo"><img src="photo/${hrpid}" alt="${directory_name}" /></div>' +
                     '<div class="nom">' +
-                        '{{if is_female}}&bull;{{/if}}<a href="profile/${hrpid}">${directory_name}</a>' +
+                        '{{if is_female}}&bull;{{/if}}<a>${directory_name}</a>' +
                     '</div>' +
                     '<div class="edu">${promo}</div>' +
                 '</div>' +
@@ -882,9 +883,9 @@ function sendTestEmail(token, hruid)
 
     function buildPopup(input, destination, linkBindFunction)
     {
-        var pos    = findPos(input.get(0));
         var $popup = destination;
         var selected = null;
+        var hovered  = 0;
 
         function updateSelection()
         {
@@ -902,24 +903,25 @@ function sendTestEmail(token, hruid)
 
         function formatProfile(i, profile) {
             var data = $.tmpl('quickMinifiche', profile)
+                .css('cursor', 'pointer')
                 .hover(function() {
                     selected = i;
                     updateSelection();
+                    hovered++;
                 }, function() {
                     if (selected === i) {
                         selected = null;
                         updateSelection();
                     }
+                    hovered--;
                 }).mouseup(function() {
                     var sel = $(this).find('a');
-                    try {
-                        if (!sel.is(':hover')) {
-                            sel.click();
-                        }
-                    } catch (e) {
+                    if (!sel.attr('hovered')) {
                         sel.click();
                     }
                 });
+            data.find('a').hover(function() { $(this).attr('hovered', true) },
+                                 function() { $(this).attr('hovered', false) });
             return data;
         }
 
@@ -930,7 +932,6 @@ function sendTestEmail(token, hruid)
                 position: 'absolute',
                 width: '300px',
                 top: input.css('bottom'),
-                left: pos.x - 300 + input.width(),
                 clear: 'both',
                 'text-align': 'left'
             });
@@ -939,7 +940,7 @@ function sendTestEmail(token, hruid)
 
         return {
             hide: function(ignoreIfHover) {
-                if (ignoreIfHover && $popup.is(':hover')) {
+                if (ignoreIfHover && hovered !== 0) {
                     return true;
                 }
                 selected = null;
@@ -949,7 +950,8 @@ function sendTestEmail(token, hruid)
             },
 
             show: function() {
-                $popup.show();
+                var pos = findPos(input.get(0));
+                $popup.css('left', pos.x - 300 + input.width()).show();
                 return true;
             },
 
@@ -991,13 +993,18 @@ function sendTestEmail(token, hruid)
                 return true;
             },
 
-            updateContent: function(profiles) {
+            updateContent: function(profiles, extra) {
                 var profile;
+                var $this;
                 $popup.empty();
                 for (var i = 0, len = profiles.length; i < len; i++) {
-                    profile = formatProfile(i, profiles[i]);
-                    profile.find('a').each(linkBindFunction);
-                    profile.appendTo($popup);
+                    (function(elt) {
+                        var profile = formatProfile(i, elt);
+                        profile.find('a').each(function() {
+                            linkBindFunction.call(this, elt, $this, extra);
+                        });
+                        profile.appendTo($popup);
+                    }(profiles[i]));
                 }
                 if (len === 1) {
                     selected = 0;
@@ -1036,23 +1043,29 @@ function sendTestEmail(token, hruid)
                 queryParams:       {
                     offset: 0,
                     count:  10,
+                    allow_special: true,
                 },
                 loadingClassLeft:  'ac_loading',
                 loadingClassRight: 'ac_loading_left',
-                selectAction: function() {
-                    $(this).popWin(840, 600);
+                selectAction: function(profile, popup, extra) {
+                    var type = extra.link_type || 'profile';
+                    switch (type) {
+                      case 'profile':
+                        $(this).attr('href', 'profile/' + profile.hrpid)
+                        .popWin(840, 600)
+                        .click(function() { $popup.hide(); return false; });
+                        break;
+                      case 'admin':
+                        $(this).attr('href', 'admin/user/' + profile.hrpid)
+                        .click(function() { window.open($(this).attr('href')); return false });
+                        break;
+                    }
                 }
             }, options);
             options.loadingClass = $this.css('text-align') === 'right' ? options.loadingClassRight
                                                                        : options.loadingClassLeft;
             $this.attr('autocomplete', 'off');
-
-            $popup = buildPopup($this, options.destination, function() {
-                options.selectAction.apply(this, arguments);
-                $(this).click(function() {
-                    $popup.hide();
-                });
-            });
+            $popup = buildPopup($this, options.destination, options.selectAction);
 
             function markPending() {
                 pending = true;
@@ -1069,7 +1082,7 @@ function sendTestEmail(token, hruid)
                     if (data.profile_count > options.queryParams.count || data.profile_count < 0) {
                         return $popup.hide();
                     }
-                    $popup.updateContent(data.profiles);
+                    $popup.updateContent(data.profiles, data);
                     previous = quick;
                 }, function(data, text) {
                     if (text !== 'abort') {