Advertisement
Guest User

mampf

a guest
Aug 21st, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. srv = ['$http', 'config', ($http, config) ->
  2.  
  3.   baseHTTP = (opts) ->
  4.     $http({
  5.       method: opts.method
  6.       url: "#{config.server}"
  7.       data: opts.data})
  8.   {
  9.     create: (opts) ->
  10.       baseHTTP(angular.extend(opts, {
  11.         method: 'POST'
  12.         data: JSON.stringify(opts.data, null, '  ')
  13.         headers: {
  14.           'Access-Control-Allow-Origin': '*',
  15.           'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
  16.           'Access-Control-Allow-Headers': 'Content-Type, X-Requested-With',
  17.           'Content-Type': 'application/json'
  18.         }
  19.       }))
  20.     update: (opts) ->
  21.       baseHTTP(angular.extend(opts, { method: 'PUT' }))
  22.     delete: (opts) ->
  23.       baseHTTP(angular.extend(opts, { method: 'DELETE' }))
  24.     get: (opts) ->
  25.       baseHTTP(angular.extend(opts, { method: 'GET' }))
  26.     callbackError: ->
  27.       console.log "yay error"
  28.     callbackDone: ->
  29.       console.log "yay done"
  30.   }
  31. ]
  32.  
  33. module.exports = srv
  34.  
  35.  
  36. .....
  37.  
  38.  
  39. $scope.doRequest = ->
  40.     # first format dates according to API specification
  41.     #tmpDate = new Date()
  42.     #dateString = "#{tmpDate.getFullYear()}-#{tmpDate.getMonth()+1}-#{tmpDate.getDate()}"
  43.     #startTime = new Date(Date.parse("#{dateString}, #{$scope.request.startTime}")).toISOString()
  44.     #endTime = new Date(Date.parse("#{dateString}, #{$scope.request.endTime}")).toISOString()
  45.     # second, fetch invitees' hashes
  46.    inviteeHashes = sharedData.contacts.filter((contact) -> contact.selected).map((contact) -> contact.telephoneHash)
  47.    # third, fetch the own users md5
  48.    telephoneHash = $scope.user.telephoneHash
  49.  
  50.    # either fetch the current position or use predefined destination
  51.    _getLocation().then (coords) ->
  52.  
  53.      request =
  54.      identity: telephoneHash
  55.      invitees: inviteeHashes
  56.      currentPosition: coords
  57.      timeSlots: sharedData.timeslots # [ #for testing reasons only one allowed
  58.       # {
  59.       #   startTime: startTime
  60.       #   endTime: endTime
  61.       # }
  62.      #]
  63.      server.create({data: JSON.stringify(request, null, '  ')})
  64.        .success (response) ->
  65.          console.log "we have a response", response
  66.        .error (error) ->
  67.          console.log "fehler", error
  68.  
  69.    , (error) ->
  70.      console.log "oops error while retrieving coordinates", error
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement