Created
September 1, 2014 21:31
-
-
Save andrewhl/0791b353f9c77de5c8d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// food_items._ingredient_list partial | |
<h3>Ingredients</h3> | |
<table class="table table-striped"> | |
<tr> | |
<th>Name</th> | |
<th>Unit of Measure</th> | |
<th>Split Amount</th> | |
<th>Full Amount</th> | |
<th>Comments</th> | |
<th>Delete</th> | |
</tr> | |
@foreach($page->getFoodItemIngredients() as $ingredient) | |
<tr> | |
<td>{{ $ingredient['name'] }}</td> | |
<td>{{ $page->getUnitOfMeasureName($ingredient['pivot']['unit_of_measure_id']) }}</td> | |
<td>{{ $ingredient['pivot']['split_amount'] }}</td> | |
<td>{{ $ingredient['pivot']['full_amount'] }}</td> | |
<td>{{ $ingredient['pivot']['comments'] }}</td> | |
<td> | |
<!-- Button trigger modal --> | |
<button class="btn btn-danger btn-mini delete-food-item delete-button" data-toggle="modal" data-target="#modal-deleteConfirm-{{ $page->getFoodItem()->id }}"> | |
Delete | |
</button> | |
@include('food_items/_remove_ingredient_modal', ['route' => 'food_items.remove_ingredient', 'id' => $page->getFoodItem()->id, 'ingredient_id' => $ingredient['id'], 'modalClass' => 'delete-modal', 'title' => 'Remove ingredient', 'body' => 'Are you sure you want to remove this ingredient?', 'confirmText' => 'Confirm', 'dismissText' => 'Cancel']) | |
</td> | |
</tr> | |
@endforeach | |
</table> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// food_items edit page, includes _ingredient_list partial | |
@extends('layouts.master') | |
@section('content') | |
<div class="col-md-12"> | |
<h2>Edit Entree / Side - {{ $page->getFoodItem()->name }}</h2> | |
</div> | |
<!-- Nav tabs --> | |
<ul class="nav nav-tabs" role="tablist"> | |
<li class="active"><a href="#edit" role="tab" data-toggle="tab">Edit</a></li> | |
<li><a href="#add_ingredient" role="tab" data-toggle="tab">Add Ingredient</a></li> | |
</ul> | |
<!-- Tab panes --> | |
<div class="tab-content tab-content-boxed"> | |
<div class="tab-pane active clearfix" id="edit"> | |
<h3>Edit</h3> | |
@include('food_items._edit_food_item_form', ['page' => $page]) | |
</div> | |
<div class="tab-pane" id="add_ingredient"> | |
<h3>Add Ingredient</h3> | |
@include('food_items._add_ingredient_form', ['page' => $page]) | |
@include('food_items._ingredient_list', ['page' => $page]) | |
</div> | |
</div> | |
@stop | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
public function add_ingredient() | |
{ | |
if (Session::token() !== Input::get('_token')) | |
{ | |
return Response::json(array( | |
'msg' => 'Unauthorized attempt to create option' | |
)); | |
} | |
// Ommitting setting up $page object and processing Input | |
// return View::make('food_items._ingredient_list')->with('page', $page); | |
return View::make('food_items.edit')->nest('page', 'food_items._ingredient_list', $page); | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var IngredientModule = { | |
listen: function() { | |
var self = this; | |
$(document).on('ready', function() { | |
$('#add_ingredient_form').on('submit', function(e) { | |
e.preventDefault(); | |
var data = $(this).serialize(); | |
self.addIngredient(data); | |
}); | |
}); | |
}, | |
addIngredient: function (data) { | |
$.ajax({ | |
url: '/food_items/add_ingredient', | |
type: 'POST', | |
data: data | |
}).done(function (data) { | |
console.log(data); | |
}); | |
} | |
} | |
module.exports = IngredientModule; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment