var AIRTIME = (function(AIRTIME) {
var mod;
if (AIRTIME.history === undefined) {
AIRTIME.history = {};
}
mod = AIRTIME.history;
var $historyContentDiv;
var oTableTools = {
"sSwfPath": baseUrl+"js/datatables/plugin/TableTools-2.1.5/swf/copy_csv_xls_pdf.swf",
"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));
},
//set because only the checkbox row is not sortable.
"mColumns": "sortable"
},
{
"sExtends": "csv",
"fnClick": setFlashFileName,
//set because only the checkbox row is not sortable.
"mColumns": "sortable"
},
{
"sExtends": "pdf",
"fnClick": setFlashFileName,
"sPdfOrientation": "landscape",
//set because only the checkbox row is not sortable.
"mColumns": "sortable"
},
{
"sExtends": "print",
"sInfo" : sprintf($.i18n._("%sPrint view%sPlease use your browser's print function to print this table. Press escape when finished."), "
", "
"),
//set because only the checkbox row is not sortable.
"mColumns": "sortable"
}
]
};
var lengthMenu = [[10, 25, 50, 100, 500, -1], [10, 25, 50, 100, 500, $.i18n._("All")]];
var sDom = 'l<"dt-process-rel"r><"H"T><"dataTables_scrolling"t><"F"ip>';
var selectedLogItems = {};
var dateStartId = "#his_date_start",
timeStartId = "#his_time_start",
dateEndId = "#his_date_end",
timeEndId = "#his_time_end",
oTableAgg,
oTableItem,
oTableShow,
inShowsTab = false;
function getSelectedLogItems() {
var items = Object.keys(selectedLogItems);
return items;
}
function addSelectedLogItem($el) {
var id;
$el.addClass("his-selected");
id = $el.data("his-id");
selectedLogItems[id] = "";
}
function removeSelectedLogItem($el) {
var id;
$el.removeClass("his-selected");
id = $el.data("his-id");
delete selectedLogItems[id];
}
function emptySelectedLogItems() {
var $inputs = $historyContentDiv.find(".his_checkbox").find("input");
$inputs.prop('checked', false);
$inputs.parents("tr").removeClass("his-selected");
selectedLogItems = {};
}
function selectCurrentPage(e) {
var $ctx = $(e.currentTarget).parents("div.dataTables_wrapper"),
$inputs = $ctx.find(".his_checkbox").find("input"),
$tr,
$input;
$.each($inputs, function(index, input) {
$input = $(input);
$input.prop('checked', true);
$tr = $input.parents("tr");
addSelectedLogItem($tr);
});
}
function deselectCurrentPage(e) {
var $ctx = $(e.currentTarget).parents("div.dataTables_wrapper"),
$inputs = $ctx.find(".his_checkbox").find("input"),
$tr,
$input;
$.each($inputs, function(index, input) {
$input = $(input);
$input.prop('checked', false);
$tr = $input.parents("tr");
removeSelectedLogItem($tr);
});
}
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");
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,
"title:"+ this.fnGetTitle(oConfig) +"\n"+
"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} );
}
if (fnServerData.hasOwnProperty("instance")) {
aoData.push( { name: "instance_id", value: fnServerData.instance} );
}
aoData.push( { name: "format", value: "json"} );
$.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
function createShowAccordSection(config) {
var template,
$el;
template =
"
";
template = _.template(template);
$el = $(template(config));
return $el;
}
//$el is the div in the accordian we should create the table on.
function createShowTable($el) {
var instance = $el.data("instance");
var $table = $("
", {
'cellpadding': "0",
'cellspacing': "0",
'class': "datatable",
'id': "history_table_show"
});
//assign the retrieval function the show instance id.
fnServerData.instance = instance;
$el.append($table);
$el.css("height", "auto");
oTableShow = itemHistoryTable("history_table_show");
}
function drawShowList(oShows) {
var $showList = $historyContentDiv.find("#history_show_summary"),
i,
len,
$accordSection,
show,
tmp;
$showList
.accordion( "destroy" )
.empty();
for (i = 0, len = oShows.length; i < len; i++) {
show = oShows[i];
tmp = show.starts.split(" ");
$accordSection = createShowAccordSection({
instance: show.instance_id,
name: show.name,
date: tmp[0],
startTime: tmp[1],
endTime: show.ends.split(" ").pop()
});
$showList.append($accordSection);
}
$showList.accordion({
animated: false,
create: function( event, ui ) {
var $div = $showList.find(".ui-accordion-content-active");
createShowTable($div);
},
change: function( event, ui ) {
var $div = $(ui.newContent);
$(ui.oldContent).empty();
createShowTable($div);
selectedLogItems = {};
}
//changestart: function( event, ui ) {}
});
}
function createToolbarButtons ($el) {
var $menu = $("");
$menu.append("