routes.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* exported initializeRoutes */
  2. function initializeRoutes()
  3. {
  4. router('/login', routes.login);
  5. router('/sd', routes.sd);
  6. router('*', routes.login);
  7. }
  8. //add a 'firstLoad' setup function into the route's middleware chain
  9. var routes =
  10. {
  11. login: function()
  12. {
  13. showPage('login');
  14. },
  15. logout: function()
  16. {
  17. $.post('api/logout.php');
  18. showPage('login');
  19. },
  20. sd: function()
  21. {
  22. showPage('sd');
  23. loadAllData();
  24. }
  25. };
  26. function showPage(page)
  27. {
  28. console.log('show page', page);
  29. var $page_old = $('.screen.active');
  30. var $page_new = $('#screen-' + page);
  31. //do nothing if we are already on the page
  32. if($page_old.is($page_new))
  33. return;
  34. $('body').attr('class', 'screen-' + page);
  35. //put new page on top of old
  36. $page_new.insertAfter('.screen.active');
  37. //slide it to the right while crossfading
  38. $page_old
  39. .one('animationend', function(event) //jshint ignore:line, unused
  40. {
  41. $(this).hide();
  42. }) //TODO: add detect webkitanimationend or animationend
  43. .removeClass('active');
  44. //slide from left while crossfading
  45. $page_new
  46. .show()
  47. .off('animationend')
  48. .addClass('active')
  49. .focus(); //this needs to be used in conjunction with a "tabindex" field on the html object to maintain keyboard focus
  50. }
  51. function loadAllData()
  52. {
  53. $.post('api/getAllData.php', 'json')
  54. .done(function(companies)
  55. {
  56. //go through each company and add a tab if one isn't present
  57. if(!companies.length)
  58. return;
  59. for(var c = 0; c < companies.length; c++)
  60. {
  61. var company = companies[c];
  62. //if the company's tab doesn't exist, create it
  63. if($('#screen-sd ul.nav-tabs > li[data-id_company]').length === 0)
  64. {
  65. //add tab
  66. $('<li><a data-toggle="tab" href="#tabletab-' + company['id_company'] + '">' + company['name'] + '</a></li>')
  67. .appendTo('#screen-sd ul.nav-tabs');
  68. //add table
  69. $('<div id="tabletab-' + company['id_company'] + '" class="tab-pane fade in">'
  70. + '<div class="table-responsive">'
  71. + '<table class="table table-striped editable">'
  72. + '<thead>'
  73. + '<tr>'
  74. + '<th>Division</th>'
  75. + '<th>Consignee</th>'
  76. + '<th>Called&nbsp;In</th>'
  77. + '<th>Dispatch&nbsp;#</th>'
  78. + '<th>Shipper</th>'
  79. + '<th>Ready</th>'
  80. + '<th>Address&nbsp;1</th>'
  81. + '<th>Address&nbsp;2</th>'
  82. + '<th>City</th>'
  83. + '<th>ST</th>'
  84. + '<th>Zip</th>'
  85. + '<th>Phone</th>'
  86. + '<th>Ready&nbsp;Time</th>'
  87. + '<th>Close&nbsp;Time</th>'
  88. + '<th class="editable">Pickup&nbsp;Time</th>'
  89. + '<th class="editable">Depart&nbsp;Time</th>'
  90. + '<th class="editable">BOL&nbsp;Delivered</th>'
  91. + '<th>Dispatch&nbsp;Refere</th>'
  92. + '<th>Ctns</th>'
  93. + '<th>Weight</th>'
  94. + '<th>Cube</th>'
  95. + '</tr>'
  96. + '</thead>'
  97. + '<tbody></tbody>'
  98. //+ '<tfoot></tfoot>'
  99. + '</table>'
  100. + '</div>'
  101. + '</div>')
  102. .appendTo('#screen-sd .tab-content');
  103. }
  104. //empty table
  105. var tbody = $('#screen-sd #tabletab-' + company['id_company'] + ' table > tbody');
  106. tbody.empty();
  107. //add all data
  108. var rows = company['file_rows'];
  109. console.log(tbody);
  110. for(var r = 0; r < rows.length; r++)
  111. {
  112. var row = rows[r];
  113. $('<tr>'
  114. + '<td class="division">' + (row['division']||'') + '</td>'
  115. + '<td class="consignee">' + (row['consignee']||'') + '</td>'
  116. + '<td class="date_called_in">' + (row['date_called_in']||'') + '</td>'
  117. + '<td class="dispatch_number">' + (row['dispatch_number']||'') + '</td>'
  118. + '<td class="shipper">' + (row['shipper']||'') + '</td>'
  119. + '<td class="date_ready">' + (row['date_ready']||'') + '</td>'
  120. + '<td class="address_1">' + (row['address_1']||'') + '</td>'
  121. + '<td class="address_2">' + (row['address_2']||'') + '</td>'
  122. + '<td class="city">' + (row['city']||'') + '</td>'
  123. + '<td class="state">' + (row['state']||'') + '</td>'
  124. + '<td class="zip">' + (row['zip']||'') + '</td>'
  125. + '<td class="phone">' + (row['phone']||'') + '</td>'
  126. + '<td class="time_ready">' + (row['time_ready']||'') + '</td>'
  127. + '<td class="time_close">' + (row['time_close']||'') + '</td>'
  128. + '<td class="time_pickup">' + (row['time_pickup']||'') + '</td>'
  129. + '<td class="time_depart">' + (row['time_depart']||'') + '</td>'
  130. + '<td class="bol_delivered">' + (row['bol_delivered']||'') + '</td>'
  131. + '<td class="dispatch_reference">' + (row['dispatch_reference']||'') + '</td>'
  132. + '<td class="ctns">' + (row['ctns']||'') + '</td>'
  133. + '<td class="weight">' + (row['weight']||'') + '</td>'
  134. + '<td class="cube">' + (row['cube']||'') + '</td>'
  135. + '</tr>')
  136. .appendTo(tbody);
  137. }
  138. }
  139. if($('#screen-sd ul.nav-tabs > li.active').length === 0)
  140. $('#screen-sd ul.nav-tabs > li:eq(0) a').click();
  141. $('table.editable').editableTableWidget();
  142. $('table.editable td').off('change').on('change', function(evt, newValue)
  143. {
  144. // do something with the new cell value
  145. /* if (....) {
  146. return false; // reject change
  147. }
  148. */
  149. });
  150. })
  151. .fail(function(err, xhr, text)
  152. {
  153. console.error(err.responseText);
  154. });
  155. }
  156. function loadCompanies()
  157. {
  158. $.post('api/getCompanies.php')
  159. .done(function(response)
  160. {
  161. })
  162. .fail(function(err, xhr, text)
  163. {
  164. console.error(err.responseText);
  165. });
  166. }
  167. function addCompany(company)
  168. {
  169. }