Merge branch 'master' of github.com:crunchbutton/crunchbutton
This commit is contained in:
commit
2a463e8901
17
include/controllers/default/crunchbutton/api/dish/index.php
Normal file
17
include/controllers/default/crunchbutton/api/dish/index.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,7 +5,7 @@ class Crunchbutton_Dish extends Cana_Table {
|
|||||||
$out = $this->properties();
|
$out = $this->properties();
|
||||||
$out['price'] = number_format($out['price'],2);
|
$out['price'] = number_format($out['price'],2);
|
||||||
foreach ($this->options() as $option) {
|
foreach ($this->options() as $option) {
|
||||||
$out['_options'][$option->id_option] = $option->exports();
|
$out['_options'][] = $option->exports();
|
||||||
}
|
}
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
@ -20,6 +20,7 @@ class Crunchbutton_Dish extends Cana_Table {
|
|||||||
select `option`.*, dish_option.default, dish_option.id_dish_option from `option`
|
select `option`.*, dish_option.default, dish_option.id_dish_option from `option`
|
||||||
left join dish_option using(id_option)
|
left join dish_option using(id_option)
|
||||||
where id_dish="'.$this->id_dish.'"
|
where id_dish="'.$this->id_dish.'"
|
||||||
|
order by option.type asc, dish_option.sort desc, option.name
|
||||||
');
|
');
|
||||||
}
|
}
|
||||||
return $this->_options;
|
return $this->_options;
|
||||||
|
|||||||
@ -186,7 +186,7 @@ $(function() {
|
|||||||
saveRestaurant();
|
saveRestaurant();
|
||||||
});
|
});
|
||||||
|
|
||||||
var saveDishes = function() {
|
var saveDishes = function(complete) {
|
||||||
var selector = 'input.dataset-dish, select.dataset-dish, textarea.dataset-dish';
|
var selector = 'input.dataset-dish, select.dataset-dish, textarea.dataset-dish';
|
||||||
var dishes = [];
|
var dishes = [];
|
||||||
|
|
||||||
@ -245,7 +245,11 @@ $(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
console.log(dishes);
|
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() {
|
var saveRestaurant = function() {
|
||||||
@ -256,10 +260,11 @@ $(function() {
|
|||||||
App.cache('Restaurant', id, function() {
|
App.cache('Restaurant', id, function() {
|
||||||
var restaurant = getValues(selector, this);
|
var restaurant = getValues(selector, this);
|
||||||
restaurant.save(function() {
|
restaurant.save(function() {
|
||||||
saveHours();
|
saveHours(function() {
|
||||||
saveDishes();
|
saveDishes(function() {
|
||||||
|
|
||||||
location.href = location.href;
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -269,15 +274,18 @@ $(function() {
|
|||||||
|
|
||||||
App.cache('Restaurant', r.id_restaurant, function() {
|
App.cache('Restaurant', r.id_restaurant, function() {
|
||||||
App.restaurant = this.id_restaurant;
|
App.restaurant = this.id_restaurant;
|
||||||
saveHours();
|
saveHours(function() {
|
||||||
saveDishes();
|
saveDishes(function() {
|
||||||
location.href = '/admin/restaurants/' + App.restaurant;
|
location.href = '/admin/restaurants/' + App.restaurant;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var saveHours = function() {
|
var saveHours = function(complete) {
|
||||||
var selector = '.hours-date-hour input';
|
var selector = '.hours-date-hour input';
|
||||||
var id = App.restaurant;
|
var id = App.restaurant;
|
||||||
|
|
||||||
@ -297,7 +305,11 @@ $(function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(hours);
|
console.log(hours);
|
||||||
$.post('/api/restaurant/' + id + '/hours', {hours: hours});
|
$.post('/api/restaurant/' + id + '/hours', {hours: hours}, function() {
|
||||||
|
if (complete) {
|
||||||
|
complete();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user