Commit 77201888 authored by Dave Methvin's avatar Dave Methvin Committed by Sam Saccone

typescript-angular: Add ability to abandon edits with Esc key

Ref #789

This roughly follows the pattern in examples/angularjs which already had the
ability to use Esc.
parent 7d6eb896
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
<button class="destroy" ng-click="vm.removeTodo(todo)"></button> <button class="destroy" ng-click="vm.removeTodo(todo)"></button>
</div> </div>
<form ng-submit="vm.doneEditing(todo)"> <form ng-submit="vm.doneEditing(todo)">
<input class="edit" ng-model="todo.title" todo-blur="vm.doneEditing(todo)" todo-focus="todo == editedTodo"> <input class="edit" ng-model="todo.title" todo-blur="vm.doneEditing(todo)" todo-focus="todo == editedTodo" todo-escape="vm.revertEdits(todo)">
</form> </form>
</li> </li>
</ul> </ul>
......
...@@ -53,6 +53,28 @@ var todos; ...@@ -53,6 +53,28 @@ var todos;
})(todos || (todos = {})); })(todos || (todos = {}));
/// <reference path='../_all.ts' /> /// <reference path='../_all.ts' />
var todos; var todos;
(function (todos) {
'use strict';
var ESCAPE_KEY = 27;
/**
* Directive that cancels editing a todo if the user presses the Esc key.
*/
function todoEscape() {
return {
link: function ($scope, element, attributes) {
element.bind('keydown', function (event) {
if (event.keyCode === ESCAPE_KEY) {
$scope.$apply(attributes.todoEscape);
}
});
$scope.$on('$destroy', function () { element.unbind('keydown'); });
}
};
}
todos.todoEscape = todoEscape;
})(todos || (todos = {}));
/// <reference path='../_all.ts' />
var todos;
(function (todos_1) { (function (todos_1) {
'use strict'; 'use strict';
/** /**
...@@ -125,9 +147,21 @@ var todos; ...@@ -125,9 +147,21 @@ var todos;
}; };
TodoCtrl.prototype.editTodo = function (todoItem) { TodoCtrl.prototype.editTodo = function (todoItem) {
this.$scope.editedTodo = todoItem; this.$scope.editedTodo = todoItem;
// Clone the original todo in case editing is cancelled.
this.$scope.originalTodo = angular.extend({}, todoItem);
};
TodoCtrl.prototype.revertEdits = function (todoItem) {
this.todos[this.todos.indexOf(todoItem)] = this.$scope.originalTodo;
this.$scope.reverted = true;
}; };
TodoCtrl.prototype.doneEditing = function (todoItem) { TodoCtrl.prototype.doneEditing = function (todoItem) {
this.$scope.editedTodo = null; this.$scope.editedTodo = null;
this.$scope.originalTodo = null;
if (this.$scope.reverted) {
// Todo edits were reverted, don't save.
this.$scope.reverted = null;
return;
}
todoItem.title = todoItem.title.trim(); todoItem.title = todoItem.title.trim();
if (!todoItem.title) { if (!todoItem.title) {
this.removeTodo(todoItem); this.removeTodo(todoItem);
...@@ -169,6 +203,7 @@ var todos; ...@@ -169,6 +203,7 @@ var todos;
.controller('todoCtrl', todos.TodoCtrl) .controller('todoCtrl', todos.TodoCtrl)
.directive('todoBlur', todos.todoBlur) .directive('todoBlur', todos.todoBlur)
.directive('todoFocus', todos.todoFocus) .directive('todoFocus', todos.todoFocus)
.directive('todoEscape', todos.todoEscape)
.service('todoStorage', todos.TodoStorage); .service('todoStorage', todos.TodoStorage);
})(todos || (todos = {})); })(todos || (todos = {}));
/// <reference path='libs/jquery/jquery.d.ts' /> /// <reference path='libs/jquery/jquery.d.ts' />
...@@ -178,6 +213,7 @@ var todos; ...@@ -178,6 +213,7 @@ var todos;
/// <reference path='interfaces/ITodoStorage.ts' /> /// <reference path='interfaces/ITodoStorage.ts' />
/// <reference path='directives/TodoFocus.ts' /> /// <reference path='directives/TodoFocus.ts' />
/// <reference path='directives/TodoBlur.ts' /> /// <reference path='directives/TodoBlur.ts' />
/// <reference path='directives/TodoEscape.ts' />
/// <reference path='services/TodoStorage.ts' /> /// <reference path='services/TodoStorage.ts' />
/// <reference path='controllers/TodoCtrl.ts' /> /// <reference path='controllers/TodoCtrl.ts' />
/// <reference path='Application.ts' /> /// <reference path='Application.ts' />
......
{"version":3,"file":"Application.js","sourceRoot":"","sources":["models/TodoItem.ts","interfaces/ITodoScope.ts","interfaces/ITodoStorage.ts","directives/TodoFocus.ts","directives/TodoBlur.ts","services/TodoStorage.ts","controllers/TodoCtrl.ts","Application.ts","_all.ts"],"names":["todos","todos.TodoItem","todos.TodoItem.constructor","todos.todoFocus","todos.todoBlur","todos.TodoStorage","todos.TodoStorage.constructor","todos.TodoStorage.get","todos.TodoStorage.put","todos.TodoCtrl","todos.TodoCtrl.constructor","todos.TodoCtrl.onPath","todos.TodoCtrl.onTodos","todos.TodoCtrl.addTodo","todos.TodoCtrl.editTodo","todos.TodoCtrl.doneEditing","todos.TodoCtrl.removeTodo","todos.TodoCtrl.clearDoneTodos","todos.TodoCtrl.markAll"],"mappings":"AAAA,mCAAmC;AAEnC,IAAO,KAAK,CASX;AATD,WAAO,KAAK,EAAC,CAAC;IACVA,YAAYA,CAACA;IAEbA;QACIC,kBACWA,KAAaA,EACbA,SAAkBA;YADlBC,UAAKA,GAALA,KAAKA,CAAQA;YACbA,cAASA,GAATA,SAASA,CAASA;QACrBA,CAACA;QACbD,eAACA;IAADA,CAACA,AALDD,IAKCA;IALYA,cAAQA,WAKpBA,CAAAA;AACLA,CAACA,EATM,KAAK,KAAL,KAAK,QASX;ACXD,mCAAmC;ACAnC,mCAAmC;ACAnC,mCAAmC;AAEnC,IAAO,KAAK,CAoBX;AApBD,WAAO,KAAK,EAAC,CAAC;IACbA,YAAYA,CAACA;IAKbA,AAHAA;;OAEGA;uBACuBA,QAA4BA;QACrDG,MAAMA,CAACA;YACNA,IAAIA,EAAEA,UAACA,MAAiBA,EAAEA,OAAeA,EAAEA,UAAeA;gBACzDA,MAAMA,CAACA,MAAMA,CAACA,UAAUA,CAACA,SAASA,EAAEA,UAAAA,MAAMA;oBACzCA,EAAEA,CAACA,CAACA,MAAMA,CAACA,CAACA,CAACA;wBACZA,QAAQA,CAACA,cAAMA,OAAAA,OAAOA,CAACA,CAACA,CAACA,CAACA,KAAKA,EAAEA,EAAlBA,CAAkBA,EAAEA,CAACA,EAAEA,KAAKA,CAACA,CAACA;oBAC9CA,CAACA;gBACFA,CAACA,CAACA,CAACA;YACJA,CAACA;SACDA,CAACA;IACHA,CAACA;IAVeH,eAASA,YAUxBA,CAAAA;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AAAA;AAEFA,CAACA,EAjGM,KAAK,KAAL,KAAK,QAiGX;ACnGD,gCAAgC;AAOhC,AALA;;;;GAIG;AACH,IAAO,KAAK,CAQX;AARD,WAAO,KAAK,EAAC,CAAC;IACVA,YAAYA,CAACA;IAEbA,IAAIA,OAAOA,GAAGA,OAAOA,CAACA,MAAMA,CAACA,SAASA,EAAEA,EAAEA,CAACA;SAClCA,UAAUA,CAACA,UAAUA,EAAEA,cAAQA,CAACA;SAChCA,SAASA,CAACA,UAAUA,EAAEA,cAAQA,CAACA;SAC/BA,SAASA,CAACA,WAAWA,EAAEA,eAASA,CAACA;SACjCA,OAAOA,CAACA,aAAaA,EAAEA,iBAAWA,CAACA,CAACA;AACjDA,CAACA,EARM,KAAK,KAAL,KAAK,QAQX;ACfD,gDAAgD;AAChD,kDAAkD;AAClD,2CAA2C;AAC3C,iDAAiD;AACjD,mDAAmD;AACnD,gDAAgD;AAChD,+CAA+C;AAC/C,gDAAgD;AAChD,gDAAgD;AAChD,uCAAuC"} {"version":3,"file":"Application.js","sourceRoot":"","sources":["models/TodoItem.ts","interfaces/ITodoScope.ts","interfaces/ITodoStorage.ts","directives/TodoFocus.ts","directives/TodoBlur.ts","directives/TodoEscape.ts","services/TodoStorage.ts","controllers/TodoCtrl.ts","Application.ts","_all.ts"],"names":["todos","todos.TodoItem","todos.TodoItem.constructor","todos.todoFocus","todos.todoBlur","todos.todoEscape","todos.TodoStorage","todos.TodoStorage.constructor","todos.TodoStorage.get","todos.TodoStorage.put","todos.TodoCtrl","todos.TodoCtrl.constructor","todos.TodoCtrl.onPath","todos.TodoCtrl.onTodos","todos.TodoCtrl.addTodo","todos.TodoCtrl.editTodo","todos.TodoCtrl.revertEdits","todos.TodoCtrl.doneEditing","todos.TodoCtrl.removeTodo","todos.TodoCtrl.clearDoneTodos","todos.TodoCtrl.markAll"],"mappings":"AAAA,mCAAmC;AAEnC,IAAO,KAAK,CASX;AATD,WAAO,KAAK,EAAC,CAAC;IACVA,YAAYA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cAAQA,CAACA;SAChCA,SAASA,CAACA,UAAUA,EAAEA,cAAQA,CAACA;SAC/BA,SAASA,CAACA,WAAWA,EAAEA,eAASA,CAACA;SACjCA,SAASA,CAACA,YAAYA,EAAEA,gBAAUA,CAACA;SACnCA,OAAOA,CAACA,aAAaA,EAAEA,iBAAWA,CAACA,CAACA;AACjDA,CAACA,EATM,KAAK,KAAL,KAAK,QASX;AChBD,gDAAgD;AAChD,kDAAkD;AAClD,2CAA2C;AAC3C,iDAAiD;AACjD,mDAAmD;AACnD,gDAAgD;AAChD,+CAA+C;AAC/C,iDAAiD;AACjD,gDAAgD;AAChD,gDAAgD;AAChD,uCAAuC"}
\ No newline at end of file \ No newline at end of file
...@@ -12,5 +12,6 @@ module todos { ...@@ -12,5 +12,6 @@ module todos {
.controller('todoCtrl', TodoCtrl) .controller('todoCtrl', TodoCtrl)
.directive('todoBlur', todoBlur) .directive('todoBlur', todoBlur)
.directive('todoFocus', todoFocus) .directive('todoFocus', todoFocus)
.directive('todoEscape', todoEscape)
.service('todoStorage', TodoStorage); .service('todoStorage', TodoStorage);
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
/// <reference path='interfaces/ITodoStorage.ts' /> /// <reference path='interfaces/ITodoStorage.ts' />
/// <reference path='directives/TodoFocus.ts' /> /// <reference path='directives/TodoFocus.ts' />
/// <reference path='directives/TodoBlur.ts' /> /// <reference path='directives/TodoBlur.ts' />
/// <reference path='directives/TodoEscape.ts' />
/// <reference path='services/TodoStorage.ts' /> /// <reference path='services/TodoStorage.ts' />
/// <reference path='controllers/TodoCtrl.ts' /> /// <reference path='controllers/TodoCtrl.ts' />
/// <reference path='Application.ts' /> /// <reference path='Application.ts' />
...@@ -74,10 +74,24 @@ module todos { ...@@ -74,10 +74,24 @@ module todos {
editTodo(todoItem: TodoItem) { editTodo(todoItem: TodoItem) {
this.$scope.editedTodo = todoItem; this.$scope.editedTodo = todoItem;
// Clone the original todo in case editing is cancelled.
this.$scope.originalTodo = angular.extend({}, todoItem);
}
revertEdits(todoItem: TodoItem) {
this.todos[this.todos.indexOf(todoItem)] = this.$scope.originalTodo;
this.$scope.reverted = true;
} }
doneEditing(todoItem: TodoItem) { doneEditing(todoItem: TodoItem) {
this.$scope.editedTodo = null; this.$scope.editedTodo = null;
this.$scope.originalTodo = null;
if (this.$scope.reverted) {
// Todo edits were reverted, don't save.
this.$scope.reverted = null;
return;
}
todoItem.title = todoItem.title.trim(); todoItem.title = todoItem.title.trim();
if (!todoItem.title) { if (!todoItem.title) {
this.removeTodo(todoItem); this.removeTodo(todoItem);
......
/// <reference path='../_all.ts' />
module todos {
'use strict';
const ESCAPE_KEY = 27;
/**
* Directive that cancels editing a todo if the user presses the Esc key.
*/
export function todoEscape(): ng.IDirective {
return {
link: ($scope: ng.IScope, element: JQuery, attributes: any) => {
element.bind('keydown', (event) => {
if (event.keyCode === ESCAPE_KEY) {
$scope.$apply(attributes.todoEscape);
}
});
$scope.$on('$destroy', () => { element.unbind('keydown'); });
}
};
}
}
...@@ -5,9 +5,11 @@ module todos { ...@@ -5,9 +5,11 @@ module todos {
todos: TodoItem[]; todos: TodoItem[];
newTodo: string; newTodo: string;
editedTodo: TodoItem; editedTodo: TodoItem;
originalTodo: TodoItem;
remainingCount: number; remainingCount: number;
doneCount: number; doneCount: number;
allChecked: boolean; allChecked: boolean;
reverted: boolean;
statusFilter: { completed: boolean; }; statusFilter: { completed: boolean; };
location: ng.ILocationService; location: ng.ILocationService;
vm: TodoCtrl; vm: TodoCtrl;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment