Merge branch 'master' of https://github.com/crunchbutton/crunchbutton
This commit is contained in:
commit
367388c7d1
@ -212,6 +212,8 @@ class Crunchbutton_Restaurant extends Cana_Table
|
||||
*/
|
||||
public function saveCategories($rawData)
|
||||
{
|
||||
$originalCategories = $this->categories();
|
||||
$doNotDelete = [];
|
||||
if ($rawData) {
|
||||
foreach ($rawData as $data) {
|
||||
// if (!$data['name']) continue;
|
||||
@ -220,8 +222,16 @@ class Crunchbutton_Restaurant extends Cana_Table
|
||||
$element->name = $data['name'];
|
||||
$element->sort = $data['sort'];
|
||||
$element->save();
|
||||
$doNotDelete[] = $element->id_category;
|
||||
}
|
||||
}
|
||||
foreach($originalCategories as $toDelete) {
|
||||
/* @var $toDelete Crunchbutton_Category */
|
||||
if (!in_array($toDelete->id_category, $doNotDelete)) {
|
||||
$toDelete->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$this->_categories = null;
|
||||
$elements = $this->categories();
|
||||
return $elements;
|
||||
|
||||
@ -93,7 +93,7 @@
|
||||
</div>
|
||||
<script>
|
||||
$(function() {
|
||||
$('.refund').live('click',function() {
|
||||
$(document).on('click', '.refund', function() {
|
||||
if (!confirm('Are you sure you want to refund this?')) {
|
||||
return;
|
||||
}
|
||||
@ -102,16 +102,16 @@
|
||||
el.replaceWith('REFUNDED');
|
||||
});
|
||||
});
|
||||
|
||||
$('.admin-order-search').live('click', function() {
|
||||
|
||||
$(document).on('click', '.admin-order-search', function() {
|
||||
App.orders.load();
|
||||
});
|
||||
|
||||
$('.admin-order-export').live('click', function() {
|
||||
|
||||
$(document).on('click', '.admin-order-export', function() {
|
||||
App.orders.export();
|
||||
});
|
||||
|
||||
$('[name="order-search"]').live('keyup', function(e) {
|
||||
$(document).on('keyup', '.[name="order-search"]', function(e) {
|
||||
if (e.which == 13) {
|
||||
App.orders.load();
|
||||
}
|
||||
|
||||
@ -26,6 +26,22 @@ function _selectedCommunity(Crunchbutton_Community $current, Crunchbutton_Commun
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<script>
|
||||
|
||||
$(function(){
|
||||
$('body').on('mouseenter', '.jqui-button', function(){
|
||||
$(this).removeClass('ui-state-default');
|
||||
$(this).addClass ('ui-state-hover');
|
||||
});
|
||||
$('body').on('mouseleave', '.jqui-button', function(){
|
||||
$(this).addClass ('ui-state-default');
|
||||
$(this).removeClass('ui-state-hover');
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/**
|
||||
* sets the page one column only
|
||||
@ -60,18 +76,25 @@ function _selectedCommunity(Crunchbutton_Community $current, Crunchbutton_Commun
|
||||
input.notification {width: 400px;}
|
||||
|
||||
|
||||
.labeled-fields > label {
|
||||
.labeled-fields label {
|
||||
float: none;
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.labeled-fields > label span {
|
||||
.labeled-fields label span {
|
||||
display: inline-block;
|
||||
width: 115px;
|
||||
}
|
||||
.labeled-fields .clear + label { margin-top: 5px; }
|
||||
|
||||
#categories .button-delete {
|
||||
cursor: pointer;
|
||||
float: right;
|
||||
margin: 2px;
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<div class="admin-id_restaurant" data-id_restaurant=""></div>
|
||||
|
||||
@ -19,6 +19,49 @@ var App = {
|
||||
_pageInit: false
|
||||
};
|
||||
|
||||
|
||||
function _deleteCategoryDialog(){
|
||||
$('body').on('click', '.jqui-button.button-delete', function(){
|
||||
var category_id = $(this).parent('.ui-accordion-content').prev('h3').data().id_category;
|
||||
var categories = App.restaurantObject.categories();
|
||||
var catOptions = '';
|
||||
for(var i = 0; i < categories.length; i++) {
|
||||
var disabled = false
|
||||
if (categories[i].id_category == category_id) {
|
||||
disabled = ' disabled="disabled" ';
|
||||
}
|
||||
catOptions += '<option value="' + categories[i].id_category + '" ' + disabled + '>' + categories[i].name + '</option>';
|
||||
}
|
||||
|
||||
|
||||
var html = '<div id="dialog-delete-category" title="Delete category" class="labeled-fields"> ' +
|
||||
'<p>You are about to delete this category. Existing dishes in the category will be moved to another category.<p>' +
|
||||
'<br />' +
|
||||
'<label><span class="label">Move dishes to:</span><select>' + catOptions + '</select><label>'
|
||||
'<p>Are you sure you want to delete the category?</p>' +
|
||||
'</div>';
|
||||
$(html).dialog({
|
||||
resizable: false,
|
||||
height: 200,
|
||||
width: 400,
|
||||
modal: true,
|
||||
buttons: {
|
||||
Delete: function() {
|
||||
var to_id = $('select', this).val();
|
||||
deleteCategory(category_id, to_id);
|
||||
$(this).dialog('close');
|
||||
$(this).remove();
|
||||
},
|
||||
Cancel: function() {
|
||||
$(this).dialog('close');
|
||||
$(this).remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Populates notifications types with empty fields to be inserted
|
||||
*
|
||||
@ -126,6 +169,7 @@ function _loadRestaurant() {
|
||||
* Swip all categories
|
||||
*
|
||||
* @todo Use the App.createCategory
|
||||
* @todo Encapsulate the categories loading in a private _loadCategories() method
|
||||
*/
|
||||
for (var i in categories) {
|
||||
var dishes = categories[i].dishes();
|
||||
@ -133,6 +177,7 @@ function _loadRestaurant() {
|
||||
var sort = (categories[i].sort && (categories[i].sort != 'null')) ? categories[i].sort : 0;
|
||||
var $categoryTab = $('<h3 data-id_category="'+ categories[i].id_category +'">'+ name+'</h3>' +
|
||||
'<div>' +
|
||||
'<div title="delete" class="ui-state-default ui-corner-all jqui-button button-delete"><span class="ui-icon ui-icon-trash"></span></div>'+
|
||||
'<div class="labeled-fields category">' +
|
||||
'<label><span class="label">Name</span> <input name="name" value="' + name + '" /></label>' +
|
||||
'<label><span class="label">Sort Order</span> <input name="sort" value="' + sort + '" /></label>' +
|
||||
@ -158,6 +203,8 @@ function _loadRestaurant() {
|
||||
}, 1.1 * speed);
|
||||
}
|
||||
});
|
||||
_deleteCategoryDialog();
|
||||
// end of loadingCategories;
|
||||
|
||||
if (!isDishes) {
|
||||
$('input[name="dish_check"][value="0"]').prop('checked', true);
|
||||
@ -340,7 +387,7 @@ function saveDishes (complete) {
|
||||
});
|
||||
// Just to make sure that the name was typed and the user don't clicked at 'Add another dish?' by mistake.
|
||||
if( dish.name && dish.name != 'null' && dish.name != '' ){
|
||||
dishes[dishes.length] = dish;
|
||||
dishes[dishes.length] = dish;
|
||||
}
|
||||
});
|
||||
|
||||
@ -492,6 +539,16 @@ function saveHours (complete) {
|
||||
}
|
||||
};
|
||||
|
||||
function deleteCategory(from_id, to_id) {
|
||||
var $toDelete = $('h3[data-id_category="'+from_id+'"]');
|
||||
var dishes = $('.admin-food-item-wrap', $toDelete.next());
|
||||
$('select[name="dish-id_category"]').val(to_id);
|
||||
$('h3[data-id_category="'+to_id+'"]').next().append(dishes);
|
||||
$toDelete.next().remove();
|
||||
$toDelete.remove();
|
||||
}
|
||||
|
||||
|
||||
function getValues(selector, restaurant) {
|
||||
$(selector).each(function() {
|
||||
var name, value, group = false;
|
||||
@ -1142,7 +1199,7 @@ $(function() {
|
||||
},
|
||||
Cancel: function() {
|
||||
$(this).dialog('close');
|
||||
$(this).find('[admin-category-name"]').val('');
|
||||
$(this).find('[name="admin-category-name"]').val('');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user