       result = e.target.result
       @refresh(result or [], options)
 
-  saveNote: (content) ->
+  saveNote: (content, callback) ->
     trans = Sync.db.transaction(["notes"], "readwrite")
     store = trans.objectStore "notes"
     request = store.put(content, @id)
+
+    request.onsuccess = (e) =>
+      callback() if callback
 
   loadNote: (callback) ->
     trans = Sync.db.transaction(["notes"], "readwrite")

      beforeSend: (xhr) ->
        xhr.setRequestHeader "Authorization", "Bearer " + localStorage.Token
    ).done((data) ->
      console.log data
    ).error (data) ->
      console.log "we should check if the bearer token is wrong"
      console.log "meta does not exist. uploading a new meta w/ every single file"

      promises = []
      $(Note.all()).each (i, e) ->
        e.loadNote (data) ->

          # make ajax request based on inputs from current loop element
          promises.push($.ajax(
              type: "put"
              crossDomain: true
              contentType: "application/octet-stream"
              url: "https://api-content.dropbox.com/1/files_put/sandbox/" + e.id + ".seed"
              data: data
              beforeSend: (xhr) ->
                xhr.setRequestHeader 'Authorization', 'Bearer ' + localStorage.Token
            )
          )

      # stuff
      $.when(promises).done ->
        console.log 'All files uploaded, uploading the meta file'

        $.ajax(
          type: "put"
          crossDomain: true
          contentType: "application/octet-stream"
          dataType: "json"
          url: "https://api-content.dropbox.com/1/files_put/sandbox/meta.seed"
          data: Sync.exportData()
          beforeSend: (xhr) ->
            xhr.setRequestHeader 'Authorization', 'Bearer ' + localStorage.Token
        ).done (data) ->
          console.log("all done! Delete the queue")
          localStorage.Queue = '{"Note": {}, "Notebook": {}}'


  connect: (fn) ->

      "Notebook": Notebook.toJSON()
    }
    JSON.stringify(output)

  importData: (obj) ->
    input = JSON.parse(obj)
    Note.refresh(input.Note)
    Notebook.refresh(input.Notebook)

  # Merges the client & server, using a queue
  # Spits out the result, id changes & fs changes
