@@ -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' ) ;
0 commit comments