Skip to content

Commit

Permalink
Merge pull request #862 from EmilJunker/improve-editor-back-handling
Browse files Browse the repository at this point in the history
Improve editor hardware back button confirm handling
  • Loading branch information
davidhealey authored Sep 22, 2024
2 parents 409081b + 6f83ae1 commit 153686e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions www/activities/foods-meals-recipes/js/food-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ app.FoodEditor = {

item: undefined,
item_image_url: undefined,
addingNewItem: undefined,
index: undefined,
scan: false,
origin: undefined,
Expand All @@ -32,18 +33,21 @@ app.FoodEditor = {

app.FoodEditor.item = undefined;
app.FoodEditor.item_image_url = undefined;
app.FoodEditor.addingNewItem = true;
app.FoodEditor.scan = false;
app.FoodEditor.images = [];

if (context) {

app.FoodEditor.addingNewItem = (context.item == undefined || context.item.id == undefined);

if (context.item !== undefined)
app.FoodEditor.item = context.item;

if (context.index !== undefined)
app.FoodEditor.index = context.index;

if (context.item == undefined || (context.item != undefined && context.item.id == undefined))
if (app.FoodEditor.addingNewItem)
app.FoodEditor.linked = false; //Unlinked by default for adding new items
else
app.FoodEditor.linked = true;
Expand Down Expand Up @@ -273,7 +277,7 @@ app.FoodEditor = {
},

setupHardwareBackButtonExitHandling: function() {
if (app.FoodEditor.origin == "foodlist")
if (app.FoodEditor.addingNewItem)
app.FoodEditor.el.page.setAttribute("confirm-backbutton", "");
else
app.FoodEditor.el.page.removeAttribute("confirm-backbutton");
Expand Down
4 changes: 3 additions & 1 deletion www/activities/meals/js/meal-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

app.MealEditor = {

addingNewMeal: undefined,
editingEnabled: undefined,
meal_image_url: undefined,
meal: {},
Expand Down Expand Up @@ -146,7 +147,7 @@ app.MealEditor = {
},

setupHardwareBackButtonExitHandling: function() {
if (app.MealEditor.editingEnabled)
if (app.MealEditor.addingNewMeal)
app.MealEditor.el.page.setAttribute("confirm-backbutton", "");
else
app.MealEditor.el.page.removeAttribute("confirm-backbutton");
Expand Down Expand Up @@ -338,6 +339,7 @@ document.addEventListener("page:init", function(event) {
let context = app.data.context;
app.data.context = undefined;

app.MealEditor.addingNewMeal = (context == undefined || context.meal == undefined);
app.MealEditor.editingEnabled = (app.FoodsMealsRecipes.editItems == "enabled");

// Clear old meal
Expand Down
4 changes: 3 additions & 1 deletion www/activities/recipes/js/recipe-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

app.RecipeEditor = {

addingNewRecipe: undefined,
editingEnabled: undefined,
recipe_image_url: undefined,
recipe: {},
Expand Down Expand Up @@ -146,7 +147,7 @@ app.RecipeEditor = {
},

setupHardwareBackButtonExitHandling: function() {
if (app.RecipeEditor.editingEnabled)
if (app.RecipeEditor.addingNewRecipe)
app.RecipeEditor.el.page.setAttribute("confirm-backbutton", "");
else
app.RecipeEditor.el.page.removeAttribute("confirm-backbutton");
Expand Down Expand Up @@ -345,6 +346,7 @@ document.addEventListener("page:init", function(event) {
let context = app.data.context;
app.data.context = undefined;

app.RecipeEditor.addingNewRecipe = (context == undefined || context.recipe == undefined);
app.RecipeEditor.editingEnabled = (app.FoodsMealsRecipes.editItems == "enabled");

// Clear old recipe
Expand Down

0 comments on commit 153686e

Please # to comment.