 
 
   remove: (e) =>
+    e.preventDefault()
+
     if notesManager.debug
       console.debug 'Note#remove (id=%d)', @id
     @hideEditBox e
     @bodyHide()
-    this_note = this
+
     if @is_new
       @removeCleanup()
       notice 'Note removed'
     else
       notice 'Removing note...'
-      new (Ajax.Request)('/note/update.json',
-        requestHeaders: 'X-CSRF-Token': jQuery('meta[name=csrf-token]').attr('content')
-        parameters:
-          'id': @id
-          'note[is_active]': '0'
-        onComplete: (resp) ->
-          resp = resp.responseJSON
-          if resp.success
-            notice 'Note removed'
-            this_note.removeCleanup()
-          else
-            notice 'Error: ' + resp.reason
-          return
-)
-    e.stop()
+      jQuery.ajax '/note/update.json',
+        data:
+          id: @id
+          note:
+            is_active: 0
+        dataType: 'json'
+        method: 'POST'
+      .done =>
+        notice 'Note removed'
+        @removeCleanup()
+      .fail (xhr) =>
+        notice "Error: #{xhr.responseJSON?.reason ? 'unknown error'}"
+
     return
 
 



  save: (e) =>
    if notesManager.debug
      console.debug 'Note#save (id=%d)', @id
    note = this
    for p of @fullsize
      @old[p] = @fullsize[p]
    @old.raw_body = $('edit-box-text').value

    @hideEditBox e
    @bodyHide()
    @bodyfit = false
    params =
      id: @id
      note:
        x: @old.left
        y: @old.top
        width: @old.width
        height: @old.height
        body: @old.raw_body

    if @is_new
      params.note.post_id = notesManager.post_id

    notice 'Saving note...'

    jQuery.ajax '/note/update.json',
      data: params
      dataType: 'json'
      method: 'POST'
    .done (resp) =>
      notice 'Note saved'
      if resp.old_id < 0
        @is_new = false
        @id = resp.new_id
        @elements.box.id = "note-box-#{@id}"
        @elements.body.id = "note-body-#{@id}"
        @elements.corner.id = "note-corner-#{@id}"
      @elements.body.innerHTML = resp.formatted_body
      @elements.box.setOpacity 0.5
      @elements.box.removeClassName 'unsaved'
    .fail (xhr) =>
      notice "Error: #{xhr.responseJSON?.reason ? 'unknown error'}"
      @elements.box.addClassName 'unsaved'

    return


