scinote-web/app/assets/javascripts/users/settings/teams/index.js

60 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-01-31 20:33:55 +08:00
function initLeaveTeams() {
2017-01-25 19:12:27 +08:00
// Bind the "leave team" buttons in teams table
2016-02-12 23:52:43 +08:00
$(document)
.on(
"ajax:success",
2017-01-25 19:12:27 +08:00
"[data-action='leave-user-team']",
2016-02-12 23:52:43 +08:00
function (e, data, status, xhr) {
// Populate the modal heading & body
2017-01-25 19:12:27 +08:00
var modal = $("#modal-leave-user-team");
2016-02-12 23:52:43 +08:00
var modalHeading = modal.find(".modal-header").find(".modal-title");
var modalBody = modal.find(".modal-body");
modalHeading.text(data.heading);
modalBody.html(data.html);
// Show the modal
modal.modal("show");
}
)
.on(
"ajax:error",
2017-01-25 19:12:27 +08:00
"[data-action='destroy-user-team']",
2016-02-12 23:52:43 +08:00
function (e, data, status, xhr) {
// TODO
}
);
// Also, bind the click action on the modal
2017-01-25 19:12:27 +08:00
$("#modal-leave-user-team")
2016-02-12 23:52:43 +08:00
.on("click", "[data-action='submit']", function() {
var btn = $(this);
var form = btn
.closest(".modal")
.find(".modal-body")
2017-01-25 19:12:27 +08:00
.find("form[data-id='leave-user-team-form']");
2016-02-12 23:52:43 +08:00
// Simply submit the form!
form.submit();
});
// Lastly, bind on the ajax form
$(document)
.on(
"ajax:success",
2017-01-25 19:12:27 +08:00
"[data-id='leave-user-team-form']",
2016-02-12 23:52:43 +08:00
function (e, data, status, xhr) {
// Simply reload the page
location.reload();
}
)
.on(
"ajax:error",
2017-01-25 19:12:27 +08:00
"[data-id='destroy-user-team-form']",
2016-02-12 23:52:43 +08:00
function (e, data, status, xhr) {
// TODO
}
);
}
2017-01-31 20:33:55 +08:00
initLeaveTeams();