123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- /*
- * Licensed Materials - Property of IBM
- *
- * IBM Cognos Products: SHARE
- *
- * (C) Copyright IBM Corp. 2015, 2018
- *
- * US Government Users Restricted Rights - Use, duplication or disclosure
- * restricted by GSA ADP Schedule Contract with IBM Corp.
- */
- define([
- 'underscore',
- 'bi/glass/app/ContentView',
- 'bi/content_apps/utils/GlassContextHelper',
- 'jquery',
- 'q',
- 'bi/sharecommon/utils/simpledoT',
- 'text!bi/notifications/templates/preview.html',
- 'bi/sharecommon/utils/translator',
- 'bi/commons/utils/ContentFormatter',
- 'bi/commons/utils/Utils',
- 'bi/notifications/app/n10nController',
- 'moment-timezone'
- ], function(_,View, GlassContextHelper, $, Q, dot, previewTemplate, t, stringFormater, Utils, controller, moment) {
- var DEFAULT_DELAY = 500;
- var __STANDAR_DATE_TIME_FORMAT = 'lll';
- var previewView = View.extend({
- init: function(options){
- this.events = {
- 'primaryaction .headerBack': 'close'
- };
- previewView.inherited('init', this, arguments);
- this.data = {};
- $.extend(this, options);
- this.$currentMessageItem = this.messageList.$el.find('#' + this.data.id);
- this.timezone = this.glassContext.services.userProfile.preferences.timeZoneID;
- this.contentLocale = this.glassContext.services.userProfile.preferences.contentLocale || "en-us";
- },
- setFocus: function() {
- this.$el.find('.n10n_preview_links .n10n_preview_link:first').focus();
- },
- /**
- * Set the events for the notification detail view
- *
- * @param links_map a map from unique id to link for each link
- */
- setEvents: function(links_map) {
- var glassContext = this.glassContext;
- this.$el.find('.n10n_preview_link').click(function(event) {
- // on link click, launch saved output viewer
- var link = links_map[event.target.id];
- this.openLink(link);
- }.bind(this));
- // Click event to delete the notification
- this.$el.find(".n10n_delete_icon:not(.clickBound)").addClass('clickBound').on('primaryaction', function(event) {
- if(this.messageList) {
- var deletionRequest = {
- messageId: this.data.id,
- pending: true
- };
- if (this.glassContext.services.userProfile.preferences.accessibilityFeatures) {
- this.glassContext.appController.showMessage(t.translate('delete_notification_confirm_message'), t.translate('delete_confirm'), 'info', ['ok','cancel'], undefined, function(evt) {
- if (evt.btn==='ok') {
- this._completeNotificationDelete(deletionRequest);
- this._focusNextMessage();
- }
- }.bind(this));
- } else {
- this.close();
- this.$currentMessageItem.hide(DEFAULT_DELAY);
- this.glassContext.appController.showToast(t.translate('delete_notification_message'), {
- 'type': 'info',
- 'btnLabel' : t.translate('delete_undo'),
- 'callback' : function() {
- deletionRequest.pending = false;
- this.messageList.$el.find('#' + deletionRequest.messageId).show(DEFAULT_DELAY);
- }.bind(this),
- 'newestOnTop' : true,
- 'preventDuplicates' : false,
- 'timeOut': 6000,
- 'extendedTimeOut': 1000,
- 'onHidden' : function() {this._completeNotificationDelete(deletionRequest)}.bind(this)
- });
- this._focusNextMessage();
- }
- }
- }.bind(this));
- },
- /**
- * Well set the keyboard focus to the next message in the notification list
- * or if deleting the last message set it to the previous message.
- * If no messages are found then it doesn't set focus to anything.
- */
- _focusNextMessage: function() {
- // Make sure the notification view has at least one message in it
- this.messageList.focusNextMessage(this.$currentMessageItem);
- },
- _completeNotificationDelete: function(deleteRequest) {
- var $pendingDeleteMessage = this.messageList.$el.find('#' + deleteRequest.messageId);
- var context = {
- glassContext: this.glassContext
- };
- if(deleteRequest.pending) {
- controller.deleteNotification(deleteRequest.messageId, context).done(function(){
- $pendingDeleteMessage.remove();
- });
- }
- },
- openLink: function(link) {
- var deferred = Q.defer();
- // We only care about the output object (link.id). Unfortunately getObjectProperties assumes we are dealing
- // with reports so it looks for reportId instead of id.
- var properties = {
- reportId: link.id
- };
- var context = {glassContext: this.glassContext};
- controller.getObjectProperties(properties, context).then(function(newProperties) {
- // user attached an artifact
- // Turn reportId back into outputId since it is actually the output object
- // and restore original reportId in case client can make use of it
- newProperties.outputId = newProperties.reportId;
- newProperties.reportId = link.reportId;
- this._openObject(newProperties);
- deferred.resolve();
- }.bind(this)).fail(function(xhr, status, error) {
- // May want to consider removing this error handling to let client deal with
- // missing output object.
- this.glassContext.appController.showToast(t.translate('error_object_not_found'),
- {
- 'type': 'error',
- 'newestOnTop' : true,
- 'preventDuplicates' : false,
- 'timeOut': 6000,
- 'extendedTimeOut': 1000
- });
- deferred.reject();
- }.bind(this));
- return deferred.promise;
- },
- _openObject: function(context) {
- this.glassContext.appController.hideSlideOut();
- this.glassContext.appController.openAppView( undefined, {
- content: {
- objRef: context.outputId,
- reportId: context.reportId
- }
- });
- },
- close: function() {
- this.slideout.hide();
- },
- render: function() {
- var deferred = Q.defer();
- //clear the existing second panel content
- this.$el.find('.preview_tab_panel').remove();
- GlassContextHelper.getContentLocales(this.glassContext).then(function(contentLocales) {
- this._renderPreview(contentLocales);
- deferred.resolve(this);
- }.bind(this)).fail(function() {
- console.warn("failed to retrieve the current content locales");
- this._renderPreview();
- deferred.resolve(this);
- }.bind(this));
- return deferred.promise;
- },
- _renderPreview: function(contentLocales) {
- var data = this.data || {};
- var previewAttrs = {
- id: data.id,
- type_tab: t.translate("type_tab"),
- status_tab: t.translate("status_tab"),
- owner_tab: t.translate("owner_tab"),
- type_name: data.type || "",
- owner_name: _.escape(data.sender) || "",
- subject: _.escape(data.subject) || "",
- created: moment(data.created).locale(this.contentLocale).tz(this.timezone).format(__STANDAR_DATE_TIME_FORMAT),
- content: _.escape(data.body) || "",
- links: data.links || [],
- //HARDCODE ALERT: hard core "read" for now. Wait and see the future content UI
- status_name: t.translate("status_name"),
- output_links_description: t.translate('preview_output_links_description'),
- deleteLabel: t.translate('delete_message_label'),
- back: t.translate('back')
- };
- var links_map=[];
- if (data.links) {
- for (var i = 0; i<data.links.length; i++) {
- var details = this._getLinkDetails(data.links[i], contentLocales);
- if(details && details !== "") {
- data.links[i].displayName = _.escape(data.links[i].displayName + details);
- } else {
- data.links[i].displayName = _.escape(data.links[i].displayName);
- }
- links_map[data.links[i].id] = data.links[i];
- }
- }
- var msg = dot.simpleTemplate(previewTemplate);
- this.$el.html(msg(previewAttrs));
- this.setEvents(links_map);
- this._setIcons();
- this.formatLinks();
- },
- _getLinkDetails: function(link, contentLocales) {
- var details;
- if (link.format && link.format !== "") {
- var linkFormat = this.l10nFormat(link.format);
- details = " (" + linkFormat;
- if (link.locale && link.locale !== "") {
- if (linkFormat !== "") {
- details += ", ";
- }
- details += this.l10nLocale(link.locale, contentLocales);
- }
- details += ")";
- }
- return details;
- },
- l10nLocale: function(locale, contentLocales) {
- if (contentLocales && locale in contentLocales) {
- return contentLocales[locale];
- }
- return locale;
- },
- l10nFormat: function(format) {
- switch(format) {
- case 'HTML': return t.translate("schedule_format_web");
- case 'XHTML': return t.translate("schedule_format_web");
- case 'PDF': return t.translate("schedule_format_pdf");
- case 'CSV': return t.translate("schedule_format_csv");
- case 'XML': return t.translate("schedule_format_xml");
- case 'spreadsheetML': return t.translate("schedule_format_xlsx");
- case 'xlsxData': return t.translate("schedule_format_xlsx_data");
- default: {
- console.warn("Unknown format: ", format);
- return "";
- }
- };
- },
- _setIcons: function(){
- var deleteIcon = this.$el.find(".n10n_delete_icon").has("span");
- Utils.setIcon(deleteIcon, 'common-remove-trash', t.translate('delete_notification'));
- },
- formatLinks: function() {
- var links = this.$el.find('.n10n_preview_link');
- for(var i = 0; i < links.length; i++) {
- stringFormater.middleShortenString(links[i]);
- }
- }
- });
- return previewView;
- });
|