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. # Categories.
cats = (Category.objects cats = Category.objects
.filter(Q(application=request.APP.id) | if cat == 'apps':
Q(type=amo.ADDON_SEARCH)))
if cat == 'personas':
cats = cats.filter(type=amo.ADDON_PERSONA)
elif cat == 'apps':
cats = cats.filter(type=amo.ADDON_WEBAPP) cats = cats.filter(type=amo.ADDON_WEBAPP)
else: 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: for c in cats:
if not c.name: if not c.name:

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

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

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

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

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

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