IM-784 : Create Editing Abilities For History

This commit is contained in:
Naomi 2013-07-08 18:00:02 -04:00
parent 1abbe85d6d
commit c744d88f23
7 changed files with 209 additions and 30 deletions

View File

@ -7,6 +7,7 @@ class PlayouthistoryController extends Zend_Controller_Action
$ajaxContext = $this->_helper->getHelper('AjaxContext'); $ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext $ajaxContext
->addActionContext('playout-history-feed', 'json') ->addActionContext('playout-history-feed', 'json')
->addActionContext('edit-aggregate-item', 'json')
->initContext(); ->initContext();
} }
@ -71,7 +72,7 @@ class PlayouthistoryController extends Zend_Controller_Action
$endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC"));
$historyService = new Application_Service_HistoryService(); $historyService = new Application_Service_HistoryService();
$r = $historyService->getItems($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"];
@ -79,4 +80,25 @@ class PlayouthistoryController extends Zend_Controller_Action
$this->view->history = $r["history"]; $this->view->history = $r["history"];
} }
public function editAggregateItemAction()
{
$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()
{
$file_id = $this->_getParam('id');
$historyService = new Application_Service_HistoryService();
$historyService->editPlayedFile($file_id);
}
} }

View File

@ -0,0 +1,86 @@
<?php
class Application_Form_EditHistoryFile extends Zend_Form
{
public function init() {
/*
$this->setDecorators(
array(
array('ViewScript', array('viewScript' => 'form/edit-history-file.phtml'))
)
);
*/
$this->setMethod('post');
$this->addElement('hidden', 'file_id');
/* Title form element */
$title = new Zend_Form_Element_Text('his_file_title');
$title->setLabel(_('Title:'));
$title->setAttrib('class', 'input_text');
$title->addFilter('StringTrim');
//$title->setDecorators(array('viewHelper'));
$this->addElement($title);
/* Creator form element */
$creator = new Zend_Form_Element_Text('his_file_creator');
$creator->setLabel(_('Creator:'));
$creator->setAttrib('class', 'input_text');
$creator->addFilter('StringTrim');
//$creator->setDecorators(array('viewHelper'));
$this->addElement($creator);
/* Composer form element */
$composer = new Zend_Form_Element_Text('his_file_composer');
$composer->setLabel(_('Composer:'));
$composer->setAttrib('class', 'input_text');
$composer->addFilter('StringTrim');
//$composer->setDecorators(array('viewHelper'));
$this->addElement($composer);
/* Copyright form element */
$copyright = new Zend_Form_Element_Text('his_file_copyright');
$copyright->setLabel(_('Copyright:'));
$copyright->setAttrib('class', 'input_text');
$copyright->addFilter('StringTrim');
//$copyright->setDecorators(array('viewHelper'));
$this->addElement($copyright);
// Add the submit button
$this->addElement('button', 'his_file_save', array(
'ignore' => true,
'class' => 'btn',
'label' => _('Save'),
'decorators' => array(
'ViewHelper'
)
));
// Add the cancel button
$this->addElement('button', 'his_file_cancel', array(
'ignore' => true,
'class' => 'btn',
'label' => _('Cancel'),
'decorators' => array(
'ViewHelper'
)
));
$this->addDisplayGroup(
array(
'his_file_save',
'his_file_cancel'
),
'submitButtons',
array(
'decorators' => array(
'FormElements',
'DtDdWrapper'
)
)
);
}
}

View File

@ -0,0 +1,8 @@
<?php
class Application_Form_EditHistoryItem extends Zend_Form
{
public function init() {
}
}

View File

@ -7,13 +7,13 @@ 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",
"played" => "played", "played" => "played",
"length" => "length", "length" => "length",
"composer" => "composer", "composer" => "composer",
"copyright" => "copyright", "copyright" => "copyright",
); );
public function __construct() public function __construct()
@ -29,22 +29,24 @@ class Application_Service_HistoryService
{ {
for ($i = 0; $i < $opts["iColumns"]; $i++) { for ($i = 0; $i < $opts["iColumns"]; $i++) {
$opts["mDataProp_{$i}"] = $this->mDataPropMap[$opts["mDataProp_{$i}"]]; if ($opts["bSearchable_{$i}"] === "true") {
$opts["mDataProp_{$i}"] = $this->mDataPropMap[$opts["mDataProp_{$i}"]];
}
} }
} }
public function getItems($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",
"playout.file_id", "playout.file_id",
"file.composer", "file.composer",
"file.copyright", "file.copyright",
"file.length" "file.length"
); );
$start = $startDT->format("Y-m-d H:i:s"); $start = $startDT->format("Y-m-d H:i:s");
@ -118,4 +120,25 @@ class Application_Service_HistoryService
} }
} }
public function makeHistoryItemForm() {
}
public function makeHistoryFileForm($id) {
$form = new Application_Form_EditHistoryFile();
return $form;
}
/* id is an id in cc_playout_history */
public function editPlayedItem($id) {
}
/* id is an id in cc_files */
public function editPlayedFile($id) {
}
} }

