Created
November 30, 2011 15:37
-
-
Save wilsolutions/1409511 to your computer and use it in GitHub Desktop.
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
@app = window.app ? {} | |
class Insight extends Backbone.Model | |
@app.Insight = Insight | |
class Insights extends Backbone.Collection | |
model: app.Insight | |
url: 'http://localhost/items.json' | |
initialize: -> | |
#@fetch() | |
#console.log @ | |
setActiveLibrary: (library) -> | |
@activeLibrary = library | |
@trigger 'sort' | |
sortChronologic: -> | |
console.log @ | |
_.sortBy @, (insight) -> | |
console.log insight | |
@app.Insights = new Insights | |
(($) -> | |
class LibraryView extends Backbone.View | |
el: '#home' | |
initialize: (options) -> | |
console.log "Library View Initialized..." | |
@collection.bind 'reset', @render, @ | |
@subviews = | |
LibraryChronologicView: new LibraryChronologicView | |
collection: @collection | |
###LibraryAlphabeticalView: new LibraryAlphabeticalView | |
collection: @collection | |
LibraryPopularView: new LibraryPopularView | |
collection: @collection | |
LibraryRelatedView: new LibraryRelatedView | |
collection: @collection | |
### | |
@app.LibraryView = LibraryView | |
class LibraryChronologicView extends Backbone.View | |
el: '#library' | |
template: "#library-template" | |
initialize: -> | |
console.log "LibraryChronologicView View Initialized!!!" | |
@collection.bind "sort", @render, @ | |
render: => | |
#console.log @collection | |
if @collection.activeLibrary is 'LibraryChronologicView' | |
#Add Collection sorting here | |
console.log 'BEGIN: LOOP' | |
#console.log @collection | |
###for item in @collection | |
console.log 'asdfasdf' | |
console.log item | |
@appendItem item | |
#### | |
#console.log this | |
#console.log @ | |
#x = @collection | |
console.log 'WWWWWWWWW' | |
#_.each(@collection, function(model) { console.log 'o' }) | |
console.log app.Insights.models | |
#console.log app | |
console.log @collection | |
@collection.each ((item) -> | |
console.log 'XXXXXXXXX' | |
), this | |
console.log 'END: LOOP' | |
console.log "Rendered Library" | |
@ | |
appendItem: (item) -> | |
console.log item | |
libraryItemView = new LibraryItemView | |
model: item | |
$(@el).append libraryItemView.render().el | |
class DetailView extends Backbone.View | |
template: "#insight-detail" | |
tag: "div" | |
id: "product" | |
initialize: -> | |
console.log "#CALLED#: initialize..." | |
_.bindAll this, "render" | |
@model.bind "change", @render | |
@initializeTemplate() | |
events: | |
"tap #backhome": "gohome" | |
gohome: (e) -> | |
$('.view') .removeClass('slidein') .addClass('slideout') | |
#this should be here, right? | |
#window.App.navigate '#frontpage', true | |
0 | |
initializeTemplate: -> | |
@template = Handlebars.compile($(@template).html()) | |
render: -> | |
console.log "# Called: InsightView render!" | |
console.log @model.get("Item").title | |
$(@el).html @template(@model.toJSON()) | |
@ | |
@app.DetailView = DetailView | |
class AuthenticationView extends Backbone.View | |
el: '#authentication' | |
events: | |
'tap #request-access': 'requestAccess' | |
'tap #login': 'login' | |
requestAccess: -> | |
@login | |
login: -> | |
@app.AuthenticationView = AuthenticationView | |
class LibraryItemView extends Backbone.View | |
template: "#library-template" | |
tagName: "div" | |
className: "box" | |
events: | |
"tap .button_item": "showItem" | |
showItem: (e) -> | |
console.log @model.cid | |
window.App.navigate('insight/'+@model.cid, true) | |
return @ | |
insightView = undefined | |
console.log "### taped LibraryItemView showItem!" | |
insightView = new InsightView(model: @model) | |
$("#product").remove() | |
$("body").append insightView.render().el | |
initialize: -> | |
_.bindAll this, "render", "unrender", "remove", "showItem" | |
@model.bind "change", @render | |
@model.bind "remove", @unrender | |
@template = Handlebars.compile($(@template).html()) | |
render: -> | |
$(@el).html @template(@model.toJSON()) | |
this | |
unrender: -> | |
$(@el).remove() | |
remove: (e) -> | |
console.log e | |
@model.destroy() | |
class InsightsApp extends Backbone.Router | |
routes: | |
"": "authentication" | |
"frontpage": "frontpage" | |
"insight/:id": "insight" | |
initialize: -> | |
console.log "## ROUTER: initialize: function() called! " | |
#app.Insights.fetch() | |
#console.log 'eba' | |
#console.log(app.Insights) | |
#console.log 'eba2' | |
@view = new app.LibraryView collection: app.Insights | |
@view.collection.setActiveLibrary 'LibraryChronologicView' | |
#window.library.fetch() | |
#@libraryView = new LibraryView | |
# collection: window.library | |
# model: library | |
console.log "## END: ROUTER: initialize: function() " | |
frontpage: -> | |
console.log "Frontpage Called" | |
$('#authentication') .addClass('slidedown') .removeClass('.slideup') | |
$('#home').show() | |
$("#library div").empty() | |
$("#library div").append @libraryView.render().el | |
@ | |
insight: (id) -> | |
console.log "### taped LibraryItemView showItem2!" | |
console.log id | |
insightView = undefined | |
insightView = new InsightView(model: window.library.getByCid(id)) | |
$("#product").remove() | |
$("#productcontent").append insightView.render().el | |
$('.view') .removeClass('slideout') .addClass('slidein') | |
@ | |
@app.InsightsApp = InsightsApp | |
@app.router = new app.InsightsApp | |
Backbone.history.start({pushState:true}) | |
) $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment