Skip to content

Commit 53b2b01

Browse files
author
root
committed
Fixes #41
1 parent 2df7489 commit 53b2b01

File tree

7 files changed

+81
-43
lines changed

7 files changed

+81
-43
lines changed

appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>Cookbook</name>
66
<summary>An integrated cookbook using schema.org JSON files as recipes</summary>
77
<description><![CDATA[A library for all your recipes. It uses JSON files following the schema.org recipe format. To add a recipe to the collection, you can paste in the URL of the recipe, and the provided web page will be parsed and downloaded to whichever folder you specify in the app settings.]]></description>
8-
<version>0.2.0</version>
8+
<version>0.3.0</version>
99
<licence>agpl</licence>
1010
<author mail="[email protected]" >Jeppe Zapp</author>
1111
<namespace>Cookbook</namespace>

css/style.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@
8686
margin-bottom: 1rem;
8787
line-height: 1.5;
8888
}
89+
#app-content-wrapper header .recipe-toolbar {
90+
display: flex;
91+
justify-content: flex-end;
92+
}
93+
94+
#app-content-wrapper header .recipe-toolbar .button {
95+
width: 40px;
96+
height: 40px;
97+
line-height: 40px;
98+
text-align: center;
99+
}
100+
89101
#app-content-wrapper header figure {
90102
position: relative;
91103
overflow: hidden;

