From c1d9133451a642c47708780def02c9bb804ef8d7 Mon Sep 17 00:00:00 2001 From: Matchu Date: Wed, 2 Apr 2014 14:53:58 -0500 Subject: [PATCH] add an item search form to closet so that new users will be less stumped --- app/assets/javascripts/outfits/edit.js | 26 ++++++++++------------- app/assets/stylesheets/outfits/_edit.sass | 10 +++++++-- app/views/outfits/edit.html.haml | 10 +++++++-- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/outfits/edit.js b/app/assets/javascripts/outfits/edit.js index 2be4b368..4e40f279 100644 --- a/app/assets/javascripts/outfits/edit.js +++ b/app/assets/javascripts/outfits/edit.js @@ -1071,8 +1071,8 @@ View.ReportBrokenImage = function (wardrobe) { } View.Search = function (wardrobe) { - var form_selector = '#preview-search-basic', form = $(form_selector), - item_set = new Partial.ItemSet(wardrobe, form_selector + ' ul'), + var form = $('form.item-search'), + item_set = new Partial.ItemSet(wardrobe, '#preview-search-basic ul'), input_el = form.find('input[name=query]'), clear_el = $('#preview-search-form-clear'), error_el = $('#preview-search-form-error'), @@ -1080,7 +1080,6 @@ View.Search = function (wardrobe) { loading_el = $('#preview-search-form-loading'), no_results_el = $('#preview-search-form-no-results'), no_results_span = no_results_el.children('span'), - your_items_links = $('.preview-search-form-your-items'), wrapper = $('#preview-search'), PAGINATION = { INNER_WINDOW: 4, @@ -1088,7 +1087,8 @@ View.Search = function (wardrobe) { EL_ID: '#preview-search-form-pagination', PER_PAGE: 21, TEMPLATE: $('#pagination-template') - }, object_width = 112, last_request; + }, object_width = 112, last_request, + current_query = ""; PAGINATION.EL = $(PAGINATION.EL_ID); @@ -1102,7 +1102,7 @@ View.Search = function (wardrobe) { wardrobe.search.setPerPage(PAGINATION.PER_PAGE); function updatePerPage() { - var new_per_page = Math.floor(form.width() / object_width), + var new_per_page = Math.floor(wrapper.width() / object_width), offset, new_page; if(!$(document.body).hasClass('fullscreen')) new_per_page *= 4; if(new_per_page != PAGINATION.PER_PAGE) { @@ -1117,11 +1117,11 @@ View.Search = function (wardrobe) { updatePerPage(); function loadOffset(offset) { - wardrobe.search.setItemsByQuery(input_el.val(), {offset: offset}); + wardrobe.search.setItemsByQuery(current_query, {offset: offset}); } function loadPage(page) { - wardrobe.search.setItemsByQuery(input_el.val(), {page: page}); + wardrobe.search.setItemsByQuery(current_query, {page: page}); } function stopLoading() { @@ -1130,6 +1130,7 @@ View.Search = function (wardrobe) { form.submit(function (e) { e.preventDefault(); + current_query = $(this).find('input[name=query]').val(); loadPage(1); }); @@ -1139,12 +1140,6 @@ View.Search = function (wardrobe) { form.submit(); }); - your_items_links.click(function (e) { - e.preventDefault(); - input_el.val('user:' + this.getAttribute('data-search-value')); - form.submit(); - }); - wardrobe.search.bind('startRequest', function () { loading_el.delay(1000).show('slow'); }); @@ -1169,8 +1164,9 @@ View.Search = function (wardrobe) { error_el.hide('fast'); help_el.hide(); no_results_el.hide(); - input_el.val(request.query || ''); - no_results_span.text(request.query); + current_query = request.query || ''; + input_el.val(current_query); + no_results_span.text(current_query); clear_el.toggle(!!request.query); }); diff --git a/app/assets/stylesheets/outfits/_edit.sass b/app/assets/stylesheets/outfits/_edit.sass index 719325bd..42691306 100644 --- a/app/assets/stylesheets/outfits/_edit.sass +++ b/app/assets/stylesheets/outfits/_edit.sass @@ -200,8 +200,6 @@ body.outfits-edit .sidebar-view margin: 1.5em 0 #preview-closet - h2 - margin-bottom: 0 ul text-align: center .object @@ -218,6 +216,14 @@ body.outfits-edit padding-bottom: 1.25em .no-assets-message display: block + .item-search + font-size: 85% + margin-bottom: 1em + text-align: center + + span + font-weight: bold + margin-right: 1em .no-assets-message background: $error-bg-color - #080808 bottom: 0 diff --git a/app/views/outfits/edit.html.haml b/app/views/outfits/edit.html.haml index a0e18200..707e4fe3 100644 --- a/app/views/outfits/edit.html.haml +++ b/app/views/outfits/edit.html.haml @@ -49,6 +49,12 @@ #save-error #preview-closet.sidebar-view = prank_color_message(''.html_safe, '$artist-name', '$artist-url') + %form.item-search + %label + -# TODO: i18n + %span Add an item + %input{type: 'text', name: 'query'} + %button{type: 'submit'} Search %ul #preview-outfits.sidebar-view %ul#preview-outfits-list @@ -93,10 +99,10 @@ %li{'data-format' => 'bbcode'} =t '.sidebar.sharing.formats.bbcode' #preview-search - %form#preview-search-basic + %form#preview-search-basic.item-search %header %h2= t '.search.header' - %input{:name => "query", :placeholder => t('.search.form.query_placeholder'), :type => "search"}/ + %input{:name => "query", :type => "search"}/ %input{:type => "submit", :value => t('.search.form.submit')}/ -# TODO: i18n %a#preview-search-advanced-link{href: 'javascript:void(0)'} Advanced Search