YearlyCadencePickerView.js 17 KB

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