use attr instead of cat field for search suggestion type

This commit is contained in:
Chris Van 2011-11-21 14:23:03 -05:00
Родитель 696cee752b
Коммит e1f0a0691a
4 изменённых файлов: 16 добавлений и 13 удалений

Просмотреть файл

@ -368,15 +368,17 @@ def ajax_search_suggestions(request):
})
# Categories.
cats = (Category.objects
.filter(Q(application=request.APP.id) |
Q(type=amo.ADDON_SEARCH)))
if cat == 'personas':
cats = cats.filter(type=amo.ADDON_PERSONA)
elif cat == 'apps':
cats = Category.objects
if cat == 'apps':
cats = cats.filter(type=amo.ADDON_WEBAPP)
else:
cats = cats.exclude(type__in=[amo.ADDON_PERSONA, amo.ADDON_WEBAPP])
cats = cats.filter(Q(application=request.APP.id) |
Q(type=amo.ADDON_SEARCH))
if cat == 'personas':
cats = cats.filter(type=amo.ADDON_PERSONA)
else:
cats = cats.exclude(type__in=[amo.ADDON_PERSONA,
amo.ADDON_WEBAPP])
for c in cats:
if not c.name:

Просмотреть файл

@ -18,17 +18,16 @@ $.fn.highlightTerm = function(val) {
};
$.fn.searchSuggestions = function(results) {
$.fn.searchSuggestions = function($results) {
var $self = this,
$form = $self.closest('form'),
$results = results;
$form = $self.closest('form');
if (!$results.length) {
return;
}
// Some base elements that we don't want to keep creating on the fly.
var cat = $form.find('input[name=cat]').val(),
var cat = $results.attr('data-cat'),
msg;
if (cat == 'personas') {
msg = gettext('Search personas for <b>{0}</b>');
@ -147,8 +146,8 @@ $.fn.searchSuggestions = function(results) {
);
$.ajaxCache({
url: $results.attr('data-src'),
data: $form.serialize(),
url: $form.serialize() + '&cat=' + cat,
data: fields,
newItems: function(formdata, items) {
var eventName;
if (items !== undefined) {

Просмотреть файл

@ -19,6 +19,7 @@
src="{{ media('img/zamboni/global/btn-search.png') }}"></button>
{% if search_cat != 'collections' and waffle.switch('search-suggestions') %}
<div id="site-search-suggestions"
data-cat="{{ search_placeholder or search_cat }}"
data-src="{{ url('search.suggestions') }}"></div>
{% endif %}
</form>

Просмотреть файл

@ -13,6 +13,7 @@
src="{{ media('img/zamboni/global/btn-search.png') }}">
{% if search_cat != 'collections' and waffle.switch('search-suggestions') %}
<div id="site-search-suggestions"
data-cat="{{ search_placeholder or search_cat }}"
data-src="{{ url('search.suggestions') }}"></div>
{% endif %}
</form>