From 25214575159086362f9803827b3cf9e4e4ce29da Mon Sep 17 00:00:00 2001 From: arzynik Date: Thu, 27 Sep 2012 12:33:21 -0400 Subject: [PATCH 1/4] safe save --- www/assets/js/admin.js | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/www/assets/js/admin.js b/www/assets/js/admin.js index b1fef26ea..5ab0e3c57 100644 --- a/www/assets/js/admin.js +++ b/www/assets/js/admin.js @@ -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(); - - location.href = location.href; + 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(); + } + }); }); } }; From 6ccc49b7f67e27095ec8fe0a41aeaf9a99e2f67f Mon Sep 17 00:00:00 2001 From: arzynik Date: Thu, 27 Sep 2012 14:32:39 -0400 Subject: [PATCH 2/4] removed any aumated refreshing for shityness --- www/assets/js/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/assets/js/admin.js b/www/assets/js/admin.js index 5ab0e3c57..b3ec5329f 100644 --- a/www/assets/js/admin.js +++ b/www/assets/js/admin.js @@ -262,7 +262,7 @@ $(function() { restaurant.save(function() { saveHours(function() { saveDishes(function() { - location.href = location.href; + //location.href = location.href; }); }); }); From 91b292b25a622b68ad59d5bbe677deaee57846d2 Mon Sep 17 00:00:00 2001 From: arzynik Date: Thu, 27 Sep 2012 14:42:25 -0400 Subject: [PATCH 3/4] wtf --- www/assets/js/admin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/assets/js/admin.js b/www/assets/js/admin.js index b3ec5329f..65ea49a9f 100644 --- a/www/assets/js/admin.js +++ b/www/assets/js/admin.js @@ -262,7 +262,7 @@ $(function() { restaurant.save(function() { saveHours(function() { saveDishes(function() { - //location.href = location.href; + }); }); }); From 8f60955f73f86d6906e50f7b7a02eca8c079b5b9 Mon Sep 17 00:00:00 2001 From: arzynik Date: Thu, 27 Sep 2012 17:12:18 -0400 Subject: [PATCH 4/4] added some sort options --- .../default/crunchbutton/api/dish/index.php | 17 +++++++++++++++++ include/library/Crunchbutton/Dish.php | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 include/controllers/default/crunchbutton/api/dish/index.php diff --git a/include/controllers/default/crunchbutton/api/dish/index.php b/include/controllers/default/crunchbutton/api/dish/index.php new file mode 100644 index 000000000..916113b0c --- /dev/null +++ b/include/controllers/default/crunchbutton/api/dish/index.php @@ -0,0 +1,17 @@ +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; + } + } +} \ No newline at end of file diff --git a/include/library/Crunchbutton/Dish.php b/include/library/Crunchbutton/Dish.php index dd4f4892b..5f7358aac 100644 --- a/include/library/Crunchbutton/Dish.php +++ b/include/library/Crunchbutton/Dish.php @@ -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;