1
0
Fork 0
forked from OpenNeo/impress

i18n for closet_hangers#index search bar autocomplete

This commit is contained in:
Emi Matchu 2013-01-03 13:25:14 -05:00
parent 706fad0174
commit 8c9dda37d5
4 changed files with 116 additions and 81 deletions

View file

@ -73,11 +73,29 @@
= render_unlisted_closet_hangers(owned) = render_unlisted_closet_hangers(owned)
%span.empty-list= t '.unlisted.empty' %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 - content_for :stylesheets do
= stylesheet_link_tag 'south-street/jquery-ui' = stylesheet_link_tag 'south-street/jquery-ui'
- content_for :javascripts do - content_for :javascripts do
= include_javascript_libraries :jquery = include_javascript_libraries :jquery, :jquery_tmpl
= javascript_include_tag 'ajax_auth', 'jquery.ui', 'jquery.jgrowl', = javascript_include_tag 'ajax_auth', 'jquery.ui', 'jquery.jgrowl',
'placeholder', 'closet_hangers/index' 'placeholder', 'closet_hangers/index'

View file

@ -117,6 +117,12 @@ en-meep:
submit: Meep submit: Meep
header: (Not in a meepit) header: (Not in a meepit)
empty: There aren't any meepits here. empty: There aren't any meepits here.
autocomplete:
add_item_html: Meep <strong>%{item_name}</strong>
add_to_list_html: Meep to <strong>%{list_name}</strong>
add_to_group_html: Meep to <strong>%{group_name}</strong>, no list
already_in_collection_html:
It's already meeped in <strong>%{collection_name}</strong>
petpage: petpage:
title: Export to meeppage title: Export to meeppage

View file

@ -118,6 +118,12 @@ en:
submit: Save submit: Save
header: (Not in a list) header: (Not in a list)
empty: There aren't any items here. empty: There aren't any items here.
autocomplete:
add_item_html: Add <strong>%{item_name}</strong>
add_to_list_html: Add to <strong>%{list_name}</strong>
add_to_group_html: Add to <strong>%{group_name}</strong>, no list
already_in_collection_html:
It's already in <strong>%{collection_name}</strong>
petpage: petpage:
title: Export to petpage title: Export to petpage

View file

@ -19,36 +19,36 @@
var hangerGroups = []; var hangerGroups = [];
$('div.closet-hangers-group').each(function () { $('div.closet-hangers-group').each(function () {
var el = $(this); var el = $(this);
var lists = []; var lists = [];
el.find('div.closet-list').each(function () { el.find('div.closet-list').each(function () {
var el = $(this); var el = $(this);
var id = el.attr('data-id'); var id = el.attr('data-id');
if(id) { if(id) {
lists[lists.length] = { lists[lists.length] = {
id: parseInt(id, 10), id: parseInt(id, 10),
label: el.find('h4').text() label: el.find('h4').text()
} }
} }
}); });
hangerGroups[hangerGroups.length] = { hangerGroups[hangerGroups.length] = {
label: el.find('h3').text(), label: el.find('h3').text(),
lists: lists, lists: lists,
owned: (el.attr('data-owned') == 'true') owned: (el.attr('data-owned') == 'true')
}; };
}); });
$('div.closet-hangers-group span.toggle').live('click', function () { $('div.closet-hangers-group span.toggle').live('click', function () {
$(this).closest('.closet-hangers-group').toggleClass('hidden'); $(this).closest('.closet-hangers-group').toggleClass('hidden');
}); });
var hangersElQuery = '#closet-hangers'; var hangersElQuery = '#closet-hangers';
var hangersEl = $(hangersElQuery); var hangersEl = $(hangersElQuery);
/* /*
Compare with Your Items Compare with Your Items
@ -381,85 +381,90 @@
autocompleter._renderItem = function( ul, item ) { autocompleter._renderItem = function( ul, item ) {
var li = $("<li></li>").data("item.autocomplete", item); var li = $("<li></li>").data("item.autocomplete", item);
if(item.is_item) { // these are items from the server if(item.is_item) { // these are items from the server
li.append("<a>Add <strong>" + item.label + "</strong>"); $('#autocomplete-item-tmpl').tmpl({item_name: item.label}).appendTo(li);
} else if(item.list) { // these are list inserts } else if(item.list) { // these are list inserts
var listName = item.list.label;
if(item.hasHanger) { if(item.hasHanger) {
li.append("<span>It's already in <strong>" + item.list.label + "</strong>"); $('#autocomplete-already-in-collection-tmpl').
tmpl({collection_name: listName}).appendTo(li);
} else { } else {
li.append("<a>Add to <strong>" + item.list.label + "</strong>"); $('#autocomplete-add-to-list-tmpl').tmpl({list_name: listName}).
appendTo(li);
} }
li.addClass("closet-list-autocomplete-item"); li.addClass("closet-list-autocomplete-item");
} else { // these are group inserts } else { // these are group inserts
var groupName = item.group.label; var groupName = item.group.label;
if(!item.hasHanger) { if(!item.hasHanger) {
li.append("<a>Add to <strong>" + groupName.replace(/\s+$/, '') + "</strong>, no list"); $('#autocomplete-add-to-group-tmpl').
tmpl({group_name: groupName.replace(/\s+$/, '')}).appendTo(li);
} else { } else {
li.append("<span>It's already in <strong>" + groupName + "</strong>"); $('#autocomplete-already-in-collection-tmpl').
tmpl({collection_name: groupName}).appendTo(li);
} }
li.addClass('closet-hangers-group-autocomplete-item'); li.addClass('closet-hangers-group-autocomplete-item');
} }
return li.appendTo(ul); return li.appendTo(ul);
} }
/* /*
Contact Neopets username form Contact Neopets username form
*/ */
var contactEl = $('#closet-hangers-contact'); var contactEl = $('#closet-hangers-contact');
var editContactLink = $('.edit-contact-link'); var editContactLink = $('.edit-contact-link');
var contactForm = contactEl.children('form'); var contactForm = contactEl.children('form');
var cancelContactLink = $('#cancel-contact-link'); var cancelContactLink = $('#cancel-contact-link');
var contactFormUsername = contactForm.children('input[type=text]'); var contactFormUsername = contactForm.children('input[type=text]');
var editContactLinkUsername = $('#contact-link-has-value span'); var editContactLinkUsername = $('#contact-link-has-value span');
function closeContactForm() { function closeContactForm() {
contactEl.removeClass('editing'); contactEl.removeClass('editing');
} }
editContactLink.click(function () { editContactLink.click(function () {
contactEl.addClass('editing'); contactEl.addClass('editing');
contactFormUsername.focus(); contactFormUsername.focus();
}); });
cancelContactLink.click(closeContactForm); cancelContactLink.click(closeContactForm);
contactForm.submit(function (e) { contactForm.submit(function (e) {
var data = contactForm.serialize(); var data = contactForm.serialize();
contactForm.disableForms(); contactForm.disableForms();
$.ajax({ $.ajax({
url: contactForm.attr('action') + '.json', url: contactForm.attr('action') + '.json',
type: 'post', type: 'post',
data: data, data: data,
dataType: 'json', dataType: 'json',
complete: function () { complete: function () {
contactForm.enableForms(); 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();
}, },
error: function (xhr) { success: function () {
handleSaveError(xhr, 'saving Neopets username'); var newName = contactFormUsername.val();
} if(newName.length > 0) {
}); editContactLink.addClass('has-value');
e.preventDefault(); 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(); if(!confirm(this.getAttribute('data-confirm'))) e.preventDefault();
}); });