editing in progress

This commit is contained in:
Naomi Aro 2013-07-18 01:31:20 -04:00
parent c744d88f23
commit 29c8570ade
8 changed files with 551 additions and 338 deletions

View file

@ -6,8 +6,11 @@ class PlayouthistoryController extends Zend_Controller_Action
{ {
$ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext $ajaxContext
->addActionContext('playout-history-feed', 'json') ->addActionContext('aggregate-history-feed', 'json')
->addActionContext('item-history-feed', 'json')
->addActionContext('edit-aggregate-item', 'json') ->addActionContext('edit-aggregate-item', 'json')
->addActionContext('edit-list-item', 'json')
->addActionContext('update-aggregate-item', 'json')
->initContext(); ->initContext();
} }
@ -58,7 +61,7 @@ class PlayouthistoryController extends Zend_Controller_Action
$this->view->headLink()->appendStylesheet($baseUrl.'css/playouthistory.css?'.$CC_CONFIG['airtime_version']); $this->view->headLink()->appendStylesheet($baseUrl.'css/playouthistory.css?'.$CC_CONFIG['airtime_version']);
} }
public function playoutHistoryFeedAction() public function aggregateHistoryFeedAction()
{ {
$request = $this->getRequest(); $request = $this->getRequest();
$current_time = time(); $current_time = time();
@ -73,32 +76,70 @@ class PlayouthistoryController extends Zend_Controller_Action
$historyService = new Application_Service_HistoryService(); $historyService = new Application_Service_HistoryService();
$r = $historyService->getAggregateView($startsDT, $endsDT, $params); $r = $historyService->getAggregateView($startsDT, $endsDT, $params);
$this->view->sEcho = $r["sEcho"]; $this->view->sEcho = $r["sEcho"];
$this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"]; $this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"];
$this->view->iTotalRecords = $r["iTotalRecords"]; $this->view->iTotalRecords = $r["iTotalRecords"];
$this->view->history = $r["history"]; $this->view->history = $r["history"];
} }
public function itemHistoryFeedAction()
{
$request = $this->getRequest();
$current_time = time();
$params = $request->getParams();
$starts_epoch = $request->getParam("start", $current_time - (60*60*24));
$ends_epoch = $request->getParam("end", $current_time);
$startsDT = DateTime::createFromFormat("U", $starts_epoch, new DateTimeZone("UTC"));
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
$historyService = new Application_Service_HistoryService();
$r = $historyService->getListView($startsDT, $endsDT, $params);
$this->view->sEcho = $r["sEcho"];
$this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"];
$this->view->iTotalRecords = $r["iTotalRecords"];
$this->view->history = $r["history"];
}
public function editAggregateItemAction() public function editAggregateItemAction()
{ {
$file_id = $this->_getParam('id'); $file_id = $this->_getParam('id');
$historyService = new Application_Service_HistoryService(); $historyService = new Application_Service_HistoryService();
$form = $historyService->makeHistoryFileForm($file_id); $form = $historyService->makeHistoryFileForm($file_id);
$this->view->form = $form; $this->view->form = $form;
$this->view->dialog = $this->view->render('form/edit-history-file.phtml'); $this->view->dialog = $this->view->render('form/edit-history-file.phtml');
unset($this->view->form); unset($this->view->form);
} }
public function editListItemAction()
{
$file_id = $this->_getParam('id');
$historyService = new Application_Service_HistoryService();
$form = $historyService->makeHistoryFileForm($file_id);
$this->view->form = $form;
$this->view->dialog = $this->view->render('form/edit-history-file.phtml');
unset($this->view->form);
}
public function updateAggregateItemAction() public function updateAggregateItemAction()
{ {
$file_id = $this->_getParam('id'); $request = $this->getRequest();
$params = $request->getPost();
$historyService = new Application_Service_HistoryService(); Logging::info($params);
$historyService->editPlayedFile($file_id);
}
$historyService = new Application_Service_HistoryService();
$json = $historyService->editPlayedFile($params);
$this->view->data = $json;
}
} }

View file

