moving edit UI out into a template.

This commit is contained in:
Jeremy Ashkenas
2010-10-19 17:20:40 -04:00
parent 8282270d56
commit 6ea50e6a1e
2 changed files with 9 additions and 15 deletions

View File

@@ -18,6 +18,11 @@
<span class="todo-content"><%= model.get('content') %></span>
</script>
<script id="edit-template" type="x-ejs">
<input type="text" value="<%= model.get('content') %>" />
<input type="submit" class="update" value="Update" />
</script>
<script src="todos.js"></script>
</head>
<body>

View File

@@ -23,7 +23,8 @@
className: "todo",
template: _.template($('#todo-template').html()),
displayTemplate: _.template($('#todo-template').html()),
editTemplate: _.template($('#edit-template').html()),
events: {
"dblclick span": "edit",
@@ -40,7 +41,7 @@
// Render (or empty and re-render) this view. If this task is complete,
// make the text have strike through.
render: function () {
$(this.el).html(this.template({model: this.model}));
$(this.el).html(this.displayTemplate({model: this.model}));
this.setComplete();
return this;
},
@@ -53,19 +54,7 @@
// to edit this task's content and a submit button to click to save the
// updates.
edit: function () {
var input = this.$(this.make("input", {
type: "text",
value: this.$(this.el).text()
}));
var submit = this.$(this.make("input", {
type: "submit",
className: "update",
value: "Update"
}));
this.$(this.el)
.empty()
.append(input)
.append(submit);
$(this.el).html(this.editTemplate({model : this.model}));
},
// Switch back to display mode after being in edit mode. Save the new