PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/src/views/socialview.js

https://bitbucket.org/gordonbrander/rjs-compile-test
JavaScript | 57 lines | 40 code | 7 blank | 10 comment | 0 complexity | 3d8d84740895893b208dd717c20c2da6 MD5 | raw file
  1. // Create a view widget for social controller.
  2. // TODO: This should be abstracted at some point, probably.
  3. define([
  4. 'underscore',
  5. 'backbone',
  6. 'views/widgetview',
  7. 'views/sitelistview',
  8. 'views/headlineview',
  9. 'views/connectviews'
  10. ], function (
  11. util, Backbone,
  12. WidgetView,
  13. SiteListView,
  14. HeadlineView,
  15. connectViews
  16. ) {
  17. var superproto = WidgetView.prototype;
  18. var SocialView = WidgetView.extend({
  19. html: '<div class="services"></div><div class="sites"></div>',
  20. className: 'socialview',
  21. initialize: function(options) {
  22. // Make this a WidgetView, plz.
  23. superproto.initialize.call(this, options);
  24. // When services are updated, create and update a services display.
  25. this.model
  26. .bind('change:services', function (socialModel) {
  27. // Get the services collection...
  28. var collection = socialModel.get('services');
  29. // Create a listview that displays that collection.
  30. var servicesView = new connectViews.ConnectionsView({
  31. collection: collection
  32. });
  33. // Provide custom view picking logic for when views are
  34. // being created.
  35. // Display the widget.
  36. this.widget('.services', servicesView);
  37. }, this)
  38. // When sites are updated, create and update a sites display.
  39. .bind('change:sites', function (socialModel) {
  40. var collection = socialModel.get('sites');
  41. var sitesView = new SiteListView({
  42. view: HeadlineView,
  43. collection: collection
  44. });
  45. this.widget('.sites', sitesView);
  46. }, this);
  47. }
  48. });
  49. return SocialView;
  50. });