table.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. // form
  2. QUnit.test('table test', assert => {
  3. App.i18n.set('de-de')
  4. $('#qunit').append('<hr><h1>table simple I</h1><div id="table1"></div>')
  5. var el = $('#table1')
  6. App.TicketPriority.refresh( [
  7. {
  8. id: 1,
  9. name: '1 low',
  10. note: 'some note 1',
  11. active: true,
  12. created_at: '2014-06-10T11:17:34.000Z',
  13. },
  14. {
  15. id: 2,
  16. name: '2 normal',
  17. note: 'some note 2',
  18. active: false,
  19. created_at: '2014-06-10T10:17:34.000Z',
  20. },
  21. ] )
  22. var rowClick = function (id, e) {
  23. e.preventDefault()
  24. console.log('rowClick', id, e.target)
  25. };
  26. var rowDblClick = function (id, e) {
  27. e.preventDefault()
  28. console.log('rowDblClick', id, e.target)
  29. };
  30. var rowMouseover = function (id, e) {
  31. e.preventDefault()
  32. console.log('rowMouseover', id, e.target)
  33. };
  34. var rowMouseout = function (id, e) {
  35. e.preventDefault()
  36. console.log('rowMouseout', id, e.target)
  37. };
  38. var colClick = function (id, e) {
  39. e.preventDefault()
  40. console.log('colClick', id, e.target)
  41. };
  42. var colDblClick = function (id, e) {
  43. e.preventDefault()
  44. console.log('colDblClick', id, e.target)
  45. };
  46. var colMouseover = function (id, e) {
  47. e.preventDefault()
  48. console.log('colMouseover', id, e.target)
  49. };
  50. var colMouseout = function (id, e) {
  51. e.preventDefault()
  52. console.log('colMouseout', id, e.target)
  53. };
  54. new App.ControllerTable({
  55. el: el,
  56. overview: ['name', 'created_at', 'active'],
  57. model: App.TicketPriority,
  58. objects: App.TicketPriority.search({sortBy:'name', order: 'ASC'}),
  59. checkbox: false,
  60. radio: false,
  61. bindRow: {
  62. events: {
  63. 'click': rowClick,
  64. 'mouseover': rowMouseover,
  65. 'mouseout': rowMouseout,
  66. 'dblclick': rowDblClick,
  67. }
  68. },
  69. bindCol: {
  70. name: {
  71. events: {
  72. 'click': colClick,
  73. 'mouseover': colMouseover,
  74. 'mouseout': colMouseout,
  75. 'dblclick': colDblClick,
  76. }
  77. },
  78. created_at: {
  79. events: {
  80. 'mouseover': colMouseover,
  81. 'mouseout': colMouseout,
  82. }
  83. }
  84. },
  85. })
  86. assert.equal(el.find('table > thead > tr').length, 1, 'row count')
  87. assert.equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  88. assert.equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  89. assert.equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  90. assert.equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  91. assert.equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
  92. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 1')
  93. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
  94. assert.equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
  95. assert.equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
  96. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
  97. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'false', 'check row 2')
  98. $('#qunit').append('<hr><h1>table simple II</h1><div id="table2"></div>')
  99. el = $('#table2')
  100. new App.ControllerTable({
  101. el: el,
  102. overview: ['name', 'created_at', 'active'],
  103. model: App.TicketPriority,
  104. objects: App.TicketPriority.search({sortBy:'name', order: 'DESC'}),
  105. checkbox: false,
  106. radio: false,
  107. })
  108. assert.equal(el.find('table > thead > tr').length, 1, 'row count')
  109. assert.equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  110. assert.equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  111. assert.equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  112. assert.equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  113. assert.equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '2 normal', 'check row 1')
  114. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 1')
  115. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'false', 'check row 1')
  116. assert.equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
  117. assert.equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '1 niedrig', 'check row 2')
  118. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '10.06.2014', 'check row 2')
  119. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'true', 'check row 2')
  120. $('#qunit').append('<hr><h1>table simple III</h1><div id="table3"></div>')
  121. el = $('#table3')
  122. new App.ControllerTable({
  123. el: el,
  124. model: App.TicketPriority,
  125. objects: App.TicketPriority.search({sortBy:'created_at', order: 'DESC'}),
  126. checkbox: false,
  127. radio: false,
  128. })
  129. assert.equal(el.find('table > thead > tr').length, 1, 'row count')
  130. assert.equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  131. assert.notEqual( el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Erstellt', 'check header')
  132. assert.notEqual( el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  133. assert.equal(el.find('tbody > tr:nth-child(2) > td').length, 1, 'check row 2')
  134. assert.equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), '2 normal', 'check row 2')
  135. assert.notEqual( el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '?', 'check row 2')
  136. assert.notEqual( el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'true', 'check row 2')
  137. assert.equal(el.find('tbody > tr:nth-child(1) > td').length, 1, 'check row 1')
  138. assert.equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), '1 niedrig', 'check row 1')
  139. assert.notEqual( el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '?', 'check row 1')
  140. assert.notEqual( el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'false', 'check row 1')
  141. App.Group.refresh( [
  142. {
  143. id: 1,
  144. name: 'group 1',
  145. active: true,
  146. created_at: '2014-06-10T11:17:34.000Z',
  147. },
  148. {
  149. id: 2,
  150. name: 'group 2',
  151. active: true,
  152. created_at: '2014-06-10T11:17:34.000Z',
  153. },
  154. ])
  155. App.User.refresh( [
  156. {
  157. id: 55,
  158. login: 'login55',
  159. firstname: 'firstname55',
  160. lastname: 'lastname55',
  161. email: 'email55',
  162. active: true,
  163. created_at: '2014-06-10T11:17:34.000Z',
  164. },
  165. {
  166. id: 56,
  167. login: 'login56',
  168. firstname: 'firstname56',
  169. lastname: 'lastname56',
  170. email: 'email56',
  171. active: true,
  172. created_at: '2014-06-10T11:17:34.000Z',
  173. },
  174. ])
  175. App.TicketState.refresh( [
  176. {
  177. id: 1,
  178. name: 'new',
  179. active: true,
  180. created_at: '2014-06-10T11:17:34.000Z',
  181. },
  182. {
  183. id: 2,
  184. name: 'open',
  185. note: 'some note 2',
  186. active: false,
  187. created_at: '2014-06-10T10:17:34.000Z',
  188. },
  189. ])
  190. App.Ticket.refresh( [
  191. {
  192. id: 1,
  193. title: 'some title 1',
  194. number: '4711',
  195. priority_id: 1,
  196. owner_id: 55,
  197. customer_id: 56,
  198. state_id: 1,
  199. group_id: 2,
  200. created_at: '2014-06-10T11:17:34.000Z',
  201. },
  202. {
  203. id: 3,
  204. title: 'some title 3',
  205. number: '4713',
  206. priority_id: 2,
  207. owner_id: 56,
  208. state_id: 1,
  209. group_id: 2,
  210. created_at: '2014-07-11T11:19:34.000Z',
  211. },
  212. {
  213. id: 2,
  214. title: 'some title 2',
  215. number: '4712',
  216. priority_id: 1,
  217. state_id: 2,
  218. group_id: 1,
  219. created_at: '2014-06-10T11:19:34.000Z',
  220. },
  221. ])
  222. $('#qunit').append('<hr><h1>table complex I</h1><div id="table4"></div>')
  223. el = $('#table4')
  224. new App.ControllerTable({
  225. el: el,
  226. overview: ['number', 'title', 'owner', 'customer', 'priority', 'group', 'state', 'created_at'],
  227. model: App.Ticket,
  228. objects: App.Ticket.search({sortBy:'created_at', order: 'DESC'}),
  229. checkbox: true,
  230. })
  231. assert.equal(el.find('table > thead > tr').length, 1, 'row count')
  232. assert.equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), '', 'check header')
  233. assert.equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), '#', 'check header')
  234. assert.equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Titel', 'check header')
  235. assert.equal(el.find('table > thead > tr > th:nth-child(4)').text().trim(), 'Besitzer', 'check header')
  236. assert.equal(el.find('table > thead > tr > th:nth-child(5)').text().trim(), 'Kunde', 'check header')
  237. assert.equal(el.find('table > thead > tr > th:nth-child(6)').text().trim(), 'Priorität', 'check header')
  238. assert.equal(el.find('table > thead > tr > th:nth-child(7)').text().trim(), 'Gruppe', 'check header')
  239. assert.equal(el.find('table > thead > tr > th:nth-child(8)').text().trim(), 'Status', 'check header')
  240. assert.equal(el.find('table > thead > tr > th:nth-child(9)').text().trim(), 'Erstellt am', 'check header')
  241. assert.equal(el.find('tbody > tr:nth-child(1) > td').length, 9, 'check row 1')
  242. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1) input').val(), '3', 'check row 1')
  243. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1) input').prop('checked'), '', 'check row 1')
  244. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), '', 'check row 1')
  245. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), '4713', 'check row 1')
  246. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'some title 3', 'check row 1')
  247. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(4)').text().trim(), 'firstname56 lastname56', 'check row 2')
  248. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(5)').text().trim(), '-', 'check row 2')
  249. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(6)').text().trim(), '2 normal', 'check row 1')
  250. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(7)').text().trim(), 'group 2', 'check row 1')
  251. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(8)').text().trim(), 'neu', 'check row 1')
  252. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(9)').text().trim(), '11.07.2014', 'check row 1')
  253. assert.equal(el.find('tbody > tr:nth-child(2) > td').length, 9, 'check row 2')
  254. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1) input').val(), '2', 'check row 2')
  255. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1) input').prop('checked'), '', 'check row 2')
  256. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1)').text().trim(), '', 'check row 2')
  257. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '4712', 'check row 2')
  258. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'some title 2', 'check row 2')
  259. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(4)').text().trim(), '-', 'check row 2')
  260. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5)').text().trim(), '-', 'check row 2')
  261. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(6)').text().trim(), '1 niedrig', 'check row 2')
  262. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(7)').text().trim(), 'group 1', 'check row 2')
  263. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(8)').text().trim(), 'offen', 'check row 2')
  264. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(9)').text().trim(), '10.06.2014', 'check row 2')
  265. assert.equal(el.find('tbody > tr:nth-child(3) > td').length, 9, 'check row 3')
  266. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(1) input').val(), '1', 'check row 3')
  267. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(1) input').prop('checked'), '', 'check row 3')
  268. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(1)').text().trim(), '', 'check row 3')
  269. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(2)').text().trim(), '4711', 'check row 3')
  270. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(3)').text().trim(), 'some title 1', 'check row 3')
  271. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(4)').text().trim(), 'firstname55 lastname55', 'check row 2')
  272. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(5)').text().trim(), 'firstname56 lastname56', 'check row 2')
  273. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(6)').text().trim(), '1 niedrig', 'check row 3')
  274. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(7)').text().trim(), 'group 2', 'check row 3')
  275. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(8)').text().trim(), 'neu', 'check row 3')
  276. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(9)').text().trim(), '10.06.2014', 'check row 3')
  277. el.find('input[name="bulk_all"]').trigger('click')
  278. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1) input').prop('checked'), true, 'check row 1')
  279. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1) input').val(), '3', 'check row 1')
  280. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1) input').prop('checked'), true, 'check row 2')
  281. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1) input').val(), '2', 'check row 2')
  282. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(1) input').prop('checked'), true, 'check row 3')
  283. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(1) input').val(), '1', 'check row 3')
  284. $('#qunit').append('<hr><h1>table complex II</h1><div id="table5"></div>')
  285. el = $('#table5')
  286. var clickCheckbox = function (id, checked, e) {
  287. console.log('clickCheckbox', id, checked, e.target)
  288. };
  289. new App.ControllerTable({
  290. el: el,
  291. overview: ['number', 'title', 'owner', 'customer', 'priority', 'group', 'state', 'created_at'],
  292. model: App.Ticket,
  293. objects: App.Ticket.search({sortBy:'created_at', order: 'DESC'}),
  294. checkbox: true,
  295. groupBy: 'group',
  296. bindCheckbox: {
  297. events: {
  298. 'click': clickCheckbox,
  299. }
  300. },
  301. })
  302. assert.equal(el.find('table > thead > tr').length, 1, 'row count')
  303. assert.equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), '', 'check header')
  304. assert.equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), '#', 'check header')
  305. assert.equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Titel', 'check header')
  306. assert.equal(el.find('table > thead > tr > th:nth-child(4)').text().trim(), 'Besitzer', 'check header')
  307. assert.equal(el.find('table > thead > tr > th:nth-child(5)').text().trim(), 'Kunde', 'check header')
  308. assert.equal(el.find('table > thead > tr > th:nth-child(6)').text().trim(), 'Priorität', 'check header')
  309. assert.equal(el.find('table > thead > tr > th:nth-child(7)').text().trim(), 'Status', 'check header')
  310. assert.equal(el.find('table > thead > tr > th:nth-child(8)').text().trim(), 'Erstellt am', 'check header')
  311. assert.equal(el.find('tbody > tr:nth-child(1) > td').length, 1, 'check row 1')
  312. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), 'group 1', 'check row 1')
  313. assert.equal(el.find('tbody > tr:nth-child(2) > td').length, 8, 'check row 2')
  314. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1) input').val(), '2', 'check row 2')
  315. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1) input').prop('checked'), '', 'check row 2')
  316. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1)').text().trim(), '', 'check row 2')
  317. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), '4712', 'check row 2')
  318. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'some title 2', 'check row 2')
  319. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(4)').text().trim(), '-', 'check row 2')
  320. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5)').text().trim(), '-', 'check row 2')
  321. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(6)').text().trim(), '1 niedrig', 'check row 2')
  322. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(7)').text().trim(), 'offen', 'check row 2')
  323. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(8)').text().trim(), '10.06.2014', 'check row 2')
  324. assert.equal(el.find('tbody > tr:nth-child(3) > td').length, 1, 'check row 3')
  325. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(1)').text().trim(), 'group 2', 'check row 4')
  326. assert.equal(el.find('tbody > tr:nth-child(4) > td').length, 8, 'check row 4')
  327. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(1) input').val(), '3', 'check row 4')
  328. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(1) input').prop('checked'), '', 'check row 4')
  329. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(1)').text().trim(), '', 'check row 4')
  330. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(2)').text().trim(), '4713', 'check row 4')
  331. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(3)').text().trim(), 'some title 3', 'check row 4')
  332. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(4)').text().trim(), 'firstname56 lastname56', 'check row 2')
  333. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(5)').text().trim(), '-', 'check row 2')
  334. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(6)').text().trim(), '2 normal', 'check row 4')
  335. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(7)').text().trim(), 'neu', 'check row 4')
  336. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(8)').text().trim(), '11.07.2014', 'check row 4')
  337. el.find('input[name="bulk"]:eq(1)').trigger('click')
  338. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1) input').prop('checked'), '', 'check row 2')
  339. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1) input').val(), '2', 'check row 1')
  340. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(1) input').prop('checked'), true, 'check row 4')
  341. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(1) input').val(), '3', 'check row 4')
  342. assert.equal(el.find('tbody > tr:nth-child(5) > td:nth-child(1) input').prop('checked'), '', 'check row 5')
  343. assert.equal(el.find('tbody > tr:nth-child(5) > td:nth-child(1) input').val(), '1', 'check row 5')
  344. el.find('tbody > tr:nth-child(5) > td:nth-child(1) label').trigger('click')
  345. assert.equal(el.find('tbody > tr:nth-child(5) > td:nth-child(1) input').prop('checked'), true, 'check row 5')
  346. assert.equal(el.find('tbody > tr:nth-child(5) > td:nth-child(1) input').val(), '1', 'check row 5')
  347. $('#qunit').append('<hr><h1>table Group By Direction DESC</h1><div id="table6"></div>')
  348. el = $('#table6')
  349. var clickCheckbox = function (id, checked, e) {
  350. console.log('clickCheckbox', id, checked, e.target)
  351. };
  352. new App.ControllerTable({
  353. el: el,
  354. overview: ['number', 'title', 'owner', 'customer', 'priority', 'group', 'state', 'created_at'],
  355. model: App.Ticket,
  356. objects: App.Ticket.search({sortBy:'created_at', order: 'DESC'}),
  357. groupBy: 'priority',
  358. groupDirection: 'DESC',
  359. })
  360. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), '2 normal', 'check row 1')
  361. assert.equal(el.find('tbody > tr:nth-child(3) > td:nth-child(1)').text().trim(), '1 niedrig', 'check row 3')
  362. $('#qunit').append('<hr><h1>table Group By Direction ASC</h1><div id="table7"></div>')
  363. el = $('#table7')
  364. var clickCheckbox = function (id, checked, e) {
  365. console.log('clickCheckbox', id, checked, e.target)
  366. };
  367. new App.ControllerTable({
  368. el: el,
  369. overview: ['number', 'title', 'owner', 'customer', 'priority', 'group', 'state', 'created_at'],
  370. model: App.Ticket,
  371. objects: App.Ticket.search({sortBy:'created_at', order: 'DESC'}),
  372. groupBy: 'priority',
  373. groupDirection: 'ASC',
  374. })
  375. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), '1 niedrig', 'check row 1')
  376. assert.equal(el.find('tbody > tr:nth-child(4) > td:nth-child(1)').text().trim(), '2 normal', 'check row 4')
  377. });
  378. QUnit.test('table test 2.1', assert => {
  379. App.i18n.set('de-de')
  380. $('#qunit').append('<hr><h1>table with hash</h1><div id="table-hash2_1"></div>')
  381. var el = $('#table-hash2_1')
  382. App.Group.refresh( [
  383. {
  384. id: 5,
  385. name: 'group 5',
  386. active: true,
  387. created_at: '2014-06-10T11:17:34.000Z',
  388. },
  389. ])
  390. App.Channel.configure_delete = true
  391. App.Channel.configure_clone = false
  392. App.Channel.configure_attributes = [
  393. { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { IMAP: 'IMAP', POP3: 'POP3' } },
  394. { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false },
  395. { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false },
  396. { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false },
  397. { name: 'options::ssl', display: 'SSL', tag: 'select', multiple: false, null: true, options: { true: 'yes', false: 'no' }, translate: true, default: true},
  398. { name: 'options::folder', display: 'Folder', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false },
  399. { name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: false, nulloption: true, relation: 'Group' },
  400. { name: 'active', display: 'Active', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' }, translate: true, default: true },
  401. ]
  402. App.Channel.refresh( [
  403. {
  404. id: 1,
  405. adapter: 'adapter1',
  406. options: {
  407. host: 'host1',
  408. user: 'user1',
  409. },
  410. group_id: 5,
  411. active: true,
  412. created_at: '2014-06-10T11:17:34.000Z',
  413. },
  414. {
  415. id: 2,
  416. adapter: 'adapter2',
  417. options: {
  418. host: 'host2',
  419. user: 'user2',
  420. },
  421. group_id: 5,
  422. active: true,
  423. created_at: '2014-06-10T11:17:34.000Z',
  424. },
  425. ] )
  426. new App.ControllerTable({
  427. el: el,
  428. overview: ['adapter', 'options::host', 'options::user', 'active'],
  429. model: App.Channel,
  430. objects: App.Channel.search({sortBy:'adapter', order: 'ASC'}),
  431. })
  432. assert.equal(el.find('table > thead > tr').length, 1, 'row count')
  433. assert.equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Typ', 'check header')
  434. assert.equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Host', 'check header')
  435. assert.equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Benutzer', 'check header')
  436. assert.equal(el.find('table > thead > tr > th:nth-child(4)').text().trim(), 'Aktiv', 'check header')
  437. assert.equal(el.find('table > thead > tr > th:nth-child(5)').text().trim(), 'Aktion', 'check header')
  438. assert.equal(el.find('tbody > tr:nth-child(1) > td').length, 5, 'check row 1')
  439. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), 'adapter1', 'check row 1')
  440. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), 'host1', 'check row 1')
  441. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'user1', 'check row 1')
  442. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(4)').text().trim(), 'ja', 'check row 1')
  443. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(5)').text().trim(), '', 'check row 1')
  444. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(5) .dropdown.dropdown--actions').length, 0, 'check row 1')
  445. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(5) .js-delete').length, 1, 'check row 1')
  446. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(5) .js-clone').length, 0, 'check row 1')
  447. assert.equal(el.find('tbody > tr:nth-child(2) > td').length, 5, 'check row 2')
  448. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1)').text().trim(), 'adapter2', 'check row 2')
  449. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), 'host2', 'check row 2')
  450. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'user2', 'check row 2')
  451. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(4)').text().trim(), 'ja', 'check row 2')
  452. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5)').text().trim(), '', 'check row 2')
  453. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5) .dropdown.dropdown--actions').length, 0, 'check row 1')
  454. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5) .js-delete').length, 1, 'check row 1')
  455. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5) .js-clone').length, 0, 'check row 1')
  456. });
  457. QUnit.test('table test 2.2', assert => {
  458. App.i18n.set('de-de')
  459. $('#qunit').append('<hr><h1>table with hash</h1><div id="table-hash2_2"></div>')
  460. var el = $('#table-hash2_2')
  461. App.Group.refresh( [
  462. {
  463. id: 5,
  464. name: 'group 5',
  465. active: true,
  466. created_at: '2014-06-10T11:17:34.000Z',
  467. },
  468. ])
  469. App.Channel.configure_delete = false
  470. App.Channel.configure_clone = true
  471. App.Channel.configure_attributes = [
  472. { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { IMAP: 'IMAP', POP3: 'POP3' } },
  473. { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false },
  474. { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false },
  475. { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false },
  476. { name: 'options::ssl', display: 'SSL', tag: 'select', multiple: false, null: true, options: { true: 'yes', false: 'no' }, translate: true, default: true},
  477. { name: 'options::folder', display: 'Folder', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false },
  478. { name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: false, nulloption: true, relation: 'Group' },
  479. { name: 'active', display: 'Active', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' }, translate: true, default: true },
  480. ]
  481. App.Channel.refresh( [
  482. {
  483. id: 1,
  484. adapter: 'adapter1',
  485. options: {
  486. host: 'host1',
  487. user: 'user1',
  488. },
  489. group_id: 5,
  490. active: true,
  491. created_at: '2014-06-10T11:17:34.000Z',
  492. },
  493. {
  494. id: 2,
  495. adapter: 'adapter2',
  496. options: {
  497. host: 'host2',
  498. user: 'user2',
  499. },
  500. group_id: 5,
  501. active: true,
  502. created_at: '2014-06-10T11:17:34.000Z',
  503. },
  504. ] )
  505. new App.ControllerTable({
  506. el: el,
  507. overview: ['adapter', 'options::host', 'options::user', 'active'],
  508. model: App.Channel,
  509. objects: App.Channel.search({sortBy:'adapter', order: 'ASC'}),
  510. })
  511. assert.equal(el.find('table > thead > tr').length, 1, 'row count')
  512. assert.equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Typ', 'check header')
  513. assert.equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Host', 'check header')
  514. assert.equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Benutzer', 'check header')
  515. assert.equal(el.find('table > thead > tr > th:nth-child(4)').text().trim(), 'Aktiv', 'check header')
  516. assert.equal(el.find('table > thead > tr > th:nth-child(5)').text().trim(), 'Aktion', 'check header')
  517. assert.equal(el.find('tbody > tr:nth-child(1) > td').length, 5, 'check row 1')
  518. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), 'adapter1', 'check row 1')
  519. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), 'host1', 'check row 1')
  520. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'user1', 'check row 1')
  521. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(4)').text().trim(), 'ja', 'check row 1')
  522. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(5)').text().trim(), '', 'check row 1')
  523. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(5) .dropdown.dropdown--actions').length, 0, 'check row 1')
  524. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(5) .js-delete').length, 0, 'check row 1')
  525. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(5) .js-clone').length, 1, 'check row 1')
  526. assert.equal(el.find('tbody > tr:nth-child(2) > td').length, 5, 'check row 2')
  527. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1)').text().trim(), 'adapter2', 'check row 2')
  528. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), 'host2', 'check row 2')
  529. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'user2', 'check row 2')
  530. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(4)').text().trim(), 'ja', 'check row 2')
  531. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5)').text().trim(), '', 'check row 2')
  532. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5) .dropdown.dropdown--actions').length, 0, 'check row 1')
  533. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5) .js-delete').length, 0, 'check row 1')
  534. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5) .js-clone').length, 1, 'check row 1')
  535. });
  536. QUnit.test('table test 3', assert => {
  537. App.i18n.set('de-de')
  538. $('#qunit').append('<hr><h1>table with hash</h1><div id="table-hash2"></div>')
  539. var el = $('#table-hash2')
  540. App.Group.refresh( [
  541. {
  542. id: 5,
  543. name: 'group 5',
  544. active: true,
  545. created_at: '2014-06-10T11:17:34.000Z',
  546. },
  547. ])
  548. App.Channel.configure_delete = true
  549. App.Channel.configure_clone = true
  550. App.Channel.configure_attributes = [
  551. { name: 'adapter', display: 'Type', tag: 'select', multiple: false, null: false, options: { IMAP: 'IMAP', POP3: 'POP3' } },
  552. { name: 'options::host', display: 'Host', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false },
  553. { name: 'options::user', display: 'User', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false },
  554. { name: 'options::password', display: 'Password', tag: 'input', type: 'password', limit: 120, null: true, autocapitalize: false },
  555. { name: 'options::ssl', display: 'SSL', tag: 'select', multiple: false, null: true, options: { true: 'yes', false: 'no' }, translate: true, default: true},
  556. { name: 'options::folder', display: 'Folder', tag: 'input', type: 'text', limit: 120, null: true, autocapitalize: false },
  557. { name: 'group_id', display: 'Group', tag: 'select', multiple: false, null: false, nulloption: true, relation: 'Group' },
  558. { name: 'active', display: 'Active', tag: 'select', multiple: false, null: false, options: { true: 'yes', false: 'no' }, translate: true, default: true },
  559. ]
  560. App.Channel.refresh( [
  561. {
  562. id: 1,
  563. adapter: 'adapter1',
  564. options: {
  565. host: 'host1',
  566. user: 'user1',
  567. },
  568. group_id: 5,
  569. active: true,
  570. created_at: '2014-06-10T11:17:34.000Z',
  571. },
  572. {
  573. id: 2,
  574. adapter: 'adapter2',
  575. options: {
  576. host: 'host2',
  577. user: 'user2',
  578. },
  579. group_id: 5,
  580. active: true,
  581. created_at: '2014-06-10T11:17:34.000Z',
  582. },
  583. ] )
  584. new App.ControllerTable({
  585. el: el,
  586. overview: ['adapter', 'options::host', 'options::user', 'active'],
  587. model: App.Channel,
  588. objects: App.Channel.search({sortBy:'adapter', order: 'ASC'}),
  589. })
  590. assert.equal(el.find('table > thead > tr').length, 1, 'row count')
  591. assert.equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Typ', 'check header')
  592. assert.equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Host', 'check header')
  593. assert.equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Benutzer', 'check header')
  594. assert.equal(el.find('table > thead > tr > th:nth-child(4)').text().trim(), 'Aktiv', 'check header')
  595. assert.equal(el.find('table > thead > tr > th:nth-child(5)').text().trim(), 'Aktion', 'check header')
  596. assert.equal(el.find('tbody > tr:nth-child(1) > td').length, 5, 'check row 1')
  597. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), 'adapter1', 'check row 1')
  598. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), 'host1', 'check row 1')
  599. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'user1', 'check row 1')
  600. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(4)').text().trim(), 'ja', 'check row 1')
  601. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(5) .dropdown.dropdown--actions .js-delete').length, 1, 'check row 1')
  602. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(5) .dropdown.dropdown--actions .js-clone').length, 1, 'check row 1')
  603. assert.equal(el.find('tbody > tr:nth-child(2) > td').length, 5, 'check row 2')
  604. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1)').text().trim(), 'adapter2', 'check row 2')
  605. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), 'host2', 'check row 2')
  606. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'user2', 'check row 2')
  607. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(4)').text().trim(), 'ja', 'check row 2')
  608. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5) .dropdown.dropdown--actions .js-delete').length, 1, 'check row 2')
  609. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(5) .dropdown.dropdown--actions .js-clone').length, 1, 'check row 2')
  610. });
  611. QUnit.test('table test 4', assert => {
  612. App.i18n.set('de-de')
  613. $('#qunit').append('<hr><h1>table with link</h1><div id="table-link1"></div>')
  614. var el = $('#table-link1')
  615. App.EmailAddress.refresh( [
  616. {
  617. id: 55,
  618. realname: 'realname 55',
  619. email: 'email 55',
  620. active: true,
  621. created_at: '2014-06-10T11:17:34.000Z',
  622. },
  623. {
  624. id: 56,
  625. realname: 'realname 56',
  626. email: 'email 56',
  627. active: true,
  628. created_at: '2014-06-10T11:17:34.000Z',
  629. },
  630. ])
  631. var callbackHeader = function (header) {
  632. console.log('current header is', header);
  633. // add new header item
  634. var attribute = {
  635. name: 'some name',
  636. display: 'Some Name',
  637. };
  638. header.push(attribute);
  639. console.log('new header is', header);
  640. return header
  641. }
  642. var callbackAttributes = function(value, object, attribute, header, refObject) {
  643. console.log('data of item col', value, object, attribute, header, refObject)
  644. value = ' '
  645. attribute.class = 'glyphicon glyphicon-user'
  646. attribute.link = '#'
  647. attribute.title = App.i18n.translateInline('Current User')
  648. if (object.id == 55) {
  649. attribute.data = {
  650. some: 'value55',
  651. xxx: 55,
  652. }
  653. }
  654. else {
  655. attribute.data = {
  656. some: 'value56',
  657. xxx: 56,
  658. }
  659. }
  660. return value
  661. }
  662. var switchTo = function(id, e) {
  663. e.preventDefault()
  664. console.log('switchTo with id', id, e.target)
  665. //@disconnectClient()
  666. //App.Auth._logout()
  667. //window.location = App.Config.get('api_path') + '/sessions/switch/' + id
  668. }
  669. new App.ControllerTable({
  670. el: el,
  671. model: App.EmailAddress,
  672. objects: App.EmailAddress.search({sortBy:'realname', order: 'ASC'}),
  673. callbackHeader: [callbackHeader],
  674. callbackAttributes: {
  675. 'some name': [ callbackAttributes ]
  676. },
  677. bindCol: {
  678. 'some name': {
  679. events: {
  680. 'click': switchTo,
  681. }
  682. },
  683. },
  684. })
  685. assert.equal(el.find('table > thead > tr').length, 1, 'row count')
  686. assert.equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Anzeigename', 'check header')
  687. assert.equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Some Name', 'check header')
  688. assert.equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  689. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(1)').text().trim(), 'realname 55', 'check row 1')
  690. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), 'email 55', 'check row 1')
  691. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), '', 'check row 1')
  692. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3) > a > span').hasClass('glyphicon-user'), true, 'check row 1')
  693. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3) > a > span').hasClass('glyphicon'), true, 'check row 1')
  694. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').attr('title'), 'Aktueller Benutzer', 'check row 1')
  695. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3) > a > span').data('some'), 'value55', 'check row 2')
  696. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3) > a > span').data('xxx'), '55', 'check row 2')
  697. assert.equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
  698. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(1)').text().trim(), 'realname 56', 'check row 2')
  699. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), 'email 56', 'check row 2')
  700. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), '', 'check row 2')
  701. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3) > a > span').hasClass('glyphicon-user'), true, 'check row 2')
  702. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3) > a > span').hasClass('glyphicon'), true, 'check row 2')
  703. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').attr('title'), 'Aktueller Benutzer', 'check row 2')
  704. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3) > a > span').data('some'), 'value56', 'check row 2')
  705. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3) > a > span').data('xxx'), '56', 'check row 2')
  706. });
  707. QUnit.test('table test 5', assert => {
  708. App.i18n.set('de-de')
  709. $('#qunit').append('<hr><h1>table with data</h1><div id="table-data1"></div>')
  710. var el = $('#table-data1')
  711. data = [
  712. { name: 'some name 1', data: 'some data 1', active: true },
  713. { name: 'some name 2', data: 'some data 2', active: false },
  714. { name: 'some name 3', data: 'some data 3', active: true },
  715. ]
  716. new App.ControllerTable({
  717. el: el,
  718. overview: ['name', 'data', 'active'],
  719. attribute_list: [
  720. { name: 'name', display: 'Name', type: 'text', style: 'width: 10%' },
  721. { name: 'data', display: 'Data', type: 'text' },
  722. { name: 'active', display: 'Active', type: 'text' },
  723. ],
  724. objects: data
  725. });
  726. assert.equal(el.find('table > thead > tr').length, 1, 'row count')
  727. assert.equal(el.find('table > thead > tr > th:nth-child(1)').text().trim(), 'Name', 'check header')
  728. assert.equal(el.find('table > thead > tr > th:nth-child(2)').text().trim(), 'Data', 'check header')
  729. assert.equal(el.find('table > thead > tr > th:nth-child(3)').text().trim(), 'Aktiv', 'check header')
  730. assert.equal(el.find('tbody > tr:nth-child(1) > td').length, 3, 'check row 1')
  731. assert.equal(el.find('tbody > tr:nth-child(1) > td:first').text().trim(), 'some name 1', 'check row 1')
  732. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), 'some data 1', 'check row 1')
  733. assert.equal(el.find('tbody > tr:nth-child(1) > td:nth-child(3)').text().trim(), 'true', 'check row 1')
  734. assert.equal(el.find('tbody > tr:nth-child(2) > td').length, 3, 'check row 2')
  735. assert.equal(el.find('tbody > tr:nth-child(2) > td:first').text().trim(), 'some name 2', 'check row 2')
  736. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(2)').text().trim(), 'some data 2', 'check row 2')
  737. assert.equal(el.find('tbody > tr:nth-child(2) > td:nth-child(3)').text().trim(), 'false', 'check row 2')
  738. });
  739. QUnit.test('table test 6/7', assert => {
  740. $('#qunit').append('<hr><h1>sotable table with data</h1><div id="table-data6"></div>')
  741. var el_head_sortable = $('#table-data6')
  742. $('#qunit').append('<hr><h1>not sortable table with data</h1><div id="table-data7"></div>')
  743. var el_not_head_sortable = $('#table-data7')
  744. data = [
  745. { name: 'a item', data: 'g data', active: true },
  746. { name: 'b item', data: 'b data', active: false },
  747. { name: 'c item', data: 'z data', active: false },
  748. { name: 'd item', data: '', active: false },
  749. ]
  750. new App.ControllerTable({
  751. tableId: 'a',
  752. el: el_head_sortable,
  753. overview: ['name', 'data', 'active'],
  754. attribute_list: [
  755. { name: 'name', display: 'Name', type: 'text', style: 'width: 10%', unsortable: true },
  756. { name: 'data', display: 'Data', type: 'text' },
  757. { name: 'active', display: 'Active', type: 'text' },
  758. ],
  759. objects: data
  760. });
  761. new App.ControllerTable({
  762. tableId: 'b',
  763. el: el_not_head_sortable,
  764. overview: ['name', 'data', 'active'],
  765. attribute_list: [
  766. { name: 'name', display: 'Name', type: 'text', style: 'width: 10%', unsortable: true },
  767. { name: 'data', display: 'Data', type: 'text' },
  768. { name: 'active', display: 'Active', type: 'text' },
  769. ],
  770. objects: data,
  771. dndCallback: function() { return true }
  772. });
  773. assert.equal(el_head_sortable.find('tbody > tr:nth-child(1) > td:first').text().trim(), 'a item', 'check row 1')
  774. assert.equal(el_not_head_sortable.find('tbody > tr:nth-child(1) > td:nth-child(2)').text().trim(), 'a item', 'check row 1')
  775. assert.ok(_.isEqual(list_items(el_head_sortable, 1), ['a item', 'b item', 'c item', 'd item']), 'sortable table is rendered correctly')
  776. assert.ok(_.isEqual(list_items(el_not_head_sortable, 2), ['a item', 'b item', 'c item', 'd item']), 'unsortable table is rendered correctly')
  777. click_sort(el_head_sortable, 2)
  778. click_sort(el_not_head_sortable, 3)
  779. assert.ok(_.isEqual(list_items(el_head_sortable, 1), ['b item', 'a item', 'c item', 'd item']), 'sortable table is sorted')
  780. assert.ok(_.isEqual(list_items(el_not_head_sortable, 2), ['a item', 'b item', 'c item', 'd item']), 'unsortable table is not sorted')
  781. click_sort(el_head_sortable, 3)
  782. assert.ok(_.isEqual(list_items(el_head_sortable, 1), ['b item', 'c item', 'd item', 'a item']), 'sorting by boolean column works')
  783. click_sort(el_head_sortable, 1)
  784. assert.ok(_.isEqual(list_items(el_head_sortable, 1), ['b item', 'c item', 'd item', 'a item']), 'sorting on name column is disabled')
  785. });
  786. QUnit.test('table test 8 - double escaping for translatables', assert => {
  787. $('#qunit').append('<hr><h1>table with translated and escapable data</h1><div id="table-data8"></div>')
  788. var el = $('#table-data8')
  789. data = [
  790. { name: 'some name 1', data: 'some data 1' },
  791. { name: 'some "name" 2', data: 'some data 2' },
  792. { name: 'some name 3', data: 'some data 3' },
  793. ]
  794. new App.ControllerTable({
  795. el: el,
  796. overview: ['name', 'data', 'active'],
  797. attribute_list: [
  798. { name: 'name', display: 'Name', type: 'text', tag: 'input', translate: true },
  799. { name: 'data', display: 'Data', type: 'text' },
  800. ],
  801. objects: data
  802. });
  803. assert.equal(el.find('tbody > tr:nth-child(2) > td:first-child').text().trim(), 'some "name" 2', 'check translated name with quotes')
  804. });
  805. QUnit.test('Overview grouping does not work with multi_tree_select #4408', assert => {
  806. $('#qunit').append('<hr><h1>Overview grouping does not work with multi_tree_select #4408</h1><div id="table-data9"></div>')
  807. var el = $('#table-data9')
  808. data = [
  809. { name: 'some name 1', data: ['some data 1'] },
  810. { name: 'some "name" 2', data: ['some data 2', 'some data 3'] },
  811. { name: 'some name 3', data: ['some data 3', 'some data 2'] },
  812. ]
  813. new App.ControllerTable({
  814. el: el,
  815. overview: ['name', 'data', 'active'],
  816. attribute_list: [
  817. { name: 'name', display: 'Name', type: 'text', tag: 'input', translate: true },
  818. { name: 'data', display: 'Data', type: 'multi_tree_select' },
  819. ],
  820. groupBy: 'data',
  821. objects: data
  822. });
  823. assert.equal(el.find('tbody > tr > td[colspan=1]').length, 2, '#4408 - element count')
  824. assert.deepEqual(el.find('tbody > tr > td[colspan=1]').map(function() { return $(this).text() }).get(), ['some data 1', 'some data 2, some data 3'], '#4408 - correct group descriptions')
  825. });
  826. function click_sort(table, column_number) {
  827. table
  828. .find(`table > thead > tr > th:nth-child(${column_number}) > .js-sort`)
  829. .trigger('click')
  830. }
  831. function list_items(table, column_number) {
  832. return table
  833. .find(`tbody > tr > td:nth-child(${column_number})`)
  834. .text()
  835. .split("\n")
  836. .filter(elem => elem.match(/[\w]+/))
  837. .map(elem => elem.trim())
  838. }