PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/client/galaxy/scripts/mvc/collection/collection-li.js

https://bitbucket.org/remy_d1/galaxy-central-manageapi
JavaScript | 227 lines | 130 code | 36 blank | 61 comment | 5 complexity | 6bc6b68a597f84d9858924b7eeecb0c5 MD5 | raw file
Possible License(s): CC-BY-3.0
  1. define([
  2. "mvc/list/list-item",
  3. "mvc/dataset/dataset-li",
  4. "mvc/base-mvc",
  5. "utils/localization"
  6. ], function( LIST_ITEM, DATASET_LI, BASE_MVC, _l ){
  7. /* global Backbone, LoggableMixin */
  8. //==============================================================================
  9. var FoldoutListItemView = LIST_ITEM.FoldoutListItemView,
  10. ListItemView = LIST_ITEM.ListItemView;
  11. /** @class Read only view for DatasetCollection.
  12. */
  13. var DCListItemView = FoldoutListItemView.extend(
  14. /** @lends DCListItemView.prototype */{
  15. //TODO: may not be needed
  16. /** logger used to record this.log messages, commonly set to console */
  17. //logger : console,
  18. className : FoldoutListItemView.prototype.className + " dataset-collection",
  19. id : function(){
  20. return [ 'dataset_collection', this.model.get( 'id' ) ].join( '-' );
  21. },
  22. /** override to add linkTarget */
  23. initialize : function( attributes ){
  24. FoldoutListItemView.prototype.initialize.call( this, attributes );
  25. this.linkTarget = attributes.linkTarget || '_blank';
  26. },
  27. // ......................................................................... rendering
  28. //TODO:?? possibly move to listItem
  29. /** render a subtitle to show the user what sort of collection this is */
  30. _renderSubtitle : function(){
  31. var $subtitle = $( '<div class="subtitle"></div>' );
  32. //TODO: would be good to get this in the subtitle
  33. //var len = this.model.elements.length;
  34. switch( this.model.get( 'collection_type' ) ){
  35. case 'list':
  36. return $subtitle.text( _l( 'a list of datasets' ) );
  37. case 'paired':
  38. return $subtitle.text( _l( 'a pair of datasets' ) );
  39. case 'list:paired':
  40. return $subtitle.text( _l( 'a list of paired datasets' ) );
  41. }
  42. return $subtitle;
  43. },
  44. // ......................................................................... foldout
  45. /** override to add linktarget to sub-panel */
  46. _getFoldoutPanelOptions : function(){
  47. var options = FoldoutListItemView.prototype._getFoldoutPanelOptions.call( this );
  48. return _.extend( options, {
  49. linkTarget : this.linkTarget
  50. });
  51. },
  52. /** override to not catch sub-panel selectors */
  53. $selector : function(){
  54. return this.$( '> .selector' );
  55. },
  56. // ......................................................................... misc
  57. /** String representation */
  58. toString : function(){
  59. var modelString = ( this.model )?( this.model + '' ):( '(no model)' );
  60. return 'DCListItemView(' + modelString + ')';
  61. }
  62. });
  63. // ............................................................................ TEMPLATES
  64. /** underscore templates */
  65. DCListItemView.prototype.templates = (function(){
  66. // use element identifier
  67. var titleBarTemplate = BASE_MVC.wrapTemplate([
  68. '<div class="title-bar clear" tabindex="0">',
  69. '<div class="title">',
  70. '<span class="name"><%- collection.element_identifier || collection.name %></span>',
  71. '</div>',
  72. '<div class="subtitle"></div>',
  73. '</div>'
  74. ], 'collection' );
  75. return _.extend( {}, FoldoutListItemView.prototype.templates, {
  76. titleBar : titleBarTemplate
  77. });
  78. }());
  79. //==============================================================================
  80. /** @class Read only view for DatasetCollectionElement.
  81. */
  82. var DCEListItemView = ListItemView.extend(
  83. /** @lends DCEListItemView.prototype */{
  84. //TODO: this might be expendable - compacted with HDAListItemView
  85. /** logger used to record this.log messages, commonly set to console */
  86. //logger : console,
  87. /** add the DCE class to the list item */
  88. className : ListItemView.prototype.className + " dataset-collection-element",
  89. /** set up */
  90. initialize : function( attributes ){
  91. if( attributes.logger ){ this.logger = this.model.logger = attributes.logger; }
  92. this.log( 'DCEListItemView.initialize:', attributes );
  93. ListItemView.prototype.initialize.call( this, attributes );
  94. },
  95. // ......................................................................... misc
  96. /** String representation */
  97. toString : function(){
  98. var modelString = ( this.model )?( this.model + '' ):( '(no model)' );
  99. return 'DCEListItemView(' + modelString + ')';
  100. }
  101. });
  102. // ............................................................................ TEMPLATES
  103. /** underscore templates */
  104. DCEListItemView.prototype.templates = (function(){
  105. // use the element identifier here - since that will persist and the user will need it
  106. var titleBarTemplate = BASE_MVC.wrapTemplate([
  107. '<div class="title-bar clear" tabindex="0">',
  108. '<div class="title">',
  109. '<span class="name"><%- element.element_identifier %></span>',
  110. '</div>',
  111. '<div class="subtitle"></div>',
  112. '</div>'
  113. ], 'element' );
  114. return _.extend( {}, ListItemView.prototype.templates, {
  115. titleBar : titleBarTemplate
  116. });
  117. }());
  118. //==============================================================================
  119. /** @class Read only view for a DatasetCollectionElement that is also an DatasetAssociation
  120. * (a dataset contained in a dataset collection).
  121. */
  122. var DatasetDCEListItemView = DATASET_LI.DatasetListItemView.extend(
  123. /** @lends DatasetDCEListItemView.prototype */{
  124. className : DATASET_LI.DatasetListItemView.prototype.className + " dataset-collection-element",
  125. /** logger used to record this.log messages, commonly set to console */
  126. //logger : console,
  127. /** set up */
  128. initialize : function( attributes ){
  129. if( attributes.logger ){ this.logger = this.model.logger = attributes.logger; }
  130. this.log( 'DatasetDCEListItemView.initialize:', attributes );
  131. DATASET_LI.DatasetListItemView.prototype.initialize.call( this, attributes );
  132. },
  133. // ......................................................................... misc
  134. /** String representation */
  135. toString : function(){
  136. var modelString = ( this.model )?( this.model + '' ):( '(no model)' );
  137. return 'DatasetDCEListItemView(' + modelString + ')';
  138. }
  139. });
  140. // ............................................................................ TEMPLATES
  141. /** underscore templates */
  142. DatasetDCEListItemView.prototype.templates = (function(){
  143. // use the element identifier here and not the dataset name
  144. //TODO:?? can we steal the DCE titlebar?
  145. var titleBarTemplate = BASE_MVC.wrapTemplate([
  146. '<div class="title-bar clear" tabindex="0">',
  147. '<span class="state-icon"></span>',
  148. '<div class="title">',
  149. '<span class="name"><%- element.element_identifier %></span>',
  150. '</div>',
  151. '</div>'
  152. ], 'element' );
  153. return _.extend( {}, DATASET_LI.DatasetListItemView.prototype.templates, {
  154. titleBar : titleBarTemplate
  155. });
  156. }());
  157. //==============================================================================
  158. /** @class Read only view for a DatasetCollectionElement that is also a DatasetCollection
  159. * (a nested DC).
  160. */
  161. var NestedDCDCEListItemView = DCListItemView.extend(
  162. /** @lends NestedDCDCEListItemView.prototype */{
  163. className : DCListItemView.prototype.className + " dataset-collection-element",
  164. /** logger used to record this.log messages, commonly set to console */
  165. // comment this out to suppress log output
  166. //logger : console,
  167. /** In this override, add the state as a class for use with state-based CSS */
  168. _swapNewRender : function( $newRender ){
  169. DCListItemView.prototype._swapNewRender.call( this, $newRender );
  170. //TODO: model currently has no state
  171. var state = this.model.get( 'state' ) || 'ok';
  172. //if( this.model.has( 'state' ) ){
  173. this.$el.addClass( 'state-' + state );
  174. //}
  175. return this.$el;
  176. },
  177. // ......................................................................... misc
  178. /** String representation */
  179. toString : function(){
  180. var modelString = ( this.model )?( this.model + '' ):( '(no model)' );
  181. return 'NestedDCDCEListItemView(' + modelString + ')';
  182. }
  183. });
  184. //==============================================================================
  185. return {
  186. DCListItemView : DCListItemView,
  187. DCEListItemView : DCEListItemView,
  188. DatasetDCEListItemView : DatasetDCEListItemView,
  189. NestedDCDCEListItemView : NestedDCDCEListItemView
  190. };
  191. });