| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- /* exported initializeRoutes */
- function initializeRoutes()
- {
- router('/login', routes.login);
- router('/sd', routes.sd);
-
- router('*', routes.login);
- }
- //add a 'firstLoad' setup function into the route's middleware chain
- var routes =
- {
- login: function()
- {
- showPage('login');
- },
-
- logout: function()
- {
- $.post('api/logout.php');
-
- showPage('login');
- },
-
- sd: function()
- {
- showPage('sd');
-
- loadAllData();
- }
- };
- function showPage(page)
- {
- console.log('show page', page);
-
- var $page_old = $('.screen.active');
- var $page_new = $('#screen-' + page);
-
- //do nothing if we are already on the page
- if($page_old.is($page_new))
- return;
-
- $('body').attr('class', 'screen-' + page);
-
-
- //put new page on top of old
- $page_new.insertAfter('.screen.active');
- //slide it to the right while crossfading
- $page_old
- .one('animationend', function(event) //jshint ignore:line, unused
- {
- $(this).hide();
- }) //TODO: add detect webkitanimationend or animationend
- .removeClass('active');
- //slide from left while crossfading
- $page_new
- .show()
- .off('animationend')
- .addClass('active')
- .focus(); //this needs to be used in conjunction with a "tabindex" field on the html object to maintain keyboard focus
- }
- function loadAllData()
- {
- $.post('api/getAllData.php', 'json')
- .done(function(companies)
- {
- //go through each company and add a tab if one isn't present
-
- if(!companies.length)
- return;
-
- for(var c = 0; c < companies.length; c++)
- {
- var company = companies[c];
-
- //if the company's tab doesn't exist, create it
- if($('#screen-sd ul.nav-tabs > li[data-id_company]').length === 0)
- {
- //add tab
- $('<li><a data-toggle="tab" href="#tabletab-' + company['id_company'] + '">' + company['name'] + '</a></li>')
- .appendTo('#screen-sd ul.nav-tabs');
-
- //add table
- $('<div id="tabletab-' + company['id_company'] + '" class="tab-pane fade in">'
- + '<div class="table-responsive">'
- + '<table class="table table-striped editable">'
- + '<thead>'
- + '<tr>'
- + '<th>Division</th>'
- + '<th>Consignee</th>'
- + '<th>Called In</th>'
- + '<th>Dispatch #</th>'
- + '<th>Shipper</th>'
- + '<th>Ready</th>'
- + '<th>Address 1</th>'
- + '<th>Address 2</th>'
- + '<th>City</th>'
- + '<th>ST</th>'
- + '<th>Zip</th>'
- + '<th>Phone</th>'
-
- + '<th>Ready Time</th>'
- + '<th>Close Time</th>'
- + '<th class="editable">Pickup Time</th>'
- + '<th class="editable">Depart Time</th>'
- + '<th class="editable">BOL Delivered</th>'
-
- + '<th>Dispatch Refere</th>'
-
- + '<th>Ctns</th>'
- + '<th>Weight</th>'
- + '<th>Cube</th>'
- + '</tr>'
- + '</thead>'
-
- + '<tbody></tbody>'
- //+ '<tfoot></tfoot>'
- + '</table>'
- + '</div>'
- + '</div>')
- .appendTo('#screen-sd .tab-content');
- }
-
- //empty table
- var tbody = $('#screen-sd #tabletab-' + company['id_company'] + ' table > tbody');
- tbody.empty();
-
- //add all data
- var rows = company['file_rows'];
-
- console.log(tbody);
-
- for(var r = 0; r < rows.length; r++)
- {
- var row = rows[r];
- $('<tr>'
- + '<td class="division">' + (row['division']||'') + '</td>'
- + '<td class="consignee">' + (row['consignee']||'') + '</td>'
- + '<td class="date_called_in">' + (row['date_called_in']||'') + '</td>'
- + '<td class="dispatch_number">' + (row['dispatch_number']||'') + '</td>'
- + '<td class="shipper">' + (row['shipper']||'') + '</td>'
- + '<td class="date_ready">' + (row['date_ready']||'') + '</td>'
- + '<td class="address_1">' + (row['address_1']||'') + '</td>'
- + '<td class="address_2">' + (row['address_2']||'') + '</td>'
- + '<td class="city">' + (row['city']||'') + '</td>'
- + '<td class="state">' + (row['state']||'') + '</td>'
- + '<td class="zip">' + (row['zip']||'') + '</td>'
- + '<td class="phone">' + (row['phone']||'') + '</td>'
- + '<td class="time_ready">' + (row['time_ready']||'') + '</td>'
- + '<td class="time_close">' + (row['time_close']||'') + '</td>'
-
- + '<td class="time_pickup">' + (row['time_pickup']||'') + '</td>'
- + '<td class="time_depart">' + (row['time_depart']||'') + '</td>'
- + '<td class="bol_delivered">' + (row['bol_delivered']||'') + '</td>'
- + '<td class="dispatch_reference">' + (row['dispatch_reference']||'') + '</td>'
- + '<td class="ctns">' + (row['ctns']||'') + '</td>'
- + '<td class="weight">' + (row['weight']||'') + '</td>'
- + '<td class="cube">' + (row['cube']||'') + '</td>'
- + '</tr>')
- .appendTo(tbody);
- }
- }
-
- if($('#screen-sd ul.nav-tabs > li.active').length === 0)
- $('#screen-sd ul.nav-tabs > li:eq(0) a').click();
-
-
- $('table.editable').editableTableWidget();
-
- $('table.editable td').off('change').on('change', function(evt, newValue)
- {
- // do something with the new cell value
- /* if (....) {
- return false; // reject change
- }
- */
- });
- })
- .fail(function(err, xhr, text)
- {
- console.error(err.responseText);
- });
- }
- function loadCompanies()
- {
- $.post('api/getCompanies.php')
- .done(function(response)
- {
-
- })
- .fail(function(err, xhr, text)
- {
- console.error(err.responseText);
- });
- }
- function addCompany(company)
- {
- }
|