BaseCustomizationTab.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. "use strict";
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Cognos Analytics
  5. * Copyright IBM Corp. 2017, 2017
  6. * US Government Users Restricted Rights - Use, duplication or disclosure
  7. * restricted by GSA ADP Schedule Contract with IBM Corp.
  8. */
  9. define(['underscore', 'bi/admin/nls/StringResource', 'bi/glass/app/ContentView', 'bi/commons/ui/properties/PropertyUIControl', 'bi/commons/ui/dialogs/ConfirmationDialog', 'bi/admin/common/utils/AJAXUtils', 'ba-react-admin/ba-react-admin.min'], function (_, StringResource, ContentView, PropertyUIControl, ConfirmationDialog, AJAXUtils, AdminReact) {
  10. 'use strict'; //NOSONAR
  11. var BaseCustomizationTab = ContentView.extend({
  12. init: function init(options) {
  13. BaseCustomizationTab.inherited('init', this, arguments);
  14. _.extend(this, options);
  15. this._customizationService = null;
  16. this._customizations = null;
  17. },
  18. _getNewPropertyUIControl: function _getNewPropertyUIControl(options) {
  19. return new PropertyUIControl(options);
  20. },
  21. render: function render() {
  22. return this._getCustomizations().then(function () {
  23. this._propertyUIControl = this._getNewPropertyUIControl({
  24. 'el': this.$el,
  25. 'glassContext': this.glassContext,
  26. 'slideout': this.slideout,
  27. 'items': this._getPropertyControlItems()
  28. });
  29. return this._propertyUIControl.render();
  30. }.bind(this));
  31. },
  32. _getCustomizations: function _getCustomizations() {
  33. return Promise.try(function () {
  34. if (this._customizations === null) {
  35. return this._customizationService.getCustomizations(this.objectInfo.id).then(function (result) {
  36. this._customizations = result;
  37. if (result.ui_excludedFeatures && result.ui_excludedFeatures.ids) {
  38. AdminReact.FeaturesTreeStore.setDisabledOptions(result.ui_excludedFeatures.ids);
  39. }
  40. return this._setHomeViewValue();
  41. }.bind(this));
  42. }
  43. }.bind(this));
  44. },
  45. _getPropertyControlItems: function _getPropertyControlItems() {
  46. var propertyControlItems = [];
  47. propertyControlItems.push(this._getHomePagePropertyControlItem());
  48. propertyControlItems.push(this._getFeaturesPropertyControlItem());
  49. propertyControlItems.push(this._getThemesPropertyControlItem());
  50. propertyControlItems.push(this._getTeamFoldersPropertyControlItem());
  51. propertyControlItems.push(this._getCustomSaveLocationControlItem());
  52. propertyControlItems.push(this._getGlobalParametersControlItem());
  53. var advancedProps = this._getAdvancedPropertyControlItem();
  54. if (advancedProps !== undefined) {
  55. propertyControlItems.push(advancedProps);
  56. }
  57. return propertyControlItems;
  58. },
  59. _getHomePagePropertyControlItem: function _getHomePagePropertyControlItem() {
  60. return {
  61. 'name': 'homePage',
  62. 'label': StringResource.get('homePage'),
  63. 'value': this.homeViewValue,
  64. 'type': 'SingleLineValue',
  65. 'ellipses': true,
  66. 'editCallback': this._showHomePagePanel.bind(this)
  67. };
  68. },
  69. _getFeaturesPropertyControlItem: function _getFeaturesPropertyControlItem() {
  70. var excludedFeatures = this._getExcludedFeatures();
  71. return {
  72. 'name': 'features',
  73. 'label': StringResource.get('features'),
  74. 'value': excludedFeatures.ids.length > 0 ? StringResource.get('customized') : StringResource.get('default'),
  75. 'type': 'SingleLineValue',
  76. 'disabled': false,
  77. 'ellipses': true,
  78. 'editCallback': this._showFeaturesPanel.bind(this)
  79. };
  80. },
  81. _getThemesPropertyControlItem: function _getThemesPropertyControlItem() {
  82. var customizedTheme = this._getTheme();
  83. return {
  84. 'name': 'themes',
  85. 'label': StringResource.get('themes'),
  86. 'value': customizedTheme,
  87. 'type': 'SingleLineValue',
  88. 'disabled': false,
  89. 'ellipses': true,
  90. 'editCallback': this._showThemesPanel.bind(this)
  91. };
  92. },
  93. _getTeamFoldersPropertyControlItem: function _getTeamFoldersPropertyControlItem() {
  94. var teamFolders = this._getTeamFolders();
  95. return {
  96. 'name': 'teamFolders',
  97. 'label': StringResource.get('teamFolders'),
  98. 'value': this._getTeamFoldersLabel(teamFolders),
  99. 'type': 'SingleLineValue',
  100. 'disabled': false,
  101. 'ellipses': true,
  102. 'editCallback': this._showTeamFoldersPanel.bind(this)
  103. };
  104. },
  105. _getCustomSaveLocationControlItem: function _getCustomSaveLocationControlItem() {
  106. var CustomSaveLocation = this._getCustomSaveLocation();
  107. return {
  108. 'name': 'uploadLocation',
  109. 'label': StringResource.get('defaultUploadLocation'),
  110. 'value': this._getCustomSaveLocationLabel(CustomSaveLocation),
  111. // default or customized
  112. 'type': 'SingleLineValue',
  113. 'disabled': false,
  114. 'ellipses': true,
  115. 'editCallback': this._showCustomSaveLocationPanel.bind(this)
  116. };
  117. },
  118. _getGlobalParametersControlItem: function _getGlobalParametersControlItem() {
  119. return {
  120. 'name': 'roleParameters',
  121. 'label': StringResource.get('globalParameters'),
  122. 'value': StringResource.get('connection_details'),
  123. 'type': 'SingleLineValue',
  124. 'disabled': false,
  125. 'ellipses': true,
  126. 'editCallback': this._showGlobalParametersPanel.bind(this)
  127. };
  128. },
  129. _showFeaturesPanel: function _showFeaturesPanel() {
  130. this._featuresSlideout = this.glassContext.appController.showSlideOut({
  131. 'parent': this.slideout,
  132. 'width': '400px',
  133. 'label': StringResource.get('features'),
  134. 'content': {
  135. 'module': 'bi/admin/account/slideout/features/FeaturesPane',
  136. 'parentView': this,
  137. 'glassContext': this.glassContext,
  138. 'objectInfo': this.objectInfo,
  139. 'onReset': this.confirmResetFeature.bind(this),
  140. 'onApply': this.applyFeatureLensing.bind(this),
  141. 'isCustomized': this._getExcludedFeatures().ids.length > 0,
  142. 'getExcludeList': this._getExcludedFeatures.bind(this),
  143. 'getPerspectives': this.getLensiblePerspectives.bind(this)
  144. }
  145. });
  146. },
  147. _showHomePagePanel: function _showHomePagePanel() {
  148. this._homeSlideout = this.glassContext.appController.showSlideOut({
  149. parent: this.slideout,
  150. width: '400px',
  151. label: StringResource.get('homePage'),
  152. content: {
  153. 'module': 'bi/admin/system/HomePerspectiveListView',
  154. 'glassContext': this.glassContext,
  155. 'title': StringResource.get('homePage'),
  156. 'currentValue': this._getHomePage(),
  157. 'homeViewValue': this.homeViewValue,
  158. 'perspectivesURL': 'v1/perspectives',
  159. 'onApplyCallback': this.setHomePage.bind(this),
  160. 'global': false
  161. }
  162. });
  163. },
  164. _showThemesPanel: function _showThemesPanel() {
  165. this._themesSlideout = this.glassContext.appController.showSlideOut({
  166. parent: this.slideout,
  167. width: '400px',
  168. label: StringResource.get('themes'),
  169. content: {
  170. module: 'bi/admin/system/ThemesTab',
  171. showTitle: true,
  172. glassContext: this.glassContext,
  173. title: StringResource.get('themes'),
  174. getDefaultThemeCallback: function () {
  175. return $.when(this._getTheme());
  176. }.bind(this),
  177. setDefaultThemeCallback: this.setTheme.bind(this),
  178. global: false
  179. }
  180. });
  181. },
  182. _showTeamFoldersPanel: function _showTeamFoldersPanel() {
  183. this._teamFoldersSlideout = this.glassContext.appController.showSlideOut({
  184. parent: this.slideout,
  185. width: '400px',
  186. label: StringResource.get('teamFolders'),
  187. content: {
  188. 'module': 'bi/admin/account/slideout/teamfolders/TeamFoldersPane',
  189. 'glassContext': this.glassContext,
  190. 'title': StringResource.get('teamFolders'),
  191. 'currentValue': this._getTeamFolders(),
  192. 'onApplyCallback': this.setTeamFolders.bind(this),
  193. 'global': false,
  194. 'teamContentOnly': true
  195. }
  196. });
  197. },
  198. _showCustomSaveLocationPanel: function _showCustomSaveLocationPanel() {
  199. this._CustomSaveLocationSlideout = this.glassContext.appController.showSlideOut({
  200. parent: this.slideout,
  201. width: '400px',
  202. label: StringResource.get('uploadLocation'),
  203. content: {
  204. 'module': 'bi/admin/account/slideout/teamfolders/CustomSaveLocationPane',
  205. 'glassContext': this.glassContext,
  206. 'title': StringResource.get('defaultUploadLocation'),
  207. 'currentValue': this._getCustomSaveLocation(),
  208. 'onApplyCallback': this.setCustomSaveLocation.bind(this),
  209. 'global': false,
  210. 'teamContentOnly': true
  211. }
  212. });
  213. },
  214. _setHomeViewValue: function _setHomeViewValue() {
  215. return Promise.try(function () {
  216. var defaultHome = this._getHomePage();
  217. if (_.isUndefined(defaultHome.content)) {
  218. this.homeViewValue = defaultHome.perspective;
  219. } else {
  220. return this.glassContext.services.ajax.ajax({
  221. type: 'GET',
  222. url: 'v1/path?path=' + encodeURIComponent(defaultHome.content.pathRef)
  223. }).then(function (object) {
  224. this.homeViewValue = _.isUndefined(object.data[0]) ? StringResource.get('unavailable') : object.data[0].defaultName;
  225. }.bind(this));
  226. }
  227. }.bind(this)).catch(function (err) {
  228. this.homeViewValue = StringResource.get('unavailable');
  229. this.logger.error(err);
  230. }.bind(this));
  231. },
  232. _getExcludedFeatures: function _getExcludedFeatures() {
  233. var excludedFeatures = {
  234. ids: AdminReact.FeaturesTreeStore.disabledOptions.slice()
  235. };
  236. return this._customizations ? excludedFeatures : null;
  237. },
  238. _getParameters: function _getParameters() {
  239. return this._customizations ? this._customizations.parameters : {};
  240. },
  241. _getParameterValues: function _getParameterValues() {
  242. return this._customizations ? this._customizations.parameter_values : {};
  243. },
  244. _getHomePage: function _getHomePage() {
  245. return this._customizations ? this._customizations.ui_homePage : null;
  246. },
  247. _getTheme: function _getTheme() {
  248. return this._customizations ? this._customizations.ui_theme : null;
  249. },
  250. _getTeamFolders: function _getTeamFolders() {
  251. return this._customizations ? this._customizations.ui_teamFolders : null;
  252. },
  253. _getCustomSaveLocation: function _getCustomSaveLocation() {
  254. return this._customizations ? this._customizations.fileUpload_location : null;
  255. },
  256. getLensiblePerspectives: function getLensiblePerspectives() {
  257. return this.glassContext.services.ajax.ajax({
  258. 'method': 'GET',
  259. 'contentType': 'application/json; charset=utf-8',
  260. 'dataType': 'json',
  261. 'url': AJAXUtils.getPath('getPerspective') + '?fields=definition&lensable=true'
  262. });
  263. },
  264. applyFeatureLensing: function applyFeatureLensing() {
  265. return this._customizationService.setExcludedFeatures(this.objectInfo.id, this._getExcludedFeatures()).then(function (result) {
  266. this._customizations = result;
  267. this._updateFeatureControlItem();
  268. if (this._featuresSlideout) {
  269. this._featuresSlideout.hide();
  270. }
  271. this.glassContext.appController.showToast(StringResource.get('featuresSetMsg'), {
  272. type: 'success'
  273. });
  274. return this._refresh();
  275. }.bind(this));
  276. },
  277. confirmResetFeature: function confirmResetFeature() {
  278. var oDialog = this._getNewConfirmationDialog('confirmApplyChanges', StringResource.get('confirmDefaultTitle'), StringResource.get('confirmDefaultMessage'));
  279. oDialog.confirm(this.resetFeatureLensing.bind(this));
  280. },
  281. _getNewConfirmationDialog: function _getNewConfirmationDialog(type, title, message) {
  282. return new ConfirmationDialog(type, title, message);
  283. },
  284. resetFeatureLensing: function resetFeatureLensing() {
  285. return this._customizationService.resetFeatures(this.objectInfo.id).then(function (result) {
  286. this._customizations = result;
  287. AdminReact.FeaturesTreeStore.clearDisabledOptions();
  288. this._updateFeatureControlItem();
  289. this.glassContext.appController.showToast(StringResource.get('featuresResetMsg'), {
  290. type: 'success'
  291. });
  292. if (this._featuresSlideout) {
  293. this._featuresSlideout.hide();
  294. this._showFeaturesPanel();
  295. }
  296. }.bind(this));
  297. },
  298. _updateFeatureControlItem: function _updateFeatureControlItem() {
  299. if (this._propertyUIControl) {
  300. var excludedFeatures = this._customizations.ui_excludedFeatures;
  301. var value = excludedFeatures.ids.length > 0 ? StringResource.get('customized') : StringResource.get('default');
  302. this._propertyUIControl.getProperty('features').setValue(value);
  303. }
  304. },
  305. setHomePage: function setHomePage(homePage) {
  306. return this._customizationService.setHomePage(this.objectInfo.id, homePage.value).then(function (result) {
  307. this._customizations = result;
  308. this._propertyUIControl.getProperty('homePage').setValue(homePage.name);
  309. this.homeViewValue = homePage.name;
  310. if (this._homeSlideout) {
  311. this._homeSlideout.hide();
  312. }
  313. this.glassContext.appController.showToast(StringResource.get('defaultHomeViewSet'), {
  314. type: 'success'
  315. });
  316. return this._refresh();
  317. }.bind(this));
  318. },
  319. setTheme: function setTheme(theme) {
  320. return this._customizationService.setTheme(this.objectInfo.id, theme).then(function (result) {
  321. this._customizations = result;
  322. this._propertyUIControl.getProperty('themes').setValue(theme || StringResource.get('default'));
  323. if (this._themesSlideout) {
  324. this._themesSlideout.hide();
  325. }
  326. return this._refresh();
  327. }.bind(this));
  328. },
  329. setTeamFolders: function setTeamFolders(teamFolders) {
  330. return this._customizationService.setTeamFolders(this.objectInfo.id, teamFolders).then(function (result) {
  331. this._customizations = result;
  332. var label = this._getTeamFoldersLabel(this._customizations.ui_teamFolders);
  333. this._propertyUIControl.getProperty('teamFolders').setValue(label);
  334. if (this._teamFoldersSlideout) {
  335. this._teamFoldersSlideout.hide();
  336. }
  337. var message = this._customizations.ui_teamFolders.pathRef ? StringResource.get('teamFoldersSetMsg') : StringResource.get('teamFoldersResetMsg');
  338. this.glassContext.appController.showToast(message, {
  339. type: 'success'
  340. });
  341. return this._refresh();
  342. }.bind(this));
  343. },
  344. setCustomSaveLocation: function setCustomSaveLocation(customSaveLocation) {
  345. return this._customizationService.setCustomSaveLocation(this.objectInfo.id, customSaveLocation).then(function (result) {
  346. this._customizations = result;
  347. var label = this._getCustomSaveLocationLabel(this._customizations.fileUpload_location);
  348. this._propertyUIControl.getProperty('uploadLocation').setValue(label);
  349. if (this._CustomSaveLocationSlideout) {
  350. this._CustomSaveLocationSlideout.hide();
  351. }
  352. var message = this._customizations.fileUpload_location !== ".my_folders" ? StringResource.get('fileUpload_locationSetMsg') : StringResource.get('fileUpload_locationResetMsg');
  353. this.glassContext.appController.showToast(message, {
  354. type: 'success'
  355. });
  356. return this._refresh();
  357. }.bind(this));
  358. },
  359. _getTeamFoldersLabel: function _getTeamFoldersLabel(teamFolders) {
  360. return teamFolders && teamFolders.pathRef ? StringResource.get('customized') : '';
  361. },
  362. _getCustomSaveLocationLabel: function _getCustomSaveLocationLabel(customSaveLocation) {
  363. return customSaveLocation && customSaveLocation !== ".my_folders" ? StringResource.get('customized') : StringResource.get('default');
  364. }
  365. });
  366. return BaseCustomizationTab;
  367. });