Skip to content

Commit

Permalink
Implemented the complete refactoring to remove the string based logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rutvikrj26 committed Nov 23, 2023
1 parent 38888f3 commit 693624a
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 57 deletions.
53 changes: 53 additions & 0 deletions physionet-django/console/templates/console/event_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,57 @@ <h5 class="modal-title">Participants</h5>

{% block local_js_bottom %}
<script src="{% static 'custom/js/resize-ck.js' %}"></script>
<script>
$(document).ready(function () {
$('.manage-cohost').submit(function (e) {
e.preventDefault();
let $form = $(this);
$form.find('input[type="submit"]').prop('disabled', true);

let participant_id = e.target.participant.value;
let event_slug = e.target.event.value;
let submit_value = $form.find('input[type="submit"]').val();
let action = $form.find('input[type="submit"]').attr('data-action');
let csrftoken = e.target.csrfmiddlewaretoken.value;
let url = e.target.action;

$.ajax({
url: url,
type: 'POST',
data: {
'participant_id': participant_id,
'event_slug': event_slug,
'csrfmiddlewaretoken': csrftoken,
'action': action,
'submit': submit_value
},
success: function (data) {

$form.find('input[type="submit"]').prop('disabled', false);

current_action = $form.find('input[type="submit"]').attr('data-action');
make_cohost_action = '{{ cohostStatus.MAKE_COHOST }}';
remove_cohost_action = '{{ cohostStatus.REMOVE_COHOST }}';

console.log(current_action, make_cohost_action, remove_cohost_action);

if (current_action == make_cohost_action) {
$form.find('input[type="submit"]').attr('data-action', remove_cohost_action);
$form.find('input[type="submit"]').val('Remove cohost');
$form.find('input[type="submit"]').removeClass('btn-primary');
$form.find('input[type="submit"]').addClass('btn-danger');
} else if (current_action == remove_cohost_action) {
$form.find('input[type="submit"]').attr('data-action', make_cohost_action);
$form.find('input[type="submit"]').val('Make cohost');
$form.find('input[type="submit"]').removeClass('btn-danger');
$form.find('input[type="submit"]').addClass('btn-success');
}
},
error: function (data) {
$form.find('input[type="submit"]').prop('disabled', false);
}
});
});
});
</script>
{% endblock %}
58 changes: 1 addition & 57 deletions physionet-django/events/templates/events/event_applications.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,60 +37,4 @@
{% endfor %}
</tbody>
</table>
</div>

{% block local_js_bottom %}
<script>
$(document).ready(function () {
$('.manage-cohost').submit(function (e) {
e.preventDefault();
let $form = $(this);
$form.find('input[type="submit"]').prop('disabled', true);

let participant_id = e.target.participant.value;
let event_slug = e.target.event.value;
let submit_value = $form.find('input[type="submit"]').val();
let action = $form.find('input[type="submit"]').attr('data-action');
let csrftoken = e.target.csrfmiddlewaretoken.value;
let url = e.target.action;

$.ajax({
url: url,
type: 'POST',
data: {
'participant_id': participant_id,
'event_slug': event_slug,
'csrfmiddlewaretoken': csrftoken,
'action': action,
'submit': submit_value
},
success: function (data) {

$form.find('input[type="submit"]').prop('disabled', false);

current_action = $form.find('input[type="submit"]').attr('data-action');
make_cohost_action = '{{ cohostStatus.MAKE_COHOST }}';
remove_cohost_action = '{{ cohostStatus.REMOVE_COHOST }}';

console.log(current_action, make_cohost_action, remove_cohost_action);

if (current_action == make_cohost_action) {
$form.find('input[type="submit"]').attr('data-action', remove_cohost_action);
$form.find('input[type="submit"]').val('Remove cohost');
$form.find('input[type="submit"]').removeClass('btn-primary');
$form.find('input[type="submit"]').addClass('btn-danger');
} else if (current_action == remove_cohost_action) {
$form.find('input[type="submit"]').attr('data-action', make_cohost_action);
$form.find('input[type="submit"]').val('Make cohost');
$form.find('input[type="submit"]').removeClass('btn-danger');
$form.find('input[type="submit"]').addClass('btn-success');
}
},
error: function (data) {
$form.find('input[type="submit"]').prop('disabled', false);
}
});
});
});
</script>
{% endblock %}
</div>
51 changes: 51 additions & 0 deletions physionet-django/events/templates/events/event_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,55 @@ <h5 class="modal-title">Participants</h5>

{% block local_js_bottom %}
<script src="{% static 'custom/js/resize-ck.js' %}"></script>
<script>
$(document).ready(function () {
$('.manage-cohost').submit(function (e) {
e.preventDefault();
let $form = $(this);
$form.find('input[type="submit"]').prop('disabled', true);

let participant_id = e.target.participant.value;
let event_slug = e.target.event.value;
let submit_value = $form.find('input[type="submit"]').val();
let action = $form.find('input[type="submit"]').attr('data-action');
let csrftoken = e.target.csrfmiddlewaretoken.value;
let url = e.target.action;

$.ajax({
url: url,
type: 'POST',
data: {
'participant_id': participant_id,
'event_slug': event_slug,
'csrfmiddlewaretoken': csrftoken,
'action': action,
'submit': submit_value
},
success: function (data) {

$form.find('input[type="submit"]').prop('disabled', false);

current_action = $form.find('input[type="submit"]').attr('data-action');
make_cohost_action = '{{ cohostStatus.MAKE_COHOST }}';
remove_cohost_action = '{{ cohostStatus.REMOVE_COHOST }}';

if (current_action == make_cohost_action) {
$form.find('input[type="submit"]').attr('data-action', remove_cohost_action);
$form.find('input[type="submit"]').val('Remove cohost');
$form.find('input[type="submit"]').removeClass('btn-primary');
$form.find('input[type="submit"]').addClass('btn-danger');
} else if (current_action == remove_cohost_action) {
$form.find('input[type="submit"]').attr('data-action', make_cohost_action);
$form.find('input[type="submit"]').val('Make cohost');
$form.find('input[type="submit"]').removeClass('btn-danger');
$form.find('input[type="submit"]').addClass('btn-success');
}
},
error: function (data) {
$form.find('input[type="submit"]').prop('disabled', false);
}
});
});
});
</script>
{% endblock %}

0 comments on commit 693624a

Please sign in to comment.