Skip to content

Commit 33c03fd

Browse files
committed
Implemented basic requirements
1 parent 6f832e0 commit 33c03fd

27 files changed

+477
-25
lines changed

.rspec

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--colour

Gemfile

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ gem 'rails', '3.0.0'
55
# Bundle edge Rails instead:
66
# gem 'rails', :git => 'git://github.com/rails/rails.git'
77

8-
gem 'sqlite3-ruby', :require => 'sqlite3'
8+
gem 'mysql2'
99

1010
group :test, :development do
11-
gem 'rspec'
12-
gem 'rspec-rails'
1311
gem 'autotest'
1412
gem 'less'
13+
gem 'rspec', '2.0.0'
14+
gem 'rspec-rails', '2.0.0'
15+
gem 'factory_girl'
1516
end
1617

1718
# Use unicorn as the web server

Gemfile.lock

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ GEM
3535
diff-lcs (1.1.2)
3636
erubis (2.6.6)
3737
abstract (>= 1.0.0)
38+
factory_girl (1.3.2)
3839
i18n (0.4.2)
3940
less (1.2.21)
4041
mutter (>= 0.4.2)
@@ -46,6 +47,7 @@ GEM
4647
treetop (~> 1.4.8)
4748
mime-types (1.16)
4849
mutter (0.5.3)
50+
mysql2 (0.2.6)
4951
polyglot (0.3.1)
5052
rack (1.2.1)
5153
rack-mount (0.6.13)
@@ -78,7 +80,6 @@ GEM
7880
rspec-expectations (= 2.0.0)
7981
rspec-rails (2.0.0)
8082
rspec (= 2.0.0)
81-
sqlite3-ruby (1.3.1)
8283
thor (0.14.3)
8384
treetop (1.4.8)
8485
polyglot (>= 0.3.1)
@@ -89,8 +90,9 @@ PLATFORMS
8990

9091
DEPENDENCIES
9192
autotest
93+
factory_girl
9294
less
95+
mysql2
9396
rails (= 3.0.0)
94-
rspec
95-
rspec-rails
96-
sqlite3-ruby
97+
rspec (= 2.0.0)
98+
rspec-rails (= 2.0.0)

app/controllers/home_controller.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
class HomeController < ApplicationController
22

3-
def index
3+
def welcome
4+
render :partial => "welcome"
5+
end
6+
7+
def about
8+
render :partial => "about"
49
end
510

611
end
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class ParticipantsController < ApplicationController
2+
3+
def new
4+
@participant = Participant.new
5+
render :partial => "form"
6+
end
7+
8+
def create
9+
@participant = Participant.create(params[:participant])
10+
if @participant.valid?
11+
render :partial => "success"
12+
else
13+
render :partial => "form"
14+
end
15+
end
16+
17+
end

app/helpers/participants_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module ParticipantsHelper
2+
end

app/models/participant.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Participant < ActiveRecord::Base
2+
3+
validates_presence_of :name, :email, :phone, :organization, :designation
4+
validate :default_text
5+
6+
def default_text
7+
errors.add(:name, "can't be blank") if name == "Your Name"
8+
if email == "Email"
9+
errors.add(:email, "can't be blank")
10+
elsif !email.nil?
11+
validates_format_of :email, :with => /^([^\s]+)((?:[-a-z0-9]\.)[a-z]{2,})$/i
12+
end
13+
errors.add(:phone, "can't be blank") if phone == "Phone"
14+
errors.add(:organization, "can't be blank") if organization == "Organization"
15+
errors.add(:designation, "can't be blank") if designation == "Your Role"
16+
end
17+
18+
end

app/views/home/_about.html.erb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div id="header">
2+
<a class="navigation" href="javascript:void(0)" data-url="<%= welcome_path %>" id="backButton">Back</a>
3+
<h1 class="with_back">About</h1>
4+
</div>
5+
<ul class="data">
6+
<li>
7+
<p>
8+
Informal meetings for tech people to exchange ideas, code and learning. Held periodically at <a href="http://www.thoughtworks.com" target="_blank">ThoughtWorks</a> offices in Bangalore, Pune and Chennai.
9+
</p>
10+
</li>
11+
</ul>

