Reusable datatable control that hooks up to any of our REST APIs

* Implements item selection (single, shift, ctrl), pagination, and
  sorting. To be used in the future.
* Added example code for how to use the table widget
* Temporarily added a table test page to the DashboardController
This commit is contained in:
Albert Santoni 2015-09-15 14:18:35 -04:00
parent 2d2ed25fcc
commit ffdc83dc26
7 changed files with 411 additions and 21 deletions

View file

@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* User: asantoni
* Date: 11/09/15
* Time: 2:47 PM
*/
class AirtimeTableView {
private static function _getTableJavaScriptDependencies() {
return ['js/airtime/widgets/table.js',
'js/datatables/js/jquery.dataTables.js',
'js/datatables/plugin/dataTables.pluginAPI.js',
'js/datatables/plugin/dataTables.fnSetFilteringDelay.js',
'js/datatables/plugin/dataTables.ColVis.js',
'js/datatables/plugin/dataTables.colReorder.min.js?',
'js/datatables/plugin/dataTables.FixedColumns.js',
'js/datatables/plugin/dataTables.FixedHeader.js',
'js/datatables/plugin/dataTables.columnFilter.js?'];
}
public static function injectTableJavaScriptDependencies(&$headScript, $baseUrl, $airtimeVersion)
{
$deps = self::_getTableJavaScriptDependencies();
for ($i = 0; $i < count($deps); $i++) {
$headScript->appendFile($baseUrl . $deps[$i] .'?'. $airtimeVersion, 'text/javascript');
}
}
}

View file

@ -1,5 +1,7 @@
<?php
require_once(__DIR__.'/../common/widgets/Table.php');
class DashboardController extends Zend_Controller_Action
{
@ -117,4 +119,17 @@ class DashboardController extends Zend_Controller_Action
$this->view->airtime_version = Application_Model_Preference::GetAirtimeVersion();
}
public function tableTestAction()
{
Zend_Layout::getMvcInstance()->assign('parent_page', 'Help');
$CC_CONFIG = Config::getConfig();
$baseUrl = Application_Common_OsPath::getBaseDir();
$headScript = $this->view->headScript();
AirtimeTableView::injectTableJavaScriptDependencies($headScript, $baseUrl, $CC_CONFIG['airtime_version']);
$this->view->headScript()->appendFile($baseUrl.'js/airtime/widgets/table-example.js?'.$CC_CONFIG['airtime_version']);
}
}

View file

@ -21,13 +21,20 @@ class Rest_MediaController extends Zend_Rest_Controller
$offset = $this->_getParam('offset', 0);
$limit = $this->_getParam('limit', $totalFileCount);
//Sorting parameters
$sortColumn = $this->_getParam('sort', CcFilesPeer::ID);
$sortDir = $this->_getParam('sort_dir', Criteria::ASC);
$query = CcFilesQuery::create()
->filterByDbHidden(false)
->filterByDbFileExists(true)
->filterByDbImportStatus(0)
->setLimit($limit)
->setOffset($offset)
->orderByDbId();
->orderBy($sortColumn, $sortDir);
//->orderByDbId();
$queryCount = $query->count();
$queryResult = $query->find();
@ -39,7 +46,7 @@ class Rest_MediaController extends Zend_Rest_Controller
$this->getResponse()
->setHttpResponseCode(200)
->setHeader('X-TOTAL-COUNT', $queryCount)
->setHeader('X-TOTAL-COUNT', $totalFileCount)
->appendBody(json_encode($files_array));
/** TODO: Use this simpler code instead after we upgrade to Propel 1.7 (Airtime 2.6.x branch):

View file

@ -0,0 +1,7 @@
<div class="text-content">
<h2><?php echo _("Table Test") ?></h2>
<p>
Hello
</p>
<table id="example-table" cellpadding="0" cellspacing="0" class="datatable"></table>
</div>