diff --git a/entries/static/entries/js/components/Entries.js b/entries/static/entries/js/components/Entries.js index 3cde7062cfee5700837b5279768b84eea3598a16..b10f3fa714f9050b3549e5aca77876cf9d060f61 100644 --- a/entries/static/entries/js/components/Entries.js +++ b/entries/static/entries/js/components/Entries.js @@ -24,6 +24,16 @@ export default { } }, mounted () { + $('#entries-list').length && Split(['#entries-list', '#entry-display'], { + sizes: [20, 80], + minSize: 300, + gutterSize: 4, + elementStyle: (dimension, size, gutterSize) => { + return { + 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)' + } + }, + }); Split(['#right-pane', '#examples'], { direction: 'vertical', sizes: [75, 25], diff --git a/entries/static/entries/js/components/UnificationComponent.js b/entries/static/entries/js/components/UnificationComponent.js index 4dafededbb7194c9504dd3adf43a6e85b19ac5f8..29f9c7978abd799210bf0b4882252db99654635f 100644 --- a/entries/static/entries/js/components/UnificationComponent.js +++ b/entries/static/entries/js/components/UnificationComponent.js @@ -35,6 +35,16 @@ export default { if (window.initialUnifiedFrameId) { setTimeout(() => { this.unifiedFrameSelected(window.initialUnifiedFrameId); }, 1000); } + $('#entries-list').length && Split(['#entries-list', '#entry-display'], { + sizes: [20, 80], + minSize: 300, + gutterSize: 4, + elementStyle: (dimension, size, gutterSize) => { + return { + 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)' + } + }, + }); }, template: ` <div id="entries-list" class="col h-100 w-100 px-0"> diff --git a/entries/static/entries/js/components/UnificationRightPane.js b/entries/static/entries/js/components/UnificationRightPane.js index 3e635049d3bacc5ee08f58ebad1e8b5bc7b00a63..6640ec3176d6672c8f37a2fd1be9fa34fb5273dc 100644 --- a/entries/static/entries/js/components/UnificationRightPane.js +++ b/entries/static/entries/js/components/UnificationRightPane.js @@ -29,7 +29,6 @@ export default { refresh () { this.key = null; setTimeout(() => { this.key = this.lexicalUnitId; }, 0); - update_entries(); // TODO }, swapFrames (previewedUnifiedFrameId) { this.previewedUnifiedFrameId = this.unifiedFrameId; diff --git a/entries/static/entries/js/entries.js b/entries/static/entries/js/entries.js index f02c81afdf364a407610a69920bf5c0468f6431b..d9ce5ac147c0250402e674cee1033987cb2d0fad 100644 --- a/entries/static/entries/js/entries.js +++ b/entries/static/entries/js/entries.js @@ -1097,18 +1097,6 @@ function getRoleAttributes() { } $(document).ready(function() { - - Split(['#entries-list', '#entry-display'], { - sizes: [20, 80], - minSize: 300, - gutterSize: 4, - elementStyle: (dimension, size, gutterSize) => { - return { - 'flex-basis': 'calc(' + size + '% - ' + gutterSize + 'px)' - } - }, - }); - $('#semantics-top-pane').length && $('#semantics-examples-pane').length && Split(['#semantics-top-pane', '#semantics-examples-pane'], { direction: 'vertical', sizes: [75, 25], diff --git a/entries/static/entries/js/entries_index.js b/entries/static/entries/js/entries_index.js index 69f7aef94b918e0062f63093b143c1a232064887..b09d1940df0ea7a7c1a7b7c8d36eec2e5496a152 100644 --- a/entries/static/entries/js/entries_index.js +++ b/entries/static/entries/js/entries_index.js @@ -1,6 +1,6 @@ import Entries from './components/Entries.js'; const { createApp } = Vue; -window.update_entries = function () {} - -window.unificationLeftPaneApp = createApp(Entries).mount('#vue-app'); +window.update_entries = function () { + window.unificationLeftPaneApp = createApp(Entries).mount('#vue-app'); +} diff --git a/entries/static/entries/js/unification_entries_list.js b/entries/static/entries/js/unification_entries_list.js index 710824d2cadf4b0d4e44ce146a3b4e28c21a25de..5847bfac5167fe39eb4294831ac4839f2c8c58d0 100644 --- a/entries/static/entries/js/unification_entries_list.js +++ b/entries/static/entries/js/unification_entries_list.js @@ -88,7 +88,10 @@ function setup_notes($container, $template, pk, model, refreshFunction) { type : 'post', url : $('#note-form-template').data('url').replace('MODEL', model).replace('PK', pk), dataType : 'json', - data : { note: $('.note-form textarea[name=note]').val() }, + data : { + title: $('.note-form input[name=title]').val(), + note: $('.note-form textarea[name=note]').val() + }, timeout : 5000, success : function (response) { refreshFunction(); @@ -105,7 +108,39 @@ function setup_notes($container, $template, pk, model, refreshFunction) { url: $('.notes-table').data('url').replace('MODEL', model).replace('PK', pk), success: function (data) { data.notes.map(function (note) { - $('.notes-table tbody', $container).append(`<tr><td>${note.note}</td><td>${note.owner_label}</td></tr>`); + $('.notes-table tbody', $container).append( + ` + <tr role="button" data-toggle="collapse" data-target="#note-${note.pk}" class="cursor-pointer"> + <td>${note.title}</td> + <td>${note.owner_label}</td> + <td> + <a + href="#" + class="btn btn-xs btn-outline-dark float-right delete-note" + data-pk="${note.pk}" + >×</a> + </td> + </tr> + <tr id="note-${note.pk}" class="collapse v-hidden"><td colspan="3">${note.note}</td></tr> + ` + ); + $('.delete-note', $container).click(function (e) { + e.preventDefault(); + const pk = $(this).data("pk"); + if (!confirm(gettext("Czy na pewno chcesz usunąć notatkÄ™?"))) return false; + $.ajax({ + type : 'delete', + url : `/${lang}/users/notes/${pk}/delete/`, + timeout : 5000, + success : function () { + refreshFunction(); + }, + error : function () { + alert(gettext('Nie udaÅ‚o siÄ™ usunąć notatki.')); + } + }); + return false; + }); }); } }) diff --git a/entries/static/entries/js/unification_index.js b/entries/static/entries/js/unification_index.js index e4a7344fca46be90695f573c19169d3b93fa824e..a714cbd643e03fea1228bb7a8d1c01cc27f72135 100644 --- a/entries/static/entries/js/unification_index.js +++ b/entries/static/entries/js/unification_index.js @@ -2,6 +2,6 @@ import UnificationComponent from './components/UnificationComponent.js'; const { createApp } = Vue; -window.update_entries = function () {} - -window.unificationLeftPaneApp = createApp(UnificationComponent).mount('#vue-app'); +window.update_entries = function () { + window.unificationLeftPaneApp = createApp(UnificationComponent).mount('#vue-app'); +} diff --git a/users/forms.py b/users/forms.py index da41112a26828d4e545fc0ee5ccc51bb9d5265d5..26bc2e478f7a5275ccfb14a1d880e9491f16f6c6 100644 --- a/users/forms.py +++ b/users/forms.py @@ -109,4 +109,4 @@ password_reset_set_password_form_helper.layout = Layout( class NoteForm(forms.ModelForm): class Meta: model = Note - fields = ["note"] + fields = ["title", "note"] diff --git a/users/models.py b/users/models.py index df1755846d324e36822827e7fa5f6e4c3a4dd879..6d99a10abd10c4f4c0c624e7cf82d2630d3fc3c7 100644 --- a/users/models.py +++ b/users/models.py @@ -47,6 +47,7 @@ class Note(models.Model): subject_ct = models.ForeignKey(ContentType, on_delete=models.PROTECT) subject_id = models.PositiveIntegerField() subject = GenericForeignKey('subject_ct', 'subject_id') + title = models.CharField(max_length=100) note = models.TextField() created_at = models.DateTimeField(auto_now_add=True) diff --git a/users/templates/notes.html b/users/templates/notes.html index 75a7198118d195d30eac3b3082d48c72fe82d9ff..d9aa102edf93a53f6d1342393dec8f48f212dfc7 100644 --- a/users/templates/notes.html +++ b/users/templates/notes.html @@ -8,7 +8,10 @@ <a href="#" class="btn btn-xs btn-outline-dark float-right hide-note-form">×</a> </div> <div class="d-flex"> - <textarea name="note" class="form-control mr-3"></textarea> + <div class="flex-grow-1 mr-3"> + <input name="title" class="form-control mb-2" placeholder="{% trans 'TytuÅ‚ notatki' %}" /> + <textarea name="note" class="form-control" placeholder="{% trans 'Treść notatki' %}"></textarea> + </div> <a href="#" class="btn btn-sm btn-outline-dark ml-auto align-self-end add-note">{% trans 'Dodaj' %}</a> </div> </div> diff --git a/users/urls.py b/users/urls.py index 08c20de4635764614d5bef88e47e3c965c99d87c..911aa58e603246bcdcf3466aed032d379c962b4a 100644 --- a/users/urls.py +++ b/users/urls.py @@ -56,4 +56,5 @@ urlpatterns = [ ), re_path(r'^notes/(?P<model>\w+.\w+)/(?P<pk>\w+)/$', views.get_notes, name='get_notes'), re_path(r'^notes/(?P<model>\w+.\w+)/(?P<pk>\w+)/add/$', views.add_note, name='add_note'), + path('notes/<int:pk>/delete/', views.delete_note, name='delete_note'), ] diff --git a/users/views.py b/users/views.py index d12ab449cdce46ccf1d04a71cdb9847d32be4cb0..63b23cf22eec2fcafb56b1e2d3ff8e382f5b22a4 100644 --- a/users/views.py +++ b/users/views.py @@ -68,6 +68,7 @@ def get_notes(request, model, pk): "pk": note.pk, "owner_label": note.owner_label, "created_at": note.created_at, + "title": note.title, "note": note.note, } for note in notes], }) @@ -84,3 +85,11 @@ def add_note(request, model, pk): form.save() return JsonResponse({}) return JsonResponse(form.errors.get_json_data(), status=400) + + +@require_http_methods(["DELETE"]) +@login_required +def delete_note(request, pk): + note = get_object_or_404(Note.objects.for_user(request.user), pk=pk) + note.delete() + return JsonResponse({})