Permalink
Browse files

got dt-list working, somehow

need to improve that, but im tired as hell right now
  • Loading branch information...
1 parent 950e01b commit 02340641f3f23d3bc0ea3d3575711b751997f09f @dodo dodo committed Feb 28, 2012
View
@@ -37,6 +37,7 @@
, "dynamictemplate": "0.4.2"
, "dt-compiler": "0.1.5"
, "dt-jquery": "0.2.6"
+, "dt-list": "0.0.1"
, "Strophe.js": "https://github.com/metajack/strophejs/tarball/master"
, "notificon": "https://github.com/dodo/Notificon/tarball/master"
}
@@ -8,12 +8,14 @@ unless process.title is 'browser'
{ Template } = require 'dynamictemplate'
jqueryify = require 'dt-jquery'
design = require '../../_design/channel/comments'
+{ List } = require '../util'
module.exports = design (view) ->
return jqueryify new Template schema:5, ->
@$section class:'comments', ->
- # <% if @user?.hasRightToPost: %> FIXME
+ list = new List this
+ list.bind(view, 'view:comment')
@$section class:'answer', ->
update_answer = =>
if app.users.current.canPost(view.parent.parent.parent.model)
@@ -10,7 +10,7 @@ unless process.title is 'browser'
{ Template } = require 'dynamictemplate'
jqueryify = require 'dt-jquery'
design = require '../../_design/channel/post'
-{ load_indicate } = require '../util'
+{ load_indicate, ready } = require '../util'
module.exports = design (view) ->
@@ -50,6 +50,8 @@ module.exports = design (view) ->
view.once('update:content', load_indicate(this).clear)
view.bind('update:content', update_text.bind(this, view))
+ ready this, view
+
update_text = do ->
# Don't load them twice:
@@ -8,9 +8,9 @@ unless process.title is 'browser'
{ Template } = require 'dynamictemplate'
jqueryify = require 'dt-jquery'
design = require '../../_design/channel/posts'
+{ List } = require '../util'
module.exports = design (view) ->
return jqueryify new Template schema:5, ->
- @$section class:'topics'#, ->
-# view.bind 'view:topic', (tag) =>
-# @_jquery?.append(tag._jquery ? tag)
+ list = new List @$section class:'topics'
+ list.bind(view, 'view:topic')
@@ -8,6 +8,7 @@ unless process.title is 'browser'
{ Template } = require 'dynamictemplate'
jqueryify = require 'dt-jquery'
design = require '../../_design/channel/topicpost'
+{ ready } = require '../util'
module.exports = design (view) ->
@@ -17,3 +18,5 @@ module.exports = design (view) ->
view.bind('subview:opener', @replace)
@$section class:'comments', ->
view.bind('subview:comments', @replace)
+
+ ready this, view
View
@@ -1,3 +1,16 @@
+{ List:dtList, jqueryify } = require 'dt-list'
+
+class exports.List extends dtList
+ constructor: (rootel) ->
+ super jqueryify rootel
+
+ bind: (emitter, ns = "") ->
+ ns += ":" if ns?.length?
+ for fn in "push pop insert shift unshift remove".split(' ')
+ emitter.bind(ns+fn, this[fn])
+ return this
+
+
exports.load_indicate = (tag) ->
indicator = null
@@ -12,4 +25,11 @@ exports.load_indicate = (tag) ->
clearTimeout(timeout)
self?.remove?()
remove: ->
- indicator?.remove()
+ indicator?.remove()
+
+
+
+exports.ready = (tag, view) ->
+ tag.ready ->
+ view.trigger 'dom:ready'
+
View
@@ -6,6 +6,12 @@ class exports.BaseView extends Backbone.View
initialize: ({@parent} = {}) ->
@rendered = no
+ @domisready = no
+ @bind 'dom:ready', =>
+ @domisready = yes
+ if @_waitingfordom?
+ cb() for cb in @_waitingfordom
+ delete @_waitingfordom
render: (callback) ->
@render = -> throw new Error "ffffffffffffuuuuuuuuuuuuuu"
@@ -21,12 +27,23 @@ class exports.BaseView extends Backbone.View
callback?.call?(this)
# invoke delayed callbackes from ready
if @_waiting?
- cb?() for cb in @_waiting
+ cb() for cb in @_waiting
delete @_waiting
- ready: (callback) ->
- return unless callback?
- return callback() if @rendered
- @_waiting ?= []
- @_waiting.push callback
+ ready: (callback) =>
+ return this unless callback?
+ if @rendered
+ callback()
+ else
+ @_waiting ?= []
+ @_waiting.push callback
+ return this
+ domready: (callback) =>
+ return this unless callback?
+ if @domisready
+ callback()
+ else
+ @_waitingfordom ?= []
+ @_waitingfordom.push callback
+ return this
@@ -63,28 +63,15 @@ class exports.CommentsView extends BaseView
model:comment
parent:this
return if view.rendering
- view.render =>
- @ready =>
- @insert_comment_view view
-
-# comment.bind 'change', =>
-# view.el.detach()
-# @insert_comment_view view
-
- insert_comment_view: (view) =>
i = @model.indexOf(view.model)
- olderComment = @views[@model.at(i + 1)?.cid]
- if olderComment?.rendered
- if olderComment.el.parent().length > 0
- olderComment.el.after view.el
- else
- # wtf .. jquery's design is so b0rken m(
- olderComment.el = olderComment.el.add view.el
- else if olderComment
- olderComment.ready =>
- @insert_comment_view view
- else
- @el.prepend view.el
+ @ready =>
+ @trigger('view:comment:insert', i, (done) ->
+ view.ready ->
+ view.domready ->
+ view.__defineGetter__('_jquery',->view.el) # FIXME wtfuck?
+ done()
+ )
+ view.render()
render: (callback) ->
super ->
@@ -30,33 +30,20 @@ class exports.PostsView extends BaseView
model:post
parent:this
return if view.rendering
- view.render =>
- @ready =>
- @insert_post_view view
-
-# post.bind 'change', =>
-# view.el.detach()
-# @insert_post_view view
-
- insert_post_view: (view) =>
i = @model.posts.indexOf(view.model)
- olderPost = @views[@model.posts.at(i + 1)?.cid]
- if olderPost?.rendered
- if olderPost.el.parent().length > 0
- olderPost.el.before view.el
- else
- # wtf .. jquery's design is so b0rken m(
- dummy = $()
- dummy = dummy.add view.el
- dummy = dummy.add olderPost.el
- olderPost.el = dummy
- else if olderPost
- olderPost.ready =>
- @insert_post_view view
- else
- @el.append view.el
+# console.error "============================", i
+ @ready =>
+ @trigger('view:topic:insert', i, (done) ->
+# console.error "insert", i, view.cid
+ view.ready ->
+ view.domready ->
+# console.error "domeready => ", i, view.el
+ view.__defineGetter__('_jquery',->view.el) # FIXME wtfuck?
+ done()
+ )
+ view.render()
-#
+# FIXME this code should work again, i guess
# @$('.tutorial, .empty').remove()
# if not @parent.isLoading and count is 0
# if app.users.current.get('id') is @parent.model.get('id') # FIXME show tutorial for all users which have write access

0 comments on commit 0234064

Please sign in to comment.