UNC Chipotle and Hamilton Whole Foods notifications deleted from database #3109

This commit is contained in:
Daniel Camargo 2014-06-05 10:15:41 -03:00
parent 1fda55f67c
commit c83ee4e379
2 changed files with 55 additions and 47 deletions

View File

@ -662,34 +662,43 @@ class Crunchbutton_Restaurant extends Cana_Table_Trackchange {
* @param array $elements
*/
public function saveNotifications($elements) {
c::db()->query('DELETE FROM notification WHERE id_restaurant="'.$this->id_restaurant.'"');
if(!$elements)
return;
foreach ($elements as $data) {
foreach( $elements as $element ){
$shouldSave = false;
if( $data['type'] == 'admin' && $data['id_admin'] ){
$id_admin = $data['id_admin'];
if( $element[ 'type' ] == 'admin' && trim( $element[ 'id_admin' ] ) != '' ){
$id_admin = $element[ 'id_admin' ];
$value = '';
$shouldSave = true;
} if( $data['type'] != 'admin' && $data['value'] ){
$value = $data['value'];
}
if( $element[ 'type' ] != 'admin' && trim( $element[ 'value' ] ) != '' ){
$value = $element[ 'value' ];
$id_admin = NULL;
$shouldSave = true;
}
if (!$shouldSave) { continue; }
$element = new Crunchbutton_Notification($data['id_notification']);
$element->id_restaurant = $this->id_restaurant;
$element->active = ($data['active'] == 'true' || $data['active'] == '1') ? "1" : "0";
$element->type = $data['type'];
$element->id_admin = $id_admin;
$element->value = $value;
$element->save();
// echo '<pre>';var_dump( $shouldSave, $element );exit();
if( $shouldSave ){
if( $element[ 'id_notification' ] ){
$notification = Crunchbutton_Notification::o( $element[ 'id_notification' ] );
} else {
$notification = new Crunchbutton_Notification;
}
$notification->id_restaurant = $this->id_restaurant;
$notification->active = ( $element[ 'active' ] == 'true' || $element[ 'active' ] == '1' ) ? 1 : 0;
$notification->type = $element[ 'type' ];
$notification->id_admin = $id_admin;
$notification->value = $value;
$notification->save();
} else {
// remove
if( $element[ 'id_notification' ] ){
c::db()->query( 'DELETE FROM notification WHERE id_notification = "' . $element[ 'id_notification' ] . '"' );
}
}
}
$this->_notifications = null;
$where = [];
$where['active'] = NULL;
$elements = $this->notifications($where);
$where = [];
$where[ 'active' ] = NULL;
$elements = $this->notifications( $where );
return $elements;
}

View File

@ -20,7 +20,7 @@ var UTIL = {
},
slide_swap : function($set1, $set2, duration) {
var $set3 = $set2.last().nextAll();
var mb_prev = UTIL.cssprop($set1.first().prev(), "margin-bottom");
if (isNaN(mb_prev)) mb_prev = 0;
var mt_next = UTIL.cssprop($set2.last().next(), "margin-top");
@ -36,17 +36,17 @@ var UTIL = {
move1 = h2 + Math.max(mb_2, mt_1) + Math.max(mb_prev, mt_2) - Math.max(mb_prev, mt_1);
move2 = -h1 - Math.max(mb_1, mt_2) - Math.max(mb_prev, mt_1) + Math.max(mb_prev, mt_2);
move3 = move1 + $set1.first().offset().top + h1 - $set2.first().offset().top - h2 +
move3 = move1 + $set1.first().offset().top + h1 - $set2.first().offset().top - h2 +
Math.max(mb_1,mt_next) - Math.max(mb_2,mt_next);
// let's move stuff
$set1.css('position', 'relative');
$set2.css('position', 'relative');
$set3.css('position', 'relative');
$set3.css('position', 'relative');
$set1.animate({'top': move1}, {duration: duration});
$set3.animate({'top': move3}, {duration: duration/2});
$set2.animate({'top': move2}, {duration: duration, complete: function() {
// rearrange the DOM and restore positioning when we're done moving
// rearrange the DOM and restore positioning when we're done moving
$set1.insertAfter($set2.last())
$set1.css({'position': 'static', 'top': 0});
$set2.css({'position': 'static', 'top': 0});
@ -556,7 +556,7 @@ var WIDGET = {
});
$(modal_dom).find('.admin-modal-title').text(dish_name);
select_element_1 = $(modal_dom)
.find('select.move-dish-to-category-select')
.html('');
@ -626,9 +626,9 @@ var WIDGET = {
.on(
'click.copy-dish-to-category-button',
(function() {
return function() {
return function() {
self.copy_dish_to_category(
dish_dom,
dish_dom,
$(modal_dom).find('select.copy-dish-to-category-select').val());
$(modal_dom).dialog('close');
};
@ -662,7 +662,7 @@ var WIDGET = {
};
this.apply_dish = function(dish_dom, dish ) {
// 'view' button
$(dish_dom).find('.details-button').first().click(function() {
UTIL.toggle_visibility(dish_dom.find('.admin-menu-dish-details'));
@ -677,12 +677,12 @@ var WIDGET = {
var remaining = 60 - $( this ).val().length;
$( dish_dom ).find( '.description-warning' ).text( remaining );
} )
setTimeout( function(){
var remaining = 60 - $( dish_dom ).find( '.admin-menu-dish-description' ).first().val().length;
$( dish_dom ).find( '.description-warning' ).text( remaining );
}, 100 );
// it means is a new one
if( isNaN( dish.id_dish ) ){
@ -769,8 +769,8 @@ var WIDGET = {
type : 'dish',
},
{duration:100});
}
});
}
});
options = dish._options;
if(!options) options = [];
@ -964,7 +964,7 @@ var WIDGET = {
});
restaurant._categories = categories;
};
this.validate = function(invalid_list) {
this.validate = function(invalid_list) {
};
this.remove = function() { self.dom.remove(); }
this.reset_dom = function() {
@ -1002,7 +1002,7 @@ var WIDGET = {
active: restaurant.confirmation,
id: null,
id_notification: null,
id_restaurant: restaurant.id,
id_restaurant: restaurant.id,
type: 'confirmation',
value: restaurant.confirmation_type
};
@ -1026,7 +1026,6 @@ var WIDGET = {
restaurant.confirmation_type = data.confirmation_type;
continue;
}
if( ( !data.value || data.value==='' ) && data.type != 'admin' ) continue;
restaurant._notifications.push(data);
}
},
@ -1184,7 +1183,7 @@ var ADMIN = {
map = new google.maps.Map(
$('#restaurant-map')[0],
{
zoom : 14,
zoom : 14,
mapTypeId : google.maps.MapTypeId.ROADMAP
});
map.setCenter(data[0].geometry.location);
@ -1279,9 +1278,9 @@ var ADMIN = {
}
$('#save-button').text('Saving...');
ASYNC.req(
{
{
type : 'sav',
data : {
data : {
// uncomment here and in controller to use serialization
// serialized_data : $.param(ADMIN.restaurant),
data : ADMIN.restaurant,
@ -1320,8 +1319,8 @@ var DOM_MAP = {
flush : function() {
for(item in this.map.data.text) {
UTIL.setJSONVal(
ADMIN.restaurant,
this.map.data.text[item],
ADMIN.restaurant,
this.map.data.text[item],
$(item).val());
}
for(item in this.map.data.func) {
@ -1406,25 +1405,25 @@ var DOM_MAP = {
widget : [], // a list of widgets supporting 'apply' and 'flush' funcs etc
func : {
'.button-fax' : {
apply : function(restaurant, element) {
apply : function(restaurant, element) {
$(element).attr('href', '/restaurants/' + restaurant.id_restaurant + '/fax');
},
flush : function(restaurant, element) { },
},
'.button-pay' : {
apply : function(restaurant, element) {
apply : function(restaurant, element) {
$(element).attr('href', '/restaurants/' + restaurant.id_restaurant + '/pay');
},
flush : function(restaurant, element) { },
},
'#view-on-site-button' : {
apply : function(restaurant, element) {
apply : function(restaurant, element) {
$(element).attr('href', 'https://crunchbutton.com/food-delivery/' + restaurant.id_restaurant);
},
flush : function(restaurant, element) { },
},
'#view-on-site-button' : {
apply : function(restaurant, element) {
apply : function(restaurant, element) {
$(element).attr('href', 'https://crunchbutton.com/food-delivery/' + restaurant.id_restaurant);
},
flush : function(restaurant, element) { },
@ -1432,7 +1431,7 @@ var DOM_MAP = {
'#restaurant-image' : {
apply : function(restaurant, element) {
$(element).find('a').attr(
'href',
'href',
'/restaurants/' + restaurant.id_restaurant + '/image');
$(element).find('img').attr('src', restaurant.img);
},
@ -1536,7 +1535,7 @@ var DOM_MAP = {
end_m = parseInt(m[5]) || 0;
end_ampm = m[6].toLowerCase();
if(begin_ampm === 'am' && begin_h === 12) {
begin_h = begin_h - 12;
begin_h = begin_h - 12;
if(end_h === 12 && end_ampm === 'am' && end_m > begin_m) {
end_h = end_h - 12;
}