Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- srv = ['$http', 'config', ($http, config) ->
- baseHTTP = (opts) ->
- $http({
- method: opts.method
- url: "#{config.server}"
- data: opts.data})
- {
- create: (opts) ->
- baseHTTP(angular.extend(opts, {
- method: 'POST'
- data: JSON.stringify(opts.data, null, ' ')
- headers: {
- 'Access-Control-Allow-Origin': '*',
- 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
- 'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With',
- 'Content-Type': 'application/json'
- }
- }))
- update: (opts) ->
- baseHTTP(angular.extend(opts, { method: 'PUT' }))
- delete: (opts) ->
- baseHTTP(angular.extend(opts, { method: 'DELETE' }))
- get: (opts) ->
- baseHTTP(angular.extend(opts, { method: 'GET' }))
- callbackError: ->
- console.log "yay error"
- callbackDone: ->
- console.log "yay done"
- }
- ]
- module.exports = srv
- .....
- $scope.doRequest = ->
- # first format dates according to API specification
- #tmpDate = new Date()
- #dateString = "#{tmpDate.getFullYear()}-#{tmpDate.getMonth()+1}-#{tmpDate.getDate()}"
- #startTime = new Date(Date.parse("#{dateString}, #{$scope.request.startTime}")).toISOString()
- #endTime = new Date(Date.parse("#{dateString}, #{$scope.request.endTime}")).toISOString()
- # second, fetch invitees' hashes
- inviteeHashes = sharedData.contacts.filter((contact) -> contact.selected).map((contact) -> contact.telephoneHash)
- # third, fetch the own users md5
- telephoneHash = $scope.user.telephoneHash
- # either fetch the current position or use predefined destination
- _getLocation().then (coords) ->
- request =
- identity: telephoneHash
- invitees: inviteeHashes
- currentPosition: coords
- timeSlots: sharedData.timeslots # [ #for testing reasons only one allowed
- # {
- # startTime: startTime
- # endTime: endTime
- # }
- #]
- server.create({data: JSON.stringify(request, null, ' ')})
- .success (response) ->
- console.log "we have a response", response
- .error (error) ->
- console.log "fehler", error
- , (error) ->
- console.log "oops error while retrieving coordinates", error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement