Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to the example To-Do list app to use shared partial for the f…
…orm.
- Loading branch information
Showing
7 changed files
with
64 additions
and
60 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,4 @@ | ||
<div class="hero-unit"> | ||
<h2>Add a ToDo:</h2> | ||
<form action="/todos" method="POST"> | ||
<% if (params.error) { | ||
var title = 'title not long enough, must be 5 characters or more.' | ||
} else { | ||
var title = 'enter title' | ||
} | ||
%> | ||
<input type="text" class="span6" placeholder="<%= title %>" name="title"/> | ||
<input type="submit" class="btn btn-primary"> | ||
</form> | ||
<%= partial('_form', {params: params}); %> | ||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
<div class="hero-unit"> | ||
<h3>Params</h3> | ||
<ul> | ||
<% for (var p in params) { %> | ||
<li><%= p + ': ' + params[p]; %></li> | ||
<% } %> | ||
</ul> | ||
<h2>Update ToDo:</h2> | ||
<%= partial('_form', {params: params, todo: todo}); %> | ||
</div> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,8 @@ | ||
<div class="hero-unit"> | ||
<h3><%= todo.title; %></h3> | ||
<div class="pull-right"> | ||
<% if (todo.status == 'open') { %> | ||
<form id="finish-todo" class="hidden" action="/todos/<%= todo.id;%>"> | ||
<input type="hidden" name="status" value="done"/> | ||
<input type="hidden" name="id" value="<%= todo.id; %>"/> | ||
<input type="hidden" name="title" value="<%= todo.title; %>"> | ||
</form> | ||
<span><a href="#" class="btn btn-primary btn-large" id="finish-btn">Finish To Do</a></span> | ||
<script type="text/javascript"> | ||
var form = $('#finish-todo'); | ||
$('#finish-btn').click(function(e){ | ||
e.preventDefault(); | ||
$.ajax({ | ||
type: "PUT", | ||
url: form.attr('action'), | ||
data: form.serialize() | ||
}).done(function( msg ) { | ||
$(e.target).replaceWith('<p>This todo is finished!</p>'); | ||
}); | ||
}) | ||
</script> | ||
<% } else { %> | ||
<p>This to do is finished!</p> | ||
<h3>Params</h3> | ||
<ul> | ||
<% for (var p in params) { %> | ||
<li><%= p + ': ' + params[p]; %></li> | ||
<% } %> | ||
</div> | ||
</ul> | ||
</div> |
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
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