diff --git a/src/Controller/RecipesController.php b/src/Controller/RecipesController.php index 9e3017f..2714743 100644 --- a/src/Controller/RecipesController.php +++ b/src/Controller/RecipesController.php @@ -86,7 +86,8 @@ public function view($id = null, $servings=null) ], 'Units' => [ 'fields' => ['name', 'abbreviation'] - ] + ], + 'sort' => ['IngredientMappings.sort_order' => 'ASC'] ], 'RelatedRecipes' => [ 'Recipes' => [ @@ -94,10 +95,11 @@ public function view($id = null, $servings=null) 'IngredientMappings' => [ 'Ingredients' => [ 'fields' => ['name'] - ], - 'Units' => [ - 'fields' => ['name', 'abbreviation'] - ] + ], + 'Units' => [ + 'fields' => ['name', 'abbreviation'] + ], + 'sort' => ['IngredientMappings.sort_order' => 'ASC'] ] ] ], @@ -143,7 +145,8 @@ public function edit($id = null) ], 'Units' => [ 'fields' => ['name', 'abbreviation'] - ] + ], + 'sort' => ['IngredientMappings.sort_order' => 'ASC'] ], 'RelatedRecipes' => [ 'Recipes' => [ @@ -154,7 +157,8 @@ public function edit($id = null) ], 'Units' => [ 'fields' => ['name', 'abbreviation'] - ] + ], + 'sort' => ['IngredientMappings.sort_order' => 'ASC'] ] ] ], @@ -170,21 +174,18 @@ public function edit($id = null) $recipe->user_id = $this->Auth->user('id'); if ($this->Recipes->save($recipe)) { $this->Flash->success(__('The recipe has been saved.')); - return $this->redirect(['action' => 'index']); + } else { + $this->Flash->error(__('The recipe could not be saved. Please, try again.')); } - /* - NOTE: Helpful debug info - - $x = $recipe->getErrors(); + //NOTE: Helpful debug info + /*$x = $recipe->getErrors(); if ($x) { debug($recipe); debug($x); return false; - } - */ - $this->Flash->error(__('The recipe could not be saved. Please, try again.')); + }*/ } $ethnicities = $this->Recipes->Ethnicities->find('list', ['limit' => 200, 'order' => ['Ethnicities.name']]); $baseTypes = $this->Recipes->BaseTypes->find('list', ['limit' => 200, 'order' => ['BaseTypes.name']]); @@ -211,6 +212,15 @@ public function delete($id = null) return $this->redirect(['action' => 'index']); } + public function removeIngredientMapping($recipeId, $mappingId) { + $entity = $this->Recipes->IngredientMappings->get($mappingId); + if ($this->Recipes->IngredientMappings->delete($entity)) { + $this->Flash->success(__('The ingredient has been removed.')); + } else { + $this->Flash->error(__('The ingredient could not be removed. Please, try again.')); + } + } + public function findByBase($baseId) { $this->filterConditions['Recipes.base_type_id'] = $baseId; diff --git a/src/Model/Table/AttachmentsTable.php b/src/Model/Table/AttachmentsTable.php index 2c64626..675ee16 100644 --- a/src/Model/Table/AttachmentsTable.php +++ b/src/Model/Table/AttachmentsTable.php @@ -72,8 +72,8 @@ public function validationDefault(Validator $validator) ->notEmptyString('name'); $validator - ->scalar('attachment') - ->maxLength('attachment', 255) + //->scalar('attachment') + //->maxLength('attachment', 255) ->requirePresence('attachment', 'create') ->notEmptyString('attachment'); diff --git a/src/Template/Recipes/edit.ctp b/src/Template/Recipes/edit.ctp index da4acef..1be98f5 100644 --- a/src/Template/Recipes/edit.ctp +++ b/src/Template/Recipes/edit.ctp @@ -167,8 +167,6 @@ $recipeId = isset($recipe->id) ? $recipe->id : ""; return; // Not good if we get here } - console.log("Regex:" + regMatch); - // Don't delete the last table row if (thisRow.is(":last-child")) { return; @@ -406,21 +404,22 @@ $recipeId = isset($recipe->id) ? $recipe->id : ""; echo $this->Form->control('preparation_time_id', array('empty'=>true)); echo $this->Form->control('difficulty_id', array('empty'=>true)); echo $this->Form->control('serving_size'); - $imageCount = (isset($recipe) && isset($recipe->image))? count($recipe->image) : 0; - + $imageCount = (isset($recipe) && isset($recipe->attachments))? count($recipe->attachments) : 0; + $newImageIndex = $imageCount-1; + echo "