       for n in notes
         if (n.guid not in remote_note_guid_list) && n.status != @NOTE_STATUS.NEW && n.status != @NOTE_STATUS.MODIFIED
           @delete_note(n.guid)
-          console.log('local note ' + n.guid + ' deleted.')
 
   # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| DB Operations >
 
   get_all_notes: () =>
-    return @db_server.notes.query().all().execute()
+    return new Promise (resolve, reject) =>
+      resolve(@db_server.notes.query().all().execute())
 
   delete_note: (guid) =>
-    @find_note_by_guid(guid).then (notes) =>
-      for note in notes
-        do (note) =>
+    console.log('delete_note(' + guid + ') invoked')
+    @find_note_by_guid(guid).then(
+      (note) =>
+        alert('!!')
+        if note is null
+          console.log('cannot delete note null, aborted')
+        else
+          console.log('about to remove note id ' + note.id)
           @db_server.notes.remove(note.id)
+          console.log('local note ' + note.guid + ' deleted. id: ' + note.id)
+      ,(error) =>
+        alert('error!')
+    )
 
   # fixme for debug
   add_fake_note: () =>

          # close modal
          vm.close_loading_modal()
        (error) ->
          alert('load note failed: ' + JSON.stringify(error))
          vm.close_loading_modal()
      )


  # ------------------------------------------------------------
  add_note_meta: (note) ->
    console.log('Adding note to db - guid: ' + note.guid + ' title: ' + note.title)
    return new Promise (resolve, reject) =>
      resolve(
        @db_server.notes.add({
          guid: note.guid
          title: note.title
          status: @NOTE_STATUS.SYNCED_META
        })
      )

  # ------------------------------------------------------------
  # Update a note
  # return: promise
  # ------------------------------------------------------------
  update_note: (note) ->
    console.log('update_note(' + note.guid + ')')
    # register resource data into ImageManager
    if note.resources
      for r in note.resources
        imageManager.add_image_data_mapping(r.uuid, r.data_url)
        console.log("register uuid: " + r.uuid + " data len: " + r.data_url.length)
    # update notes db
    return new Promise (resolve, reject) =>
      resolve(@db_server.notes.query('guid').only(note['guid']).modify(note).execute())

  # ------------------------------------------------------------
  # Clear db
  # return: promise
  # ------------------------------------------------------------
  clear_all_notes: () ->
    return new Promise (resolve, reject) =>
      resolve(@db_server.notes.clear())

  # --------------------------------- tmp operations --------------------------------
]
