sintonia/legacy/public/js/airtime/playouthistory/historytable.js

949 lines
26 KiB
JavaScript
Raw Normal View History

var AIRTIME = (function(AIRTIME) {
var mod;
2021-10-12 11:17:57 +02:00
if (AIRTIME.history === undefined) {
AIRTIME.history = {};
}
mod = AIRTIME.history;
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
var $historyContentDiv;
2021-10-12 11:17:57 +02:00
var lengthMenu = [[10, 25, 50, 100, 500, -1], [10, 25, 50, 100, 500, $.i18n._("All")]];
2021-10-12 11:17:57 +02:00
2020-12-31 04:16:07 +01:00
var sDom = 'l<"dt-process-rel"r><"H"><"dataTables_scrolling"t><"F"ip>';
2021-10-12 11:17:57 +02:00
var selectedLogItems = {};
2021-10-12 11:17:57 +02:00
var dateStartId = "#his_date_start",
timeStartId = "#his_time_start",
dateEndId = "#his_date_end",
2013-08-29 21:17:24 +02:00
timeEndId = "#his_time_end",
2021-10-12 11:17:57 +02:00
2013-08-29 21:17:24 +02:00
oTableAgg,
oTableItem,
oTableShow,
inShowsTab = false;
2021-10-12 11:17:57 +02:00
function validateTimeRange() {
var oRange,
inputs = $('.his-timerange > input'),
start, end;
2021-10-12 11:17:57 +02:00
oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId);
2021-10-12 11:17:57 +02:00
start = oRange.start;
end = oRange.end;
2021-10-12 11:17:57 +02:00
if (end >= start) {
inputs.removeClass('error');
}
else {
inputs.addClass('error');
}
2021-10-12 11:17:57 +02:00
return {
start: start,
end: end,
isValid: end >= start
};
}
2021-10-12 11:17:57 +02:00
function getSelectedLogItems() {
var items = Object.keys(selectedLogItems);
2021-10-12 11:17:57 +02:00
return items;
}
2021-10-12 11:17:57 +02:00
function addSelectedLogItem($el) {
var id;
2021-10-12 11:17:57 +02:00
$el.addClass("his-selected");
id = $el.data("his-id");
selectedLogItems[id] = "";
}
2021-10-12 11:17:57 +02:00
function removeSelectedLogItem($el) {
var id;
2021-10-12 11:17:57 +02:00
$el.removeClass("his-selected");
id = $el.data("his-id");
delete selectedLogItems[id];
}
2021-10-12 11:17:57 +02:00
function emptySelectedLogItems() {
2013-08-28 19:42:33 +02:00
var $inputs = $historyContentDiv.find(".his_checkbox").find("input");
2021-10-12 11:17:57 +02:00
$inputs.prop('checked', false);
$inputs.parents("tr").removeClass("his-selected");
2021-10-12 11:17:57 +02:00
selectedLogItems = {};
}
2021-10-12 11:17:57 +02:00
function selectCurrentPage(e) {
var $ctx = $(e.currentTarget).parents("div.dataTables_wrapper"),
$inputs = $ctx.find(".his_checkbox").find("input"),
2021-10-12 11:17:57 +02:00
$tr,
2013-08-28 19:42:33 +02:00
$input;
2021-10-12 11:17:57 +02:00
2013-08-23 19:18:17 +02:00
$.each($inputs, function(index, input) {
$input = $(input);
$input.prop('checked', true);
$tr = $input.parents("tr");
addSelectedLogItem($tr);
2013-08-23 19:18:17 +02:00
});
}
2021-10-12 11:17:57 +02:00
function deselectCurrentPage(e) {
var $ctx = $(e.currentTarget).parents("div.dataTables_wrapper"),
$inputs = $ctx.find(".his_checkbox").find("input"),
2021-10-12 11:17:57 +02:00
$tr,
2013-08-28 19:42:33 +02:00
$input;
2021-10-12 11:17:57 +02:00
2013-08-23 19:18:17 +02:00
$.each($inputs, function(index, input) {
$input = $(input);
$input.prop('checked', false);
$tr = $input.parents("tr");
removeSelectedLogItem($tr);
2013-08-23 19:18:17 +02:00
});
}
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
function getFileName(ext){
var filename = $("#his_date_start").val()+"_"+$("#his_time_start").val()+"m--"+$("#his_date_end").val()+"_"+$("#his_time_end").val()+"m";
filename = filename.replace(/:/g,"h");
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
if (ext == "pdf"){
filename = filename+".pdf";
}
else {
filename = filename+".csv";
}
return filename;
}
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
/* This callback can be used for all history tables */
function fnServerData( sSource, aoData, fnCallback ) {
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
if (fnServerData.hasOwnProperty("start")) {
aoData.push( { name: "start", value: fnServerData.start} );
}
if (fnServerData.hasOwnProperty("end")) {
aoData.push( { name: "end", value: fnServerData.end} );
}
if (fnServerData.hasOwnProperty("instance")) {
aoData.push( { name: "instance_id", value: fnServerData.instance} );
}
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
aoData.push( { name: "format", value: "json"} );
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
$.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
2021-10-12 11:17:57 +02:00
function createShowAccordSection(config) {
var template,
$el;
2021-10-12 11:17:57 +02:00
template =
2013-08-29 21:17:24 +02:00
"<h3>" +
"<a href='#'>" +
"<span class='show-title'><%= name %></span>" +
"<span class='push-right'>" +
"<span class='show-date'><%= date %></span>" +
"<span class='show-time'><%= startTime %></span>" +
"-" +
"<span class='show-time'><%= endTime %></span>" +
"</span>" +
"</a>" +
"</h3>" +
2013-08-29 21:17:24 +02:00
"<div " +
"data-instance='<%= instance %>' " +
"></div>";
2021-10-12 11:17:57 +02:00
template = _.template(template);
$el = $(template(config));
2021-10-12 11:17:57 +02:00
return $el;
}
2021-10-12 11:17:57 +02:00
2013-08-29 17:01:03 +02:00
//$el is the div in the accordian we should create the table on.
function createShowTable($el) {
2021-10-12 11:17:57 +02:00
2013-08-29 21:17:24 +02:00
var instance = $el.data("instance");
var $table = $("<table/>", {
2021-10-12 11:17:57 +02:00
'cellpadding': "0",
'cellspacing': "0",
2013-08-29 21:17:24 +02:00
'class': "datatable",
'id': "history_table_show"
});
2021-10-12 11:17:57 +02:00
2013-08-29 21:17:24 +02:00
//assign the retrieval function the show instance id.
fnServerData.instance = instance;
$el.append($table);
$el.css("height", "auto");
oTableShow = itemHistoryTable("history_table_show");
2013-08-29 17:01:03 +02:00
}
2021-10-12 11:17:57 +02:00
function drawShowList(oShows) {
var $showList = $historyContentDiv.find("#history_show_summary"),
2021-10-12 11:17:57 +02:00
i,
len,
$accordSection,
show,
tmp;
2021-10-12 11:17:57 +02:00
2013-08-29 21:52:24 +02:00
$showList
.accordion( "destroy" )
.empty();
2021-10-12 11:17:57 +02:00
for (i = 0, len = oShows.length; i < len; i++) {
show = oShows[i];
tmp = show.starts.split(" ");
2021-10-12 11:17:57 +02:00
$accordSection = createShowAccordSection({
instance: show.instance_id,
name: show.name,
date: tmp[0],
startTime: tmp[1],
endTime: show.ends.split(" ").pop()
});
2021-10-12 11:17:57 +02:00
$showList.append($accordSection);
}
2021-10-12 11:17:57 +02:00
$showList.accordion({
animated: false,
create: function( event, ui ) {
var $div = $showList.find(".ui-accordion-content-active");
console.log(event);
//$div.css()
2013-08-29 21:17:24 +02:00
createShowTable($div);
},
change: function( event, ui ) {
2013-08-29 21:17:24 +02:00
var $div = $(ui.newContent);
$(ui.oldContent).empty();
2013-08-29 21:17:24 +02:00
createShowTable($div);
selectedLogItems = {};
}
//changestart: function( event, ui ) {}
});
}
2021-10-12 11:17:57 +02:00
function createToolbarButtons ($el) {
var $menu = $("<div class='btn-toolbar' />");
$menu.append("<div class='btn-group'>" +
"<button class='btn btn-small btn-new' id='his_create'>" +
"<i class='icon-white icon-plus'></i>" +
$.i18n._("New Log Entry") +
"</button>" +
"</div>");
$menu.append("<div class='btn-group'>" +
"<button class='btn btn-small dropdown-toggle' data-toggle='dropdown'>" +
$.i18n._("Select")+" <span class='caret'></span>" +
"</button>" +
"<ul class='dropdown-menu'>" +
2013-08-30 08:11:26 +02:00
"<li class='his-select-page'><a href='#'>"+$.i18n._("Select this page")+"</a></li>" +
"<li class='his-dselect-page'><a href='#'>"+$.i18n._("Deselect this page")+"</a></li>" +
"<li class='his-dselect-all'><a href='#'>"+$.i18n._("Deselect all")+"</a></li>" +
"</ul>" +
2021-01-18 03:03:04 +01:00
"</div>");
2021-01-18 18:11:33 +01:00
$menu.append("<div class='btn-group'>" +
"<button class='btn btn-small dropdown-toggle' data-toggle='dropdown'>" +
$.i18n._("Export")+" <span class='caret'></span>" +
"</button>" +
"<ul class='dropdown-menu'>" +
"<li id='csv_export'><a href='#'>"+$.i18n._("Export as CSV")+"</a></li>" +
"<li id='pdf_export'><a href='#'>"+$.i18n._("Export as PDF")+"</a></li>" +
"</ul>" +
"</div>");
$menu.append("<div class='btn-group'>" +
"<button class='btn btn-small' id='his_trash'>" +
"<i class='icon-white icon-trash'></i>" +
"</button>" +
2021-01-18 03:03:04 +01:00
"</div>");
2021-10-12 11:17:57 +02:00
$el.append($menu);
}
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
function aggregateHistoryTable() {
var oTable,
$historyTableDiv = $historyContentDiv.find("#history_table_aggregate"),
columns,
2013-07-18 07:31:20 +02:00
fnRowCallback;
fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var editUrl = baseUrl+"playouthistory/edit-file-item/id/"+aData.file_id,
$nRow = $(nRow);
2021-10-12 11:17:57 +02:00
$nRow.data('url-edit', editUrl);
};
2021-10-12 11:17:57 +02:00
columns = JSON.parse(localStorage.getItem('datatables-historyfile-aoColumns'));
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
oTable = $historyTableDiv.dataTable( {
2021-10-12 11:17:57 +02:00
"aoColumns": columns,
2021-10-12 11:17:57 +02:00
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": baseUrl+"playouthistory/file-history-feed",
"sAjaxDataProp": "history",
"fnServerData": fnServerData,
"fnRowCallback": fnRowCallback,
"oLanguage": getDatatablesStrings({
"sEmptyTable": $.i18n._("No tracks were played during the selected time period."),
"sInfoEmpty": $.i18n._("Showing 0 to 0 of 0 tracks"),
"sInfo": $.i18n._("Showing _START_ to _END_ of _TOTAL_ tracks"),
"sInfoEmpty": $.i18n._("Showing 0 to 0 of 0 tracks"),
"sInfoFiltered": $.i18n._("(filtered from _MAX_ total tracks)"),
}),
2013-07-18 07:31:20 +02:00
"aLengthMenu": lengthMenu,
2013-08-22 21:45:09 +02:00
"iDisplayLength": 25,
"sPaginationType": "full_numbers",
"bJQueryUI": true,
"bAutoWidth": true,
2021-10-12 11:17:57 +02:00
"sDom": sDom,
});
oTable.fnSetFilteringDelay(350);
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
return oTable;
}
2021-10-12 11:17:57 +02:00
function itemHistoryTable(id) {
2013-07-18 07:31:20 +02:00
var oTable,
$historyTableDiv = $historyContentDiv.find("#"+id),
$toolbar,
columns,
fnRowCallback,
booleans = {},
i, c;
2021-10-12 11:17:57 +02:00
columns = JSON.parse(localStorage.getItem('datatables-historyitem-aoColumns'));
2021-10-12 11:17:57 +02:00
for (i in columns) {
2021-10-12 11:17:57 +02:00
c = columns[i];
if (c["sDataType"] === "boolean") {
booleans[c["mDataProp"]] = c["sTitle"];
}
}
2013-07-18 07:31:20 +02:00
fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var editUrl = baseUrl+"playouthistory/edit-list-item/id/"+aData.history_id,
deleteUrl = baseUrl+"playouthistory/delete-list-item/id/"+aData.history_id,
emptyCheckBox = String.fromCharCode(parseInt(2610, 16)),
checkedCheckBox = String.fromCharCode(parseInt(2612, 16)),
2021-10-12 11:17:57 +02:00
b,
text,
$nRow = $(nRow);
2021-10-12 11:17:57 +02:00
// add checkbox
$nRow.find('td.his_checkbox').html("<input type='checkbox' name='cb_"+aData.history_id+"'>");
2021-10-12 11:17:57 +02:00
$nRow.data('his-id', aData.history_id);
$nRow.data('url-edit', editUrl);
$nRow.data('url-delete', deleteUrl);
2021-10-12 11:17:57 +02:00
for (b in booleans) {
2021-10-12 11:17:57 +02:00
text = aData[b] ? checkedCheckBox : emptyCheckBox;
text = text + " " + booleans[b];
2021-10-12 11:17:57 +02:00
$nRow.find(".his_"+b).html(text);
}
2013-07-18 07:31:20 +02:00
};
2015-08-12 19:50:42 +02:00
oTable = $historyTableDiv.dataTable( {
"aoColumns": columns,
2013-07-18 07:31:20 +02:00
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": baseUrl+"playouthistory/item-history-feed",
"sAjaxDataProp": "history",
"fnServerData": fnServerData,
"fnRowCallback": fnRowCallback,
"oLanguage": getDatatablesStrings({
"sEmptyTable": $.i18n._("No tracks were played during the selected time period."),
"sInfoEmpty": $.i18n._("Showing 0 to 0 of 0 tracks"),
"sInfo": $.i18n._("Showing _START_ to _END_ of _TOTAL_ tracks"),
"sInfoEmpty": $.i18n._("Showing 0 to 0 of 0 tracks"),
"sInfoFiltered": $.i18n._("(filtered from _MAX_ total tracks)"),
}),
2015-08-12 19:50:42 +02:00
"aLengthMenu": lengthMenu,
2013-08-22 21:45:09 +02:00
"iDisplayLength": 25,
2013-07-18 07:31:20 +02:00
"sPaginationType": "full_numbers",
"bJQueryUI": true,
"bAutoWidth": true,
2021-10-12 11:17:57 +02:00
"sDom": sDom,
2013-07-18 07:31:20 +02:00
});
oTable.fnSetFilteringDelay(350);
2021-10-12 11:17:57 +02:00
$toolbar = $historyTableDiv.parents(".dataTables_wrapper").find(".fg-toolbar:first");
createToolbarButtons($toolbar);
2021-10-12 11:17:57 +02:00
return oTable;
2013-07-18 07:31:20 +02:00
}
2021-10-12 11:17:57 +02:00
function showSummaryList(start, end) {
var url = baseUrl+"playouthistory/show-history-feed",
data = {
format: "json",
start: start,
end: end
};
2021-10-12 11:17:57 +02:00
$.post(url, data, function(json) {
drawShowList(json);
});
}
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
mod.onReady = function() {
2021-10-12 11:17:57 +02:00
var oBaseDatePickerSettings,
2013-07-18 07:31:20 +02:00
oBaseTimePickerSettings,
$hisDialogEl,
2021-10-12 11:17:57 +02:00
tabsInit = [
{
initialized: false,
initialize: function() {
oTableItem = itemHistoryTable("history_table_list");
2013-08-29 21:17:24 +02:00
},
navigate: function() {
delete fnServerData.instance;
2013-08-30 08:39:14 +02:00
oTableItem.fnDraw();
},
always: function() {
inShowsTab = false;
emptySelectedLogItems();
}
},
{
initialized: false,
initialize: function() {
oTableAgg = aggregateHistoryTable();
2013-08-29 21:17:24 +02:00
},
navigate: function() {
delete fnServerData.instance;
2013-08-30 08:39:14 +02:00
oTableAgg.fnDraw();
},
always: function() {
inShowsTab = false;
emptySelectedLogItems();
}
},
{
initialized: false,
initialize: function() {
2021-10-12 11:17:57 +02:00
2013-08-29 21:17:24 +02:00
},
navigate: function() {
2021-10-12 11:17:57 +02:00
},
always: function() {
inShowsTab = true;
2021-10-12 11:17:57 +02:00
var info = getStartEnd();
showSummaryList(info.start, info.end);
emptySelectedLogItems();
}
}
];
2021-10-12 11:17:57 +02:00
//set the locale names for the bootstrap calendar.
$.fn.datetimepicker.dates = {
daysMin: i18n_days_short,
months: i18n_months,
monthsShort: i18n_months_short
};
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
$historyContentDiv = $("#history_content");
2021-10-12 11:17:57 +02:00
function redrawTables() {
oTableAgg && oTableAgg.fnDraw();
oTableItem && oTableItem.fnDraw();
2013-08-29 21:34:34 +02:00
oTableShow && oTableShow.fnDraw();
}
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
function removeHistoryDialog() {
$hisDialogEl.dialog("destroy");
$hisDialogEl.remove();
}
2021-10-12 11:17:57 +02:00
2013-08-28 19:42:33 +02:00
function initializeDialog() {
var $startPicker = $hisDialogEl.find('#his_item_starts_datetimepicker'),
$endPicker = $hisDialogEl.find('#his_item_ends_datetimepicker');
2021-10-12 11:17:57 +02:00
2013-08-28 19:42:33 +02:00
$startPicker.datetimepicker();
$endPicker.datetimepicker({
showTimeFirst: true
});
2021-10-12 11:17:57 +02:00
2013-08-28 19:42:33 +02:00
$startPicker.on('changeDate', function(e) {
2021-10-12 11:17:57 +02:00
$endPicker.data('datetimepicker').setLocalDate(e.localDate);
2013-08-28 19:42:33 +02:00
});
}
2021-10-12 11:17:57 +02:00
function processDialogHtml($el) {
2021-10-12 11:17:57 +02:00
if (inShowsTab) {
$el.find("#his_choose_instance").remove();
}
2021-10-12 11:17:57 +02:00
return $el
}
2021-10-12 11:17:57 +02:00
function makeHistoryDialog(html) {
$hisDialogEl = $(html);
$hisDialogEl = processDialogHtml($hisDialogEl);
2021-10-12 11:17:57 +02:00
$hisDialogEl.dialog({
2013-07-18 07:31:20 +02:00
title: $.i18n._("Edit History Record"),
modal: false,
open: function( event, ui ) {
2021-10-12 11:17:57 +02:00
initializeDialog();
},
2013-07-18 07:31:20 +02:00
close: function() {
removeHistoryDialog();
}
});
2021-01-22 15:20:04 +01:00
}
2021-10-12 11:17:57 +02:00
2021-01-22 15:20:04 +01:00
hisSubmit(); // Fixes display bug
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
/*
* Icon hover states for search.
*/
$historyContentDiv.on("mouseenter", ".his-timerange .ui-button", function(ev) {
2021-10-12 11:17:57 +02:00
$(this).addClass("ui-state-hover");
2013-07-18 07:31:20 +02:00
});
$historyContentDiv.on("mouseleave", ".his-timerange .ui-button", function(ev) {
$(this).removeClass("ui-state-hover");
});
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
oBaseDatePickerSettings = {
dateFormat: 'yy-mm-dd',
//i18n_months, i18n_days_short are in common.js
monthNames: i18n_months,
dayNamesMin: i18n_days_short,
2021-10-12 11:17:57 +02:00
onSelect: function(sDate, oDatePicker) {
2013-07-18 07:31:20 +02:00
$(this).datepicker( "setDate", sDate );
},
onClose: validateTimeRange
2013-07-18 07:31:20 +02:00
};
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
oBaseTimePickerSettings = {
showPeriodLabels: false,
showCloseButton: true,
closeButtonText: $.i18n._("Done"),
showLeadingZero: false,
defaultTime: '0:00',
hourText: $.i18n._("Hour"),
minuteText: $.i18n._("Minute"),
onClose: validateTimeRange
2013-07-18 07:31:20 +02:00
};
$historyContentDiv.find(dateStartId)
.datepicker(oBaseDatePickerSettings)
.blur(validateTimeRange);
2021-10-12 11:17:57 +02:00
$historyContentDiv.find(timeStartId)
.timepicker(oBaseTimePickerSettings)
.blur(validateTimeRange);
2021-10-12 11:17:57 +02:00
$historyContentDiv.find(dateEndId)
.datepicker(oBaseDatePickerSettings)
.blur(validateTimeRange);
2021-10-12 11:17:57 +02:00
$historyContentDiv.find(timeEndId)
.timepicker(oBaseTimePickerSettings)
.blur(validateTimeRange);
2021-10-12 11:17:57 +02:00
$historyContentDiv.on("click", "#his_create", function(e) {
var url = baseUrl+"playouthistory/edit-list-item/format/json" ;
2021-10-12 11:17:57 +02:00
e.preventDefault();
2021-10-12 11:17:57 +02:00
$.get(url, function(json) {
2021-10-12 11:17:57 +02:00
makeHistoryDialog(json.dialog);
2021-10-12 11:17:57 +02:00
}, "json");
2021-01-18 03:03:04 +01:00
});
2021-01-18 18:11:33 +01:00
$historyContentDiv.on("click", "#pdf_export", async function(){
// Get date/time from pickers
var startDay = document.querySelector('#his_date_start').value;
var startTime = document.querySelector('#his_time_start').value;
var endDay = document.querySelector('#his_date_end').value;
var endTime = document.querySelector('#his_time_end').value;
var url = baseUrl + "api/item-history-feed?start=" + startDay + " " + startTime + "&end=" + endDay + " " + endTime;
var requestData = await fetch(url);
var hisData = await requestData.json();
if (!hisData.length) {
alert("The date range selected doesn't have any items to export.");
return
} else {
// Generate PDF template
var dd = {
content: [
{text: 'Libretime', style: 'subheader'},
{text: 'Playout History from ' + startDay + ' ' + startTime + ' to ' + endDay + ' ' + endTime, style: 'header'},
{
style: 'mainTable',
table: {
headerRows: 1,
body: [
[{text: 'Start Time', style: 'tableHeader'}, {text: 'End Time', style: 'tableHeader'}, {text: 'Song', style: 'tableHeader'}, {text: 'Artist', style: 'tableHeader'}],
]
}
}
],
styles: {
header: {
fontSize: 18,
bold: true,
margin: [0, 0, 0, 10]
},
subheader: {
fontSize: 14,
bold: true,
margin: [0, 10, 0, 5]
},
mainTable: {
margin: [0, 5, 0, 15]
},
tableHeader: {
bold: true,
fontSize: 13,
color: 'black'
}
},
defaultStyle: {
}
};
hisData.forEach(element => {
// Removing extra fields
delete element.checkbox;
delete element.history_id;
2021-10-12 11:17:57 +02:00
delete element.instance_id;
2021-01-18 18:11:33 +01:00
dd.content[2].table.body.push(Object.values(element));
});
// Make PDF and start download
pdfMake.createPdf(dd).download();
};
});
2021-10-12 11:17:57 +02:00
2021-01-18 03:03:04 +01:00
$historyContentDiv.on("click", "#csv_export", async function(){
// Get date/time from pickers
var startDay = document.querySelector('#his_date_start').value;
var startTime = document.querySelector('#his_time_start').value;
var endDay = document.querySelector('#his_date_end').value;
var endTime = document.querySelector('#his_time_end').value;
var url = baseUrl + "api/item-history-feed?start=" + startDay + " " + startTime + "&end=" + endDay + " " + endTime;
var requestData = await fetch(url);
var hisData = await requestData.json();
if (!hisData.length) {
alert("The date range selected doesn't have any items to export.");
return
} else {
// Clean returned data
hisData.forEach(element => {
// Start date/time
element.startDate = element.starts.split(" ")[0];
element.startTime = element.starts.split(" ")[1];
// End date/time
element.endDate = element.ends.split(" ")[0];
element.endTime = element.ends.split(" ")[1];
// Moving Title and Artist fields to the end
element.title = element.track_title;
element.artist = element.artist_name;
// Removing extra fields
delete element.checkbox;
delete element.history_id;
delete element.instance_id;
delete element.starts; // we already converted these, so we don't need them anymore
delete element.ends;
delete element.track_title;
delete element.artist_name;
});
};
var csvX = new CSVExport(hisData); // Actual export function
return false // Was part of the demo. Please leave as is.
});
2021-10-12 11:17:57 +02:00
$('body').on("click", ".his_file_cancel, .his_item_cancel", function(e) {
removeHistoryDialog();
});
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
$('body').on("click", ".his_file_save", function(e) {
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
e.preventDefault();
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
var $form = $(this).parents("form");
var data = $form.serializeArray();
2021-10-12 11:17:57 +02:00
var url = baseUrl+"Playouthistory/update-file-item/format/json";
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
$.post(url, data, function(json) {
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
//TODO put errors on form.
if (json.error !== undefined) {
2013-07-18 07:31:20 +02:00
//makeHistoryDialog(json.dialog);
}
else {
removeHistoryDialog();
redrawTables();
2013-07-18 07:31:20 +02:00
}
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
}, "json");
2021-10-12 11:17:57 +02:00
2013-07-18 07:31:20 +02:00
});
2021-10-12 11:17:57 +02:00
2013-07-23 00:11:44 +02:00
$('body').on("click", ".his_item_save", function(e) {
2021-10-12 11:17:57 +02:00
2013-07-23 00:11:44 +02:00
e.preventDefault();
2021-10-12 11:17:57 +02:00
var $form = $(this).parents("form"),
data = $form.serializeArray(),
id = data[0].value,
createUrl = baseUrl+"Playouthistory/create-list-item/format/json",
updateUrl = baseUrl+"Playouthistory/update-list-item/format/json",
2013-08-30 21:03:43 +02:00
url,
$select = $hisDialogEl.find("#his_instance_select"),
instance;
2021-10-12 11:17:57 +02:00
url = (id === "") ? createUrl : updateUrl;
2021-10-12 11:17:57 +02:00
if (fnServerData.instance !== undefined) {
data.push({
name: "instance_id",
value: fnServerData.instance
});
}
2013-08-30 21:03:43 +02:00
else if ($select.length > 0) {
instance = $select.val();
2021-10-12 11:17:57 +02:00
2013-08-30 21:03:43 +02:00
if (instance > 0) {
data.push({
name: "instance_id",
value: instance
});
2021-10-12 11:17:57 +02:00
}
2013-08-30 21:03:43 +02:00
}
2021-10-12 11:17:57 +02:00
2013-07-23 00:11:44 +02:00
$.post(url, data, function(json) {
2021-10-12 11:17:57 +02:00
if (json.form !== undefined) {
var $newForm = $(json.form);
$newForm = processDialogHtml($newForm);
$hisDialogEl.html($newForm.html());
2013-08-28 19:42:33 +02:00
initializeDialog();
2013-07-23 00:11:44 +02:00
}
else {
removeHistoryDialog();
redrawTables();
2013-07-23 00:11:44 +02:00
}
2021-10-12 11:17:57 +02:00
2013-07-23 00:11:44 +02:00
}, "json");
2021-10-12 11:17:57 +02:00
});
2021-10-12 11:17:57 +02:00
$historyContentDiv.on("click", ".his_checkbox input", function(e) {
var checked = e.currentTarget.checked,
$tr = $(e.currentTarget).parents("tr");
2021-10-12 11:17:57 +02:00
if (checked) {
addSelectedLogItem($tr);
}
else {
removeSelectedLogItem($tr);
}
});
2021-10-12 11:17:57 +02:00
2013-08-30 21:03:43 +02:00
$('body').on("click", "#his_instance_retrieve", function(e) {
var startPicker = $hisDialogEl.find('#his_item_starts'),
endPicker = $hisDialogEl.find('#his_item_ends'),
2013-08-30 21:03:43 +02:00
url = baseUrl+"playouthistory/show-history-feed",
startDate = startPicker.val(),
endDate = endPicker.val(),
2013-08-30 21:03:43 +02:00
data;
2021-10-12 11:17:57 +02:00
2013-08-30 21:03:43 +02:00
data = {
start: startDate,
end: endDate,
2013-08-30 21:03:43 +02:00
format: "json"
};
2021-10-12 11:17:57 +02:00
2013-08-30 21:03:43 +02:00
$.get(url, data, function(json) {
var i,
$select = $('<select/>', {
id: 'his_instance_select'
}),
$option,
show;
2021-10-12 11:17:57 +02:00
if (json.length > 0) {
2013-08-30 21:03:43 +02:00
for (i = 0; i < json.length; i++) {
show = json[i];
2021-10-12 11:17:57 +02:00
2013-08-30 21:03:43 +02:00
$option = $('<option/>')
.text(show.name)
.attr('value', show.instance_id);
2021-10-12 11:17:57 +02:00
2013-08-30 21:03:43 +02:00
$select.append($option);
}
}
2021-10-12 11:17:57 +02:00
$option = $('<option/>')
.text($.i18n._("No Show"))
.attr('value', 0);
2021-10-12 11:17:57 +02:00
$select.append($option);
2021-10-12 11:17:57 +02:00
2013-08-30 21:03:43 +02:00
$hisDialogEl.find("#his_instance_select").replaceWith($select);
});
});
2021-10-12 11:17:57 +02:00
function getStartEnd() {
return AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId);
}
2021-10-12 11:17:57 +02:00
2021-01-22 15:20:04 +01:00
function hisSubmit(){
var fn, info;
2021-10-12 11:17:57 +02:00
2021-01-22 15:20:04 +01:00
info = getStartEnd();
2021-10-12 11:17:57 +02:00
2021-01-22 15:20:04 +01:00
fn = fnServerData;
fn.start = info.start;
fn.end = info.end;
2021-10-12 11:17:57 +02:00
2021-01-22 15:20:04 +01:00
if (inShowsTab) {
showSummaryList(info.start, info.end);
}
else {
redrawTables();
};
};
2013-07-18 07:31:20 +02:00
$historyContentDiv.find("#his_submit").click(function(ev){
2021-01-22 15:20:04 +01:00
hisSubmit();
});
2021-10-12 11:17:57 +02:00
2013-08-30 08:11:26 +02:00
$historyContentDiv.on("click", ".his-select-page", selectCurrentPage);
$historyContentDiv.on("click", ".his-dselect-page", deselectCurrentPage);
$historyContentDiv.on("click", ".his-dselect-all", emptySelectedLogItems);
2021-10-12 11:17:57 +02:00
2013-08-23 19:18:17 +02:00
$historyContentDiv.on("click", "#his_trash", function(ev){
var items = getSelectedLogItems(),
url = baseUrl+"playouthistory/delete-list-items";
2021-10-12 11:17:57 +02:00
$.post(url, {ids: items, format: "json"}, function() {
selectedLogItems = {};
redrawTables();
});
2013-07-18 07:31:20 +02:00
});
2021-10-12 11:17:57 +02:00
$historyContentDiv.find("#his-tabs").tabs({
show: function( event, ui ) {
var href = $(ui.tab).attr("href");
var index = href.split('-').pop();
var tab = tabsInit[index-1];
2021-10-12 11:17:57 +02:00
if (!tab.initialized) {
tab.initialize();
tab.initialized = true;
}
2013-08-29 21:17:24 +02:00
else {
tab.navigate();
}
2021-10-12 11:17:57 +02:00
tab.always();
}
});
2021-10-12 11:17:57 +02:00
// begin context menu initialization.
$.contextMenu({
selector: '#history_content td:not(.his_checkbox)',
trigger: "left",
ignoreRightClick: true,
2021-10-12 11:17:57 +02:00
build: function($el, e) {
2021-10-12 11:17:57 +02:00
var items = {},
callback,
$tr,
editUrl,
deleteUrl;
2021-10-12 11:17:57 +02:00
$tr = $el.parents("tr");
editUrl = $tr.data("url-edit");
deleteUrl = $tr.data("url-delete");
2021-10-12 11:17:57 +02:00
if (editUrl !== undefined) {
2021-10-12 11:17:57 +02:00
callback = function() {
$.post(editUrl, {format: "json"}, function(json) {
2021-10-12 11:17:57 +02:00
makeHistoryDialog(json.dialog);
2021-10-12 11:17:57 +02:00
}, "json");
};
2021-10-12 11:17:57 +02:00
items["edit"] = {
"name": $.i18n._("Edit"),
"icon": "edit",
"callback": callback
};
}
2021-10-12 11:17:57 +02:00
if (deleteUrl !== undefined) {
2021-10-12 11:17:57 +02:00
callback = function() {
var c = confirm("Delete this entry?");
2021-10-12 11:17:57 +02:00
if (c) {
$.post(deleteUrl, {format: "json"}, function(json) {
redrawTables();
});
2021-10-12 11:17:57 +02:00
}
};
2021-10-12 11:17:57 +02:00
items["del"] = {
"name": $.i18n._("Delete"),
"icon": "delete",
"callback": callback
};
}
2021-10-12 11:17:57 +02:00
return {
items: items
};
}
});
};
2021-10-12 11:17:57 +02:00
return AIRTIME;
2021-10-12 11:17:57 +02:00
}(AIRTIME || {}));
2021-10-12 11:17:57 +02:00
$(document).ready(AIRTIME.history.onReady);