View File

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

View File

@ -1,18 +1,21 @@
function getFileName(ext){ function getFileName(ext){
var filename = $("#his_date_start").val()+"_"+$("#his_time_start").val()+"m--"+$("#his_date_end").val()+"_"+$("#his_time_end").val()+"m" 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") filename = filename.replace(/:/g,"h");
if(ext == "pdf"){
filename = filename+".pdf" if (ext == "pdf"){
}else{ filename = filename+".pdf";
filename = filename+".csv" }
else {
filename = filename+".csv";
} }
return filename; return filename;
} }
function setFlashFileName( nButton, oConfig, oFlash ) { function setFlashFileName( nButton, oConfig, oFlash ) {
var filename = getFileName(oConfig.sExtends) var filename = getFileName(oConfig.sExtends);
oFlash.setFileName( filename ); oFlash.setFileName( filename );
if(oConfig.sExtends == "pdf"){
if (oConfig.sExtends == "pdf") {
this.fnSetText( oFlash, this.fnSetText( oFlash,
"title:"+ this.fnGetTitle(oConfig) +"\n"+ "title:"+ this.fnGetTitle(oConfig) +"\n"+
"message:"+ oConfig.sPdfMessage +"\n"+ "message:"+ oConfig.sPdfMessage +"\n"+
@ -21,9 +24,9 @@ function setFlashFileName( nButton, oConfig, oFlash ) {
"size:"+ oConfig.sPdfSize +"\n"+ "size:"+ oConfig.sPdfSize +"\n"+
"--/TableToolsOpts--\n" + "--/TableToolsOpts--\n" +
this.fnGetTableData(oConfig)); this.fnGetTableData(oConfig));
}else{ }
this.fnSetText( oFlash, else {
this.fnGetTableData(oConfig)); this.fnSetText(oFlash, this.fnGetTableData(oConfig));
} }
} }
@ -60,6 +63,16 @@ var AIRTIME = (function(AIRTIME) {
"data": aoData, "data": aoData,
"success": fnCallback "success": fnCallback
} ); } );
},
fnRowCallback = function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
var url = baseUrl+"Playouthistory/edit-aggregate-item/format/json/id/"+aData.file_id,
$link = $("<a/>", {
"href": url,
"text": $.i18n._("Edit")
});
$('td.his_edit', nRow).html($link);
}; };
oTable = historyTableDiv.dataTable( { oTable = historyTableDiv.dataTable( {
@ -70,7 +83,8 @@ var AIRTIME = (function(AIRTIME) {
{"sTitle": $.i18n._("Played"), "mDataProp": "played", "sClass": "his_artist"}, /* times played */ {"sTitle": $.i18n._("Played"), "mDataProp": "played", "sClass": "his_artist"}, /* times played */
{"sTitle": $.i18n._("Length"), "mDataProp": "length", "sClass": "his_length library_length"}, /* Length */ {"sTitle": $.i18n._("Length"), "mDataProp": "length", "sClass": "his_length library_length"}, /* Length */
{"sTitle": $.i18n._("Composer"), "mDataProp": "composer", "sClass": "his_composer"}, /* Composer */ {"sTitle": $.i18n._("Composer"), "mDataProp": "composer", "sClass": "his_composer"}, /* Composer */
{"sTitle": $.i18n._("Copyright"), "mDataProp": "copyright", "sClass": "his_copyright"} /* Copyright */ {"sTitle": $.i18n._("Copyright"), "mDataProp": "copyright", "sClass": "his_copyright"}, /* Copyright */
{"sTitle" : $.i18n._("Admin"), "mDataProp": "file_id", "bSearchable" : false, "sClass": "his_edit"}, /* id of history item */
], ],
"bProcessing": true, "bProcessing": true,
@ -80,6 +94,8 @@ var AIRTIME = (function(AIRTIME) {
"fnServerData": fnServerData, "fnServerData": fnServerData,
"fnRowCallback": fnRowCallback,
"oLanguage": datatables_dict, "oLanguage": datatables_dict,
"aLengthMenu": [[50, 100, 500, -1], [50, 100, 500, $.i18n._("All")]], "aLengthMenu": [[50, 100, 500, -1], [50, 100, 500, $.i18n._("All")]],
@ -184,6 +200,27 @@ $(document).ready(function(){
history_content.find(dateEndId).datepicker(oBaseDatePickerSettings); history_content.find(dateEndId).datepicker(oBaseDatePickerSettings);
history_content.find(timeEndId).timepicker(oBaseTimePickerSettings); 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){ history_content.find("#his_submit").click(function(ev){
var fn, var fn,