Commit afa8b10a authored by Tanner Prestegard's avatar Tanner Prestegard Committed by GraceDB

events: update web view/form for grbevent updates

parent 6652534a
......@@ -3,7 +3,7 @@ import logging
from django import forms
from django.utils.safestring import mark_safe
from django.utils.html import escape
from .models import Event, Group, Label
from .models import Event, Group, Label, GrbEvent
from .models import Pipeline, Search, Signoff
from django.contrib.auth.models import User
from django.core.exceptions import FieldError
......@@ -49,3 +49,10 @@ class SignoffForm(ModelForm):
class Meta:
model = Signoff
fields = [ 'status', 'comment' ]
class GrbEventUpdateForm(ModelForm):
class Meta:
model = GrbEvent
fields = ['ra', 'dec', 'error_radius', 't90', 'redshift',
'designation']
......@@ -16,7 +16,7 @@ from core.file_utils import get_file_list
from core.http import check_and_serve_file
from .models import Event, Group, EventLog, Label, Tag, Pipeline, Search, GrbEvent
from .models import EMGroup, Signoff, PipelineLog
from .forms import CreateEventForm, SignoffForm
from .forms import CreateEventForm, SignoffForm, GrbEventUpdateForm
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.models import User, Permission
......@@ -369,8 +369,15 @@ def view(request, event):
# given permission to access an event. We want it to be the observers group.
context['lvem_group_name'] = settings.LVEM_OBSERVERS_GROUP
# GRB event update permissions/form
if event.pipeline.name in settings.GRB_PIPELINES:
context['can_modify_t90'] = request.user.has_perm('events.t90_grbevent')
context['can_update_grbevent'] = request.user.has_perm(
'events.t90_grbevent')
# If the user has permission, add the form
if context['can_update_grbevent']:
context['update_grbevent_form'] = \
GrbEventUpdateForm(instance=event)
# Is the user an external user? (I.e., not part of the LVC?) The template
# needs to know that in order to decide what pieces of information to show.
......
......@@ -12,6 +12,7 @@
<script src="{% static "moment/moment.js" %}"></script>
<script src="{% static "moment-timezone/builds/moment-timezone-with-data.min.js" %}"></script>
<script src="{% static "dojo/dojo.js" %}" data-dojo-config="async: true"></script>
<script src="{% static "jquery/dist/jquery.min.js" %}"></script>
<!-- Styles for dgrid -->
<!-- <link rel="stylesheet" href="{% static "dgrid/css/dgrid.css" %}" /> -->
<!-- Styles for the editor components -->
......
......@@ -90,19 +90,18 @@
</tbody>
</table>
{% if can_modify_t90 %}
{% if can_update_grbevent %}
<div class="content-area">
<form action="{% url "modify_t90" object.graceid %}" method="post">
<input type="text" name="t90" value="{{ object.t90 }}">
<input type="submit" value="Update T90" class="t90ButtonClass">
</form>
<form action="{% url "modify_t90" object.graceid %}" method="post">
<input type="text" name="redshift" value="{{ object.redshift }}">
<input type="submit" value="Update redshift" class="t90ButtonClass">
</form>
<form action="{% url "modify_t90" object.graceid %}" method="post">
<input type="text" name="designation" value="{{ object.designation }}">
<input type="submit" value="Update designation" class="t90ButtonClass">
<h3>Update GRB Event</h3>
<form id="update_grbevent_form" action="{% url "legacy_apiweb:default:events:update-grbevent" object.graceid %}">
<table>
{{ update_grbevent_form.as_table }}
<tr>
<td></td>
<td><input type="submit" value="Update" disabled></td>
</tr>
</table>
</form>
</div>
{% endif %}
......
......@@ -225,6 +225,49 @@ require([
Save, Preview, ScrollPane, Uploader) {
parser.parse();
// We don't enable the input buttons until right now otherwise fast users
// can trigger the form before the javascript is ready... not ideal
$("#update_grbevent_form input[type=submit]").attr('disabled', false);
// Update GRB form
$("#update_grbevent_form").submit(function(e) {
e.preventDefault();
// Get button and disable it to prevent multiple clicks
var submit_button = $(this).find("input[type=submit]");
submit_button.attr("disabled", true);
// Make ajax request - we have to specify a PATCH method here
// since we can't do it in the HTML
$.ajax({
type: 'PATCH',
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(resp) {
// Don't need to re-enable since we reload the page
//submit_button.attr("disabled", false);
location.reload(true);
},
error: function(error) {
//this.button.set("disabled", false);
var err_msg = "Error " + error.status + ": ";
if (error.responseText != "") {
err_msg += error.responseText;
} else {
err_msg += error.statusText;
}
if (error.status == 404) {
err_msg += ". Reload the page.";
}
alert(err_msg);
// Re-enable submit button
submit_button.attr("disabled", false);
}
});
});
//----------------------------------------------------------------------------------------
// Some utility functions
//----------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment