Skip to content

Commit

Permalink
<cj> autocomplete on tags
Browse files Browse the repository at this point in the history
  • Loading branch information
chandan committed Sep 16, 2010
1 parent 9120976 commit d22062a
Show file tree
Hide file tree
Showing 13 changed files with 843 additions and 77 deletions.
27 changes: 19 additions & 8 deletions BookHuntStories.txt
Expand Up @@ -8,37 +8,48 @@
-for sale/share/exchange/donate

- book detail validations(client and server side)
- styling
- styling. two col layout.
- ability to tag the book with multiple tags ########done
- the added books view shown down as you add the books ########done
- ability to edit and delete posted book details. ########done
--------------------------------------------

--------------------------------------------
- search the books based on the tags and book details
--------------------------------------------
- pagination and sorting of the book listings.
- Filtering the books view

---------------------------------------------

---------------------------------------------
- user Login using gmail.
- capture required user info.(address, phone number)

---------------------------------------------
- ability to edit the personal details
--------------------------------------------
- pagination and sorting of the book listings.
------------------------------------------------

------------------------------------------------
- ability to choose the books from the list to buy and show interest to the owner


--------------------------------------------
- ability to search a book based on isbn(web service)
- ability to add the details and store it in db



--------------------------------------------
Overall site wide styling:
-Ability to show banner and google ads.
-Use stack overflow for tagging screenshorts


--------------------------------------------
- Google Analytics

--------------------------------------------





Marketing strategy:

-Save money
Expand Down
20 changes: 17 additions & 3 deletions app/controllers/books_controller.rb
Expand Up @@ -3,11 +3,19 @@ class BooksController < ApplicationController

def index
@books = Book.find(:all)
render :layout => "two_column"
end

def add
book_tags = []
if request.post?
@book = Book.new(params[:book])
book_fields = params[:book]
book_tags << book_fields[:tag_list]
book_tags << book_fields[:name]
book_tags << book_fields[:author]

book_fields[:tag_list] = book_tags
@book = Book.new(book_fields)
@book.save!
redirect_to :action => 'index'
end
Expand All @@ -27,9 +35,15 @@ def delete
end
end

def tags
tags = ActsAsTaggableOn::Tag.where("name LIKE '%#{params[:q]}%'")
tag_names = tags.collect{|tag| tag.name}

render :json => tag_names.compact.join("\n").to_json
end

def search
@books = []
render if request.get?

end

end
2 changes: 0 additions & 2 deletions app/controllers/books_controller_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/books/_book_form.html.haml
Expand Up @@ -8,6 +8,6 @@
= f.label :sale_price
= f.text_field :sale_price, :maxlength => 5, :size => 10
= f.label :tag_list
= f.text_field :tag_list, :maxlength => 15, :size => 15
= f.text_field :tag_list, :maxlength => 100, :size => 30
= submit_tag 'add'

6 changes: 4 additions & 2 deletions app/views/books/index.html.haml
Expand Up @@ -6,10 +6,12 @@
%h1
Post a Book
.search_on_isbn{:style=>'display:none;'}
Search books on isbn number
.description
Search books on isbn number
%input{:type=>"text"}
.manual
Enter book details manually
.description
Enter book details manually
= render :partial => 'book_form', :locals =>{ :for_action => :add, :url => {:action => 'add'}}

.posted_books
Expand Down
5 changes: 4 additions & 1 deletion app/views/layouts/application.html.haml
Expand Up @@ -5,17 +5,20 @@
%title
Book Hunt
%script{:src=>'/javascripts/jquery.js', :type=>"text/javascript"}
%script{:src=>'/javascripts/jquery-typewatch.js', :type=>"text/javascript"}
%script{:src=>'/javascripts/jquery.autocomplete.min.js', :type=>"text/javascript"}
%script{:src=>'/javascripts/jquery-ui.js', :type=>"text/javascript"}

%link{:href=>'/stylesheets/layout.css', :media=>'screen, projection' , :rel=>"stylesheet", :type=>"text/css"}
%link{:href=>'/stylesheets/jquery.autocomplete.css', :media=>'screen, projection' , :rel=>"stylesheet", :type=>"text/css"}
%link{:href=>'http://fonts.googleapis.com/css?family=Reenie+Beanie', :media=>'screen, projection' , :rel=>"stylesheet", :type=>"text/css"}
%body
#container
#header
.type_of_user_container
%a{:href => book_index_url}
.seller.user
%a{:href => book_search_url}
%a{:href => '#'}
.buyer.user
%a{:href => '#'}
.exchange.user
Expand Down
86 changes: 45 additions & 41 deletions app/views/layouts/two_column.html.haml
@@ -1,49 +1,53 @@
= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
= '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'
%head
%meta{:http_equiv => "Content-Type", :content=>"text/html", :charset=> 'utf-8'}
%title
Book Hunt
%script{:src=>'/javascripts/jquery.js', :type=>"text/javascript"}
%script{:src=>'/javascripts/jquery-ui.js', :type=>"text/javascript"}
%meta{:http_equiv => "Content-Type", :content=>"text/html", :charset=> 'utf-8'}
%title
Book Hunt
%script{:src=>'/javascripts/jquery.js', :type=>"text/javascript"}
%script{:src=>'/javascripts/jquery-typewatch.js', :type=>"text/javascript"}
%script{:src=>'/javascripts/jquery.autocomplete.min.js', :type=>"text/javascript"}
%script{:src=>'/javascripts/jquery-ui.js', :type=>"text/javascript"}

