Permalink
Browse files

refactor add new card

  • Loading branch information...
1 parent c96d728 commit 5edaa153f1828048f362f80e384f3dbd3f1d59f9 @ghendry committed Apr 22, 2012
Showing with 32 additions and 104 deletions.
  1. +12 −24 app/client/coffeescripts/views.coffee
  2. +0 −11 app/client/haml/index.haml
  3. +20 −54 public/assets/javascripts/views.js
  4. +0 −15 public/index.html
@@ -7,41 +7,31 @@ jQuery ->
console.log '@model is ' + JSON.stringify(@model)
$(@el).html @template(@model.toJSON())
- class NewCardView extends Backbone.View
- className: 'card-entry'
- template: _.template($('#new-card').html())
- events: {
- "click #save-card": "showCard" }
- showCard: ->
- card = new app.Card
- card.set card_name: $('form input#card_name').val()
- card.set card_text: 'xxxxxxx!!!!!'
- #TODO handle second field
- #TODO include this as subview in main rather than hard-code
- view = new CardView model: card
- $('#container').append view.render()
- $('.dcard').draggable({handle: 'p.handle'})
- modelBindings:
- "change form input.card_name" : "card_name"
- render: ->
- $(@el).html @template()
-
class CardsView extends Backbone.View
el: '#container'
initialize: ->
@collection = new app.Cards
c = @addCard('the text', 'content')
c = @addCard('the second text', 'content2')
@render()
+ events: {
+ "click #extra-card": "extraCard" }
+ extraCard: ->
+ c = @addCard('new','new')
+ console.log 'in extra2'
+ view = new CardView model: c
+ $(@el).append view.render()
+ $('.dcard').draggable({handle: 'p.handle'})
+
render: ->
$(@el).empty()
for i in [0..@collection.length-1]
view = new CardView model: @collection.at(i)
$(@el).append view.render()
$('.dcard').draggable({handle: 'p.handle'})
- view = new NewCardView model: new app.Card
- $(@el).append view.render()
- $(@el).append("<p>this is the end of cards view</p>")
+ $(@el).append('<button id="extra-card" type="button">Extra!</button>
+ </div>')
+
@
addCard: (title, content) ->
card = new app.Card
@@ -50,8 +40,6 @@ jQuery ->
@collection.add(card)
card
-
@app = window.app ? {}
@app.CardView = CardView
- @app.NewCardView = NewCardView
@app.CardsView = CardsView
View
@@ -27,17 +27,6 @@
%p{:contenteditable=>"true"} {{ card_name }}
%p{:contenteditable=>"true"} {{ card_text }}
- %script{:type=>"text/template", :id=>"new-card"}
- %form
- %label{:for=>"card_name"}
- The Title
- %input{:type=>"text", :id=>"card_name"}
- %label{:for=>"content"}
- The Content
- %textarea{:rows=>"4", :id=>"content"}
- %button{:type=>"button", :id=>"save-card"}
- Render it!
-
%body
%h1 NXan App
%div#container App goes here

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -25,21 +25,6 @@
<p contenteditable='true'>{{ card_text }}</p>
</div>
</script>
- <script id='new-card' type='text/template'>
- <form>
- <label for='card_name'>
- The Title
- </label>
- <input id='card_name' type='text' />
- <label for='content'>
- The Content
- </label>
- <textarea id='content' rows='4'></textarea>
- </form>
- <button id='save-card' type='button'>
- Render it!
- </button>
- </script>
</head>
<body>
<h1>NXan App</h1>

0 comments on commit 5edaa15

Please sign in to comment.