From 8aea86b451613a44a6fa4f7cdcd0dac564cb269a Mon Sep 17 00:00:00 2001 From: Duncan Sommerville Date: Thu, 30 Apr 2015 16:23:52 -0400 Subject: [PATCH] SAAS-744 - Updated double click and Add button functionality on Now Playing and Add/Remove content screens --- .../js/airtime/dashboard/helperfunctions.js | 18 +++++++ .../library/events/library_showbuilder.js | 52 ++++++++++++++++--- .../public/js/airtime/library/library.js | 4 +- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/airtime_mvc/public/js/airtime/dashboard/helperfunctions.js b/airtime_mvc/public/js/airtime/dashboard/helperfunctions.js index bccef632b..ad156dfe8 100644 --- a/airtime_mvc/public/js/airtime/dashboard/helperfunctions.js +++ b/airtime_mvc/public/js/airtime/dashboard/helperfunctions.js @@ -213,3 +213,21 @@ function resizeToMaxHeight(ele, targetHeight){ img.css("width", newWidth+"px"); } } + +/* From http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport/#7557433 */ +function isInView(el) { + //special bonus for those using jQuery + if (typeof jQuery === "function" && el instanceof jQuery) { + el = el[0]; + } + + var rect = el.getBoundingClientRect(); + + return ( + rect.top >= 0 && + rect.left >= 0 && + rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */ + rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ + ); +} + diff --git a/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js b/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js index 75a100b8a..315caf986 100644 --- a/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js +++ b/airtime_mvc/public/js/airtime/library/events/library_showbuilder.js @@ -8,20 +8,31 @@ var AIRTIME = (function(AIRTIME) { mod = AIRTIME.library; mod.checkAddButton = function() { - var selected = mod.getChosenItemsLength(), $cursor = $('tr.sb-selected'), check = false; + var selected = mod.getChosenItemsLength(), $cursor = $('tr.sb-selected'), check = false, + shows = $('tr.sb-header'), current = $('tr.sb-current-show'), + cursorText = $.i18n._('Add to next show'); // make sure library items are selected and a cursor is selected. - if (selected !== 0 && $cursor.length !== 0) { + if (selected !== 0) { check = true; } + if (shows.length === 0) { + check = false; + } + if (check === true) { AIRTIME.button.enableButton("btn-group #library-plus", false); } else { AIRTIME.button.disableButton("btn-group #library-plus", false); } - - AIRTIME.library.changeAddButtonText($('.btn-group #library-plus #lib-plus-text'), ' '+$.i18n._('Add to selected show')); + + if ($cursor.length !== 0) { + cursorText = $.i18n._('Add before selected items'); + } else if (current.length !== 0) { + cursorText = $.i18n._('Add to current show'); + } + AIRTIME.library.changeAddButtonText($('.btn-group #library-plus #lib-plus-text'), ' '+ cursorText); }; mod.fnRowCallback = function(nRow, aData, iDisplayIndex, iDisplayIndexFull) { @@ -98,7 +109,7 @@ var AIRTIME = (function(AIRTIME) { "type" : type }); - $("#show_builder_table tr.cursor-selected-row").each(function(i, el) { + $("#show_builder_table tr.sb-selected").each(function(i, el) { aData.push($(el).prev().data("aData")); }); @@ -113,12 +124,35 @@ var AIRTIME = (function(AIRTIME) { } if (aSchedIds.length == 0) { - alert($.i18n._("Please select a cursor position on timeline.")); - return false; + addToCurrentOrNext(aSchedIds); } + AIRTIME.showbuilder.fnAdd(aMediaIds, aSchedIds); }; + function addToCurrentOrNext(arr) { + var el; + // Get the show instance id of the first non-data row (id = 0) + // The second last row in the table with that instance id is the + // last schedule item for the first show. (This is important for + // the Now Playing screen if multiple shows are in view). + el = $("[si_id="+$("#0").attr("si_id")+"]"); + var temp = el.eq(-2).data("aData"); + arr.push({ + "id" : temp.id, + "instance" : temp.instance, + "timestamp" : temp.timestamp + }); + + if (!isInView(el)) { + $('.dataTables_scrolling.sb-padded').animate({ + scrollTop: el.offset().top + }, 0); + } + + return arr; + } + mod.setupLibraryToolbar = function() { var $toolbar = $(".lib-content .fg-toolbar:first"); @@ -161,6 +195,10 @@ var AIRTIME = (function(AIRTIME) { "timestamp" : temp.timestamp }); } + + if (aSchedIds.length == 0) { + addToCurrentOrNext(aSchedIds); + } AIRTIME.showbuilder.fnAdd(aMediaIds, aSchedIds); }); diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index ae223171a..dae2d916e 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -109,7 +109,7 @@ var AIRTIME = (function(AIRTIME) { mod.changeAddButtonText = function($button, btnText) { $button.text(btnText); - } + }; mod.createToolbarButtons = function() { $menu = $("
"); @@ -135,7 +135,7 @@ var AIRTIME = (function(AIRTIME) { "" + "" + "
"); - } + }; mod.createToolbarDropDown = function() { $('#sb-select-page').click(function(){mod.selectCurrentPage();});