Commit 949463d8 authored by Pavel Savara's avatar Pavel Savara

added js as requested, fixed bugs

parent 815aa07e
*.suo
*.user
*.js
*.map
/bin
/obj
\ No newline at end of file
......@@ -63,7 +63,7 @@
</p>
</footer>
<script src="../../../assets/base.js"></script>
<script src="js/libs/angular/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
<script src="js/controllers/TodoCtrl.js"></script>
<script src="js/services/TodoStorage.js"></script>
<script src="js/directives/TodoFocus.js"></script>
......
'use strict';
var todomvc = angular.module('todomvc', []).controller('todoCtrl', TodoCtrl).directive('todoBlur', function () {
return new TodoBlur();
}).directive('todoFocus', function ($timeout) {
return new TodoFocus($timeout);
}).service('todoStorage', TodoStorage);
//@ sourceMappingURL=app.js.map
......@@ -12,7 +12,7 @@
*/
var todomvc = angular.module('todomvc', [])
.controller('todoCtrl', TodoCtrl)
.directive('todoBlur', function () { return new TodoBlur(); })
.directive('todoFocus', function ($timeout: ng.ITimeoutService) { return new TodoFocus($timeout); })
.directive('todoBlur', () => { return new TodoBlur(); })
.directive('todoFocus', ($timeout: ng.ITimeoutService) => { return new TodoFocus($timeout); })
.service('todoStorage', TodoStorage)
;
'use strict';
var TodoCtrl = (function () {
function TodoCtrl($scope, $location, todoStorage, filterFilter) {
this.$scope = $scope;
this.todoStorage = todoStorage;
this.filterFilter = filterFilter;
var _this = this;
this.todos = $scope.todos = todoStorage.get();
$scope.newTodo = "";
$scope.editedTodo = null;
$scope.addTodo = function () {
return _this.addTodo();
};
$scope.editTodo = function (t) {
return _this.editTodo(t);
};
$scope.doneEditing = function (t) {
return _this.doneEditing(t);
};
$scope.removeTodo = function (t) {
return _this.removeTodo(t);
};
$scope.clearDoneTodos = function () {
return _this.clearDoneTodos();
};
$scope.markAll = function (d) {
return _this.markAll(d);
};
$scope.$watch('todos', function () {
return _this.onTodos();
}, true);
$scope.$watch('location.path()', function (path) {
return _this.onPath(path);
});
if($location.path() === '') {
$location.path('/');
}
$scope.location = $location;
}
TodoCtrl.prototype.onPath = function (path) {
this.$scope.statusFilter = (path == '/active') ? {
completed: false
} : (path == '/completed') ? {
completed: true
} : null;
};
TodoCtrl.prototype.onTodos = function () {
this.$scope.remainingCount = this.filterFilter(this.todos, {
completed: false
}).length;
this.$scope.doneCount = this.todos.length - this.$scope.remainingCount;
this.$scope.allChecked = !this.$scope.remainingCount;
this.todoStorage.put(this.todos);
};
TodoCtrl.prototype.addTodo = function () {
if(!this.$scope.newTodo.length) {
return;
}
this.todos.push({
title: this.$scope.newTodo,
completed: false
});
this.$scope.newTodo = '';
};
TodoCtrl.prototype.editTodo = function (todo) {
this.$scope.editedTodo = todo;
};
TodoCtrl.prototype.doneEditing = function (todo) {
this.$scope.editedTodo = null;
if(!todo.title) {
this.$scope.removeTodo(todo);
}
};
TodoCtrl.prototype.removeTodo = function (todo) {
this.todos.splice(this.todos.indexOf(todo), 1);
};
TodoCtrl.prototype.clearDoneTodos = function () {
this.$scope.todos = this.todos = this.todos.filter(function (val) {
return !val.completed;
});
};
TodoCtrl.prototype.markAll = function (done) {
this.todos.forEach(function (todo) {
todo.completed = done;
});
};
return TodoCtrl;
})();
//@ sourceMappingURL=TodoCtrl.js.map
......@@ -14,22 +14,22 @@
class TodoCtrl {
private todos;
constructor (private $scope: ITodoScope, $location: ng.ILocationService, private todoStorage: ITodoStorage, private filterFilter) {
constructor(private $scope: ITodoScope, $location: ng.ILocationService, private todoStorage: ITodoStorage, private filterFilter) {
this.todos = $scope.todos = todoStorage.get();
$scope.newTodo = "";
$scope.editedTodo = null;
$scope.addTodo = () =>this.addTodo();
$scope.editTodo = (t) =>this.editTodo(t);
$scope.doneEditing = (t) =>this.doneEditing(t);
$scope.removeTodo = (t) =>this.removeTodo(t);
$scope.clearDoneTodos = () =>this.clearDoneTodos();
$scope.markAll = (d) =>this.markAll(d);
$scope.addTodo = () => this.addTodo();
$scope.editTodo = (t) => this.editTodo(t);
$scope.doneEditing = (t) => this.doneEditing(t);
$scope.removeTodo = (t) => this.removeTodo(t);
$scope.clearDoneTodos = () => this.clearDoneTodos();
$scope.markAll = (d) => this.markAll(d);
$scope.$watch('todos', () =>this.onTodos(), true);
$scope.$watch('location.path()', (path) =>this.onPath(path));
$scope.$watch('todos', () => this.onTodos(), true);
$scope.$watch('location.path()', (path) => this.onPath(path));
if ($location.path() === '') $location.path('/');
$scope.location = $location;
......@@ -77,13 +77,13 @@ class TodoCtrl {
};
clearDoneTodos() {
this.$scope.todos = this.todos = this.todos.filter(function (val) {
this.$scope.todos = this.todos = this.todos.filter((val) => {
return !val.completed;
});
};
markAll(done: bool) {
this.todos.forEach(function (todo: TodoItem) {
this.todos.forEach((todo: TodoItem) => {
todo.completed = done;
});
};
......
'use strict';
var TodoBlur = (function () {
function TodoBlur() {
var _this = this;
this.link = function (s, e, a) {
return _this.linkFn(s, e, a);
};
}
TodoBlur.prototype.linkFn = function ($scope, elem, attrs) {
elem.bind('blur', function () {
$scope.$apply(attrs.todoBlur);
});
};
return TodoBlur;
})();
//@ sourceMappingURL=TodoBlur.js.map
......@@ -8,12 +8,12 @@
class TodoBlur {
public link: ($scope: ng.IScope, elem: JQuery, attrs: any) => any;
constructor () {
this.link = (s, e, a) =>this.linkFn(s, e, a);
constructor() {
this.link = (s, e, a) => this.linkFn(s, e, a);
}
linkFn($scope: ng.IScope, elem: JQuery, attrs: any): any {
elem.bind('blur', function () {
elem.bind('blur', () => {
$scope.$apply(attrs.todoBlur);
});
};
......
'use strict';
var TodoFocus = (function () {
function TodoFocus($timeout) {
this.$timeout = $timeout;
var _this = this;
this.link = function (s, e, a) {
return _this.linkFn(s, e, a);
};
}
TodoFocus.prototype.linkFn = function ($scope, elem, attrs) {
var _this = this;
$scope.$watch(attrs.todoFocus, function (newval) {
if(newval) {
_this.$timeout(function () {
elem[0].focus();
}, 0, false);
}
});
};
return TodoFocus;
})();
//@ sourceMappingURL=TodoFocus.js.map
......@@ -8,14 +8,14 @@ class TodoFocus {
public link: ($scope: ng.IScope, elem: JQuery, attrs: any) => any;
constructor (private $timeout: ng.ITimeoutService) {
this.link = (s, e, a) =>this.linkFn(s, e, a);
constructor(private $timeout: ng.ITimeoutService) {
this.link = (s, e, a) => this.linkFn(s, e, a);
}
linkFn($scope: ng.IScope, elem: JQuery, attrs: any): any {
$scope.$watch(attrs.todoFocus, function (newval) {
$scope.$watch(attrs.todoFocus, (newval) => {
if (newval) {
this.$timeout(function () {
this.$timeout(() => {
elem[0].focus();
}, 0, false);
}
......
'use strict';
//@ sourceMappingURL=ITodoScope.js.map
'use strict';
//@ sourceMappingURL=ITodoStorage.js.map
'use strict';
var TodoItem = (function () {
function TodoItem() { }
return TodoItem;
})();
//@ sourceMappingURL=TodoItem.js.map
'use strict';
var TodoStorage = (function () {
function TodoStorage() {
this.STORAGE_ID = 'todos-angularjs-requirejs';
}
TodoStorage.prototype.get = function () {
return JSON.parse(localStorage.getItem(this.STORAGE_ID) || '[]');
};
TodoStorage.prototype.put = function (todos) {
localStorage.setItem(this.STORAGE_ID, JSON.stringify(todos));
};
return TodoStorage;
})();
//@ sourceMappingURL=TodoStorage.js.map
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