From 5fa92f3d17acefa4a1fc689d6a925d520f3be915 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 4 Jan 2012 12:47:27 -0500 Subject: [PATCH 1/7] - temp commit on group action --- .../controllers/LibraryController.php | 1 + airtime_mvc/application/models/StoredFile.php | 19 +++++++-- airtime_mvc/public/css/media_library.css | 10 ++++- .../public/js/airtime/library/library.js | 41 +++++++++++-------- 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/airtime_mvc/application/controllers/LibraryController.php b/airtime_mvc/application/controllers/LibraryController.php index f0b72099d..7bad3225e 100644 --- a/airtime_mvc/application/controllers/LibraryController.php +++ b/airtime_mvc/application/controllers/LibraryController.php @@ -182,6 +182,7 @@ class LibraryController extends Zend_Controller_Action public function contentsAction() { $post = $this->getRequest()->getPost(); + Logging::log(print_r($post, true)); $datatables = Application_Model_StoredFile::searchFilesForPlaylistBuilder($post); //format clip lengh to 1 decimal diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index d48c3c420..8b6fe4a99 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -666,9 +666,8 @@ class Application_Model_StoredFile { UNION (".$fileSelect."id FROM ".$CC_CONFIG["filesTable"]." AS FILES)) AS RESULTS"; - + return Application_Model_StoredFile::searchFiles($fromTable, $datatables); - } public static function searchPlaylistsForSchedule($datatables) @@ -690,7 +689,12 @@ class Application_Model_StoredFile { $searchTerms = explode(" ", $data["sSearch"]); $selectorCount = "SELECT COUNT(*)"; - $selectorRows = "SELECT ". join("," , $columnsDisplayed); + foreach( $columnsDisplayed as $key=>$col){ + if($col == ''){ + unset($columnsDisplayed[$key]); + } + } + $selectorRows = "SELECT " . join(',', $columnsDisplayed ); $sql = $selectorCount." FROM ".$fromTable; $totalRows = $CC_DBC->getOne($sql); @@ -733,7 +737,7 @@ class Application_Model_StoredFile { // End Order By clause //ordered by integer as expected by datatables. - $CC_DBC->setFetchMode(DB_FETCHMODE_ORDERED); + //$CC_DBC->setFetchMode(DB_FETCHMODE_ORDERED); if(isset($where)) { $where = join(" AND ", $where); @@ -746,6 +750,13 @@ class Application_Model_StoredFile { } $results = $CC_DBC->getAll($sql); + // add checkbox row + foreach($results as &$row){ + $row['checkbox'] = ""; + } + //$results['checkbox'] + //$results = $CC_DBC->getAssoc($sql); + Logging::log(print_r($results, true)); //echo $results; //echo $sql; diff --git a/airtime_mvc/public/css/media_library.css b/airtime_mvc/public/css/media_library.css index dbef3052a..925baa36a 100644 --- a/airtime_mvc/public/css/media_library.css +++ b/airtime_mvc/public/css/media_library.css @@ -66,4 +66,12 @@ -moz-user-select: none; -o-user-select: none; user-select: none; -} \ No newline at end of file +} + +.datatable_checkbox { + text-align: center; +} + +.datatable_checkbox .DataTables_sort_wrapper { + text-align: center; +} diff --git a/airtime_mvc/public/js/airtime/library/library.js b/airtime_mvc/public/js/airtime/library/library.js index eefa73ccf..88fc6a9aa 100644 --- a/airtime_mvc/public/js/airtime/library/library.js +++ b/airtime_mvc/public/js/airtime/library/library.js @@ -1,13 +1,15 @@ +var dTable; + //used by jjmenu function getId() { - var tr_id = $(this.triggerElement).attr("id"); + var tr_id = $(this.triggerElement).parent().attr("id"); tr_id = tr_id.split("_"); return tr_id[1]; } function getType() { - var tr_id = $(this.triggerElement).attr("id"); + var tr_id = $(this.triggerElement).parent().attr("id"); tr_id = tr_id.split("_"); return tr_id[0]; @@ -90,7 +92,7 @@ function addLibraryItemEvents() { cursor: 'pointer' }); - $('#library_display tbody tr') + $('#library_display tbody tr td').not('[class=datatable_checkbox]') .jjmenu("click", [{get:"/Library/context-menu/format/json/id/#id#/type/#type#"}], {id: getId, type: getType}, @@ -101,20 +103,20 @@ function addLibraryItemEvents() { function dtRowCallback( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { var id, type, once; - type = aData[6].substring(0,2); - id = aData[0]; + type = aData["ftype"].substring(0,2); + id = aData["id"]; if(type == "au") { - $('td:eq(5)', nRow).html( '' ); + $('td:eq(6)', nRow).html( '' ); } else if(type == "pl") { - $('td:eq(5)', nRow).html( '' ); + $('td:eq(6)', nRow).html( '' ); } $(nRow).attr("id", type+'_'+id); // insert id on lenth field - $('td:eq(4)', nRow).attr("id", "length"); + $('td:eq(5)', nRow).attr("id", "length"); return nRow; } @@ -123,6 +125,8 @@ function dtDrawCallback() { addLibraryItemEvents(); addMetadataQtip(); saveNumEntriesSetting(); + var temp = dTable.fnGetData() + console.log(temp) } function addProgressIcon(id) { @@ -298,29 +302,30 @@ function getNumEntriesPreference(data) { } function createDataTable(data) { - var dTable = $('#library_display').dataTable( { + dTable = $('#library_display').dataTable( { "bProcessing": true, "bServerSide": true, "sAjaxSource": "/Library/contents/format/json", - "fnServerData": function ( sSource, aoData, fnCallback ) { + "fnServerData": function ( sSource, aoData, testCallback ) { $.ajax( { "dataType": 'json', "type": "POST", "url": sSource, "data": aoData, - "success": fnCallback + "success": testCallback } ); }, "fnRowCallback": dtRowCallback, "fnDrawCallback": dtDrawCallback, "aoColumns": [ - /* Id */ { "sName": "id", "bSearchable": false, "bVisible": false }, - /* Title */ { "sTitle": "Title", "sName": "track_title" }, - /* Creator */ { "sTitle": "Creator", "sName": "artist_name" }, - /* Album */ { "sTitle": "Album", "sName": "album_title" }, - /* Genre */ { "sTitle": "Genre", "sName": "genre" }, - /* Length */ { "sTitle": "Length", "sName": "length" }, - /* Type */ { "sTitle": "Type", "sName": "ftype", "bSearchable": false } + /* Checkbox */ { "sTitle": "", "bSortable": false, "bSearchable": false, "mDataProp": "checkbox", "sWidth": "25px", "sClass": "datatable_checkbox" }, + /* Id */ { "sName": "id", "bSearchable": false, "bVisible": false, "mDataProp": "id" }, + /* Title */ { "sTitle": "Title", "sName": "track_title", "mDataProp": "track_title" }, + /* Creator */ { "sTitle": "Creator", "sName": "artist_name", "mDataProp": "artist_name" }, + /* Album */ { "sTitle": "Album", "sName": "album_title", "mDataProp": "album_title" }, + /* Genre */ { "sTitle": "Genre", "sName": "genre", "mDataProp": "genre" }, + /* Length */ { "sTitle": "Length", "sName": "length", "mDataProp": "length" }, + /* Type */ { "sTitle": "Type", "sName": "ftype", "bSearchable": false, "mDataProp": "ftype", "sWidth": "50px" }, ], "aaSorting": [[2,'asc']], "sPaginationType": "full_numbers", From 6597f6701ad169a0ad84ac9c865566bb8092a2e3 Mon Sep 17 00:00:00 2001 From: Yuchen Wang Date: Sat, 7 Jan 2012 10:03:54 -0500 Subject: [PATCH 2/7] CC-1986: Configurable columns for media search Adding ColVis plugin for datatable, this plugin can be used to Show/Hide columns --- .../js/datatables/plugin/dataTables.ColVis.js | 871 ++++++++++++++++++ 1 file changed, 871 insertions(+) create mode 100644 airtime_mvc/public/js/datatables/plugin/dataTables.ColVis.js diff --git a/airtime_mvc/public/js/datatables/plugin/dataTables.ColVis.js b/airtime_mvc/public/js/datatables/plugin/dataTables.ColVis.js new file mode 100644 index 000000000..d6d1bcfd4 --- /dev/null +++ b/airtime_mvc/public/js/datatables/plugin/dataTables.ColVis.js @@ -0,0 +1,871 @@ +/* + * File: ColVis.js + * Version: 1.0.6 + * CVS: $Id$ + * Description: Controls for column visiblity in DataTables + * Author: Allan Jardine (www.sprymedia.co.uk) + * Created: Wed Sep 15 18:23:29 BST 2010 + * Modified: $Date$ by $Author$ + * Language: Javascript + * License: GPL v2 or BSD 3 point style + * Project: Just a little bit of fun :-) + * Contact: www.sprymedia.co.uk/contact + * + * Copyright 2010-2011 Allan Jardine, all rights reserved. + * + * This source file is free software, under either the GPL v2 license or a + * BSD style license, available at: + * http://datatables.net/license_gpl2 + * http://datatables.net/license_bsd + */ + +(function($) { + +/** + * ColVis provides column visiblity control for DataTables + * @class ColVis + * @constructor + * @param {object} DataTables settings object + */ +ColVis = function( oDTSettings, oInit ) +{ + /* Santiy check that we are a new instance */ + if ( !this.CLASS || this.CLASS != "ColVis" ) + { + alert( "Warning: ColVis must be initialised with the keyword 'new'" ); + } + + if ( typeof oInit == 'undefined' ) + { + oInit = {}; + } + + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Public class variables + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + /** + * @namespace Settings object which contains customisable information for ColVis instance + */ + this.s = { + /** + * DataTables settings object + * @property dt + * @type Object + * @default null + */ + "dt": null, + + /** + * Customisation object + * @property oInit + * @type Object + * @default passed in + */ + "oInit": oInit, + + /** + * Callback function to tell the user when the state has changed + * @property fnStateChange + * @type function + * @default null + */ + "fnStateChange": null, + + /** + * Mode of activation. Can be 'click' or 'mouseover' + * @property activate + * @type String + * @default click + */ + "activate": "click", + + /** + * Position of the collection menu when shown - align "left" or "right" + * @property sAlign + * @type String + * @default right + */ + "sAlign": "left", + + /** + * Text used for the button + * @property buttonText + * @type String + * @default Show / hide columns + */ + "buttonText": "Show / hide columns", + + /** + * Flag to say if the collection is hidden + * @property hidden + * @type boolean + * @default true + */ + "hidden": true, + + /** + * List of columns (integers) which should be excluded from the list + * @property aiExclude + * @type Array + * @default [] + */ + "aiExclude": [], + + /** + * Store the original viisbility settings so they could be restored + * @property abOriginal + * @type Array + * @default [] + */ + "abOriginal": [], + + /** + * Show restore button + * @property bRestore + * @type Array + * @default [] + */ + "bRestore": false, + + /** + * Restore button text + * @property sRestore + * @type String + * @default Restore original + */ + "sRestore": "Restore original", + + /** + * Overlay animation duration in mS + * @property iOverlayFade + * @type Integer + * @default 500 + */ + "iOverlayFade": 500, + + /** + * Label callback for column names. Takes three parameters: 1. the column index, 2. the column + * title detected by DataTables and 3. the TH node for the column + * @property fnLabel + * @type Function + * @default null + */ + "fnLabel": null, + + /** + * Indicate if ColVis should automatically calculate the size of buttons or not. The default + * is for it to do so. Set to "css" to disable the automatic sizing + * @property sSize + * @type String + * @default auto + */ + "sSize": "auto" + }; + + + /** + * @namespace Common and useful DOM elements for the class instance + */ + this.dom = { + /** + * Wrapper for the button - given back to DataTables as the node to insert + * @property wrapper + * @type Node + * @default null + */ + "wrapper": null, + + /** + * Activation button + * @property button + * @type Node + * @default null + */ + "button": null, + + /** + * Collection list node + * @property collection + * @type Node + * @default null + */ + "collection": null, + + /** + * Background node used for shading the display and event capturing + * @property background + * @type Node + * @default null + */ + "background": null, + + /** + * Element to position over the activation button to catch mouse events when using mouseover + * @property catcher + * @type Node + * @default null + */ + "catcher": null, + + /** + * List of button elements + * @property buttons + * @type Array + * @default [] + */ + "buttons": [], + + /** + * Restore button + * @property restore + * @type Node + * @default null + */ + "restore": null + }; + + /* Store global reference */ + ColVis.aInstances.push( this ); + + /* Constructor logic */ + this.s.dt = oDTSettings; + this._fnConstruct(); + return this; +}; + + + +ColVis.prototype = { + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Public methods + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + /** + * Rebuild the list of buttons for this instance (i.e. if there is a column header update) + * @method fnRebuild + * @returns void + */ + "fnRebuild": function () + { + /* Remove the old buttons */ + for ( var i=this.dom.buttons.length-1 ; i>=0 ; i-- ) + { + if ( this.dom.buttons[i] !== null ) + { + this.dom.collection.removeChild( this.dom.buttons[i] ); + } + } + this.dom.buttons.splice( 0, this.dom.buttons.length ); + + if ( this.dom.restore ) + { + this.dom.restore.parentNode( this.dom.restore ); + } + + /* Re-add them (this is not the optimal way of doing this, it is fast and effective) */ + this._fnAddButtons(); + + /* Update the checkboxes */ + this._fnDrawCallback(); + }, + + + + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * Private methods (they are of course public in JS, but recommended as private) + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + + /** + * Constructor logic + * @method _fnConstruct + * @returns void + * @private + */ + "_fnConstruct": function () + { + this._fnApplyCustomisation(); + + var that = this; + this.dom.wrapper = document.createElement('div'); + this.dom.wrapper.className = "ColVis TableTools"; + + this.dom.button = this._fnDomBaseButton( this.s.buttonText ); + this.dom.button.className += " ColVis_MasterButton"; + this.dom.wrapper.appendChild( this.dom.button ); + + this.dom.catcher = this._fnDomCatcher(); + this.dom.collection = this._fnDomCollection(); + this.dom.background = this._fnDomBackground(); + + this._fnAddButtons(); + + /* Store the original visbility information */ + for ( var i=0, iLen=this.s.dt.aoColumns.length ; i'+this.s.sRestore+'' ); + + $(nButton).click( function (e) { + for ( var i=0, iLen=that.s.abOriginal.length ; i'+ + ''+sTitle+'' ); + + $(nButton).click( function (e) { + var showHide = !$('input', this).is(":checked"); + if ( e.target.nodeName.toLowerCase() == "input" ) + { + showHide = $('input', this).is(":checked"); + } + + /* Need to consider the case where the initialiser created more than one table - change the + * API index that DataTables is using + */ + var oldIndex = $.fn.dataTableExt.iApiIndex; + $.fn.dataTableExt.iApiIndex = that._fnDataTablesApiIndex.call(that); + that.s.dt.oInstance.fnSetColumnVis( i, showHide ); + $.fn.dataTableExt.iApiIndex = oldIndex; /* Restore */ + + if ( that.s.fnStateChange !== null ) + { + that.s.fnStateChange.call( that, i, showHide ); + } + } ); + + return nButton; + }, + + + /** + * Get the position in the DataTables instance array of the table for this instance of ColVis + * @method _fnDataTablesApiIndex + * @returns {int} Index + * @private + */ + "_fnDataTablesApiIndex": function () + { + for ( var i=0, iLen=this.s.dt.oInstance.length ; i