TeamFoldersPane.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2016, 2017
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['underscore', 'q', 'bi/admin/nls/StringResource', 'bi/commons/ui/StandardLayoutView', 'bi/commons/ui/SlideoutHeaderView', 'bi/commons/ui/ButtonBar', 'bi/admin/account/slideout/contentFilePicker/ContentFilePickerBody', 'bi/admin/account/slideout/contentFilePicker/TeamFolderController'], function (_, Q, StringResource, StandardLayoutView, SlideoutHeaderView, ButtonBar, ContentFilePickerBody, TeamFolderController) {
  9. var TeamFoldersPane = StandardLayoutView.extend({
  10. RESET_BUTTON_ID: 'resetSelectionBtn',
  11. APPLY_BUTTON_ID: 'applySelectionBtn',
  12. init: function init(options) {
  13. TeamFoldersPane.inherited('init', this, arguments);
  14. this.headerView = this._createHeader();
  15. this.bodyView = this._createBody();
  16. this.footerView = this._createFooter();
  17. },
  18. _createHeader: function _createHeader() {
  19. return new SlideoutHeaderView({
  20. 'title': this.title,
  21. 'slideout': this.slideout
  22. });
  23. },
  24. _createBody: function _createBody() {
  25. return new ContentFilePickerBody({
  26. 'glassContext': this.glassContext,
  27. 'className': 'setTeamFoldersView',
  28. 'slideout': this.slideout,
  29. 'onChange': this._onChange.bind(this),
  30. 'teamContentOnly': true,
  31. 'controller': this._createTeamFolderController()
  32. });
  33. },
  34. _createTeamFolderController: function _createTeamFolderController() {
  35. return new TeamFolderController({
  36. 'currentValue': this.currentValue
  37. });
  38. },
  39. _createFooter: function _createFooter() {
  40. return new ButtonBar({
  41. buttons: [{
  42. 'id': this.APPLY_BUTTON_ID,
  43. 'label': StringResource.get('apply'),
  44. 'onSelect': this._onApply.bind(this),
  45. 'disabled': true
  46. }, {
  47. 'id': this.RESET_BUTTON_ID,
  48. 'label': StringResource.get('clear'),
  49. 'onSelect': this._onReset.bind(this),
  50. 'disabled': !this.currentValue || !this.currentValue.pathRef
  51. }]
  52. });
  53. },
  54. render: function render() {
  55. var promise = TeamFoldersPane.inherited('render', this);
  56. promise.then(function () {
  57. _.each(this.footerView.getButtonList(), function (button) {
  58. button.disabled ? button.disable() : button.enable();
  59. }.bind(this));
  60. }.bind(this));
  61. return promise;
  62. },
  63. _onReset: function _onReset() {
  64. this.bodyView.reset();
  65. if (this.bodyView.isValueChanged()) {
  66. this._getApplyButton().enable();
  67. } else {
  68. this._getApplyButton().disable();
  69. }
  70. this._getResetButton().disable();
  71. },
  72. _onApply: function _onApply() {
  73. if (_.isFunction(this.onApplyCallback)) {
  74. this.onApplyCallback(this.bodyView.getCurrentValue());
  75. }
  76. _.each(this.footerView.getButtonList(), function (button) {
  77. button.disable();
  78. }.bind(this));
  79. },
  80. _onChange: function _onChange(isValueChanged) {
  81. if (isValueChanged) {
  82. _.each(this.footerView.getButtonList(), function (button) {
  83. button.enable();
  84. }.bind(this));
  85. } else {
  86. this._getApplyButton().disable();
  87. }
  88. },
  89. _getApplyButton: function _getApplyButton() {
  90. return this.footerView.getButtonList()[this.APPLY_BUTTON_ID];
  91. },
  92. _getResetButton: function _getResetButton() {
  93. return this.footerView.getButtonList()[this.RESET_BUTTON_ID];
  94. }
  95. });
  96. return TeamFoldersPane;
  97. });