/* 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 $('
  • ' + company['name'] + '
  • ') .appendTo('#screen-sd ul.nav-tabs'); //add table $('
    ' + '
    ' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' //+ '' + '
    DivisionConsigneeCalled InDispatch #ShipperReadyAddress 1Address 2CitySTZipPhoneReady TimeClose TimePickup TimeDepart TimeBOL DeliveredDispatch RefereCtnsWeightCube
    ' + '
    ' + '
    ') .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]; $('' + '' + (row['division']||'') + '' + '' + (row['consignee']||'') + '' + '' + (row['date_called_in']||'') + '' + '' + (row['dispatch_number']||'') + '' + '' + (row['shipper']||'') + '' + '' + (row['date_ready']||'') + '' + '' + (row['address_1']||'') + '' + '' + (row['address_2']||'') + '' + '' + (row['city']||'') + '' + '' + (row['state']||'') + '' + '' + (row['zip']||'') + '' + '' + (row['phone']||'') + '' + '' + (row['time_ready']||'') + '' + '' + (row['time_close']||'') + '' + '' + (row['time_pickup']||'') + '' + '' + (row['time_depart']||'') + '' + '' + (row['bol_delivered']||'') + '' + '' + (row['dispatch_reference']||'') + '' + '' + (row['ctns']||'') + '' + '' + (row['weight']||'') + '' + '' + (row['cube']||'') + '' + '') .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) { }