table.js 48 KB

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