calibre-web/cps/static/js/table.js

183 lines
6.5 KiB
JavaScript
Raw Normal View History

/* This file is part of the Calibre-Web (https://github.com/janeczku/calibre-web)
* Copyright (C) 2018 OzzieIsaacs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* exported TableActions */
2018-08-28 07:42:19 +00:00
$(function() {
$("#domain_allow_submit").click(function(event) {
2018-08-28 07:42:19 +00:00
event.preventDefault();
$("#domain_add_allow").ajaxForm();
2018-08-28 07:42:19 +00:00
$(this).closest("form").submit();
$.ajax ({
2018-08-28 07:42:19 +00:00
method:"get",
url: window.location.pathname + "/../../ajax/domainlist/1",
2018-08-28 07:42:19 +00:00
async: true,
timeout: 900,
success:function(data) {
$("#domain-allow-table").bootstrapTable("load", data);
2018-08-28 07:42:19 +00:00
}
});
});
$("#domain-allow-table").bootstrapTable({
formatNoMatches: function () {
return "";
},
striped: false
});
$("#domain_deny_submit").click(function(event) {
event.preventDefault();
$("#domain_add_deny").ajaxForm();
$(this).closest("form").submit();
$.ajax ({
method:"get",
url: window.location.pathname + "/../../ajax/domainlist/0",
async: true,
timeout: 900,
success:function(data) {
$("#domain-deny-table").bootstrapTable("load", data);
}
});
});
$("#domain-deny-table").bootstrapTable({
formatNoMatches: function () {
return "";
2019-03-05 15:31:09 +00:00
},
striped: false
2018-08-28 07:42:19 +00:00
});
$("#btndeletedomain").click(function() {
//get data-id attribute of the clicked element
var domainId = $(this).data("domainId");
2018-08-28 07:42:19 +00:00
$.ajax({
method:"post",
url: window.location.pathname + "/../../ajax/deletedomain",
data: {"domainid":domainId}
});
$("#DeleteDomain").modal("hide");
2018-08-28 07:42:19 +00:00
$.ajax({
method:"get",
url: window.location.pathname + "/../../ajax/domainlist/1",
2018-08-28 07:42:19 +00:00
async: true,
timeout: 900,
2019-03-05 15:31:09 +00:00
success:function(data) {
$("#domain-allow-table").bootstrapTable("load", data);
}
});
$.ajax({
method:"get",
url: window.location.pathname + "/../../ajax/domainlist/0",
async: true,
timeout: 900,
success:function(data) {
$("#domain-deny-table").bootstrapTable("load", data);
2018-08-28 07:42:19 +00:00
}
});
});
//triggered when modal is about to be shown
2019-01-15 19:08:47 +00:00
$("#DeleteDomain").on("show.bs.modal", function(e) {
2018-08-28 07:42:19 +00:00
//get data-id attribute of the clicked element and store in button
var domainId = $(e.relatedTarget).data("domain-id");
$(e.currentTarget).find("#btndeletedomain").data("domainId", domainId);
2018-08-28 07:42:19 +00:00
});
2020-01-01 16:26:47 +00:00
$('#restrictModal').on('hidden.bs.modal', function () {
$('#restrict-elements-table').bootstrapTable('destroy');
});
// $('#table').bootstrapTable('destroy');
function startTable(type){
$("#restrict-elements-table").bootstrapTable({
formatNoMatches: function () {
return "";
},
url:window.location.pathname + "/../../ajax/listrestriction/" + type,
onClickCell: function (field, value, row, $element) {
// ...
if(field == 3){
$.ajax ({
type: 'Post',
data: 'id=' + row.id + '&type=' + row.type + "&Element=" + row.Element,
url: window.location.pathname + "/../../ajax/deleterestriction/" + type,
async: true,
timeout: 900,
success:function(data) {
$.ajax({
method:"get",
url: window.location.pathname + "/../../ajax/listrestriction/"+type,
async: true,
timeout: 900,
success:function(data) {
$("#restrict-elements-table").bootstrapTable("load", data);
}
});
}
});
}
},
striped: false
});
$("[id^=submit_]").click(function(event) {
event.preventDefault();
console.log($(this)[0].name)
$.ajax({
url: window.location.pathname + "/../../ajax/addrestriction/"+type,
type: 'Post',
data: $(this).closest("form").serialize() + "&" + $(this)[0].name + "=",
success: function () {
$.ajax ({
method:"get",
url: window.location.pathname + "/../../ajax/listrestriction/"+type,
async: true,
timeout: 900,
success:function(data) {
$("#restrict-elements-table").bootstrapTable("load", data);
}
});
}
});
return;
});
}
$('#get_column_values').on('click',function()
{
startTable(1);
});
$('#get_tags').on('click',function()
{
startTable(0);
});
2018-08-28 07:42:19 +00:00
});
/* Function for deleting domain restrictions */
function TableActions (value, row, index) {
2018-08-28 07:42:19 +00:00
return [
"<a class=\"danger remove\" data-toggle=\"modal\" data-target=\"#DeleteDomain\" data-domain-id=\"" + row.id
+ "\" title=\"Remove\">",
"<i class=\"glyphicon glyphicon-trash\"></i>",
"</a>"
].join("");
}
2020-01-01 16:26:47 +00:00
/* Function for deleting domain restrictions */
function RestrictionActions (value, row, index) {
return [
"<div class=\"danger remove\" data-restriction-id=\"" + row.id + "\" title=\"Remove\">",
"<i class=\"glyphicon glyphicon-trash\"></i>",
"</div>"
].join("");
}