//zmienne globalne var gridRek = false; var lastPage = 1; var prevFilter = {}; var baseURL = 'https://pinax.bu.uni.wroc.pl/prod'; //ustawienia okna szczegółów rekordu if ($(window).width() > 1200) { $.blockUI.defaults.css = {width:'50%', top:'10%',left:'25%', textAlign: 'left'}; } else { $.blockUI.defaults.css = {width:'80%', top:'5%',left:'10%', textAlign: 'left'}; } function initApp() { //set Polish|German locale jsGrid.locale('pl') //policz wysokość tabeli rekordów (uwzględniając wysokość nagłówka i stopki) var winHeight = $(window).height() - $("#header").outerHeight() - $("#filters").outerHeight() - $("#info").outerHeight() - $("#footer").outerHeight() - 20; gridRek = new jsGrid.Grid($("#jsGridRek"),{ width: "100%", height: winHeight,//"70%", autoload: true, filtering: true, inserting: false, editing: false, sorting: true, paging: true, pageLoading:true, pageIndex: 1, pageSize: 50, loadMessage: "Trwa ładowanie danych..", pagerFormat: "Strony: {first} {prev} {pages} {next} {last}    Liczba znalezionych rekordów: {itemCount}", rowClick: function(args) { showDetails(args.item, type = 'record'); }, controller: gcRek, fields: [ { name: "id_rekordu", title: 'Id', type: "number", width: 15, validate: "required", visible: false}, { name: "sygnatura", title: 'Sygnatura', type: "text", width: 50, filtering: false, css: "grey"}, { name: "tresc", title: 'Treść', type: "text", width: 200,filtering: false, css: "grey"}, { name: "data_powstania", title: 'Data powstania', type: "text", width: 32,filtering: false, css: "grey", cellRenderer: function(value, item){ //zwróć pustą komórkę if (!value) return ''; return '' + ((item['data_powstania_do'] > 0) ? value + ' - ' + item['data_powstania_do'] : value) + ''; }}, { name: "id_jezyka", title: 'Język', type: "text", width: 35,filtering: false, css: "grey", cellRenderer: function(value, item){ //zwróć pustą komórkę if (!value) return ''; var tabValues = value.split('|'); return ''; ; }}, { name: "id_proweniencji", title: 'Proweniencja', type: "text", width: 120,filtering: false, css: "grey", cellRenderer: function(value, item){ //zwróć pustą komórkę if (!value) return ''; var tabValues = value.split('|'); return ''; }}, { name: "bcuwr_link", title: 'Wersje cyfrowe', type: "text", width: 70,filtering: false, css: "grey", cellRenderer: function(value, item) { var link = ''; //link do BCUWr if (value) { //wersja z miniatura if (item['bcuwr_miniatura_link']) { link += ''; //wersja z samym piktogramem } else { link += '
'; } if (item['bcuwr_status'] == 'planowana') link += '
(planowana)
'; link += '
'; } //dodaj link do wersji IIP if (item['iip_link'] /*&& (item['bcuwr_miniatura_link'] == '')*/) { link += '
'; } return '' + link + ''; }}, ], onDataLoading: function(args) { //parametr w adresie? var tabIds = false; var strIds = getValue(window.location.search,'id'); if (strIds) { tabIds = strIds.split(',').map(element => { return Number(element); }); if (tabIds.length > 0) { args.filter['id_rekordu'] = tabIds.join(','); } } var txt = $("#tbxSearchBox").val(); var scope = $("#selScope").val(); var dict = $("#selDict").val(); var dictValueId = $("#selDictValues").val(); var bcuwr = ($("#cbxBCUWr").is(":checked")) ? 'on' : 'off'; var startDate = $("#tbxStartDate").val(); var endDate = $("#tbxEndDate").val(); var dateRange = $("#selDateRange").val(); if (startDate > 0 || endDate > 0) { args.filter['data_start'] = startDate; args.filter['data_koniec'] = endDate; args.filter['zakres_dat'] = dateRange; } if (txt && scope && scope != '-1') { if (scope != 'dowolne_pole') scope += '_value'; args.filter[scope] = txt; } if (dict && dict != '-1' && dictValueId && dictValueId != '-1') { args.filter[dict] = dictValueId; } if (bcuwr) { args.filter['bcuwr'] = bcuwr; } //przy zmianie filtra resetuj żądanie strony do pierwszej if (prevFilter['data_start'] != args.filter['data_start'] || prevFilter['data_koniec'] != args.filter['data_koniec'] || prevFilter['bcuwr'] != args.filter['bcuwr'] || prevFilter['dowolne_pole'] != args.filter['dowolne_pole'] || prevFilter['zakres'] != args.filter['zakres']) { args.filter['pageIndex'] = 1; //zapisz też wybrany numer strony w samym gridzie aby nie wyświetlał błędnego wybranego numeru strony args.grid['pageIndex'] = 1; } //zapisz użyty filtr prevFilter = args.filter; }, onDataLoaded: function(args) { //dla filtra id w adresie URL pokaż szczegóły pierwszego rekordu let strIds = getValue(window.location.search, 'id'); let item = false; if (strIds) { tabIds = strIds.split(',').map(element => { return Number(element); }); //zapisz dane szczegółowe pierwszego rekordu z listy id if (tabIds[0] > 0) item = args.data.data[0]; } //załaduj etykiety i opcjonalnie pokaż szczegóły pierwszego rekordu loadFieldLabels(type = 'record', item); }, }); } function loadDictValues() { var mapping = $("#selDict").val(); if (mapping && mapping != -1) { var request = $.ajax({ url: "engine/main.php", method: "GET", data: {"action": "getDictValues", "mapping": mapping}, contentType: "application/json", dataType: "json" }); request.done(function(response) { //wyczyść stare wartosci $("#selDictValues").find('option').remove(); $("#selDictValues").append(''); $("#selDictValues").append(''); //załaduj po kolei nowe opcje $.each( response.data, function(key, record) { $("#selDictValues").append(''); }); }); } } //ukrywa/pokazuje drugie pole daty w filtrze function switchComplement(value) { if (value == 'rok') document.getElementById('complement').style.display = 'none'; else document.getElementById('complement').style.display = 'inline'; document.getElementById('tbxEndDate').value = ''; filter(); } //skrót do funkcji filtrujacej function filter(type = 'record') { if (type == 'record') gridRek.loadData(); //else if (type == 'parent') gridParRek.loadData(); } function toggleAdvancedFilters() { $('#advancedFilters').toggle(); if ($("#switchAdvancedFilters").html() == 'więcej opcji ►') { gridRek.height = '70%'; gridRek.refresh(); $("#switchAdvancedFilters").html('więcej opcji ▼'); } else { gridRek.height = '75%'; gridRek.refresh(); $("#switchAdvancedFilters").html('więcej opcji ►'); } } function clearFilter() { $("#tbxSearchBox").val(''); $("#selScope").val('dowolne_pole'); $("#selDict").val('-1'); $("#selDictValues").val('-1'); $("#tbxStartDate").val(''); $("#tbxEndDate").val(''); $("#selDateRange").val('przed'); switchComplement('zakres_dat'); $("#cbxBCUWr").prop('checked', false); //usuń opcjonalny filtr w adresie URL let myURL = '?'; window.history.pushState("", "", myURL); filter(); } function loadFieldLabels(type = 'record', item = false) { var request = $.ajax({ url: "engine/main.php", method: "GET", data: {"action": "getFieldLabels", "type": type}, contentType: "application/json", dataType: "json" }); request.done(function(response) { if (type == 'record') { window.dsFieldLabels = response.data; } else if (type == 'parent') { window.dsParFieldLabels = response.data; } //opcjonalnie pokaż szczegóły rekordu jak podano id if (item) showDetails(item, type = 'record'); }); } //tester adresów URL function isValidURL(str) { var a = document.createElement('a'); a.href = str; return (a.host && a.host != window.location.host); } function hideInfo() { let barHeight = $("#info").outerHeight(); $("#info").hide(); gridRek.height = gridRek.height + barHeight; gridRek.refresh(); } function showDetails(items, type = 'record') { //stwórz lokalną kopię tablicy var tabItems = JSON.parse(JSON.stringify(items)); //budowanie fiszki szczegółów rekordu var frm = ''; $.blockUI({ message: frm }); } $(document).ready(function() { initApp(); });