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