From 33d6d68d5543a811301b2c5be95ebc7fd8d412a6 Mon Sep 17 00:00:00 2001 From: abhinav Date: Wed, 21 Aug 2013 19:32:54 +0530 Subject: [PATCH] the editing property is removed from the todo object and moved into the root. Also - rolled back the silliness in the last edit. --- .../durandal/js/viewmodels/list.js | 20 +++++++++++-------- .../durandal/js/views/list.html | 4 ++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/labs/dependency-examples/durandal/js/viewmodels/list.js b/labs/dependency-examples/durandal/js/viewmodels/list.js index 10b0f6e084..9a6bfd8bf0 100644 --- a/labs/dependency-examples/durandal/js/viewmodels/list.js +++ b/labs/dependency-examples/durandal/js/viewmodels/list.js @@ -5,23 +5,21 @@ define([ ], function (app, shell) { 'use strict'; + // represent a single todo item - var Todo = function (title, completed) { this.title = ko.observable(title); this.completed = ko.observable(completed); - this.editTitle = ko.observable(title) //we use this as a shadow for the title so that if the user exits without saving, it is not persisted. - this.editing = ko.observable(false); }; var ViewModel = function () { var self = this; self.activate = function () { - //initialize the show mode + //initialize the show mode var filter = shell.filter; - if ( filter === undefined){ + if (filter === undefined) { filter = 'all'; } @@ -70,6 +68,8 @@ define([ } }); + self.itemBeingEdited = ko.observable(undefined); + // remove a single todo self.remove = function (todo) { self.todos.remove(todo); @@ -82,17 +82,21 @@ define([ }); }; + self.isThisItemBeingEdited = function (todo) { + return (todo === self.itemBeingEdited()); + }; + // edit an item self.editItem = function (item) { - item.editing(true); + self.itemBeingEdited(item); }; // stop editing an item. Remove the item, if it is now empty self.stopEditing = function (item) { - item.editing(false); + self.itemBeingEdited(undefined); //trim and save back - var trimmed = item.editTitle().trim(); + var trimmed = item.title().trim(); item.title(trimmed); if (!trimmed) { diff --git a/labs/dependency-examples/durandal/js/views/list.html b/labs/dependency-examples/durandal/js/views/list.html index 84c4d6c937..3fcc688772 100644 --- a/labs/dependency-examples/durandal/js/views/list.html +++ b/labs/dependency-examples/durandal/js/views/list.html @@ -4,13 +4,13 @@