mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-21 04:48:06 -05:00
moving edit UI out into a template.
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user