2012-03-08 18:30:56 +01:00
|
|
|
var AIRTIME = (function(AIRTIME) {
|
|
|
|
var mod;
|
|
|
|
|
|
|
|
if (AIRTIME.history === undefined) {
|
|
|
|
AIRTIME.history = {};
|
|
|
|
}
|
|
|
|
mod = AIRTIME.history;
|
|
|
|
|
2013-07-18 07:31:20 +02:00
|
|
|
var $historyContentDiv;
|
|
|
|
|
|
|
|
var oTableTools = {
|
2013-08-13 00:18:33 +02:00
|
|
|
"sSwfPath": baseUrl+"js/datatables/plugin/TableTools-2.1.5/swf/copy_csv_xls_pdf.swf",
|
2013-07-18 07:31:20 +02:00
|
|
|
"aButtons": [
|
|
|
|
{
|
|
|
|
"sExtends": "copy",
|
|
|
|
"fnComplete": function(nButton, oConfig, oFlash, text) {
|
|
|
|
var lines = text.split('\n').length,
|
|
|
|
len = this.s.dt.nTFoot === null ? lines-1 : lines-2,
|
|
|
|
plural = (len==1) ? "" : "s";
|
|
|
|
alert(sprintf($.i18n._('Copied %s row%s to the clipboard'), len, plural));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"sExtends": "csv",
|
|
|
|
"fnClick": setFlashFileName
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"sExtends": "pdf",
|
|
|
|
"fnClick": setFlashFileName
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"sExtends": "print",
|
|
|
|
"sInfo" : sprintf($.i18n._("%sPrint view%sPlease use your browser's print function to print this table. Press escape when finished."), "<h6>", "</h6><p>")
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2013-07-24 00:01:43 +02:00
|
|
|
var lengthMenu = [[10, 25, 50, 100, 500, -1], [10, 25, 50, 100, 500, $.i18n._("All")]];
|
2013-07-18 07:31:20 +02:00
|
|
|
|
2013-07-24 00:01:43 +02:00
|
|
|
var sDom = 'l<"dt-process-rel"r><"H"T><"dataTables_scrolling"t><"F"ip>';
|
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");
|
2013-07-09 00:00:02 +02:00
|
|
|
|
2013-07-18 07:31:20 +02:00
|
|
|
if (ext == "pdf"){
|
|
|
|
filename = filename+".pdf";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
filename = filename+".csv";
|
|
|
|
}
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setFlashFileName( nButton, oConfig, oFlash ) {
|
|
|
|
var filename = getFileName(oConfig.sExtends);
|
|
|
|
oFlash.setFileName( filename );
|
|
|
|
|
|
|
|
if (oConfig.sExtends == "pdf") {
|
|
|
|
this.fnSetText( oFlash,
|
2013-07-26 17:36:58 +02:00
|
|
|
//"title:"+ this.fnGetTitle(oConfig) +"\n"+
|
|
|
|
"title: Testing the Title Out\n"+
|
2013-07-18 07:31:20 +02:00
|
|
|
"message:"+ oConfig.sPdfMessage +"\n"+
|
|
|
|
"colWidth:"+ this.fnCalcColRatios(oConfig) +"\n"+
|
|
|
|
"orientation:"+ oConfig.sPdfOrientation +"\n"+
|
|
|
|
"size:"+ oConfig.sPdfSize +"\n"+
|
|
|
|
"--/TableToolsOpts--\n" +
|
|
|
|
this.fnGetTableData(oConfig));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.fnSetText(oFlash, this.fnGetTableData(oConfig));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This callback can be used for all history tables */
|
|
|
|
function fnServerData( sSource, aoData, fnCallback ) {
|
|
|
|
|
|
|
|
if (fnServerData.hasOwnProperty("start")) {
|
|
|
|
aoData.push( { name: "start", value: fnServerData.start} );
|
|
|
|
}
|
|
|
|
if (fnServerData.hasOwnProperty("end")) {
|
|
|
|
aoData.push( { name: "end", value: fnServerData.end} );
|
|
|
|
}
|
|
|
|
|
|
|
|
aoData.push( { name: "format", value: "json"} );
|
|
|
|
|
|
|
|
$.ajax( {
|
|
|
|
"dataType": 'json',
|
|
|
|
"type": "GET",
|
|
|
|
"url": sSource,
|
|
|
|
"data": aoData,
|
|
|
|
"success": fnCallback
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
function aggregateHistoryTable() {
|
|
|
|
var oTable,
|
|
|
|
$historyTableDiv = $historyContentDiv.find("#history_table_aggregate"),
|
|
|
|
fnRowCallback;
|
|
|
|
|
2013-07-09 00:00:02 +02:00
|
|
|
fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
|
2013-08-12 21:06:26 +02:00
|
|
|
var editUrl = baseUrl+"Playouthistory/edit-file-item/format/json/id/"+aData.file_id;
|
2013-07-24 00:01:43 +02:00
|
|
|
|
|
|
|
nRow.setAttribute('url-edit', editUrl);
|
2012-03-12 11:47:25 +01:00
|
|
|
};
|
2012-03-08 18:30:56 +01:00
|
|
|
|
2013-08-02 21:29:39 +02:00
|
|
|
var columns = JSON.parse(localStorage.getItem('datatables-historyfile-aoColumns'));
|
|
|
|
|
2013-07-18 07:31:20 +02:00
|
|
|
oTable = $historyTableDiv.dataTable( {
|
2012-03-08 18:30:56 +01:00
|
|
|
|
2013-08-02 21:29:39 +02:00
|
|
|
"aoColumns": columns,
|
2012-03-08 18:30:56 +01:00
|
|
|
|
|
|
|
"bProcessing": true,
|
|
|
|
"bServerSide": true,
|
2013-08-12 21:06:26 +02:00
|
|
|
"sAjaxSource": baseUrl+"playouthistory/file-history-feed",
|
2012-03-08 18:30:56 +01:00
|
|
|
"sAjaxDataProp": "history",
|
2012-03-12 11:47:25 +01:00
|
|
|
"fnServerData": fnServerData,
|
2013-07-09 00:00:02 +02:00
|
|
|
"fnRowCallback": fnRowCallback,
|
2012-11-27 18:17:59 +01:00
|
|
|
"oLanguage": datatables_dict,
|
2013-07-18 07:31:20 +02:00
|
|
|
"aLengthMenu": lengthMenu,
|
2012-03-12 11:47:25 +01:00
|
|
|
"iDisplayLength": 50,
|
2012-03-08 18:30:56 +01:00
|
|
|
"sPaginationType": "full_numbers",
|
|
|
|
"bJQueryUI": true,
|
2012-03-12 11:47:25 +01:00
|
|
|
"bAutoWidth": true,
|
2013-07-18 07:31:20 +02:00
|
|
|
"sDom": sDom,
|
|
|
|
"oTableTools": oTableTools
|
2012-03-08 18:30:56 +01:00
|
|
|
});
|
2012-03-09 11:13:32 +01:00
|
|
|
oTable.fnSetFilteringDelay(350);
|
2013-07-18 07:31:20 +02:00
|
|
|
|
|
|
|
return oTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
function itemHistoryTable() {
|
|
|
|
var oTable,
|
|
|
|
$historyTableDiv = $historyContentDiv.find("#history_table_list"),
|
|
|
|
fnRowCallback;
|
2013-07-31 23:38:48 +02:00
|
|
|
|
|
|
|
var columns = JSON.parse(localStorage.getItem('datatables-historyitem-aoColumns'));
|
2013-07-18 07:31:20 +02:00
|
|
|
|
|
|
|
fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
|
2013-07-24 00:01:43 +02:00
|
|
|
var editUrl = baseUrl+"playouthistory/edit-list-item/format/json/id/"+aData.history_id,
|
|
|
|
deleteUrl = baseUrl+"playouthistory/delete-list-item/format/json/id/"+aData.history_id;
|
|
|
|
|
|
|
|
nRow.setAttribute('url-edit', editUrl);
|
|
|
|
nRow.setAttribute('url-delete', deleteUrl);
|
2013-07-18 07:31:20 +02:00
|
|
|
};
|
2012-03-12 11:47:25 +01:00
|
|
|
|
2013-07-18 07:31:20 +02:00
|
|
|
oTable = $historyTableDiv.dataTable( {
|
|
|
|
|
2013-07-31 23:38:48 +02:00
|
|
|
"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": datatables_dict,
|
|
|
|
"aLengthMenu": lengthMenu,
|
|
|
|
"iDisplayLength": 50,
|
|
|
|
"sPaginationType": "full_numbers",
|
|
|
|
"bJQueryUI": true,
|
|
|
|
"bAutoWidth": true,
|
|
|
|
"sDom": sDom,
|
|
|
|
"oTableTools": oTableTools
|
|
|
|
});
|
|
|
|
oTable.fnSetFilteringDelay(350);
|
|
|
|
|
2012-03-12 11:47:25 +01:00
|
|
|
return oTable;
|
2013-07-18 07:31:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mod.onReady = function() {
|
|
|
|
|
|
|
|
var viewport = AIRTIME.utilities.findViewportDimensions(),
|
|
|
|
widgetHeight = viewport.height - 185,
|
|
|
|
screenWidth = Math.floor(viewport.width - 110),
|
|
|
|
oBaseDatePickerSettings,
|
|
|
|
oBaseTimePickerSettings,
|
2013-07-24 00:01:43 +02:00
|
|
|
oTableAgg,
|
|
|
|
oTableItem,
|
2013-07-18 07:31:20 +02:00
|
|
|
dateStartId = "#his_date_start",
|
|
|
|
timeStartId = "#his_time_start",
|
|
|
|
dateEndId = "#his_date_end",
|
|
|
|
timeEndId = "#his_time_end",
|
|
|
|
$hisDialogEl;
|
|
|
|
|
|
|
|
$historyContentDiv = $("#history_content");
|
|
|
|
|
|
|
|
function removeHistoryDialog() {
|
|
|
|
$hisDialogEl.dialog("destroy");
|
|
|
|
$hisDialogEl.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeHistoryDialog(html) {
|
|
|
|
$hisDialogEl = $(html);
|
2013-07-26 23:33:17 +02:00
|
|
|
|
2013-07-18 07:31:20 +02:00
|
|
|
$hisDialogEl.dialog({
|
|
|
|
title: $.i18n._("Edit History Record"),
|
|
|
|
modal: true,
|
2013-07-26 23:33:17 +02:00
|
|
|
open: function( event, ui ) {
|
2013-07-29 14:57:31 +02:00
|
|
|
$hisDialogEl.find('.date').datetimepicker({
|
|
|
|
"pick12HourFormat": false
|
|
|
|
});
|
2013-07-26 23:33:17 +02:00
|
|
|
},
|
2013-07-18 07:31:20 +02:00
|
|
|
close: function() {
|
|
|
|
removeHistoryDialog();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Icon hover states for search.
|
|
|
|
*/
|
|
|
|
$historyContentDiv.on("mouseenter", ".his-timerange .ui-button", function(ev) {
|
|
|
|
$(this).addClass("ui-state-hover");
|
|
|
|
});
|
|
|
|
$historyContentDiv.on("mouseleave", ".his-timerange .ui-button", function(ev) {
|
|
|
|
$(this).removeClass("ui-state-hover");
|
|
|
|
});
|
|
|
|
|
|
|
|
$historyContentDiv
|
|
|
|
.height(widgetHeight)
|
|
|
|
.width(screenWidth);
|
|
|
|
|
|
|
|
oBaseDatePickerSettings = {
|
|
|
|
dateFormat: 'yy-mm-dd',
|
|
|
|
//i18n_months, i18n_days_short are in common.js
|
|
|
|
monthNames: i18n_months,
|
|
|
|
dayNamesMin: i18n_days_short,
|
|
|
|
onSelect: function(sDate, oDatePicker) {
|
|
|
|
$(this).datepicker( "setDate", sDate );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
oBaseTimePickerSettings = {
|
|
|
|
showPeriodLabels: false,
|
|
|
|
showCloseButton: true,
|
|
|
|
closeButtonText: $.i18n._("Done"),
|
|
|
|
showLeadingZero: false,
|
|
|
|
defaultTime: '0:00',
|
|
|
|
hourText: $.i18n._("Hour"),
|
|
|
|
minuteText: $.i18n._("Minute")
|
|
|
|
};
|
|
|
|
|
2013-07-24 00:01:43 +02:00
|
|
|
oTableItem = itemHistoryTable();
|
|
|
|
oTableAgg = aggregateHistoryTable();
|
2013-07-18 07:31:20 +02:00
|
|
|
|
|
|
|
$historyContentDiv.find(dateStartId).datepicker(oBaseDatePickerSettings);
|
|
|
|
$historyContentDiv.find(timeStartId).timepicker(oBaseTimePickerSettings);
|
|
|
|
$historyContentDiv.find(dateEndId).datepicker(oBaseDatePickerSettings);
|
|
|
|
$historyContentDiv.find(timeEndId).timepicker(oBaseTimePickerSettings);
|
|
|
|
|
2013-07-24 00:01:43 +02:00
|
|
|
// 'open' an information row when a row is clicked on
|
|
|
|
//for create/edit/delete
|
|
|
|
function openRow(oTable, tr) {
|
|
|
|
var links = ['url-edit', 'url-delete'],
|
|
|
|
i, len,
|
|
|
|
attr,
|
|
|
|
name,
|
|
|
|
$link,
|
|
|
|
$div;
|
|
|
|
|
|
|
|
$div = $("<div/>");
|
|
|
|
|
|
|
|
for (i = 0, len = links.length; i < len; i++) {
|
|
|
|
|
|
|
|
attr = links[i];
|
|
|
|
|
|
|
|
if (tr.hasAttribute(attr)) {
|
|
|
|
name = attr.split("-")[1];
|
|
|
|
|
|
|
|
$link = $("<a/>", {
|
|
|
|
"href": tr.getAttribute(attr),
|
|
|
|
"text": $.i18n._(name),
|
|
|
|
"class": "his_"+name
|
|
|
|
});
|
|
|
|
|
|
|
|
$div.append($link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oTable.fnIsOpen(tr)) {
|
|
|
|
oTable.fnClose(tr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
oTable.fnOpen(tr, $div, "his_update");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$historyContentDiv.on("click", "#history_table_list tr", function(ev) {
|
|
|
|
openRow(oTableItem, this);
|
|
|
|
});
|
|
|
|
|
|
|
|
$historyContentDiv.on("click", "#history_table_aggregate tr", function(ev) {
|
|
|
|
openRow(oTableAgg, this);
|
|
|
|
});
|
|
|
|
|
|
|
|
$("#his_create").click(function(e) {
|
|
|
|
var url = baseUrl+"playouthistory/edit-list-item/format/json" ;
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
$.get(url, function(json) {
|
|
|
|
|
|
|
|
makeHistoryDialog(json.dialog);
|
|
|
|
|
|
|
|
}, "json");
|
|
|
|
});
|
|
|
|
|
|
|
|
$historyContentDiv.on("click", "a.his_edit", function(e) {
|
2013-07-18 07:31:20 +02:00
|
|
|
var url = e.target.href;
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
$.get(url, function(json) {
|
|
|
|
|
|
|
|
makeHistoryDialog(json.dialog);
|
|
|
|
|
|
|
|
}, "json");
|
|
|
|
});
|
|
|
|
|
2013-07-24 00:01:43 +02:00
|
|
|
$historyContentDiv.on("click", "a.his_delete", function(e) {
|
|
|
|
var url = e.target.href,
|
|
|
|
doDelete;
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
doDelete = confirm($.i18n._("Delete this history record?"));
|
|
|
|
|
|
|
|
if (doDelete) {
|
|
|
|
$.post(url, function(json) {
|
|
|
|
oTableAgg.fnDraw();
|
|
|
|
oTableItem.fnDraw();
|
|
|
|
|
|
|
|
}, "json");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('body').on("click", ".his_file_cancel, .his_item_cancel", function(e) {
|
|
|
|
removeHistoryDialog();
|
|
|
|
});
|
|
|
|
|
2013-07-18 07:31:20 +02:00
|
|
|
$('body').on("click", ".his_file_save", function(e) {
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var $form = $(this).parents("form");
|
|
|
|
var data = $form.serializeArray();
|
|
|
|
|
2013-08-12 21:06:26 +02:00
|
|
|
var url = baseUrl+"Playouthistory/update-file-item/format/json";
|
2013-07-18 07:31:20 +02:00
|
|
|
|
|
|
|
$.post(url, data, function(json) {
|
|
|
|
|
|
|
|
//TODO put errors on form.
|
2013-08-12 21:06:26 +02:00
|
|
|
if (json.error !== undefined) {
|
2013-07-18 07:31:20 +02:00
|
|
|
//makeHistoryDialog(json.dialog);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
removeHistoryDialog();
|
2013-07-24 00:01:43 +02:00
|
|
|
oTableAgg.fnDraw();
|
2013-07-18 07:31:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}, "json");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-07-23 00:11:44 +02:00
|
|
|
$('body').on("click", ".his_item_save", function(e) {
|
|
|
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
2013-07-24 00:01:43 +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",
|
|
|
|
url;
|
2013-07-23 00:11:44 +02:00
|
|
|
|
2013-07-24 00:01:43 +02:00
|
|
|
url = (id === "") ? createUrl : updateUrl;
|
|
|
|
|
2013-07-23 00:11:44 +02:00
|
|
|
$.post(url, data, function(json) {
|
|
|
|
|
|
|
|
//TODO put errors on form.
|
2013-08-05 21:05:26 +02:00
|
|
|
if (json.error !== undefined) {
|
|
|
|
|
2013-07-23 00:11:44 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
removeHistoryDialog();
|
2013-07-24 00:01:43 +02:00
|
|
|
oTableItem.fnDraw();
|
2013-07-23 00:11:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}, "json");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-07-18 07:31:20 +02:00
|
|
|
$historyContentDiv.find("#his_submit").click(function(ev){
|
|
|
|
var fn,
|
|
|
|
oRange;
|
|
|
|
|
|
|
|
oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId);
|
|
|
|
|
2013-07-24 00:01:43 +02:00
|
|
|
fn = fnServerData;
|
2013-07-18 07:31:20 +02:00
|
|
|
fn.start = oRange.start;
|
|
|
|
fn.end = oRange.end;
|
|
|
|
|
2013-07-24 00:01:43 +02:00
|
|
|
oTableAgg.fnDraw();
|
|
|
|
oTableItem.fnDraw();
|
2013-07-18 07:31:20 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$historyContentDiv.find("#his-tabs").tabs();
|
|
|
|
|
2012-03-08 18:30:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return AIRTIME;
|
|
|
|
|
|
|
|
}(AIRTIME || {}));
|
|
|
|
|
2013-07-18 07:31:20 +02:00
|
|
|
$(document).ready(AIRTIME.history.onReady);
|