forked from geddy/geddy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lots of changes to the examples, these should work seamlessly in a tu…
…torial now
- Loading branch information
Techwraith
committed
Mar 13, 2012
1 parent
887ea26
commit f01c2d5
Showing
13 changed files
with
166 additions
and
103 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,31 +1,46 @@ | ||
<% | ||
var isUpdate = params.action == 'edit' | ||
, action = isUpdate ? '/todos/' + todo.id + '?_method=PUT': '/todos' | ||
, formTitle = isUpdate ? 'Update this To Do Item' : 'Create a new To Do Item' | ||
, action = isUpdate ? '/todos/' + todo.id + '?_method=PUT' : '/todos' | ||
, deleteAction = isUpdate ? '/todos/' + todo.id + '?_method=DELETE' : '' | ||
, btnText = isUpdate ? 'Update' : 'Add' | ||
, doneStatus = isUpdate ? 'checked' : '' | ||
, titleValue = isUpdate ? todo.title : '' | ||
, errors = params.errors; | ||
%> | ||
<form id="todo-form" action="<%= action %>" method="POST"> | ||
<% if (errors) { | ||
for (var p in errors) { %> | ||
<div><%= errors[p]; %></div> | ||
<% } | ||
} | ||
%> | ||
<div> | ||
<% if (isUpdate) { %> | ||
<%= todo.title %> | ||
<input type="hidden" class="span6" placeholder="<%= todo.title %>" name="title"/> | ||
<% } | ||
else {%> | ||
<input type="text" class="span6" placeholder="enter title" name="title"/> | ||
<% } %> | ||
</div> | ||
<div> | ||
<input type="checkbox" name="status" <%= doneStatus %> /> Done | ||
</div> | ||
<div> | ||
<input type="submit" class="btn btn-primary" value="<%= btnText %>"> | ||
</div> | ||
<form id="todo-form" class="form-horizontal" action="<%= action %>" method="POST"> | ||
<fieldset> | ||
<legend><%= formTitle %></legend> | ||
<div class="control-group"> | ||
<label for="title" class="control-label">Title</label> | ||
<div class="controls"> | ||
<input type="text" class="span6" placeholder="enter title" name="title" value='<%= titleValue %>'/> | ||
<% if (errors) { %> | ||
<p> | ||
<% for (var p in errors) { %> | ||
<div><%= errors[p]; %></div> | ||
<% } %> | ||
</p> | ||
<% } %> | ||
</div> | ||
</div> | ||
<% if (isUpdate) { %> | ||
<div class="control-group"> | ||
<label for="status">Status</label> | ||
<div class="controls"> | ||
<select name="status"> | ||
<option>open</option> | ||
<option>done</option> | ||
</select> | ||
</div> | ||
</div> | ||
<% } %> | ||
<div class="form-actions"> | ||
<input type="submit" class="btn btn-primary" value="<%= btnText %>"/> | ||
<% if (isUpdate) { %> | ||
<button type="submit" formaction="<%= deleteAction %>" formmethod="POST" class="btn btn-danger">Remove</button> | ||
<% } %> | ||
</div> | ||
</fieldset> | ||
</form> | ||
|
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,4 +1,3 @@ | ||
<div class="hero-unit"> | ||
<h2>Add a ToDo:</h2> | ||
<%= 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,4 +1,3 @@ | ||
<div class="hero-unit"> | ||
<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
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
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,3 @@ | ||
<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,3 @@ | ||
<div class="hero-unit"> | ||
<h3>Params</h3> | ||
<ul> | ||
<% for (var p in params) { %> | ||
<li><%= p + ': ' + params[p]; %></li> | ||
<% } %> | ||
</ul> | ||
<%= 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> |
Oops, something went wrong.