%link{:href=>'/stylesheets/layout.css', :media=>'screen, projection' , :rel=>"stylesheet", :type=>"text/css"}
%link{:href=>'http://fonts.googleapis.com/css?family=Reenie+Beanie', :media=>'screen, projection' , :rel=>"stylesheet", :type=>"text/css"}
%link{:href=>'/stylesheets/layout.css', :media=>'screen, projection' , :rel=>"stylesheet", :type=>"text/css"}
%link{:href=>'/stylesheets/jquery.autocomplete.css', :media=>'screen, projection' , :rel=>"stylesheet", :type=>"text/css"}
%link{:href=>'http://fonts.googleapis.com/css?family=Reenie+Beanie', :media=>'screen, projection' , :rel=>"stylesheet", :type=>"text/css"}
%body
#container
#header
.type_of_user_container
%a{:href=>'books/add'}
.seller.user
%a{:href=>'books/search'}
.buyer.user
%a{:href=>'books/exchange'}
.exchange.user
#container
#header
.type_of_user_container
%a{:href => book_index_url}
.seller.user
%a{:href => '#'}
.buyer.user
%a{:href => '#'}
.exchange.user

%a{:href=>'/'}
.logo
&nbsp;
%a{:href=>'/'}
.logo
&nbsp;

#content
= yield
#right_side_bar
#footer
.legalese
Copyright &copy; 2010. All Rights Reserved. Book hunt.
%ul
%li
%a{:href=>"#"}
Privacy Policy
%li
%a{:href=>"#"}
About Us
%li
%a{:href=>"#"}
Contact Us
%li
%a{:href=>"#"}
FAQ
%li
%a{:href=>"#"}
Sitemap
#content
= yield
#right-side-bar

#footer
.legalese
Copyright &copy; 2010. All Rights Reserved. Book hunt.
%ul
%li
%a{:href=>"#"}
Privacy Policy
%li
%a{:href=>"#"}
About Us
%li
%a{:href=>"#"}
Contact Us
%li
%a{:href=>"#"}
FAQ
%li
%a{:href=>"#"}
Sitemap

4 changes: 2 additions & 2 deletions db/schema.rb
Expand Up @@ -14,8 +14,8 @@
create_table "books", :force => true do |t|
t.string "name"
t.string "author"
t.integer "mrp"
t.integer "sale_price"
t.integer "mrp", :limit => 10, :precision => 10, :scale => 0
t.integer "sale_price", :limit => 10, :precision => 10, :scale => 0
t.datetime "created_at"
t.datetime "updated_at"
end
Expand Down
88 changes: 88 additions & 0 deletions public/javascripts/jquery-typewatch.js
@@ -0,0 +1,88 @@
/*
* TypeWatch 2.0 - Original by Denny Ferrassoli / Refactored by Charles Christolini
*
* Examples/Docs: www.dennydotnet.com
*
* Copyright(c) 2007 Denny Ferrassoli - DennyDotNet.com
* Coprright(c) 2008 Charles Christolini - BinaryPie.com
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/

(function(jQuery) {
jQuery.fn.typeWatch = function(o){
// Options
var options = jQuery.extend({
wait : 750,
callback : function() { },
highlight : true,
captureLength : 2
}, o);

function checkElement(timer, override) {
var elTxt = jQuery(timer.el).val();

// Fire if text > options.captureLength AND text != saved txt OR if override AND text > options.captureLength
if ((elTxt.length > options.captureLength && elTxt.toUpperCase() != timer.text)
|| (override && elTxt.length > options.captureLength)) {
timer.text = elTxt.toUpperCase();
timer.cb(elTxt);
}
};

function watchElement(elem) {
// Must be text or textarea
if (elem.type.toUpperCase() == "TEXT" || elem.nodeName.toUpperCase() == "TEXTAREA") {

// Allocate timer element
var timer = {
timer : null,
text : jQuery(elem).val().toUpperCase(),
cb : options.callback,
el : elem,
wait : options.wait
};

// Set focus action (highlight)
if (options.highlight) {
jQuery(elem).focus(
function() {
this.select();
});
}

// Key watcher / clear and reset the timer
var startWatch = function(evt) {
var timerWait = timer.wait;
var overrideBool = false;

if (evt.keyCode == 13 && this.type.toUpperCase() == "TEXT") {
timerWait = 1;
overrideBool = true;
}

var timerCallbackFx = function()
{
checkElement(timer, overrideBool)
}

// Clear timer
clearTimeout(timer.timer);
timer.timer = setTimeout(timerCallbackFx, timerWait);

};

jQuery(elem).keydown(startWatch);
}
};

// Watch Each Element
return this.each(function(index){
watchElement(this);
});

};

})(jQuery);

0 comments on commit d22062a

Please sign in to comment.