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 ) ) ;
2013-08-22 21:19:38 +02:00
} ,
//set because only the checkbox row is not sortable.
"mColumns" : "sortable"
2013-07-18 07:31:20 +02:00
} ,
{
"sExtends" : "csv" ,
2013-08-22 21:19:38 +02:00
"fnClick" : setFlashFileName ,
//set because only the checkbox row is not sortable.
"mColumns" : "sortable"
2013-07-18 07:31:20 +02:00
} ,
{
"sExtends" : "pdf" ,
2013-08-22 21:19:38 +02:00
"fnClick" : setFlashFileName ,
"sPdfOrientation" : "landscape" ,
//set because only the checkbox row is not sortable.
"mColumns" : "sortable"
2013-07-18 07:31:20 +02:00
} ,
{
"sExtends" : "print" ,
2013-08-22 21:19:38 +02:00
"sInfo" : sprintf ( $ . i18n . _ ( "%sPrint view%sPlease use your browser's print function to print this table. Press escape when finished." ) , "<h6>" , "</h6><p>" ) ,
//set because only the checkbox row is not sortable.
"mColumns" : "sortable"
2013-07-18 07:31:20 +02:00
}
]
} ;
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
2013-08-20 23:23:15 +02:00
var selectedLogItems = { } ;
2013-08-29 01:37:46 +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" ,
oTableAgg ,
oTableItem ,
2013-08-30 00:52:40 +02:00
oTableShow ,
inShowsTab = false ;
2013-08-29 01:37:46 +02:00
2014-03-10 23:33:07 +01:00
function validateTimeRange ( ) {
var oRange ,
inputs = $ ( '.his-timerange > input' ) ,
start , end ;
oRange = AIRTIME . utilities . fnGetScheduleRange ( dateStartId , timeStartId , dateEndId , timeEndId ) ;
start = oRange . start ;
end = oRange . end ;
if ( end >= start ) {
inputs . removeClass ( 'error' ) ;
}
else {
inputs . addClass ( 'error' ) ;
}
return {
start : start ,
end : end ,
isValid : end >= start
} ;
}
2013-08-20 23:23:15 +02:00
function getSelectedLogItems ( ) {
var items = Object . keys ( selectedLogItems ) ;
return items ;
}
2013-08-23 19:31:37 +02:00
function addSelectedLogItem ( $el ) {
var id ;
$el . addClass ( "his-selected" ) ;
id = $el . data ( "his-id" ) ;
2013-08-20 23:23:15 +02:00
selectedLogItems [ id ] = "" ;
}
2013-08-23 19:31:37 +02:00
function removeSelectedLogItem ( $el ) {
var id ;
$el . removeClass ( "his-selected" ) ;
id = $el . data ( "his-id" ) ;
2013-08-20 23:23:15 +02:00
delete selectedLogItems [ id ] ;
}
function emptySelectedLogItems ( ) {
2013-08-28 19:42:33 +02:00
var $inputs = $historyContentDiv . find ( ".his_checkbox" ) . find ( "input" ) ;
2013-08-23 19:31:37 +02:00
$inputs . prop ( 'checked' , false ) ;
$inputs . parents ( "tr" ) . removeClass ( "his-selected" ) ;
2013-08-23 19:18:17 +02:00
2013-08-20 23:23:15 +02:00
selectedLogItems = { } ;
}
2013-08-30 08:31:23 +02:00
function selectCurrentPage ( e ) {
var $ctx = $ ( e . currentTarget ) . parents ( "div.dataTables_wrapper" ) ,
$inputs = $ctx . find ( ".his_checkbox" ) . find ( "input" ) ,
2013-08-28 19:42:33 +02:00
$tr ,
$input ;
2013-08-23 19:18:17 +02:00
$ . each ( $inputs , function ( index , input ) {
$input = $ ( input ) ;
$input . prop ( 'checked' , true ) ;
$tr = $input . parents ( "tr" ) ;
2013-08-23 19:31:37 +02:00
addSelectedLogItem ( $tr ) ;
2013-08-23 19:18:17 +02:00
} ) ;
}
2013-08-30 08:31:23 +02:00
function deselectCurrentPage ( e ) {
var $ctx = $ ( e . currentTarget ) . parents ( "div.dataTables_wrapper" ) ,
$inputs = $ctx . find ( ".his_checkbox" ) . find ( "input" ) ,
2013-08-28 19:42:33 +02:00
$tr ,
$input ;
2013-08-23 19:18:17 +02:00
$ . each ( $inputs , function ( index , input ) {
$input = $ ( input ) ;
$input . prop ( 'checked' , false ) ;
$tr = $input . parents ( "tr" ) ;
2013-08-23 19:31:37 +02:00
removeSelectedLogItem ( $tr ) ;
2013-08-23 19:18:17 +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" ) ;
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-08-22 21:19:38 +02:00
"title:" + this . fnGetTitle ( oConfig ) + "\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 } ) ;
}
2013-08-29 05:30:15 +02:00
if ( fnServerData . hasOwnProperty ( "instance" ) ) {
aoData . push ( { name : "instance_id" , value : fnServerData . instance } ) ;
}
2013-07-18 07:31:20 +02:00
aoData . push ( { name : "format" , value : "json" } ) ;
$ . ajax ( {
"dataType" : 'json' ,
"type" : "GET" ,
"url" : sSource ,
"data" : aoData ,
"success" : fnCallback
} ) ;
}
2013-08-29 05:30:15 +02:00
function createShowAccordSection ( config ) {
var template ,
$el ;
template =
2013-08-29 21:17:24 +02:00
"<h3>" +
2013-08-29 05:30:15 +02:00
"<a href='#'>" +
2013-08-30 07:06:59 +02:00
"<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>" +
2013-08-29 05:30:15 +02:00
"</a>" +
"</h3>" +
2013-08-29 21:17:24 +02:00
"<div " +
"data-instance='<%= instance %>' " +
"></div>" ;
2013-08-29 05:30:15 +02:00
template = _ . template ( template ) ;
$el = $ ( template ( config ) ) ;
return $el ;
}
2013-08-29 17:01:03 +02:00
//$el is the div in the accordian we should create the table on.
function createShowTable ( $el ) {
2013-08-29 21:17:24 +02:00
var instance = $el . data ( "instance" ) ;
var $table = $ ( "<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" ) ;
2013-08-29 17:01:03 +02:00
}
2013-08-29 05:30:15 +02:00
function drawShowList ( oShows ) {
var $showList = $historyContentDiv . find ( "#history_show_summary" ) ,
i ,
len ,
$accordSection ,
2013-08-30 07:06:59 +02:00
show ,
tmp ;
2013-08-29 05:30:15 +02:00
2013-08-29 21:52:24 +02:00
$showList
. accordion ( "destroy" )
. empty ( ) ;
2013-08-29 05:30:15 +02:00
for ( i = 0 , len = oShows . length ; i < len ; i ++ ) {
show = oShows [ i ] ;
2013-08-30 07:06:59 +02:00
tmp = show . starts . split ( " " ) ;
2013-08-29 05:30:15 +02:00
$accordSection = createShowAccordSection ( {
instance : show . instance _id ,
name : show . name ,
2013-08-30 07:06:59 +02:00
date : tmp [ 0 ] ,
startTime : tmp [ 1 ] ,
endTime : show . ends . split ( " " ) . pop ( )
2013-08-29 05:30:15 +02:00
} ) ;
$showList . append ( $accordSection ) ;
}
$showList . accordion ( {
2013-08-30 07:39:51 +02:00
animated : false ,
2013-08-29 05:30:15 +02:00
create : function ( event , ui ) {
var $div = $showList . find ( ".ui-accordion-content-active" ) ;
2015-08-12 18:55:39 +02:00
console . log ( event ) ;
//$div.css()
2013-08-29 21:17:24 +02:00
createShowTable ( $div ) ;
2013-08-29 05:30:15 +02:00
} ,
change : function ( event , ui ) {
2013-08-29 21:17:24 +02:00
var $div = $ ( ui . newContent ) ;
2013-08-30 07:39:51 +02:00
$ ( ui . oldContent ) . empty ( ) ;
2013-08-29 21:17:24 +02:00
createShowTable ( $div ) ;
2013-08-30 08:24:16 +02:00
selectedLogItems = { } ;
2013-08-29 05:30:15 +02:00
}
2013-08-30 08:24:16 +02:00
//changestart: function( event, ui ) {}
2013-08-29 05:30:15 +02:00
} ) ;
}
2013-08-20 05:19:13 +02:00
function createToolbarButtons ( $el ) {
var $menu = $ ( "<div class='btn-toolbar' />" ) ;
2015-08-12 18:55:39 +02:00
$menu . append ( "<div class='btn-group'>" +
"<button class='btn btn-small' id='his_create'>" +
"<i class='icon-white icon-plus'></i>" +
$ . i18n . _ ( "New Log Entry" ) +
"</button>" +
"</div>" ) ;
$menu . append ( "<div class='btn-group'>" +
2013-08-20 05:19:13 +02:00
"<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>" +
2013-08-20 05:19:13 +02:00
"</ul>" +
"</div>" ) ;
$menu . append ( "<div class='btn-group'>" +
"<button class='btn btn-small' id='his_trash'>" +
"<i class='icon-white icon-trash'></i>" +
"</button>" +
"</div>" ) ;
$el . append ( $menu ) ;
}
2013-07-18 07:31:20 +02:00
function aggregateHistoryTable ( ) {
var oTable ,
$historyTableDiv = $historyContentDiv . find ( "#history_table_aggregate" ) ,
2013-08-14 22:38:59 +02:00
columns ,
2013-07-18 07:31:20 +02:00
fnRowCallback ;
2013-07-09 00:00:02 +02:00
fnRowCallback = function ( nRow , aData , iDisplayIndex , iDisplayIndexFull ) {
2013-08-20 20:58:22 +02:00
var editUrl = baseUrl + "playouthistory/edit-file-item/id/" + aData . file _id ,
$nRow = $ ( nRow ) ;
2013-07-24 00:01:43 +02:00
2013-08-20 20:58:22 +02:00
$nRow . data ( 'url-edit' , editUrl ) ;
2012-03-12 11:47:25 +01:00
} ;
2012-03-08 18:30:56 +01:00
2013-08-14 22:38:59 +02:00
columns = JSON . parse ( localStorage . getItem ( 'datatables-historyfile-aoColumns' ) ) ;
2013-08-02 21:29:39 +02:00
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 ,
2013-08-22 21:45:09 +02:00
"iDisplayLength" : 25 ,
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 ;
}
2013-08-29 05:30:15 +02:00
function itemHistoryTable ( id ) {
2013-07-18 07:31:20 +02:00
var oTable ,
2013-08-29 05:30:15 +02:00
$historyTableDiv = $historyContentDiv . find ( "#" + id ) ,
2013-08-20 05:19:13 +02:00
$toolbar ,
2013-08-14 22:38:59 +02:00
columns ,
fnRowCallback ,
booleans = { } ,
i , c ;
columns = JSON . parse ( localStorage . getItem ( 'datatables-historyitem-aoColumns' ) ) ;
2013-07-31 23:38:48 +02:00
2013-08-14 22:38:59 +02:00
for ( i in columns ) {
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 ) {
2013-08-20 20:58:22 +02:00
var editUrl = baseUrl + "playouthistory/edit-list-item/id/" + aData . history _id ,
deleteUrl = baseUrl + "playouthistory/delete-list-item/id/" + aData . history _id ,
2013-08-14 22:38:59 +02:00
emptyCheckBox = String . fromCharCode ( parseInt ( 2610 , 16 ) ) ,
checkedCheckBox = String . fromCharCode ( parseInt ( 2612 , 16 ) ) ,
b ,
text ,
$nRow = $ ( nRow ) ;
2013-08-20 05:19:13 +02:00
// add checkbox
$nRow . find ( 'td.his_checkbox' ) . html ( "<input type='checkbox' name='cb_" + aData . history _id + "'>" ) ;
2013-07-24 00:01:43 +02:00
2013-08-20 20:58:22 +02:00
$nRow . data ( 'his-id' , aData . history _id ) ;
$nRow . data ( 'url-edit' , editUrl ) ;
$nRow . data ( 'url-delete' , deleteUrl ) ;
2013-08-14 22:38:59 +02:00
for ( b in booleans ) {
text = aData [ b ] ? checkedCheckBox : emptyCheckBox ;
text = text + " " + booleans [ b ] ;
$nRow . find ( ".his_" + b ) . html ( text ) ;
}
2013-07-18 07:31:20 +02:00
} ;
2013-08-14 22:38:59 +02: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 ,
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 ,
"sDom" : sDom ,
"oTableTools" : oTableTools
} ) ;
oTable . fnSetFilteringDelay ( 350 ) ;
2013-08-20 05:19:13 +02:00
$toolbar = $historyTableDiv . parents ( ".dataTables_wrapper" ) . find ( ".fg-toolbar:first" ) ;
createToolbarButtons ( $toolbar ) ;
2013-08-30 08:11:26 +02:00
2012-03-12 11:47:25 +01:00
return oTable ;
2013-07-18 07:31:20 +02:00
}
2014-03-10 22:39:17 +01:00
function showSummaryList ( start , end ) {
2013-08-29 01:37:46 +02:00
var url = baseUrl + "playouthistory/show-history-feed" ,
data = {
format : "json" ,
2014-03-10 22:39:17 +01:00
start : start ,
end : end
2013-08-29 01:37:46 +02:00
} ;
2013-08-29 05:30:15 +02:00
$ . post ( url , data , function ( json ) {
drawShowList ( json ) ;
2013-08-29 01:37:46 +02:00
} ) ;
}
2013-07-18 07:31:20 +02:00
mod . onReady = function ( ) {
2013-08-22 20:50:58 +02:00
var oBaseDatePickerSettings ,
2013-07-18 07:31:20 +02:00
oBaseTimePickerSettings ,
2013-08-23 18:28:37 +02:00
$hisDialogEl ,
tabsInit = [
{
initialized : false ,
initialize : function ( ) {
2013-08-29 05:30:15 +02:00
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 ( ) ;
2013-08-30 00:52:40 +02:00
} ,
always : function ( ) {
inShowsTab = false ;
2013-08-30 08:31:23 +02:00
emptySelectedLogItems ( ) ;
2013-08-23 18:28:37 +02:00
}
} ,
{
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 ( ) ;
2013-08-30 00:52:40 +02:00
} ,
always : function ( ) {
inShowsTab = false ;
2013-08-30 08:31:23 +02:00
emptySelectedLogItems ( ) ;
2013-08-23 18:28:37 +02:00
}
2013-08-29 01:37:46 +02:00
} ,
{
initialized : false ,
initialize : function ( ) {
2013-08-30 00:52:40 +02:00
2013-08-29 21:17:24 +02:00
} ,
navigate : function ( ) {
2013-08-30 00:52:40 +02:00
} ,
always : function ( ) {
inShowsTab = true ;
2014-03-10 22:39:17 +01:00
var info = getStartEnd ( ) ;
showSummaryList ( info . start , info . end ) ;
2013-08-30 08:31:23 +02:00
emptySelectedLogItems ( ) ;
2013-08-29 01:37:46 +02:00
}
2013-08-23 18:28:37 +02:00
}
] ;
2013-09-24 11:47:20 +02:00
//set the locale names for the bootstrap calendar.
$ . fn . datetimepicker . dates = {
daysMin : i18n _days _short ,
months : i18n _months ,
monthsShort : i18n _months _short
} ;
2013-07-18 07:31:20 +02:00
$historyContentDiv = $ ( "#history_content" ) ;
2013-08-20 23:23:15 +02:00
function redrawTables ( ) {
2013-08-23 18:28:37 +02:00
oTableAgg && oTableAgg . fnDraw ( ) ;
oTableItem && oTableItem . fnDraw ( ) ;
2013-08-29 21:34:34 +02:00
oTableShow && oTableShow . fnDraw ( ) ;
2013-08-20 23:23:15 +02:00
}
2013-07-18 07:31:20 +02:00
function removeHistoryDialog ( ) {
$hisDialogEl . dialog ( "destroy" ) ;
$hisDialogEl . remove ( ) ;
}
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' ) ;
$startPicker . datetimepicker ( ) ;
$endPicker . datetimepicker ( {
showTimeFirst : true
} ) ;
$startPicker . on ( 'changeDate' , function ( e ) {
$endPicker . data ( 'datetimepicker' ) . setLocalDate ( e . localDate ) ;
} ) ;
}
2013-08-30 06:43:43 +02:00
function processDialogHtml ( $el ) {
2013-07-26 23:33:17 +02:00
2013-08-30 00:52:40 +02:00
if ( inShowsTab ) {
2013-08-30 06:43:43 +02:00
$el . find ( "#his_choose_instance" ) . remove ( ) ;
2013-08-30 00:52:40 +02:00
}
2013-08-30 06:43:43 +02:00
return $el
}
function makeHistoryDialog ( html ) {
$hisDialogEl = $ ( html ) ;
$hisDialogEl = processDialogHtml ( $hisDialogEl ) ;
2013-07-18 07:31:20 +02:00
$hisDialogEl . dialog ( {
title : $ . i18n . _ ( "Edit History Record" ) ,
2013-08-16 21:12:00 +02:00
modal : false ,
2013-07-26 23:33:17 +02:00
open : function ( event , ui ) {
2013-08-28 19:42:33 +02:00
initializeDialog ( ) ;
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" ) ;
} ) ;
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 ) ;
2014-03-10 23:33:07 +01:00
} ,
onClose : validateTimeRange
2013-07-18 07:31:20 +02:00
} ;
oBaseTimePickerSettings = {
showPeriodLabels : false ,
showCloseButton : true ,
closeButtonText : $ . i18n . _ ( "Done" ) ,
showLeadingZero : false ,
defaultTime : '0:00' ,
hourText : $ . i18n . _ ( "Hour" ) ,
2014-03-10 23:33:07 +01:00
minuteText : $ . i18n . _ ( "Minute" ) ,
onClose : validateTimeRange
2013-07-18 07:31:20 +02:00
} ;
2013-08-23 18:28:37 +02:00
2014-03-10 23:33:07 +01:00
$historyContentDiv . find ( dateStartId )
. datepicker ( oBaseDatePickerSettings )
. blur ( validateTimeRange ) ;
$historyContentDiv . find ( timeStartId )
. timepicker ( oBaseTimePickerSettings )
. blur ( validateTimeRange ) ;
$historyContentDiv . find ( dateEndId )
. datepicker ( oBaseDatePickerSettings )
. blur ( validateTimeRange ) ;
$historyContentDiv . find ( timeEndId )
. timepicker ( oBaseTimePickerSettings )
. blur ( validateTimeRange ) ;
2013-07-18 07:31:20 +02:00
2013-08-23 19:38:20 +02:00
$historyContentDiv . on ( "click" , "#his_create" , function ( e ) {
2013-07-24 00:01:43 +02:00
var url = baseUrl + "playouthistory/edit-list-item/format/json" ;
e . preventDefault ( ) ;
$ . get ( url , function ( json ) {
makeHistoryDialog ( json . dialog ) ;
} , "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-08-20 23:23:15 +02:00
redrawTables ( ) ;
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" ,
2013-08-30 21:03:43 +02:00
url ,
$select = $hisDialogEl . find ( "#his_instance_select" ) ,
instance ;
2013-07-23 00:11:44 +02:00
2013-07-24 00:01:43 +02:00
url = ( id === "" ) ? createUrl : updateUrl ;
2013-08-29 23:40:08 +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 ( ) ;
if ( instance > 0 ) {
data . push ( {
name : "instance_id" ,
value : instance
} ) ;
}
}
2013-07-24 00:01:43 +02:00
2013-07-23 00:11:44 +02:00
$ . post ( url , data , function ( json ) {
2013-08-23 21:52:49 +02:00
if ( json . form !== undefined ) {
var $newForm = $ ( json . form ) ;
2013-08-30 06:43:43 +02:00
$newForm = processDialogHtml ( $newForm ) ;
2013-08-23 21:52:49 +02:00
$hisDialogEl . html ( $newForm . html ( ) ) ;
2013-08-28 19:42:33 +02:00
initializeDialog ( ) ;
2013-07-23 00:11:44 +02:00
}
else {
removeHistoryDialog ( ) ;
2013-08-20 23:23:15 +02:00
redrawTables ( ) ;
2013-07-23 00:11:44 +02:00
}
} , "json" ) ;
2013-08-20 23:23:15 +02:00
} ) ;
$historyContentDiv . on ( "click" , ".his_checkbox input" , function ( e ) {
var checked = e . currentTarget . checked ,
2013-08-23 19:31:37 +02:00
$tr = $ ( e . currentTarget ) . parents ( "tr" ) ;
2013-08-20 23:23:15 +02:00
if ( checked ) {
2013-08-23 19:31:37 +02:00
addSelectedLogItem ( $tr ) ;
2013-08-20 23:23:15 +02:00
}
else {
2013-08-23 19:31:37 +02:00
removeSelectedLogItem ( $tr ) ;
2013-08-20 23:23:15 +02:00
}
} ) ;
2013-07-23 00:11:44 +02:00
2013-08-30 21:03:43 +02:00
$ ( 'body' ) . on ( "click" , "#his_instance_retrieve" , function ( e ) {
2014-03-10 23:48:40 +01:00
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" ,
2014-03-10 23:48:40 +01:00
startDate = startPicker . val ( ) ,
endDate = endPicker . val ( ) ,
2013-08-30 21:03:43 +02:00
data ;
data = {
2014-03-10 23:48:40 +01:00
start : startDate ,
end : endDate ,
2013-08-30 21:03:43 +02:00
format : "json"
} ;
$ . get ( url , data , function ( json ) {
var i ,
$select = $ ( '<select/>' , {
id : 'his_instance_select'
} ) ,
$option ,
show ;
2013-09-01 04:56:22 +02:00
2013-08-30 21:03:43 +02:00
if ( json . length > 0 ) {
for ( i = 0 ; i < json . length ; i ++ ) {
show = json [ i ] ;
$option = $ ( '<option/>' )
. text ( show . name )
. attr ( 'value' , show . instance _id ) ;
$select . append ( $option ) ;
}
}
2013-09-01 04:56:22 +02:00
$option = $ ( '<option/>' )
. text ( $ . i18n . _ ( "No Show" ) )
. attr ( 'value' , 0 ) ;
$select . append ( $option ) ;
2013-08-30 21:03:43 +02:00
$hisDialogEl . find ( "#his_instance_select" ) . replaceWith ( $select ) ;
} ) ;
} ) ;
2014-03-10 23:33:07 +01:00
function getStartEnd ( ) {
2014-03-10 22:39:17 +01:00
2014-03-10 23:33:07 +01:00
return AIRTIME . utilities . fnGetScheduleRange ( dateStartId , timeStartId , dateEndId , timeEndId ) ;
2014-03-10 22:39:17 +01:00
}
2013-07-18 07:31:20 +02:00
$historyContentDiv . find ( "#his_submit" ) . click ( function ( ev ) {
var fn ,
2014-03-10 22:39:17 +01:00
info ;
2013-07-18 07:31:20 +02:00
2014-03-10 22:39:17 +01:00
info = getStartEnd ( ) ;
2013-07-18 07:31:20 +02:00
2013-07-24 00:01:43 +02:00
fn = fnServerData ;
2014-03-10 22:39:17 +01:00
fn . start = info . start ;
fn . end = info . end ;
2013-07-18 07:31:20 +02:00
2013-08-30 07:51:33 +02:00
if ( inShowsTab ) {
2014-03-10 22:39:17 +01:00
showSummaryList ( info . start , info . end ) ;
2013-08-30 07:51:33 +02:00
}
2013-08-30 21:03:43 +02:00
else {
redrawTables ( ) ;
}
2013-08-20 23:23:15 +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 ) ;
2013-08-23 19:18:17 +02:00
$historyContentDiv . on ( "click" , "#his_trash" , function ( ev ) {
2013-08-20 23:23:15 +02:00
var items = getSelectedLogItems ( ) ,
url = baseUrl + "playouthistory/delete-list-items" ;
2013-08-30 08:24:16 +02:00
$ . post ( url , { ids : items , format : "json" } , function ( ) {
selectedLogItems = { } ;
2013-08-20 23:23:15 +02:00
redrawTables ( ) ;
} ) ;
2013-07-18 07:31:20 +02:00
} ) ;
2013-08-23 18:28:37 +02:00
$historyContentDiv . find ( "#his-tabs" ) . tabs ( {
show : function ( event , ui ) {
2013-08-29 01:37:46 +02:00
var href = $ ( ui . tab ) . attr ( "href" ) ;
var index = href . split ( '-' ) . pop ( ) ;
var tab = tabsInit [ index - 1 ] ;
2013-08-23 18:28:37 +02:00
if ( ! tab . initialized ) {
tab . initialize ( ) ;
tab . initialized = true ;
}
2013-08-29 21:17:24 +02:00
else {
tab . navigate ( ) ;
}
2013-08-30 00:52:40 +02:00
tab . always ( ) ;
2013-08-23 18:28:37 +02:00
}
} ) ;
2013-07-18 07:31:20 +02:00
2013-08-20 05:19:13 +02:00
// begin context menu initialization.
$ . contextMenu ( {
2013-08-20 20:58:22 +02:00
selector : '#history_content td:not(.his_checkbox)' ,
2013-08-20 05:19:13 +02:00
trigger : "left" ,
ignoreRightClick : true ,
build : function ( $el , e ) {
2013-08-20 20:58:22 +02:00
var items = { } ,
2013-08-20 05:19:13 +02:00
callback ,
2013-08-20 21:18:05 +02:00
$tr ,
editUrl ,
deleteUrl ;
2013-08-20 05:19:13 +02:00
$tr = $el . parents ( "tr" ) ;
2013-08-20 21:18:05 +02:00
editUrl = $tr . data ( "url-edit" ) ;
deleteUrl = $tr . data ( "url-delete" ) ;
2013-08-20 20:58:22 +02:00
if ( editUrl !== undefined ) {
callback = function ( ) {
$ . post ( editUrl , { format : "json" } , function ( json ) {
makeHistoryDialog ( json . dialog ) ;
} , "json" ) ;
} ;
2013-08-20 05:19:13 +02:00
2013-08-20 20:58:22 +02:00
items [ "edit" ] = {
"name" : $ . i18n . _ ( "Edit" ) ,
"icon" : "edit" ,
"callback" : callback
} ;
}
if ( deleteUrl !== undefined ) {
callback = function ( ) {
var c = confirm ( "Delete this entry?" ) ;
if ( c ) {
$ . post ( deleteUrl , { format : "json" } , function ( json ) {
2013-08-23 18:28:37 +02:00
redrawTables ( ) ;
2013-08-20 20:58:22 +02:00
} ) ;
}
} ;
2013-08-20 05:19:13 +02:00
2013-08-20 20:58:22 +02:00
items [ "del" ] = {
"name" : $ . i18n . _ ( "Delete" ) ,
"icon" : "delete" ,
"callback" : callback
} ;
2013-08-20 05:19:13 +02:00
}
return {
items : items
} ;
}
} ) ;
2012-03-08 18:30:56 +01:00
} ;
return AIRTIME ;
} ( AIRTIME || { } ) ) ;
2013-07-18 07:31:20 +02:00
$ ( document ) . ready ( AIRTIME . history . onReady ) ;