detailtabview.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. (function() {
  7. /**
  8. * @class OCA.Files.DetailTabView
  9. * @classdesc
  10. *
  11. * Base class for tab views to display file information.
  12. *
  13. */
  14. var DetailTabView = OC.Backbone.View.extend({
  15. tag: 'div',
  16. className: 'tab',
  17. /**
  18. * Tab label
  19. */
  20. _label: null,
  21. _template: null,
  22. initialize: function(options) {
  23. options = options || {};
  24. if (!this.id) {
  25. this.id = 'detailTabView' + DetailTabView._TAB_COUNT;
  26. DetailTabView._TAB_COUNT++;
  27. }
  28. if (options.order) {
  29. this.order = options.order || 0;
  30. }
  31. },
  32. /**
  33. * Returns the extra CSS classes used by the tabs container when this
  34. * tab is the selected one.
  35. *
  36. * In general you should not extend this method, as tabs should not
  37. * modify the classes of its container; this is reserved as a last
  38. * resort for very specific cases in which there is no other way to get
  39. * the proper style or behaviour.
  40. *
  41. * @return {String} space-separated CSS classes
  42. */
  43. getTabsContainerExtraClasses: function() {
  44. return '';
  45. },
  46. /**
  47. * Returns the tab label
  48. *
  49. * @return {String} label
  50. */
  51. getLabel: function() {
  52. return 'Tab ' + this.id;
  53. },
  54. /**
  55. * Returns the tab label
  56. *
  57. * @return {String}|{null} icon class
  58. */
  59. getIcon: function() {
  60. return null
  61. },
  62. /**
  63. * returns the jQuery object for HTML output
  64. *
  65. * @returns {jQuery}
  66. */
  67. get$: function() {
  68. return this.$el;
  69. },
  70. /**
  71. * Renders this details view
  72. *
  73. * @abstract
  74. */
  75. render: function() {
  76. // to be implemented in subclass
  77. // FIXME: code is only for testing
  78. this.$el.html('<div>Hello ' + this.id + '</div>');
  79. },
  80. /**
  81. * Sets the file info to be displayed in the view
  82. *
  83. * @param {OCA.Files.FileInfoModel} fileInfo file info to set
  84. */
  85. setFileInfo: function(fileInfo) {
  86. if (this.model !== fileInfo) {
  87. this.model = fileInfo;
  88. this.render();
  89. }
  90. },
  91. /**
  92. * Returns the file info.
  93. *
  94. * @return {OCA.Files.FileInfoModel} file info
  95. */
  96. getFileInfo: function() {
  97. return this.model;
  98. },
  99. /**
  100. * Load the next page of results
  101. */
  102. nextPage: function() {
  103. // load the next page, if applicable
  104. },
  105. /**
  106. * Returns whether the current tab is able to display
  107. * the given file info, for example based on mime type.
  108. *
  109. * @param {OCA.Files.FileInfoModel} fileInfo file info model
  110. * @return {boolean} whether to display this tab
  111. */
  112. canDisplay: function(fileInfo) {
  113. return true;
  114. }
  115. });
  116. DetailTabView._TAB_COUNT = 0;
  117. OCA.Files = OCA.Files || {};
  118. OCA.Files.DetailTabView = DetailTabView;
  119. })();