PageRenderTime 100ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/static/js/views/sitelistview.js

https://bitbucket.org/gordonbrander/accordion-drawer-prototypes
JavaScript | 92 lines | 64 code | 18 blank | 10 comment | 7 complexity | be4be152ef38378cca1ce52f41ce7982 MD5 | raw file
Possible License(s): Apache-2.0
  1. define([
  2. 'underscore', 'backbone',
  3. 'models/sitecollection',
  4. 'views/listview',
  5. 'views/sitesingleview',
  6. 'logger'
  7. ],
  8. function (util, Backbone, SiteCollection, ListView, SiteSingleView, logger) {
  9. var __ListView = ListView.prototype;
  10. // A widget that contains the views for a collection of sites.
  11. var SiteListView = ListView.extend({
  12. className: 'mod-cards cf',
  13. initialize: function (options) {
  14. var self = this;
  15. options = options || {};
  16. options.view = options.view || SiteSingleView;
  17. options.collection = options.collection || new SiteCollection();
  18. __ListView.initialize.call(this, options);
  19. // Collection Events
  20. this.collection
  21. .bind('fetch', this.renderLoader, this)
  22. .bind('success', this.removeLoader, this);
  23. // View events
  24. },
  25. events: {
  26. 'click a[href]': 'onitemclick'
  27. },
  28. fetch: function () {
  29. var collection = this.collection;
  30. collection.fetch.apply(collection, arguments);
  31. },
  32. onitemclick: function(evt){
  33. // TODO: this is preventing the app from following links. Determine
  34. // if this is the intended behavior, given our frame-based
  35. // architecture.
  36. evt.preventDefault();
  37. var itemNode = evt.currentTarget,
  38. itemId = itemNode.getAttribute("data-itemid");
  39. logger.log("site item clicked: ", evt.currentTarget, itemNode.getAttribute("data-itemid"));
  40. if(!itemId) {
  41. logger.log("no data-itemid attribute on click target: ", itemNode);
  42. return;
  43. }
  44. if(this.bridge && this.bridge.selectSite){
  45. this.bridge.selectSite( this.collection.get(itemId) );
  46. } else {
  47. logger.log("no bridge.selectSite to call with itemId: ", itemId);
  48. }
  49. },
  50. renderLoader: function () {
  51. // Create a new loader and assign it to a property so we can easily
  52. // remove it later. Creating a new loader every time means we don't
  53. // have to undo the animation leftovers from removeLoader.
  54. this.$loader = $('<div class="loader pin-center">Loading&hellip;</div>')
  55. .css({ opacity: 0 });
  56. $(this.el).append(this.$loader);
  57. this.$loader.animate({ opacity: 0.5, scale: 1 }, 500, 'ease-out');
  58. return this;
  59. },
  60. removeLoader: function () {
  61. var $loader = this.$loader;
  62. $loader.animate(
  63. { opacity: 0, scale: 1.5 },
  64. 400,
  65. 'ease-in',
  66. // After animating the loader, remove it from the DOM.
  67. function () { $loader.remove(); }
  68. );
  69. return this;
  70. },
  71. render: function () { return this; }
  72. });
  73. return SiteListView;
  74. });