/cdnsrc/js/view/DocumentDetailView.js
JavaScript | 81 lines | 34 code | 13 blank | 34 comment | 0 complexity | 5a8ec92b18717e39ecc75ed6da6e6daf MD5 | raw file
Possible License(s): Apache-2.0
- /**
- Aaron Greenlee
- http://aarongreenlee.com/
-
- This work is licensed under a Creative Commons Attribution-Share-Alike 3.0
- Unported License.
-
- // Original Info -----------------------------------------------------------
- Author : Aaron Greenlee
- Created : 12/19/2010 9:53:53 AM
-
- The detail view of a document for an example Backbone.js application.
-
- // Modifications :----------------------------------------------------------
-
- */
- var DocumentDetailView = Backbone.View.extend({
-
- // Constructor
- initialize: function ()
- {
- _.bindAll(this, "render");
-
- this.model.bind('change', this.render);
-
- this.model.addView(this);
-
- this.name = 'DocumentDetailView';
-
- return this;
- }
- // Bind events which can occur within our view to actions specific to
- // this instance of the view.
- ,events:
- {
- 'click .delete' : 'deleteDocument'
- }
- ,render: function ()
- {
- // Use the jQuery Template plug-in built by Microsoft to
- // render our model. The model will be provided to the template
- // as JSON using the toJSON method provided by BackboneJS.
- //
- // For this example, the templates exist within the initial HTML
- // rendered on the server; however, I plan to push these from
- // the CDN.
- $(this.el).html(
- $.tmpl('DetailTemplate',this.model.toJSON() )
- );
- // Return this to allow chaining.
- return this;
- }
-
- // Destroy the model
- ,deleteDocument: function()
- {
- // The model will now remove all of it's views.
- this.model.unloadViews();
-
- // Remove the model from the collection
- this.model.collection.remove(this.model);
-
- // Return this to allow chaining.
- return this;
- }
- ,unloadView : function ()
- {
- // We are not going to delete this specific view from the DOM.
- // We want to inform the user they deleted the model.
- $(this.el).html(
- $.tmpl('DeletedDocumentTemplate',{id: this.model.id} )
- );
-
- // Return this to allow chaining.
- return this;
- }
- });