"use strict"; /** * Licensed Materials - Property of IBM * IBM Cognos Products: admin * Copyright IBM Corp. 2015, 2017 * US Government Users Restricted Rights -Use, duplication or disclosure * restricted by GSA ADP Schedule Contract with IBM Corp. */ define(['underscore', 'bi/admin/common/Uploader', 'bi/admin/nls/StringResource'], function (_, Uploader, StringResource) { 'use strict'; //NOSONAR: meant to be strict var TopicUploader = Uploader.extend({ /** *@options.glassContext - glassContext *@options.$el - Container *@options.ajax() - ajax function to upload data *@options.ajaxOptions */ init: function init(options) { TopicUploader.inherited('init', this, arguments); _.extend(this, options); this.includeFileName = true; }, _getInput: function _getInput() { var inputOptions = this._getBaseInputOptions(); if (this.fileType && this.fileType === 'json') { inputOptions.accept = '.json'; } else { inputOptions.accept = '.txt'; } return $('', inputOptions); }, _isValidFileName: function _isValidFileName(fileName) { if (this.fileType === 'json') { return /^[a-z0-9_ \-]{1,200}\.json$/i.test(fileName); } else { return /^[a-z0-9_ \-]{1,200}\.txt$/i.test(fileName); } }, // NB - the message returned should match regexp above _getInvalidFileNameMessage: function _getInvalidFileNameMessage() { return StringResource.get('msgFileNameTopicUpload'); }, _getFileName: function _getFileName(fileName, e) { var topicName; try { var fileStr = String.fromCharCode.apply(null, new Uint8Array(e.target.result)); topicName = JSON.parse(fileStr).topicName; if (_.isUndefined(topicName) || _.isEmpty(topicName)) { topicName = fileName.substr(0, fileName.lastIndexOf('.')); } } catch (error) { return fileName.substr(0, fileName.lastIndexOf('.')); } return topicName; } }); return TopicUploader; });