@ -3,7 +3,7 @@
class Application_Form_EditHistoryFile extends Zend_Form class Application_Form_EditHistoryFile extends Zend_Form
{ {
public function init() { public function init() {
/* /*
$this->setDecorators( $this->setDecorators(
array( array(
@ -11,12 +11,17 @@ class Application_Form_EditHistoryFile extends Zend_Form
) )
); );
*/ */
$this->setMethod('post'); $this->setMethod('post');
$this->addElement('hidden', 'file_id'); $file_id = new Zend_Form_Element_Hidden('his_file_id');
$file_id->setValidators(array(
new Zend_Validate_Int()
));
$this->addElement($file_id);
/* Title form element */ /* Title form element */
$title = new Zend_Form_Element_Text('his_file_title'); $title = new Zend_Form_Element_Text('his_file_title');
$title->setLabel(_('Title:')); $title->setLabel(_('Title:'));
@ -24,7 +29,7 @@ class Application_Form_EditHistoryFile extends Zend_Form
$title->addFilter('StringTrim'); $title->addFilter('StringTrim');
//$title->setDecorators(array('viewHelper')); //$title->setDecorators(array('viewHelper'));
$this->addElement($title); $this->addElement($title);
/* Creator form element */ /* Creator form element */
$creator = new Zend_Form_Element_Text('his_file_creator'); $creator = new Zend_Form_Element_Text('his_file_creator');
$creator->setLabel(_('Creator:')); $creator->setLabel(_('Creator:'));
@ -32,7 +37,7 @@ class Application_Form_EditHistoryFile extends Zend_Form
$creator->addFilter('StringTrim'); $creator->addFilter('StringTrim');
//$creator->setDecorators(array('viewHelper')); //$creator->setDecorators(array('viewHelper'));
$this->addElement($creator); $this->addElement($creator);
/* Composer form element */ /* Composer form element */
$composer = new Zend_Form_Element_Text('his_file_composer'); $composer = new Zend_Form_Element_Text('his_file_composer');
$composer->setLabel(_('Composer:')); $composer->setLabel(_('Composer:'));
@ -40,7 +45,7 @@ class Application_Form_EditHistoryFile extends Zend_Form
$composer->addFilter('StringTrim'); $composer->addFilter('StringTrim');
//$composer->setDecorators(array('viewHelper')); //$composer->setDecorators(array('viewHelper'));
$this->addElement($composer); $this->addElement($composer);
/* Copyright form element */ /* Copyright form element */
$copyright = new Zend_Form_Element_Text('his_file_copyright'); $copyright = new Zend_Form_Element_Text('his_file_copyright');
$copyright->setLabel(_('Copyright:')); $copyright->setLabel(_('Copyright:'));
@ -48,33 +53,33 @@ class Application_Form_EditHistoryFile extends Zend_Form
$copyright->addFilter('StringTrim'); $copyright->addFilter('StringTrim');
//$copyright->setDecorators(array('viewHelper')); //$copyright->setDecorators(array('viewHelper'));
$this->addElement($copyright); $this->addElement($copyright);
// Add the submit button // Add the submit button
$this->addElement('button', 'his_file_save', array( $this->addElement('button', 'his_file_save', array(
'ignore' => true, 'ignore' => true,
'class' => 'btn', 'class' => 'btn his_file_save',
'label' => _('Save'), 'label' => _('Save'),
'decorators' => array( 'decorators' => array(
'ViewHelper' 'ViewHelper'
) )
)); ));
// Add the cancel button // Add the cancel button
$this->addElement('button', 'his_file_cancel', array( $this->addElement('button', 'his_file_cancel', array(
'ignore' => true, 'ignore' => true,
'class' => 'btn', 'class' => 'btn his_file_cancel',
'label' => _('Cancel'), 'label' => _('Cancel'),
'decorators' => array( 'decorators' => array(
'ViewHelper' 'ViewHelper'
) )
)); ));
$this->addDisplayGroup( $this->addDisplayGroup(
array( array(
'his_file_save', 'his_file_save',
'his_file_cancel' 'his_file_cancel'
), ),
'submitButtons', 'submitButtons',
array( array(
'decorators' => array( 'decorators' => array(
'FormElements', 'FormElements',

View file

@ -58,43 +58,6 @@ class Application_Model_Datatables
public static function findEntries($con, $displayColumns, $fromTable, public static function findEntries($con, $displayColumns, $fromTable,
$data, $dataProp = "aaData") $data, $dataProp = "aaData")
{ {
$librarySetting =
Application_Model_Preference::getCurrentLibraryTableColumnMap();
//$displayColumns[] = 'owner';
// 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;
} elseif (strstr($key, "sSearch_")) {
list($dump, $index) = explode("_", $key);
$orig2searchTerm[$index] = $d;
}
}
// map that maps dbname to searchTerm
$dbname2searchTerm = array();
foreach ($current2dbname as $currentPos => $dbname) {
$new_index = $librarySetting($currentPos);
// TODO : Fix this retarded hack later. Just a band aid for
// now at least we print some warnings so that we don't
// forget about this -- cc-4462
if ( array_key_exists($new_index, $orig2searchTerm) ) {
$dbname2searchTerm[$dbname] = $orig2searchTerm[$new_index];
} else {
Logging::warn("Trying to reorder to unknown index
printing as much debugging as possible...");
$debug = array(
'$new_index' => $new_index,
'$currentPos' => $currentPos,
'$orig2searchTerm' => $orig2searchTerm);
Logging::warn($debug);
}
}
$where = array(); $where = array();
/* Holds the parameters for binding after the statement has been /* Holds the parameters for binding after the statement has been
@ -102,6 +65,45 @@ class Application_Model_Datatables
$params = array(); $params = array();
if (isset($data['advSearch']) && $data['advSearch'] === 'true') { if (isset($data['advSearch']) && $data['advSearch'] === 'true') {
$librarySetting =
Application_Model_Preference::getCurrentLibraryTableColumnMap();
//$displayColumns[] = 'owner';
// 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;
} elseif (strstr($key, "sSearch_")) {
list($dump, $index) = explode("_", $key);
$orig2searchTerm[$index] = $d;
}
}
// map that maps dbname to searchTerm
$dbname2searchTerm = array();
foreach ($current2dbname as $currentPos => $dbname) {
$new_index = $librarySetting($currentPos);
// TODO : Fix this retarded hack later. Just a band aid for
// now at least we print some warnings so that we don't
// forget about this -- cc-4462
if ( array_key_exists($new_index, $orig2searchTerm) ) {
$dbname2searchTerm[$dbname] = $orig2searchTerm[$new_index];
} else {
Logging::warn("Trying to reorder to unknown index
printing as much debugging as possible...");
$debug = array(
'$new_index' => $new_index,
'$currentPos' => $currentPos,
'$orig2searchTerm' => $orig2searchTerm);
Logging::warn($debug);
}
}
$advancedWhere = self::buildWhereClauseForAdvancedSearch($dbname2searchTerm); $advancedWhere = self::buildWhereClauseForAdvancedSearch($dbname2searchTerm);
if (!empty($advancedWhere['clause'])) { if (!empty($advancedWhere['clause'])) {
$where[] = join(" AND ", $advancedWhere['clause']); $where[] = join(" AND ", $advancedWhere['clause']);
@ -119,7 +121,6 @@ class Application_Model_Datatables
$sql = $selectorCount." FROM ".$fromTable; $sql = $selectorCount." FROM ".$fromTable;
$sqlTotalRows = $sql; $sqlTotalRows = $sql;
if (isset($searchTerms)) { if (isset($searchTerms)) {
$searchCols = array(); $searchCols = array();
for ($i = 0; $i < $data["iColumns"]; $i++) { for ($i = 0; $i < $data["iColumns"]; $i++) {
@ -164,57 +165,47 @@ class Application_Model_Datatables
$sql = $selectorRows." FROM ".$fromTable." WHERE ".$where." ORDER BY ".$orderby; $sql = $selectorRows." FROM ".$fromTable." WHERE ".$where." ORDER BY ".$orderby;
//limit the results returned.
if ($displayLength !== -1) {
$sql .= " OFFSET ".$data["iDisplayStart"]." LIMIT ".$displayLength;
}
} else {
$sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby;
//limit the results returned.
if ($displayLength !== -1) {
$sql .= " OFFSET ".$data["iDisplayStart"]." LIMIT ".$displayLength;
}
} }
else {
$sql = $selectorRows." FROM ".$fromTable." ORDER BY ".$orderby;
}
//limit the results returned.
if ($displayLength !== -1) {
$sql .= " OFFSET ".$data["iDisplayStart"]." LIMIT ".$displayLength;
}
try { try {
Logging::info($sqlTotalRows);
$r = $con->query($sqlTotalRows); $r = $con->query($sqlTotalRows);
$totalRows = $r->fetchColumn(0); $totalRows = $r->fetchColumn(0);
if (isset($sqlTotalDisplayRows)) { if (isset($sqlTotalDisplayRows)) {
Logging::info("sql is set");
Logging::info($sqlTotalDisplayRows);
$totalDisplayRows = Application_Common_Database::prepareAndExecute($sqlTotalDisplayRows, $params, 'column'); $totalDisplayRows = Application_Common_Database::prepareAndExecute($sqlTotalDisplayRows, $params, 'column');
} else { }
else {
Logging::info("sql is not set.");
$totalDisplayRows = $totalRows; $totalDisplayRows = $totalRows;
} }
//TODO //TODO
if ($needToBind) { if ($needToBind) {
$results = Application_Common_Database::prepareAndExecute($sql, $params); $results = Application_Common_Database::prepareAndExecute($sql, $params);
} else { }
else {
$stmt = $con->query($sql); $stmt = $con->query($sql);
$stmt->setFetchMode(PDO::FETCH_ASSOC); $stmt->setFetchMode(PDO::FETCH_ASSOC);
$results = $stmt->fetchAll(); $results = $stmt->fetchAll();
} }
// we need to go over all items and fix length for playlist
// in case the playlist contains dynamic block
foreach ($results as &$r) {
//this function is also called for Manage Users so in
//this case there will be no 'ftype'
if (isset($r['ftype'])) {
if ($r['ftype'] == 'playlist') {
$pl = new Application_Model_Playlist($r['id']);
$r['length'] = $pl->getLength();
} elseif ($r['ftype'] == "block") {
$bl = new Application_Model_Block($r['id']);
$r['bl_type'] = $bl->isStatic() ? 'static' : 'dynamic';
$r['length'] = $bl->getLength();
}
}
}
} catch (Exception $e) {
Logging::debug($e->getMessage());
} }
catch (Exception $e) {
Logging::info($e->getMessage());
}
return array( return array(
"sEcho" => intval($data["sEcho"]), "sEcho" => intval($data["sEcho"]),
"iTotalDisplayRecords" => intval($totalDisplayRows), "iTotalDisplayRecords" => intval($totalDisplayRows),

View file

@ -778,6 +778,18 @@ SQL;
foreach ($results['aaData'] as &$row) { foreach ($results['aaData'] as &$row) {
$row['id'] = intval($row['id']); $row['id'] = intval($row['id']);
//taken from Datatables.php, needs to be cleaned up there.
if (isset($r['ftype'])) {
if ($r['ftype'] == 'playlist') {
$pl = new Application_Model_Playlist($r['id']);
$r['length'] = $pl->getLength();
} elseif ($r['ftype'] == "block") {
$bl = new Application_Model_Block($r['id']);
$r['bl_type'] = $bl->isStatic() ? 'static' : 'dynamic';
$r['length'] = $bl->getLength();
}
}
if ($row['ftype'] === "audioclip") { if ($row['ftype'] === "audioclip") {
$cuein_formatter = new LengthFormatter($row["cuein"]); $cuein_formatter = new LengthFormatter($row["cuein"]);

View file

@ -6,7 +6,7 @@ class Application_Service_HistoryService
{ {
private $con; private $con;
private $timezone; private $timezone;
private $mDataPropMap = array ( private $mDataPropMap = array (
"artist" => "artist_name", "artist" => "artist_name",
"title" => "track_title", "title" => "track_title",
@ -14,131 +14,200 @@ class Application_Service_HistoryService
"length" => "length", "length" => "length",
"composer" => "composer", "composer" => "composer",
"copyright" => "copyright", "copyright" => "copyright",
"starts" => "starts",
"ends" => "ends"
); );
public function __construct() public function __construct()
{ {
$this->con = isset($con) ? $con : Propel::getConnection(CcPlayoutHistoryPeer::DATABASE_NAME); $this->con = isset($con) ? $con : Propel::getConnection(CcPlayoutHistoryPeer::DATABASE_NAME);
$this->timezone = date_default_timezone_get(); $this->timezone = date_default_timezone_get();
} }
/* /*
* map front end mDataProp labels to proper column names for searching etc. * map front end mDataProp labels to proper column names for searching etc.
*/ */
private function translateColumns($opts) private function translateColumns($opts)
{ {
for ($i = 0; $i < $opts["iColumns"]; $i++) { for ($i = 0; $i < $opts["iColumns"]; $i++) {
if ($opts["bSearchable_{$i}"] === "true") { if ($opts["bSearchable_{$i}"] === "true") {
$opts["mDataProp_{$i}"] = $this->mDataPropMap[$opts["mDataProp_{$i}"]]; $opts["mDataProp_{$i}"] = $this->mDataPropMap[$opts["mDataProp_{$i}"]];
} }
} }
} }
public function getListView($startDT, $endDT, $opts)
{
$this->translateColumns($opts);
$select = array (
"file.track_title as title",
"file.artist_name as artist",
"playout.starts",
"playout.ends",
"playout.history_id"
);
$start = $startDT->format("Y-m-d H:i:s");
$end = $endDT->format("Y-m-d H:i:s");
$historyTable = "(
select history.starts as starts, history.ends as ends,
history.id as history_id, history.file_id as file_id
from cc_playout_history as history
where history.starts >= '{$start}' and history.starts < '{$end}'
) AS playout
left join cc_files as file on (file.id = playout.file_id)";
$results = Application_Model_Datatables::findEntries($this->con, $select, $historyTable, $opts, "history");
return $results;
}
public function getAggregateView($startDT, $endDT, $opts) public function getAggregateView($startDT, $endDT, $opts)
{ {
$this->translateColumns($opts); $this->translateColumns($opts);
$select = array ( $select = array (
"file.track_title as title", "file.track_title as title",
"file.artist_name as artist", "file.artist_name as artist",
"playout.played", "playout.played as played",
"playout.file_id", "playout.file_id",
"file.composer", "file.composer as composer",
"file.copyright", "file.copyright as copyright",
"file.length" "file.length as length"
); );
$start = $startDT->format("Y-m-d H:i:s"); $start = $startDT->format("Y-m-d H:i:s");
$end = $endDT->format("Y-m-d H:i:s"); $end = $endDT->format("Y-m-d H:i:s");
$historyTable = "( $historyTable = "(
select count(history.file_id) as played, history.file_id as file_id select count(history.file_id) as played, history.file_id as file_id
from cc_playout_history as history from cc_playout_history as history
where history.starts >= '{$start}' and history.starts < '{$end}' where history.starts >= '{$start}' and history.starts < '{$end}'
group by history.file_id group by history.file_id
) AS playout ) AS playout
left join cc_files as file on (file.id = playout.file_id)"; left join cc_files as file on (file.id = playout.file_id)";
$results = Application_Model_Datatables::findEntries($this->con, $select, $historyTable, $opts, "history"); $results = Application_Model_Datatables::findEntries($this->con, $select, $historyTable, $opts, "history");
foreach ($results["history"] as &$row) { foreach ($results["history"] as &$row) {
$formatter = new LengthFormatter($row['length']); $formatter = new LengthFormatter($row['length']);
$row['length'] = $formatter->format(); $row['length'] = $formatter->format();
} }
return $results; return $results;
} }
public function insertPlayedItem($schedId) { public function insertPlayedItem($schedId) {
$this->con->beginTransaction(); $this->con->beginTransaction();
try { try {
$item = CcScheduleQuery::create()->findPK($schedId, $this->con); $item = CcScheduleQuery::create()->findPK($schedId, $this->con);
//TODO figure out how to combine these all into 1 query. //TODO figure out how to combine these all into 1 query.
$showInstance = $item->getCcShowInstances($this->con); $showInstance = $item->getCcShowInstances($this->con);
$show = $showInstance->getCcShow($this->con); $show = $showInstance->getCcShow($this->con);
$fileId = $item->getDbFileId(); $fileId = $item->getDbFileId();
//don't add webstreams //don't add webstreams
if (isset($fileId)) { if (isset($fileId)) {
//$starts = $item->getDbStarts(null); //$starts = $item->getDbStarts(null);
//$ends = $item->getDbEnds(null); //$ends = $item->getDbEnds(null);
$metadata = array(); $metadata = array();
//$metadata["date"] = $starts->format('Y-m-d'); //$metadata["date"] = $starts->format('Y-m-d');
//$metadata["start"] = $starts->format('H:i:s'); //$metadata["start"] = $starts->format('H:i:s');
//$metadata["end"] = $ends->format('H:i:s'); //$metadata["end"] = $ends->format('H:i:s');
$metadata["showname"] = $show->getDbName(); $metadata["showname"] = $show->getDbName();
$history = new CcPlayoutHistory(); $history = new CcPlayoutHistory();
$history->setDbFileId($fileId); $history->setDbFileId($fileId);
$history->setDbStarts($item->getDbStarts(null)); $history->setDbStarts($item->getDbStarts(null));
$history->setDbEnds($item->getDbEnds(null)); $history->setDbEnds($item->getDbEnds(null));
foreach ($metadata as $key => $val) { foreach ($metadata as $key => $val) {
$meta = new CcPlayoutHistoryMetaData(); $meta = new CcPlayoutHistoryMetaData();
$meta->setDbKey($key); $meta->setDbKey($key);
$meta->setDbValue($val); $meta->setDbValue($val);
$history->addCcPlayoutHistoryMetaData($meta); $history->addCcPlayoutHistoryMetaData($meta);
} }
$history->save($this->con); $history->save($this->con);
} }
$this->con->commit(); $this->con->commit();
} }
catch (Exception $e) { catch (Exception $e) {
$this->con->rollback(); $this->con->rollback();
throw $e; throw $e;
} }
} }
public function makeHistoryItemForm() { /* id is an id in cc_playout_history */
public function makeHistoryItemForm($id) {
} }
/* id is an id in cc_files */
public function makeHistoryFileForm($id) { public function makeHistoryFileForm($id) {
$form = new Application_Form_EditHistoryFile(); try {
$form = new Application_Form_EditHistoryFile();
return $form;
$file = Application_Model_StoredFile::RecallById($id, $this->con);
$md = $file->getDbColMetadata();
$form->populate(array(
'his_file_id' => $id,
'his_file_title' => $md[MDATA_KEY_TITLE],
'his_file_creator' => $md[MDATA_KEY_CREATOR],
'his_file_composer' => $md[MDATA_KEY_COMPOSER],
'his_file_copyright' => $md[MDATA_KEY_COPYRIGHT]
));
return $form;
}
catch (Exception $e) {
Logging::debug($e);
}
} }
/* id is an id in cc_playout_history */ /* id is an id in cc_playout_history */
public function editPlayedItem($id) { public function editPlayedItem($id) {
} }
/* id is an id in cc_files */ /* id is an id in cc_files */
public function editPlayedFile($id) { public function editPlayedFile($data) {
$form = new Application_Form_EditHistoryFile();
$json = $form->processAjax($data);
Logging::info($json);
if ($form->isValid($data)) {
$id = $data["his_file_id"];
$file = Application_Model_StoredFile::RecallById($id, $this->con);
$md = array(
MDATA_KEY_TITLE => $data['his_file_title'],
MDATA_KEY_CREATOR => $data['his_file_creator'],
MDATA_KEY_COMPOSER => $data['his_file_composer'],
MDATA_KEY_COPYRIGHT => $data['his_file_copyright']
);
$file->setDbColMetadata($md);
}
return $json;
} }
} }

View file

@ -1,3 +1,3 @@
<div class="ui-widget ui-widget-content block-shadow simple-formblock clearfix padded-strong" id="edit-history-file"> <div class="ui-widget ui-widget-content block-shadow simple-formblock clearfix padded-strong" id="edit-history-file">
<?php echo $this->form; ?> <?php echo $this->form; ?>
</div> </div>

View file

@ -1,4 +1,18 @@
<div id="history_content" class="ui-widget ui-widget-content block-shadow alpha-block padded"> <div id="history_content" class="ui-widget ui-widget-content block-shadow alpha-block padded">
<?php echo $this->date_form; ?> <?php echo $this->date_form; ?>
<table id="history_table" cellpadding="0" cellspacing="0" class="datatable"></table>
<div id="his-tabs">
<ul>
<li><a href="#his-tabs-1"><?php echo _("Aggregate"); ?></a></li>
<li><a href="#his-tabs-2"><?php echo _("List"); ?></a></li>
</ul>
<div id="his-tabs-1">
<table id="history_table_aggregate" cellpadding="0" cellspacing="0" class="datatable"></table>
</div>
<div id="his-tabs-2">
<table id="history_table_list" cellpadding="0" cellspacing="0" class="datatable"></table>
</div>
</div>
</div> </div>

View file

@ -1,35 +1,3 @@
function getFileName(ext){
var filename = $("#his_date_start").val()+"_"+$("#his_time_start").val()+"m--"+$("#his_date_end").val()+"_"+$("#his_time_end").val()+"m";
filename = filename.replace(/:/g,"h");
if (ext == "pdf"){
filename = filename+".pdf";
}
else {
filename = filename+".csv";
}
return filename;
}
function setFlashFileName( nButton, oConfig, oFlash ) {
var filename = getFileName(oConfig.sExtends);
oFlash.setFileName( filename );
if (oConfig.sExtends == "pdf") {
this.fnSetText( oFlash,
"title:"+ this.fnGetTitle(oConfig) +"\n"+
"message:"+ oConfig.sPdfMessage +"\n"+
"colWidth:"+ this.fnCalcColRatios(oConfig) +"\n"+
"orientation:"+ oConfig.sPdfOrientation +"\n"+
"size:"+ oConfig.sPdfSize +"\n"+
"--/TableToolsOpts--\n" +
this.fnGetTableData(oConfig));
}
else {
this.fnSetText(oFlash, this.fnGetTableData(oConfig));
}
}
var AIRTIME = (function(AIRTIME) { var AIRTIME = (function(AIRTIME) {
var mod; var mod;
@ -38,33 +6,97 @@ var AIRTIME = (function(AIRTIME) {
} }
mod = AIRTIME.history; mod = AIRTIME.history;
mod.historyTable = function() { var $historyContentDiv;
var oTable,
historyContentDiv = $("#history_content"), var oTableTools = {
historyTableDiv = historyContentDiv.find("#history_table"), "sSwfPath": baseUrl+"js/datatables/plugin/TableTools/swf/copy_cvs_xls_pdf.swf",
tableHeight = historyContentDiv.height() - 200, "aButtons": [
fnServerData; {
"sExtends": "copy",
fnServerData = function ( sSource, aoData, fnCallback ) { "fnComplete": function(nButton, oConfig, oFlash, text) {
var lines = text.split('\n').length,
if (fnServerData.hasOwnProperty("start")) { len = this.s.dt.nTFoot === null ? lines-1 : lines-2,
aoData.push( { name: "start", value: fnServerData.start} ); plural = (len==1) ? "" : "s";
} alert(sprintf($.i18n._('Copied %s row%s to the clipboard'), len, plural));
if (fnServerData.hasOwnProperty("end")) { }
aoData.push( { name: "end", value: fnServerData.end} ); },
} {
"sExtends": "csv",
aoData.push( { name: "format", value: "json"} ); "fnClick": setFlashFileName
},
$.ajax( { {
"dataType": 'json', "sExtends": "pdf",
"type": "GET", "fnClick": setFlashFileName
"url": sSource, },
"data": aoData, {
"success": fnCallback "sExtends": "print",
} ); "sInfo" : sprintf($.i18n._("%sPrint view%sPlease use your browser's print function to print this table. Press escape when finished."), "<h6>", "</h6><p>")
}, }
]
};
var lengthMenu = [[50, 100, 500, -1], [50, 100, 500, $.i18n._("All")]];
var sDom = 'lf<"dt-process-rel"r><"H"T><"dataTables_scrolling"t><"F"ip>';
function getFileName(ext){
var filename = $("#his_date_start").val()+"_"+$("#his_time_start").val()+"m--"+$("#his_date_end").val()+"_"+$("#his_time_end").val()+"m";
filename = filename.replace(/:/g,"h");
if (ext == "pdf"){
filename = filename+".pdf";
}
else {
filename = filename+".csv";
}
return filename;
}
function setFlashFileName( nButton, oConfig, oFlash ) {
var filename = getFileName(oConfig.sExtends);
oFlash.setFileName( filename );
if (oConfig.sExtends == "pdf") {
this.fnSetText( oFlash,
"title:"+ this.fnGetTitle(oConfig) +"\n"+
"message:"+ oConfig.sPdfMessage +"\n"+
"colWidth:"+ this.fnCalcColRatios(oConfig) +"\n"+
"orientation:"+ oConfig.sPdfOrientation +"\n"+
"size:"+ oConfig.sPdfSize +"\n"+
"--/TableToolsOpts--\n" +
this.fnGetTableData(oConfig));
}
else {
this.fnSetText(oFlash, this.fnGetTableData(oConfig));
}
}
/* This callback can be used for all history tables */
function fnServerData( sSource, aoData, fnCallback ) {
if (fnServerData.hasOwnProperty("start")) {
aoData.push( { name: "start", value: fnServerData.start} );
}
if (fnServerData.hasOwnProperty("end")) {
aoData.push( { name: "end", value: fnServerData.end} );
}
aoData.push( { name: "format", value: "json"} );
$.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
function aggregateHistoryTable() {
var oTable,
$historyTableDiv = $historyContentDiv.find("#history_table_aggregate"),
fnRowCallback;
fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) { fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var url = baseUrl+"Playouthistory/edit-aggregate-item/format/json/id/"+aData.file_id, var url = baseUrl+"Playouthistory/edit-aggregate-item/format/json/id/"+aData.file_id,
$link = $("<a/>", { $link = $("<a/>", {
@ -75,7 +107,7 @@ var AIRTIME = (function(AIRTIME) {
$('td.his_edit', nRow).html($link); $('td.his_edit', nRow).html($link);
}; };
oTable = historyTableDiv.dataTable( { oTable = $historyTableDiv.dataTable( {
"aoColumns": [ "aoColumns": [
{"sTitle": $.i18n._("Title"), "mDataProp": "title", "sClass": "his_title"}, /* Title */ {"sTitle": $.i18n._("Title"), "mDataProp": "title", "sClass": "his_title"}, /* Title */
@ -89,150 +121,199 @@ var AIRTIME = (function(AIRTIME) {
"bProcessing": true, "bProcessing": true,
"bServerSide": true, "bServerSide": true,
"sAjaxSource": baseUrl+"Playouthistory/playout-history-feed", "sAjaxSource": baseUrl+"playouthistory/aggregate-history-feed",
"sAjaxDataProp": "history", "sAjaxDataProp": "history",
"fnServerData": fnServerData, "fnServerData": fnServerData,
"fnRowCallback": fnRowCallback, "fnRowCallback": fnRowCallback,
"oLanguage": datatables_dict, "oLanguage": datatables_dict,
"aLengthMenu": lengthMenu,
"aLengthMenu": [[50, 100, 500, -1], [50, 100, 500, $.i18n._("All")]],
"iDisplayLength": 50, "iDisplayLength": 50,
"sPaginationType": "full_numbers", "sPaginationType": "full_numbers",
"bJQueryUI": true, "bJQueryUI": true,
"bAutoWidth": true, "bAutoWidth": true,
"sDom": sDom,
"sDom": 'lf<"dt-process-rel"r><"H"T><"dataTables_scrolling"t><"F"ip>', "oTableTools": oTableTools
"oTableTools": {
"sSwfPath": baseUrl+"js/datatables/plugin/TableTools/swf/copy_cvs_xls_pdf.swf",
"aButtons": [
{
"sExtends": "copy",
"fnComplete": function(nButton, oConfig, oFlash, text) {
var lines = text.split('\n').length,
len = this.s.dt.nTFoot === null ? lines-1 : lines-2,
plural = (len==1) ? "" : "s";
alert(sprintf($.i18n._('Copied %s row%s to the clipboard'), len, plural));
}
},
{
"sExtends": "csv",
"fnClick": setFlashFileName
},
{
"sExtends": "pdf",
"fnClick": setFlashFileName
},
{
"sExtends": "print",
"sInfo" : sprintf($.i18n._("%sPrint view%sPlease use your browser's print function to print this table. Press escape when finished."), "<h6>", "</h6><p>")
}
]
}
}); });
oTable.fnSetFilteringDelay(350); oTable.fnSetFilteringDelay(350);
historyContentDiv.find(".dataTables_scrolling").css("max-height", tableHeight);
return oTable; return oTable;
}
function itemHistoryTable() {
var oTable,
$historyTableDiv = $historyContentDiv.find("#history_table_list"),
fnRowCallback;
fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var url = baseUrl+"playouthistory/edit-list-item/format/json/id/"+aData.history_id,
$link = $("<a/>", {
"href": url,
"text": $.i18n._("Edit")
});
$('td.his_edit', nRow).html($link);
};
oTable = $historyTableDiv.dataTable( {
"aoColumns": [
{"sTitle": $.i18n._("Start"), "mDataProp": "starts", "sClass": "his_starts"}, /* Starts */
{"sTitle": $.i18n._("End"), "mDataProp": "ends", "sClass": "his_ends"}, /* Ends */
{"sTitle": $.i18n._("Title"), "mDataProp": "title", "sClass": "his_title"}, /* Title */
{"sTitle": $.i18n._("Creator"), "mDataProp": "artist", "sClass": "his_artist"}, /* Creator */
{"sTitle" : $.i18n._("Admin"), "mDataProp": "history_id", "bSearchable" : false, "sClass": "his_edit"}, /* id of history item */
],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": baseUrl+"playouthistory/item-history-feed",
"sAjaxDataProp": "history",
"fnServerData": fnServerData,
"fnRowCallback": fnRowCallback,
"oLanguage": datatables_dict,
"aLengthMenu": lengthMenu,
"iDisplayLength": 50,
"sPaginationType": "full_numbers",
"bJQueryUI": true,
"bAutoWidth": true,
"sDom": sDom,
"oTableTools": oTableTools
});
oTable.fnSetFilteringDelay(350);
return oTable;
}
mod.onReady = function() {
var viewport = AIRTIME.utilities.findViewportDimensions(),
widgetHeight = viewport.height - 185,
screenWidth = Math.floor(viewport.width - 110),
oBaseDatePickerSettings,
oBaseTimePickerSettings,
oTable,
dateStartId = "#his_date_start",
timeStartId = "#his_time_start",
dateEndId = "#his_date_end",
timeEndId = "#his_time_end",
$hisDialogEl;
$historyContentDiv = $("#history_content");
function removeHistoryDialog() {
$hisDialogEl.dialog("destroy");
$hisDialogEl.remove();
}
function makeHistoryDialog(html) {
$hisDialogEl = $(html);
$hisDialogEl.dialog({
title: $.i18n._("Edit History Record"),
modal: true,
close: function() {
removeHistoryDialog();
}
});
}
/*
* Icon hover states for search.
*/
$historyContentDiv.on("mouseenter", ".his-timerange .ui-button", function(ev) {
$(this).addClass("ui-state-hover");
});
$historyContentDiv.on("mouseleave", ".his-timerange .ui-button", function(ev) {
$(this).removeClass("ui-state-hover");
});
$historyContentDiv
.height(widgetHeight)
.width(screenWidth);
oBaseDatePickerSettings = {
dateFormat: 'yy-mm-dd',
//i18n_months, i18n_days_short are in common.js
monthNames: i18n_months,
dayNamesMin: i18n_days_short,
onSelect: function(sDate, oDatePicker) {
$(this).datepicker( "setDate", sDate );
}
};
oBaseTimePickerSettings = {
showPeriodLabels: false,
showCloseButton: true,
closeButtonText: $.i18n._("Done"),
showLeadingZero: false,
defaultTime: '0:00',
hourText: $.i18n._("Hour"),
minuteText: $.i18n._("Minute")
};
oTable = aggregateHistoryTable();
itemHistoryTable();
$historyContentDiv.find(dateStartId).datepicker(oBaseDatePickerSettings);
$historyContentDiv.find(timeStartId).timepicker(oBaseTimePickerSettings);
$historyContentDiv.find(dateEndId).datepicker(oBaseDatePickerSettings);
$historyContentDiv.find(timeEndId).timepicker(oBaseTimePickerSettings);
$historyContentDiv.on("click", "td.his_edit", function(e) {
var url = e.target.href;
e.preventDefault();
$.get(url, function(json) {
makeHistoryDialog(json.dialog);
}, "json");
});
$('body').on("click", ".his_file_save", function(e) {
e.preventDefault();
var $form = $(this).parents("form");
var data = $form.serializeArray();
var url = baseUrl+"Playouthistory/update-aggregate-item/format/json";
$.post(url, data, function(json) {
//TODO put errors on form.
if (json.data !== "true") {
//makeHistoryDialog(json.dialog);
}
else {
removeHistoryDialog();
oTable.fnDraw();
}
}, "json");
});
$historyContentDiv.find("#his_submit").click(function(ev){
var fn,
oRange;
oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId);
fn = oTable.fnSettings().fnServerData;
fn.start = oRange.start;
fn.end = oRange.end;
oTable.fnDraw();
});
$historyContentDiv.find("#his-tabs").tabs();
}; };
return AIRTIME; return AIRTIME;
}(AIRTIME || {})); }(AIRTIME || {}));
$(document).ready(function(){ $(document).ready(AIRTIME.history.onReady);
var viewport = AIRTIME.utilities.findViewportDimensions(),
history_content = $("#history_content"),
widgetHeight = viewport.height - 185,
screenWidth = Math.floor(viewport.width - 110),
oBaseDatePickerSettings,
oBaseTimePickerSettings,
oTable,
dateStartId = "#his_date_start",
timeStartId = "#his_time_start",
dateEndId = "#his_date_end",
timeEndId = "#his_time_end";
/*
* Icon hover states for search.
*/
history_content.on("mouseenter", ".his-timerange .ui-button", function(ev) {
$(this).addClass("ui-state-hover");
});
history_content.on("mouseleave", ".his-timerange .ui-button", function(ev) {
$(this).removeClass("ui-state-hover");
});
history_content
.height(widgetHeight)
.width(screenWidth);
oBaseDatePickerSettings = {
dateFormat: 'yy-mm-dd',
//i18n_months, i18n_days_short are in common.js
monthNames: i18n_months,
dayNamesMin: i18n_days_short,
onSelect: function(sDate, oDatePicker) {
$(this).datepicker( "setDate", sDate );
}
};
oBaseTimePickerSettings = {
showPeriodLabels: false,
showCloseButton: true,
closeButtonText: $.i18n._("Done"),
showLeadingZero: false,
defaultTime: '0:00',
hourText: $.i18n._("Hour"),
minuteText: $.i18n._("Minute")
};
oTable = AIRTIME.history.historyTable();
history_content.find(dateStartId).datepicker(oBaseDatePickerSettings);
history_content.find(timeStartId).timepicker(oBaseTimePickerSettings);
history_content.find(dateEndId).datepicker(oBaseDatePickerSettings);
history_content.find(timeEndId).timepicker(oBaseTimePickerSettings);
history_content.on("click", "td.his_edit", function(e) {
var url = e.target.href;
e.preventDefault();
$.get(url, function(json) {
var dialog = $(json.dialog);
dialog.dialog({
autoOpen: false,
title: $.i18n._("Edit History Record"),
//width: 460,
//height: 660,
modal: true
//close: closeDialogLibrary
});
dialog.dialog('open');
}, "json");
});
history_content.find("#his_submit").click(function(ev){
var fn,
oRange;
oRange = AIRTIME.utilities.fnGetScheduleRange(dateStartId, timeStartId, dateEndId, timeEndId);
fn = oTable.fnSettings().fnServerData;
fn.start = oRange.start;
fn.end = oRange.end;
oTable.fnDraw();
});
});