TriggerCadencePickerView.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Licensed Materials - Property of IBM
  3. *
  4. * IBM Cognos Products: SHARE
  5. *
  6. * (C) Copyright IBM Corp. 2015, 2017
  7. *
  8. * US Government Users Restricted Rights - Use, duplication or disclosure
  9. * restricted by GSA ADP Schedule Contract with IBM Corp.
  10. */
  11. define([
  12. 'bi/schedule/views/CadencePickerView',
  13. 'bi/schedule/app/appControler',
  14. 'jquery',
  15. 'bi/sharecommon/utils/translator',
  16. 'q',
  17. 'bi/sharecommon/utils/simpledoT',
  18. 'text!bi/schedule/templates/TriggerCadencePicker.html',
  19. 'underscore'
  20. ],
  21. function (View, controler, $, t, Q, dot, template, _) {
  22. 'use strict';
  23. var triggerCadence = View.extend({
  24. /**
  25. * @constructor
  26. */
  27. init: function(options) {
  28. triggerCadence.inherited('init', this, arguments);
  29. this.isEditMode = false;
  30. this.scheduleInfo = {};
  31. _.extend(this, options);
  32. if(typeof(this.objectInformation.descriptor)!=="undefined"){
  33. this.scheduleInfo = this.objectInformation.descriptor.scheduleInfo;
  34. this.isEditMode = true;
  35. }
  36. this.uniqueId = _.uniqueId();
  37. },
  38. /**
  39. * Render the new schedule view month picker section
  40. *
  41. */
  42. render: function() {
  43. var deferred = Q.defer();
  44. var htmlGenerator = dot.simpleTemplate(template);
  45. var triggerName = " ";
  46. if (this.isEditMode && this.scheduleInfo.trigger) {
  47. triggerName = this.scheduleInfo.trigger.triggerName;
  48. }
  49. var attributes = {
  50. schedule_trigger_name_label: t.translate("schedule_trigger_name_label"),
  51. schedule_trigger_name_value: triggerName,
  52. uniqueId: this.uniqueId
  53. };
  54. this.$el.append(htmlGenerator(attributes));
  55. deferred.resolve(this);
  56. return deferred.promise;
  57. },
  58. /** All views should overwrite this function.
  59. * It takes a partially populated json schedule descriptor and adds to it
  60. * based on the properties of this view.
  61. * @param desc the partial JSON schedule descriptor
  62. * @returns the descriptor passed in, with added attributes.
  63. */
  64. toDescriptor: function(desc) {
  65. desc.trigger = {
  66. triggerName: _.escape(this.$el.find('.schedule_trigger_name_input').val().trim())
  67. };
  68. desc.everyNPeriods = 1; // mandatory, even though it makes little sense for triggers
  69. return desc;
  70. },
  71. validate: function(msgs) {
  72. if(this.$el.find('.schedule_trigger_name_input').val().trim() === "") {
  73. msgs.push(t.translate("schedule_invalid_trigger_name_empty"));
  74. }
  75. return msgs;
  76. }
  77. });
  78. return triggerCadence;
  79. });