src/render.js
function(formData, eventData) {

    var nativeFields = ['name', 'email', 'location', 'comment', 'phone', 'voip']

    var args = {
      start: eventData.start.format(),
      end: eventData.end.format(),
      description: '',
      customer: {
        name: formData.name,
        email: formData.email,
        timezone: customerTimezone
      } 
    };

    if (getConfig().project_id) {
      args.project_id = getConfig().project_id
    } else {
      $.extend(true, args, {
        what: 'Meeting with ' + formData.name,
        where: 'TBD'
      });
    }

    args.description += (getConfig().customer_fields.name.title || 'Name') + ': ' + formData.name + '\n';
    args.description += (getConfig().customer_fields.name.email || 'Email') + ': ' + formData.email + '\n';

    if (getConfig().customer_fields.location) {
      args.customer.where = formData.location;
      args.where = formData.location;
    }
    if (getConfig().customer_fields.comment) {
      args.customer.comment = formData.comment;
      args.description += (getConfig().customer_fields.comment.title || 'Comment') + ': ' + formData.comment + '\n';
    }
    if (getConfig().customer_fields.phone) {
      args.customer.phone = formData.phone;
      args.description += (getConfig().customer_fields.phone.title || 'Phone') + ': ' + formData.phone + '\n';
    }
    if (getConfig().customer_fields.voip) {
      args.customer.voip = formData.voip;
      args.description += (getConfig().customer_fields.voip.title || 'Voip') + ': ' + formData.voip + '\n';
    }

    // Save custom fields in meta object
    $.each(getConfig().customer_fields, function(key, field) {
      if ($.inArray(key, nativeFields) >= 0) return
      if (field.format === 'checkbox') formData[key] = !!formData[key]
      args.customer[key] = formData[key]
      args.description += (getConfig().customer_fields[key].title || key) + ': ' + formData[key] + '\n';
    })

    if (getConfig().booking.graph === 'group_customer' || getConfig().booking.graph === 'group_customer_payment') {
      args.related = { owner_booking_id: eventData.booking.id }
      args.resource_id = eventData.booking.resource.id
    } else if (typeof eventData.resources === 'undefined' || eventData.resources.length === 0) {
      throw triggerError(['No resources to pick from when creating booking']);
    } else {
      args.resource_id = eventData.resources[0].id
    }

    $.extend(true, args, getConfig().booking);

    utils.doCallback('createBookingStarted', args);

    var request = sdk
    .include(getConfig().create_booking_response_include)
    .createBooking(args);

    request
    .then(function(response){
      utils.doCallback('createBookingSuccessful', response);
    }).catch(function(response){
      utils.doCallback('createBookingFailed', response);
      triggerError(['An error with Timekit Create Booking occured', response]);
    });

    return request;

  }
function(formData, eventData) {

    var nativeFields = ['name', 'email', 'location', 'comment', 'phone', 'voip']

    var args = {
      start: eventData.start.format(),
      end: eventData.end.format(),
      description: '',
      customer: {
        name: formData.name,
        email: formData.email,
        timezone: customerTimezone
      } 
    };

    if (getConfig().project_id) {
      args.project_id = getConfig().project_id
    } else {
      $.extend(true, args, {
        what: 'Meeting with ' + formData.name,
        where: 'TBD'
      });
    }

    args.description += (getConfig().customer_fields.name.title || 'Name') + ': ' + formData.name + '\n';
    args.description += (getConfig().customer_fields.name.email || 'Email') + ': ' + formData.email + '\n';

    if (getConfig().customer_fields.location) {
      args.customer.where = formData.location;
      args.where = formData.location;
    }
    if (getConfig().customer_fields.comment) {
      args.customer.comment = formData.comment;
      args.description += (getConfig().customer_fields.comment.title || 'Comment') + ': ' + formData.comment + '\n';
    }
    if (getConfig().customer_fields.phone) {
      args.customer.phone = formData.phone;
      args.description += (getConfig().customer_fields.phone.title || 'Phone') + ': ' + formData.phone + '\n';
    }
    if (getConfig().customer_fields.voip) {
      args.customer.voip = formData.voip;
      args.description += (getConfig().customer_fields.voip.title || 'Voip') + ': ' + formData.voip + '\n';
    }

    // Save custom fields in meta object
    $.each(getConfig().customer_fields, function(key, field) {
      if ($.inArray(key, nativeFields) >= 0) return
      if (field.format === 'checkbox') formData[key] = !!formData[key]
      args.customer[key] = formData[key]
      args.description += (getConfig().customer_fields[key].title || key) + ': ' + formData[key] + '\n';
    })

    if (getConfig().booking.graph === 'group_customer' || getConfig().booking.graph === 'group_customer_payment') {
      args.related = { owner_booking_id: eventData.booking.id }
      args.resource_id = eventData.booking.resource.id
    } else if (typeof eventData.resources === 'undefined' || eventData.resources.length === 0) {
      throw triggerError(['No resources to pick from when creating booking']);
    } else {
      args.resource_id = eventData.resources[0].id
    }

    $.extend(true, args, getConfig().booking);

    utils.doCallback('createBookingStarted', args);

    var request = sdk
    .include(getConfig().create_booking_response_include)
    .createBooking(args);

    request
    .then(function(response){
      utils.doCallback('createBookingSuccessful', response);
    }).catch(function(response){
      utils.doCallback('createBookingFailed', response);
      triggerError(['An error with Timekit Create Booking occured', response]);
    });

    return request;

  }
