Editing templates, strictly typing metadata for datatables (for unions)
This commit is contained in:
parent
b33f33964a
commit
a5a99da21e
9 changed files with 386 additions and 246 deletions
|
@ -86,9 +86,10 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
||||||
|
|
||||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||||
|
|
||||||
//$view->headScript()->appendFile($baseUrl.'js/libs/jquery-1.7.2.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
$view->headScript()->appendFile($baseUrl.'js/libs/jquery-1.8.3.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
||||||
$view->headScript()->appendFile('http://code.jquery.com/jquery-1.10.1.js','text/javascript');
|
|
||||||
$view->headScript()->appendFile('http://code.jquery.com/jquery-migrate-1.2.1.js','text/javascript');
|
//$view->headScript()->appendFile('http://code.jquery.com/jquery-1.10.1.js','text/javascript');
|
||||||
|
//$view->headScript()->appendFile('http://code.jquery.com/jquery-migrate-1.2.1.js','text/javascript');
|
||||||
|
|
||||||
//$view->headScript()->appendFile($baseUrl.'js/libs/jquery-ui-1.8.18.custom.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
//$view->headScript()->appendFile($baseUrl.'js/libs/jquery-ui-1.8.18.custom.min.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
||||||
$view->headScript()->appendFile('http://code.jquery.com/ui/1.10.3/jquery-ui.js','text/javascript');
|
$view->headScript()->appendFile('http://code.jquery.com/ui/1.10.3/jquery-ui.js','text/javascript');
|
||||||
|
|
|
@ -15,7 +15,7 @@ class PlayouthistoryController extends Zend_Controller_Action
|
||||||
->addActionContext('update-list-item', 'json')
|
->addActionContext('update-list-item', 'json')
|
||||||
->addActionContext('update-aggregate-item', 'json')
|
->addActionContext('update-aggregate-item', 'json')
|
||||||
->addActionContext('create-template', 'json')
|
->addActionContext('create-template', 'json')
|
||||||
->addActionContext('edit-template', 'json')
|
->addActionContext('update-template', 'json')
|
||||||
->addActionContext('delete-template', 'json')
|
->addActionContext('delete-template', 'json')
|
||||||
->addActionContext('set-item-template-default', 'json')
|
->addActionContext('set-item-template-default', 'json')
|
||||||
->initContext();
|
->initContext();
|
||||||
|
@ -197,7 +197,14 @@ class PlayouthistoryController extends Zend_Controller_Action
|
||||||
|
|
||||||
public function templateAction()
|
public function templateAction()
|
||||||
{
|
{
|
||||||
|
$CC_CONFIG = Config::getConfig();
|
||||||
|
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||||
|
|
||||||
|
$this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/template.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
||||||
|
|
||||||
|
$historyService = new Application_Service_HistoryService();
|
||||||
|
$this->view->template_list = $historyService->getListItemTemplates();
|
||||||
|
$this->view->configured = $historyService->getConfiguredTemplateIds();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function configureItemTemplateAction() {
|
public function configureItemTemplateAction() {
|
||||||
|
@ -210,7 +217,7 @@ class PlayouthistoryController extends Zend_Controller_Action
|
||||||
$CC_CONFIG = Config::getConfig();
|
$CC_CONFIG = Config::getConfig();
|
||||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||||
|
|
||||||
$this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/template.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
$this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/itemtemplate.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
|
||||||
|
|
||||||
$template_id = $this->_getParam('id', null);
|
$template_id = $this->_getParam('id', null);
|
||||||
|
|
||||||
|
@ -225,6 +232,7 @@ class PlayouthistoryController extends Zend_Controller_Action
|
||||||
$this->view->fileMD = $historyService->getFileMetadataTypes();
|
$this->view->fileMD = $historyService->getFileMetadataTypes();
|
||||||
$this->view->fields = $historyService->getFieldTypes();
|
$this->view->fields = $historyService->getFieldTypes();
|
||||||
$this->view->required_fields = $mandatoryFields;
|
$this->view->required_fields = $mandatoryFields;
|
||||||
|
$this->view->configured = $historyService->getConfiguredTemplateIds();
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
Logging::info($e);
|
Logging::info($e);
|
||||||
|
@ -240,11 +248,15 @@ class PlayouthistoryController extends Zend_Controller_Action
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$historyService = new Application_Service_HistoryService();
|
$historyService = new Application_Service_HistoryService();
|
||||||
$historyService->createItemTemplate($params);
|
$id = $historyService->createItemTemplate($params);
|
||||||
|
|
||||||
|
$this->view->url = $this->view->baseUrl("Playouthistory/configure-item-template/id/{$id}");
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
Logging::info($e);
|
Logging::info($e);
|
||||||
Logging::info($e->getMessage());
|
Logging::info($e->getMessage());
|
||||||
|
|
||||||
|
$this->view->error = $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,13 +282,41 @@ class PlayouthistoryController extends Zend_Controller_Action
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function editTemplateAction()
|
public function updateTemplateAction()
|
||||||
{
|
{
|
||||||
|
$request = $this->getRequest();
|
||||||
|
$params = $request->getPost();
|
||||||
|
Logging::info($params);
|
||||||
|
|
||||||
|
$template_id = $this->_getParam('id', null);
|
||||||
|
$name = $this->_getParam('name', null);
|
||||||
|
$fields = $this->_getParam('fields', array());
|
||||||
|
|
||||||
|
if (empty($template_id)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$historyService = new Application_Service_HistoryService();
|
||||||
|
$historyService->updateItemTemplate($template_id, $name, $fields);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
Logging::info($e);
|
||||||
|
Logging::info($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteTemplateAction()
|
public function deleteTemplateAction()
|
||||||
{
|
{
|
||||||
|
$template_id = $this->_getParam('id');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$historyService = new Application_Service_HistoryService();
|
||||||
|
$historyService->deleteTemplate($template_id);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
Logging::info($e);
|
||||||
|
Logging::info($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ class Application_Service_HistoryService
|
||||||
{
|
{
|
||||||
$mainSqlQuery = "";
|
$mainSqlQuery = "";
|
||||||
$paramMap = array();
|
$paramMap = array();
|
||||||
|
$sqlTypes = $this->getSqlTypes();
|
||||||
|
|
||||||
$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");
|
||||||
|
@ -104,11 +105,12 @@ class Application_Service_HistoryService
|
||||||
|
|
||||||
$field = $fields_filemd[$i];
|
$field = $fields_filemd[$i];
|
||||||
$key = $field["name"];
|
$key = $field["name"];
|
||||||
|
$type = $sqlTypes[$field["type"]];
|
||||||
|
|
||||||
$fileSelect[] = "file_md.{$key}";
|
$fileSelect[] = "file_md.{$key}::{$type}";
|
||||||
$nonNullFileSelect[] = "file.{$key}";
|
$nonNullFileSelect[] = "file.{$key}::{$type}";
|
||||||
$nullFileSelect[] = "{$key}_filter.{$key}";
|
$nullFileSelect[] = "{$key}_filter.{$key}::{$type}";
|
||||||
$mainSelect[] = "file_info.{$key}";
|
$mainSelect[] = "file_info.{$key}::{$type}";
|
||||||
|
|
||||||
$fileMdFilters[] = str_replace("%KEY%", $key, $manualMeta);
|
$fileMdFilters[] = str_replace("%KEY%", $key, $manualMeta);
|
||||||
$paramMap["meta_{$key}"] = $key;
|
$paramMap["meta_{$key}"] = $key;
|
||||||
|
@ -159,10 +161,11 @@ class Application_Service_HistoryService
|
||||||
|
|
||||||
$field = $fields_general[$i];
|
$field = $fields_general[$i];
|
||||||
$key = $field["name"];
|
$key = $field["name"];
|
||||||
|
$type = $sqlTypes[$field["type"]];
|
||||||
|
|
||||||
$mdFilters[] = str_replace("%KEY%", $key, $manualMeta);
|
$mdFilters[] = str_replace("%KEY%", $key, $manualMeta);
|
||||||
$paramMap["meta_{$key}"] = $key;
|
$paramMap["meta_{$key}"] = $key;
|
||||||
$mainSelect[] = "{$key}_filter.{$key}";
|
$mainSelect[] = "{$key}_filter.{$key}::{$type}";
|
||||||
}
|
}
|
||||||
|
|
||||||
$mainSqlQuery.=
|
$mainSqlQuery.=
|
||||||
|
@ -229,50 +232,6 @@ class Application_Service_HistoryService
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
$timezoneUTC = new DateTimeZone("UTC");
|
|
||||||
$timezoneLocal = new DateTimeZone($this->timezone);
|
|
||||||
|
|
||||||
//need to display the results in the station's timezone.
|
|
||||||
foreach ($results["history"] as $index => &$result) {
|
|
||||||
|
|
||||||
$dateTime = new DateTime($result["starts"], $timezoneUTC);
|
|
||||||
$dateTime->setTimezone($timezoneLocal);
|
|
||||||
$result["starts"] = $dateTime->format("Y-m-d H:i:s");
|
|
||||||
|
|
||||||
$dateTime = new DateTime($result["ends"], $timezoneUTC);
|
|
||||||
$dateTime->setTimezone($timezoneLocal);
|
|
||||||
$result["ends"] = $dateTime->format("Y-m-d H:i:s");
|
|
||||||
}
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAggregateView($startDT, $endDT, $opts)
|
public function getAggregateView($startDT, $endDT, $opts)
|
||||||
{
|
{
|
||||||
$this->translateColumns($opts);
|
$this->translateColumns($opts);
|
||||||
|
@ -326,13 +285,7 @@ class Application_Service_HistoryService
|
||||||
//don't add webstreams
|
//don't add webstreams
|
||||||
if (isset($fileId)) {
|
if (isset($fileId)) {
|
||||||
|
|
||||||
//$starts = $item->getDbStarts(null);
|
|
||||||
//$ends = $item->getDbEnds(null);
|
|
||||||
|
|
||||||
$metadata = array();
|
$metadata = array();
|
||||||
//$metadata["date"] = $starts->format('Y-m-d');
|
|
||||||
//$metadata["start"] = $starts->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();
|
||||||
|
@ -340,7 +293,6 @@ class Application_Service_HistoryService
|
||||||
$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);
|
||||||
|
@ -348,7 +300,6 @@ class Application_Service_HistoryService
|
||||||
|
|
||||||
$history->addCcPlayoutHistoryMetaData($meta);
|
$history->addCcPlayoutHistoryMetaData($meta);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
$history->save($this->con);
|
$history->save($this->con);
|
||||||
}
|
}
|
||||||
|
@ -605,10 +556,25 @@ class Application_Service_HistoryService
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getSqlTypes() {
|
||||||
|
|
||||||
|
$fields = array(
|
||||||
|
TEMPLATE_DATE => "date",
|
||||||
|
TEMPLATE_TIME => "time",
|
||||||
|
TEMPLATE_DATETIME => "datetime",
|
||||||
|
TEMPLATE_STRING => "text",
|
||||||
|
TEMPLATE_BOOLEAN => "boolean",
|
||||||
|
TEMPLATE_INT => "integer",
|
||||||
|
TEMPLATE_FLOAT => "float",
|
||||||
|
);
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
public function getFileMetadataTypes() {
|
public function getFileMetadataTypes() {
|
||||||
|
|
||||||
$fileMD = array(
|
$fileMD = array(
|
||||||
array("name"=> MDATA_KEY_TITLE, "type"=> TEMPLATE_STRING),
|
array("name"=> MDATA_KEY_TITLE, "type"=> TEMPLATE_STRING, "sql"),
|
||||||
array("name"=> MDATA_KEY_CREATOR, "type"=> TEMPLATE_STRING),
|
array("name"=> MDATA_KEY_CREATOR, "type"=> TEMPLATE_STRING),
|
||||||
array("name"=> MDATA_KEY_SOURCE, "type"=> TEMPLATE_STRING),
|
array("name"=> MDATA_KEY_SOURCE, "type"=> TEMPLATE_STRING),
|
||||||
array("name"=> MDATA_KEY_DURATION, "type"=> TEMPLATE_STRING),
|
array("name"=> MDATA_KEY_DURATION, "type"=> TEMPLATE_STRING),
|
||||||
|
@ -644,7 +610,7 @@ class Application_Service_HistoryService
|
||||||
$fields[] = array("name" => MDATA_KEY_TITLE, "type" => TEMPLATE_STRING, "isFileMd" => true); //these fields can be populated from an associated file.
|
$fields[] = array("name" => MDATA_KEY_TITLE, "type" => TEMPLATE_STRING, "isFileMd" => true); //these fields can be populated from an associated file.
|
||||||
$fields[] = array("name" => MDATA_KEY_CREATOR, "type" => TEMPLATE_STRING, "isFileMd" => true);
|
$fields[] = array("name" => MDATA_KEY_CREATOR, "type" => TEMPLATE_STRING, "isFileMd" => true);
|
||||||
|
|
||||||
$template["name"] = "";
|
$template["name"] = "Template".date("Y-m-d H:i:s");
|
||||||
$template["fields"] = $fields;
|
$template["fields"] = $fields;
|
||||||
|
|
||||||
return $template;
|
return $template;
|
||||||
|
@ -719,8 +685,6 @@ class Application_Service_HistoryService
|
||||||
public function getDatatablesPlayedItemColumns() {
|
public function getDatatablesPlayedItemColumns() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//{"sTitle": $.i18n._("Start"), "mDataProp": "starts", "sClass": "his_starts"}
|
|
||||||
|
|
||||||
$template = $this->getConfiguredItemTemplate();
|
$template = $this->getConfiguredItemTemplate();
|
||||||
|
|
||||||
$columns = array();
|
$columns = array();
|
||||||
|
@ -762,21 +726,38 @@ class Application_Service_HistoryService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getConfiguredTemplateIds() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
$id = Application_Model_Preference::GetHistoryItemTemplate();
|
||||||
|
|
||||||
|
return array($id);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function createItemTemplate($config) {
|
public function createItemTemplate($config) {
|
||||||
|
|
||||||
$this->con->beginTransaction();
|
$this->con->beginTransaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$template = new CcPlayoutHistoryTemplate();
|
$default = $this->defaultItemTemplate();
|
||||||
$template->setDbName($config["name"]);
|
|
||||||
$template->setDbType(self::TEMPLATE_TYPE_ITEM);
|
|
||||||
|
|
||||||
$fields = $config["fields"];
|
$name = isset($config["name"]) ? $config["name"] : $default["name"];
|
||||||
|
$fields = isset($config["fields"]) ? $config["fields"] : $default["fields"];
|
||||||
|
|
||||||
|
$doSetDefault = isset($config['setDefault']) ? $config['setDefault'] : false;
|
||||||
|
|
||||||
|
$template = new CcPlayoutHistoryTemplate();
|
||||||
|
$template->setDbName($name);
|
||||||
|
$template->setDbType(self::TEMPLATE_TYPE_ITEM);
|
||||||
|
|
||||||
foreach ($fields as $index=>$field) {
|
foreach ($fields as $index=>$field) {
|
||||||
|
|
||||||
$isMd = ($field["filemd"] == 'true') ? true : false;
|
$isMd = ($field["isFileMd"] == 'true') ? true : false;
|
||||||
|
|
||||||
$templateField = new CcPlayoutHistoryTemplateField();
|
$templateField = new CcPlayoutHistoryTemplateField();
|
||||||
$templateField->setDbName($field["name"]);
|
$templateField->setDbName($field["name"]);
|
||||||
|
@ -789,8 +770,52 @@ class Application_Service_HistoryService
|
||||||
|
|
||||||
$template->save($this->con);
|
$template->save($this->con);
|
||||||
|
|
||||||
$doSetDefault = $config['setDefault'];
|
if ($doSetDefault) {
|
||||||
if (isset($doSetDefault) && $doSetDefault) {
|
$this->setConfiguredItemTemplate($template->getDbid());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->con->commit();
|
||||||
|
|
||||||
|
return $template->getDbid();
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$this->con->rollback();
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateItemTemplate($id, $name, $fields, $doSetDefault=false) {
|
||||||
|
|
||||||
|
$this->con->beginTransaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$template = CcPlayoutHistoryTemplateQuery::create()->findPk($id, $this->con);
|
||||||
|
$template->setDbName($name);
|
||||||
|
|
||||||
|
if (count($fields) === 0) {
|
||||||
|
$t = $this->defaultItemTemplate();
|
||||||
|
$fields = $t["fields"];
|
||||||
|
}
|
||||||
|
|
||||||
|
$template->getCcPlayoutHistoryTemplateFields()->delete($this->con);
|
||||||
|
|
||||||
|
foreach ($fields as $index=>$field) {
|
||||||
|
|
||||||
|
$isMd = ($field["isFileMd"] == 'true') ? true : false;
|
||||||
|
|
||||||
|
$templateField = new CcPlayoutHistoryTemplateField();
|
||||||
|
$templateField->setDbName($field["name"]);
|
||||||
|
$templateField->setDbType($field["type"]);
|
||||||
|
$templateField->setDbIsFileMD($isMd);
|
||||||
|
$templateField->setDbPosition($index);
|
||||||
|
|
||||||
|
$template->addCcPlayoutHistoryTemplateField($templateField);
|
||||||
|
}
|
||||||
|
|
||||||
|
$template->save($this->con);
|
||||||
|
|
||||||
|
if ($doSetDefault) {
|
||||||
$this->setConfiguredItemTemplate($template->getDbid());
|
$this->setConfiguredItemTemplate($template->getDbid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -802,4 +827,20 @@ class Application_Service_HistoryService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteTemplate($id) {
|
||||||
|
|
||||||
|
$this->con->beginTransaction();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$template = CcPlayoutHistoryTemplateQuery::create()->findPk($id, $this->con);
|
||||||
|
$template->delete($this->con);
|
||||||
|
|
||||||
|
$this->con->commit();
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
$this->con->rollback();
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,14 +1,3 @@
|
||||||
<div id="configure_item_template" class="ui-widget ui-widget-content block-shadow alpha-block padded">
|
<div id="configure_item_template" class="ui-widget ui-widget-content block-shadow alpha-block padded">
|
||||||
|
|
||||||
<div>
|
|
||||||
<select id="template_list">
|
|
||||||
<option value="">New</option>
|
|
||||||
<?php foreach ($this->template_list as $id=>$name): ?>
|
|
||||||
<option value="<?php echo $id; ?>"><?php echo $name; ?></option>
|
|
||||||
<?php endforeach; ?>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php echo $this->render('playouthistory/item-template.phtml'); ?>
|
<?php echo $this->render('playouthistory/item-template.phtml'); ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
|
@ -1,5 +1,7 @@
|
||||||
<div>
|
<div>
|
||||||
|
<?php if (!in_array($this->template_id, $this->configured)): ?>
|
||||||
<button id="template_set_default" data-template="<?php echo $this->template_id; ?>">Set Default Template</button>
|
<button id="template_set_default" data-template="<?php echo $this->template_id; ?>">Set Default Template</button>
|
||||||
|
<?php endif; ?>
|
||||||
<button id="template_item_save" data-template="<?php echo $this->template_id; ?>">Save</button>
|
<button id="template_item_save" data-template="<?php echo $this->template_id; ?>">Save</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,21 @@
|
||||||
<div id="history_template" class="ui-widget ui-widget-content block-shadow alpha-block padded">
|
<div id="history_template" class="ui-widget ui-widget-content block-shadow alpha-block padded">
|
||||||
<a href="<?php echo $this->baseUrl("Playouthistory/configure-item-template"); ?>">Configure Item Template</a>
|
|
||||||
|
<div>
|
||||||
|
<div>Edit Existing</div>
|
||||||
|
<ul id="template_list">
|
||||||
|
<?php foreach ($this->template_list as $id=>$name): ?>
|
||||||
|
<?php if (in_array($id, $this->configured)): ?>
|
||||||
|
<li data-template="<?php echo $id; ?>" data-name="<?php echo $name; ?>" class="template_configured">
|
||||||
|
<a class="template_name" href="<?php echo $this->baseUrl("Playouthistory/configure-item-template/id/{$id}"); ?>"><?php echo $name; ?></a>
|
||||||
|
<?php else: ?>
|
||||||
|
<li data-template="<?php echo $id; ?>" data-name="<?php echo $name; ?>">
|
||||||
|
<a class="template_name" href="<?php echo $this->baseUrl("Playouthistory/configure-item-template/id/{$id}"); ?>"><?php echo $name; ?></a>
|
||||||
|
<a class="template_default" href="<?php echo $this->baseUrl("Playouthistory/set-item-template-default/id/{$id}"); ?>">Set Default</a>
|
||||||
|
<a class="template_remove" href="<?php echo $this->baseUrl("Playouthistory/delete-template/id/{$id}"); ?>">Remove</a>
|
||||||
|
<?php endif; ?>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<button id="new_item_template" class="btn">New Item Template</button>
|
||||||
</div>
|
</div>
|
|
@ -1102,16 +1102,16 @@ function closeDialogLibrary(event, ui) {
|
||||||
|
|
||||||
function checkImportStatus() {
|
function checkImportStatus() {
|
||||||
$.getJSON(baseUrl+'Preference/is-import-in-progress', function(data){
|
$.getJSON(baseUrl+'Preference/is-import-in-progress', function(data){
|
||||||
var div = $('#import_status');
|
var $div = $('#import_status');
|
||||||
var table = $('#library_display').dataTable();
|
var table = $('#library_display').dataTable();
|
||||||
if (data == true){
|
if (data == true){
|
||||||
div.show();
|
$div.show();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if ($(div).is(':visible')) {
|
if ($div.is(':visible')) {
|
||||||
table.fnStandingRedraw();
|
table.fnStandingRedraw();
|
||||||
}
|
}
|
||||||
div.hide();
|
$div.hide();
|
||||||
}
|
}
|
||||||
setTimeout(checkImportStatus, 5000);
|
setTimeout(checkImportStatus, 5000);
|
||||||
});
|
});
|
||||||
|
|
137
airtime_mvc/public/js/airtime/playouthistory/itemtemplate.js
Normal file
137
airtime_mvc/public/js/airtime/playouthistory/itemtemplate.js
Normal file
|
@ -0,0 +1,137 @@
|
||||||
|
var AIRTIME = (function(AIRTIME) {
|
||||||
|
var mod;
|
||||||
|
var $templateDiv;
|
||||||
|
var $templateList;
|
||||||
|
var $fileMDList;
|
||||||
|
|
||||||
|
if (AIRTIME.itemTemplate === undefined) {
|
||||||
|
AIRTIME.itemTemplate = {};
|
||||||
|
}
|
||||||
|
mod = AIRTIME.itemTemplate;
|
||||||
|
|
||||||
|
function createTemplateLi(name, type, filemd, required) {
|
||||||
|
|
||||||
|
var templateRequired =
|
||||||
|
"<li id='<%= id %>' data-name='<%= name %>' data-type='<%= type %>' data-filemd='<%= filemd %>'>" +
|
||||||
|
"<span><%= name %></span>" +
|
||||||
|
"<span><%= type %></span>" +
|
||||||
|
"</li>";
|
||||||
|
|
||||||
|
var templateOptional =
|
||||||
|
"<li id='<%= id %>' data-name='<%= name %>' data-type='<%= type %>' data-filemd='<%= filemd %>'>" +
|
||||||
|
"<span><%= name %></span>" +
|
||||||
|
"<span><%= type %></span>" +
|
||||||
|
"<span class='template_item_remove'>Remove</span>" +
|
||||||
|
"</li>";
|
||||||
|
|
||||||
|
var template = (required) === true ? templateRequired : templateOptional;
|
||||||
|
|
||||||
|
var template = _.template(template);
|
||||||
|
var count = $templateList.find("li").length;
|
||||||
|
var id = "field_"+count;
|
||||||
|
var $li = $(template({id: id, name: name, type: type, filemd: filemd}));
|
||||||
|
|
||||||
|
return $li;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addField(name, type, filemd, required) {
|
||||||
|
|
||||||
|
$templateList.append(createTemplateLi(name, type, filemd, required));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFieldData($el) {
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: $el.data("name"),
|
||||||
|
type: $el.data("type"),
|
||||||
|
isFileMd: $el.data("filemd"),
|
||||||
|
id: $el.data("id")
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
mod.onReady = function() {
|
||||||
|
|
||||||
|
$templateDiv = $("#configure_item_template");
|
||||||
|
$templateList = $(".template_item_list");
|
||||||
|
$fileMDList = $(".template_file_md");
|
||||||
|
|
||||||
|
$fileMDList.on("dblclick", "li", function(){
|
||||||
|
|
||||||
|
var $li = $(this);
|
||||||
|
var name = $li.data("name");
|
||||||
|
var type = $li.data("type");
|
||||||
|
|
||||||
|
$templateList.append(createTemplateLi(name, type, true, false));
|
||||||
|
});
|
||||||
|
|
||||||
|
$templateList.sortable();
|
||||||
|
|
||||||
|
$templateDiv.on("click", ".template_item_remove", function() {
|
||||||
|
$(this).parents("li").remove();
|
||||||
|
});
|
||||||
|
|
||||||
|
$templateDiv.on("click", ".template_item_add button", function() {
|
||||||
|
var $div = $(this).parents("div.template_item_add");
|
||||||
|
|
||||||
|
var name = $div.find("input").val();
|
||||||
|
var type = $div.find("select").val();
|
||||||
|
|
||||||
|
addField(name, type, false, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
function createUpdateTemplate(template_id, isDefault) {
|
||||||
|
var createUrl = baseUrl+"Playouthistory/create-template/format/json";
|
||||||
|
var updateUrl = baseUrl+"Playouthistory/update-template/format/json";
|
||||||
|
var url;
|
||||||
|
var data = {};
|
||||||
|
var $lis, $li;
|
||||||
|
var i, len;
|
||||||
|
var templateName;
|
||||||
|
|
||||||
|
url = (isNaN(parseInt(template_id, 10))) ? createUrl : updateUrl;
|
||||||
|
|
||||||
|
templateName = $("#template_name").val();
|
||||||
|
$lis = $templateList.children();
|
||||||
|
|
||||||
|
for (i = 0, len = $lis.length; i < len; i++) {
|
||||||
|
$li = $($lis[i]);
|
||||||
|
|
||||||
|
data[i] = getFieldData($li);
|
||||||
|
}
|
||||||
|
|
||||||
|
$.post(url, {'id': template_id, 'name': templateName, 'fields': data, 'setDefault': isDefault}, function(json) {
|
||||||
|
var x;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$templateDiv.on("click", "#template_item_save", function(){
|
||||||
|
var template_id = $(this).data("template");
|
||||||
|
|
||||||
|
createUpdateTemplate(template_id, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
$templateDiv.on("click", "#template_set_default", function(){
|
||||||
|
var template_id = $(this).data("template");
|
||||||
|
|
||||||
|
if (isNaN(parseInt(template_id, 10))) {
|
||||||
|
|
||||||
|
createUpdateTemplate(template_id, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
var url = baseUrl+"Playouthistory/set-item-template-default/format/json";
|
||||||
|
|
||||||
|
$.post(url, {id: template_id}, function(json) {
|
||||||
|
var x;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
return AIRTIME;
|
||||||
|
|
||||||
|
}(AIRTIME || {}));
|
||||||
|
|
||||||
|
$(document).ready(AIRTIME.itemTemplate.onReady);
|
|
@ -1,181 +1,93 @@
|
||||||
var AIRTIME = (function(AIRTIME) {
|
var AIRTIME = (function(AIRTIME) {
|
||||||
var mod;
|
var mod;
|
||||||
var $templateDiv;
|
var $historyTemplate;
|
||||||
var $templateList;
|
|
||||||
var $fileMDList;
|
|
||||||
|
|
||||||
if (AIRTIME.historyTemplate === undefined) {
|
if (AIRTIME.template === undefined) {
|
||||||
AIRTIME.historyTemplate = {};
|
AIRTIME.template = {};
|
||||||
}
|
}
|
||||||
mod = AIRTIME.historyTemplate;
|
mod = AIRTIME.template;
|
||||||
|
|
||||||
function createTemplateLi(name, type, filemd, required) {
|
function createItemLi(id, name, configured) {
|
||||||
|
|
||||||
var templateRequired =
|
var editUrl = baseUrl+"Playouthistory/configure-item-template/id/"+id;
|
||||||
"<li id='<%= id %>' data-name='<%= name %>' data-type='<%= type %>' data-filemd='<%= filemd %>'>" +
|
var defaultUrl = baseUrl+"Playouthistory/set-item-template-default/format/json/id/"+id;
|
||||||
"<span><%= name %></span>" +
|
var removeUrl = baseUrl+"Playouthistory/delete-template/format/json/id/"+id;
|
||||||
"<span><%= type %></span>" +
|
|
||||||
|
var itemConfigured =
|
||||||
|
"<li class='template_configured' data-template='<%= id %>' data-name='<%= name %>'>" +
|
||||||
|
"<a href='<%= editUrl %>' class='template_name'><%= name %></a>" +
|
||||||
"</li>";
|
"</li>";
|
||||||
|
|
||||||
var templateOptional =
|
var item =
|
||||||
"<li id='<%= id %>' data-name='<%= name %>' data-type='<%= type %>' data-filemd='<%= filemd %>'>" +
|
"<li data-template='<%= id %>' data-name='<%= name %>'>" +
|
||||||
"<span><%= name %></span>" +
|
"<a href='<%= editUrl %>' class='template_name'><%= name %></a>" +
|
||||||
"<span><%= type %></span>" +
|
"<a href='<%= defaultUrl %>' class='template_default'>Set Default</a>" +
|
||||||
"<span class='template_item_remove'>Remove</span>" +
|
"<a href='<%= removeUrl %>' class='template_remove'>Remove</a>" +
|
||||||
"</li>";
|
"</li>";
|
||||||
|
|
||||||
var template = (required) === true ? templateRequired : templateOptional;
|
var template = (configured) === true ? itemConfigured : item;
|
||||||
|
|
||||||
var template = _.template(template);
|
var template = _.template(template);
|
||||||
var count = $templateList.find("li").length;
|
|
||||||
var id = "field_"+count;
|
var $li = $(template({id: id, name: name, editUrl: editUrl, defaultUrl: defaultUrl, removeUrl: removeUrl}));
|
||||||
var $li = $(template({id: id, name: name, type: type, filemd: filemd}));
|
|
||||||
|
|
||||||
return $li;
|
return $li;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addField(name, type, filemd, required) {
|
|
||||||
|
|
||||||
$templateList.append(createTemplateLi(name, type, filemd, required));
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFieldData($el) {
|
|
||||||
|
|
||||||
return {
|
|
||||||
name: $el.data("name"),
|
|
||||||
type: $el.data("type"),
|
|
||||||
filemd: $el.data("filemd"),
|
|
||||||
id: $el.data("id")
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
var fieldSortable = (function() {
|
|
||||||
|
|
||||||
var $newLi;
|
|
||||||
|
|
||||||
return {
|
|
||||||
receive: function( event, ui ) {
|
|
||||||
var name = $newLi.data("name");
|
|
||||||
var type = $newLi.data("type");
|
|
||||||
var $prev = $newLi.prev();
|
|
||||||
|
|
||||||
$newLi.remove();
|
|
||||||
|
|
||||||
var $li = createTemplateLi(name, type, true, false);
|
|
||||||
|
|
||||||
if ($prev.length) {
|
|
||||||
$prev.after($li);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$templateList.prepend($li);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
beforeStop: function( event, ui ) {
|
|
||||||
$newLi = ui.item;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
})();
|
|
||||||
|
|
||||||
mod.onReady = function() {
|
mod.onReady = function() {
|
||||||
|
|
||||||
$templateDiv = $("#configure_item_template");
|
$historyTemplate = $("#history_template");
|
||||||
$templateList = $(".template_item_list");
|
|
||||||
$fileMDList = $(".template_file_md");
|
|
||||||
|
|
||||||
|
$historyTemplate.on("click", ".template_remove", function(ev) {
|
||||||
|
|
||||||
$fileMDList.find("li").draggable({
|
ev.preventDefault();
|
||||||
helper: function(event, ui) {
|
|
||||||
var $li = $(this);
|
|
||||||
var name = $li.data("name");
|
|
||||||
var type = $li.data("type");
|
|
||||||
|
|
||||||
return createTemplateLi(name, type, true, false);
|
var $a = $(this);
|
||||||
|
var url = $a.attr("href");
|
||||||
|
$a.parents("li").remove();
|
||||||
|
|
||||||
},
|
$.post(url, function(){
|
||||||
connectToSortable: ".template_item_list"
|
|
||||||
});
|
|
||||||
|
|
||||||
$templateList.sortable(fieldSortable);
|
|
||||||
|
|
||||||
$templateDiv.on("click", ".template_item_remove", function() {
|
|
||||||
$(this).parents("li").remove();
|
|
||||||
});
|
|
||||||
|
|
||||||
$templateDiv.on("click", ".template_item_add button", function() {
|
|
||||||
var $div = $(this).parents("div.template_item_add");
|
|
||||||
|
|
||||||
var name = $div.find("input").val();
|
|
||||||
var type = $div.find("select").val();
|
|
||||||
|
|
||||||
addField(name, type, false, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
function createUpdateTemplate(template_id, isDefault) {
|
|
||||||
var createUrl = baseUrl+"Playouthistory/create-template/format/json";
|
|
||||||
var updateUrl = baseUrl+"Playouthistory/update-template/format/json";
|
|
||||||
var url;
|
|
||||||
var data = {};
|
|
||||||
var $lis, $li;
|
|
||||||
var i, len;
|
|
||||||
var templateName;
|
|
||||||
|
|
||||||
url = (isNaN(parseInt(template_id, 10))) ? createUrl : updateUrl;
|
|
||||||
|
|
||||||
templateName = $("#template_name").val();
|
|
||||||
$lis = $templateList.children();
|
|
||||||
|
|
||||||
for (i = 0, len = $lis.length; i < len; i++) {
|
|
||||||
$li = $($lis[i]);
|
|
||||||
|
|
||||||
data[i] = getFieldData($li);
|
|
||||||
}
|
|
||||||
|
|
||||||
$.post(url, {'name': templateName, 'fields': data, 'setDefault': isDefault}, function(json) {
|
|
||||||
var x;
|
var x;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
$templateDiv.on("click", "#template_item_save", function(){
|
|
||||||
var template_id = $(this).data("template");
|
|
||||||
|
|
||||||
createUpdateTemplate(template_id, false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$templateDiv.on("click", "#template_set_default", function(){
|
$historyTemplate.on("click", ".template_default", function(ev) {
|
||||||
var template_id = $(this).data("template");
|
|
||||||
|
|
||||||
if (isNaN(parseInt(template_id, 10))) {
|
ev.preventDefault();
|
||||||
|
|
||||||
createUpdateTemplate(template_id, true);
|
var $a = $(this);
|
||||||
}
|
var url = $a.attr("href");
|
||||||
else {
|
var $oldLi, $newLi;
|
||||||
|
|
||||||
var url = baseUrl+"Playouthistory/set-item-template-default/format/json";
|
$oldLi = $a.parents("ul").find("li.template_configured");
|
||||||
|
$newLi = $a.parents("li");
|
||||||
|
|
||||||
$.post(url, {id: template_id}, function(json) {
|
$oldLi.replaceWith(createItemLi($oldLi.data('template'), $oldLi.data('name'), false));
|
||||||
|
$newLi.replaceWith(createItemLi($newLi.data('template'), $newLi.data('name'), true));
|
||||||
|
|
||||||
|
$.post(url, function(){
|
||||||
var x;
|
var x;
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#template_list").change(function(){
|
$historyTemplate.on("click", "#new_item_template", function() {
|
||||||
var template_id = $(this).find(":selected").val(),
|
var createUrl = baseUrl+"Playouthistory/create-template";
|
||||||
url;
|
|
||||||
|
|
||||||
if (!isNaN(parseInt(template_id, 10))) {
|
$.post(createUrl, {format: "json"}, function(json) {
|
||||||
url = baseUrl+"Playouthistory/configure-item-template/id/"+template_id;
|
|
||||||
}
|
if (json.error !== undefined) {
|
||||||
else {
|
alert(json.error);
|
||||||
url = baseUrl+"Playouthistory/configure-item-template";
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.location.href = url;
|
window.location.href = json.url;
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return AIRTIME;
|
return AIRTIME;
|
||||||
|
|
||||||
}(AIRTIME || {}));
|
}(AIRTIME || {}));
|
||||||
|
|
||||||
$(document).ready(AIRTIME.historyTemplate.onReady);
|
$(document).ready(AIRTIME.template.onReady);
|
Loading…
Add table
Add a link
Reference in a new issue