PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/static/scripts/mvc/collection/dataset-collection-base.js

https://bitbucket.org/hbc/galaxy-central-hbc/
JavaScript | 151 lines | 60 code | 12 blank | 79 comment | 3 complexity | 2129f1902941b58286c4cd69b3cc88e3 MD5 | raw file
Possible License(s): CC-BY-3.0
  1. define([
  2. "mvc/base-mvc",
  3. "utils/localization"
  4. ], function( BASE_MVC, _l ){
  5. /* global Backbone, LoggableMixin */
  6. //==============================================================================
  7. /** @class Read only view for DatasetCollection.
  8. * @name DCBaseView
  9. *
  10. * @augments Backbone.View
  11. * @borrows LoggableMixin#logger as #logger
  12. * @borrows LoggableMixin#log as #log
  13. * @constructs
  14. */
  15. var DCBaseView = Backbone.View.extend( BASE_MVC.LoggableMixin ).extend({
  16. /** logger used to record this.log messages, commonly set to console */
  17. // comment this out to suppress log output
  18. //logger : console,
  19. /** */
  20. className : "dataset-collection",
  21. /** */
  22. fxSpeed : 'fast',
  23. /** */
  24. initialize : function( attributes ){
  25. if( attributes.logger ){ this.logger = this.model.logger = attributes.logger; }
  26. this.log( 'DCBaseView.initialize:', attributes );
  27. },
  28. //TODO: render has been removed from the inheritance chain here, so this won't work when called as is
  29. // ......................................................................... misc
  30. /** String representation */
  31. toString : function(){
  32. var modelString = ( this.model )?( this.model + '' ):( '(no model)' );
  33. return 'DCBaseView(' + modelString + ')';
  34. }
  35. });
  36. /** templates for DCBaseViews (skeleton and body) */
  37. DCBaseView.templates = (function(){
  38. // use closure to run underscore template fn only once at module load
  39. var skeletonTemplate = _.template([
  40. '<div class="dataset hda">',
  41. '<div class="dataset-warnings">',
  42. '<% if ( collection.deleted ) { %>',
  43. '<div class="dataset-deleted-msg warningmessagesmall"><strong>',
  44. _l( 'This collection has been deleted.' ),
  45. '</div>',
  46. '<% } %>',
  47. '<% if ( !collection.visible ) { %>',
  48. '<div class="dataset-hidden-msg warningmessagesmall"><strong>',
  49. _l( 'This collection has been hidden.' ),
  50. '</div>',
  51. '<% } %>',
  52. '</div>',
  53. '<div class="dataset-primary-actions"></div>',
  54. '<div class="dataset-title-bar clear" tabindex="0">',
  55. '<span class="dataset-state-icon state-icon"></span>',
  56. '<div class="dataset-title">',
  57. '<span class="dataset-name"><%- collection.name %></span>',
  58. '</div>',
  59. '</div>',
  60. '<div class="dataset-body"></div>',
  61. '</div>'
  62. ].join( '' ));
  63. var bodyTemplate = _.template([
  64. '<div class="dataset-body">',
  65. '<div class="dataset-summary">',
  66. _l( 'A dataset collection.' ),
  67. '</div>'
  68. ].join( '' ));
  69. // we override here in order to pass the localizer (_L) into the template scope - since we use it as a fn within
  70. return {
  71. skeleton : function( collectionJSON ){
  72. return skeletonTemplate({ _l: _l, collection: collectionJSON });
  73. },
  74. body : function( collectionJSON ){
  75. return bodyTemplate({ _l: _l, collection: collectionJSON });
  76. }
  77. };
  78. }());
  79. //TODO: unused
  80. ////==============================================================================
  81. ///** @class Read only view for DatasetCollectionElement.
  82. // * @name DCEBaseView
  83. // *
  84. // * @augments Backbone.View
  85. // * @borrows LoggableMixin#logger as #logger
  86. // * @borrows LoggableMixin#log as #log
  87. // * @constructs
  88. // */
  89. //var NestedDCBaseView = DCBaseView.extend({
  90. //
  91. // logger : console,
  92. //
  93. // /** */
  94. // initialize : function( attributes ){
  95. // if( attributes.logger ){ this.logger = this.model.logger = attributes.logger; }
  96. // this.warn( this + '.initialize:', attributes );
  97. // DCBaseView.prototype.initialize.call( this, attributes );
  98. // },
  99. //
  100. // _template : function(){
  101. // this.debug( this.model );
  102. // this.debug( this.model.toJSON() );
  103. // return NestedDCBaseView.templates.skeleton( this.model.toJSON() );
  104. // },
  105. //
  106. // // ......................................................................... misc
  107. // /** String representation */
  108. // toString : function(){
  109. // var modelString = ( this.model )?( this.model + '' ):( '(no model)' );
  110. // return 'NestedDCBaseView(' + modelString + ')';
  111. // }
  112. //});
  113. //
  114. ////------------------------------------------------------------------------------ TEMPLATES
  115. ////TODO: possibly break these out into a sep. module
  116. //NestedDCBaseView.templates = (function(){
  117. // var skeleton = _.template([
  118. // '<div class="dataset hda history-panel-hda state-ok">',
  119. // '<div class="dataset-primary-actions"></div>',
  120. // '<div class="dataset-title-bar clear" tabindex="0">',
  121. // '<div class="dataset-title">',
  122. // '<span class="dataset-name"><%= collection.name %></span>',
  123. // '</div>',
  124. // '</div>',
  125. // '</div>'
  126. // ].join( '' ));
  127. // // we override here in order to pass the localizer (_L) into the template scope - since we use it as a fn within
  128. // return {
  129. // skeleton : function( json ){
  130. // return skeleton({ _l: _l, collection: json });
  131. // }
  132. // };
  133. //}());
  134. //==============================================================================
  135. return {
  136. DCBaseView : DCBaseView,
  137. //NestedDCBaseView : NestedDCBaseView,
  138. };
  139. });