function ( formData , eventData ) { var nativeFields = [ 'name' , 'email' , 'location' , 'comment' , 'phone' , 'voip' ] var args = { start : eventData . start . format ( ) , end : eventData . end . format ( ) , description : '' , customer : { name : formData . name , email : formData . email , timezone : customerTimezone } } ; if ( getConfig ( ) . project_id ) { args . project_id = getConfig ( ) . project_id } else { $ . extend ( true , args , { what : 'Meeting with ' + formData . name , where : 'TBD' } ) ; } args . description += ( getConfig ( ) . customer_fields . name . title || 'Name' ) + ': ' + formData . name + '\n' ; args . description += ( getConfig ( ) . customer_fields . name . email || 'Email' ) + ': ' + formData . email + '\n' ; if ( getConfig ( ) . customer_fields . location ) { args . customer . where = formData . location ; args . where = formData . location ; } if ( getConfig ( ) . customer_fields . comment ) { args . customer . comment = formData . comment ; args . description += ( getConfig ( ) . customer_fields . comment . title || 'Comment' ) + ': ' + formData . comment + '\n' ; } if ( getConfig ( ) . customer_fields . phone ) { args . customer . phone = formData . phone ; args . description += ( getConfig ( ) . customer_fields . phone . title || 'Phone' ) + ': ' + formData . phone + '\n' ; } if ( getConfig ( ) . customer_fields . voip ) { args . customer . voip = formData . voip ; args . description += ( getConfig ( ) . customer_fields . voip . title || 'Voip' ) + ': ' + formData . voip + '\n' ; } // Save custom fields in meta object $ . each ( getConfig ( ) . customer_fields , function ( key , field ) { if ( $ . inArray ( key , nativeFields ) >= 0 ) return if ( field . format === 'checkbox' ) formData [ key ] = ! ! formData [ key ] args . customer [ key ] = formData [ key ] args . description += ( getConfig ( ) . customer_fields [ key ] . title || key ) + ': ' + formData [ key ] + '\n' ; } ) if ( getConfig ( ) . booking . graph === 'group_customer' || getConfig ( ) . booking . graph === 'group_customer_payment' ) { args . related = { owner_booking_id : eventData . booking . id } args . resource_id = eventData . booking . resource . id } else if ( typeof eventData . resources === 'undefined' || eventData . resources . length === 0 ) { throw triggerError ( [ 'No resources to pick from when creating booking' ] ) ; } else { args . resource_id = eventData . resources [ 0 ] . id } $ . extend ( true , args , getConfig ( ) . booking ) ; utils . doCallback ( 'createBookingStarted' , args ) ; var request = sdk . include ( getConfig ( ) . create_booking_response_include ) . createBooking ( args ) ; request . then ( function ( response ) { utils . doCallback ( 'createBookingSuccessful' , response ) ; } ) . catch ( function ( response ) { utils . doCallback ( 'createBookingFailed' , response ) ; triggerError ( [ 'An error with Timekit Create Booking occured' , response ] ) ; } ) ; return request ; }
Create new booking
Create new booking