SetPriorityPane.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. "use strict";
  2. /**
  3. *  Licensed Materials - Property of IBM  
  4. * IBM Cognos Products: Cognos Analytics  
  5. * Copyright IBM Corp. 2015, 2017  
  6. * US Government Users Restricted Rights - Use,
  7. * duplication or disclosure restricted by GSA ADP Schedule
  8. * Contract with IBM Corp.  
  9. */
  10. 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) {
  11. //NOSONAR: needed for amd
  12. var SetPriorityPane = BasePane.extend({
  13. title: StringResource.get('setPriority'),
  14. init: function init(options) {
  15. SetPriorityPane.inherited('init', this, arguments);
  16. $.extend(this, options);
  17. this._stringResource = StringResource;
  18. },
  19. renderBody: function renderBody($body) {
  20. var tmpObj = {};
  21. tmpObj.strings = {
  22. 'setPriorityDescription': StringResource.get('setPriorityDescription')
  23. };
  24. var sHtml = dot.template(SetPriorityPaneTemplate)(tmpObj);
  25. $body.html(sHtml);
  26. var deferred = Q.defer(); // priority may not be a string
  27. var priority = Number(this.schedule[0].priority).toString();
  28. this.selectedPriority = this.schedule.length > 1 ? '3' : priority;
  29. var priorityRadioButtons = [{
  30. 'type': 'RadioButtonGroup',
  31. 'name': 'priorityRadioButton',
  32. 'value': this.selectedPriority,
  33. 'controlOnLeft': true,
  34. 'items': [{
  35. 'label': '1',
  36. 'value': '1'
  37. }, {
  38. 'label': '2',
  39. 'value': '2'
  40. }, {
  41. 'label': '3',
  42. 'value': '3'
  43. }, {
  44. 'label': '4',
  45. 'value': '4'
  46. }, {
  47. 'label': '5',
  48. 'value': '5'
  49. }],
  50. 'onChange': this.onChangePriority.bind(this),
  51. 'ariaLabel': StringResource.get('setPriority')
  52. }];
  53. this._oPropertyUIControl = new PropertyUIControl({
  54. 'glassContext': this.glassContext,
  55. 'el': this.$el.find(".bi-admin-radio-buttons-container"),
  56. 'items': priorityRadioButtons
  57. });
  58. this._oPropertyUIControl.render().then(function () {
  59. deferred.resolve(this._oPropertyUIControl);
  60. }.bind(this));
  61. return deferred.promise;
  62. },
  63. onChangePriority: function onChangePriority(group, value) {
  64. this.selectedPriority = value;
  65. },
  66. // call update based on object type (activity or schedule)
  67. callUpdateApi: function callUpdateApi(item, selectedPriority) {
  68. var isActivity = item.eventID !== undefined;
  69. if (isActivity) {
  70. return Api.updateUpcomingActivityPriority(item.eventID, selectedPriority, this.parentView.activityType);
  71. } else {
  72. return Api.updateSchedulePriority(item.id, selectedPriority);
  73. }
  74. },
  75. onHide: function onHide() {
  76. var self = this;
  77. var selectedPriority = parseInt(this.selectedPriority);
  78. var selectedNum = this.schedule.length;
  79. var fail = StringResource.get('priorityFailed');
  80. function showErrorToast() {
  81. this.glassContext.appController.showToast(fail, {
  82. type: 'error',
  83. timeOut: 3000
  84. });
  85. setTimeout(function () {
  86. this.parentView.listView.reload();
  87. }.bind(this), 500);
  88. }
  89. if (this.schedule.length > 1) {
  90. var aPromises = [];
  91. _.each(this.schedule, function (item) {
  92. var innerDeferred = Q.defer();
  93. self.callUpdateApi(item, selectedPriority).done(function () {
  94. innerDeferred.resolve();
  95. }.bind(this));
  96. aPromises.push(innerDeferred.promise);
  97. });
  98. Q.all(aPromises).then(function (results) {
  99. var sText = StringResource.get('multiSchedulePriorityUpdateSuccessful', {
  100. 'num': selectedNum
  101. });
  102. this.glassContext.appController.showToast(sText, {
  103. type: 'success'
  104. });
  105. setTimeout(function () {
  106. this.parentView.listView.reload();
  107. }.bind(this), 500);
  108. return deferred.resolve(results);
  109. }.bind(this), showErrorToast.bind(this));
  110. } else {
  111. self.callUpdateApi(this.schedule[0], selectedPriority).then(function () {
  112. this.glassContext.appController.showToast(StringResource.get('schedulePriorityUpdateSuccessful'), {
  113. type: 'success',
  114. timeOut: 3000
  115. });
  116. setTimeout(function () {
  117. this.parentView.listView.reload();
  118. }.bind(this), 500);
  119. }.bind(this), showErrorToast.bind(this));
  120. }
  121. }
  122. });
  123. return SetPriorityPane;
  124. });