diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php
index c3d2bfa6e..baa8f2d33 100644
--- a/airtime_mvc/application/controllers/PlaylistController.php
+++ b/airtime_mvc/application/controllers/PlaylistController.php
@@ -176,6 +176,7 @@ class PlaylistController extends Zend_Controller_Action
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColVis.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.ColReorder.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.FixedColumns.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
+ $this->view->headScript()->appendFile($baseUrl.'/js/datatables/plugin/dataTables.columnFilter.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
$this->view->headScript()->appendFile($baseUrl.'/js/airtime/utilities/utilities.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
diff --git a/airtime_mvc/application/models/Datatables.php b/airtime_mvc/application/models/Datatables.php
index 66737b7d9..69e9b7f31 100644
--- a/airtime_mvc/application/models/Datatables.php
+++ b/airtime_mvc/application/models/Datatables.php
@@ -2,12 +2,74 @@
class Application_Model_Datatables
{
+ private static function buildWhereClauseForAdvancedSearch($dbname2searchTerm)
+ {
+ $where = array();
+ foreach ($dbname2searchTerm as $dbname=>$term) {
+ $isRange = false;
+ if (strstr($term, '~')) {
+ $info = explode('~', $term);
+ $input1 = isset($info[0])?$info[0]:null;
+ $input2 = isset($info[1])?$info[1]:null;
+ $isRange = true;
+ } else {
+ $input1 = $term;
+ }
+
+ if ($isRange) {
+ $sub = array();
+ if ($input1 != null) {
+ $sub[] = $dbname." >= '".$input1."'";
+ }
+ if ($input2 != null) {
+ $sub[] = $dbname." <= '".$input2."'";
+ }
+ if (!empty($sub)) {
+ $where[] = "(".implode(' AND ', $sub).")";
+ }
+ } else {
+ if (trim($input1) !== "") {
+ $where[] = $dbname." ILIKE "."'%".$input1."%'";
+ }
+ }
+ }
+ return implode(" AND ", $where);
+ }
/*
* query used to return data for a paginated/searchable datatable.
*/
public static function findEntries($con, $displayColumns, $fromTable, $data, $dataProp = "aaData")
{
+ $librarySetting = Application_Model_Preference::getCurrentLibraryTableSetting();
+
+ // map that maps original column position to db name
+ $current2dbname = array();
+ // array of search terms
+ $orig2searchTerm= array();
+ foreach ($data as $key=>$d) {
+ if (strstr($key, "mDataProp_")) {
+ list($dump, $index) = explode("_", $key);
+ $current2dbname[$index] = $d;
+ } else if (strstr($key, "sSearch_")) {
+ list($dump, $index) = explode("_", $key);
+ $orig2searchTerm[$index] = $d;
+ }
+ }
+ // map that maps current column position to original position
+ $current2orig = $librarySetting['ColReorder'];
+
+ // map that maps dbname to searchTerm
+ $dbname2searchTerm = array();
+ foreach ($current2dbname as $currentPos=>$dbname) {
+ $dbname2searchTerm[$dbname] = $orig2searchTerm[$current2orig[$currentPos]];
+ }
+
$where = array();
+
+ $advancedWhere = self::buildWhereClauseForAdvancedSearch($dbname2searchTerm);
+ if ($advancedWhere != "") {
+ $where[] = $advancedWhere;
+ }
if ($data["sSearch"] !== "") {
$searchTerms = explode(" ", $data["sSearch"]);
diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php
index df3b1fdde..9d98b2134 100644
--- a/airtime_mvc/application/models/Preference.php
+++ b/airtime_mvc/application/models/Preference.php
@@ -1099,4 +1099,8 @@ class Application_Model_Preference
return true;
}
}
+
+ public static function getCurrentLibraryTableSetting(){
+ return unserialize(self::getValue("library_datatable"));
+ }
}
diff --git a/airtime_mvc/application/views/scripts/library/library.phtml b/airtime_mvc/application/views/scripts/library/library.phtml
index 9bdb1c387..e0d889f76 100644
--- a/airtime_mvc/application/views/scripts/library/library.phtml
+++ b/airtime_mvc/application/views/scripts/library/library.phtml
@@ -1,2 +1,5 @@
'; //dialog div
+ //r+= '
'; //reset button and its div
+ r += divRowDef;
+
+ for (j = 0; j < iLen; j++) {
+
+ //if last check close div
+ if (j % numRow == 0 && j != 0) {
+ r += divClose + divRowDef;
+ }
+
+ //check button
+ r += '
' + aData[j] + '
';
+
+ var checkbox = $(r);
+ th.html(checkbox);
+ th.wrapInner('
');
+ //on every checkbox selection
+ checkbox.change(function () {
+
+ var search = '';
+ var or = '|'; //var for select checks in 'or' into the regex
+ var resSize = $('input:checkbox[name="' + localLabel + '"]:checked').size();
+ $('input:checkbox[name="' + localLabel + '"]:checked').each(function (index) {
+
+ //search = search + ' ' + $(this).val();
+ //concatenation for selected checks in or
+ if ((index == 0 && resSize == 1)
+ || (index != 0 && index == resSize - 1)) {
+ or = '';
+ }
+ //trim
+ search = search.replace(/^\s+|\s+$/g, "");
+ search = search + $(this).val() + or;
+ or = '|';
+
+ });
+
+ for (var jj = 0; jj < iLen; jj++) {
+ if (search != "") {
+ $('#' + aData[jj]).removeClass("search_init");
+ } else {
+ $('#' + aData[jj]).addClass("search_init");
+ }
+ }
+
+ //execute search
+ oTable.fnFilter(search, index, true, false);
+ fnOnFiltered();
+ });
+ }
+
+ //filter button
+ $('#' + buttonId).button();
+ //dialog
+ $('#' + checkToggleDiv).dialog({
+ //height: 140,
+ autoOpen: false,
+ //show: "blind",
+ hide: "blind",
+ buttons: [{
+ text: "Reset",
+ click: function () {
+ //$('#'+buttonId).removeClass("filter_selected"); //LM remove border if filter selected
+ $('input:checkbox[name="' + localLabel + '"]:checked').each(function (index3) {
+ $(this).attr('checked', false);
+ $(this).addClass("search_init");
+ });
+ oTable.fnFilter('', index, true, false);
+ fnOnFiltered();
+ return false;
+ }
+ },
+ {
+ text: "Close",
+ click: function () { $(this).dialog("close"); }
+ }
+ ]
+ });
+
+
+ $('#' + buttonId).click(function () {
+
+ $('#' + checkToggleDiv).dialog('open');
+ var target = $(this);
+ $('#' + checkToggleDiv).dialog("widget").position({ my: 'top',
+ at: 'bottom',
+ of: target
+ });
+
+ return false;
+ });
+
+ var fnOnFilteredCurrent = fnOnFiltered;
+
+ fnOnFiltered = function () {
+ var target = $('#' + buttonId);
+ $('#' + checkToggleDiv).dialog("widget").position({ my: 'top',
+ at: 'bottom',
+ of: target
+ });
+ fnOnFilteredCurrent();
+ };
+ //reset
+ /*
+ $('#'+buttonId+"Reset").button();
+ $('#'+buttonId+"Reset").click(function(){
+ $('#'+buttonId).removeClass("filter_selected"); //LM remove border if filter selected
+ $('input:checkbox[name="'+localLabel+'"]:checked').each(function(index3) {
+ $(this).attr('checked', false);
+ $(this).addClass("search_init");
+ });
+ oTable.fnFilter('', index, true, false);
+ return false;
+ });
+ */
+ }
+
+
+
+
+ function _fnRangeLabelPart(iPlace) {
+ switch (iPlace) {
+ case 0:
+ return sRangeFormat.substring(0, sRangeFormat.indexOf("{from}"));
+ case 1:
+ return sRangeFormat.substring(sRangeFormat.indexOf("{from}") + 6, sRangeFormat.indexOf("{to}"));
+ default:
+ return sRangeFormat.substring(sRangeFormat.indexOf("{to}") + 4);
+ }
+ }
+
+
+
+
+ oTable = this;
+
+ var defaults = {
+ sPlaceHolder: "foot",
+ sRangeSeparator: "~",
+ iFilteringDelay: 500,
+ aoColumns: null,
+ sRangeFormat: "From {from} to {to}"
+ };
+
+ properties = $.extend(defaults, options);
+
+ return this.each(function () {
+
+ if (!oTable.fnSettings().oFeatures.bFilter)
+ return;
+ asInitVals = new Array();
+
+ aoFilterCells = oTable.fnSettings().aoFooter[0];
+
+ var oHost = oTable.fnSettings().nTFoot; //Before fix for ColVis
+ var sFilterRow = "tr"; //Before fix for ColVis
+
+ if (properties.sPlaceHolder == "head:after") {
+ var tr = $("tr:first", oTable.fnSettings().nTHead).detach();
+ //tr.appendTo($(oTable.fnSettings().nTHead));
+ if (oTable.fnSettings().bSortCellsTop) {
+ tr.prependTo($(oTable.fnSettings().nTHead));
+ //tr.appendTo($("thead", oTable));
+ aoFilterCells = oTable.fnSettings().aoHeader[1];
+ }
+ else {
+ tr.appendTo($(oTable.fnSettings().nTHead));
+ //tr.prependTo($("thead", oTable));
+ aoFilterCells = oTable.fnSettings().aoHeader[0];
+ }
+
+ sFilterRow = "tr:last";
+ oHost = oTable.fnSettings().nTHead;
+
+ } else if (properties.sPlaceHolder == "head:before") {
+
+ if (oTable.fnSettings().bSortCellsTop) {
+ var tr = $("tr:first", oTable.fnSettings().nTHead).detach();
+ tr.appendTo($(oTable.fnSettings().nTHead));
+ aoFilterCells = oTable.fnSettings().aoHeader[1];
+ } else {
+ aoFilterCells = oTable.fnSettings().aoHeader[0];
+ }
+ /*else {
+ //tr.prependTo($("thead", oTable));
+ sFilterRow = "tr:first";
+ }*/
+
+ sFilterRow = "tr:first";
+
+ oHost = oTable.fnSettings().nTHead;
+
+
+ }
+
+ //$(sFilterRow + " th", oHost).each(function (index) {//bug with ColVis
+ $(aoFilterCells).each(function (index) {//fix for ColVis
+ i = index;
+ var aoColumn = { type: "text",
+ bRegex: false,
+ bSmart: true,
+ iMaxLenght: -1,
+ iFilterLength: 0
+ };
+ if (properties.aoColumns != null) {
+ if (properties.aoColumns.length < i || properties.aoColumns[i] == null)
+ return;
+ aoColumn = properties.aoColumns[i];
+ }
+ //label = $(this).text(); //Before fix for ColVis
+ label = $($(this)[0].cell).text(); //Fix for ColVis
+ if (aoColumn.sSelector == null) {
+ //th = $($(this)[0]);//Before fix for ColVis
+ th = $($(this)[0].cell); //Fix for ColVis
+ }
+ else {
+ th = $(aoColumn.sSelector);
+ if (th.length == 0)
+ th = $($(this)[0].cell);
+ }
+
+ if (aoColumn != null) {
+ if (aoColumn.sRangeFormat != null)
+ sRangeFormat = aoColumn.sRangeFormat;
+ else
+ sRangeFormat = properties.sRangeFormat;
+ switch (aoColumn.type) {
+ case "null":
+ break;
+ case "number":
+ fnCreateInput(oTable, true, false, true, aoColumn.iFilterLength, aoColumn.iMaxLenght);
+ break;
+ case "select":
+ if (aoColumn.bRegex != true)
+ aoColumn.bRegex = false;
+ fnCreateSelect(oTable, aoColumn.values, aoColumn.bRegex);
+ break;
+ case "number-range":
+ fnCreateRangeInput(oTable);
+ break;
+ case "date-range":
+ fnCreateDateRangeInput(oTable);
+ break;
+ case "checkbox":
+ fnCreateCheckbox(oTable, aoColumn.values);
+ break;
+ case "text":
+ default:
+ bRegex = (aoColumn.bRegex == null ? false : aoColumn.bRegex);
+ bSmart = (aoColumn.bSmart == null ? false : aoColumn.bSmart);
+ fnCreateInput(oTable, bRegex, bSmart, false, aoColumn.iFilterLength, aoColumn.iMaxLenght);
+ break;
+
+ }
+ }
+ });
+
+ for (j = 0; j < aiCustomSearch_Indexes.length; j++) {
+ //var index = aiCustomSearch_Indexes[j];
+ var fnSearch_ = function () {
+ var id = oTable.attr("id");
+ return $("#" + id + "_range_from_" + aiCustomSearch_Indexes[j]).val() + properties.sRangeSeparator + $("#" + id + "_range_to_" + aiCustomSearch_Indexes[j]).val()
+ }
+ afnSearch_.push(fnSearch_);
+ }
+
+ if (oTable.fnSettings().oFeatures.bServerSide) {
+
+ var fnServerDataOriginal = oTable.fnSettings().fnServerData;
+
+ oTable.fnSettings().fnServerData = function (sSource, aoData, fnCallback) {
+
+ for (j = 0; j < aiCustomSearch_Indexes.length; j++) {
+ var index = aiCustomSearch_Indexes[j];
+
+ for (k = 0; k < aoData.length; k++) {
+ if (aoData[k].name == "sSearch_" + index)
+ aoData[k].value = afnSearch_[j]();
+ }
+ }
+ aoData.push({ "name": "sRangeSeparator", "value": properties.sRangeSeparator });
+
+ if (fnServerDataOriginal != null) {
+ try {
+ fnServerDataOriginal(sSource, aoData, fnCallback, oTable.fnSettings()); //TODO: See Issue 18
+ } catch (ex) {
+ fnServerDataOriginal(sSource, aoData, fnCallback);
+ }
+ }
+ else {
+ $.getJSON(sSource, aoData, function (json) {
+ fnCallback(json)
+ });
+ }
+ };
+
+ }
+
+ });
+
+ };
+
+
+
+
+})(jQuery);
\ No newline at end of file