diff --git a/assets/javascripts/discourse/adapters/staff-note.js.es6 b/assets/javascripts/discourse/adapters/staff-note.js.es6
new file mode 100644
index 0000000..a9189d3
--- /dev/null
+++ b/assets/javascripts/discourse/adapters/staff-note.js.es6
@@ -0,0 +1,11 @@
+import RestAdapter from 'discourse/adapters/rest';
+const ajax = Discourse.ajax;
+
+export default RestAdapter.extend({
+ destroyRecord(store, type, record) {
+ const path = this.pathFor(store, type, record.get('id'));
+ const userId = record.get('user_id');
+ return ajax(`${path}?user_id=${userId}`, { method: 'DELETE' });
+ }
+});
+
diff --git a/assets/javascripts/discourse/controllers/staff-notes.js.es6 b/assets/javascripts/discourse/controllers/staff-notes.js.es6
index 80cd594..01d1cc3 100644
--- a/assets/javascripts/discourse/controllers/staff-notes.js.es6
+++ b/assets/javascripts/discourse/controllers/staff-notes.js.es6
@@ -23,6 +23,10 @@ export default Ember.Controller.extend({
this.set('newNote', '');
this.get('model').pushObject(note);
}).catch(popupAjaxError).finally(() => this.set('saving', false));
+ },
+
+ removeNote(note) {
+ note.destroyRecord().then(() => this.get('model').removeObject(note));
}
}
});
diff --git a/assets/javascripts/discourse/templates/modal/staff-notes.hbs b/assets/javascripts/discourse/templates/modal/staff-notes.hbs
index edf4580..e76d127 100644
--- a/assets/javascripts/discourse/templates/modal/staff-notes.hbs
+++ b/assets/javascripts/discourse/templates/modal/staff-notes.hbs
@@ -11,6 +11,15 @@
{{n.created_by.username}}
{{age-with-tooltip n.created_at}}
+
+
+ {{d-button action="removeNote"
+ actionParam=n
+ icon="times"
+ class="btn-small btn-danger"
+ title="staff_notes.remove"}}
+
+
diff --git a/assets/stylesheets/staff_notes.scss b/assets/stylesheets/staff_notes.scss
index bb9817f..659acfe 100644
--- a/assets/stylesheets/staff_notes.scss
+++ b/assets/stylesheets/staff_notes.scss
@@ -1,8 +1,12 @@
.modal-body.staff-notes-modal {
height: 300px;
+ -webkit-box-sizing: border-box;
+ -moz-box-sizing: border-box;
+ box-sizing: border-box;
+
textarea {
- width: 99%;
+ width: 98%;
}
.posted-by {
@@ -29,7 +33,7 @@
margin-bottom: 1em;
}
- .post-date {
+ .controls {
float: right;
}
}
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 0f128b7..75323e8 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -3,3 +3,4 @@ en:
staff_notes:
title: "Staff Notes"
attach: "Attach Note"
+ remove: "Remove Note"
diff --git a/plugin.rb b/plugin.rb
index ce7bbca..a319254 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -27,23 +27,39 @@ after_initialize do
def self.add_note(user_id, raw, created_by)
notes = notes_for(user_id)
- record = { id: SecureRandom.hex(16), raw: raw, created_by: created_by, created_at: Time.now }
+ record = { id: SecureRandom.hex(16), user_id: user_id, raw: raw, created_by: created_by, created_at: Time.now }
notes << record
::PluginStore.set("staff_notes", key_for(user_id), notes)
record
end
+ def self.remove_note(user_id, note_id)
+ notes = notes_for(user_id)
+ notes.reject! {|n| n[:id] == note_id}
+
+ if notes.size > 0
+ ::PluginStore.set("staff_notes", key_for(user_id), notes)
+ else
+ ::PluginStore.remove("staff_notes", key_for(user_id))
+ end
+
+ end
+
end
require_dependency 'application_serializer'
class ::StaffNoteSerializer < ApplicationSerializer
- attributes :id, :raw, :created_by, :created_at
+ attributes :id, :user_id, :raw, :created_by, :created_at
def id
object[:id]
end
+ def user_id
+ object[:user_id]
+ end
+
def raw
object[:raw]
end
@@ -85,11 +101,21 @@ after_initialize do
render json: serialize_data(staff_note, ::StaffNoteSerializer)
end
+
+ def destroy
+ user = User.where(id: params[:user_id]).first
+ raise Discourse::NotFound if user.blank?
+
+ ::DiscourseStaffNotes.remove_note(user.id, params[:id])
+ render json: success_json
+ end
+
end
DiscourseStaffNotes::Engine.routes.draw do
get '/' => 'staff_notes#index'
post '/' => 'staff_notes#create'
+ delete '/:id' => 'staff_notes#destroy'
end
Discourse::Application.routes.append do