You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
calibre-web/cps/static/js/table.js

407 lines
15 KiB
JavaScript

/* 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, RestrictionActions, EbookActions, responseHandler */
var selections = [];
$(function() {
$("#books-table").on("check.bs.table check-all.bs.table uncheck.bs.table uncheck-all.bs.table",
function (e, rowsAfter, rowsBefore) {
var rows = rowsAfter;
if (e.type === "uncheck-all") {
rows = rowsBefore;
}
var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) {
return row.id;
});
var func = $.inArray(e.type, ["check", "check-all"]) > -1 ? "union" : "difference";
selections = window._[func](selections, ids);
if (selections.length >= 2) {
$("#merge_books").removeClass("disabled");
$("#merge_books").attr("aria-disabled", false);
} else {
$("#merge_books").addClass("disabled");
$("#merge_books").attr("aria-disabled", true);
}
});
$("#merge_books").click(function() {
$.ajax({
method:"post",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: window.location.pathname + "/../../ajax/mergebooks",
data: JSON.stringify({"Merge_books":selections}),
success: function success() {
// ToDo:
}
});
});
/*$("#books-table").bootstrapTable({
});
test = $("#books-table").bootstrapTable('getOptions');
var column = test.columns[0]
column.forEach(function(item){
if ('editableValidate' in item) {
item.editable = {
mode: 'inline',
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
}
}
});
$("#books-table").bootstrapTable('refreshOptions', {columns: [column]});*/
var column = [];
$('#table1 > thead > tr > th').each(function(){
if ($(this).attr('data-edit')) {
if ($(this).attr('data-edit-validate')) {
column.push({
editable: {
mode: 'inline',
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
}
});
} else {
column.push({
editable: {
mode: 'inline',
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
}
});
}
} else {
column.push({});
}
});
$("#table1").bootstrapTable({
sidePagination: "server",
pagination: true,
paginationDetailHAlign: " hidden",
paginationHAlign: "left",
/*url: window.location.pathname + "/../../ajax/listbooks",*/
idField: "id",
search: true,
showColumns: true,
searchAlign: "left",
showSearchButton : false,
searchOnEnterKey: true,
checkboxHeader: false,
maintainMetaData: true,
responseHandler: responseHandler,
columns: column,
/*editable-mode="inline"
editable-emptytext="<span class='glyphicon glyphicon-plus'></span>">*/
/*columns: [
{},
{}, {
editable: {
mode: 'inline',
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
},
}, {
editable: {
mode: 'inline',
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
},
}, {
editable: {
mode: 'inline',
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
}
}, {
editable: {
mode: 'inline',
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
},
}, {
editable: {
mode: 'inline',
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
},
}, {
editable: {
mode: 'inline',
emptytext: "<span class='glyphicon glyphicon-plus'></span>",
validate: function (value) { if($.trim(value) == '') return 'This field is required'; },
},
}],*/
formatNoMatches: function () {
return "";
},
});
/*var $table = $('#books-table');
$('#books-table').bootstrapTable('getOptions')*/
/*$('#books-table').bootstrapTable('editable')*/
/*{ field: 'aimValue', title: 'Aim<br>Value', class: 'danger',editable: { mode: 'inline', validate: function (v) { return validateData(this, v); }, }, },*/
$("#domain_allow_submit").click(function(event) {
event.preventDefault();
$("#domain_add_allow").ajaxForm();
$(this).closest("form").submit();
$.ajax ({
method:"get",
url: window.location.pathname + "/../../ajax/domainlist/1",
async: true,
timeout: 900,
success:function(data) {
$("#domain-allow-table").bootstrapTable("load", data);
}
});
});
$("#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 "";
5 years ago
},
striped: false
});
$("#btndeletedomain").click(function() {
//get data-id attribute of the clicked element
var domainId = $(this).data("domainId");
$.ajax({
method:"post",
url: window.location.pathname + "/../../ajax/deletedomain",
data: {"domainid":domainId}
});
$("#DeleteDomain").modal("hide");
$.ajax({
method:"get",
url: window.location.pathname + "/../../ajax/domainlist/1",
async: true,
timeout: 900,
5 years ago
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);
}
});
});
//triggered when modal is about to be shown
$("#DeleteDomain").on("show.bs.modal", function(e) {
//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);
});
$("#delete_confirm").click(function() {
//get data-id attribute of the clicked element
var deleteId = $(this).data("deleteid");
$.ajax({
method:"get",
url: window.location.pathname + "/../../delete/" + deleteId,
});
});
//triggered when modal is about to be shown
$("#deleteModal").on("show.bs.modal", function(e) {
//get data-id attribute of the clicked element and store in button
var bookId = $(e.relatedTarget).data("delete-id");
$(e.currentTarget).find("#delete_confirm").data("deleteid", bookId);
});
// receive result from request, dismiss modal dialog, show flash message
// insert after navbar
/*$("#deleteModal").on("hidden.bs.modal", function () {
<div class="row-fluid text-center" style="margin-top: -20px;">
<div id="flash_success" class="alert alert-success">{{ message[1] }}</div>
</div>*/
// to save current setting
// coresponding event: onColumnSwitch
//$table.bootstrapTable('getVisibleColumns')
//$table.bootstrapTable('getHiddenColumns').
$("#restrictModal").on("hidden.bs.modal", function () {
// Destroy table and remove hooks for buttons
$("#restrict-elements-table").unbind();
$("#restrict-elements-table").bootstrapTable("destroy");
$("[id^=submit_]").unbind();
$("#h1").addClass("hidden");
$("#h2").addClass("hidden");
$("#h3").addClass("hidden");
$("#h4").addClass("hidden");
});
function startTable(type) {
var pathname = document.getElementsByTagName("script"), src = pathname[pathname.length - 1].src;
var path = src.substring(0, src.lastIndexOf("/"));
$("#restrict-elements-table").bootstrapTable({
formatNoMatches: function () {
return "";
},
url: path + "/../../ajax/listrestriction/" + type,
4 years ago
rowStyle: function(row) {
// console.log('Reihe :' + row + " Index :" + index);
if (row.id.charAt(0) === "a") {
return {classes: "bg-primary"};
} else {
return {classes: "bg-dark-danger"};
}
},
4 years ago
onClickCell: function (field, value, row) {
if (field === 3) {
$.ajax ({
type: "Post",
data: "id=" + row.id + "&type=" + row.type + "&Element=" + encodeURIComponent(row.Element),
url: path + "/../../ajax/deleterestriction/" + type,
async: true,
timeout: 900,
4 years ago
success:function() {
$.ajax({
method:"get",
url: path + "/../../ajax/listrestriction/" + type,
async: true,
timeout: 900,
success:function(data) {
$("#restrict-elements-table").bootstrapTable("load", data);
}
});
}
});
}
},
striped: false
});
$("#restrict-elements-table").removeClass("table-hover");
4 years ago
$("#restrict-elements-table").on("editable-save.bs.table", function (e, field, row) {
$.ajax({
url: path + "/../../ajax/editrestriction/" + type,
type: "Post",
data: row
});
});
4 years ago
$("[id^=submit_]").click(function() {
$(this)[0].blur();
$.ajax({
url: path + "/../../ajax/addrestriction/" + type,
type: "Post",
data: $(this).closest("form").serialize() + "&" + $(this)[0].name + "=",
success: function () {
$.ajax ({
method:"get",
url: path + "/../../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);
$("#h2").removeClass("hidden");
});
$("#get_tags").on("click", function() {
startTable(0);
$("#h1").removeClass("hidden");
});
$("#get_user_column_values").on("click", function() {
startTable(3);
$("#h4").removeClass("hidden");
});
$("#get_user_tags").on("click", function() {
startTable(2);
$(this)[0].blur();
$("#h3").removeClass("hidden");
});
});
/* Function for deleting domain restrictions */
4 years ago
function TableActions (value, row) {
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("");
}
/* Function for deleting domain restrictions */
4 years ago
function RestrictionActions (value, row) {
return [
"<div class=\"danger remove\" data-restriction-id=\"" + row.id + "\" title=\"Remove\">",
"<i class=\"glyphicon glyphicon-trash\"></i>",
"</div>"
].join("");
}
/* Function for deleting books */
function EbookActions (value, row) {
return [
"<div class=\"book-remove\" data-toggle=\"modal\" data-target=\"#deleteModal\" data-delete-id=\"" + row.id + "\" title=\"Remove\">",
"<i class=\"glyphicon glyphicon-trash\"></i>",
"</div>"
].join("");
}
/* Function for keeping checked rows */
function responseHandler(res) {
$.each(res.rows, function (i, row) {
row.state = $.inArray(row.id, selections) !== -1;
});
return res;
}
function validato(value) {
if($.trim(value) == '') return 'This field is required';
}
/*function validateVal(value) { if($.trim(value) == '') return 'This field is required'; }*/