diff --git a/app/assets/javascripts/backbone/broadcasters/faye.js.coffee b/app/assets/javascripts/backbone/broadcasters/faye.js.coffee index f4ef716d..1807cdd4 100644 --- a/app/assets/javascripts/backbone/broadcasters/faye.js.coffee +++ b/app/assets/javascripts/backbone/broadcasters/faye.js.coffee @@ -14,6 +14,8 @@ class Kandan.Broadcasters.FayeBroadcaster @faye_client.addExtension(auth_extension) @faye_client.subscribe "/app/activities", (data)=> console.log "activities", data + $(document).data('active_users', data.data.active_users) + console.log "sets active users", $(document).data('active_users') Kandan.Helpers.Channels.add_activity({ user: data.data.user, action: data.event.split("#")[1] @@ -24,5 +26,6 @@ class Kandan.Broadcasters.FayeBroadcaster console.log "Subscribing to #{channel}" subscription = @faye_client.subscribe channel, (data)=> Kandan.Helpers.Channels.add_activity(data) - subscription.errback ()-> - console.log "Oops! could not connect to the server" + subscription.errback(()-> + alert "Oops! could not connect to the server" + ) diff --git a/app/assets/javascripts/backbone/kandan.js.coffee b/app/assets/javascripts/backbone/kandan.js.coffee index b80f8f34..f18e0fc7 100644 --- a/app/assets/javascripts/backbone/kandan.js.coffee +++ b/app/assets/javascripts/backbone/kandan.js.coffee @@ -14,6 +14,7 @@ window.Kandan = Helpers: {} Broadcasters: {} Data: {} + Plugins: {} init: -> channels = new Kandan.Collections.Channels() @@ -29,9 +30,12 @@ window.Kandan = # TODO move broadcast subscription to a helper # TODO change this to use the broadcaster from the settings # TODO set as global to debug. remove later. + # TODO use wildcard channel names window.broadcaster = new Kandan.Broadcasters.FayeBroadcaster() for channel in channels.models window.broadcaster.subscribe "/channels/#{channel.get('id')}" + + console.log "plugins", Kandan.Plugins.all() }) diff --git a/app/assets/javascripts/backbone/plugins.js.coffee b/app/assets/javascripts/backbone/plugins.js.coffee new file mode 100644 index 00000000..b64be56c --- /dev/null +++ b/app/assets/javascripts/backbone/plugins.js.coffee @@ -0,0 +1,8 @@ +class Kandan.Plugins + @plugins: [] + + @register: (plugin)-> + @plugins.push(plugin) + + @all: ()-> + @plugins \ No newline at end of file diff --git a/app/assets/javascripts/backbone/plugins/user_list.js.coffee b/app/assets/javascripts/backbone/plugins/user_list.js.coffee new file mode 100644 index 00000000..375f244f --- /dev/null +++ b/app/assets/javascripts/backbone/plugins/user_list.js.coffee @@ -0,0 +1,21 @@ +class Kandan.Plugins.UserList + @active_users: ()-> + console.log "active users", $(document).data("active_users") + $(document).data("active_users") || [] + + + @render: ()-> + users = [] + for user in @active_users() + users.push user.first_name + $(".user_list").html(users.join ", ") + + @init: ()-> + console.log "user list plugin started" + $('body').prepend($("
")) + @render() + $(document).bind 'changeData', (event, name, value)=> + @render() if name == "active_users" + + +Kandan.Plugins.register "Kandan.Plugins.UserList" \ No newline at end of file diff --git a/app/assets/javascripts/backbone/post_init.js.coffee b/app/assets/javascripts/backbone/post_init.js.coffee index 07dcc321..37e9bbeb 100644 --- a/app/assets/javascripts/backbone/post_init.js.coffee +++ b/app/assets/javascripts/backbone/post_init.js.coffee @@ -1,6 +1,5 @@ - -$(document).ready -> - $(document).bind "changeData", (event, name, value)-> - if name == "active_users" - for callback in Kandan.Helpers.ActiveUsers.callbacks - callback() \ No newline at end of file +# $(document).ready -> +# $(document).bind "changeData", (event, name, value)-> +# if name == "active_users" +# for callback in Kandan.Helpers.ActiveUsers.callbacks +# callback() \ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 73bf19b3..e676e986 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -8,7 +8,7 @@ <%- Kandan::Config.broadcaster.assets.each do |asset| %> <%= javascript_include_tag asset %> <%- end %> - + <%= javascript_include_tag "application" %> <%= javascript_tag do %> <%- if user_signed_in? %> @@ -22,6 +22,18 @@ <%- end %> <%- end %> + <%= javascript_tag do %> + + <%- end %> + + <%= javascript_tag do %> + $(document).ready(function(){ + $.each(Kandan.Plugins.all(), function(index, plugin){ + eval(plugin).init() + }) + }) + <%- end %> + <%= csrf_meta_tags %>