You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

systemtagsinfoviewtoggleview.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. *
  3. * @copyright Copyright (c) 2017, Daniel Calviño Sánchez (danxuliu@gmail.com)
  4. *
  5. * @license GNU AGPL version 3 or any later version
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as
  9. * published by the Free Software Foundation, either version 3 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. (function(OCA) {
  22. var TEMPLATE =
  23. '<span class="icon icon-tag"/>' + t('systemtags', 'Tags');
  24. /**
  25. * @class OCA.SystemTags.SystemTagsInfoViewToggleView
  26. * @classdesc
  27. *
  28. * View to toggle the visibility of a SystemTagsInfoView.
  29. *
  30. * This toggle view must be explicitly rendered before it is used.
  31. */
  32. var SystemTagsInfoViewToggleView = OC.Backbone.View.extend(
  33. /** @lends OC.Backbone.View.prototype */ {
  34. tagName: 'span',
  35. className: 'tag-label',
  36. events: {
  37. 'click': 'click'
  38. },
  39. /**
  40. * @type OCA.SystemTags.SystemTagsInfoView
  41. */
  42. _systemTagsInfoView: null,
  43. template: function(data) {
  44. if (!this._template) {
  45. this._template = Handlebars.compile(TEMPLATE);
  46. }
  47. return this._template(data);
  48. },
  49. /**
  50. * Initialize this toggle view.
  51. *
  52. * The options must provide a systemTagsInfoView parameter that
  53. * references the SystemTagsInfoView to associate to this toggle view.
  54. */
  55. initialize: function(options) {
  56. var self = this;
  57. options = options || {};
  58. this._systemTagsInfoView = options.systemTagsInfoView;
  59. if (!this._systemTagsInfoView) {
  60. throw 'Missing required parameter "systemTagsInfoView"';
  61. }
  62. },
  63. /**
  64. * Toggles the visibility of the associated SystemTagsInfoView.
  65. *
  66. * When the systemTagsInfoView is shown its dropdown is also opened.
  67. */
  68. click: function() {
  69. if (this._systemTagsInfoView.isVisible()) {
  70. this._systemTagsInfoView.hide();
  71. } else {
  72. this._systemTagsInfoView.show();
  73. this._systemTagsInfoView.openDropdown();
  74. }
  75. },
  76. /**
  77. * Renders this toggle view.
  78. *
  79. * @return OCA.SystemTags.SystemTagsInfoViewToggleView this object.
  80. */
  81. render: function() {
  82. this.$el.html(this.template());
  83. return this;
  84. },
  85. });
  86. OCA.SystemTags.SystemTagsInfoViewToggleView = SystemTagsInfoViewToggleView;
  87. })(OCA);