... |
... |
@@ -21,8 +21,6 @@ |
21 |
21 |
|
22 |
22 |
// Define the todolist store that will write to the TodoListsService |
23 |
23 |
Todos.ApplicationAdapter = DS.Adapter.extend({ |
24 |
|
- namespace: 'api', // Moved inside the adapter definition |
25 |
|
- |
26 |
26 |
createRecord: function(store, type, record) { |
27 |
27 |
console.log("createRecord"); |
28 |
28 |
var data = this.serialize(record, { includeId: true }); |
... |
... |
@@ -29,18 +29,16 @@ |
29 |
29 |
var query = { create: "1", content: JSON.stringify(data) }; |
30 |
30 |
|
31 |
31 |
return new Ember.RSVP.Promise(function(resolve, reject) { |
32 |
|
- var url = "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
|
30 |
+ jQuery.getJSON( |
|
31 |
+ "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
33 |
33 |
XWiki.currentSpace + "." + XWiki.currentPage + |
34 |
|
- "&xpage=plain&outputSyntax=plain"; |
35 |
|
- console.log("Creating record, URL:", url); |
36 |
|
- |
37 |
|
- jQuery.getJSON(url, query).then(function(data) { |
38 |
|
- console.log("Create success:", data); |
|
33 |
+ "&xpage=plain&outputSyntax=plain", |
|
34 |
+ query |
|
35 |
+ ).then(function(data) { |
39 |
39 |
Ember.run(function() { |
40 |
40 |
resolve(data); |
41 |
41 |
}); |
42 |
42 |
}, function(jqXHR) { |
43 |
|
- console.error("Create error:", jqXHR); |
44 |
44 |
Ember.run(function() { |
45 |
45 |
reject(jqXHR); |
46 |
46 |
}); |
... |
... |
@@ -67,18 +67,16 @@ |
67 |
67 |
var query = { since: sinceToken }; |
68 |
68 |
|
69 |
69 |
return new Ember.RSVP.Promise(function(resolve, reject) { |
70 |
|
- var url = "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
|
66 |
+ jQuery.getJSON( |
|
67 |
+ "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
71 |
71 |
XWiki.currentSpace + "." + XWiki.currentPage + |
72 |
|
- "&xpage=plain&outputSyntax=plain"; |
73 |
|
- console.log("Finding all records, URL:", url); |
74 |
|
- |
75 |
|
- jQuery.getJSON(url, query).then(function(data) { |
76 |
|
- console.log("FindAll success:", data); |
|
69 |
+ "&xpage=plain&outputSyntax=plain", |
|
70 |
+ query |
|
71 |
+ ).then(function(data) { |
77 |
77 |
Ember.run(function() { |
78 |
78 |
resolve(data); |
79 |
79 |
}); |
80 |
80 |
}, function(jqXHR) { |
81 |
|
- console.error("FindAll error:", jqXHR); |
82 |
82 |
Ember.run(function() { |
83 |
83 |
reject(jqXHR); |
84 |
84 |
}); |
... |
... |
@@ -87,7 +87,6 @@ |
87 |
87 |
}, |
88 |
88 |
|
89 |
89 |
updateRecord: function(store, type, record) { |
90 |
|
- console.log("updateRecord"); |
91 |
91 |
var recordArrays = store.recordArrayManager.recordArraysForRecord(record); |
92 |
92 |
if (recordArrays && recordArrays.list && recordArrays.list[0]) { |
93 |
93 |
return this.saveAll(recordArrays.list[0].content); |
... |
... |
@@ -100,18 +100,16 @@ |
100 |
100 |
var query = { save: "1", content: JSON.stringify(alldata) }; |
101 |
101 |
|
102 |
102 |
return new Ember.RSVP.Promise(function(resolve, reject) { |
103 |
|
- var currentPage = XWiki.currentSpace + "." + XWiki.currentPage; |
104 |
|
- var url = "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
105 |
|
- currentPage + "&xpage=plain&outputSyntax=plain"; |
106 |
|
- console.log("Saving all records, URL:", url, "Page:", currentPage); |
107 |
|
- |
108 |
|
- jQuery.getJSON(url, query).then(function(data) { |
109 |
|
- console.log("SaveAll success:", data); |
|
96 |
+ jQuery.getJSON( |
|
97 |
+ "${xwiki.getURL('TodoLists.TodoListsService')}?page=" + |
|
98 |
+ XWiki.currentSpace + "." + XWiki.currentPage + |
|
99 |
+ "&xpage=plain&outputSyntax=plain", |
|
100 |
+ query |
|
101 |
+ ).then(function(data) { |
110 |
110 |
Ember.run(function() { |
111 |
111 |
resolve(data); |
112 |
112 |
}); |
113 |
113 |
}, function(jqXHR) { |
114 |
|
- console.error("SaveAll error:", jqXHR); |
115 |
115 |
Ember.run(function() { |
116 |
116 |
reject(jqXHR); |
117 |
117 |
}); |
... |
... |
@@ -120,6 +120,11 @@ |
120 |
120 |
} |
121 |
121 |
}); |
122 |
122 |
|
|
114 |
+ // Register the adapter |
|
115 |
+ Todos.ApplicationAdapter.reopen({ |
|
116 |
+ namespace: 'api' |
|
117 |
+ }); |
|
118 |
+ |
123 |
123 |
// Routing |
124 |
124 |
Todos.Router.map(function() { |
125 |
125 |
this.resource('todos', { path: '' }, function() { |
... |
... |
@@ -216,8 +216,6 @@ |
216 |
216 |
var title = this.get('newTitle'); |
217 |
217 |
if (!title || !title.trim()) { return; } |
218 |
218 |
|
219 |
|
- console.log("Creating new todo with title:", title); |
220 |
|
- |
221 |
221 |
// Create the new Todo model |
222 |
222 |
var todo = this.store.createRecord('todo', { |
223 |
223 |
title: title, |
... |
... |
@@ -230,15 +230,11 @@ |
230 |
230 |
this.set('newTitle', ''); |
231 |
231 |
|
232 |
232 |
// Save the new model |
233 |
|
- todo.save().then(function(savedTodo) { |
234 |
|
- console.log("Todo saved successfully:", savedTodo); |
|
227 |
+ todo.save().then(function() { |
235 |
235 |
// Force a refresh of the list after saving |
236 |
236 |
Ember.run.later(function() { |
237 |
|
- console.log("Refreshing todo list"); |
238 |
238 |
Todos.store.find('todo'); |
239 |
239 |
}, 100); |
240 |
|
- }, function(error) { |
241 |
|
- console.error("Failed to save todo:", error); |
242 |
242 |
}); |
243 |
243 |
}, |
244 |
244 |
|