From 8c9dda37d59685d23dfde1e21ca9491ddd2792f1 Mon Sep 17 00:00:00 2001 From: Matchu Date: Thu, 3 Jan 2013 13:25:14 -0500 Subject: [PATCH] i18n for closet_hangers#index search bar autocomplete --- app/views/closet_hangers/index.html.haml | 20 ++- config/locales/en-meep.yml | 6 + config/locales/en.yml | 6 + public/javascripts/closet_hangers/index.js | 165 +++++++++++---------- 4 files changed, 116 insertions(+), 81 deletions(-) diff --git a/app/views/closet_hangers/index.html.haml b/app/views/closet_hangers/index.html.haml index 6fb56f24..2d68af13 100644 --- a/app/views/closet_hangers/index.html.haml +++ b/app/views/closet_hangers/index.html.haml @@ -73,11 +73,29 @@ = render_unlisted_closet_hangers(owned) %span.empty-list= t '.unlisted.empty' +- localized_cache :action_suffix => 'autocomplete_tmpls' do + %script#autocomplete-item-tmpl{:type => 'text/x-jquery-tmpl'} + %a + = t '.autocomplete.add_item_html', :item_name => '${item_name}' + + %script#autocomplete-add-to-list-tmpl{:type => 'text/x-jquery-tmpl'} + %a + = t '.autocomplete.add_to_list_html', :list_name => '${list_name}' + + %script#autocomplete-add-to-group-tmpl{:type => 'text/x-jquery-tmpl'} + %a + = t '.autocomplete.add_to_group_html', :group_name => '${group_name}' + + %script#autocomplete-already-in-collection-tmpl{:type => 'text/x-jquery-tmpl'} + %span + = t '.autocomplete.already_in_collection_html', + :collection_name => '${collection_name}' + - content_for :stylesheets do = stylesheet_link_tag 'south-street/jquery-ui' - content_for :javascripts do - = include_javascript_libraries :jquery + = include_javascript_libraries :jquery, :jquery_tmpl = javascript_include_tag 'ajax_auth', 'jquery.ui', 'jquery.jgrowl', 'placeholder', 'closet_hangers/index' diff --git a/config/locales/en-meep.yml b/config/locales/en-meep.yml index 2ed67406..6b147421 100644 --- a/config/locales/en-meep.yml +++ b/config/locales/en-meep.yml @@ -117,6 +117,12 @@ en-meep: submit: Meep header: (Not in a meepit) empty: There aren't any meepits here. + autocomplete: + add_item_html: Meep %{item_name} + add_to_list_html: Meep to %{list_name} + add_to_group_html: Meep to %{group_name}, no list + already_in_collection_html: + It's already meeped in %{collection_name} petpage: title: Export to meeppage diff --git a/config/locales/en.yml b/config/locales/en.yml index f4797888..9f582407 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -118,6 +118,12 @@ en: submit: Save header: (Not in a list) empty: There aren't any items here. + autocomplete: + add_item_html: Add %{item_name} + add_to_list_html: Add to %{list_name} + add_to_group_html: Add to %{group_name}, no list + already_in_collection_html: + It's already in %{collection_name} petpage: title: Export to petpage diff --git a/public/javascripts/closet_hangers/index.js b/public/javascripts/closet_hangers/index.js index fda15b2a..dc8a489e 100644 --- a/public/javascripts/closet_hangers/index.js +++ b/public/javascripts/closet_hangers/index.js @@ -19,36 +19,36 @@ var hangerGroups = []; - $('div.closet-hangers-group').each(function () { - var el = $(this); - var lists = []; + $('div.closet-hangers-group').each(function () { + var el = $(this); + var lists = []; - el.find('div.closet-list').each(function () { - var el = $(this); - var id = el.attr('data-id'); - if(id) { - lists[lists.length] = { - id: parseInt(id, 10), - label: el.find('h4').text() - } - } - }); + el.find('div.closet-list').each(function () { + var el = $(this); + var id = el.attr('data-id'); + if(id) { + lists[lists.length] = { + id: parseInt(id, 10), + label: el.find('h4').text() + } + } + }); - hangerGroups[hangerGroups.length] = { - label: el.find('h3').text(), - lists: lists, - owned: (el.attr('data-owned') == 'true') - }; - }); + hangerGroups[hangerGroups.length] = { + label: el.find('h3').text(), + lists: lists, + owned: (el.attr('data-owned') == 'true') + }; + }); - $('div.closet-hangers-group span.toggle').live('click', function () { - $(this).closest('.closet-hangers-group').toggleClass('hidden'); - }); + $('div.closet-hangers-group span.toggle').live('click', function () { + $(this).closest('.closet-hangers-group').toggleClass('hidden'); + }); - var hangersElQuery = '#closet-hangers'; + var hangersElQuery = '#closet-hangers'; var hangersEl = $(hangersElQuery); - /* + /* Compare with Your Items @@ -381,85 +381,90 @@ autocompleter._renderItem = function( ul, item ) { var li = $("
  • ").data("item.autocomplete", item); if(item.is_item) { // these are items from the server - li.append("Add " + item.label + ""); + $('#autocomplete-item-tmpl').tmpl({item_name: item.label}).appendTo(li); } else if(item.list) { // these are list inserts + var listName = item.list.label; if(item.hasHanger) { - li.append("It's already in " + item.list.label + ""); + $('#autocomplete-already-in-collection-tmpl'). + tmpl({collection_name: listName}).appendTo(li); } else { - li.append("Add to " + item.list.label + ""); + $('#autocomplete-add-to-list-tmpl').tmpl({list_name: listName}). + appendTo(li); } li.addClass("closet-list-autocomplete-item"); } else { // these are group inserts var groupName = item.group.label; if(!item.hasHanger) { - li.append("Add to " + groupName.replace(/\s+$/, '') + ", no list"); + $('#autocomplete-add-to-group-tmpl'). + tmpl({group_name: groupName.replace(/\s+$/, '')}).appendTo(li); } else { - li.append("It's already in " + groupName + ""); + $('#autocomplete-already-in-collection-tmpl'). + tmpl({collection_name: groupName}).appendTo(li); } - li.addClass('closet-hangers-group-autocomplete-item'); - } - return li.appendTo(ul); - } + li.addClass('closet-hangers-group-autocomplete-item'); + } + return li.appendTo(ul); + } - /* + /* - Contact Neopets username form + Contact Neopets username form - */ + */ - var contactEl = $('#closet-hangers-contact'); - var editContactLink = $('.edit-contact-link'); - var contactForm = contactEl.children('form'); - var cancelContactLink = $('#cancel-contact-link'); - var contactFormUsername = contactForm.children('input[type=text]'); - var editContactLinkUsername = $('#contact-link-has-value span'); + var contactEl = $('#closet-hangers-contact'); + var editContactLink = $('.edit-contact-link'); + var contactForm = contactEl.children('form'); + var cancelContactLink = $('#cancel-contact-link'); + var contactFormUsername = contactForm.children('input[type=text]'); + var editContactLinkUsername = $('#contact-link-has-value span'); - function closeContactForm() { - contactEl.removeClass('editing'); - } + function closeContactForm() { + contactEl.removeClass('editing'); + } - editContactLink.click(function () { - contactEl.addClass('editing'); - contactFormUsername.focus(); - }); + editContactLink.click(function () { + contactEl.addClass('editing'); + contactFormUsername.focus(); + }); - cancelContactLink.click(closeContactForm); + cancelContactLink.click(closeContactForm); - contactForm.submit(function (e) { - var data = contactForm.serialize(); - contactForm.disableForms(); - $.ajax({ - url: contactForm.attr('action') + '.json', - type: 'post', - data: data, - dataType: 'json', - complete: function () { - contactForm.enableForms(); - }, - success: function () { - var newName = contactFormUsername.val(); - if(newName.length > 0) { - editContactLink.addClass('has-value'); - editContactLinkUsername.text(newName); - } else { - editContactLink.removeClass('has-value'); - } - closeContactForm(); + contactForm.submit(function (e) { + var data = contactForm.serialize(); + contactForm.disableForms(); + $.ajax({ + url: contactForm.attr('action') + '.json', + type: 'post', + data: data, + dataType: 'json', + complete: function () { + contactForm.enableForms(); }, - error: function (xhr) { - handleSaveError(xhr, 'saving Neopets username'); - } - }); - e.preventDefault(); - }); + success: function () { + var newName = contactFormUsername.val(); + if(newName.length > 0) { + editContactLink.addClass('has-value'); + editContactLinkUsername.text(newName); + } else { + editContactLink.removeClass('has-value'); + } + closeContactForm(); + }, + error: function (xhr) { + handleSaveError(xhr, 'saving Neopets username'); + } + }); + e.preventDefault(); + }); - /* + /* - Hanger list controls + Hanger list controls - */ + */ - $('input[type=submit][data-confirm]').live('click', function (e) { + $('input[type=submit][data-confirm]').live('click', function (e) { if(!confirm(this.getAttribute('data-confirm'))) e.preventDefault(); });