Merge branch 'master' of github.com:crunchbutton/crunchbutton

This commit is contained in:
arzynik 2012-09-27 14:40:32 -07:00
commit 2a463e8901
3 changed files with 41 additions and 11 deletions

View File

@ -0,0 +1,17 @@
<?php
class Controller_api_dish extends Crunchbutton_Controller_Rest {
public function init() {
switch ($this->method()) {
case 'post':
case 'get':
$out = Dish::o(c::getPagePiece(2));
if ($out->id_dish) {
echo $out->json();
} else {
echo json_encode(['error' => 'invalid object']);
}
break;
}
}
}

View File

@ -5,7 +5,7 @@ class Crunchbutton_Dish extends Cana_Table {
$out = $this->properties();
$out['price'] = number_format($out['price'],2);
foreach ($this->options() as $option) {
$out['_options'][$option->id_option] = $option->exports();
$out['_options'][] = $option->exports();
}
return $out;
}
@ -20,6 +20,7 @@ class Crunchbutton_Dish extends Cana_Table {
select `option`.*, dish_option.default, dish_option.id_dish_option from `option`
left join dish_option using(id_option)
where id_dish="'.$this->id_dish.'"
order by option.type asc, dish_option.sort desc, option.name
');
}
return $this->_options;

View File

@ -186,7 +186,7 @@ $(function() {
saveRestaurant();
});
var saveDishes = function() {
var saveDishes = function(complete) {
var selector = 'input.dataset-dish, select.dataset-dish, textarea.dataset-dish';
var dishes = [];
@ -245,7 +245,11 @@ $(function() {
});
console.log(dishes);
$.post('/api/restaurant/' + App.restaurant + '/dishes', {dishes: dishes});
$.post('/api/restaurant/' + App.restaurant + '/dishes', {dishes: dishes}, function() {
if (complete) {
complete();
}
});
}
var saveRestaurant = function() {
@ -256,10 +260,11 @@ $(function() {
App.cache('Restaurant', id, function() {
var restaurant = getValues(selector, this);
restaurant.save(function() {
saveHours();
saveDishes();
saveHours(function() {
saveDishes(function() {
location.href = location.href;
});
});
});
});
} else {
@ -269,15 +274,18 @@ $(function() {
App.cache('Restaurant', r.id_restaurant, function() {
App.restaurant = this.id_restaurant;
saveHours();
saveDishes();
location.href = '/admin/restaurants/' + App.restaurant;
saveHours(function() {
saveDishes(function() {
location.href = '/admin/restaurants/' + App.restaurant;
});
});
});
});
}
};
var saveHours = function() {
var saveHours = function(complete) {
var selector = '.hours-date-hour input';
var id = App.restaurant;
@ -297,7 +305,11 @@ $(function() {
}
}
console.log(hours);
$.post('/api/restaurant/' + id + '/hours', {hours: hours});
$.post('/api/restaurant/' + id + '/hours', {hours: hours}, function() {
if (complete) {
complete();
}
});
});
}
};