From c110b4b4dfb25441ac52e37a6ce1d4e0149ee8a4 Mon Sep 17 00:00:00 2001 From: Naomi Date: Fri, 2 Aug 2013 15:29:39 -0400 Subject: [PATCH] file summary table now starting to work with templates.need to change query around to be configurable still. --- .../controllers/PlayouthistoryController.php | 97 ++++---- airtime_mvc/application/models/Datatables.php | 8 +- airtime_mvc/application/models/Preference.php | 8 + .../application/services/HistoryService.php | 230 +++++++++++++----- ...emplate.phtml => configure-template.phtml} | 2 +- ...template.phtml => template-contents.phtml} | 24 +- .../scripts/playouthistory/template.phtml | 34 ++- .../{itemtemplate.js => configuretemplate.js} | 30 +-- .../js/airtime/playouthistory/historytable.js | 11 +- .../js/airtime/playouthistory/template.js | 16 +- 10 files changed, 298 insertions(+), 162 deletions(-) rename airtime_mvc/application/views/scripts/playouthistory/{configure-item-template.phtml => configure-template.phtml} (56%) rename airtime_mvc/application/views/scripts/playouthistory/{item-template.phtml => template-contents.phtml} (74%) rename airtime_mvc/public/js/airtime/playouthistory/{itemtemplate.js => configuretemplate.js} (80%) diff --git a/airtime_mvc/application/controllers/PlayouthistoryController.php b/airtime_mvc/application/controllers/PlayouthistoryController.php index 215111528..9b14e8feb 100644 --- a/airtime_mvc/application/controllers/PlayouthistoryController.php +++ b/airtime_mvc/application/controllers/PlayouthistoryController.php @@ -17,7 +17,7 @@ class PlayouthistoryController extends Zend_Controller_Action ->addActionContext('create-template', 'json') ->addActionContext('update-template', 'json') ->addActionContext('delete-template', 'json') - ->addActionContext('set-item-template-default', 'json') + ->addActionContext('set-template-default', 'json') ->initContext(); } @@ -71,8 +71,11 @@ class PlayouthistoryController extends Zend_Controller_Action //set datatables columns for display of data. $historyService = new Application_Service_HistoryService(); - $columns = json_encode($historyService->getDatatablesPlayedItemColumns()); - $script = "localStorage.setItem( 'datatables-historyitem-aoColumns', JSON.stringify($columns) );"; + $columns = json_encode($historyService->getDatatablesLogSheetColumns()); + $script = "localStorage.setItem( 'datatables-historyitem-aoColumns', JSON.stringify($columns) ); "; + + $columns = json_encode($historyService->getDatatablesFileSummaryColumns()); + $script.= "localStorage.setItem( 'datatables-historyfile-aoColumns', JSON.stringify($columns) );"; $this->view->headScript()->appendScript($script); } @@ -90,7 +93,7 @@ class PlayouthistoryController extends Zend_Controller_Action $endsDT = DateTime::createFromFormat("U", $ends_epoch, new DateTimeZone("UTC")); $historyService = new Application_Service_HistoryService(); - $r = $historyService->getAggregateView($startsDT, $endsDT, $params); + $r = $historyService->getFileSummaryData($startsDT, $endsDT, $params); $this->view->sEcho = $r["sEcho"]; $this->view->iTotalDisplayRecords = $r["iTotalDisplayRecords"]; @@ -204,53 +207,67 @@ class PlayouthistoryController extends Zend_Controller_Action $historyService = new Application_Service_HistoryService(); $this->view->template_list = $historyService->getListItemTemplates(); + $this->view->template_file = $historyService->getFileTemplates(); $this->view->configured = $historyService->getConfiguredTemplateIds(); } - public function configureItemTemplateAction() { + public function configureTemplateAction() { - $request = $this->getRequest(); - $params = $request->getPost(); - Logging::info($params); + $CC_CONFIG = Config::getConfig(); + $baseUrl = Application_Common_OsPath::getBaseDir(); + + $this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/configuretemplate.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); try { - $CC_CONFIG = Config::getConfig(); - $baseUrl = Application_Common_OsPath::getBaseDir(); - $this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/itemtemplate.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - - $template_id = $this->_getParam('id', null); + $templateId = $this->_getParam('id'); - $historyService = new Application_Service_HistoryService(); - $mandatoryFields = $historyService->mandatoryItemFields(); - $template = $historyService->getItemTemplate($template_id); - - $this->view->template_id = $template_id; + $historyService = new Application_Service_HistoryService(); + $template = $historyService->loadTemplate($templateId); + + $templateType = $template["type"]; + $supportedTypes = $historyService->getSupportedTemplateTypes(); + + if (!in_array($templateType, $supportedTypes)) { + throw new Exception("Error: $templateType is not supported."); + } + + $getMandatoryFields = "mandatory".ucfirst($templateType)."Fields"; + $mandatoryFields = $historyService->$getMandatoryFields(); + + $this->view->template_id = $templateId; $this->view->template_name = $template["name"]; $this->view->template_fields = $template["fields"]; - $this->view->template_list = $historyService->getListItemTemplates(); + $this->view->template_type = $templateType; $this->view->fileMD = $historyService->getFileMetadataTypes(); $this->view->fields = $historyService->getFieldTypes(); $this->view->required_fields = $mandatoryFields; $this->view->configured = $historyService->getConfiguredTemplateIds(); } catch (Exception $e) { + Logging::info("Error?"); Logging::info($e); Logging::info($e->getMessage()); + + $this->_forward('template', 'playouthistory'); } } public function createTemplateAction() { - $request = $this->getRequest(); - $params = $request->getPost(); - Logging::info($params); + $templateType = $this->_getParam('type', null); try { $historyService = new Application_Service_HistoryService(); - $id = $historyService->createItemTemplate($params); + $supportedTypes = $historyService->getSupportedTemplateTypes(); - $this->view->url = $this->view->baseUrl("Playouthistory/configure-item-template/id/{$id}"); + if (!in_array($templateType, $supportedTypes)) { + throw new Exception("Error: $templateType is not supported."); + } + + $id = $historyService->createTemplate($params); + + $this->view->url = $this->view->baseUrl("Playouthistory/configure-template/id/{$id}"); } catch (Exception $e) { Logging::info($e); @@ -260,21 +277,13 @@ class PlayouthistoryController extends Zend_Controller_Action } } - public function setItemTemplateDefaultAction() + public function setTemplateDefaultAction() { - $request = $this->getRequest(); - $params = $request->getPost(); - Logging::info($params); + $templateId = $this->_getParam('id', null); - $template_id = $this->_getParam('id', null); - - if (empty($template_id)) { - return; - } - try { $historyService = new Application_Service_HistoryService(); - $historyService->setConfiguredItemTemplate($template_id); + $historyService->setConfiguredTemplate($templateId); } catch (Exception $e) { Logging::info($e); @@ -283,22 +292,14 @@ class PlayouthistoryController extends Zend_Controller_Action } public function updateTemplateAction() - { - $request = $this->getRequest(); - $params = $request->getPost(); - Logging::info($params); - - $template_id = $this->_getParam('id', null); + { + $templateId = $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); + $historyService->updateItemTemplate($templateId, $name, $fields); } catch (Exception $e) { Logging::info($e); @@ -308,11 +309,11 @@ class PlayouthistoryController extends Zend_Controller_Action public function deleteTemplateAction() { - $template_id = $this->_getParam('id'); + $templateId = $this->_getParam('id'); try { $historyService = new Application_Service_HistoryService(); - $historyService->deleteTemplate($template_id); + $historyService->deleteTemplate($templateId); } catch (Exception $e) { Logging::info($e); diff --git a/airtime_mvc/application/models/Datatables.php b/airtime_mvc/application/models/Datatables.php index ef6b6e80e..d39a939fa 100644 --- a/airtime_mvc/application/models/Datatables.php +++ b/airtime_mvc/application/models/Datatables.php @@ -177,18 +177,18 @@ class Application_Model_Datatables try { - Logging::info($sqlTotalRows); + //Logging::info($sqlTotalRows); $r = $con->query($sqlTotalRows); $totalRows = $r->fetchColumn(0); if (isset($sqlTotalDisplayRows)) { - Logging::info("sql is set"); - Logging::info($sqlTotalDisplayRows); + //Logging::info("sql is set"); + //Logging::info($sqlTotalDisplayRows); $totalDisplayRows = Application_Common_Database::prepareAndExecute($sqlTotalDisplayRows, $params, 'column'); } else { - Logging::info("sql is not set."); + //Logging::info("sql is not set."); $totalDisplayRows = $totalRows; } diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index b5f17900f..76e10e751 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -1377,4 +1377,12 @@ class Application_Model_Preference public static function GetHistoryItemTemplate() { return self::getValue("history_item_template"); } + + public static function SetHistoryFileTemplate($value) { + self::setValue("history_file_template", $value); + } + + public static function GetHistoryFileTemplate() { + return self::getValue("history_file_template"); + } } diff --git a/airtime_mvc/application/services/HistoryService.php b/airtime_mvc/application/services/HistoryService.php index 3962461fc..13f6fd96e 100644 --- a/airtime_mvc/application/services/HistoryService.php +++ b/airtime_mvc/application/services/HistoryService.php @@ -8,36 +8,17 @@ class Application_Service_HistoryService private $timezone; const TEMPLATE_TYPE_ITEM = "item"; - const TEMPLATE_TYPE_AGGREGATE = "aggregate"; - - private $mDataPropMap = array ( - "artist" => "artist_name", - "title" => "track_title", - "played" => "played", - "length" => "length", - "composer" => "composer", - "copyright" => "copyright", - "starts" => "starts", - "ends" => "ends" - ); + const TEMPLATE_TYPE_FILE = "file"; public function __construct() { $this->con = isset($con) ? $con : Propel::getConnection(CcPlayoutHistoryPeer::DATABASE_NAME); $this->timezone = Application_Model_Preference::GetTimezone(); } - - /* - * map front end mDataProp labels to proper column names for searching etc. - */ - private function translateColumns($opts) + + public function getSupportedTemplateTypes() { - for ($i = 0; $i < $opts["iColumns"]; $i++) { - - if ($opts["bSearchable_{$i}"] === "true") { - $opts["mDataProp_{$i}"] = $this->mDataPropMap[$opts["mDataProp_{$i}"]]; - } - } + return array(self::TEMPLATE_TYPE_ITEM, self::TEMPLATE_TYPE_FILE); } //opts is from datatables. @@ -293,18 +274,16 @@ class Application_Service_HistoryService ); } - public function getAggregateView($startDT, $endDT, $opts) + public function getFileSummaryData($startDT, $endDT, $opts) { - $this->translateColumns($opts); - $select = array ( - "file.track_title as title", - "file.artist_name as artist", - "playout.played as played", + "file.track_title", + "file.artist_name", + "playout.played", "playout.file_id", - "file.composer as composer", - "file.copyright as copyright", - "file.length as length" + "file.composer", + "file.copyright", + "file.length" ); $start = $startDT->format("Y-m-d H:i:s"); @@ -660,6 +639,13 @@ class Application_Service_HistoryService return $fields; } + + public function mandatoryFileFields() { + + $fields = array("played", MDATA_KEY_TITLE, MDATA_KEY_CREATOR); + + return $fields; + } private function defaultItemTemplate() { @@ -671,17 +657,47 @@ 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_CREATOR, "type" => TEMPLATE_STRING, "isFileMd" => true); - $template["name"] = "Template".date("Y-m-d H:i:s"); + $template["name"] = "Log Sheet ".date("Y-m-d H:i:s")." Template"; $template["fields"] = $fields; return $template; } - private function loadTemplate($id) { + /* + * Default File Summary Template. Taken from The Czech radio requirements (customer requested this in the past). + */ + private function defaultFileTemplate() { + + $template = array(); + $fields = array(); + + $fields[] = array("name" => MDATA_KEY_TITLE, "type" => TEMPLATE_STRING, "isFileMd" => true); + $fields[] = array("name" => MDATA_KEY_CREATOR, "type" => TEMPLATE_STRING, "isFileMd" => true); + $fields[] = array("name" => "played", "type" => TEMPLATE_INT, "isFileMd" => false); + $fields[] = array("name" => MDATA_KEY_DURATION, "type" => TEMPLATE_STRING, "isFileMd" => true); + $fields[] = array("name" => MDATA_KEY_COMPOSER, "type" => TEMPLATE_STRING, "isFileMd" => true); + $fields[] = array("name" => MDATA_KEY_COPYRIGHT, "type" => TEMPLATE_STRING, "isFileMd" => true); + + $template["name"] = "File Summary ".date("Y-m-d H:i:s")." Template"; + $template["fields"] = $fields; + + return $template; + } + + public function loadTemplate($id) { try { + + if (!is_numeric($id)) { + throw new Exception("Error: $id is not numeric."); + } + $template = CcPlayoutHistoryTemplateQuery::create()->findPk($id, $this->con); + if (empty($template)) { + throw new Exception("Error: Template $id does not exist."); + } + $c = new Criteria(); $c->addAscendingOrderByColumn(CcPlayoutHistoryTemplateFieldPeer::POSITION); $config = $template->getCcPlayoutHistoryTemplateFields($c, $this->con); @@ -700,6 +716,7 @@ class Application_Service_HistoryService $data = array(); $data["name"] = $template->getDbName(); $data["fields"] = $fields; + $data["type"] = $template->getDbType(); return $data; } @@ -722,15 +739,21 @@ class Application_Service_HistoryService return $template; } - public function getListItemTemplates() { + public function getTemplates($type) { $list = array(); try { - $templates = CcPlayoutHistoryTemplateQuery::create() - ->setFormatter(ModelCriteria::FORMAT_ON_DEMAND) - ->findByDbType(self::TEMPLATE_TYPE_ITEM); + $query = CcPlayoutHistoryTemplateQuery::create() + ->setFormatter(ModelCriteria::FORMAT_ON_DEMAND); + + if (isset($type)) { + $templates = $query->findByDbType($type); + } + else { + $templates = $query->find(); + } foreach ($templates as $template) { $list[$template->getDbId()] = $template->getDbName(); @@ -743,35 +766,66 @@ class Application_Service_HistoryService } } - public function getDatatablesPlayedItemColumns() { + public function getListItemTemplates() { + return $this->getTemplates(self::TEMPLATE_TYPE_ITEM); + } + + public function getFileTemplates() { + return $this->getTemplates(self::TEMPLATE_TYPE_FILE); + } + + private function datatablesColumns($template) { + + $columns = array(); + + foreach ($template["fields"] as $index=>$field) { + + $key = $field["name"]; + + $columns[] = array( + "sTitle"=> $key, + "mDataProp"=> $key, + "sClass"=> "his_{$key}" + ); + } + + return $columns; + } + + public function getDatatablesLogSheetColumns() { try { - $template = $this->getConfiguredItemTemplate(); - - $columns = array(); - - foreach ($template["fields"] as $index=>$field) { - - $key = $field["name"]; - - $columns[] = array( - "sTitle"=> $key, - "mDataProp"=> $key, - "sClass"=> "his_{$key}" - ); - } - - return $columns; + $template = $this->getConfiguredItemTemplate(); + return $this->datatablesColumns($template); } catch (Exception $e) { throw $e; } } + public function getDatatablesFileSummaryColumns() { + + try { + $template = $this->getConfiguredFileTemplate(); + return $this->datatablesColumns($template); + } + catch (Exception $e) { + throw $e; + } + } + public function getConfiguredItemTemplate() { + try { $id = Application_Model_Preference::GetHistoryItemTemplate(); - return $this->getItemTemplate($id); + + if (is_numeric($id)) { + $template = $this->loadTemplate($id); + } + else { + $template = $this->defaultItemTemplate(); + } + return $template; } catch (Exception $e) { throw $e; @@ -787,25 +841,81 @@ class Application_Service_HistoryService } } + public function getConfiguredFileTemplate() { + + try { + $id = Application_Model_Preference::GetHistoryFileTemplate(); + + if (is_numeric($id)) { + $template = $this->loadTemplate($id); + } + else { + $template = $this->defaultFileTemplate(); + } + return $template; + } + catch (Exception $e) { + throw $e; + } + } + + public function setConfiguredFileTemplate($id) { + try { + Application_Model_Preference::SetHistoryFileTemplate($id); + } + catch (Exception $e) { + throw $e; + } + } + + public function setConfiguredTemplate($id) { + try { + + $template = $this->loadTemplate($id); + $type = $template["type"]; + + $setTemplate = "setConfigured".ucfirst($type)."Template"; + + $this->$setTemplate($id); + } + catch (Exception $e) { + throw $e; + } + } + public function getConfiguredTemplateIds() { try { $id = Application_Model_Preference::GetHistoryItemTemplate(); + $id2 = Application_Model_Preference::GetHistoryFileTemplate(); - return array($id); + $configured = array(); + + if (is_numeric($id)) { + $configured[] = $id; + } + + if (is_numeric($id2)) { + $configured[] = $id2; + } + + return $configured; } catch (Exception $e) { throw $e; } } - public function createItemTemplate($config) { + public function createTemplate($config) { $this->con->beginTransaction(); try { - $default = $this->defaultItemTemplate(); + $type = $config["type"]; + + $method = "default".ucfirst($type)."Template"; + $default = $this->$method(); $name = isset($config["name"]) ? $config["name"] : $default["name"]; $fields = isset($config["fields"]) ? $config["fields"] : $default["fields"]; @@ -814,7 +924,7 @@ class Application_Service_HistoryService $template = new CcPlayoutHistoryTemplate(); $template->setDbName($name); - $template->setDbType(self::TEMPLATE_TYPE_ITEM); + $template->setDbType($type); foreach ($fields as $index=>$field) { diff --git a/airtime_mvc/application/views/scripts/playouthistory/configure-item-template.phtml b/airtime_mvc/application/views/scripts/playouthistory/configure-template.phtml similarity index 56% rename from airtime_mvc/application/views/scripts/playouthistory/configure-item-template.phtml rename to airtime_mvc/application/views/scripts/playouthistory/configure-template.phtml index b19f0764e..051ba1dc6 100644 --- a/airtime_mvc/application/views/scripts/playouthistory/configure-item-template.phtml +++ b/airtime_mvc/application/views/scripts/playouthistory/configure-template.phtml @@ -1,3 +1,3 @@
- render('playouthistory/item-template.phtml'); ?> + render('playouthistory/template-contents.phtml'); ?>
\ No newline at end of file diff --git a/airtime_mvc/application/views/scripts/playouthistory/item-template.phtml b/airtime_mvc/application/views/scripts/playouthistory/template-contents.phtml similarity index 74% rename from airtime_mvc/application/views/scripts/playouthistory/item-template.phtml rename to airtime_mvc/application/views/scripts/playouthistory/template-contents.phtml index d9c1473fd..3c626f9be 100644 --- a/airtime_mvc/application/views/scripts/playouthistory/item-template.phtml +++ b/airtime_mvc/application/views/scripts/playouthistory/template-contents.phtml @@ -31,15 +31,17 @@ -
-
Add New Field
-
- - - -
+ template_type !== Application_Service_HistoryService::TEMPLATE_TYPE_FILE): ?> +
+
Add New Field
+
+ + + +
+
\ No newline at end of file diff --git a/airtime_mvc/application/views/scripts/playouthistory/template.phtml b/airtime_mvc/application/views/scripts/playouthistory/template.phtml index 334c26317..3c24d45e9 100644 --- a/airtime_mvc/application/views/scripts/playouthistory/template.phtml +++ b/airtime_mvc/application/views/scripts/playouthistory/template.phtml @@ -1,21 +1,45 @@
-
Edit Existing
+
Edit Log Sheet Template
- +
+
Edit File Summary Template
+
    + template_file) == 0): ?> +
  • No File Summary Templates
  • + + template_file as $id=>$name): ?> + configured)): ?> +
  • + "> + +
  • + "> + ">Set Default + ">Remove + +
  • + +
