From 0f8ca11e1375bbc76ba1da0b6d1b4448ab5cf70e Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 27 Feb 2011 16:58:49 +0100 Subject: [PATCH] Support admin: links. Signed-off-by: Florent Bruneau --- htdocs/javascript/xorg.js | 41 ++++++++++++++++++++++++++--------------- modules/api.php | 22 ++++++++++++++++++++-- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/htdocs/javascript/xorg.js b/htdocs/javascript/xorg.js index 2f80860..55e43fe 100644 --- a/htdocs/javascript/xorg.js +++ b/htdocs/javascript/xorg.js @@ -871,7 +871,7 @@ function sendTestEmail(token, hruid) '
' + '
${directory_name}
' + '
' + - '{{if is_female}}•{{/if}}${directory_name}' + + '{{if is_female}}•{{/if}}${directory_name}' + '
' + '
${promo}
' + '
' + @@ -993,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; @@ -1038,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(); }); + 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; @@ -1071,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') { diff --git a/modules/api.php b/modules/api.php index 0df1ae8..dd0bf04 100644 --- a/modules/api.php +++ b/modules/api.php @@ -56,12 +56,30 @@ class ApiModule extends PlModule $page->trigError('Malformed search query'); return PL_BAD_REQUEST; } - if (strlen(trim($payload['quick'])) < 3) { + + $query = trim($payload['quick']); + if (@$payload['allow_special']) { + if (starts_with($query, 'admin:')) { + $page->jsonAssign('link_type', 'admin'); + $query = substr($query, 6); + } else if (starts_with($query, 'adm:')) { + $page->jsonAssign('link_type', 'admin'); + $query = substr($query, 4); + } else if (starts_with('admin', $query) || strpos($query, ':') !== false) { + $page->jsonAssign('profile_count', -1); + $page->jsonAssign('profiles', array()); + return PL_JSON; + } else { + $page->jsonAssign('link_type', 'profile'); + } + } + if (strlen($query) < 3) { $page->jsonAssign('profile_count', -1); $page->jsonAssign('profiles', array()); return PL_JSON; } - Env::set('quick', $payload['quick']); + + Env::set('quick', $query); foreach (array('with_soundex', 'exact') as $key) { if (isset($payload[$key])) { Env::set($key, $payload[$key]); -- 2.1.4