|
- (function ($) {
- $(function () {
- /*_____________________________________________*/
-
- function test(){
- var temp = $('#bts_staff_hours_template').html();
- var lines = [];
- for (var i=1; i<10; i++){
- var data = {
- staff_name: 'john',
- rate_name : 'some rate name',
- staff_id:"abc_"+ i,
- };
- data.days={};
- for (var j =1; j<=14; j++){
- data['days_' + j] = j + '/July';
- }
- lines.push(data);
- }
- var html = Mustache.render(temp, {lines:lines});
- $('#staff').append(html);
- }
- function datebox(){
- $( ".boundary_datepicker" ).datepicker();
- $( ".boundary_datepicker" ).datepicker("option", "dateFormat", "yy-mm-dd");
- }
-
- function display_hour_lines(response)
- {
- $('#staff').html();
- var temp = $('#bts_staff_hours_template').html();
- var html = Mustache.render(temp, response);
- $('#staff').append(html);
- }
-
- function set_payroll_calendar(cal)
- {
- $('#cstart').attr('value', cal.start);
- $('#cfinish').attr('value', cal.finish);
- $('#paydate').attr('value', cal.paydate);
- }
-
- function get_timesheet_from_xero(){
- $.post(bts().ajax_url, { // POST request
- _ajax_nonce: bts().nonce, // nonce
- action: "get_timesheet_from_xero", // action
- sync: false,
- }).done(function(response){
- set_payroll_calendar(response.payroll_calendar);
- console.log("%o", response);
- display_hour_lines(response);
- }).fail(function(){
- console.warn('failed');
- }).always(function(){
- console.log('completed');
- });
- }
-
- function sync_timesheet_from_xero(){
- $.post(bts().ajax_url, { // POST request
- _ajax_nonce: bts().nonce, // nonce
- action: "get_timesheet_from_xero", // action
- sync: true,
- }).done(function(response){
- set_payroll_calendar(response.payroll_calendar);
- console.log("%o", response);
- display_hour_lines(response);
- }).fail(function(){
- console.warn('failed');
- }).always(function(){
- console.log('completed');
- });
- }
- $('#sync_timesheet').click(function(){
- sync_timesheet_from_xero();
- });
- /*_____________________________________________*/
- });
- })(jQuery);
|