"use strict"; /** * Licensed Materials - Property of IBM * IBM Cognos Products: Cognos Analytics * Copyright IBM Corp. 2016, 2017 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', 'bi/commons/ui/View', 'bi/admin/nls/StringResource', 'bacontentnav/ui/widgets/FileSelector', 'bi/commons/utils/BidiUtil', 'bacontentnav/utils/ContentStoreObject'], function (_, View, StringResource, FileSelector, BidiUtil, ContentStoreObject) { 'use strict'; //NOSONAR var ContentFilePickerBody = View.extend({ init: function init(options) { ContentFilePickerBody.inherited('init', this, arguments); _.extend(this, options); this._placeholder = StringResource.get('selectFolder'); }, render: function render() { var objectInfo; var $container = $('
'); this.$el.append($container); this._fileSelector = new FileSelector({ $el: $container, placeholder: this._placeholder, title: this._placeholder, openDialogOptions: { 'glassContext': this.glassContext, 'typesToOpen': ['folder'], 'multiSelect': false, 'onOpenCallback': this._setContentPath.bind(this), 'dialogTitle': this._placeholder, 'primaryBtnText': StringResource.get('select'), 'teamContentOnly': this.teamContentOnly } }); return this.glassContext.getSvc('.Content').then(function (contentSvc) { return new Promise(function (resolve) { if (this.controller._isCurrentValueDefined()) { var requestEndpoint = this.controller._getRequestEndpoint(contentSvc); var options = { dataType: 'json', data: { fields: 'defaultName,ancestors' } }; this.glassContext.services.ajax.get(requestEndpoint, options).then(function (result) { objectInfo = result.data[0]; resolve(); }.bind(this), function () { resolve(); }); } else { resolve(); } }.bind(this)); }.bind(this)).then(function () { return this._fileSelector.render(); }.bind(this)).then(function () { this._setFileSelectorLabel(objectInfo, true); return this.$el; }.bind(this)); }, _setFileSelectorLabel: function _setFileSelectorLabel(objectInfo, appendDefaultName) { if (objectInfo) { var path = ContentStoreObject.getLocation(objectInfo, appendDefaultName); this._fileSelector.setValue(BidiUtil.userPreferredTextDir === '' ? path : BidiUtil.enforceTextDirectionForLocation(path)); } else if (this.controller._isCurrentValueDefined()) { this._fileSelector.setValue(StringResource.get('unavailable')); } }, _setContentPath: function _setContentPath(selectedObject) { this.controller._setContentPath(selectedObject); this._setFileSelectorLabel(selectedObject[0], false); if (_.isFunction(this.onChange)) { this.onChange(this.isValueChanged()); } }, reset: function reset() { this.controller.setDefaultValue(); this._fileSelector.reset(); }, getCurrentValue: function getCurrentValue() { return this.controller.currentValue; }, isValueChanged: function isValueChanged() { return this.controller.isValueChanged(); } }); return ContentFilePickerBody; });