better casting on form checkbox, setting populate flag properly based on if id is set (for create/update)

This commit is contained in:
Naomi 2013-08-05 15:05:26 -04:00
parent 31c604d09c
commit aaf2e5c2f6
4 changed files with 54 additions and 24 deletions

View File

@ -157,7 +157,9 @@ class PlayouthistoryController extends Zend_Controller_Action
Logging::info($params); Logging::info($params);
$historyService = new Application_Service_HistoryService(); $historyService = new Application_Service_HistoryService();
$historyService->createPlayedItem($params); $json = $historyService->createPlayedItem($params);
$this->_helper->json->sendJson($json);
} }
catch (Exception $e) { catch (Exception $e) {
Logging::info($e); Logging::info($e);
@ -168,9 +170,12 @@ class PlayouthistoryController extends Zend_Controller_Action
public function editListItemAction() public function editListItemAction()
{ {
$id = $this->_getParam('id', null); $id = $this->_getParam('id', null);
Logging::info("Id is: $id");
$populate = isset($id) ? true : false;
$historyService = new Application_Service_HistoryService(); $historyService = new Application_Service_HistoryService();
$form = $historyService->makeHistoryItemForm($id, true); $form = $historyService->makeHistoryItemForm($id, $populate);
$this->view->form = $form; $this->view->form = $form;
$this->view->dialog = $this->view->render('playouthistory/dialog.phtml'); $this->view->dialog = $this->view->render('playouthistory/dialog.phtml');
@ -188,14 +193,20 @@ class PlayouthistoryController extends Zend_Controller_Action
public function updateListItemAction() public function updateListItemAction()
{ {
$request = $this->getRequest(); try {
$params = $request->getPost(); $request = $this->getRequest();
Logging::info($params); $params = $request->getPost();
Logging::info($params);
$historyService = new Application_Service_HistoryService();
$json = $historyService->editPlayedItem($params); $historyService = new Application_Service_HistoryService();
$json = $historyService->editPlayedItem($params);
$this->view->data = $json;
$this->_helper->json->sendJson($json);
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
} }
public function updateAggregateItemAction() public function updateAggregateItemAction()
@ -207,7 +218,7 @@ class PlayouthistoryController extends Zend_Controller_Action
$historyService = new Application_Service_HistoryService(); $historyService = new Application_Service_HistoryService();
$json = $historyService->editPlayedFile($params); $json = $historyService->editPlayedFile($params);
$this->view->data = $json; $this->_helper->json->sendJson($json);
} }
public function templateAction() public function templateAction()

View File

@ -13,6 +13,7 @@ class Application_Form_EditHistoryItem extends Zend_Form
const ITEM_TYPE = "type"; const ITEM_TYPE = "type";
const ITEM_CLASS = "class"; const ITEM_CLASS = "class";
const ITEM_OPTIONS = "options";
const ITEM_ID_SUFFIX = "name"; const ITEM_ID_SUFFIX = "name";
const TEXT_INPUT_CLASS = "input_text"; const TEXT_INPUT_CLASS = "input_text";
@ -80,8 +81,13 @@ class Application_Form_EditHistoryItem extends Zend_Form
), ),
TEMPLATE_BOOLEAN => array( TEMPLATE_BOOLEAN => array(
"class" => "Zend_Form_Element_Checkbox", "class" => "Zend_Form_Element_Checkbox",
"filters" => array( "validators" => array(
"Boolean" array(
"class" => "Zend_Validate_InArray",
"options" => array(
"haystack" => array(0,1)
)
)
) )
), ),
TEMPLATE_INT => array( TEMPLATE_INT => array(
@ -93,9 +99,6 @@ class Application_Form_EditHistoryItem extends Zend_Form
), ),
"attrs" => array( "attrs" => array(
"class" => self::TEXT_INPUT_CLASS "class" => self::TEXT_INPUT_CLASS
),
"filters" => array(
"Int"
) )
), ),
TEMPLATE_FLOAT => array( TEMPLATE_FLOAT => array(
@ -198,7 +201,7 @@ class Application_Form_EditHistoryItem extends Zend_Form
if (isset($formElType["attrs"])) { if (isset($formElType["attrs"])) {
$attrs = $formElType["filters"]; $attrs = $formElType["attrs"];
foreach ($attrs as $key => $value) { foreach ($attrs as $key => $value) {
$el->setAttrib($key, $value); $el->setAttrib($key, $value);
@ -219,7 +222,8 @@ class Application_Form_EditHistoryItem extends Zend_Form
$validators = $formElType["validators"]; $validators = $formElType["validators"];
foreach ($validators as $index => $arr) { foreach ($validators as $index => $arr) {
$validator = new $arr[self::ITEM_CLASS](); $options = isset($arr[self::ITEM_OPTIONS]) ? $arr[self::ITEM_OPTIONS] : null;
$validator = new $arr[self::ITEM_CLASS]($options);
//extra validator info //extra validator info
if (isset($arr["params"])) { if (isset($arr["params"])) {

View File

@ -635,6 +635,7 @@ class Application_Service_HistoryService
try { try {
$form = $this->makeHistoryItemForm(null); $form = $this->makeHistoryItemForm(null);
$history_id = $form->getElement("his_item_id"); $history_id = $form->getElement("his_item_id");
$json = array();
if ($form->isValid($data)) { if ($form->isValid($data)) {
$history_id->setIgnore(true); $history_id->setIgnore(true);
@ -647,8 +648,14 @@ class Application_Service_HistoryService
} }
else { else {
Logging::info("created list item NOT VALID"); Logging::info("created list item NOT VALID");
Logging::info($form->getMessages());
$msgs = $form->getMessages();
Logging::info($msgs);
$json["error"] = $msgs;
} }
return $json;
} }
catch (Exception $e) { catch (Exception $e) {
throw $e; throw $e;
@ -664,6 +671,9 @@ class Application_Service_HistoryService
$history_id = $form->getElement("his_item_id"); $history_id = $form->getElement("his_item_id");
$history_id->setRequired(true); $history_id->setRequired(true);
Logging::info($data);
$json = array();
if ($form->isValid($data)) { if ($form->isValid($data)) {
$history_id->setIgnore(true); $history_id->setIgnore(true);
$values = $form->getValues(); $values = $form->getValues();
@ -675,12 +685,17 @@ class Application_Service_HistoryService
} }
else { else {
Logging::info("edited list item NOT VALID"); Logging::info("edited list item NOT VALID");
$msgs = $form->getMessages();
Logging::info($msgs);
$json["error"] = $msgs;
} }
Logging::info($form->getMessages()); return $json;
} }
catch (Exception $e) { catch (Exception $e) {
Logging::info($e); throw $e;
} }
} }

View File

@ -379,8 +379,8 @@ var AIRTIME = (function(AIRTIME) {
$.post(url, data, function(json) { $.post(url, data, function(json) {
//TODO put errors on form. //TODO put errors on form.
if (json.data !== "true") { if (json.error !== undefined) {
//makeHistoryDialog(json.dialog);
} }
else { else {
removeHistoryDialog(); removeHistoryDialog();