app/views/home/_welcome.html.erb

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div id="header">
2+
<h1>Geek Week</h1>
3+
</div>
4+
<ul>
5+
<li>
6+
<a class="navigation" href="javascript:void(0);" data-url="<%= new_participant_path %>">Register</a>
7+
</li>
8+
<li>
9+
<a class="navigation" href="javascript:void(0);" data-url="<%= about_path %>">About</a>
10+
</li>
11+
</ul>

app/views/home/index.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= render :partial => 'home/welcome' %>

app/views/layouts/application.html.erb

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</div>
1818

1919
<div class="body">
20-
<div class="content">
20+
<div id="iphone_body" class="content">
2121
<%= yield %>
2222
</div>
2323
</div>
@@ -29,4 +29,11 @@
2929

3030
</body>
3131

32+
<script type="text/javascript" language="javascript">
33+
document.observe("dom:loaded", function() {
34+
var geek = new GeekWeek();
35+
});
36+
37+
</script>
38+
3239
</html>

app/views/participants/_form.html.erb

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<div id="header">
2+
<a class="navigation" href="javascript:void(0)" data-url="<%= welcome_path %>" id="backButton">Back</a>
3+
<h1 class="with_back">Register</h1>
4+
</div>
5+
6+
<%= form_for @participant do |f| %>
7+
<ul class="form">
8+
<li class=<%= (@participant.errors[:name].empty? ? "valid" : "error") %>>
9+
<%= f.text_field :name, :class => "capitalize", :title => "Your Name" %>
10+
</li>
11+
<li class=<%= (@participant.errors[:email].empty? ? "valid" : "error") %>>
12+
<%= f.text_field :email, :title => "Email" %>
13+
</li>
14+
<li class=<%= (@participant.errors[:phone].empty? ? "valid" : "error") %>>
15+
<%= f.text_field :phone, :title => "Phone" %>
16+
</li>
17+
<li class=<%= (@participant.errors[:organization].empty? ? "valid" : "error") %>>
18+
<%= f.text_field :organization, :class => "capitalize", :title => "Organization" %>
19+
</li>
20+
<li class=<%= (@participant.errors[:designation].empty? ? "valid" : "error") %>>
21+
<%= f.text_field :designation, :class => "capitalize", :title => "Your Role" %>
22+
</li>
23+
</ul>
24+
<div>
25+
<a class="button white submit" href="javascript:void(0)"">Register</a>
26+
</div>
27+
<% end %>
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div id="header">
2+
<a class="navigation" href="javascript:void(0)" data-url="<%= welcome_path %>" id="backButton">Exit</a>
3+
<h1 class="with_back">Register</h1>
4+
</div>
5+
<ul class="data">
6+
<li>
7+
<p>You have been registered for the event</p>
8+
<p>You will be contacted soon!!!</p>
9+
</li>
10+
</ul>

autotest/discover.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Autotest.add_discovery { "rails" }
2+
Autotest.add_discovery { "rspec2" }

config/database.yml

+24-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
1-
# SQLite version 3.x
2-
# gem install sqlite3-ruby (not necessary on OS X Leopard)
1+
# MySQL. Versions 4.1 and 5.0 are recommended.
2+
#
3+
# Install the MySQL driver:
4+
# gem install mysql2
5+
#
6+
# And be sure to use new-style password hashing:
7+
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
8+
9+
310
development:
4-
adapter: sqlite3
5-
database: db/development.sqlite3
11+
adapter: mysql2
12+
database: geekweek_dev
613
pool: 5
7-
timeout: 5000
14+
username: root
15+
password:
16+
socket: /var/run/mysqld/mysqld.sock
817

918
# Warning: The database defined as "test" will be erased and
1019
# re-generated from your development database when you run "rake".
1120
# Do not set this db to the same as development or production.
1221
test:
13-
adapter: sqlite3
14-
database: db/test.sqlite3
22+
adapter: mysql2
23+
database: geekweek_test
1524
pool: 5
16-
timeout: 5000
25+
username: root
26+
password:
27+
socket: /var/run/mysqld/mysqld.sock
1728

