partial for issue #377, rearrange dishesh

* added protected _jsonBoolean() metod to turn json boolean values to something Cana_Table understood to disable the items
* added the sort field to the array of data to be send
* improved the way the dish form looks like because of the different fields
* added the sort form field to the admin.js and the sort value to the saveDishes() js action
This commit is contained in:
Stuardo Rodríguez 2013-02-08 10:33:08 -05:00
parent 85a0a346b2
commit e5560670b3
4 changed files with 50 additions and 4 deletions

View File

@ -1,6 +1,43 @@
<?php
class Crunchbutton_Restaurant extends Cana_Table {
class Crunchbutton_Restaurant extends Cana_Table
{
/**
* Json booleans are tricky as the can return different values for true or false
*
* Cana_Table does not store boolean values, so the boolean is turned to
* integer to be stored.
*
* @param array $array Where to look for the key
* @param string $key What to look in the $array
* @param bool $default What to return if not found
*
* @todo Move to somewhere else where
*/
protected function _jsonBoolean($array, $key, $default = false)
{
$return = $default;
if (isset($array[$key])){
switch ($array[$key]) {
case 'true':
case '1':
// case 1:
// case true:
$return = true;
break;
case 'false':
case '0':
// case 0:
// case false:
$return = false;
break;
default:
throw new Exception("Unrecognized JSON boolean value '{$array[$key]}' for key '$key'");
}
}
return (int) $return;
}
public function __construct($id = null) {
parent::__construct();
$this
@ -222,10 +259,11 @@ class Crunchbutton_Restaurant extends Cana_Table {
foreach ($newDishes as $dish) {
$dishO = new Dish($dish['id_dish']);
$dishO->id_restaurant = $this->id_restaurant;
$dishO->active = isset($dish['active']) ? $dish['active'] : 1;
$dishO->active = $this->_jsonBoolean($dish, 'active', true);
$dishO->name = $dish['name'];
$dishO->description = $dish['description'];
$dishO->price = $dish['price'];
$dishO->sort = isset($dish['sort']) ? $dish['sort'] : 0;
if (isset($dish['id_category']) && $dish['id_category']) {
$dishO->id_category = $dish['id_category'];
} elseif (!$dishO->id_category) { // this else doesn't make sense to me, but it is what it was before my changes

View File

@ -52,8 +52,10 @@ input.notification {width: 400px;}
clear: both;
}
/* space between label and select */
.admin-food-item-content-padding > label span { margin-right: 4px; }
.admin-food-item-content-padding > label span {
display: inline-block;
width: 115px;
}
</style>

View File

@ -287,6 +287,7 @@ function saveDishes (complete) {
price: values['dish-price'],
id_category: values['dish-id_category'],
active: values['dish-active'],
sort: values['dish-sort']
};
if (id) {
@ -584,6 +585,7 @@ App.showDish = function(dishItem) {
.append('<div class="input-faker dish-price"><div class="input-faker-content">$&nbsp;</div><input type="text" placeholder="" name="dish-price" value="' + dishItem.price + '" class="dataset-dish clean-input" data-clean_type="float"><div class="divider"></div></div>')
.append('<label><span>Move to category</span><select name="dish-id_category" class="dataset-dish clean-input">' + categoryOptions + '</select></label')
.append('<label><span>Active</span><input type="checkbox" name="dish-active" class="dataset-dish clean-input" ' + active + ' /></label')
.append('<label><span>Sort order</span><input name="dish-sort" class="dataset-dish clean-input" value="' + dishItem.sort + '" /></label')
.append('<textarea placeholder="Description" name="dish-description" class="dataset-dish clean-input dish-description">' + dishDescription + '</textarea>')
.append('<div class="divider"></div><div class="divider dots" style="margin: 10px 0 10px 0;"></div>')
.append(options);

View File

@ -118,6 +118,10 @@ var Restaurant = function(id) {
* offset = -(today.getTimezoneOffset()); // @todo: ensure this works on positive tz
*/
self.open = function() {
// console.log(this.timezone);
var isOpen = false;
var today = Date.today().toString('ddd').toLowerCase();
if (this._hours == undefined || this._hours[today] == undefined) {