js/script.js

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ var Content = function (cookbook) {
131131

132132
if(!recipeId && !isEditor) {
133133
$('#app-content-wrapper').html(t(appName, 'Please pick a recipe'));
134+
134135
} else {
135136
$.ajax({
136137
url: cookbook._baseUrl + '/' + (isEditor ? 'edit' : 'recipe') + (isEditor && !recipeId ? '?new' : '?id=' + recipeId),
@@ -147,16 +148,50 @@ var Content = function (cookbook) {
147148

148149
$('#app-content-wrapper form').off('submit');
149150
$('#app-content-wrapper form').submit(self.onUpdateRecipe);
151+
152+
$('#app-content-wrapper .icon-delete').click(self.onDeleteRecipe);
150153

151154
self.updateListItems();
155+
156+
nav.highlightActive();
152157
})
153158
.fail(function (e) {
154159
alert(t(appName, 'Could not load recipe'));
155160

161+
nav.highlightActive();
162+
156163
if(e && e instanceof Error) { throw e; }
157164
});
158165
}
159166
};
167+
168+
/**
169+
* Event: Delete recipe
170+
*/
171+
self.onDeleteRecipe = function(e) {
172+
if(!confirm(t(appName, 'Are you sure you want to delete this recipe?'))) { return; }
173+
174+
var id = e.currentTarget.dataset.id;
175+
176+
$.ajax({
177+
url: cookbook._baseUrl + '/delete?id=' + id,
178+
method: 'DELETE',
179+
})
180+
.done(function(html) {
181+
if(cookbook.getActiveId() == id) {
182+
location.hash = '';
183+
}
184+
185+
self.render();
186+
nav.render();
187+
})
188+
.fail(function(e) {
189+
alert(t(appName, 'Failed to delete recipe'));
190+
191+
if(e && e instanceof Error) { throw e; }
192+
});
193+
};
194+
160195

161196
/**
162197
* Updates all lists items with click events
@@ -305,37 +340,15 @@ var Nav = function (cookbook) {
305340
};
306341

307342
/**
308-
* Event: Edit recipe
309-
*/
310-
self.onEditRecipe = function(e) {
311-
location.hash = e.currentTarget.dataset.id + '|edit';
312-
};
313-
314-
/**
315-
* Event: Delete recipe
343+
* Event: Clear recipe search
316344
*/
317-
self.onDeleteRecipe = function(e) {
318-
if(!confirm(t(appName, 'Are you sure you want to delete this recipe?'))) { return; }
319-
320-
var id = e.currentTarget.dataset.id;
345+
self.onClearRecipeSearch = function(e) {
346+
e.preventDefault();
321347

322-
$.ajax({
323-
url: cookbook._baseUrl + '/delete?id=' + id,
324-
method: 'DELETE',
325-
})
326-
.done(function(html) {
327-
if(cookbook.getActiveId() == id) {
328-
location.hash = '';
329-
}
330-
331-
self.render();
332-
})
333-
.fail(function(e) {
334-
alert(t(appName, 'Failed to delete recipe'));
348+
$('#find-recipes input').val('');
335349

336-
if(e && e instanceof Error) { throw e; }
337-
});
338-
};
350+
self.onFindRecipes(e);
351+
}
339352

340353
/**
341354
* Get the current input keywords
@@ -346,6 +359,15 @@ var Nav = function (cookbook) {
346359
return $('#find-recipes input').val();
347360
}
348361

362+
/**
363+
* Highlight the active item
364+
*/
365+
self.highlightActive = function() {
366+
$('#app-navigation #recipes a').each(function() {
367+
$(this).toggleClass('active', $(this).attr('href') === '#' + cookbook.getActiveId());
368+
});
369+
}
370+
349371
/**
350372
* Render the view
351373
*/
@@ -356,10 +378,8 @@ var Nav = function (cookbook) {
356378
})
357379
.done(function(html) {
358380
$('#app-navigation #recipes').html(html);
359-
360-
$('#app-navigation #recipes .button-edit button').click(self.onEditRecipe);
361-
362-
$('#app-navigation #recipes .button-delete button').click(self.onDeleteRecipe);
381+
382+
self.highlightActive();
363383
})
364384
.fail(function(e) {
365385
alert(t(appName, 'Failed to fetch recipes'));
@@ -382,6 +402,10 @@ var Nav = function (cookbook) {
382402
// Find recipes
383403
$('#find-recipes').off('submit');
384404
$('#find-recipes').submit(self.onFindRecipes);
405+
406+
// Clear recipe search
407+
$('#clear-recipe-search').off('click');
408+
$('#clear-recipe-search').click(self.onClearRecipeSearch);
385409

386410
// Reindex recipes
387411
$('#reindex-recipes').off('click');

templates/content/edit.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
<header>
2+
<div class="recipe-toolbar">
3+
<a href="#<?php echo $_['id']; ?>" class="svg action icon-close"></a>
4+
</div>
5+
</header>
6+
17
<form action="/index.php/apps/cookbook/update" method="POST">
28
<fieldset>
39
<label><?php /* TRANSLATORS The name of the recipe */echo p($l->t('Name')); ?></label>

templates/content/recipe.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
<img src="<?php echo $_['imageURL']; ?>">
55
</figure>
66
<?php } ?>
7+
8+
<div class="recipe-toolbar">
9+
<a href="#<?php echo $_['id']; ?>|edit" class="button svg action icon-rename" title="<?php p($l->t('Edit recipe')); ?>"></a>
10+
<button class="button svg action icon-delete" data-id="<?php echo $_['id']; ?>" title="<?php p($l->t('Delete recipe')); ?>"></button>
11+
</div>
712

813
<h2><?php echo $_['name']; ?></h2>
914

templates/navigation/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<option value="<?php echo $keyword['name']; ?>">
1818
<?php } ?>
1919
</datalist>
20+
<button id="clear-recipe-search" class="icon-close"></button>
2021
<button class="icon-category-search" type="submit"></button>
2122
</form>
2223

templates/navigation/recipes.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,5 @@
44
<img src="<?php echo $recipe['imageURL']; ?>">
55
<?php echo $recipe['name']; ?>
66
</a>
7-
<div class="app-navigation-entry-utils">
8-
<ul>
9-
<li class="app-navigation-entry-utils-menu-button button-edit">
10-
<button class="svg action icon-rename" data-id="<?php echo $recipe['recipe_id']; ?>" title="<?php p($l->t('Edit recipe')); ?>"></button>
11-
</li>
12-
<li class="app-navigation-entry-utils-menu-button button-delete">
13-
<button class="svg action icon-delete" data-id="<?php echo $recipe['recipe_id']; ?>" title="<?php p($l->t('Delete recipe')); ?>"></button>
14-
</li>
15-
</ul>
16-
</div>
177
</li>
188
<?php } ?>

0 commit comments

Comments
 (0)