form_extended.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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. App.TicketState.refresh([
  34. {
  35. id: 1,
  36. name: 'new',
  37. note: 'some note 1',
  38. active: true,
  39. created_at: '2014-06-10T11:17:34.000Z',
  40. },
  41. {
  42. id: 2,
  43. name: 'open',
  44. note: 'some note 2',
  45. active: true,
  46. created_at: '2014-06-10T10:17:34.000Z',
  47. },
  48. {
  49. id: 3,
  50. name: 'should not be shown',
  51. note: 'some note 3',
  52. active: false,
  53. created_at: '2014-06-10T10:17:34.000Z',
  54. },
  55. ])
  56. App.User.refresh([
  57. {
  58. id: 47,
  59. login: 'bod@example.com',
  60. email: 'bod@example.com',
  61. firstname: 'Bob',
  62. lastname: 'Smith',
  63. active: true,
  64. created_at: '2014-06-10T11:17:34.000Z',
  65. },
  66. ])
  67. App.Organization.refresh([
  68. {
  69. id: 12,
  70. name: 'Org 1',
  71. active: true,
  72. created_at: '2014-06-10T11:19:34.000Z',
  73. },
  74. ])
  75. /* working hours and escalation_times */
  76. $('#forms').append('<hr><h1>form condition check</h1><form id="form1"></form>')
  77. var el = $('#form1')
  78. var defaults = {
  79. working_hours: {
  80. mon: {
  81. active: true,
  82. timeframes: [
  83. ['09:00','17:00']
  84. ]
  85. },
  86. tue: {
  87. active: true,
  88. timeframes: [
  89. ['00:00','22:00']
  90. ]
  91. },
  92. wed: {
  93. active: true,
  94. timeframes: [
  95. ['09:00','17:00']
  96. ]
  97. },
  98. thu: {
  99. active: true,
  100. timeframes: [
  101. ['09:00','12:00'],
  102. ['13:00','17:00']
  103. ]
  104. },
  105. fri: {
  106. active: true,
  107. timeframes: [
  108. ['09:00','17:00']
  109. ]
  110. },
  111. sat: {
  112. active: false,
  113. timeframes: [
  114. ['10:00','14:00']
  115. ]
  116. },
  117. sun: {
  118. active: false,
  119. timeframes: [
  120. ['10:00','14:00']
  121. ]
  122. },
  123. },
  124. first_response_time: 150,
  125. solution_time: '',
  126. update_time: 45,
  127. }
  128. new App.ControllerForm({
  129. el: el,
  130. model: {
  131. configure_attributes: [
  132. { name: 'escalation_times', display: 'Times', tag: 'sla_times', null: true },
  133. { name: 'working_hours', display: 'Hours', tag: 'business_hours', null: true },
  134. ]
  135. },
  136. params: defaults,
  137. autofocus: true
  138. })
  139. var params = App.ControllerForm.params(el)
  140. var test_params = {
  141. first_response_time: '150',
  142. first_response_time_in_text: '02:30',
  143. solution_time: '',
  144. solution_time_in_text: '',
  145. update_time: '45',
  146. update_time_in_text: '00:45',
  147. working_hours: {
  148. mon: {
  149. active: true,
  150. timeframes: [
  151. ['09:00','17:00']
  152. ]
  153. },
  154. tue: {
  155. active: true,
  156. timeframes: [
  157. ['00:00','22:00']
  158. ]
  159. },
  160. wed: {
  161. active: true,
  162. timeframes: [
  163. ['09:00','17:00']
  164. ]
  165. },
  166. thu: {
  167. active: true,
  168. timeframes: [
  169. ['09:00','12:00'],
  170. ['13:00','17:00']
  171. ]
  172. },
  173. fri: {
  174. active: true,
  175. timeframes: [
  176. ['09:00','17:00']
  177. ]
  178. },
  179. sat: {
  180. active: false,
  181. timeframes: [
  182. ['10:00','14:00']
  183. ]
  184. },
  185. sun: {
  186. active: false,
  187. timeframes: [
  188. ['10:00','14:00']
  189. ]
  190. },
  191. },
  192. }
  193. deepEqual(params, test_params, 'form param check')
  194. // change sla times
  195. el.find('[name="first_response_time_in_text"]').val('0:30').trigger('blur')
  196. el.find('#update_time').click()
  197. var params = App.ControllerForm.params(el)
  198. var test_params = {
  199. working_hours: {
  200. mon: {
  201. active: true,
  202. timeframes: [
  203. ['09:00','17:00']
  204. ]
  205. },
  206. tue: {
  207. active: true,
  208. timeframes: [
  209. ['00:00','22:00']
  210. ]
  211. },
  212. wed: {
  213. active: true,
  214. timeframes: [
  215. ['09:00','17:00']
  216. ]
  217. },
  218. thu: {
  219. active: true,
  220. timeframes: [
  221. ['09:00','12:00'],
  222. ['13:00','17:00']
  223. ]
  224. },
  225. fri: {
  226. active: true,
  227. timeframes: [
  228. ['09:00','17:00']
  229. ]
  230. },
  231. sat: {
  232. active: false,
  233. timeframes: [
  234. ['10:00','14:00']
  235. ]
  236. },
  237. sun: {
  238. active: false,
  239. timeframes: [
  240. ['10:00','14:00']
  241. ]
  242. },
  243. },
  244. first_response_time: '30',
  245. first_response_time_in_text: '00:30',
  246. solution_time: '',
  247. solution_time_in_text: '',
  248. update_time: '',
  249. update_time_in_text: '',
  250. }
  251. deepEqual(params, test_params, 'form param check')
  252. /* empty params or defaults */
  253. $('#forms').append('<hr><h1>form condition check</h1><form id="form2"></form>')
  254. var el = $('#form2')
  255. new App.ControllerForm({
  256. el: el,
  257. model: {
  258. configure_attributes: [
  259. { name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
  260. { name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true },
  261. ]
  262. },
  263. autofocus: true
  264. })
  265. var params = App.ControllerForm.params(el)
  266. var test_params = {
  267. condition: {
  268. 'ticket.state_id': {
  269. operator: 'is',
  270. value: '2',
  271. },
  272. },
  273. executions: {
  274. 'ticket.state_id': {
  275. value: '2',
  276. },
  277. },
  278. }
  279. deepEqual(params, test_params, 'form param check');
  280. /* with params or defaults */
  281. $('#forms').append('<hr><h1>form time check</h1><form id="form3"></form>')
  282. var el = $('#form3')
  283. var defaults = {
  284. condition: {
  285. 'ticket.title': {
  286. operator: 'contains',
  287. value: 'some title',
  288. },
  289. 'ticket.priority_id': {
  290. operator: 'is',
  291. value: [1,2,3],
  292. },
  293. 'ticket.created_at': {
  294. operator: 'before (absolute)',
  295. value: '2015-09-20T03:41:00.000Z',
  296. },
  297. 'ticket.updated_at': {
  298. operator: 'within last (relative)',
  299. range: 'year',
  300. value: 2,
  301. },
  302. 'ticket.organization_id': {
  303. operator: 'is not',
  304. pre_condition: 'specific',
  305. value: 12,
  306. },
  307. 'ticket.owner_id': {
  308. operator: 'is',
  309. pre_condition: 'specific',
  310. value: 47,
  311. },
  312. 'ticket.created_by_id': {
  313. operator: 'is',
  314. pre_condition: 'current_user.id',
  315. value: '',
  316. },
  317. },
  318. executions: {
  319. 'ticket.title': {
  320. value: 'some title new',
  321. },
  322. 'ticket.priority_id': {
  323. value: 3,
  324. },
  325. 'ticket.owner_id': {
  326. pre_condition: 'specific',
  327. value: 47,
  328. },
  329. 'ticket.tags': {
  330. operator: 'remove',
  331. value: 'tag1, tag2',
  332. },
  333. },
  334. }
  335. new App.ControllerForm({
  336. el: el,
  337. model: {
  338. configure_attributes: [
  339. { name: 'condition', display: 'Conditions', tag: 'ticket_selector', null: true },
  340. { name: 'executions', display: 'Executions', tag: 'ticket_perform_action', null: true },
  341. ]
  342. },
  343. params: defaults,
  344. autofocus: true
  345. })
  346. var params = App.ControllerForm.params(el)
  347. var test_params = {
  348. condition: {
  349. 'ticket.title': {
  350. operator: 'contains',
  351. value: 'some title',
  352. },
  353. 'ticket.priority_id': {
  354. operator: 'is',
  355. value: ['1', '3'],
  356. },
  357. 'ticket.created_at': {
  358. operator: 'before (absolute)',
  359. value: '2015-09-20T03:41:00.000Z',
  360. },
  361. 'ticket.updated_at': {
  362. operator: 'within last (relative)',
  363. range: 'year',
  364. value: '2',
  365. },
  366. 'ticket.organization_id': {
  367. operator: 'is not',
  368. pre_condition: 'specific',
  369. value: '12',
  370. },
  371. 'ticket.owner_id': {
  372. operator: 'is',
  373. pre_condition: 'specific',
  374. value: '47',
  375. value_completion: 'Bob Smith <bod@example.com>',
  376. },
  377. 'ticket.created_by_id': {
  378. operator: 'is',
  379. pre_condition: 'current_user.id',
  380. value: '',
  381. value_completion: ''
  382. },
  383. },
  384. executions: {
  385. 'ticket.title': {
  386. value: 'some title new',
  387. },
  388. 'ticket.owner_id': {
  389. pre_condition: 'specific',
  390. value: '47',
  391. value_completion: 'Bob Smith <bod@example.com>'
  392. },
  393. 'ticket.priority_id': {
  394. value: '3',
  395. },
  396. 'ticket.tags': {
  397. operator: 'remove',
  398. value: 'tag1, tag2',
  399. },
  400. },
  401. }
  402. deepEqual(params, test_params, 'form param check')
  403. // change selector
  404. el.find('[name="condition::ticket.priority_id::value"]').closest('.js-filterElement').find('.js-remove').click()
  405. el.find('[name="executions::ticket.title::value"]').closest('.js-filterElement').find('.js-remove').click()
  406. var params = App.ControllerForm.params(el)
  407. var test_params = {
  408. condition: {
  409. 'ticket.title': {
  410. operator: 'contains',
  411. value: 'some title',
  412. },
  413. 'ticket.created_at': {
  414. operator: 'before (absolute)',
  415. value: '2015-09-20T03:41:00.000Z',
  416. },
  417. 'ticket.updated_at': {
  418. operator: 'within last (relative)',
  419. range: 'year',
  420. value: '2',
  421. },
  422. 'ticket.organization_id': {
  423. operator: 'is not',
  424. pre_condition: 'specific',
  425. value: '12',
  426. },
  427. 'ticket.owner_id': {
  428. operator: 'is',
  429. pre_condition: 'specific',
  430. value: '47',
  431. value_completion: 'Bob Smith <bod@example.com>',
  432. },
  433. 'ticket.created_by_id': {
  434. operator: 'is',
  435. pre_condition: 'current_user.id',
  436. value: '',
  437. value_completion: ''
  438. },
  439. },
  440. executions: {
  441. 'ticket.priority_id': {
  442. value: '3',
  443. },
  444. 'ticket.owner_id': {
  445. pre_condition: 'specific',
  446. value: '47',
  447. value_completion: 'Bob Smith <bod@example.com>'
  448. },
  449. 'ticket.tags': {
  450. operator: 'remove',
  451. value: 'tag1, tag2',
  452. },
  453. },
  454. }
  455. deepEqual(params, test_params, 'form param check')
  456. //deepEqual(el.find('[name="times::days"]').val(), ['mon', 'wed'], 'check times::days value')
  457. //equal(el.find('[name="times::hours"]').val(), 2, 'check times::hours value')
  458. //equal(el.find('[name="times::minutes"]').val(), null, 'check times::minutes value')
  459. });