Skip to content

Commit

Permalink
deletion completion, lots of bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin olson authored and acidjazz committed Feb 8, 2012
1 parent 9449175 commit 7579724
Show file tree
Hide file tree
Showing 18 changed files with 179 additions and 85 deletions.
7 changes: 4 additions & 3 deletions ajx/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

$ingredient = new ingredient($data['recipe_id'], $data['title']);
$ingredient->save();
$ingredients = ingredient::gets('WHERE recipe_id = %n', $data['recipe_id']);
$ingredients = ingredient::gets('WHERE recipe_id = %n ORDER BY `set`', $data['recipe_id']);
$newone = $data['title'];

ob_start();
Expand All @@ -41,7 +41,7 @@
$instruction = new instruction($data['recipe_id'], $data['step']);
$instruction->title = $data['title'];
$instruction->save();
$instructions = instruction::gets('WHERE recipe_id = %n', $data['recipe_id']);
$instructions = instruction::gets('WHERE recipe_id = %n ORDER BY `set`', $data['recipe_id']);
$newone = $data['title'];

ob_start();
Expand All @@ -57,7 +57,8 @@

$data = json_decode($_REQUEST['data'], true);

$dr = new detail_recipe($data['recipe_id'], $data['type'], $data['value']);
$dr = new detail_recipe($data['recipe_id'], $data['name'], $data['value']);
$dr->type = $data['type'];
$dr->save();
$detail_recipe = detail_recipe::gets('WHERE recipe_id = %n', $data['recipe_id']);
$newone = $data['value'];
Expand Down
20 changes: 20 additions & 0 deletions ajx/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

switch ($data['type']) {

case 'detail' :
$grouped['detail'][] = $data['value'];
break;

case 'detail_recipe' :
$grouped['detail_recipe'][] = $data['value'];
break;
Expand All @@ -24,6 +28,10 @@
$grouped['instruction'][] = $data['value'];
break;

case 'ingredient' :
$grouped['ingredient'][] = $data['value'];
break;

}
}

Expand All @@ -39,6 +47,12 @@

}

if (isset($grouped['detail'])) {
foreach ($grouped['detail'] as $d) {
kdb::i()->q('DELETE FROM detail WHERE name = %s AND `value` = %s', $d);
}
}

if (isset($grouped['detail_recipe'])) {
foreach ($grouped['detail_recipe'] as $dr) {
kdb::i()->q('DELETE FROM detail_recipe WHERE recipe_id = %n AND `type` = %s AND `value` = %s', $dr);
Expand All @@ -52,5 +66,11 @@
}
}

if (isset($grouped['ingredient'])) {
foreach ($grouped['ingredient'] as $ingredient) {
kdb::i()->q('DELETE FROM ingredient WHERE recipe_id = %n AND `title` = %s', $ingredient);
}
}

echo json_encode(array('error' => $error));

11 changes: 3 additions & 8 deletions ajx/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@

$data = json_decode($_REQUEST['data'], true);

if (empty($data['type'])) {
$error = 'You must specify a type';
if (empty($data['name'])) {
$error = 'You must specify a name';
break;
}

if (empty($data['value'])) {
$error = 'You must specify a value';
break;
}

$detail = new detail($data['site'], $data['type'], $data['value']);
$detail = new detail($data['name'], $data['type'], $data['value']);
$detail->save();

break;
Expand Down
2 changes: 1 addition & 1 deletion ajx/set.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
}
$instructions->save();

hpr($data);
echo json_encode($data);


27 changes: 24 additions & 3 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,31 @@ body {
}

.header {
position: fixed;
padding: 10px;
background-color: #f5f5f5;
border-bottom: 1px solid #e5e5e5;
margin: 0 0 10px 0;
margin: 0 0 0 0;
width: 100%;
}

.shadow {
overflow: hidden;
position: fixed;
padding-bottom: 10px;
margin: 60px 0 10px 0;
width: 100%;
height: 10px;
}

