ensl.org/app/views/custom_urls/_controls.js.erb

43 lines
1.2 KiB
Text
Raw Normal View History

2017-11-12 00:26:00 +00:00
showEdit = function (url_id) {
2018-05-03 17:25:50 +00:00
var parent = $('#' + url_id);
parent.find('> td').toggleClass('hidden');
2017-11-12 00:26:00 +00:00
};
submitEdit = function (url_id) {
2018-05-03 17:25:50 +00:00
var parent = $('#' + url_id);
var form = parent.find('form');
2017-11-12 00:26:00 +00:00
2018-05-03 17:25:50 +00:00
$.post('<%= custom_urls_path %>/' + url_id, form.serialize())
.done(function (data) {
var nameField = parent.children('.name');
var articleField = parent.children('.article');
2017-11-12 00:26:00 +00:00
2018-05-03 17:25:50 +00:00
nameField.text(data.obj.name);
articleField.text(data.obj.title);
parent.find('> td').toggleClass('hidden');
2017-11-12 00:26:00 +00:00
2018-05-03 17:25:50 +00:00
alert(data.message);
}).fail(function (errorRes) {
var error = JSON.parse(errorRes.responseText);
alert(error.message);
});
2017-11-12 00:26:00 +00:00
}
deleteUrl = function (url_id) {
var confirmed = confirm('Are you sure you want to delete this item?');
2018-05-03 17:25:50 +00:00
if (confirmed) {
2017-11-12 00:26:00 +00:00
$.ajax({
url: '<%= custom_urls_path %>/' + url_id,
2017-11-12 00:26:00 +00:00
type: 'DELETE'
}).done(function (data) {
var trID = '#' + url_id;
$(trID).remove();
alert(data.message);
}).fail(function (errorRes) {
var error = JSON.parse(errorRes.responseText);
alert(error.message);
});
}
}