From 71f9ce19422c3fa9216b55dfa987d371fa8377be Mon Sep 17 00:00:00 2001 From: Naomi Date: Thu, 6 Feb 2014 12:41:50 -0500 Subject: [PATCH] CC-5450 : Refactor Media Management (Classes/DB) in Airtime starting working on proper visibility of advanced search fields. --- .../application/services/MediaService.php | 10 --- .../js/airtime/library/lib_separate_table.js | 84 ++++++++++++++++--- 2 files changed, 71 insertions(+), 23 deletions(-) diff --git a/airtime_mvc/application/services/MediaService.php b/airtime_mvc/application/services/MediaService.php index 209e44640..d61aa84c9 100644 --- a/airtime_mvc/application/services/MediaService.php +++ b/airtime_mvc/application/services/MediaService.php @@ -54,7 +54,6 @@ class Application_Service_MediaService "title" => _("Scheduled"), "width" => "90px", "class" => "library_is_scheduled", - "searchable" => false, "advancedSearch" => array( "type" => "checkbox" ) @@ -64,7 +63,6 @@ class Application_Service_MediaService "title" => _("Playlist"), "width" => "90px", "class" => "library_is_playlist", - "searchable" => false, "advancedSearch" => array( "type" => "checkbox" ) @@ -102,7 +100,6 @@ class Application_Service_MediaService "width" => "80px", "class" => "library_bitrate", "visible" => false, - "searchable" => false, "advancedSearch" => array( "type" => "number-range" ) @@ -113,7 +110,6 @@ class Application_Service_MediaService "width" => "50px", "class" => "library_bpm", "visible" => false, - "searchable" => false, "advancedSearch" => array( "type" => "number-range" ) @@ -226,7 +222,6 @@ class Application_Service_MediaService "width" => "125px", "class" => "library_modified_time", "visible" => false, - "searchable" => false, "advancedSearch" => array( "type" => "date-range" ) @@ -237,7 +232,6 @@ class Application_Service_MediaService "width" => "125px", "class" => "library_modified_time", "visible" => false, - "searchable" => false, "advancedSearch" => array( "type" => "date-range" ) @@ -288,7 +282,6 @@ class Application_Service_MediaService "width" => "80px", "class" => "library_replay_gain", "visible" => false, - "searchable" => false, "advancedSearch" => array( "type" => "number-range" ) @@ -299,7 +292,6 @@ class Application_Service_MediaService "width" => "80px", "class" => "library_sr", "visible" => false, - "searchable" => false, "advancedSearch" => array( "type" => "number-range" ) @@ -310,7 +302,6 @@ class Application_Service_MediaService "width" => "65px", "class" => "library_track", "visible" => false, - "searchable" => false, "advancedSearch" => array( "type" => "number-range" ) @@ -321,7 +312,6 @@ class Application_Service_MediaService "width" => "125px", "class" => "library_upload_time", "visible" => false, - "searchable" => false, "advancedSearch" => array( "type" => "date-range" ) diff --git a/airtime_mvc/public/js/airtime/library/lib_separate_table.js b/airtime_mvc/public/js/airtime/library/lib_separate_table.js index 1e288f637..9bf46c6a1 100644 --- a/airtime_mvc/public/js/airtime/library/lib_separate_table.js +++ b/airtime_mvc/public/js/airtime/library/lib_separate_table.js @@ -108,23 +108,66 @@ var AIRTIME = (function(AIRTIME) { template = "
>" + "" + - "
" + + "
" + "
"; template = _.template(template); - $el = $(template(config)); + $el = $(template({ + index: config.index, + style: display, + title: config.title, + id: config.id + })); return $el; } - function setUpAdvancedSearch(columns) { + function setUpAdvancedSearch(columns, type) { + var i, len, + selector = "#advanced_search_"+type, + $div = $(selector), + col, tmp, + searchFields = []; + for (i = 0, len = columns.length; i < len; i++) { + + col = columns[i]; + + if (col.bSearchable) { + tmp = createAdvancedSearchField({ + index: i, + display: col.bVisible, + title: col.sTitle, + id: "adv-search-"+ col.mDataProp + }); + + searchFields.push(tmp); + } + } + + //http://www.bennadel.com/blog/2281-jQuery-Appends-Multiple-Elements-Using-Efficient-Document-Fragments.htm + $div.append(searchFields); + } + + function setAdvancedSearchColumnDisplay(colNum, display) { + var selector = "#advanced_search_col_" + colNum, + $column = $(selector); + + if (display) { + $column.show(); + } + else { + $column.hide(); + } } function createDatatable(config) { - var key = "datatables-"+config.type+"-aoColumns", - columns = JSON.parse(localStorage.getItem(key)); + columns = JSON.parse(localStorage.getItem(key)), + abVisible, + i, len; + + setUpAdvancedSearch(columns, config.type); var table = $("#"+config.type + "_table").dataTable({ "aoColumns": columns, @@ -132,17 +175,17 @@ var AIRTIME = (function(AIRTIME) { "bServerSide": true, "sAjaxSource": baseUrl+"media/"+config.type+"-feed", "sAjaxDataProp": "media", - "fnServerData": function ( sSource, aoData, fnCallback ) { + "fnServerData": function (sSource, aoData, fnCallback) { - aoData.push( { name: "format", value: "json"} ); + aoData.push({ name: "format", value: "json"}); - $.ajax( { + $.ajax({ "dataType": 'json', "type": "POST", "url": sSource, "data": aoData, "success": fnCallback - } ); + }); }, //save the tables based on tableId "bStateSave": true, @@ -194,6 +237,10 @@ var AIRTIME = (function(AIRTIME) { } } + //abVisible indices belong to the original column order. + //use to fix up advanced search. + abVisible = oData.abVisCols; + oData.iEnd = parseInt(oData.iEnd, 10); oData.iLength = parseInt(oData.iLength, 10); oData.iStart = parseInt(oData.iStart, 10); @@ -216,10 +263,8 @@ var AIRTIME = (function(AIRTIME) { "fnStateChange": function ( iColumn, bVisible ) { var c = table.fnSettings().aoColumns, origIndex = c[iColumn]._ColReorder_iOrigCol; - col = columns[origIndex]; - - console.log(col); - + + setAdvancedSearchColumnDisplay(origIndex, bVisible); } }, @@ -232,6 +277,12 @@ var AIRTIME = (function(AIRTIME) { } }); + //fnStateLoadParams will have already run. + //fix up advanced search from saved settings. + for (i = 0, len = abVisible.length; i < len; i++) { + setAdvancedSearchColumnDisplay(i, abVisible[i]); + } + table.fnSetFilteringDelay(350); } @@ -486,6 +537,12 @@ var AIRTIME = (function(AIRTIME) { } }); + $library.on("click", "legend", function() { + var $fs = $(this).parents("fieldset"); + + $fs.toggleClass("closed"); + }); + $library.on("click", "#lib_new_webstream", function(e) { var url = baseUrl+"webstream/new/format/json"; @@ -566,6 +623,7 @@ var AIRTIME = (function(AIRTIME) { $('#editmdsave').click(); } }); + */ //end of events fo the edit metadata dialog. // begin context menu initialization.