Created
May 31, 2013 11:07
-
-
Save mikecmpbll/5684294 to your computer and use it in GitHub Desktop.
Renders the collection twice.
This file contains hidden or 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
| define([ | |
| 'jquery', | |
| 'underscore', | |
| 'backbone', | |
| 'views/request', | |
| 'views/new_request' | |
| ], function($, _, Backbone, RequestView, NewRequestView){ | |
| var AppView = Backbone.View.extend({ | |
| el: $("#request-app"), | |
| events: { | |
| "click button.new-request": "toggleNewRequestView" | |
| }, | |
| initialize: function() { | |
| this.listenTo(this.collection, 'all', this.render); | |
| this.collection.fetch(); | |
| }, | |
| render: function() { | |
| this.collection.each(this.addOne); | |
| }, | |
| addOne: function(request) { | |
| var view = new RequestView({model: request}); | |
| this.$("#request-list").append(view.render().el); | |
| }, | |
| toggleNewRequestView: function(ev) { | |
| if (!$("#new-request-form").length > 0) { | |
| var view = new NewRequestView(); | |
| $(ev.currentTarget).after(view.render().el); | |
| $("#new-request-form").slideDown(function() { $(ev.currentTarget).text("Cancel"); }); | |
| } else { | |
| $("#new-request-form").slideToggle(function() { | |
| $(ev.currentTarget).text($(ev.currentTarget).text() === "Cancel" ? "New Request" : "Cancel"); | |
| }); | |
| } | |
| } | |
| }); | |
| return AppView; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment