forked from railsbridge/bridge_troll
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lurching slightly closer to student sorting
Adds handlebars_assets for backbone templates
- Loading branch information
1 parent
00deba2
commit 815af89
Showing
12 changed files
with
169 additions
and
41 deletions.
There are no files selected for viewing
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
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,24 @@ | ||
Bridgetroll.Views.Base = Backbone.View.extend({ | ||
postRender: $.noop, | ||
context: $.noop, | ||
|
||
initialize: function () { | ||
this.subViews = []; | ||
}, | ||
|
||
render: function () { | ||
this.$el.empty(); | ||
if (this.template) { | ||
var template = HandlebarsTemplates[this.template]; | ||
this.$el.html(template(this.context())); | ||
} | ||
|
||
this.postRender(); | ||
this.delegateEvents(); | ||
|
||
_.each(this.subViews, function (view) { | ||
view.render(); | ||
this.$el.append(view.$el); | ||
}, this); | ||
} | ||
}); |
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 |
---|---|---|
@@ -1,8 +1,30 @@ | ||
Bridgetroll.Views.Section = Backbone.View.extend({ | ||
Bridgetroll.Views.Section = Bridgetroll.Views.Base.extend({ | ||
className: 'bridgetroll-section', | ||
template: 'section_organizer/section', | ||
|
||
render: function () { | ||
this.$el.empty(); | ||
this.$el.append('i am a section'); | ||
events: { | ||
'sortreceive .students': 'studentAdded', | ||
'sortremove .students': 'studentRemoved' | ||
}, | ||
|
||
initialize: function (options) { | ||
this._super('initialize', arguments); | ||
|
||
this.title = options.title; | ||
this.students = options.students; | ||
}, | ||
|
||
context: function () { | ||
return { | ||
title: this.title, | ||
students: this.students.toJSON() | ||
} | ||
}, | ||
|
||
studentAdded: $.noop, | ||
studentRemoved: $.noop, | ||
|
||
postRender: function () { | ||
this.$('.students').sortable({connectWith: '.bridgetroll-section .students'}); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
<h3>{{title}}</h3> | ||
<ul class='students'> | ||
{{#each students}} | ||
<li>{{this.name}}</li> | ||
{{/each}} | ||
</ul> |
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 @@ | ||
<button class='add-section'>Add Section</button> |
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,58 @@ | ||
// This method gives you an easier way of calling super | ||
// when you're using Backbone in plain javascript. | ||
// It lets you avoid writing the constructor's name multiple | ||
// times. You still have to specify the name of the method. | ||
// | ||
// So instead of having to write: | ||
// | ||
// User = Backbone.Model.extend({ | ||
// save: function(attrs) { | ||
// this.beforeSave(attrs); | ||
// return User.__super__.save.apply(this, arguments); | ||
// } | ||
// }); | ||
// | ||
// You get to write: | ||
// | ||
// User = Backbone.Model.extend({ | ||
// save: function(attrs) { | ||
// this.beforeSave(attrs); | ||
// return this._super("save", arguments); | ||
// } | ||
// }); | ||
// | ||
|
||
;(function(Backbone) { | ||
|
||
// The super method takes two parameters: a method name | ||
// and an array of arguments to pass to the overridden method. | ||
// This is to optimize for the common case of passing 'arguments'. | ||
function _super(methodName, args) { | ||
|
||
// Keep track of how far up the prototype chain we have traversed, | ||
// in order to handle nested calls to _super. | ||
this._superCallObjects || (this._superCallObjects = {}); | ||
var currentObject = this._superCallObjects[methodName] || this, | ||
parentObject = findSuper(methodName, currentObject); | ||
this._superCallObjects[methodName] = parentObject; | ||
|
||
var result = parentObject[methodName].apply(this, args || []); | ||
delete this._superCallObjects[methodName]; | ||
return result; | ||
} | ||
|
||
// Find the next object up the prototype chain that has a | ||
// different implementation of the method. | ||
function findSuper(methodName, childObject) { | ||
var object = childObject; | ||
while (object[methodName] === childObject[methodName]) { | ||
object = object.constructor.__super__; | ||
} | ||
return object; | ||
} | ||
|
||
_.each(["Model", "Collection", "View", "Router"], function(klass) { | ||
Backbone[klass].prototype._super = _super; | ||
}); | ||
|
||
})(Backbone); |