Created
October 23, 2014 18:15
-
-
Save jakobdamjensen/ea97011bb1380d2944be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var convertDateTimeFieldsToDate = function( date, time, template ) { | |
var startDate = document.querySelector( date ).value, | |
startDateSplitted = startDate.match( /([0-9]{2})\/([0-9]{2})-([0-9]{4})/ ), | |
startTime = document.querySelector( time ).value, | |
startTimeSplitted = startTime.match( /([0-9]{2}):([0-9]{2})/ ), | |
year = startDateSplitted[ 3 ], | |
month = startDateSplitted[ 2 ], | |
day = startDateSplitted[ 1 ], | |
hour = startTimeSplitted[ 1 ], | |
minutes = startTimeSplitted[ 2 ]; | |
return new Date( year, month, day, hour, minutes ); | |
}; | |
AutoForm.addHooks( [ 'event-new__form', 'event-edit__form' ], { | |
formToDoc: function( doc, ss, formId ) { | |
doc.start = convertDateTimeFieldsToDate( "#event-form__start-date", "#event-form__start-time" ); | |
doc.end = convertDateTimeFieldsToDate( "#event-form__end-date", "#event-form__end-time" ); | |
if( formId === 'event-new__form' ) { | |
doc.groupId = Router.current().params.networkGroupId; | |
} | |
return doc; | |
}, | |
onSuccess: function( operation, result, template ) { | |
var networkGroupId = Router.current().params.networkGroupId, | |
view = result; | |
Router.go( 'events', { view, networkGroupId } ); | |
NavComponents.modalWrapperWithId('app-modal-wrapper').hide(); | |
}, | |
// Called when any operation fails, where operation will be | |
// "validation", "insert", "update", or the method name. | |
onError: function( operation, error, template ) { | |
console.error( arguments ); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment