0 Votes

Changes for page Todolist Macro

Last modified by Ryan C on 2025/04/30 07:54

From version 14.1
edited by Ryan C
on 2025/04/24 11:07
Change comment: Todo List item added
To version 26.1
edited by Ryan C
on 2025/04/24 11:19
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,10 +1,9 @@
1 1  Macro to display todo-lists using emberjs. This code is based on the emberjs demo. You can see an example below
2 2  
3 3  {{todolist width="50%" center="1"}}
4 -a thing|1
5 -a second thing|0
6 6  a 3nd thing|0
7 -a 3nd thing|1
8 -a 3nd thing|0
5 +adding this thing|0
6 +adding this thing|0
7 +refreshed they are still there not even having to save page|0
9 9  
10 10  {{/todolist}}
XWiki.JavaScriptExtension[0]
Code
... ... @@ -21,6 +21,8 @@
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 +
24 24   createRecord: function(store, type, record) {
25 25   console.log("createRecord");
26 26   var data = this.serialize(record, { includeId: true });
... ... @@ -27,16 +27,18 @@
27 27   var query = { create: "1", content: JSON.stringify(data) };
28 28  
29 29   return new Ember.RSVP.Promise(function(resolve, reject) {
30 - jQuery.getJSON(
31 - "${xwiki.getURL('TodoLists.TodoListsService')}?page=" +
32 + var url = "${xwiki.getURL('TodoLists.TodoListsService')}?page=" +
32 32   XWiki.currentSpace + "." + XWiki.currentPage +
33 - "&xpage=plain&outputSyntax=plain",
34 - query
35 - ).then(function(data) {
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);
36 36   Ember.run(function() {
37 37   resolve(data);
38 38   });
39 39   }, function(jqXHR) {
43 + console.error("Create error:", jqXHR);
40 40   Ember.run(function() {
41 41   reject(jqXHR);
42 42   });
... ... @@ -63,16 +63,18 @@
63 63   var query = { since: sinceToken };
64 64  
65 65   return new Ember.RSVP.Promise(function(resolve, reject) {
66 - jQuery.getJSON(
67 - "${xwiki.getURL('TodoLists.TodoListsService')}?page=" +
70 + var url = "${xwiki.getURL('TodoLists.TodoListsService')}?page=" +
68 68   XWiki.currentSpace + "." + XWiki.currentPage +
69 - "&xpage=plain&outputSyntax=plain",
70 - query
71 - ).then(function(data) {
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);
72 72   Ember.run(function() {
73 73   resolve(data);
74 74   });
75 75   }, function(jqXHR) {
81 + console.error("FindAll error:", jqXHR);
76 76   Ember.run(function() {
77 77   reject(jqXHR);
78 78   });
... ... @@ -81,6 +81,7 @@
81 81   },
82 82  
83 83   updateRecord: function(store, type, record) {
90 + console.log("updateRecord");
84 84   var recordArrays = store.recordArrayManager.recordArraysForRecord(record);
85 85   if (recordArrays && recordArrays.list && recordArrays.list[0]) {
86 86   return this.saveAll(recordArrays.list[0].content);
... ... @@ -93,16 +93,18 @@
93 93   var query = { save: "1", content: JSON.stringify(alldata) };
94 94  
95 95   return new Ember.RSVP.Promise(function(resolve, reject) {
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) {
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);
102 102   Ember.run(function() {
103 103   resolve(data);
104 104   });
105 105   }, function(jqXHR) {
114 + console.error("SaveAll error:", jqXHR);
106 106   Ember.run(function() {
107 107   reject(jqXHR);
108 108   });
... ... @@ -111,11 +111,6 @@
111 111   }
112 112   });
113 113  
114 - // Register the adapter
115 - Todos.ApplicationAdapter.reopen({
116 - namespace: 'api'
117 - });
118 -
119 119   // Routing
120 120   Todos.Router.map(function() {
121 121   this.resource('todos', { path: '' }, function() {
... ... @@ -212,6 +212,8 @@
212 212   var title = this.get('newTitle');
213 213   if (!title || !title.trim()) { return; }
214 214  
219 + console.log("Creating new todo with title:", title);
220 +
215 215   // Create the new Todo model
216 216   var todo = this.store.createRecord('todo', {
217 217   title: title,
... ... @@ -224,11 +224,15 @@
224 224   this.set('newTitle', '');
225 225  
226 226   // Save the new model
227 - todo.save().then(function() {
233 + todo.save().then(function(savedTodo) {
234 + console.log("Todo saved successfully:", savedTodo);
228 228   // Force a refresh of the list after saving
229 229   Ember.run.later(function() {
237 + console.log("Refreshing todo list");
230 230   Todos.store.find('todo');
231 231   }, 100);
240 + }, function(error) {
241 + console.error("Failed to save todo:", error);
232 232   });
233 233   },
234 234