+
+ +
\ No newline at end of file diff --git a/airtime_mvc/public/js/airtime/playouthistory/itemtemplate.js b/airtime_mvc/public/js/airtime/playouthistory/configuretemplate.js similarity index 80% rename from airtime_mvc/public/js/airtime/playouthistory/itemtemplate.js rename to airtime_mvc/public/js/airtime/playouthistory/configuretemplate.js index 584f06282..c740d8264 100644 --- a/airtime_mvc/public/js/airtime/playouthistory/itemtemplate.js +++ b/airtime_mvc/public/js/airtime/playouthistory/configuretemplate.js @@ -80,17 +80,13 @@ var AIRTIME = (function(AIRTIME) { 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; + function updateTemplate(template_id, isDefault) { + var url = baseUrl+"Playouthistory/update-template/format/json"; 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(); @@ -108,24 +104,16 @@ var AIRTIME = (function(AIRTIME) { $templateDiv.on("click", "#template_item_save", function(){ var template_id = $(this).data("template"); - createUpdateTemplate(template_id, false); + updateTemplate(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; - }); - } + var template_id = $(this).data("template"); + var url = baseUrl+"Playouthistory/set-template-default/format/json"; + + $.post(url, {id: template_id}, function(json) { + var x; + }); }); }; diff --git a/airtime_mvc/public/js/airtime/playouthistory/historytable.js b/airtime_mvc/public/js/airtime/playouthistory/historytable.js index c096d960e..682759e0c 100644 --- a/airtime_mvc/public/js/airtime/playouthistory/historytable.js +++ b/airtime_mvc/public/js/airtime/playouthistory/historytable.js @@ -104,16 +104,11 @@ var AIRTIME = (function(AIRTIME) { nRow.setAttribute('url-edit', editUrl); }; + var columns = JSON.parse(localStorage.getItem('datatables-historyfile-aoColumns')); + oTable = $historyTableDiv.dataTable( { - "aoColumns": [ - {"sTitle": $.i18n._("Title"), "mDataProp": "title", "sClass": "his_title"}, /* Title */ - {"sTitle": $.i18n._("Creator"), "mDataProp": "artist", "sClass": "his_artist"}, /* Creator */ - {"sTitle": $.i18n._("Played"), "mDataProp": "played", "sClass": "his_artist"}, /* times played */ - {"sTitle": $.i18n._("Length"), "mDataProp": "length", "sClass": "his_length library_length"}, /* Length */ - {"sTitle": $.i18n._("Composer"), "mDataProp": "composer", "sClass": "his_composer"}, /* Composer */ - {"sTitle": $.i18n._("Copyright"), "mDataProp": "copyright", "sClass": "his_copyright"} /* Copyright */ - ], + "aoColumns": columns, "bProcessing": true, "bServerSide": true, diff --git a/airtime_mvc/public/js/airtime/playouthistory/template.js b/airtime_mvc/public/js/airtime/playouthistory/template.js index 5562dd371..c452d15aa 100644 --- a/airtime_mvc/public/js/airtime/playouthistory/template.js +++ b/airtime_mvc/public/js/airtime/playouthistory/template.js @@ -9,8 +9,8 @@ var AIRTIME = (function(AIRTIME) { function createItemLi(id, name, configured) { - var editUrl = baseUrl+"Playouthistory/configure-item-template/id/"+id; - var defaultUrl = baseUrl+"Playouthistory/set-item-template-default/format/json/id/"+id; + var editUrl = baseUrl+"Playouthistory/configure-template/id/"+id; + var defaultUrl = baseUrl+"Playouthistory/set-template-default/format/json/id/"+id; var removeUrl = baseUrl+"Playouthistory/delete-template/format/json/id/"+id; var itemConfigured = @@ -70,10 +70,11 @@ var AIRTIME = (function(AIRTIME) { }); }); - $historyTemplate.on("click", "#new_item_template", function() { + function createTemplate(type) { + var createUrl = baseUrl+"Playouthistory/create-template"; - $.post(createUrl, {format: "json"}, function(json) { + $.post(createUrl, {format: "json", type: type}, function(json) { if (json.error !== undefined) { alert(json.error); @@ -82,8 +83,15 @@ var AIRTIME = (function(AIRTIME) { window.location.href = json.url; }); + } + + $historyTemplate.on("click", "#new_item_template", function() { + createTemplate("item"); }); + $historyTemplate.on("click", "#new_file_template", function() { + createTemplate("file"); + }); }; return AIRTIME;