dataset-info.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /** Component for showing detailed information about a dataset */
  2. define(
  3. function( require ) {
  4. var Backbone = require( "backbone" ),
  5. _ = require( "underscore" ),
  6. fui = require( "app/fui" ),
  7. DatasetInfoTpl = require( "plugins/text!app/templates/dataset-info.tpl" ),
  8. DatasetStatsView = require( "app/views/dataset-stats" ),
  9. DatasetStatsModel = require( "app/models/dataset-stats" );
  10. var DatasetInfo = Backbone.Marionette.ItemView.extend( {
  11. initialize: function() {
  12. _.bindAll( this, "onModelChanged", "onCountGraphs" );
  13. this.showStatistics( true );
  14. this.model.on( "change", this.onModelChanged );
  15. },
  16. template: _.template( DatasetInfoTpl ),
  17. ui: {
  18. stats: "#statistics",
  19. count: ".count-graphs"
  20. },
  21. el: "#info .with-dataset",
  22. events: {
  23. "click .count-graphs": "onCountGraphs"
  24. },
  25. templateHelpers: {
  26. },
  27. serializeData: function() {
  28. return this.model;
  29. },
  30. /** Alias for the model */
  31. dataset: function() {
  32. return this.model;
  33. },
  34. // event handlers
  35. onModelChanged: function() {
  36. if (!this.model.counting) {
  37. this.render();
  38. this.showStatistics( false );
  39. }
  40. },
  41. onCountGraphs: function( e ) {
  42. e.preventDefault();
  43. this.model.count();
  44. },
  45. showStatistics: function( keep ) {
  46. var self = this;
  47. this.model
  48. .statistics( keep )
  49. .done( function( data ) {
  50. var statsModel = new DatasetStatsModel( self.dataset(), data );
  51. new DatasetStatsView( {model: statsModel} ).render();
  52. } );
  53. }
  54. });
  55. return DatasetInfo;
  56. }
  57. );