2012-02-16 16:29:11 +01:00
var AIRTIME = ( function ( AIRTIME ) {
2012-06-01 21:05:39 +02:00
var mod ,
oSchedTable ,
SB _SELECTED _CLASS = "sb-selected" ,
CURSOR _SELECTED _CLASS = "cursor-selected-row" ,
NOW _PLAYING _CLASS = "sb-now-playing" ,
$sbContent ,
$sbTable ,
$toolbar ,
$ul ,
2012-06-26 21:36:45 +02:00
$lib ,
cursors = [ ] ,
2012-07-03 18:42:53 +02:00
cursorIds = [ ] ,
showInstanceIds = [ ] ,
headerFooter = [ ] ;
2012-06-01 21:05:39 +02:00
if ( AIRTIME . showbuilder === undefined ) {
AIRTIME . showbuilder = { } ;
}
mod = AIRTIME . showbuilder ;
function checkError ( json ) {
if ( json . error !== undefined ) {
alert ( json . error ) ;
}
}
mod . timeout = undefined ;
mod . timestamp = - 1 ;
mod . showInstances = [ ] ;
mod . resetTimestamp = function ( ) {
mod . timestamp = - 1 ;
} ;
mod . setTimestamp = function ( timestamp ) {
mod . timestamp = timestamp ;
} ;
2013-01-11 21:37:58 +01:00
mod . updateCalendarStatusIcon = function ( json ) {
2013-01-14 20:07:32 +01:00
2013-01-14 22:00:38 +01:00
if ( window . location . pathname . toLowerCase ( ) != baseUrl + "schedule" ) {
2013-01-11 21:37:58 +01:00
return ;
}
2013-01-14 20:07:32 +01:00
2013-01-11 21:37:58 +01:00
var instance _id = json . schedule [ 0 ] . instance ;
var lastElem = json . schedule [ json . schedule . length - 1 ] ;
var $elem = $ ( $ ( ".fc-event-inner.fc-event-skin .fc-event-title#" + instance _id ) . parent ( ) ) ;
$elem . find ( ".small-icon" ) . remove ( ) ;
if ( json . schedule [ 1 ] . empty ) {
$elem
. find ( ".fc-event-title" )
. after ( '<span id="' + instance _id + '" title="' + $ . i18n . _ ( "Show is empty" ) + '" class="small-icon show-empty"></span>' ) ;
} else if ( lastElem [ "fRuntime" ] [ 0 ] == "-" ) {
$elem
. find ( ".fc-event-title" )
. after ( '<span id="' + instance _id + '" title="' + $ . i18n . _ ( "Show is partially filled" ) + '" class="small-icon show-partial-filled"></span>' ) ;
}
}
2012-06-01 21:05:39 +02:00
mod . getTimestamp = function ( ) {
if ( mod . timestamp !== undefined ) {
return mod . timestamp ;
}
else {
return - 1 ;
}
} ;
mod . setShowInstances = function ( showInstances ) {
mod . showInstances = showInstances ;
} ;
mod . getShowInstances = function ( ) {
return mod . showInstances ;
} ;
2013-02-01 23:47:07 +01:00
mod . refresh = function ( schedId ) {
2012-06-01 21:05:39 +02:00
mod . resetTimestamp ( ) ;
2013-02-01 23:47:07 +01:00
// once a track plays out we need to check if we can update
// the is_scheduled flag in cc_files
$ . post ( baseUrl + "schedule/update-future-is-scheduled" ,
2013-02-07 21:41:47 +01:00
{ "format" : "json" , "schedId" : schedId } , function ( data ) {
2013-02-06 19:25:48 +01:00
if ( data . redrawLibTable !== undefined && data . redrawLibTable ) {
2013-02-01 23:47:07 +01:00
$ ( "#library_content" ) . find ( "#library_display" ) . dataTable ( ) . fnStandingRedraw ( ) ;
}
} ) ;
2012-06-01 21:05:39 +02:00
oSchedTable . fnDraw ( ) ;
} ;
mod . checkSelectButton = function ( ) {
var $selectable = $sbTable . find ( "tbody" ) . find ( "input:checkbox" ) ;
if ( $selectable . length !== 0 ) {
2012-09-18 17:05:13 +02:00
AIRTIME . button . enableButton ( "btn-group #timeline-select" , false ) ;
2012-06-01 21:05:39 +02:00
}
else {
2012-09-18 17:05:13 +02:00
AIRTIME . button . disableButton ( "btn-group #timeline-select" , false ) ;
2012-06-01 21:05:39 +02:00
}
2012-09-17 18:10:23 +02:00
//need to check if the 'Select' button is disabled
if ( $ ( ".btn-group #timeline-select" ) . is ( ":disabled" ) ) {
$ ( ".btn-group #timeline-select" ) . removeAttr ( "disabled" ) ;
}
2012-06-01 21:05:39 +02:00
} ;
mod . checkTrimButton = function ( ) {
var $over = $sbTable . find ( ".sb-over.sb-allowed" ) ;
if ( $over . length !== 0 ) {
2012-09-13 23:10:38 +02:00
AIRTIME . button . enableButton ( "icon-cut" , true ) ;
2012-06-01 21:05:39 +02:00
}
else {
2012-09-13 23:10:38 +02:00
AIRTIME . button . disableButton ( "icon-cut" , true ) ;
2012-06-01 21:05:39 +02:00
}
} ;
mod . checkDeleteButton = function ( ) {
var $selected = $sbTable . find ( "tbody" ) . find ( "input:checkbox" ) . filter ( ":checked" ) ;
if ( $selected . length !== 0 ) {
2012-09-13 23:10:38 +02:00
AIRTIME . button . enableButton ( "icon-trash" , true ) ;
2012-06-01 21:05:39 +02:00
}
else {
2012-09-13 23:10:38 +02:00
AIRTIME . button . disableButton ( "icon-trash" , true ) ;
2012-06-01 21:05:39 +02:00
}
} ;
mod . checkJumpToCurrentButton = function ( ) {
var $current = $sbTable . find ( "." + NOW _PLAYING _CLASS ) ;
if ( $current . length !== 0 ) {
2012-09-13 23:10:38 +02:00
AIRTIME . button . enableButton ( "icon-step-forward" , true ) ;
2012-06-01 21:05:39 +02:00
}
else {
2012-09-13 23:10:38 +02:00
AIRTIME . button . disableButton ( "icon-step-forward" , true ) ;
2012-06-01 21:05:39 +02:00
}
} ;
mod . checkCancelButton = function ( ) {
2012-09-18 01:28:28 +02:00
var $current = $sbTable . find ( ".sb-current-show" ) ,
2012-06-01 21:05:39 +02:00
//this user type should be refactored into a separate users module later
//when there's more time and more JS will need to know user data.
2012-09-18 01:28:28 +02:00
userType = localStorage . getItem ( 'user-type' ) ,
canCancel = false ;
2012-06-01 21:05:39 +02:00
2012-09-18 01:28:28 +02:00
if ( $current . length !== 0 && $current . hasClass ( "sb-allowed" ) ) {
canCancel = true ;
}
else if ( $current . length !== 0 && ( userType === 'A' || userType === 'P' ) ) {
canCancel = true ;
}
if ( canCancel === true ) {
AIRTIME . button . enableButton ( "icon-ban-circle" , true ) ;
2012-06-01 21:05:39 +02:00
}
else {
2012-09-18 01:28:28 +02:00
AIRTIME . button . disableButton ( "icon-ban-circle" , true ) ;
2012-06-01 21:05:39 +02:00
}
} ;
mod . checkToolBarIcons = function ( ) {
AIRTIME . library . checkAddButton ( ) ;
mod . checkSelectButton ( ) ;
mod . checkTrimButton ( ) ;
mod . checkDeleteButton ( ) ;
mod . checkJumpToCurrentButton ( ) ;
mod . checkCancelButton ( ) ;
2012-04-27 15:44:40 +02:00
} ;
2012-05-23 12:18:51 +02:00
mod . selectCursor = function ( $el ) {
2012-06-26 21:36:45 +02:00
2012-06-01 21:05:39 +02:00
$el . addClass ( CURSOR _SELECTED _CLASS ) ;
mod . checkToolBarIcons ( ) ;
2012-05-23 12:18:51 +02:00
} ;
mod . removeCursor = function ( $el ) {
2012-06-01 21:05:39 +02:00
$el . removeClass ( CURSOR _SELECTED _CLASS ) ;
mod . checkToolBarIcons ( ) ;
2012-05-23 12:18:51 +02:00
} ;
2012-06-01 21:05:39 +02:00
2012-05-23 17:06:04 +02:00
/ *
* sNot is an optional string to filter selected elements by . ( ex removing the currently playing item )
* /
2012-06-01 21:05:39 +02:00
mod . getSelectedData = function ( sNot ) {
var $selected = $sbTable . find ( "tbody" ) . find ( "input:checkbox" ) . filter ( ":checked" ) . parents ( "tr" ) ,
aData = [ ] ,
i , length ,
$item ;
if ( sNot !== undefined ) {
$selected = $selected . not ( "." + sNot ) ;
}
for ( i = 0 , length = $selected . length ; i < length ; i ++ ) {
$item = $ ( $selected . get ( i ) ) ;
aData . push ( $item . data ( 'aData' ) ) ;
}
return aData . reverse ( ) ;
2012-04-02 19:03:11 +02:00
} ;
mod . selectAll = function ( ) {
2012-06-01 21:05:39 +02:00
$inputs = $sbTable . find ( "input:checkbox" ) ;
$inputs . attr ( "checked" , true ) ;
$trs = $inputs . parents ( "tr" ) ;
$trs . addClass ( SB _SELECTED _CLASS ) ;
mod . checkToolBarIcons ( ) ;
2012-04-02 19:03:11 +02:00
} ;
mod . selectNone = function ( ) {
2012-06-01 21:05:39 +02:00
$inputs = $sbTable . find ( "input:checkbox" ) ;
$inputs . attr ( "checked" , false ) ;
$trs = $inputs . parents ( "tr" ) ;
$trs . removeClass ( SB _SELECTED _CLASS ) ;
mod . checkToolBarIcons ( ) ;
2012-04-02 19:03:11 +02:00
} ;
2012-05-03 15:04:23 +02:00
2012-05-04 15:00:18 +02:00
mod . disableUI = function ( ) {
2012-06-01 21:05:39 +02:00
$lib . block ( {
2012-05-04 15:00:18 +02:00
message : "" ,
theme : true ,
applyPlatformOpacityRules : false
} ) ;
2012-06-01 21:05:39 +02:00
$sbContent . block ( {
2012-05-04 15:00:18 +02:00
message : "" ,
theme : true ,
applyPlatformOpacityRules : false
} ) ;
} ;
mod . enableUI = function ( ) {
2012-06-01 21:05:39 +02:00
$lib . unblock ( ) ;
$sbContent . unblock ( ) ;
//Block UI changes the postion to relative to display the messages.
$lib . css ( "position" , "static" ) ;
$sbContent . css ( "position" , "static" ) ;
2012-05-04 15:00:18 +02:00
} ;
2012-05-03 15:04:23 +02:00
mod . fnItemCallback = function ( json ) {
2012-06-01 21:05:39 +02:00
checkError ( json ) ;
2012-06-27 23:19:55 +02:00
2013-01-31 17:28:54 +01:00
mod . getSelectedCursors ( ) ;
2012-07-04 00:22:48 +02:00
oSchedTable . fnDraw ( ) ;
2013-01-31 17:28:54 +01:00
2012-07-04 00:22:48 +02:00
mod . enableUI ( ) ;
2013-01-31 17:28:54 +01:00
$ ( "#library_content" ) . find ( "#library_display" ) . dataTable ( ) . fnStandingRedraw ( ) ;
2012-07-04 00:22:48 +02:00
} ;
mod . getSelectedCursors = function ( ) {
2012-06-27 21:50:56 +02:00
cursorIds = [ ] ;
2012-07-03 18:42:53 +02:00
2012-06-28 23:55:17 +02:00
/ * W e n e e d t o k e e p r e c o r d o f w h i c h s h o w t h e c u r s o r b e l o n g s t o
* in the case where more than one show is displayed in the show builder
* because header and footer rows have the same id
* /
showInstanceIds = [ ] ;
2012-07-03 18:42:53 +02:00
/ * K e e p s t r a c k i f t h e r o w i s a f o o t e r . W e n e e d t o d o t h i s b e c a u s e
* header and footer rows have the save cursorIds and showInstanceId
* so both will be selected in the draw callback
* /
headerFooter = [ ] ;
2012-06-26 21:36:45 +02:00
cursors = $ ( ".cursor-selected-row" ) ;
for ( i = 0 ; i < cursors . length ; i ++ ) {
cursorIds . push ( ( $ ( cursors . get ( i ) ) . attr ( "id" ) ) ) ;
2012-06-28 23:55:17 +02:00
showInstanceIds . push ( ( $ ( cursors . get ( i ) ) . attr ( "si_id" ) ) ) ;
2012-07-03 18:42:53 +02:00
if ( $ ( cursors . get ( i ) ) . hasClass ( "sb-footer" ) ) {
headerFooter . push ( "f" ) ;
} else {
headerFooter . push ( "n" ) ;
}
2012-06-26 21:36:45 +02:00
}
2012-06-01 21:05:39 +02:00
} ;
2012-06-26 21:36:45 +02:00
2012-06-01 21:05:39 +02:00
mod . fnAdd = function ( aMediaIds , aSchedIds ) {
mod . disableUI ( ) ;
2013-01-14 22:00:38 +01:00
$ . post ( baseUrl + "showbuilder/schedule-add" ,
2012-06-01 21:05:39 +02:00
{ "format" : "json" , "mediaIds" : aMediaIds , "schedIds" : aSchedIds } ,
mod . fnItemCallback
) ;
} ;
mod . fnMove = function ( aSelect , aAfter ) {
mod . disableUI ( ) ;
2013-01-14 22:00:38 +01:00
$ . post ( baseUrl + "showbuilder/schedule-move" ,
2012-06-01 21:05:39 +02:00
{ "format" : "json" , "selectedItem" : aSelect , "afterItem" : aAfter } ,
mod . fnItemCallback
) ;
2012-05-03 15:04:23 +02:00
} ;
2012-06-01 21:05:39 +02:00
mod . fnRemove = function ( aItems ) {
mod . disableUI ( ) ;
2012-11-20 17:16:10 +01:00
if ( confirm ( $ . i18n . _ ( "Delete selected item(s)?" ) ) ) {
2013-01-14 22:00:38 +01:00
$ . post ( baseUrl + "showbuilder/schedule-remove" ,
2012-06-26 23:43:15 +02:00
{ "items" : aItems , "format" : "json" } ,
mod . fnItemCallback
) ;
} else {
mod . enableUI ( ) ;
}
2012-06-01 21:05:39 +02:00
} ;
mod . fnRemoveSelectedItems = function ( ) {
var aData = mod . getSelectedData ( ) ,
i ,
length ,
temp ,
aItems = [ ] ;
2012-04-02 19:03:11 +02:00
2012-06-01 21:05:39 +02:00
for ( i = 0 , length = aData . length ; i < length ; i ++ ) {
temp = aData [ i ] ;
aItems . push ( { "id" : temp . id , "instance" : temp . instance , "timestamp" : temp . timestamp } ) ;
}
mod . fnRemove ( aItems ) ;
} ;
mod . fnServerData = function fnBuilderServerData ( sSource , aoData , fnCallback ) {
2012-07-26 20:41:09 +02:00
2012-06-01 21:05:39 +02:00
aoData . push ( { name : "timestamp" , value : mod . getTimestamp ( ) } ) ;
aoData . push ( { name : "instances" , value : mod . getShowInstances ( ) } ) ;
aoData . push ( { name : "format" , value : "json" } ) ;
if ( mod . fnServerData . hasOwnProperty ( "start" ) ) {
aoData . push ( { name : "start" , value : mod . fnServerData . start } ) ;
}
if ( mod . fnServerData . hasOwnProperty ( "end" ) ) {
aoData . push ( { name : "end" , value : mod . fnServerData . end } ) ;
}
if ( mod . fnServerData . hasOwnProperty ( "ops" ) ) {
aoData . push ( { name : "myShows" , value : mod . fnServerData . ops . myShows } ) ;
aoData . push ( { name : "showFilter" , value : mod . fnServerData . ops . showFilter } ) ;
}
$ . ajax ( {
"dataType" : "json" ,
"type" : "POST" ,
"url" : sSource ,
"data" : aoData ,
"success" : function ( json ) {
2013-01-11 21:37:58 +01:00
mod . updateCalendarStatusIcon ( json )
2012-06-01 21:05:39 +02:00
mod . setTimestamp ( json . timestamp ) ;
mod . setShowInstances ( json . instances ) ;
2012-07-04 00:22:48 +02:00
mod . getSelectedCursors ( ) ;
2012-06-01 21:05:39 +02:00
fnCallback ( json ) ;
}
} ) ;
} ;
2012-10-29 20:20:16 +01:00
mod . jumpToCurrentTrack = function ( ) {
var $scroll = $sbContent . find ( ".dataTables_scrolling" ) ;
var scrolled = $scroll . scrollTop ( ) ;
var scrollingTop = $scroll . offset ( ) . top ;
var oTable = $ ( '#show_builder_table' ) . dataTable ( ) ;
var current = $sbTable . find ( "." + NOW _PLAYING _CLASS ) ;
var currentTop = current . offset ( ) . top ;
$scroll . scrollTop ( currentTop - scrollingTop + scrolled ) ;
}
2012-06-01 21:05:39 +02:00
mod . builderDataTable = function ( ) {
$sbContent = $ ( '#show_builder' ) ;
$lib = $ ( "#library_content" ) ,
$sbTable = $sbContent . find ( 'table' ) ;
2012-10-29 20:20:16 +01:00
var isInitialized = false ;
2012-06-01 21:05:39 +02:00
oSchedTable = $sbTable . dataTable ( {
"aoColumns" : [
/* checkbox */ { "mDataProp" : "allowed" , "sTitle" : "" , "sWidth" : "15px" , "sClass" : "sb-checkbox" } ,
2012-03-26 12:31:35 +02:00
/* Type */ { "mDataProp" : "image" , "sTitle" : "" , "sClass" : "library_image sb-image" , "sWidth" : "16px" } ,
2012-11-20 17:16:10 +01:00
/* starts */ { "mDataProp" : "starts" , "sTitle" : $ . i18n . _ ( "Start" ) , "sClass" : "sb-starts" , "sWidth" : "60px" } ,
/* ends */ { "mDataProp" : "ends" , "sTitle" : $ . i18n . _ ( "End" ) , "sClass" : "sb-ends" , "sWidth" : "60px" } ,
/* runtime */ { "mDataProp" : "runtime" , "sTitle" : $ . i18n . _ ( "Duration" ) , "sClass" : "library_length sb-length" , "sWidth" : "65px" } ,
/* title */ { "mDataProp" : "title" , "sTitle" : $ . i18n . _ ( "Title" ) , "sClass" : "sb-title" } ,
/* creator */ { "mDataProp" : "creator" , "sTitle" : $ . i18n . _ ( "Creator" ) , "sClass" : "sb-creator" } ,
/* album */ { "mDataProp" : "album" , "sTitle" : $ . i18n . _ ( "Album" ) , "sClass" : "sb-album" } ,
/* cue in */ { "mDataProp" : "cuein" , "sTitle" : $ . i18n . _ ( "Cue In" ) , "bVisible" : false , "sClass" : "sb-cue-in" } ,
/* cue out */ { "mDataProp" : "cueout" , "sTitle" : $ . i18n . _ ( "Cue Out" ) , "bVisible" : false , "sClass" : "sb-cue-out" } ,
/* fade in */ { "mDataProp" : "fadein" , "sTitle" : $ . i18n . _ ( "Fade In" ) , "bVisible" : false , "sClass" : "sb-fade-in" } ,
/* fade out */ { "mDataProp" : "fadeout" , "sTitle" : $ . i18n . _ ( "Fade Out" ) , "bVisible" : false , "sClass" : "sb-fade-out" } ,
/* Mime */ { "mDataProp" : "mime" , "sTitle" : $ . i18n . _ ( "Mime" ) , "bVisible" : false , "sClass" : "sb-mime" }
2012-06-01 21:05:39 +02:00
] ,
"bJQueryUI" : true ,
"bSort" : false ,
"bFilter" : false ,
"bProcessing" : true ,
"bServerSide" : true ,
"bInfo" : false ,
"bAutoWidth" : false ,
"bStateSave" : true ,
"fnStateSaveParams" : function ( oSettings , oData ) {
//remove oData components we don't want to save.
delete oData . oSearch ;
delete oData . aoSearchCols ;
} ,
"fnStateSave" : function fnStateSave ( oSettings , oData ) {
localStorage . setItem ( 'datatables-timeline' , JSON . stringify ( oData ) ) ;
$ . ajax ( {
2013-01-14 22:00:38 +01:00
url : baseUrl + "usersettings/set-timeline-datatable" ,
2012-06-01 21:05:39 +02:00
type : "POST" ,
data : { settings : oData , format : "json" } ,
dataType : "json"
} ) ;
} ,
"fnStateLoad" : function fnBuilderStateLoad ( oSettings ) {
var settings = localStorage . getItem ( 'datatables-timeline' ) ;
if ( settings !== "" ) {
return JSON . parse ( settings ) ;
}
} ,
"fnStateLoadParams" : function ( oSettings , oData ) {
var i ,
length ,
a = oData . abVisCols ;
//putting serialized data back into the correct js type to make
//sure everything works properly.
for ( i = 0 , length = a . length ; i < length ; i ++ ) {
if ( typeof ( a [ i ] ) === "string" ) {
a [ i ] = ( a [ i ] === "true" ) ? true : false ;
}
}
a = oData . ColReorder ;
for ( i = 0 , length = a . length ; i < length ; i ++ ) {
if ( typeof ( a [ i ] ) === "string" ) {
a [ i ] = parseInt ( a [ i ] , 10 ) ;
}
}
oData . iCreate = parseInt ( oData . iCreate , 10 ) ;
} ,
"fnServerData" : mod . fnServerData ,
"fnRowCallback" : function fnRowCallback ( nRow , aData , iDisplayIndex , iDisplayIndexFull ) {
var i , length ,
sSeparatorHTML ,
fnPrepareSeparatorRow ,
$node ,
cl = "" ,
//background-color to imitate calendar color.
r , g , b , a ,
$nRow = $ ( nRow ) ,
$image ,
$div ,
headerIcon ;
fnPrepareSeparatorRow = function fnPrepareSeparatorRow ( sRowContent , sClass , iNodeIndex ) {
$node = $ ( nRow . children [ iNodeIndex ] ) ;
$node . html ( sRowContent ) ;
$node . attr ( 'colspan' , 100 ) ;
for ( i = iNodeIndex + 1 , length = nRow . children . length ; i < length ; i = i + 1 ) {
$node = $ ( nRow . children [ i ] ) ;
$node . html ( "" ) ;
$node . attr ( "style" , "display : none" ) ;
}
$nRow . addClass ( sClass ) ;
} ;
2012-06-26 21:36:45 +02:00
2012-06-01 21:05:39 +02:00
if ( aData . header === true ) {
//remove the column classes from all tds.
$nRow . find ( 'td' ) . removeClass ( ) ;
$node = $ ( nRow . children [ 0 ] ) ;
$node . html ( "" ) ;
cl = 'sb-header' ;
if ( aData . record === true ) {
headerIcon = ( aData . soundcloud _id > 0 ) ? "soundcloud" : "recording" ;
$div = $ ( "<div/>" , {
"class" : "small-icon " + headerIcon
} ) ;
$node . append ( $div ) ;
}
else if ( aData . rebroadcast === true ) {
$div = $ ( "<div/>" , {
"class" : "small-icon rebroadcast"
} ) ;
$node . append ( $div ) ;
}
sSeparatorHTML = '<span class="show-title">' + aData . title + '</span>' ;
if ( aData . rebroadcast === true ) {
sSeparatorHTML += '<span>' + aData . rebroadcast _title + '</span>' ;
}
sSeparatorHTML += '<span class="push-right">' ;
if ( aData . startDate === aData . endDate ) {
sSeparatorHTML += '<span class="show-date">' + aData . startDate + '</span><span class="show-time">' + aData . startTime + '</span>' ;
sSeparatorHTML += '-<span class="show-time">' + aData . endTime + '</span>' ;
}
else {
sSeparatorHTML += '<span class="show-date">' + aData . startDate + '</span><span class="show-time">' + aData . startTime + '</span>' ;
sSeparatorHTML += '-<span class="show-date">' + aData . endDate + '</span><span class="show-time">' + aData . endTime + '</span>' ;
}
sSeparatorHTML += '</span>' ;
fnPrepareSeparatorRow ( sSeparatorHTML , cl , 1 ) ;
}
else if ( aData . footer === true ) {
//remove the column classes from all tds.
$nRow . find ( 'td' ) . removeClass ( ) ;
$node = $ ( nRow . children [ 0 ] ) ;
cl = 'sb-footer' ;
//check the show's content status.
if ( aData . runtime > 0 ) {
$node . html ( '<span class="ui-icon ui-icon-check"></span>' ) ;
cl = cl + ' ui-state-highlight' ;
}
else {
$node . html ( '<span class="ui-icon ui-icon-notice"></span>' ) ;
cl = cl + ' ui-state-error' ;
}
sSeparatorHTML = '<span>' + aData . fRuntime + '</span>' ;
fnPrepareSeparatorRow ( sSeparatorHTML , cl , 1 ) ;
}
else if ( aData . empty === true ) {
//remove the column classes from all tds.
$nRow . find ( 'td' ) . removeClass ( ) ;
$node = $ ( nRow . children [ 0 ] ) ;
$node . html ( '' ) ;
2012-11-20 17:16:10 +01:00
sSeparatorHTML = '<span>' + $ . i18n . _ ( "Show Empty" ) + '</span>' ;
2012-06-01 21:05:39 +02:00
cl = cl + " sb-empty odd" ;
fnPrepareSeparatorRow ( sSeparatorHTML , cl , 1 ) ;
}
else if ( aData . record === true ) {
//remove the column classes from all tds.
$nRow . find ( 'td' ) . removeClass ( ) ;
$node = $ ( nRow . children [ 0 ] ) ;
$node . html ( '' ) ;
2012-11-20 17:16:10 +01:00
sSeparatorHTML = '<span>' + $ . i18n . _ ( "Recording From Line In" ) + '</span>' ;
2012-06-01 21:05:39 +02:00
cl = cl + " sb-record odd" ;
fnPrepareSeparatorRow ( sSeparatorHTML , cl , 1 ) ;
}
else {
//add the play function if the file exists on disk.
$image = $nRow . find ( 'td.sb-image' ) ;
//check if the file exists.
if ( aData . image === true ) {
2012-11-01 21:44:37 +01:00
$nRow . addClass ( "lib-audio" ) ;
if ( ! isAudioSupported ( aData . mime ) ) {
$image . html ( '<span class="ui-icon ui-icon-locked"></span>' ) ;
} else {
2013-01-14 22:00:38 +01:00
$image . html ( '<img title="' + $ . i18n . _ ( "Track preview" ) + '" src="' + baseUrl + 'css/images/icon_audioclip.png"></img>' )
2012-06-01 21:05:39 +02:00
. click ( function ( ) {
open _show _preview ( aData . instance , aData . pos ) ;
return false ;
} ) ;
2012-11-01 21:44:37 +01:00
}
2012-06-01 21:05:39 +02:00
}
else {
$image . html ( '<span class="ui-icon ui-icon-alert"></span>' ) ;
2012-06-01 21:10:22 +02:00
$image . find ( ".ui-icon-alert" ) . qtip ( {
content : {
2012-11-20 17:16:10 +01:00
text : $ . i18n . _ ( "Airtime is unsure about the status of this file. This can happen when the file is on a remote drive that is unaccessible or the file is in a directory that isn't \"watched\" anymore." )
2012-06-01 21:10:22 +02:00
} ,
style : {
classes : "ui-tooltip-dark"
} ,
show : 'mouseover' ,
hide : 'mouseout'
} ) ;
2012-06-01 21:05:39 +02:00
}
$node = $ ( nRow . children [ 0 ] ) ;
if ( aData . allowed === true && aData . scheduled >= 1 ) {
$node . html ( '<input type="checkbox" name="' + aData . id + '"></input>' ) ;
}
else {
$node . html ( '' ) ;
}
}
//add the show colour to the leftmost td
2012-03-22 18:04:22 +01:00
if ( aData . footer !== true ) {
2012-06-01 21:05:39 +02:00
if ( $nRow . hasClass ( 'sb-header' ) ) {
a = 1 ;
}
else if ( $nRow . hasClass ( 'odd' ) ) {
a = 0.3 ;
}
else if ( $nRow . hasClass ( 'even' ) ) {
a = 0.4 ;
}
//convert from hex to rgb.
r = parseInt ( ( aData . backgroundColor ) . substring ( 0 , 2 ) , 16 ) ;
g = parseInt ( ( aData . backgroundColor ) . substring ( 2 , 4 ) , 16 ) ;
b = parseInt ( ( aData . backgroundColor ) . substring ( 4 , 6 ) , 16 ) ;
$nRow . find ( 'td:first' ) . css ( 'background' , 'rgba(' + r + ', ' + g + ', ' + b + ', ' + a + ')' ) ;
2012-03-22 18:04:22 +01:00
}
2012-03-27 12:44:48 +02:00
//save some info for reordering purposes.
2012-06-01 21:05:39 +02:00
$nRow . data ( { "aData" : aData } ) ;
if ( aData . scheduled === 1 ) {
$nRow . addClass ( NOW _PLAYING _CLASS ) ;
}
else if ( aData . scheduled === 0 ) {
$nRow . addClass ( "sb-past" ) ;
}
else {
$nRow . addClass ( "sb-future" ) ;
}
2012-06-29 22:59:03 +02:00
if ( aData . allowed !== true ) {
2012-06-01 21:05:39 +02:00
$nRow . addClass ( "sb-not-allowed" ) ;
}
else {
$nRow . addClass ( "sb-allowed" ) ;
2012-06-27 23:19:55 +02:00
$nRow . attr ( "id" , aData . id ) ;
2012-06-28 23:55:17 +02:00
$nRow . attr ( "si_id" , aData . instance ) ;
2012-06-01 21:05:39 +02:00
}
//status used to colour tracks.
if ( aData . status === 2 ) {
$nRow . addClass ( "sb-boundry" ) ;
}
else if ( aData . status === 0 ) {
$nRow . addClass ( "sb-over" ) ;
}
if ( aData . currentShow === true ) {
$nRow . addClass ( "sb-current-show" ) ;
}
2012-06-27 23:19:55 +02:00
2012-03-27 12:44:48 +02:00
//call the context menu so we can prevent the event from propagating.
2012-05-03 15:04:23 +02:00
$nRow . find ( 'td:gt(1)' ) . click ( function ( e ) {
2012-03-27 12:44:48 +02:00
$ ( this ) . contextMenu ( { x : e . pageX , y : e . pageY } ) ;
return false ;
} ) ;
2012-06-01 21:05:39 +02:00
} ,
//remove any selected nodes before the draw.
"fnPreDrawCallback" : function ( oSettings ) {
//make sure any dragging helpers are removed or else they'll be stranded on the screen.
$ ( "#draggingContainer" ) . remove ( ) ;
} ,
"fnDrawCallback" : function fnBuilderDrawCallback ( oSettings , json ) {
2012-10-30 20:34:38 +01:00
var isInitialized = false ;
2012-10-29 20:20:16 +01:00
if ( ! isInitialized ) {
2012-10-30 16:18:11 +01:00
//when coming to 'Now Playing' page we want the page
//to jump to the current track
2012-10-29 20:40:58 +01:00
if ( $ ( this ) . find ( "." + NOW _PLAYING _CLASS ) . length > 0 ) {
mod . jumpToCurrentTrack ( ) ;
}
2012-10-29 20:20:16 +01:00
}
isInitialized = true ;
2012-06-01 21:05:39 +02:00
var wrapperDiv ,
markerDiv ,
$td ,
aData ,
elements ,
i , length , temp ,
$cursorRows ,
$table = $ ( this ) ,
$parent = $table . parent ( ) ,
2012-06-26 21:36:45 +02:00
$tr ,
2012-06-01 21:05:39 +02:00
//use this array to cache DOM heights then we can detach the table to manipulate it to increase speed.
heights = [ ] ;
clearTimeout ( mod . timeout ) ;
//only create the cursor arrows if the library is on the page.
if ( $lib . length > 0 && $lib . filter ( ":visible" ) . length > 0 ) {
2012-04-16 16:33:32 +02:00
2012-06-01 21:05:39 +02:00
$cursorRows = $sbTable . find ( "tbody tr.sb-future.sb-allowed:not(.sb-header, .sb-empty)" ) ;
//need to get heights of tds while elements are still in the DOM.
for ( i = 0 , length = $cursorRows . length ; i < length ; i ++ ) {
$td = $ ( $cursorRows . get ( i ) ) . find ( "td:first" ) ;
heights . push ( $td . height ( ) ) ;
}
//detach the table to increase speed.
$table . detach ( ) ;
for ( i = 0 , length = $cursorRows . length ; i < length ; i ++ ) {
$td = $ ( $cursorRows . get ( i ) ) . find ( "td:first" ) ;
if ( $td . hasClass ( "dataTables_empty" ) ) {
$parent . append ( $table ) ;
return false ;
}
wrapperDiv = $ ( "<div />" , {
"class" : "innerWrapper" ,
"css" : {
"height" : heights [ i ]
}
} ) ;
markerDiv = $ ( "<div />" , {
"class" : "marker"
} ) ;
$td . append ( markerDiv ) . wrapInner ( wrapperDiv ) ;
2012-06-26 21:36:45 +02:00
}
//re-highlight selected cursors before draw took place
for ( i = 0 ; i < cursorIds . length ; i ++ ) {
2012-07-03 18:42:53 +02:00
if ( headerFooter [ i ] == "f" ) {
2012-07-03 20:52:27 +02:00
$tr = $table . find ( "tbody tr.sb-footer[id=" + cursorIds [ i ] + "][si_id=" + showInstanceIds [ i ] + "]" ) ;
2012-07-03 18:42:53 +02:00
} else {
$tr = $table . find ( "tr[id=" + cursorIds [ i ] + "][si_id=" + showInstanceIds [ i ] + "]" ) ;
}
2012-06-29 21:49:22 +02:00
/ * I f t h e c u r r e n t l y p l a y i n g t r a c k ' s c u r s o r i s s e l e c t e d ,
* and that track is deleted , the cursor position becomes
* unavailble . We have to check the position is available
* before re - highlighting it .
2012-07-03 17:48:57 +02:00
* /
2012-06-29 21:49:22 +02:00
if ( $tr . find ( ".sb-checkbox" ) . children ( ) . hasClass ( "innerWrapper" ) ) {
mod . selectCursor ( $tr ) ;
2012-07-03 17:48:57 +02:00
2012-07-03 18:42:53 +02:00
/ * I f t h e s e l e c t e d c u r s o r i s t h e f o o t e r r o w w e n e e d t o
* explicitly select it because that row does not have
2012-07-03 17:48:57 +02:00
* innerWrapper class
* /
2012-07-03 18:42:53 +02:00
} else if ( $tr . hasClass ( "sb-footer" ) ) {
2012-07-03 17:48:57 +02:00
mod . selectCursor ( $tr ) ;
2012-06-29 21:49:22 +02:00
}
2012-06-01 21:05:39 +02:00
}
//if there is only 1 cursor on the page highlight it by default.
if ( $cursorRows . length === 1 ) {
$td = $cursorRows . find ( "td:first" ) ;
if ( ! $td . hasClass ( "dataTables_empty" ) ) {
$cursorRows . addClass ( "cursor-selected-row" ) ;
}
}
$parent . append ( $table ) ;
}
//order of importance of elements for setting the next timeout.
elements = [
$sbTable . find ( "tr." + NOW _PLAYING _CLASS ) ,
$sbTable . find ( "tbody" ) . find ( "tr.sb-future.sb-footer, tr.sb-future.sb-header" ) . filter ( ":first" )
] ;
//check which element we should set a timeout relative to.
for ( i = 0 , length = elements . length ; i < length ; i ++ ) {
temp = elements [ i ] ;
if ( temp . length > 0 ) {
aData = temp . data ( "aData" ) ;
2012-06-26 22:55:43 +02:00
// max time interval
2012-06-27 17:50:31 +02:00
// setTimeout allows only up to (2^31)-1 millisecs timeout value
2012-06-26 22:55:43 +02:00
maxRefreshInterval = Math . pow ( 2 , 31 ) - 1 ;
refreshInterval = aData . refresh * 1000 ;
if ( refreshInterval > maxRefreshInterval ) {
refreshInterval = maxRefreshInterval ;
}
2013-02-01 23:47:07 +01:00
mod . timeout = setTimeout ( function ( ) { mod . refresh ( aData . id ) } , refreshInterval ) ; //need refresh in milliseconds
2012-06-01 21:05:39 +02:00
break ;
}
}
mod . checkToolBarIcons ( ) ;
} ,
"oColVis" : {
"aiExclude" : [ 0 , 1 ]
} ,
"oColReorder" : {
"iFixedColumns" : 2
} ,
// R = ColReorderResize, C = ColVis
"sDom" : 'R<"dt-process-rel"r><"sb-padded"<"H"C>><"dataTables_scrolling sb-padded"t>' ,
"sAjaxDataProp" : "schedule" ,
2012-11-27 21:51:50 +01:00
"oLanguage" : datatables _dict ,
2013-01-14 22:00:38 +01:00
"sAjaxSource" : baseUrl + "showbuilder/builder-feed"
2012-06-01 21:05:39 +02:00
} ) ;
$sbTable . find ( "tbody" ) . on ( "click" , "input:checkbox" , function ( ev ) {
var $cb = $ ( this ) ,
$tr = $cb . parents ( "tr" ) ,
$prev ;
if ( $cb . is ( ":checked" ) ) {
if ( ev . shiftKey ) {
$prev = $sbTable . find ( "tbody" ) . find ( "tr." + SB _SELECTED _CLASS ) . eq ( - 1 ) ;
$prev . nextUntil ( $tr )
. addClass ( SB _SELECTED _CLASS )
. find ( "input:checkbox" )
. attr ( "checked" , true )
. end ( ) ;
}
$tr . addClass ( SB _SELECTED _CLASS ) ;
}
else {
$tr . removeClass ( SB _SELECTED _CLASS ) ;
}
mod . checkToolBarIcons ( ) ;
2012-04-02 19:03:11 +02:00
} ) ;
2012-06-01 21:05:39 +02:00
var sortableConf = ( function ( ) {
var origTrs ,
aItemData = [ ] ,
oPrevData ,
fnAdd ,
fnMove ,
fnReceive ,
fnUpdate ,
i ,
html ,
helperData ,
draggingContainer ;
fnAdd = function ( ) {
var aMediaIds = [ ] ,
aSchedIds = [ ] ;
for ( i = 0 ; i < aItemData . length ; i ++ ) {
aMediaIds . push ( { "id" : aItemData [ i ] . id , "type" : aItemData [ i ] . ftype } ) ;
}
aSchedIds . push ( { "id" : oPrevData . id , "instance" : oPrevData . instance , "timestamp" : oPrevData . timestamp } ) ;
mod . fnAdd ( aMediaIds , aSchedIds ) ;
} ;
fnMove = function ( ) {
var aSelect = [ ] ,
aAfter = [ ] ;
for ( i = 0 ; i < helperData . length ; i ++ ) {
aSelect . push ( { "id" : helperData [ i ] . id , "instance" : helperData [ i ] . instance , "timestamp" : helperData [ i ] . timestamp } ) ;
}
aAfter . push ( { "id" : oPrevData . id , "instance" : oPrevData . instance , "timestamp" : oPrevData . timestamp } ) ;
mod . fnMove ( aSelect , aAfter ) ;
} ;
fnReceive = function ( event , ui ) {
var aItems = [ ] ;
AIRTIME . library . addToChosen ( ui . item ) ;
aItems = AIRTIME . library . getSelectedData ( ) ;
origTrs = aItems ;
html = ui . helper . html ( ) ;
AIRTIME . library . removeFromChosen ( ui . item ) ;
} ;
fnUpdate = function ( event , ui ) {
var prev = ui . item . prev ( ) ;
//can't add items outside of shows.
if ( prev . find ( "td:first" ) . hasClass ( "dataTables_empty" )
|| prev . length === 0 ) {
2012-11-20 17:16:10 +01:00
alert ( $ . i18n . _ ( "Cannot schedule outside a show." ) ) ;
2012-06-01 21:05:39 +02:00
ui . item . remove ( ) ;
return ;
}
//if item is added after a footer, add the item after the last item in the show.
if ( prev . hasClass ( "sb-footer" ) ) {
prev = prev . prev ( ) ;
}
aItemData = [ ] ;
oPrevData = prev . data ( "aData" ) ;
//item was dragged in
if ( origTrs !== undefined ) {
$sbTable . find ( "tr.ui-draggable" )
. empty ( )
. after ( html ) ;
aItemData = origTrs ;
origTrs = undefined ;
fnAdd ( ) ;
}
//item was reordered.
else {
ui . item
. empty ( )
. after ( draggingContainer . html ( ) ) ;
aItemData . push ( ui . item . data ( "aData" ) ) ;
fnMove ( ) ;
}
} ;
return {
placeholder : "sb-placeholder ui-state-highlight" ,
forcePlaceholderSize : true ,
distance : 10 ,
helper : function ( event , item ) {
var selected = mod . getSelectedData ( NOW _PLAYING _CLASS ) ,
thead = $ ( "#show_builder_table thead" ) ,
colspan = thead . find ( "th" ) . length ,
trfirst = thead . find ( "tr:first" ) ,
width = trfirst . width ( ) ,
height = trfirst . height ( ) ,
message ;
//if nothing is checked select the dragged item.
if ( selected . length === 0 ) {
selected = [ item . data ( "aData" ) ] ;
}
if ( selected . length === 1 ) {
2012-11-20 23:42:26 +01:00
message = $ . i18n . _ ( "Moving 1 Item" ) ;
2012-06-01 21:05:39 +02:00
}
else {
2012-11-20 23:42:26 +01:00
message = sprintf ( $ . i18n . _ ( "Moving %s Items" ) , selected . length ) ;
2012-06-01 21:05:39 +02:00
}
draggingContainer = $ ( '<tr/>' )
. addClass ( 'sb-helper' )
. append ( '<td/>' )
. find ( "td" )
. attr ( "colspan" , colspan )
. width ( width )
. height ( height )
. addClass ( "ui-state-highlight" )
. append ( message )
. end ( ) ;
2012-03-20 17:55:35 +01:00
2012-06-01 21:05:39 +02:00
helperData = selected ;
return draggingContainer ;
} ,
2012-06-29 22:59:03 +02:00
items : 'tr:not(:first, :last, .sb-header, .sb-not-allowed, .sb-past, .sb-now-playing, .sb-empty)' ,
2012-06-01 21:05:39 +02:00
cancel : '.sb-footer' ,
receive : fnReceive ,
update : fnUpdate ,
start : function ( event , ui ) {
/ *
var elements = $sbTable . find ( 'tr input:checked' ) . parents ( 'tr' )
. not ( ui . item )
. not ( "." + NOW _PLAYING _CLASS ) ;
//remove all other items from the screen,
//don't remove ui.item or else we can not get position information when the user drops later.
elements . remove ( ) ;
* /
var elements = $sbTable . find ( 'tr input:checked' ) . parents ( 'tr' ) . not ( "." + NOW _PLAYING _CLASS ) ;
elements . hide ( ) ;
}
} ;
} ( ) ) ;
$sbTable . sortable ( sortableConf ) ;
//start setup of the builder toolbar.
$toolbar = $ ( ".sb-content .fg-toolbar" ) ;
2012-09-13 23:10:38 +02:00
$menu = $ ( "<div class='btn-toolbar'/>" ) ;
$menu . append ( "<div class='btn-group'>" +
"<button class='btn btn-small dropdown-toggle' id='timeline-select' data-toggle='dropdown'>" +
2012-11-20 17:16:10 +01:00
$ . i18n . _ ( "Select" ) + " <span class='caret'></span>" +
2012-09-13 23:10:38 +02:00
"</button>" +
"<ul class='dropdown-menu'>" +
2012-11-20 17:16:10 +01:00
"<li id='timeline-sa'><a href='#'>" + $ . i18n . _ ( "Select all" ) + "</a></li>" +
"<li id='timeline-sn'><a href='#'>" + $ . i18n . _ ( "Select none" ) + "</a></li>" +
2012-09-13 23:10:38 +02:00
"</ul>" +
"</div>" )
. append ( "<div class='btn-group'>" +
2012-11-20 17:16:10 +01:00
"<button title='" + $ . i18n . _ ( "Remove overbooked tracks" ) + "' class='ui-state-disabled btn btn-small' disabled='disabled'>" +
2012-09-13 23:10:38 +02:00
"<i class='icon-white icon-cut'></i></button></div>" )
. append ( "<div class='btn-group'>" +
2012-11-20 17:16:10 +01:00
"<button title='" + $ . i18n . _ ( "Remove selected scheduled items" ) + "' class='ui-state-disabled btn btn-small' disabled='disabled'>" +
2012-10-30 16:18:11 +01:00
"<i class='icon-white icon-trash'></i></button></div>" ) ;
//if 'Add/Remove content' was chosen from the context menu
//in the Calendar do not append these buttons
if ( $ ( ".ui-dialog-content" ) . length === 0 ) {
$menu . append ( "<div class='btn-group'>" +
2012-11-20 17:16:10 +01:00
"<button title='" + $ . i18n . _ ( "Jump to the current playing track" ) + "' class='ui-state-disabled btn btn-small' disabled='disabled'>" +
2012-09-13 23:10:38 +02:00
"<i class='icon-white icon-step-forward'></i></button></div>" )
. append ( "<div class='btn-group'>" +
2012-11-20 17:16:10 +01:00
"<button title='" + $ . i18n . _ ( "Cancel current show" ) + "' class='ui-state-disabled btn btn-small btn-danger' disabled='disabled'>" +
2012-09-13 23:10:38 +02:00
"<i class='icon-white icon-ban-circle'></i></button></div>" ) ;
2012-10-30 16:18:11 +01:00
}
2012-09-13 23:10:38 +02:00
$toolbar . append ( $menu ) ;
$menu = undefined ;
2012-06-01 21:05:39 +02:00
2012-09-13 23:10:38 +02:00
$ ( '#timeline-sa' ) . click ( function ( ) { mod . selectAll ( ) ; } ) ;
$ ( '#timeline-sn' ) . click ( function ( ) { mod . selectNone ( ) ; } ) ;
2012-06-01 21:05:39 +02:00
2012-09-13 23:10:38 +02:00
//cancel current show
2012-09-17 18:30:43 +02:00
$toolbar . find ( '.icon-ban-circle' ) . parent ( )
2012-06-01 21:05:39 +02:00
. click ( function ( ) {
var $tr ,
data ,
2012-11-20 17:16:10 +01:00
msg = $ . i18n . _ ( 'Cancel Current Show?' ) ;
2012-06-01 21:05:39 +02:00
2012-09-18 16:53:19 +02:00
if ( AIRTIME . button . isDisabled ( 'icon-ban-circle' , true ) === true ) {
2012-06-01 21:05:39 +02:00
return ;
}
$tr = $sbTable . find ( 'tr.sb-future:first' ) ;
if ( $tr . hasClass ( 'sb-current-show' ) ) {
data = $tr . data ( "aData" ) ;
if ( data . record === true ) {
2012-11-20 17:16:10 +01:00
msg = $ . i18n . _ ( 'Stop recording current show?' ) ;
2012-06-01 21:05:39 +02:00
}
if ( confirm ( msg ) ) {
2013-01-14 22:00:38 +01:00
var url = baseUrl + "Schedule/cancel-current-show" ;
2012-06-01 21:05:39 +02:00
$ . ajax ( {
url : url ,
data : { format : "json" , id : data . instance } ,
success : function ( data ) {
var oTable = $sbTable . dataTable ( ) ;
oTable . fnDraw ( ) ;
}
} ) ;
}
}
} ) ;
//jump to current
2012-09-17 18:30:43 +02:00
$toolbar . find ( '.icon-step-forward' ) . parent ( )
2012-06-01 21:05:39 +02:00
. click ( function ( ) {
2012-09-18 16:53:19 +02:00
if ( AIRTIME . button . isDisabled ( 'icon-step-forward' , true ) === true ) {
2012-06-01 21:05:39 +02:00
return ;
}
2012-10-29 20:20:16 +01:00
/ *
2012-06-01 21:05:39 +02:00
var $scroll = $sbContent . find ( ".dataTables_scrolling" ) ,
scrolled = $scroll . scrollTop ( ) ,
scrollingTop = $scroll . offset ( ) . top ,
current = $sbTable . find ( "." + NOW _PLAYING _CLASS ) ,
currentTop = current . offset ( ) . top ;
$scroll . scrollTop ( currentTop - scrollingTop + scrolled ) ;
2012-10-29 20:20:16 +01:00
* /
mod . jumpToCurrentTrack ( ) ;
2012-06-01 21:05:39 +02:00
} ) ;
//delete overbooked tracks.
2012-09-18 16:53:19 +02:00
$toolbar . find ( '.icon-cut' , true ) . parent ( )
2012-06-01 21:05:39 +02:00
. click ( function ( ) {
2012-09-18 16:53:19 +02:00
if ( AIRTIME . button . isDisabled ( 'icon-cut' , true ) === true ) {
2012-06-01 21:05:39 +02:00
return ;
}
var temp ,
aItems = [ ] ,
trs = $sbTable . find ( ".sb-over.sb-future.sb-allowed" ) ;
trs . each ( function ( ) {
temp = $ ( this ) . data ( "aData" ) ;
aItems . push ( { "id" : temp . id , "instance" : temp . instance , "timestamp" : temp . timestamp } ) ;
} ) ;
mod . fnRemove ( aItems ) ;
} ) ;
//delete selected tracks
2012-09-17 18:27:17 +02:00
$toolbar . find ( '.icon-trash' ) . parent ( )
2012-06-01 21:05:39 +02:00
. click ( function ( ) {
2012-09-18 16:53:19 +02:00
if ( AIRTIME . button . isDisabled ( 'icon-trash' , true ) === true ) {
2012-06-01 21:05:39 +02:00
return ;
}
mod . fnRemoveSelectedItems ( ) ;
} ) ;
//add events to cursors.
$sbTable . find ( "tbody" ) . on ( "click" , "div.marker" , function ( event ) {
var $tr = $ ( this ) . parents ( "tr" ) ,
$trs ;
if ( $tr . hasClass ( CURSOR _SELECTED _CLASS ) ) {
mod . removeCursor ( $tr ) ;
}
else {
mod . selectCursor ( $tr ) ;
}
if ( event . ctrlKey === false ) {
$trs = $sbTable . find ( '.' + CURSOR _SELECTED _CLASS ) . not ( $tr ) ;
mod . removeCursor ( $trs ) ;
}
return false ;
} ) ;
2012-09-17 17:58:05 +02:00
/ *
2012-09-18 17:05:13 +02:00
* Select button dropdown state in the toolbar .
* The button has to be disabled to prevent the dropdown
* from opening
2012-09-17 17:58:05 +02:00
* /
$sbContent . on ( "mouseenter" , ".btn-group #timeline-select" , function ( ev ) {
2012-09-18 17:05:13 +02:00
$el = $ ( this ) ;
2012-09-17 17:58:05 +02:00
if ( $el . hasClass ( "ui-state-disabled" ) ) {
2012-09-18 17:05:13 +02:00
$el . attr ( "disabled" , "disabled" ) ;
2012-09-17 17:58:05 +02:00
}
else {
2012-09-18 17:05:13 +02:00
$el . removeAttr ( "disabled" ) ;
2012-09-17 17:58:05 +02:00
}
} ) ;
2012-06-01 21:05:39 +02:00
//begin context menu initialization.
2012-03-15 16:11:29 +01:00
$ . contextMenu ( {
2012-05-07 15:24:06 +02:00
selector : '.sb-content table tbody tr:not(.sb-empty, .sb-footer, .sb-header, .sb-record) td:not(.sb-checkbox, .sb-image)' ,
2012-03-15 16:11:29 +01:00
trigger : "left" ,
ignoreRightClick : true ,
2012-03-15 22:56:51 +01:00
2012-03-15 16:11:29 +01:00
build : function ( $el , e ) {
2012-03-27 17:47:21 +02:00
var items ,
2012-06-01 21:05:39 +02:00
$tr = $el . parent ( ) ,
data = $tr . data ( "aData" ) ,
cursorClass = "cursor-selected-row" ,
callback ;
2012-03-27 17:47:21 +02:00
2012-03-15 16:11:29 +01:00
function processMenuItems ( oItems ) {
2012-06-01 21:05:39 +02:00
//define a preview callback.
2012-03-27 18:27:58 +02:00
if ( oItems . preview !== undefined ) {
callback = function ( ) {
2012-06-01 21:05:39 +02:00
open _show _preview ( data . instance , data . pos ) ;
2012-03-27 18:27:58 +02:00
} ;
oItems . preview . callback = callback ;
}
2012-06-01 21:05:39 +02:00
//define a select cursor callback.
2012-03-27 15:46:25 +02:00
if ( oItems . selCurs !== undefined ) {
callback = function ( ) {
2012-06-01 21:05:39 +02:00
var $tr = $ ( this ) . parents ( 'tr' ) . next ( ) ;
mod . selectCursor ( $tr ) ;
2012-03-27 15:46:25 +02:00
} ;
oItems . selCurs . callback = callback ;
}
2012-03-27 18:27:58 +02:00
//define a remove cursor callback.
2012-03-27 15:46:25 +02:00
if ( oItems . delCurs !== undefined ) {
callback = function ( ) {
2012-06-01 21:05:39 +02:00
var $tr = $ ( this ) . parents ( 'tr' ) . next ( ) ;
mod . removeCursor ( $tr ) ;
2012-03-27 15:46:25 +02:00
} ;
oItems . delCurs . callback = callback ;
}
2012-03-15 22:56:51 +01:00
2012-03-15 16:11:29 +01:00
//define a delete callback.
if ( oItems . del !== undefined ) {
callback = function ( ) {
2012-07-10 19:08:36 +02:00
AIRTIME . showbuilder . fnRemove ( [ {
id : data . id ,
timestamp : data . timestamp ,
instance : data . instance
} ] ) ;
2012-03-15 16:11:29 +01:00
} ;
oItems . del . callback = callback ;
}
2012-03-27 17:47:21 +02:00
//only show the cursor selecting options if the library is visible on the page.
2012-03-27 18:27:58 +02:00
if ( $tr . next ( ) . find ( '.marker' ) . length === 0 ) {
2012-06-01 21:05:39 +02:00
delete oItems . selCurs ;
delete oItems . delCurs ;
2012-03-27 17:47:21 +02:00
}
2012-06-01 21:05:39 +02:00
//check to include either select or remove cursor.
2012-03-27 17:47:21 +02:00
else {
2012-06-01 21:05:39 +02:00
if ( $tr . next ( ) . hasClass ( cursorClass ) ) {
delete oItems . selCurs ;
}
else {
delete oItems . delCurs ;
}
}
2012-03-15 16:11:29 +01:00
items = oItems ;
2012-03-15 22:56:51 +01:00
}
2012-03-15 16:11:29 +01:00
request = $ . ajax ( {
2013-01-14 22:00:38 +01:00
url : baseUrl + "showbuilder/context-menu" ,
2012-03-15 16:11:29 +01:00
type : "GET" ,
data : { id : data . id , format : "json" } ,
dataType : "json" ,
async : false ,
success : function ( json ) {
processMenuItems ( json . items ) ;
}
} ) ;
2012-05-07 15:24:06 +02:00
2012-06-01 21:05:39 +02:00
return {
2012-03-15 16:11:29 +01:00
items : items
} ;
2012-05-07 15:24:06 +02:00
2012-03-15 22:56:51 +01:00
}
2012-10-29 20:20:16 +01:00
} ) ;
2012-06-01 21:05:39 +02:00
} ;
return AIRTIME ;
} ( AIRTIME || { } ) ) ;