CC-3715 : Library- carry over selected state between pages, be like gmail include select all/none
This commit is contained in:
parent
2c84420424
commit
b9e13d3b08
5 changed files with 141 additions and 75 deletions
|
@ -5,11 +5,10 @@ var AIRTIME = (function(AIRTIME){
|
||||||
AIRTIME.library = {};
|
AIRTIME.library = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
AIRTIME.library.events = {};
|
mod = AIRTIME.library;
|
||||||
mod = AIRTIME.library.events;
|
|
||||||
|
|
||||||
mod.enableAddButtonCheck = function() {
|
mod.checkAddButton = function() {
|
||||||
var selected = $('#library_display tr[id ^= "au"] input[type=checkbox]').filter(":checked"),
|
var selected = mod.getChosenItemsLength(),
|
||||||
sortable = $('#spl_sortable'),
|
sortable = $('#spl_sortable'),
|
||||||
check = false;
|
check = false;
|
||||||
|
|
||||||
|
@ -36,6 +35,9 @@ var AIRTIME = (function(AIRTIME){
|
||||||
|
|
||||||
mod.fnDrawCallback = function() {
|
mod.fnDrawCallback = function() {
|
||||||
|
|
||||||
|
mod.redrawChosen();
|
||||||
|
mod.checkToolBarIcons();
|
||||||
|
|
||||||
$('#library_display tr[id ^= "au"]').draggable({
|
$('#library_display tr[id ^= "au"]').draggable({
|
||||||
helper: function(){
|
helper: function(){
|
||||||
var selected = $('#library_display tr:not(:first) input:checked').parents('tr[id^="au"]'),
|
var selected = $('#library_display tr:not(:first) input:checked').parents('tr[id^="au"]'),
|
||||||
|
|
|
@ -5,16 +5,15 @@ var AIRTIME = (function(AIRTIME){
|
||||||
AIRTIME.library = {};
|
AIRTIME.library = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
AIRTIME.library.events = {};
|
mod = AIRTIME.library;
|
||||||
mod = AIRTIME.library.events;
|
|
||||||
|
|
||||||
mod.enableAddButtonCheck = function() {
|
mod.checkAddButton = function() {
|
||||||
var selected = $('#library_display tr input[type=checkbox]').filter(":checked"),
|
var selected = mod.getChosenItemsLength(),
|
||||||
cursor = $('tr.cursor-selected-row'),
|
cursor = $('tr.cursor-selected-row'),
|
||||||
check = false;
|
check = false;
|
||||||
|
|
||||||
//make sure library items are selected and a cursor is selected.
|
//make sure library items are selected and a cursor is selected.
|
||||||
if (selected.length !== 0 && cursor.length !== 0) {
|
if (mod.chosenItems.length !== 0 && cursor.length !== 0) {
|
||||||
check = true;
|
check = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +35,9 @@ var AIRTIME = (function(AIRTIME){
|
||||||
|
|
||||||
mod.fnDrawCallback = function fnLibDrawCallback() {
|
mod.fnDrawCallback = function fnLibDrawCallback() {
|
||||||
|
|
||||||
|
mod.redrawChosen();
|
||||||
|
mod.checkToolBarIcons();
|
||||||
|
|
||||||
$('#library_display tr:not(:first)').draggable({
|
$('#library_display tr:not(:first)').draggable({
|
||||||
helper: function(){
|
helper: function(){
|
||||||
var selected = $('#library_display tr:not(:first) input:checked').parents('tr'),
|
var selected = $('#library_display tr:not(:first) input:checked').parents('tr'),
|
||||||
|
@ -73,7 +75,7 @@ var AIRTIME = (function(AIRTIME){
|
||||||
},
|
},
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
connectToSortable: '#show_builder_table'
|
connectToSortable: '#show_builder_table'
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
mod.setupLibraryToolbar = function() {
|
mod.setupLibraryToolbar = function() {
|
||||||
|
|
|
@ -4,38 +4,128 @@ var AIRTIME = (function(AIRTIME) {
|
||||||
oTable,
|
oTable,
|
||||||
$libContent,
|
$libContent,
|
||||||
$libTable,
|
$libTable,
|
||||||
LIB_SELECTED_CLASS = "lib-selected";
|
LIB_SELECTED_CLASS = "lib-selected",
|
||||||
|
chosenItems = {};
|
||||||
|
|
||||||
if (AIRTIME.library === undefined) {
|
if (AIRTIME.library === undefined) {
|
||||||
AIRTIME.library = {};
|
AIRTIME.library = {};
|
||||||
}
|
}
|
||||||
mod = AIRTIME.library;
|
mod = AIRTIME.library;
|
||||||
|
|
||||||
mod.getSelectedData = function() {
|
mod.getChosenItemsLength = function(){
|
||||||
var $selected = $libTable.find("tbody").find("input:checkbox").filter(":checked").parents("tr"),
|
var selected = Object.keys(chosenItems).length;
|
||||||
aData = [],
|
|
||||||
i, length,
|
|
||||||
$item;
|
|
||||||
|
|
||||||
for (i = 0, length = $selected.length; i < length; i++) {
|
return selected;
|
||||||
$item = $($selected.get(i));
|
};
|
||||||
aData.push($item.data('aData'));
|
|
||||||
|
mod.checkDeleteButton = function() {
|
||||||
|
var selected = mod.getChosenItemsLength(),
|
||||||
|
check = false;
|
||||||
|
|
||||||
|
if (selected !== 0) {
|
||||||
|
check = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return aData.reverse();
|
if (check === true) {
|
||||||
|
AIRTIME.button.enableButton("lib-button-delete");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AIRTIME.button.disableButton("lib-button-delete");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
mod.selectAll = function () {
|
mod.checkToolBarIcons = function() {
|
||||||
$libTable.find("input:checkbox").attr("checked", true);
|
|
||||||
};
|
|
||||||
|
|
||||||
mod.selectNone = function () {
|
|
||||||
$libTable.find("input:checkbox").attr("checked", false);
|
|
||||||
$libTable.find("tr").removeClass(LIB_SELECTED_CLASS);
|
|
||||||
|
|
||||||
//disable all lib buttons.
|
AIRTIME.library.checkAddButton();
|
||||||
AIRTIME.button.disableButton("lib-button-delete");
|
AIRTIME.library.checkDeleteButton();
|
||||||
AIRTIME.button.disableButton("lib-button-add");
|
};
|
||||||
|
|
||||||
|
mod.getSelectedData = function() {
|
||||||
|
var id,
|
||||||
|
data = [];
|
||||||
|
|
||||||
|
for (id in chosenItems) {
|
||||||
|
|
||||||
|
if (chosenItems.hasOwnProperty(id)) {
|
||||||
|
data.push(chosenItems[id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
mod.redrawChosen = function() {
|
||||||
|
var ids = Object.keys(chosenItems),
|
||||||
|
i, length,
|
||||||
|
$el;
|
||||||
|
|
||||||
|
for (i = 0, length = ids.length; i < length; i++) {
|
||||||
|
$el = $libTable.find("#"+ids[i]);
|
||||||
|
|
||||||
|
if ($el.length !== 0) {
|
||||||
|
mod.highlightItem($el);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
mod.highlightItem = function($el) {
|
||||||
|
var $input = $el.find("input");
|
||||||
|
|
||||||
|
$input.attr("checked", true);
|
||||||
|
$el.addClass(LIB_SELECTED_CLASS);
|
||||||
|
};
|
||||||
|
|
||||||
|
mod.selectItem = function($el) {
|
||||||
|
var id;
|
||||||
|
|
||||||
|
mod.highlightItem($el);
|
||||||
|
|
||||||
|
id = $el.attr("id");
|
||||||
|
chosenItems[id] = $el.data('aData');
|
||||||
|
|
||||||
|
mod.checkToolBarIcons();
|
||||||
|
};
|
||||||
|
|
||||||
|
mod.deselectItem = function($el) {
|
||||||
|
var id,
|
||||||
|
$input = $el.find("input");
|
||||||
|
|
||||||
|
$input.attr("checked", false);
|
||||||
|
$el.removeClass(LIB_SELECTED_CLASS);
|
||||||
|
|
||||||
|
id = $el.attr("id");
|
||||||
|
delete chosenItems[id];
|
||||||
|
|
||||||
|
mod.checkToolBarIcons();
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* select all selects all items which the user can currently see.
|
||||||
|
* (behaviour taken from gmail)
|
||||||
|
*/
|
||||||
|
mod.selectAll = function () {
|
||||||
|
var $trs = $libTable.find("tbody input:checkbox").parents("tr");
|
||||||
|
|
||||||
|
$trs.each(function(i, el){
|
||||||
|
$el = $(this);
|
||||||
|
|
||||||
|
mod.selectItem($el);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* select none deselects all items that the user can currently see.
|
||||||
|
* (behaviour taken from gmail)
|
||||||
|
*/
|
||||||
|
mod.selectNone = function () {
|
||||||
|
|
||||||
|
var $trs = $libTable.find("tbody input:checkbox").filter(":checked").parents("tr");
|
||||||
|
|
||||||
|
$trs.each(function(i, el){
|
||||||
|
$el = $(this);
|
||||||
|
|
||||||
|
mod.deselectItem($el);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
mod.fnDeleteItems = function(aMedia) {
|
mod.fnDeleteItems = function(aMedia) {
|
||||||
|
@ -181,7 +271,7 @@ var AIRTIME = (function(AIRTIME) {
|
||||||
"success": fnCallback
|
"success": fnCallback
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
"fnRowCallback": AIRTIME.library.events.fnRowCallback,
|
"fnRowCallback": AIRTIME.library.fnRowCallback,
|
||||||
"fnCreatedRow": function( nRow, aData, iDataIndex ) {
|
"fnCreatedRow": function( nRow, aData, iDataIndex ) {
|
||||||
|
|
||||||
//add the play function to the library_type td
|
//add the play function to the library_type td
|
||||||
|
@ -248,10 +338,8 @@ var AIRTIME = (function(AIRTIME) {
|
||||||
//remove any selected nodes before the draw.
|
//remove any selected nodes before the draw.
|
||||||
"fnPreDrawCallback": function( oSettings ) {
|
"fnPreDrawCallback": function( oSettings ) {
|
||||||
|
|
||||||
AIRTIME.button.disableButton("lib-button-delete");
|
|
||||||
AIRTIME.button.disableButton("lib-button-add");
|
|
||||||
},
|
},
|
||||||
"fnDrawCallback": AIRTIME.library.events.fnDrawCallback,
|
"fnDrawCallback": AIRTIME.library.fnDrawCallback,
|
||||||
"fnHeaderCallback": function(nHead) {
|
"fnHeaderCallback": function(nHead) {
|
||||||
$(nHead).find("input[type=checkbox]").attr("checked", false);
|
$(nHead).find("input[type=checkbox]").attr("checked", false);
|
||||||
},
|
},
|
||||||
|
@ -283,7 +371,7 @@ var AIRTIME = (function(AIRTIME) {
|
||||||
|
|
||||||
$libContent.find(".dataTables_scrolling").css("max-height", tableHeight);
|
$libContent.find(".dataTables_scrolling").css("max-height", tableHeight);
|
||||||
|
|
||||||
AIRTIME.library.events.setupLibraryToolbar(oTable);
|
AIRTIME.library.setupLibraryToolbar(oTable);
|
||||||
|
|
||||||
$("#library_display_type")
|
$("#library_display_type")
|
||||||
.addClass("dataTables_type")
|
.addClass("dataTables_type")
|
||||||
|
@ -298,63 +386,38 @@ var AIRTIME = (function(AIRTIME) {
|
||||||
});
|
});
|
||||||
|
|
||||||
$libTable.find('[name="pl_cb_all"]').click(function() {
|
$libTable.find('[name="pl_cb_all"]').click(function() {
|
||||||
var $cbs = $libTable.find("input:checkbox"),
|
|
||||||
$trs;
|
|
||||||
|
|
||||||
if ($(this).is(":checked")) {
|
if ($(this).is(":checked")) {
|
||||||
$cbs.attr("checked", true);
|
|
||||||
//checking to enable buttons
|
|
||||||
|
|
||||||
$trs = $cbs.parents("tr");
|
AIRTIME.library.selectAll();
|
||||||
$trs.addClass(LIB_SELECTED_CLASS);
|
|
||||||
|
|
||||||
AIRTIME.button.enableButton("lib-button-delete");
|
|
||||||
AIRTIME.library.events.enableAddButtonCheck();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$cbs.attr("checked", false);
|
AIRTIME.library.selectNone();
|
||||||
|
|
||||||
$trs = $cbs.parents("tr");
|
|
||||||
$trs.removeClass(LIB_SELECTED_CLASS);
|
|
||||||
|
|
||||||
AIRTIME.button.disableButton("lib-button-delete");
|
|
||||||
AIRTIME.button.disableButton("lib-button-add");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$libTable.find("tbody").on("click", "input[type=checkbox]", function(ev) {
|
$libTable.find("tbody").on("click", "input[type=checkbox]", function(ev) {
|
||||||
|
|
||||||
var $cb = $(this),
|
var $cb = $(this),
|
||||||
$selectedCb,
|
|
||||||
$prev,
|
$prev,
|
||||||
$tr = $cb.parents("tr");
|
$tr = $cb.parents("tr"),
|
||||||
|
$trs;
|
||||||
|
|
||||||
if ($cb.is(":checked")) {
|
if ($cb.is(":checked")) {
|
||||||
|
|
||||||
if (ev.shiftKey) {
|
if (ev.shiftKey) {
|
||||||
$prev = $libTable.find("tbody").find("tr."+LIB_SELECTED_CLASS).eq(-1);
|
$prev = $libTable.find("tbody").find("tr."+LIB_SELECTED_CLASS).eq(-1);
|
||||||
|
$trs = $prev.nextUntil($tr);
|
||||||
|
|
||||||
$prev.nextUntil($tr)
|
$trs.each(function(i, el){
|
||||||
.addClass(LIB_SELECTED_CLASS)
|
mod.selectItem($(el));
|
||||||
.find("input:checkbox")
|
});
|
||||||
.attr("checked", true)
|
|
||||||
.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$tr.addClass(LIB_SELECTED_CLASS);
|
mod.selectItem($tr);
|
||||||
//checking to enable buttons
|
|
||||||
AIRTIME.button.enableButton("lib-button-delete");
|
|
||||||
AIRTIME.library.events.enableAddButtonCheck();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$selectedCb = $libTable.find("tbody input:checkbox").filter(":checked");
|
mod.deselectItem($tr);
|
||||||
$tr.removeClass(LIB_SELECTED_CLASS);
|
|
||||||
|
|
||||||
//checking to disable buttons
|
|
||||||
if ($selectedCb.length === 0) {
|
|
||||||
AIRTIME.button.disableButton("lib-button-delete");
|
|
||||||
}
|
|
||||||
AIRTIME.library.events.enableAddButtonCheck();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -275,9 +275,9 @@ var AIRTIME = (function(AIRTIME){
|
||||||
}
|
}
|
||||||
|
|
||||||
function redrawLib() {
|
function redrawLib() {
|
||||||
var dt = $("#library_display").dataTable();
|
var dt = $lib.find("#library_display").dataTable();
|
||||||
|
|
||||||
dt.fnStandingRedraw();
|
dt.fnDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPlaylistContent(json) {
|
function setPlaylistContent(json) {
|
||||||
|
|
|
@ -79,7 +79,6 @@ var AIRTIME = (function(AIRTIME){
|
||||||
function(json){
|
function(json){
|
||||||
checkError(json);
|
checkError(json);
|
||||||
oSchedTable.fnDraw();
|
oSchedTable.fnDraw();
|
||||||
AIRTIME.library.selectNone();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -541,7 +540,7 @@ var AIRTIME = (function(AIRTIME){
|
||||||
AIRTIME.button.enableButton("sb-button-cancel");
|
AIRTIME.button.enableButton("sb-button-cancel");
|
||||||
}
|
}
|
||||||
|
|
||||||
AIRTIME.library.events.enableAddButtonCheck();
|
AIRTIME.library.checkAddButton();
|
||||||
},
|
},
|
||||||
"fnHeaderCallback": function(nHead) {
|
"fnHeaderCallback": function(nHead) {
|
||||||
$(nHead).find("input[type=checkbox]").attr("checked", false);
|
$(nHead).find("input[type=checkbox]").attr("checked", false);
|
||||||
|
@ -876,7 +875,7 @@ var AIRTIME = (function(AIRTIME){
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if add button can still be enabled.
|
//check if add button can still be enabled.
|
||||||
AIRTIME.library.events.enableAddButtonCheck();
|
AIRTIME.library.checkAddButton();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue