Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactor add new card

  • Loading branch information...
commit 5edaa153f1828048f362f80e384f3dbd3f1d59f9 1 parent c96d728
@ghendry authored
View
36 app/client/coffeescripts/views.coffee
@@ -7,25 +7,6 @@ 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: ->
@@ -33,15 +14,24 @@ jQuery ->
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
11 app/client/haml/index.haml
@@ -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
View
74 public/assets/javascripts/views.js
@@ -3,7 +3,7 @@
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
jQuery(function() {
- var CardView, CardsView, NewCardView, _ref;
+ var CardView, CardsView, _ref;
CardView = (function(_super) {
__extends(CardView, _super);
@@ -26,53 +26,6 @@
return CardView;
})(Backbone.View);
- NewCardView = (function(_super) {
-
- __extends(NewCardView, _super);
-
- NewCardView.name = 'NewCardView';
-
- function NewCardView() {
- return NewCardView.__super__.constructor.apply(this, arguments);
- }
-
- NewCardView.prototype.className = 'card-entry';
-
- NewCardView.prototype.template = _.template($('#new-card').html());
-
- NewCardView.prototype.events = {
- "click #save-card": "showCard"
- };
-
- NewCardView.prototype.showCard = function() {
- var card, view;
- card = new app.Card;
- card.set({
- card_name: $('form input#card_name').val()
- });
- card.set({
- card_text: 'xxxxxxx!!!!!'
- });
- view = new CardView({
- model: card
- });
- $('#container').append(view.render());
- return $('.dcard').draggable({
- handle: 'p.handle'
- });
- };
-
- NewCardView.prototype.modelBindings = {
- "change form input.card_name": "card_name"
- };
-
- NewCardView.prototype.render = function() {
- return $(this.el).html(this.template());
- };
-
- return NewCardView;
-
- })(Backbone.View);
CardsView = (function(_super) {
__extends(CardsView, _super);
@@ -93,6 +46,23 @@
return this.render();
};
+ CardsView.prototype.events = {
+ "click #extra-card": "extraCard"
+ };
+
+ CardsView.prototype.extraCard = function() {
+ var c, view;
+ c = this.addCard('new', 'new');
+ console.log('in extra2');
+ view = new CardView({
+ model: c
+ });
+ $(this.el).append(view.render());
+ return $('.dcard').draggable({
+ handle: 'p.handle'
+ });
+ };
+
CardsView.prototype.render = function() {
var i, view, _i, _ref;
$(this.el).empty();
@@ -105,11 +75,8 @@
handle: 'p.handle'
});
}
- view = new NewCardView({
- model: new app.Card
- });
- $(this.el).append(view.render());
- $(this.el).append("<p>this is the end of cards view</p>");
+ $(this.el).append('<button id="extra-card" type="button">Extra!</button>\
+ </div>');
return this;
};
@@ -131,7 +98,6 @@
})(Backbone.View);
this.app = (_ref = window.app) != null ? _ref : {};
this.app.CardView = CardView;
- this.app.NewCardView = NewCardView;
return this.app.CardsView = CardsView;
});
View
15 public/index.html
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.