form_extended.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. // form
  2. test('form checks', function() {
  3. App.TicketPriority.refresh([
  4. {
  5. id: 1,
  6. name: '1 low',
  7. note: 'some note 1',
  8. active: true,
  9. created_at: '2014-06-10T11:17:34.000Z',
  10. },
  11. {
  12. id: 2,
  13. name: '2 normal',
  14. note: 'some note 2',
  15. active: false,
  16. created_at: '2014-06-10T10:17:34.000Z',
  17. },
  18. {
  19. id: 3,
  20. name: '3 high',
  21. note: 'some note 3',
  22. active: true,
  23. created_at: '2014-06-10T10:17:44.000Z',
  24. },
  25. {
  26. id: 4,
  27. name: '4 very high',
  28. note: 'some note 4',
  29. active: true,
  30. created_at: '2014-06-10T10:17:54.000Z',
  31. },
  32. {
  33. id: 5,
  34. name: '5 xxx very high',
  35. note: 'some note 5',
  36. active: false,
  37. created_at: '2014-06-10T10:17:56.000Z',
  38. },
  39. ])
  40. App.TicketState.refresh([
  41. {
  42. id: 1,
  43. name: 'new',
  44. note: 'some note 1',
  45. active: true,
  46. created_at: '2014-06-10T11:17:34.000Z',
  47. },
  48. {
  49. id: 2,
  50. name: 'open',
  51. note: 'some note 2',
  52. active: true,
  53. created_at: '2014-06-10T10:17:34.000Z',
  54. },
  55. {
  56. id: 3,
  57. name: 'should not be shown',
  58. note: 'some note 3',
  59. active: false,
  60. created_at: '2014-06-10T10:17:34.000Z',
  61. },
  62. ])
  63. App.User.refresh([
  64. {
  65. id: 47,
  66. login: 'bod@example.com',
  67. email: 'bod@example.com',
  68. firstname: 'Bob',
  69. lastname: 'Smith',
  70. active: true,
  71. created_at: '2014-06-10T11:17:34.000Z',
  72. },
  73. ])
  74. App.Organization.refresh([
  75. {
  76. id: 12,
  77. name: 'Org 1',
  78. active: true,
  79. created_at: '2014-06-10T11:19:34.000Z',
  80. },
  81. ])
  82. /* working hours and escalation_times */
  83. $('#forms').append('<hr><h1>form condition check</h1><form id="form1"></form>')
  84. var el = $('#form1')
  85. var defaults = {
  86. priority1_id: '1',
  87. priority2_id: ['1', '2'],
  88. priority3_id: '2',
  89. working_hours: {
  90. mon: {
  91. active: true,
  92. timeframes: [
  93. ['09:00','17:00']
  94. ]
  95. },
  96. tue: {
  97. active: true,
  98. timeframes: [
  99. ['00:00','22:00']
  100. ]
  101. },
  102. wed: {
  103. active: true,
  104. timeframes: [
  105. ['09:00','17:00']
  106. ]
  107. },
  108. thu: {
  109. active: true,
  110. timeframes: [
  111. ['09:00','12:00'],
  112. ['13:00','17:00']
  113. ]
  114. },
  115. fri: {
  116. active: true,
  117. timeframes: [
  118. ['09:00','17:00']
  119. ]
  120. },
  121. sat: {
  122. active: false,
  123. timeframes: [
  124. ['10:00','14:00']
  125. ]
  126. },
  127. sun: {
  128. active: false,
  129. timeframes: [
  130. ['10:00','14:00']
  131. ]
  132. },
  133. },
  134. first_response_time: 150,
  135. solution_time: '',
  136. update_time: 45,
  137. }
  138. new App.ControllerForm({
  139. el: el,
  140. model: {
  141. configure_attributes: [
  142. { name: 'priority1_id', display: 'Priroity1', tag: 'select', relation: 'TicketPriority', null: true },
  143. { name: 'priority2_id', display: 'Priroity2', tag: 'select', multiple: true, relation: 'TicketPriority', null: true },
  144. { name: 'priority3_id', display: 'Priroity3', tag: 'select', relation: 'TicketPriority', null: true },
  145. { name: 'escalation_times', display: 'Times', tag: 'sla_times', null: true },
  146. { name: 'working_hours', display: 'Hours', tag: 'business_hours', null: true },
  147. ]
  148. },
  149. params: defaults,
  150. autofocus: true
  151. })
  152. var params = App.ControllerForm.params(el)
  153. var test_params = {
  154. priority1_id: '1',
  155. priority2_id: ['1', '2'],
  156. priority3_id: '2',
  157. first_response_time: '150',
  158. first_response_time_in_text: '02:30',
  159. solution_time: '',
  160. solution_time_in_text: '',
  161. update_time: '45',
  162. update_time_in_text: '00:45',
  163. working_hours: {
  164. mon: {
  165. active: true,
  166. timeframes: [
  167. ['09:00','17:00']
  168. ]
  169. },
  170. tue: {
  171. active: true,
  172. timeframes: [
  173. ['00:00','22:00']
  174. ]
  175. },
  176. wed: {
  177. active: true,
  178. timeframes: [
  179. ['09:00','17:00']
  180. ]
  181. },
  182. thu: {
  183. active: true,
  184. timeframes: [
  185. ['09:00','12:00'],
  186. ['13:00','17:00']
  187. ]
  188. },
  189. fri: {
  190. active: true,
  191. timeframes: [
  192. ['09:00','17:00']
  193. ]
  194. },
  195. sat: {
  196. active: false,
  197. timeframes: [
  198. ['10:00','14:00']
  199. ]
  200. },
  201. sun: {
  202. active: false,
  203. timeframes: [
  204. ['10:00','14:00']
  205. ]
  206. },
  207. },
  208. }
  209. deepEqual(params, test_params, 'form param check')
  210. // check possible options
  211. equal(el.find('[name="priority1_id"] option').length, 3)
  212. equal(el.find('[name="priority2_id"] option').length, 4)
  213. equal(el.find('[name="priority3_id"] option').length, 4)
  214. // change sla times
  215. el.find('[name="first_response_time_in_text"]').val('0:30').trigger('blur')
  216. el.find('#update_time').click()
  217. var params = App.ControllerForm.params(el)
  218. var test_params = {
  219. priority1_id: '1',
  220. priority2_id: ['1', '2'],
  221. priority3_id: '2',
  222. working_hours: {
  223. mon: {
  224. active: true,
  225. timeframes: [
  226. ['09:00','17:00']
  227. ]
  228. },
  229. tue: {
  230. active: true,
  231. timeframes: [
  232. ['00:00','22:00']
  233. ]
  234. },
  235. wed: {
  236. active: true,
  237. timeframes: [
  238. ['09:00','17:00']
  239. ]
  240. },
  241. thu: {
  242. active: true,
  243. timeframes: [
  244. ['09:00','12:00'],
  245. ['13:00','17:00']
  246. ]
  247. },
  248. fri: {
  249. active: true,
  250. timeframes: [
  251. ['09:00','17:00']
  252. ]
  253. },
  254. sat: {
  255. active: false,
  256. timeframes: [
  257. ['10:00','14:00']
  258. ]
  259. },
  260. sun: {
  261. active: false,
  262. timeframes: [
  263. ['10:00','14:00']
  264. ]
  265. },
  266. },
  267. first_response_time: '30',
  268. first_response_time_in_text: '00:30',
  269. solution_time: '',
  270. solution_time_in_text: '',
  271. update_time: '',
  272. update_time_in_text: '',
  273. }
  274. deepEqual(params, test_params, 'form param check')
  275. /* empty params or defaults */
  276. $('#forms').append('<hr><h1>form condition check</h1><form id="form2"></form>')
  277. var el = $('#form2')
  278. new App.ControllerForm({
  279. el: el,
  280. model: {
  281. configure_attributes: [
  282. { name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
  283. { name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true, notification: true },
  284. ]
  285. },
  286. autofocus: true
  287. })
  288. var params = App.ControllerForm.params(el)
  289. var test_params = {
  290. condition: {
  291. 'ticket.state_id': {
  292. operator: 'is',
  293. value: '2',
  294. },
  295. },
  296. executions: {
  297. 'ticket.state_id': {
  298. value: '2',
  299. },
  300. },
  301. }
  302. deepEqual(params, test_params, 'form param check');
  303. /* with params or defaults */
  304. $('#forms').append('<hr><h1>form 3</h1><form id="form3"></form>')
  305. var el = $('#form3')
  306. var defaults = {
  307. condition: {
  308. 'ticket.title': {
  309. operator: 'contains',
  310. value: 'some title',
  311. },
  312. 'ticket.priority_id': {
  313. operator: 'is',
  314. value: [1,2,3],
  315. },
  316. 'ticket.created_at': {
  317. operator: 'before (absolute)',
  318. value: '2015-09-20T03:41:00.000Z',
  319. },
  320. 'ticket.updated_at': {
  321. operator: 'within last (relative)',
  322. range: 'year',
  323. value: 2,
  324. },
  325. 'ticket.organization_id': {
  326. operator: 'is not',
  327. pre_condition: 'specific',
  328. value: 12,
  329. },
  330. 'ticket.owner_id': {
  331. operator: 'is',
  332. pre_condition: 'specific',
  333. value: 47,
  334. },
  335. 'ticket.created_by_id': {
  336. operator: 'is',
  337. pre_condition: 'current_user.id',
  338. value: '',
  339. },
  340. },
  341. executions: {
  342. 'ticket.title': {
  343. value: 'some title new',
  344. },
  345. 'ticket.priority_id': {
  346. value: 3,
  347. },
  348. 'ticket.owner_id': {
  349. pre_condition: 'specific',
  350. value: 47,
  351. },
  352. 'ticket.tags': {
  353. operator: 'remove',
  354. value: 'tag1, tag2',
  355. },
  356. 'notification.email': {
  357. recipient: 'ticket_customer',
  358. subject: 'some subject',
  359. body: "some<br>\nbody",
  360. },
  361. },
  362. }
  363. new App.ControllerForm({
  364. el: el,
  365. model: {
  366. configure_attributes: [
  367. { name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
  368. { name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true, notification: true },
  369. ]
  370. },
  371. params: defaults,
  372. autofocus: true
  373. })
  374. var params = App.ControllerForm.params(el)
  375. var test_params = {
  376. condition: {
  377. 'ticket.title': {
  378. operator: 'contains',
  379. value: 'some title',
  380. },
  381. 'ticket.priority_id': {
  382. operator: 'is',
  383. value: ['1', '2', '3'], // show also invalid proirity, because it's selected
  384. },
  385. 'ticket.created_at': {
  386. operator: 'before (absolute)',
  387. value: '2015-09-20T03:41:00.000Z',
  388. },
  389. 'ticket.updated_at': {
  390. operator: 'within last (relative)',
  391. range: 'year',
  392. value: '2',
  393. },
  394. 'ticket.organization_id': {
  395. operator: 'is not',
  396. pre_condition: 'specific',
  397. value: '12',
  398. },
  399. 'ticket.owner_id': {
  400. operator: 'is',
  401. pre_condition: 'specific',
  402. value: '47',
  403. value_completion: 'Bob Smith <bod@example.com>',
  404. },
  405. 'ticket.created_by_id': {
  406. operator: 'is',
  407. pre_condition: 'current_user.id',
  408. value: '',
  409. value_completion: ''
  410. },
  411. },
  412. executions: {
  413. 'ticket.title': {
  414. value: 'some title new',
  415. },
  416. 'ticket.owner_id': {
  417. pre_condition: 'specific',
  418. value: '47',
  419. value_completion: 'Bob Smith <bod@example.com>'
  420. },
  421. 'ticket.priority_id': {
  422. value: '3',
  423. },
  424. 'ticket.tags': {
  425. operator: 'remove',
  426. value: 'tag1, tag2',
  427. },
  428. 'notification.email': {
  429. recipient: 'ticket_customer',
  430. subject: 'some subject',
  431. body: "some<br>\nbody",
  432. },
  433. },
  434. }
  435. deepEqual(params, test_params, 'form param check')
  436. // change selector
  437. el.find('[name="condition::ticket.priority_id::value"]').closest('.js-filterElement').find('.js-remove').click()
  438. el.find('[name="executions::ticket.title::value"]').closest('.js-filterElement').find('.js-remove').click()
  439. var params = App.ControllerForm.params(el)
  440. var test_params = {
  441. condition: {
  442. 'ticket.title': {
  443. operator: 'contains',
  444. value: 'some title',
  445. },
  446. 'ticket.created_at': {
  447. operator: 'before (absolute)',
  448. value: '2015-09-20T03:41:00.000Z',
  449. },
  450. 'ticket.updated_at': {
  451. operator: 'within last (relative)',
  452. range: 'year',
  453. value: '2',
  454. },
  455. 'ticket.organization_id': {
  456. operator: 'is not',
  457. pre_condition: 'specific',
  458. value: '12',
  459. },
  460. 'ticket.owner_id': {
  461. operator: 'is',
  462. pre_condition: 'specific',
  463. value: '47',
  464. value_completion: 'Bob Smith <bod@example.com>',
  465. },
  466. 'ticket.created_by_id': {
  467. operator: 'is',
  468. pre_condition: 'current_user.id',
  469. value: '',
  470. value_completion: ''
  471. },
  472. },
  473. executions: {
  474. 'ticket.priority_id': {
  475. value: '3',
  476. },
  477. 'ticket.owner_id': {
  478. pre_condition: 'specific',
  479. value: '47',
  480. value_completion: 'Bob Smith <bod@example.com>'
  481. },
  482. 'ticket.tags': {
  483. operator: 'remove',
  484. value: 'tag1, tag2',
  485. },
  486. 'notification.email': {
  487. recipient: 'ticket_customer',
  488. subject: 'some subject',
  489. body: "some<br>\nbody",
  490. },
  491. },
  492. }
  493. deepEqual(params, test_params, 'form param check')
  494. // change selector
  495. el.find('[name="executions::notification.email::subject"]').closest('.js-filterElement').find('.js-remove').click()
  496. var params = App.ControllerForm.params(el)
  497. var test_params = {
  498. condition: {
  499. 'ticket.title': {
  500. operator: 'contains',
  501. value: 'some title',
  502. },
  503. 'ticket.created_at': {
  504. operator: 'before (absolute)',
  505. value: '2015-09-20T03:41:00.000Z',
  506. },
  507. 'ticket.updated_at': {
  508. operator: 'within last (relative)',
  509. range: 'year',
  510. value: '2',
  511. },
  512. 'ticket.organization_id': {
  513. operator: 'is not',
  514. pre_condition: 'specific',
  515. value: '12',
  516. },
  517. 'ticket.owner_id': {
  518. operator: 'is',
  519. pre_condition: 'specific',
  520. value: '47',
  521. value_completion: 'Bob Smith <bod@example.com>',
  522. },
  523. 'ticket.created_by_id': {
  524. operator: 'is',
  525. pre_condition: 'current_user.id',
  526. value: '',
  527. value_completion: ''
  528. },
  529. },
  530. executions: {
  531. 'ticket.priority_id': {
  532. value: '3',
  533. },
  534. 'ticket.owner_id': {
  535. pre_condition: 'specific',
  536. value: '47',
  537. value_completion: 'Bob Smith <bod@example.com>'
  538. },
  539. 'ticket.tags': {
  540. operator: 'remove',
  541. value: 'tag1, tag2',
  542. },
  543. },
  544. }
  545. deepEqual(params, test_params, 'form param check')
  546. // change selector
  547. el.find('.js-attributeSelector').last().find('select').val('notification.email').trigger('change')
  548. el.find('[name="executions::notification.email::subject"]').val('some subject')
  549. el.find('[data-name="executions::notification.email::body"]').html('lala')
  550. var params = App.ControllerForm.params(el)
  551. var test_params = {
  552. condition: {
  553. 'ticket.title': {
  554. operator: 'contains',
  555. value: 'some title',
  556. },
  557. 'ticket.created_at': {
  558. operator: 'before (absolute)',
  559. value: '2015-09-20T03:41:00.000Z',
  560. },
  561. 'ticket.updated_at': {
  562. operator: 'within last (relative)',
  563. range: 'year',
  564. value: '2',
  565. },
  566. 'ticket.organization_id': {
  567. operator: 'is not',
  568. pre_condition: 'specific',
  569. value: '12',
  570. },
  571. 'ticket.owner_id': {
  572. operator: 'is',
  573. pre_condition: 'specific',
  574. value: '47',
  575. value_completion: 'Bob Smith <bod@example.com>',
  576. },
  577. 'ticket.created_by_id': {
  578. operator: 'is',
  579. pre_condition: 'current_user.id',
  580. value: '',
  581. value_completion: ''
  582. },
  583. },
  584. executions: {
  585. 'ticket.priority_id': {
  586. value: '3',
  587. },
  588. 'ticket.owner_id': {
  589. pre_condition: 'specific',
  590. value: '47',
  591. value_completion: 'Bob Smith <bod@example.com>'
  592. },
  593. 'notification.email': {
  594. recipient: 'ticket_owner',
  595. subject: 'some subject',
  596. body: 'lala',
  597. },
  598. },
  599. }
  600. deepEqual(params, test_params, 'form param check')
  601. /* with params or defaults */
  602. $('#forms').append('<hr><h1>form 4</h1><form id="form4"></form>')
  603. var el = $('#form4')
  604. var defaults = {
  605. condition: {
  606. 'ticket.title': {
  607. operator: 'contains',
  608. value: 'some title',
  609. },
  610. },
  611. executions: {
  612. 'notification.email': {
  613. recipient: 'ticket_customer',
  614. subject: 'some subject',
  615. body: "some<br>\nbody",
  616. },
  617. },
  618. }
  619. new App.ControllerForm({
  620. el: el,
  621. model: {
  622. configure_attributes: [
  623. { name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
  624. { name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true, notification: true },
  625. ]
  626. },
  627. params: defaults,
  628. autofocus: true
  629. })
  630. var params = App.ControllerForm.params(el)
  631. var test_params = {
  632. condition: {
  633. 'ticket.title': {
  634. operator: 'contains',
  635. value: 'some title',
  636. },
  637. },
  638. executions: {
  639. 'notification.email': {
  640. recipient: 'ticket_customer',
  641. subject: 'some subject',
  642. body: "some<br>\nbody",
  643. },
  644. },
  645. }
  646. deepEqual(params, test_params, 'form param check')
  647. });