1829
production:
19-
adapter: sqlite3
20-
database: db/production.sqlite3
30+
adapter: mysql2
31+
database: geekweek
2132
pool: 5
22-
timeout: 5000
33+
username: root
34+
password:
35+
socket: /var/run/mysqld/mysqld.sock

config/routes.rb

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Geekweek::Application.routes.draw do
22
root :to => "home#index"
3+
4+
match "/welcome" => "home#welcome"
5+
match "/about" => "home#about"
6+
7+
resources :participants
8+
39
# The priority is based upon order of creation:
410
# first created -> highest priority.
511

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class CreateParticipants < ActiveRecord::Migration
2+
def self.up
3+
create_table :participants do |t|
4+
t.string :name
5+
t.string :phone
6+
t.string :email
7+
t.string :organization
8+
t.string :designation
9+
10+
t.timestamps
11+
end
12+
end
13+
14+
def self.down
15+
drop_table :participants
16+
end
17+
end

db/schema.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This file is auto-generated from the current state of the database. Instead
2+
# of editing this file, please use the migrations feature of Active Record to
3+
# incrementally modify your database, and then regenerate this schema definition.
4+
#
5+
# Note that this schema.rb definition is the authoritative source for your
6+
# database schema. If you need to create the application database on another
7+
# system, you should be using db:schema:load, not running all the migrations
8+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
9+
# you'll amass, the slower it'll run and the greater likelihood for issues).
10+
#
11+
# It's strongly recommended to check this file into your version control system.
12+
13+
ActiveRecord::Schema.define(:version => 20101104084732) do
14+
15+
create_table "participants", :force => true do |t|
16+
t.string "name"
17+
t.string "phone"
18+
t.string "email"
19+
t.string "organization"
20+
t.string "designation"
21+
t.datetime "created_at"
22+
t.datetime "updated_at"
23+
end
24+
25+
end

public/javascripts/geek.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
var GeekWeek = Class.create({
2+
initialize: function() {
3+
this.domNode = $('iphone_body');
4+
this.attachNecessaryEvents();
5+
},
6+
7+
attachNecessaryEvents: function() {
8+
this.attachNavigationLinks();
9+
this.attachTextBoxEvents();
10+
this.attachSubmit();
11+
},
12+
13+
attachNavigationLinks: function() {
14+
this.domNode.select('a.navigation').each(function(link) {
15+
link.observe('click', this.loadContent.bindAsEventListener(this));
16+
}.bind(this));
17+
},
18+
19+
attachSubmit: function() {
20+
this.domNode.select('a.submit').each(function(link) {
21+
link.observe('click', this.submitForm.bindAsEventListener(this));
22+
}.bind(this));
23+
},
24+
25+
attachTextBoxEvents: function() {
26+
this.domNode.select('input').each(function(text) {
27+
text.observe('blur', this.maskTextField.bindAsEventListener(this));
28+
text.observe('focus', this.clearTextField.bindAsEventListener(this));
29+
text.value = text.value === "" ? text.readAttribute("title") : text.value;
30+
}.bind(this));
31+
},
32+
33+
loadContent: function(e) {
34+
var url = e.element().readAttribute("data-url");
35+
var request = new Ajax.Request(url, {
36+
method: 'get',
37+
onSuccess: function(response) {
38+
this.domNode.update().update(response.responseText);
39+
this.attachNecessaryEvents();
40+
}.bind(this)
41+
});
42+
},
43+
44+
clearTextField: function(e) {
45+
var text = e.element();
46+
var maskedText = text.readAttribute("title");
47+
text.value = (text.value == maskedText ? "" : text.value);
48+
},
49+
50+
maskTextField: function(e) {
51+
var text = e.element();
52+
var maskedText = text.readAttribute("title");
53+
text.value = (text.value === "" ? maskedText : text.value);
54+
},
55+
56+
submitForm: function(e) {
57+
var button = e.element();
58+
var form = button.up('form');
59+
var submitRequest = new Ajax.Request(form.action, {
60+
parameters: form.serialize(),
61+
onSuccess: function(response) {
62+
this.domNode.update().update(response.responseText);
63+
this.attachNecessaryEvents();
64+
}.bind(this)
65+
});
66+
}
67+
68+
});

0 commit comments

Comments
 (0)