MonthlyCadencePickerView.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  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/MonthlyCadencePicker.html',
  19. 'underscore',
  20. "bi/schedule/views/DailyIntervalCadencePickerView",
  21. 'bi/commons/ui/properties/DropDown',
  22. 'bi/commons/ui/properties/RadioButtonGroup'
  23. ],
  24. function (View, controler, $, t, Q, dot, template, _, DailyIntervalCadencePicker, DropDown, RadioButtonGroup) {
  25. 'use strict';
  26. var monthlyCadence = View.extend({
  27. isEditMode: false,
  28. /**
  29. * @constructor
  30. */
  31. init: function(options) {
  32. monthlyCadence.inherited('init', this, arguments);
  33. _.extend(this, options);
  34. if(typeof(this.objectInformation.descriptor)!=="undefined"){
  35. this.scheduleInfo = this.objectInformation.descriptor.scheduleInfo;
  36. this.isEditMode = true;
  37. }
  38. this.uniqueId = _.uniqueId();
  39. this.dayTypeSelector = null;
  40. this.daySelector = null;
  41. this.dayOfMonthSelector = null;
  42. this.readOnly = false;
  43. },
  44. /**
  45. * Render the new schedule view month picker section
  46. *
  47. */
  48. render: function() {
  49. var deferred = Q.defer();
  50. var htmlGenerator = dot.simpleTemplate(template);
  51. var defaultPeriod = 1;
  52. if (this.isEditMode && this.scheduleInfo.everyNPeriods > 1) {
  53. defaultPeriod = this.scheduleInfo.everyNPeriods;
  54. }
  55. this.readOnly = this.isEditMode && this.hasPermission && !this.hasPermission.write && this.hasPermission.read;
  56. var attributes = {
  57. schedule_run_on_label: t.translate("schedule_run_on_label"),
  58. schedule_repeat_interval_label: t.translate("schedule_repeat_interval_label"),
  59. schedule_of_every_n_months_value: defaultPeriod,
  60. schedule_repeat_interval_months_label: t.translate("schedule_repeat_interval_months_label"),
  61. uniqueid: this.uniqueId
  62. };
  63. this.$el.append(htmlGenerator(attributes));
  64. this._renderSelectors();
  65. this.dayTypeSelector.setValue('relative', true);
  66. if (this.isEditMode){
  67. if (this.scheduleInfo.monthlyRelative) {
  68. var day = this.scheduleInfo.monthlyRelative.monthlyRelativeDay || "monday";
  69. var week = this.scheduleInfo.monthlyRelative.monthlyRelativeWeek || "first";
  70. this.daySelector.getHTMLControl().val(week + '|' + day);
  71. }
  72. else if (this.scheduleInfo.monthlyAbsolute) {
  73. this.dayTypeSelector.setValue('absolute', true);
  74. this.dayOfMonthSelector.getHTMLControl().val(this.scheduleInfo.monthlyAbsolute.monthlyAbsoluteDay || 25);
  75. }
  76. }
  77. if(this.objectInformation.showDailyInterval){
  78. this.dailyInterval = new DailyIntervalCadencePicker({
  79. $el: this.$el,
  80. objectInformation: {
  81. descriptor: this.objectInformation.descriptor,
  82. showDailyIntervalCheckbox: true
  83. },
  84. glassContext: this.glassContext,
  85. readOnly: this.readOnly
  86. });
  87. this.dailyInterval.render();
  88. }
  89. this._setEvents();
  90. deferred.resolve(this);
  91. return deferred.promise;
  92. },
  93. _setEvents: function() {
  94. $('.schedule_every_weeks_input').on('input', function (event) {
  95. this.value = this.value.replace(/[^0-9]/g, '');
  96. });
  97. },
  98. /** All views should overwrite this function.
  99. * It takes a partially populated json schedule descriptor and adds to it
  100. * based on the properties of this view.
  101. * @param desc the partial JSON schedule descriptor
  102. * @returns the descriptor passed in, with added attributes.
  103. */
  104. toDescriptor: function(desc) {
  105. if (this.dayTypeSelector.getValue() === 'absolute') {
  106. desc.monthlyAbsolute = {
  107. monthlyAbsoluteDay: parseInt(this.dayOfMonthSelector.getHTMLControl().val(), 10)
  108. };
  109. desc.type = "monthlyAbsolute";
  110. }else {
  111. var val = this.daySelector.getHTMLControl().val();
  112. var vals = val.split('|');
  113. desc.monthlyRelative = {
  114. monthlyRelativeDay: vals[1],
  115. monthlyRelativeWeek: vals[0]
  116. };
  117. desc.type = "monthlyRelative";
  118. }
  119. desc.everyNPeriods = parseInt(this.$el.find('.schedule_every_weeks_input').val(), 10);
  120. if(this.dailyInterval) {
  121. desc = this.dailyInterval.toDescriptor(desc);
  122. }
  123. return desc;
  124. },
  125. validate: function(msgs) {
  126. if(this.dailyInterval) {
  127. msgs = this.dailyInterval.validate(msgs);
  128. // One warning at a time
  129. if ( msgs.length > 0) {
  130. return msgs;
  131. }
  132. }
  133. var parameters = {};
  134. var $everyNPeriodDiv = this.$el.find(".schedule_frequency_input_container");
  135. $everyNPeriodDiv.removeAttr('aria-invalid aria-describedby');
  136. var everyNPeriods = parseInt(this.$el.find('.schedule_every_weeks_input').val(), 10);
  137. if ( isNaN(everyNPeriods)) {
  138. parameters.param1 = t.translate("schedule_repeat_interval_label");
  139. msgs.push(t.translate("schedule_invalid_form_input_every_month_repeat_input", parameters));
  140. $everyNPeriodDiv.attr({
  141. 'aria-invalid': 'true',
  142. 'aria-describedby': msgs[0]
  143. });
  144. }
  145. return msgs;
  146. },
  147. _renderSelectors: function() {
  148. this.dayTypeSelector = new RadioButtonGroup({
  149. 'id': 'schedule_day_type_selector_' + this.uniqueId,
  150. 'el': this.$el.find('#schedule_day_type_selector_container_' + this.uniqueId),
  151. 'label': t.translate("schedule_run_on_label"),
  152. 'ariaLabel': t.translate("schedule_run_on_select_description"),
  153. 'name': 'schedule_day_type_selector',
  154. 'value': 'relative',
  155. 'indent': 2, // * 10 pixels
  156. 'separator': false,
  157. 'onChange': function(name, value){this._handleSelectors(name, value);}.bind(this),
  158. 'controlOnLeft': true,
  159. 'items': [{
  160. 'label': t.translate("schedule_relative_absolute_radio_absolute"),
  161. 'value': 'absolute'
  162. },{
  163. 'label': t.translate("schedule_relative_absolute_radio_relative"),
  164. 'value': 'relative'
  165. }],
  166. 'readOnly': this.readOnly
  167. });
  168. this.dayTypeSelector.render();
  169. this.daySelector = new DropDown({
  170. 'id': 'schedule_run_on_the_' + this.uniqueId,
  171. 'el': this.$el.find('#schedule_day_selector_container_' + this.uniqueId),
  172. 'label': t.translate("schedule_run_on_day_label"),
  173. 'ariaDescribedby': t.translate("schedule_run_on_select_description"),
  174. 'name' : 'schedule_relative_day_of_month',
  175. 'responsive': false,
  176. 'options': [{
  177. //Monday
  178. 'label': t.translate("schedule_run_on_first_monday_label"),
  179. 'value': 'first|monday',
  180. 'selected': false
  181. }, {
  182. 'label': t.translate("schedule_run_on_the_second_monday_label"),
  183. 'value': 'second|monday',
  184. 'selected': false
  185. }, {
  186. 'label': t.translate("schedule_run_on_the_third_monday_label"),
  187. 'value': 'third|monday',
  188. 'selected': false
  189. }, {
  190. 'label': t.translate("schedule_run_on_the_fourth_monday_label"),
  191. 'value': 'fourth|monday',
  192. 'selected': false
  193. }, {
  194. 'label': t.translate("schedule_run_on_the_last_monday_label"),
  195. 'value': 'last|monday',
  196. 'selected': false
  197. }, {
  198. //Tuesday
  199. 'label': t.translate("schedule_run_on_first_tuesday_label"),
  200. 'value': 'first|tuesday',
  201. 'selected': false
  202. }, {
  203. 'label': t.translate("schedule_run_on_the_second_tuesday_label"),
  204. 'value': 'second|tuesday',
  205. 'selected': false
  206. }, {
  207. 'label': t.translate("schedule_run_on_the_third_tuesday_label"),
  208. 'value': 'third|tuesday',
  209. 'selected': false
  210. }, {
  211. 'label': t.translate("schedule_run_on_the_fourth_tuesday_label"),
  212. 'value': 'fourth|tuesday',
  213. 'selected': false
  214. }, {
  215. 'label': t.translate("schedule_run_on_the_last_tuesday_label"),
  216. 'value': 'last|tuesday',
  217. 'selected': false
  218. }, {
  219. //Wednesday
  220. 'label': t.translate("schedule_run_on_first_wednesday_label"),
  221. 'value': 'first|wednesday',
  222. 'selected': false
  223. }, {
  224. 'label': t.translate("schedule_run_on_the_second_wednesday_label"),
  225. 'value': 'second|wednesday',
  226. 'selected': false
  227. }, {
  228. 'label': t.translate("schedule_run_on_the_third_wednesday_label"),
  229. 'value': 'third|wednesday',
  230. 'selected': false
  231. }, {
  232. 'label': t.translate("schedule_run_on_the_fourth_wednesday_label"),
  233. 'value': 'fourth|wednesday',
  234. 'selected': false
  235. }, {
  236. 'label': t.translate("schedule_run_on_the_last_wednesday_label"),
  237. 'value': 'last|wednesday',
  238. 'selected': false
  239. }, {
  240. //Thursday
  241. 'label': t.translate("schedule_run_on_first_thursday_label"),
  242. 'value': 'first|thursday',
  243. 'selected': false
  244. }, {
  245. 'label': t.translate("schedule_run_on_the_second_thursday_label"),
  246. 'value': 'second|thursday',
  247. 'selected': false
  248. }, {
  249. 'label': t.translate("schedule_run_on_the_third_thursday_label"),
  250. 'value': 'third|thursday',
  251. 'selected': false
  252. }, {
  253. 'label': t.translate("schedule_run_on_the_fourth_thursday_label"),
  254. 'value': 'fourth|thursday',
  255. 'selected': false
  256. }, {
  257. 'label': t.translate("schedule_run_on_the_last_thursday_label"),
  258. 'value': 'last|thursday',
  259. 'selected': false
  260. }, {
  261. //Friday
  262. 'label': t.translate("schedule_run_on_first_friday_label"),
  263. 'value': 'first|friday',
  264. 'selected': false
  265. }, {
  266. 'label': t.translate("schedule_run_on_the_second_friday_label"),
  267. 'value': 'second|friday',
  268. 'selected': false
  269. }, {
  270. 'label': t.translate("schedule_run_on_the_third_friday_label"),
  271. 'value': 'third|friday',
  272. 'selected': false
  273. }, {
  274. 'label': t.translate("schedule_run_on_the_fourth_friday_label"),
  275. 'value': 'fourth|friday',
  276. 'selected': false
  277. }, {
  278. 'label': t.translate("schedule_run_on_the_last_friday_label"),
  279. 'value': 'last|friday',
  280. 'selected': false
  281. }, {
  282. //Saturday
  283. 'label': t.translate("schedule_run_on_first_saturday_label"),
  284. 'value': 'first|saturday',
  285. 'selected': false
  286. }, {
  287. 'label': t.translate("schedule_run_on_the_second_saturday_label"),
  288. 'value': 'second|saturday',
  289. 'selected': false
  290. }, {
  291. 'label': t.translate("schedule_run_on_the_third_saturday_label"),
  292. 'value': 'third|saturday',
  293. 'selected': false
  294. }, {
  295. 'label': t.translate("schedule_run_on_the_fourth_saturday_label"),
  296. 'value': 'fourth|saturday',
  297. 'selected': false
  298. }, {
  299. 'label': t.translate("schedule_run_on_the_last_saturday_label"),
  300. 'value': 'last|saturday',
  301. 'selected': false
  302. }, {
  303. //Sunday
  304. 'label': t.translate("schedule_run_on_first_sunday_label"),
  305. 'value': 'first|sunday',
  306. 'selected': false
  307. }, {
  308. 'label': t.translate("schedule_run_on_the_second_sunday_label"),
  309. 'value': 'second|sunday',
  310. 'selected': false
  311. }, {
  312. 'label': t.translate("schedule_run_on_the_third_sunday_label"),
  313. 'value': 'third|sunday',
  314. 'selected': false
  315. }, {
  316. 'label': t.translate("schedule_run_on_the_fourth_sunday_label"),
  317. 'value': 'fourth|sunday',
  318. 'selected': false
  319. }, {
  320. 'label': t.translate("schedule_run_on_the_last_sunday_label"),
  321. 'value': 'last|sunday',
  322. 'selected': false
  323. }],
  324. 'readOnly': this.readOnly
  325. });
  326. this.daySelector.doRender();
  327. this.dayOfMonthSelector = new DropDown({
  328. 'id': 'schedule_absolute_day_of_month_' + this.uniqueId,
  329. 'el': this.$el.find('#schedule_day_selector_container_' + this.uniqueId),
  330. 'label': t.translate("schedule_run_on_day_label"),
  331. 'ariaDescribedby': t.translate("schedule_run_on_select_description"),
  332. 'name' : 'schedule_absolute_day_of_month',
  333. 'responsive': false,
  334. 'readOnly': this.readOnly,
  335. 'options': [{
  336. 'label': '1',
  337. 'value': '1',
  338. 'selected': false
  339. }, {
  340. 'label': '2',
  341. 'value': '2',
  342. 'selected': false
  343. }, {
  344. 'label': '3',
  345. 'value': '3',
  346. 'selected': false
  347. }, {
  348. 'label': '4',
  349. 'value': '4',
  350. 'selected': false
  351. }, {
  352. 'label': '5',
  353. 'value': '5',
  354. 'selected': false
  355. }, {
  356. 'label': '6',
  357. 'value': '6',
  358. 'selected': false
  359. }, {
  360. 'label': '7',
  361. 'value': '7',
  362. 'selected': false
  363. }, {
  364. 'label': '8',
  365. 'value': '8',
  366. 'selected': false
  367. }, {
  368. 'label': '9',
  369. 'value': '9',
  370. 'selected': false
  371. }, {
  372. 'label': '10',
  373. 'value': '10',
  374. 'selected': false
  375. }, {
  376. 'label': '11',
  377. 'value': '11',
  378. 'selected': false
  379. }, {
  380. 'label': '12',
  381. 'value': '12',
  382. 'selected': false
  383. }, {
  384. 'label': '13',
  385. 'value': '13',
  386. 'selected': false
  387. }, {
  388. 'label': '14',
  389. 'value': '14',
  390. 'selected': false
  391. }, {
  392. 'label': '15',
  393. 'value': '15',
  394. 'selected': false
  395. }, {
  396. 'label': '16',
  397. 'value': '16',
  398. 'selected': false
  399. }, {
  400. 'label': '17',
  401. 'value': '17',
  402. 'selected': false
  403. }, {
  404. 'label': '18',
  405. 'value': '18',
  406. 'selected': false
  407. }, {
  408. 'label': '19',
  409. 'value': '19',
  410. 'selected': false
  411. }, {
  412. 'label': '20',
  413. 'value': '20',
  414. 'selected': false
  415. }, {
  416. 'label': '21',
  417. 'value': '21',
  418. 'selected': false
  419. }, {
  420. 'label': '22',
  421. 'value': '22',
  422. 'selected': false
  423. }, {
  424. 'label': '23',
  425. 'value': '23',
  426. 'selected': false
  427. }, {
  428. 'label': '24',
  429. 'value': '24',
  430. 'selected': false
  431. }, {
  432. 'label': '25',
  433. 'value': '25',
  434. 'selected': false
  435. }, {
  436. 'label': '26',
  437. 'value': '26',
  438. 'selected': false
  439. }, {
  440. 'label': '27',
  441. 'value': '27',
  442. 'selected': false
  443. }, {
  444. 'label': '28',
  445. 'value': '28',
  446. 'selected': false
  447. }, {
  448. 'label': '29',
  449. 'value': '29',
  450. 'selected': false
  451. }, {
  452. 'label': '30',
  453. 'value': '30',
  454. 'selected': false
  455. }, {
  456. 'label': '31',
  457. 'value': '31',
  458. 'selected': false
  459. }]
  460. });
  461. this.dayOfMonthSelector.doRender();
  462. },
  463. _handleSelectors: function(name, value) {
  464. if (value === "absolute") {
  465. this.daySelector.hide();
  466. this.dayOfMonthSelector.show();
  467. }else{
  468. this.daySelector.show();
  469. this.dayOfMonthSelector.hide();
  470. }
  471. }
  472. });
  473. return monthlyCadence;
  474. });