... |
... |
@@ -1,13 +1,8 @@ |
1 |
1 |
requirejs.config({ |
2 |
2 |
baseUrl: '${xwiki.getDocument("TodoLists.TodoListMacro").getURL("download")}/', |
3 |
3 |
paths: { |
4 |
|
- // Use existing jQuery if available, otherwise load 1.10.2 |
5 |
|
- 'jquery': window.jQuery ? 'empty:' : 'https://code.jquery.com/jquery-1.10.2.min' |
|
4 |
+ 'jquery': 'https://code.jquery.com/jquery-3.6.0.min' // Updated jQuery version |
6 |
6 |
}, |
7 |
|
- map: { |
8 |
|
- // Map any module requiring 'jquery' to use the global jQuery |
9 |
|
- '*': { 'jquery': window.jQuery ? 'jquery-global' : 'jquery' } |
10 |
|
- }, |
11 |
11 |
shim: { |
12 |
12 |
'ember-data': { |
13 |
13 |
deps: ['ember', 'jquery'] |
... |
... |
@@ -18,331 +18,283 @@ |
18 |
18 |
} |
19 |
19 |
}); |
20 |
20 |
|
21 |
|
-// Define a module that returns the global jQuery |
22 |
|
-define('jquery-global', [], function() { |
23 |
|
- return window.jQuery; |
24 |
|
-}); |
25 |
|
- |
26 |
|
-// Define empty module for when jQuery is already loaded |
27 |
|
-define('empty:', [], function() { |
28 |
|
- return window.jQuery; |
29 |
|
-}); |
30 |
|
- |
31 |
31 |
require(['jquery', 'handlebars-v1.2.1', 'ember-data', 'ember'], function($) { |
32 |
|
- // Check jQuery version compatibility with Ember |
33 |
|
- var jQueryVersion = $.fn.jquery.split('.'); |
34 |
|
- var majorVersion = parseInt(jQueryVersion[0]); |
35 |
|
- var minorVersion = parseInt(jQueryVersion[1]); |
|
17 |
+ // Create app |
|
18 |
+ window.Todos = Ember.Application.create({ |
|
19 |
+ rootElement: '#todoappdiv' |
|
20 |
+ }); |
36 |
36 |
|
37 |
|
- console.log("Using jQuery version:", $.fn.jquery); |
38 |
|
- |
39 |
|
- // Verify jQuery version is compatible with Ember |
40 |
|
- var isCompatible = (majorVersion === 1 && minorVersion >= 7 && minorVersion <= 10) || |
41 |
|
- (majorVersion === 2 && minorVersion === 0); |
42 |
|
- |
43 |
|
- if (!isCompatible) { |
44 |
|
- console.error("Warning: Ember Views require jQuery 1.7, 1.8, 1.9, 1.10, or 2.0. Current version:", $.fn.jquery); |
45 |
|
- // Try to load a compatible version if needed |
46 |
|
- require(['https://code.jquery.com/jquery-1.10.2.min.js'], function(compatibleJQuery) { |
47 |
|
- // Store the original jQuery |
48 |
|
- var originalJQuery = window.jQuery; |
49 |
|
- // Replace with compatible jQuery temporarily |
50 |
|
- window.jQuery = compatibleJQuery; |
51 |
|
- // Continue with the rest of the code |
52 |
|
- initializeEmberApp(compatibleJQuery); |
53 |
|
- // Restore original jQuery when done |
54 |
|
- window.jQuery = originalJQuery; |
|
22 |
+ // Define the todolist store that will write to the TodoListsService |
|
23 |
+ Todos.ApplicationAdapter = DS.Adapter.extend({ |
|
24 |
+ createRecord: function(store, type, record) { |
|
25 |
+ console.log("createRecord"); |
|
26 |
+ var data = this.serialize(record, { includeId: true }); |
|
27 |
+ var query = { create: "1", content: JSON.stringify(data) }; |
|
28 |
+ |
|
29 |
+ return new Ember.RSVP.Promise(function(resolve, reject) { |
|
30 |
+ jQuery.getJSON( |
|
31 |
+ "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
|
32 |
+ XWiki.currentSpace + "." + XWiki.currentPage + |
|
33 |
+ "&xpage=plain&outputSyntax=plain", |
|
34 |
+ query |
|
35 |
+ ).then(function(data) { |
|
36 |
+ Ember.run(function() { |
|
37 |
+ resolve(data); |
|
38 |
+ }); |
|
39 |
+ }, function(jqXHR) { |
|
40 |
+ Ember.run(function() { |
|
41 |
+ reject(jqXHR); |
|
42 |
+ }); |
|
43 |
+ }); |
|
44 |
+ }); |
|
45 |
+ }, |
|
46 |
+ |
|
47 |
+ deleteRecord: function(store, type, record) { |
|
48 |
+ console.log("deleteRecord"); |
|
49 |
+ var recordArrays = store.recordArrayManager.recordArraysForRecord(record); |
|
50 |
+ if (recordArrays && recordArrays.list && recordArrays.list[0]) { |
|
51 |
+ return this.saveAll(recordArrays.list[0].content); |
|
52 |
+ } |
|
53 |
+ return Ember.RSVP.resolve(); |
|
54 |
+ }, |
|
55 |
+ |
|
56 |
+ find: function(store, type, id) { |
|
57 |
+ console.log("find"); |
|
58 |
+ return Ember.RSVP.resolve(); |
|
59 |
+ }, |
|
60 |
+ |
|
61 |
+ findAll: function(store, type, sinceToken) { |
|
62 |
+ console.log("findAll"); |
|
63 |
+ var query = { since: sinceToken }; |
|
64 |
+ |
|
65 |
+ return new Ember.RSVP.Promise(function(resolve, reject) { |
|
66 |
+ jQuery.getJSON( |
|
67 |
+ "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
|
68 |
+ XWiki.currentSpace + "." + XWiki.currentPage + |
|
69 |
+ "&xpage=plain&outputSyntax=plain", |
|
70 |
+ query |
|
71 |
+ ).then(function(data) { |
|
72 |
+ Ember.run(function() { |
|
73 |
+ resolve(data); |
|
74 |
+ }); |
|
75 |
+ }, function(jqXHR) { |
|
76 |
+ Ember.run(function() { |
|
77 |
+ reject(jqXHR); |
|
78 |
+ }); |
|
79 |
+ }); |
|
80 |
+ }); |
|
81 |
+ }, |
|
82 |
+ |
|
83 |
+ updateRecord: function(store, type, record) { |
|
84 |
+ var recordArrays = store.recordArrayManager.recordArraysForRecord(record); |
|
85 |
+ if (recordArrays && recordArrays.list && recordArrays.list[0]) { |
|
86 |
+ return this.saveAll(recordArrays.list[0].content); |
|
87 |
+ } |
|
88 |
+ return Ember.RSVP.resolve(); |
|
89 |
+ }, |
|
90 |
+ saveAll: function(alldata) { |
|
91 |
+ console.log("saveAll"); |
|
92 |
+ var query = { save: "1", content: JSON.stringify(alldata) }; |
|
93 |
+return new Ember.RSVP.Promise(function(resolve, reject) { |
|
94 |
+ jQuery.getJSON( |
|
95 |
+ "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
|
96 |
+ ( |
|
97 |
+ typeof XWiki !== 'undefined' && |
|
98 |
+ XWiki.currentSpace && |
|
99 |
+ XWiki.currentPage |
|
100 |
+ ? XWiki.currentSpace + "." + XWiki.currentPage |
|
101 |
+ : document.location.pathname.split('/').pop() |
|
102 |
+ ) + |
|
103 |
+ "&xpage=plain&outputSyntax=plain", |
|
104 |
+ query |
|
105 |
+ ).then(function(data) { |
|
106 |
+ Ember.run(function() { |
|
107 |
+ resolve(data); |
55 |
55 |
}); |
56 |
|
- } else { |
57 |
|
- // jQuery version is compatible, proceed normally |
58 |
|
- initializeEmberApp($); |
59 |
|
- } |
60 |
|
- |
61 |
|
- function initializeEmberApp($) { |
62 |
|
- // Create app |
63 |
|
- window.Todos = Ember.Application.create({ |
64 |
|
- rootElement: '#todoappdiv' |
|
109 |
+ }, function(jqXHR) { |
|
110 |
+ Ember.run(function() { |
|
111 |
+ reject(jqXHR); |
65 |
65 |
}); |
|
113 |
+ }); |
|
114 |
+}); |
66 |
66 |
|
67 |
|
- // Define the todolist store that will write to the TodoListsService |
68 |
|
- Todos.ApplicationAdapter = DS.Adapter.extend({ |
69 |
|
- namespace: 'api', // Moved inside the adapter definition |
70 |
70 |
|
71 |
|
- createRecord: function(store, type, record) { |
72 |
|
- console.log("createRecord"); |
73 |
|
- var data = this.serialize(record, { includeId: true }); |
74 |
|
- var query = { create: "1", content: JSON.stringify(data) }; |
|
117 |
+ // Register the adapter |
|
118 |
+ Todos.ApplicationAdapter.reopen({ |
|
119 |
+ namespace: 'api' |
|
120 |
+ }); |
75 |
75 |
|
76 |
|
- return new Ember.RSVP.Promise(function(resolve, reject) { |
77 |
|
- var url = "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
78 |
|
- XWiki.currentSpace + "." + XWiki.currentPage + |
79 |
|
- "&xpage=plain&outputSyntax=plain"; |
80 |
|
- console.log("Creating record, URL:", url); |
|
122 |
+ // Routing |
|
123 |
+ Todos.Router.map(function() { |
|
124 |
+ this.resource('todos', { path: '' }, function() { |
|
125 |
+ this.route('active'); |
|
126 |
+ this.route('completed'); |
|
127 |
+ }); |
|
128 |
+ }); |
81 |
81 |
|
82 |
|
- jQuery.getJSON(url, query).then(function(data) { |
83 |
|
- console.log("Create success:", data); |
84 |
|
- Ember.run(function() { |
85 |
|
- resolve(data); |
86 |
|
- }); |
87 |
|
- }, function(jqXHR) { |
88 |
|
- console.error("Create error:", jqXHR); |
89 |
|
- Ember.run(function() { |
90 |
|
- reject(jqXHR); |
91 |
|
- }); |
92 |
|
- }); |
93 |
|
- }); |
94 |
|
- }, |
|
130 |
+ Todos.TodosRoute = Ember.Route.extend({ |
|
131 |
+ model: function() { |
|
132 |
+ return this.store.find('todo'); |
|
133 |
+ } |
|
134 |
+ }); |
95 |
95 |
|
96 |
|
- deleteRecord: function(store, type, record) { |
97 |
|
- console.log("deleteRecord"); |
98 |
|
- var recordArrays = store.recordArrayManager.recordArraysForRecord(record); |
99 |
|
- if (recordArrays && recordArrays.list && recordArrays.list[0]) { |
100 |
|
- return this.saveAll(recordArrays.list[0].content); |
101 |
|
- } |
102 |
|
- return Ember.RSVP.resolve(); |
103 |
|
- }, |
|
136 |
+ Todos.TodosIndexRoute = Ember.Route.extend({ |
|
137 |
+ model: function() { |
|
138 |
+ return this.modelFor('todos'); |
|
139 |
+ } |
|
140 |
+ }); |
104 |
104 |
|
105 |
|
- find: function(store, type, id) { |
106 |
|
- console.log("find"); |
107 |
|
- return Ember.RSVP.resolve(); |
108 |
|
- }, |
|
142 |
+ Todos.TodosActiveRoute = Ember.Route.extend({ |
|
143 |
+ model: function() { |
|
144 |
+ return this.store.filter('todo', function(todo) { |
|
145 |
+ return !todo.get('isCompleted'); |
|
146 |
+ }); |
|
147 |
+ }, |
|
148 |
+ renderTemplate: function(controller) { |
|
149 |
+ this.render('todos/index', { controller: controller }); |
|
150 |
+ } |
|
151 |
+ }); |
109 |
109 |
|
110 |
|
- findAll: function(store, type, sinceToken) { |
111 |
|
- console.log("findAll"); |
112 |
|
- var query = { since: sinceToken }; |
|
153 |
+ Todos.TodosCompletedRoute = Ember.Route.extend({ |
|
154 |
+ model: function() { |
|
155 |
+ return this.store.filter('todo', function(todo) { |
|
156 |
+ return todo.get('isCompleted'); |
|
157 |
+ }); |
|
158 |
+ }, |
|
159 |
+ renderTemplate: function(controller) { |
|
160 |
+ this.render('todos/index', { controller: controller }); |
|
161 |
+ } |
|
162 |
+ }); |
113 |
113 |
|
114 |
|
- return new Ember.RSVP.Promise(function(resolve, reject) { |
115 |
|
- var url = "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
116 |
|
- XWiki.currentSpace + "." + XWiki.currentPage + |
117 |
|
- "&xpage=plain&outputSyntax=plain"; |
118 |
|
- console.log("Finding all records, URL:", url); |
|
164 |
+ // Data model |
|
165 |
+ Todos.Todo = DS.Model.extend({ |
|
166 |
+ title: DS.attr('string'), |
|
167 |
+ priority: DS.attr('string'), |
|
168 |
+ assignee: DS.attr('string'), |
|
169 |
+ isCompleted: DS.attr('boolean') |
|
170 |
+ }); |
119 |
119 |
|
120 |
|
- jQuery.getJSON(url, query).then(function(data) { |
121 |
|
- console.log("FindAll success:", data); |
122 |
|
- Ember.run(function() { |
123 |
|
- resolve(data); |
124 |
|
- }); |
125 |
|
- }, function(jqXHR) { |
126 |
|
- console.error("FindAll error:", jqXHR); |
127 |
|
- Ember.run(function() { |
128 |
|
- reject(jqXHR); |
129 |
|
- }); |
130 |
|
- }); |
131 |
|
- }); |
|
172 |
+ // Controller |
|
173 |
+ Todos.TodoController = Ember.ObjectController.extend({ |
|
174 |
+ actions: { |
|
175 |
+ editTodo: function() { |
|
176 |
+ this.set('isEditing', true); |
132 |
132 |
}, |
|
178 |
+ acceptChanges: function() { |
|
179 |
+ this.set('isEditing', false); |
133 |
133 |
|
134 |
|
- updateRecord: function(store, type, record) { |
135 |
|
- console.log("updateRecord"); |
136 |
|
- var recordArrays = store.recordArrayManager.recordArraysForRecord(record); |
137 |
|
- if (recordArrays && recordArrays.list && recordArrays.list[0]) { |
138 |
|
- return this.saveAll(recordArrays.list[0].content); |
|
181 |
+ if (Ember.isEmpty(this.get('model.title'))) { |
|
182 |
+ this.send('removeTodo'); |
|
183 |
+ } else { |
|
184 |
+ this.get('model').save(); |
139 |
139 |
} |
140 |
|
- return Ember.RSVP.resolve(); |
141 |
141 |
}, |
|
187 |
+ removeTodo: function() { |
|
188 |
+ var todo = this.get('model'); |
|
189 |
+ todo.deleteRecord(); |
|
190 |
+ todo.save(); |
|
191 |
+ } |
|
192 |
+ }, |
142 |
142 |
|
143 |
|
- saveAll: function(alldata) { |
144 |
|
- console.log("saveAll"); |
145 |
|
- var query = { save: "1", content: JSON.stringify(alldata) }; |
|
194 |
+ isEditing: false, |
146 |
146 |
|
147 |
|
- return new Ember.RSVP.Promise(function(resolve, reject) { |
148 |
|
- var currentPage = XWiki.currentSpace + "." + XWiki.currentPage; |
149 |
|
- var url = "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
150 |
|
- currentPage + "&xpage=plain&outputSyntax=plain"; |
151 |
|
- console.log("Saving all records, URL:", url, "Page:", currentPage); |
|
196 |
+ isCompleted: function(key, value) { |
|
197 |
+ var model = this.get('model'); |
152 |
152 |
|
153 |
|
- jQuery.getJSON(url, query).then(function(data) { |
154 |
|
- console.log("SaveAll success:", data); |
155 |
|
- Ember.run(function() { |
156 |
|
- resolve(data); |
157 |
|
- }); |
158 |
|
- }, function(jqXHR) { |
159 |
|
- console.error("SaveAll error:", jqXHR); |
160 |
|
- Ember.run(function() { |
161 |
|
- reject(jqXHR); |
162 |
|
- }); |
163 |
|
- }); |
164 |
|
- }); |
|
199 |
+ if (value === undefined) { |
|
200 |
+ // Property being used as a getter |
|
201 |
+ return model.get('isCompleted'); |
|
202 |
+ } else { |
|
203 |
+ // Property being used as setter |
|
204 |
+ model.set('isCompleted', value); |
|
205 |
+ model.save(); |
|
206 |
+ return value; |
165 |
165 |
} |
166 |
|
- }); |
|
208 |
+ }.property('model.isCompleted') |
|
209 |
+ }); |
167 |
167 |
|
168 |
|
- // Routing |
169 |
|
- Todos.Router.map(function() { |
170 |
|
- this.resource('todos', { path: '' }, function() { |
171 |
|
- this.route('active'); |
172 |
|
- this.route('completed'); |
173 |
|
- }); |
174 |
|
- }); |
|
211 |
+ Todos.TodosController = Ember.ArrayController.extend({ |
|
212 |
+ actions: { |
|
213 |
+ createTodo: function() { |
|
214 |
+ // Get the todo title set by the "New Todo" text field |
|
215 |
+ var title = this.get('newTitle'); |
|
216 |
+ if (!title || !title.trim()) { return; } |
175 |
175 |
|
176 |
|
- Todos.TodosRoute = Ember.Route.extend({ |
177 |
|
- model: function() { |
178 |
|
- return this.store.find('todo'); |
179 |
|
- } |
180 |
|
- }); |
|
218 |
+ // Create the new Todo model |
|
219 |
+ var todo = this.store.createRecord('todo', { |
|
220 |
+ title: title, |
|
221 |
+ priority: "P3", |
|
222 |
+ assignee: "all", |
|
223 |
+ isCompleted: false |
|
224 |
+ }); |
181 |
181 |
|
182 |
|
- Todos.TodosIndexRoute = Ember.Route.extend({ |
183 |
|
- model: function() { |
184 |
|
- return this.modelFor('todos'); |
185 |
|
- } |
186 |
|
- }); |
|
226 |
+ // Clear the "New Todo" text field |
|
227 |
+ this.set('newTitle', ''); |
187 |
187 |
|
188 |
|
- Todos.TodosActiveRoute = Ember.Route.extend({ |
189 |
|
- model: function() { |
190 |
|
- return this.store.filter('todo', function(todo) { |
191 |
|
- return !todo.get('isCompleted'); |
|
229 |
+ // Save the new model |
|
230 |
+ todo.save().then(function() { |
|
231 |
+ // Force a refresh of the list after saving |
|
232 |
+ Ember.run.later(function() { |
|
233 |
+ Todos.store.find('todo'); |
|
234 |
+ }, 100); |
192 |
192 |
}); |
193 |
193 |
}, |
194 |
|
- renderTemplate: function(controller) { |
195 |
|
- this.render('todos/index', { controller: controller }); |
196 |
|
- } |
197 |
|
- }); |
198 |
|
- |
199 |
|
- Todos.TodosCompletedRoute = Ember.Route.extend({ |
200 |
|
- model: function() { |
201 |
|
- return this.store.filter('todo', function(todo) { |
|
237 |
+ |
|
238 |
+ clearCompleted: function() { |
|
239 |
+ var completed = this.filter(function(todo) { |
202 |
202 |
return todo.get('isCompleted'); |
203 |
203 |
}); |
204 |
|
- }, |
205 |
|
- renderTemplate: function(controller) { |
206 |
|
- this.render('todos/index', { controller: controller }); |
207 |
|
- } |
208 |
|
- }); |
209 |
|
- |
210 |
|
- // Data model |
211 |
|
- Todos.Todo = DS.Model.extend({ |
212 |
|
- title: DS.attr('string'), |
213 |
|
- priority: DS.attr('string'), |
214 |
|
- assignee: DS.attr('string'), |
215 |
|
- isCompleted: DS.attr('boolean') |
216 |
|
- }); |
217 |
|
- |
218 |
|
- // Controller |
219 |
|
- Todos.TodoController = Ember.ObjectController.extend({ |
220 |
|
- actions: { |
221 |
|
- editTodo: function() { |
222 |
|
- this.set('isEditing', true); |
223 |
|
- }, |
224 |
|
- acceptChanges: function() { |
225 |
|
- this.set('isEditing', false); |
226 |
|
- |
227 |
|
- if (Ember.isEmpty(this.get('model.title'))) { |
228 |
|
- this.send('removeTodo'); |
229 |
|
- } else { |
230 |
|
- this.get('model').save(); |
231 |
|
- } |
232 |
|
- }, |
233 |
|
- removeTodo: function() { |
234 |
|
- var todo = this.get('model'); |
|
242 |
+ |
|
243 |
+ completed.forEach(function(todo) { |
235 |
235 |
todo.deleteRecord(); |
236 |
236 |
todo.save(); |
237 |
|
- } |
238 |
|
- }, |
|
246 |
+ }); |
|
247 |
+ } |
|
248 |
+ }, |
239 |
239 |
|
240 |
|
- isEditing: false, |
|
250 |
+ remaining: function() { |
|
251 |
+ return this.filter(function(todo) { |
|
252 |
+ return !todo.get('isCompleted'); |
|
253 |
+ }).get('length'); |
|
254 |
+ }.property('@each.isCompleted'), |
241 |
241 |
|
242 |
|
- isCompleted: function(key, value) { |
243 |
|
- var model = this.get('model'); |
|
256 |
+ inflection: function() { |
|
257 |
+ var remaining = this.get('remaining'); |
|
258 |
+ return remaining === 1 ? 'item' : 'items'; |
|
259 |
+ }.property('remaining'), |
|
260 |
+ |
|
261 |
+ hasCompleted: function() { |
|
262 |
+ return this.get('completed') > 0; |
|
263 |
+ }.property('completed'), |
244 |
244 |
|
245 |
|
- if (value === undefined) { |
246 |
|
- // Property being used as a getter |
247 |
|
- return model.get('isCompleted'); |
248 |
|
- } else { |
249 |
|
- // Property being used as setter |
250 |
|
- model.set('isCompleted', value); |
251 |
|
- model.save(); |
252 |
|
- return value; |
253 |
|
- } |
254 |
|
- }.property('model.isCompleted') |
255 |
|
- }); |
|
265 |
+ completed: function() { |
|
266 |
+ return this.filter(function(todo) { |
|
267 |
+ return todo.get('isCompleted'); |
|
268 |
+ }).get('length'); |
|
269 |
+ }.property('@each.isCompleted'), |
256 |
256 |
|
257 |
|
- Todos.TodosController = Ember.ArrayController.extend({ |
258 |
|
- actions: { |
259 |
|
- createTodo: function() { |
260 |
|
- // Get the todo title set by the "New Todo" text field |
261 |
|
- var title = this.get('newTitle'); |
262 |
|
- if (!title || !title.trim()) { return; } |
263 |
|
- |
264 |
|
- console.log("Creating new todo with title:", title); |
265 |
|
- |
266 |
|
- // Create the new Todo model |
267 |
|
- var todo = this.store.createRecord('todo', { |
268 |
|
- title: title, |
269 |
|
- priority: "P3", |
270 |
|
- assignee: "all", |
271 |
|
- isCompleted: false |
272 |
|
- }); |
273 |
|
- |
274 |
|
- // Clear the "New Todo" text field |
275 |
|
- this.set('newTitle', ''); |
276 |
|
- |
277 |
|
- // Save the new model |
278 |
|
- todo.save().then(function(savedTodo) { |
279 |
|
- console.log("Todo saved successfully:", savedTodo); |
280 |
|
- // Force a refresh of the list after saving |
281 |
|
- Ember.run.later(function() { |
282 |
|
- console.log("Refreshing todo list"); |
283 |
|
- Todos.store.find('todo'); |
284 |
|
- }, 100); |
285 |
|
- }, function(error) { |
286 |
|
- console.error("Failed to save todo:", error); |
287 |
|
- }); |
288 |
|
- }, |
289 |
|
- |
290 |
|
- clearCompleted: function() { |
291 |
|
- var completed = this.filter(function(todo) { |
292 |
|
- return todo.get('isCompleted'); |
293 |
|
- }); |
294 |
|
- |
295 |
|
- completed.forEach(function(todo) { |
296 |
|
- todo.deleteRecord(); |
297 |
|
- todo.save(); |
298 |
|
- }); |
299 |
|
- } |
300 |
|
- }, |
301 |
|
- |
302 |
|
- remaining: function() { |
303 |
|
- return this.filter(function(todo) { |
304 |
|
- return !todo.get('isCompleted'); |
305 |
|
- }).get('length'); |
306 |
|
- }.property('@each.isCompleted'), |
307 |
|
- |
308 |
|
- inflection: function() { |
309 |
|
- var remaining = this.get('remaining'); |
310 |
|
- return remaining === 1 ? 'item' : 'items'; |
311 |
|
- }.property('remaining'), |
312 |
|
- |
313 |
|
- hasCompleted: function() { |
314 |
|
- return this.get('completed') > 0; |
315 |
|
- }.property('completed'), |
316 |
|
- |
317 |
|
- completed: function() { |
318 |
|
- return this.filter(function(todo) { |
|
271 |
+ allAreDone: function(key, value) { |
|
272 |
+ if (value === undefined) { |
|
273 |
+ return this.get('length') > 0 && this.every(function(todo) { |
319 |
319 |
return todo.get('isCompleted'); |
320 |
|
- }).get('length'); |
321 |
|
- }.property('@each.isCompleted'), |
322 |
|
- |
323 |
|
- allAreDone: function(key, value) { |
324 |
|
- if (value === undefined) { |
325 |
|
- return this.get('length') > 0 && this.every(function(todo) { |
326 |
|
- return todo.get('isCompleted'); |
327 |
|
- }); |
328 |
|
- } else { |
329 |
|
- this.forEach(function(todo) { |
330 |
|
- todo.set('isCompleted', value); |
331 |
|
- todo.save(); |
332 |
|
- }); |
333 |
|
- return value; |
334 |
|
- } |
335 |
|
- }.property('@each.isCompleted') |
336 |
|
- }); |
337 |
|
- |
338 |
|
- // Editing |
339 |
|
- Todos.EditTodoView = Ember.TextField.extend({ |
340 |
|
- didInsertElement: function() { |
341 |
|
- this.$().focus(); |
|
275 |
+ }); |
|
276 |
+ } else { |
|
277 |
+ this.forEach(function(todo) { |
|
278 |
+ todo.set('isCompleted', value); |
|
279 |
+ todo.save(); |
|
280 |
+ }); |
|
281 |
+ return value; |
342 |
342 |
} |
343 |
|
- }); |
|
283 |
+ }.property('@each.isCompleted') |
|
284 |
+ }); |
344 |
344 |
|
345 |
|
- Ember.Handlebars.helper('edit-todo', Todos.EditTodoView); |
346 |
|
- } |
|
286 |
+ // Editing |
|
287 |
+ Todos.EditTodoView = Ember.TextField.extend({ |
|
288 |
+ didInsertElement: function() { |
|
289 |
+ this.$().focus(); |
|
290 |
+ } |
|
291 |
+ }); |
|
292 |
+ |
|
293 |
+ Ember.Handlebars.helper('edit-todo', Todos.EditTodoView); |
347 |
347 |
}); |
348 |
348 |
|