.shadow > div {
height: 10px;
border-bottom: 1px solid #666;
-moz-box-shadow: 0 2px 2px #666;
-webkit-box-shadow: 0 2px 2px #666;
box-shadow: 0 2px 2px #666;
}

.footer {
margin: 10px 0 0 0;
padding: 10px;
Expand Down Expand Up @@ -71,6 +90,7 @@ body {
.container {
width: 960px;
margin: 0 auto;
padding: 80px 0 0 0;
}

.listing {
Expand Down Expand Up @@ -100,6 +120,7 @@ body {
}
.listing_active {
background-color: #faabab;
border-bottom: 1px solid #00ff00;
}
.listing_selected {
background-color: #5b9ecc;
Expand Down Expand Up @@ -249,9 +270,9 @@ body {

.notify {

position: absolute;
top: 0;
left: 0;
position: fixed;
background-color: #faf7ab;
text-align: center;
font-size: 14px;
Expand All @@ -273,7 +294,7 @@ body {
}

.status {
position: absolute;
position: fixed;
top: 60px;
left: 800px;
text-align: center;
Expand Down
2 changes: 1 addition & 1 deletion details.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
$details = array();

foreach (detail::gets() as $detail) {
$details[$detail->type][] = $detail->data();
$details[$detail->name][] = $detail->data();
}

require_once 'tpl/details.php';
Expand Down
105 changes: 71 additions & 34 deletions jst/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,13 @@ var admin = {

init: function() {

admin.handlers();

// firefox not obeying 'selected'
if (document.forms[0]) {
document.forms[0].reset();
}

// global listing handler, show _hover and display the hidden delete button
$('.listing tr').hover(function() {

if ($(this).children().is('TD')) {
$(this).addClass('listing_hover');
$(this).find('.delete_button').transition({opacity: 1}, 0);
}

}, function() {
$(this).removeClass('listing_hover');
$(this).find('.delete_button').transition({opacity: 0}, 0);
});


$('.delete_button').click(function(e) {
e.stopPropagation();
$(this).closest('TR').toggleClass('listing_active');

$('.listing_active').length > 0 ? $('.button_delete_selected').removeClass('button_disabled') : 1;
$('.listing_active').length == 0 ? $('.button_delete_selected').addClass('button_disabled') : 1;

});

$('.site_buttons div').hover(function() { $(this).toggleClass('site_button_hover'); });
$('.site_buttons div').click(function() {

Expand Down Expand Up @@ -118,6 +97,34 @@ var admin = {

},

handlers: function() {

// global listing handler, show _hover and display the hidden delete button
$('.listing tr').unbind('hover');
$('.listing tr').hover(function() {

if ($(this).children().is('TD')) {
$(this).addClass('listing_hover');
$(this).find('.delete_button').transition({opacity: 1}, 0);
}

}, function() {
$(this).removeClass('listing_hover');
$(this).find('.delete_button').transition({opacity: 0}, 0);
});

$('.delete_button').unbind('click');
$('.delete_button').click(function(e) {
e.stopPropagation();
$(this).closest('TR').toggleClass('listing_active');

$('.listing_active').length > 0 ? $('.button_delete_selected').removeClass('button_disabled') : 1;
$('.listing_active').length == 0 ? $('.button_delete_selected').addClass('button_disabled') : 1;

});

},

delete_selected: function() {

var datas = [];
Expand Down Expand Up @@ -213,7 +220,8 @@ var admin = {
center: function(e, params) {

var middle = ($(window).width() / 2) - (e.outerWidth() / 2);
var top = ($(window).scrollTop()*1);
//var top = ($(window).scrollTop()*1);
var top = 0;

if (params && params.top) {
$(e).css({top: (top +params.top*1) + 'px', left: middle + 'px'});
Expand Down Expand Up @@ -254,7 +262,7 @@ var listing = {
if ($(this).children().is('TD') && $(this).data('recipe') != undefined) {
$('.listing tr').removeClass('listing_selected');
$(this).addClass('listing_selected');
$(this).transition({scale: 1.2});
$(this).transition({scale: 1.2}, function() { $(this).transition({scale: 1.0}, 100); });
location.href = g.G_URL + '?recipe=' + $(this).data('recipe');
}
});
Expand All @@ -274,10 +282,26 @@ var listing = {

var details = {

init: function() {

$('#value').keyup(function(e) {

if (e.keyCode == 13) {
var val = $(this).val();
var cmd = $(this).data('cmd');
if (val && val != '' && cmd) {
eval(cmd);
}
}

});

},

add: function() {

var details = {
site: $('#site').val(),
name: $('#name').val(),
type: $('#type').val(),
value: $('#value').val()
};
Expand Down Expand Up @@ -310,7 +334,7 @@ var modify = {

modify.detailtype();

$('.detail_type').change(modify.detailtype);
$('.detail_name').change(modify.detailtype);

$('#ingredient, #instruction, #set').keyup(function(e) {

Expand All @@ -327,10 +351,10 @@ var modify = {
},

detailtype: function() {
var type = $('.detail_type').val().replace(/ /g, '_');
var type = $('.detail_name').val().replace(/ /g, '_');
$('.detail_value').hide();
$('.detail_value_' + g.site + '_' + type).fadeIn();
$('.detail_value').val();
$('.detail_value_' + type).fadeIn();
//$('.detail_value').val();
},

save: function() {
Expand Down Expand Up @@ -380,8 +404,9 @@ var modify = {
break;

case 'detail':
var valueid = ('.detail_value_' + g.site + '_' + $('#detail_type').val().replace(/ /g, '_'));
var data = { recipe_id: modify.recipe_id, type: $('#detail_type').val(), value: $(valueid).val() }
var typeid = ('.detail_type_' + $('#detail_name').val().replace(/ /g, '_'));
var valueid = ('.detail_value_' + $('#detail_name').val().replace(/ /g, '_'));
var data = { recipe_id: modify.recipe_id, name: $('#detail_name').val(), type: $(typeid).val(), value: $(valueid).val() }
var fields = ['#detail_value'];
break;

Expand Down Expand Up @@ -411,7 +436,14 @@ var modify = {
}

$('.' + type + '_listing').html(response.html);
$('.newrow').transition({backgroundColor: '#fff'}, '1000', 'in');
$('.newrow').transition({backgroundColor: '#fff'}, '1000', 'in', function() {

$('.newrow').attr('style', '');
$(document).find('.newrow').removeClass('newrow');

});

admin.handlers();
}

}, 'json');
Expand All @@ -426,14 +458,19 @@ var modify = {

if (set == '') {
admin.status('You must specify a set name', {type: 'error'});
return true;
}

admin.notify('Creating set..');
var data = {recipe_id: modify.recipe_id, set: set};

$.get('/ajx/set.php', { data: JSON.stringify(data) }, function(response) {

console.log(response);
admin.notify(false, {close: true});
admin.status('Set Created');
setTimeout(function() {
location.href = g.G_URL + '?recipe=' + modify.recipe_id;
}, 1000);

}, 'json');

Expand Down
4 changes: 2 additions & 2 deletions lib/detail.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class detail extends ktbl {

public function __construct($site,$type,$value) {
parent::__construct(array('site' => $site, 'type' => $type, 'value' => $value));
public function __construct($name,$type,$value) {
parent::__construct(array('name' => $name, 'type' => $type, 'value' => $value));
}

}
4 changes: 2 additions & 2 deletions lib/detail_recipe.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class detail_recipe extends ktbl {

public function __construct($recipe_id,$type,$value) {
parent::__construct(array('recipe_id' => $recipe_id, 'type' => $type, 'value' => $value));
public function __construct($recipe_id,$name,$value) {
parent::__construct(array('recipe_id' => $recipe_id, 'name' => $name, 'value' => $value));
}

}
Loading

0 comments on commit 7579724

Please sign in to comment.