This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a select view, people can have an occupation
- Loading branch information
Chris Nelson
committed
May 26, 2012
1 parent
83a6cce
commit 303712d
Showing
17 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
example/app/assets/javascripts/backbone/models/occupation.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Example.Models.Occupation extends Backbone.Model | ||
urlRoot: "/occupations" | ||
|
||
class Example.Collections.OccupationsCollection extends Backbone.Collection | ||
model: Example.Models.Occupation | ||
|
||
url: "/occupations" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
example/app/assets/javascripts/backbone/views/edit_person_view.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class OccupationsController < InheritedResources::Base | ||
respond_to :html, :json | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Occupation < ActiveRecord::Base | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class Person < ActiveRecord::Base | ||
validates_presence_of :first_name | ||
|
||
belongs_to :occupation | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class CreateOccupations < ActiveRecord::Migration | ||
def change | ||
create_table :occupations do |t| | ||
t.string :name | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
example/spec/javascripts/views/select_field_view_spec.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class Foo extends Backbone.Model | ||
|
||
class FooCollection extends Backbone.Collection | ||
model: Foo | ||
|
||
describe "select field view", -> | ||
beforeEach -> | ||
setFixtures "<div id='select_field_view'></div>" | ||
@person = new Example.Models.Person | ||
first_name: "bob" | ||
occupation_id: "2" | ||
@occupations = new Example.Collections.OccupationsCollection [{id: 1, name: "Fireman"}, {id: 2, name: "Ragpicker"}] | ||
@selectFieldView = new Backtastic.Views.SelectFieldView | ||
model: @person | ||
field: "occupation_id" | ||
label: "Occupation" | ||
el: $("#select_field_view") | ||
collection: @occupations | ||
parentView: new Example.Views.FormView | ||
@selectFieldView.render() | ||
it "renders a value", -> | ||
expect(@selectFieldView.$("select[name=occupation_id]").val()).toEqual "2" | ||
it "renders options", -> | ||
expect(@selectFieldView.$("option").length).toEqual 2 | ||
expect(@selectFieldView.$("option").first()).toHaveText "Fireman" | ||
it "puts a label on it", -> | ||
expect(@selectFieldView.$("label[for=occupation_id]")).toExist() | ||
expect(@selectFieldView.$("label[for=occupation_id]")).toHaveText /Occupation/ |
4 changes: 4 additions & 0 deletions
4
lib/assets/javascripts/templates/select_field_template.jst.hamlc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
%label{for: @field}= @label | ||
%select{name: @field} | ||
- for model in @collection.models | ||
%option{value: model.id}= model.get("name") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Backtastic.Views.SelectFieldView extends Backtastic.Views.FormFieldView | ||
|
||
template: JST["templates/select_field_template"] | ||
|
||
render: -> | ||
super | ||
@$("select").val @model.get(@field) | ||
|