From 3ed43499e9ed18b8861318573f7d15264f9e1a7b Mon Sep 17 00:00:00 2001 From: Charles Connell Date: Thu, 2 Jan 2014 10:54:41 -0500 Subject: [PATCH] Flag button working --- karmaworld/apps/notes/views.py | 15 ++++++++++++--- karmaworld/assets/css/note_course_pages.css | 6 ++++++ karmaworld/assets/img/note_flag_disabled.png | Bin 0 -> 569 bytes karmaworld/assets/js/note-detail.js | 18 ++++++++++++++++++ karmaworld/templates/notes/note_detail.html | 12 ++++++------ karmaworld/urls.py | 4 +++- 6 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 karmaworld/assets/img/note_flag_disabled.png diff --git a/karmaworld/apps/notes/views.py b/karmaworld/apps/notes/views.py index bc43cb2..647cb97 100644 --- a/karmaworld/apps/notes/views.py +++ b/karmaworld/apps/notes/views.py @@ -180,8 +180,8 @@ class NoteSearchView(ListView): return super(NoteSearchView, self).get_context_data(**kwargs) -def thank_note(request, pk): - """Record that somebody has thanked a note.""" +def ajaxIncrementBase(request, pk, field): + """Increment a note's field by one.""" if not (request.method == 'POST' and request.is_ajax()): # return that the api call failed return HttpResponseBadRequest(json.dumps({'status': 'fail', 'message': 'must be a POST ajax request'}), @@ -189,7 +189,7 @@ def thank_note(request, pk): try: note = Note.objects.get(pk=pk) - note.thanks += 1 + note.__dict__[field] += 1 note.save() except ObjectDoesNotExist: return HttpResponseNotFound(json.dumps({'status': 'fail', 'message': 'note id does not match a note'}), @@ -197,3 +197,12 @@ def thank_note(request, pk): return HttpResponse(status=204) +def thank_note(request, pk): + """Record that somebody has thanked a note.""" + return ajaxIncrementBase(request, pk, 'thanks') + +def flag_note(request, pk): + """Record that somebody has flagged a note.""" + return ajaxIncrementBase(request, pk, 'flags') + + diff --git a/karmaworld/assets/css/note_course_pages.css b/karmaworld/assets/css/note_course_pages.css index 70d24e0..ed752d8 100644 --- a/karmaworld/assets/css/note_course_pages.css +++ b/karmaworld/assets/css/note_course_pages.css @@ -64,6 +64,12 @@ margin-right: 10px; } +#thank-button-disabled, +#flag-button-disabled +{ + cursor: default; +} + /* COURSES */ #course_meta, #school_meta diff --git a/karmaworld/assets/img/note_flag_disabled.png b/karmaworld/assets/img/note_flag_disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..b4fd85ff92c60b5228333b27b482ce6055e16665 GIT binary patch literal 569 zcmV-90>=G`P)P001Kh1^@s6VF;n900006VoOIv0RI60 z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru-T?v+EC^3Ol4Sq@0mey0 zK~zY`?UpetG(i-{e^?X_6Ge?aq7eH}CDfo2e<6%Y^CA`YGBo^}q;ShwpY%>#-<%V(oF_)O6DmE+7HZGwjcBg9;bRHY%4|H00000NkvXX Hu0mjf3Eu7^ literal 0 HcmV?d00001 diff --git a/karmaworld/assets/js/note-detail.js b/karmaworld/assets/js/note-detail.js index 9dc0a78..a5d175c 100644 --- a/karmaworld/assets/js/note-detail.js +++ b/karmaworld/assets/js/note-detail.js @@ -84,4 +84,22 @@ $(function() { type: 'POST' }); }); + + $("#flag-button").click(function() { + event.preventDefault(); + + // disable thank button so it can't + // be pressed again + $(this).hide(); + $('#flag-button-disabled').show(); + $(this).unbind('click'); + + // tell server that somebody thanked + // this note + $.ajax({ + url: note_flag_url, + dataType: "json", + type: 'POST' + }); + }); }); diff --git a/karmaworld/templates/notes/note_detail.html b/karmaworld/templates/notes/note_detail.html index f617e8e..3e0d4bc 100644 --- a/karmaworld/templates/notes/note_detail.html +++ b/karmaworld/templates/notes/note_detail.html @@ -12,6 +12,7 @@ {% block pagescripts %} @@ -46,18 +47,17 @@
-
+
- -
+
note_thank note_thank
-
+
note_download diff --git a/karmaworld/urls.py b/karmaworld/urls.py index 4d6846c..a3d3982 100644 --- a/karmaworld/urls.py +++ b/karmaworld/urls.py @@ -16,7 +16,7 @@ from karmaworld.apps.courses.views import school_list from karmaworld.apps.courses.views import school_course_list from karmaworld.apps.courses.views import school_course_instructor_list from karmaworld.apps.notes.models import Note -from karmaworld.apps.notes.views import NoteView, thank_note, NoteSearchView +from karmaworld.apps.notes.views import NoteView, thank_note, NoteSearchView, flag_note from karmaworld.apps.notes.views import RawNoteDetailView from karmaworld.apps.notes.views import PDFView from karmaworld.apps.moderation import moderator @@ -78,6 +78,8 @@ urlpatterns = patterns('', ## NOTE MODEL # Ajax endpoint to thank a note url(r'^ajax/note/thank/(?P[\d]+)/$', thank_note, name='thank_note'), + # Ajax endpoint to flag a note + url(r'^ajax/note/flag/(?P[\d]+)/$', flag_note, name='flag_note'), # Valid url cases to the Note page # a: school/course/id -- 2.25.1