basic tip functionality

This commit is contained in:
Emi Matchu 2014-04-02 23:00:50 -05:00
parent 7e73313d43
commit 8fc156833f
8 changed files with 74 additions and 10 deletions

View file

@ -1077,7 +1077,7 @@ View.ReportBrokenImage = function (wardrobe) {
View.Search = function (wardrobe) { View.Search = function (wardrobe) {
var form = $('form.item-search'), var form = $('form.item-search'),
item_set = new Partial.ItemSet(wardrobe, '#preview-search-basic ul'), item_set = new Partial.ItemSet(wardrobe, '#preview-search-results'),
input_el = form.find('input[name=query]'), input_el = form.find('input[name=query]'),
clear_el = $('#preview-search-form-clear'), clear_el = $('#preview-search-form-clear'),
error_el = $('#preview-search-form-error'), error_el = $('#preview-search-form-error'),
@ -1360,6 +1360,13 @@ View.PrankColorMessage = function(wardrobe) {
}); });
} }
View.Tips = function() {
var wrapper = $('#tips');
var children = wrapper.children();
var index = Math.floor(Math.random() * children.length);
children.eq(index).show();
}
var userbar_sessions_link = $('#userbar a:last'); var userbar_sessions_link = $('#userbar a:last');
var userbar_message_el = $('#userbar-session-message').prependTo('#userbar'); var userbar_message_el = $('#userbar-session-message').prependTo('#userbar');

View file

@ -253,11 +253,17 @@ body.outfits-edit
display: none display: none
#preview-search-advanced #preview-search-advanced
display: block display: block
#preview-search-basic > ul &.has-results
#tips
display: none
#preview-search-basic-main
clear: both clear: both
#preview-search-basic > ul, #preview-search-advanced-main #preview-search-basic-main, #preview-search-advanced-main
/* don't bounce the header around kthx */ /* don't bounce the header around kthx */
min-height: 180px min-height: 180px
#tips
li
display: none
#preview-search-advanced #preview-search-advanced
display: none display: none

View file

@ -183,8 +183,12 @@ module ApplicationHelper
content_for :title, value content_for :title, value
end end
def md(text)
RDiscount.new(text).to_html.html_safe
end
def translate_markdown(key, options={}) def translate_markdown(key, options={})
RDiscount.new(translate("#{key}_markdown", options)).to_html.html_safe md translate("#{key}_markdown", options)
end end
alias_method :tmd, :translate_markdown alias_method :tmd, :translate_markdown

View file

@ -0,0 +1,5 @@
class WardrobeTip < ActiveRecord::Base
translates :body
scope :by_index, order('`index` ASC')
end

View file

@ -101,11 +101,17 @@
%a#preview-search-advanced-link{href: 'javascript:void(0)'}= t '.search.advanced.header' %a#preview-search-advanced-link{href: 'javascript:void(0)'}= t '.search.advanced.header'
%a#preview-search-form-clear{:href => "#"}= t '.search.form.clear' %a#preview-search-form-clear{:href => "#"}= t '.search.form.clear'
#preview-search-form-pagination #preview-search-form-pagination
#preview-search-basic-main
#preview-search-form-loading= t '.search.loading' #preview-search-form-loading= t '.search.loading'
#preview-search-form-error.possible-error #preview-search-form-error.possible-error
#preview-search-form-no-results #preview-search-form-no-results
= t '.search.no_results_html', :query => content_tag(:span) = t '.search.no_results_html', :query => content_tag(:span)
%ul %ul#preview-search-results
%ul#tips
- WardrobeTip.by_index.each do |tip|
%li
%h3 Did you know?
%div= md tip.body
%form#preview-search-advanced %form#preview-search-advanced
%header %header
%h2= t '.search.advanced.header' %h2= t '.search.advanced.header'

View file

@ -0,0 +1,14 @@
class CreateWardrobeTips < ActiveRecord::Migration
def up
create_table :wardrobe_tips do |t|
t.integer :index, null: false
t.timestamps
end
WardrobeTip.create_translation_table! body: :text
end
def down
drop_table :wardrobe_tips
WardrobeTip.drop_translation_table!
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140331034031) do ActiveRecord::Schema.define(:version => 20140403034558) do
create_table "auth_servers", :force => true do |t| create_table "auth_servers", :force => true do |t|
t.string "short_name", :limit => 10, :null => false t.string "short_name", :limit => 10, :null => false
@ -333,6 +333,23 @@ ActiveRecord::Schema.define(:version => 20140331034031) do
t.integer "contact_neopets_connection_id" t.integer "contact_neopets_connection_id"
end end
create_table "wardrobe_tip_translations", :force => true do |t|
t.integer "wardrobe_tip_id"
t.string "locale"
t.text "body"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "wardrobe_tip_translations", ["locale"], :name => "index_wardrobe_tip_translations_on_locale"
add_index "wardrobe_tip_translations", ["wardrobe_tip_id"], :name => "index_wardrobe_tip_translations_on_wardrobe_tip_id"
create_table "wardrobe_tips", :force => true do |t|
t.integer "index", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "zone_translations", :force => true do |t| create_table "zone_translations", :force => true do |t|
t.integer "zone_id" t.integer "zone_id"
t.string "locale" t.string "locale"

View file

@ -0,0 +1,5 @@
require 'spec_helper'
describe WardrobeTip do
pending "add some examples to (or delete) #{__FILE__}"
end