123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- "use strict";
- /**
- * Licensed Materials - Property of IBM
- * IBM Cognos Products: Cognos Analytics
- * Copyright IBM Corp. 2015, 2017
- * US Government Users Restricted Rights - Use,
- * duplication or disclosure restricted by GSA ADP Schedule
- * Contract with IBM Corp.
- */
- define(['doT', 'q', 'jquery', 'underscore', 'bi/admin/status/services/ApiSvc', 'bi/admin/common/slideout/BasePane', 'bi/admin/nls/StringResource', 'bi/admin/common/ui/MagicWand', 'text!bi/admin/status/templates/SetPriorityPaneTemplate.html', 'bi/commons/ui/properties/PropertyUIControl'], function (dot, Q, $, _, Api, BasePane, StringResource, MagicWand, SetPriorityPaneTemplate, PropertyUIControl) {
- //NOSONAR: needed for amd
- var SetPriorityPane = BasePane.extend({
- title: StringResource.get('setPriority'),
- init: function init(options) {
- SetPriorityPane.inherited('init', this, arguments);
- $.extend(this, options);
- this._stringResource = StringResource;
- },
- renderBody: function renderBody($body) {
- var tmpObj = {};
- tmpObj.strings = {
- 'setPriorityDescription': StringResource.get('setPriorityDescription')
- };
- var sHtml = dot.template(SetPriorityPaneTemplate)(tmpObj);
- $body.html(sHtml);
- var deferred = Q.defer(); // priority may not be a string
- var priority = Number(this.schedule[0].priority).toString();
- this.selectedPriority = this.schedule.length > 1 ? '3' : priority;
- var priorityRadioButtons = [{
- 'type': 'RadioButtonGroup',
- 'name': 'priorityRadioButton',
- 'value': this.selectedPriority,
- 'controlOnLeft': true,
- 'items': [{
- 'label': '1',
- 'value': '1'
- }, {
- 'label': '2',
- 'value': '2'
- }, {
- 'label': '3',
- 'value': '3'
- }, {
- 'label': '4',
- 'value': '4'
- }, {
- 'label': '5',
- 'value': '5'
- }],
- 'onChange': this.onChangePriority.bind(this),
- 'ariaLabel': StringResource.get('setPriority')
- }];
- this._oPropertyUIControl = new PropertyUIControl({
- 'glassContext': this.glassContext,
- 'el': this.$el.find(".bi-admin-radio-buttons-container"),
- 'items': priorityRadioButtons
- });
- this._oPropertyUIControl.render().then(function () {
- deferred.resolve(this._oPropertyUIControl);
- }.bind(this));
- return deferred.promise;
- },
- onChangePriority: function onChangePriority(group, value) {
- this.selectedPriority = value;
- },
- // call update based on object type (activity or schedule)
- callUpdateApi: function callUpdateApi(item, selectedPriority) {
- var isActivity = item.eventID !== undefined;
- if (isActivity) {
- return Api.updateUpcomingActivityPriority(item.eventID, selectedPriority, this.parentView.activityType);
- } else {
- return Api.updateSchedulePriority(item.id, selectedPriority);
- }
- },
- onHide: function onHide() {
- var self = this;
- var selectedPriority = parseInt(this.selectedPriority);
- var selectedNum = this.schedule.length;
- var fail = StringResource.get('priorityFailed');
- function showErrorToast() {
- this.glassContext.appController.showToast(fail, {
- type: 'error',
- timeOut: 3000
- });
- setTimeout(function () {
- this.parentView.listView.reload();
- }.bind(this), 500);
- }
- if (this.schedule.length > 1) {
- var aPromises = [];
- _.each(this.schedule, function (item) {
- var innerDeferred = Q.defer();
- self.callUpdateApi(item, selectedPriority).done(function () {
- innerDeferred.resolve();
- }.bind(this));
- aPromises.push(innerDeferred.promise);
- });
- Q.all(aPromises).then(function (results) {
- var sText = StringResource.get('multiSchedulePriorityUpdateSuccessful', {
- 'num': selectedNum
- });
- this.glassContext.appController.showToast(sText, {
- type: 'success'
- });
- setTimeout(function () {
- this.parentView.listView.reload();
- }.bind(this), 500);
- return deferred.resolve(results);
- }.bind(this), showErrorToast.bind(this));
- } else {
- self.callUpdateApi(this.schedule[0], selectedPriority).then(function () {
- this.glassContext.appController.showToast(StringResource.get('schedulePriorityUpdateSuccessful'), {
- type: 'success',
- timeOut: 3000
- });
- setTimeout(function () {
- this.parentView.listView.reload();
- }.bind(this), 500);
- }.bind(this), showErrorToast.bind(this));
- }
- }
- });
- return SetPriorityPane;
- });
|