From: Magnus Hagander Date: Fri, 19 Jul 2013 14:39:57 +0000 (+0200) Subject: Break out the thread browsing functionality and create a widget for it X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=520992c4ab012ee26f4f302b7cc15331e61746ba;p=pgcommitfest2.git Break out the thread browsing functionality and create a widget for it Also, move the javascript to a shared javascript file --- diff --git a/pgcommitfest/commitfest/static/commitfest/js/commitfest.js b/pgcommitfest/commitfest/static/commitfest/js/commitfest.js new file mode 100644 index 0000000..8f84d8b --- /dev/null +++ b/pgcommitfest/commitfest/static/commitfest/js/commitfest.js @@ -0,0 +1,111 @@ +function verify_reject() { + return confirm('Are you sure you want to close this patch as Rejected?\n\nThis should only be done when a patch will never be applied - if more work is needed, it should instead be set to "Returned with Feedback".\n\nSo - are you sure?'); +} +function verify_returned() { + return confirm('Are you sure you want to close this patch as Returned with Feedback?\n\nThis means the patch will be marked as closed in this commitfest, but will automatically be moved to the next one. If no further work is expected on this patch, it should be closed with "Rejected" istead.\n\nSo - are you sure?'); +} +function verify_committed(is_committer) { + if (is_committer) + return confirm('Are you sure you want to close this patch as Committed?'); + else { + alert('Currently, only the committer who actually made the commit can do this. We should make a little prompt for the committer field otherwise..'); + return false; + } +} + +function findLatestThreads() { + $('#attachThreadListWrap').addClass('loading'); + $('#attachThreadSearchButton').addClass('disabled'); + $.get('/ajax/getThreads/', { + 's': $('#attachThreadSearchField').val(), + }).success(function(data) { + sel = $('#attachThreadList'); + sel.find('option').remove(); + $.each(data, function(m,i) { + sel.append(''); + }); + }).always(function() { + $('#attachThreadListWrap').removeClass('loading'); + $('#attachThreadSearchButton').removeClass('disabled'); + attachThreadChanged(); + }); + return false; +} + +function browseThreads(attachfunc) { + $('#attachThreadList').find('option').remove(); + $('#attachThreadMessageId').val(''); + $('#attachModal').modal(); + findLatestThreads(); + + $('#doAttachThreadButton').unbind('click'); + $('#doAttachThreadButton').click(function() { + msgid = $('#attachThreadMessageId').val(); + if (!msgid || msgid == '') { + msgid = $('#attachThreadList').val(); + if (!msgid) return; + } + + $('#attachThreadListWrap').addClass('loading'); + $('#attachThreadSearchButton').addClass('disabled'); + $('#attachThreadButton').addClass('disabled'); + if (attachfunc(msgid)) { + $('#attachModal').modal('hide'); + } + $('#attachThreadListWrap').removeClass('loading'); + $('#attachThreadSearchButton').removeClass('disabled'); + attachThreadChanged(); + }); + +} + +function attachThread(cfid, patchid) { + browseThreads(function(msgid) { + doAttachThread(cfid, patchid, msgid); + }); +} + +function detachThread(cfid, patchid, msgid) { + if (confirm('Are you sure you want to detach the thread with messageid "' + msgid + '" from this patch?')) { + $.post('/ajax/detachThread/', { + 'cf': cfid, + 'p': patchid, + 'msg': msgid, + }).success(function(data) { + location.reload(); + }).fail(function(data) { + alert('Failed to detach thread!'); + }); + } +} + +function attachThreadChanged() { + if ($('#attachThreadList').val() || $('#attachThreadMessageId').val()) { + $('#doAttachThreadButton').removeClass('disabled'); + } + else { + $('#doAttachThreadButton').addClass('disabled'); + } +} + +function doAttachThread(cfid, patchid, msgid) { + $.post('/ajax/attachThread/', { + 'cf': cfid, + 'p': patchid, + 'msg': msgid, + }).success(function(data) { + location.reload(); + return true; + }).fail(function(data) { + if (data.status == 404) { + alert('Message with messageid ' + msgid + ' not found'); + } + else if (data.status == 503) { + alert('Failed to attach thread: ' + data.responseText); + } + else { + alert('Failed to attach thread: ' + data.statusText); + } + return false; + }); +} diff --git a/pgcommitfest/commitfest/templates/base.html b/pgcommitfest/commitfest/templates/base.html index 644c975..4e94f13 100644 --- a/pgcommitfest/commitfest/templates/base.html +++ b/pgcommitfest/commitfest/templates/base.html @@ -43,5 +43,6 @@ li.selectable-deck-item .selectable-deck-remove { + {%block morescript%}{%endblock%} diff --git a/pgcommitfest/commitfest/templates/base_form.html b/pgcommitfest/commitfest/templates/base_form.html index e204c34..f51bf76 100644 --- a/pgcommitfest/commitfest/templates/base_form.html +++ b/pgcommitfest/commitfest/templates/base_form.html @@ -45,4 +45,26 @@ div.control-group div.controls ul li label { +{%if threadbrowse %} +{%include "thread_attach.inc" %} +{%endif%} +{%endblock%} + +{%if threadbrowse %} +{%block morescript%} + {%endblock%} +{%endif%} diff --git a/pgcommitfest/commitfest/templates/patch.html b/pgcommitfest/commitfest/templates/patch.html index 26071b1..562d7e6 100644 --- a/pgcommitfest/commitfest/templates/patch.html +++ b/pgcommitfest/commitfest/templates/patch.html @@ -2,16 +2,6 @@ {%load commitfest%} {%block contents%} + + diff --git a/pgcommitfest/commitfest/widgets.py b/pgcommitfest/commitfest/widgets.py new file mode 100644 index 0000000..623643f --- /dev/null +++ b/pgcommitfest/commitfest/widgets.py @@ -0,0 +1,8 @@ +from django.forms import TextInput +from django.utils.safestring import mark_safe + +class ThreadPickWidget(TextInput): + def render(self, name, value, attrs=None): + html = super(ThreadPickWidget, self).render(name, value, attrs) + html = html + ' ' % name + return mark_safe(html)