0 Votes

Changes for page Todolist Macro

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

From version 24.1
edited by Ryan C
on 2025/04/24 11:16
Change comment: There is no comment for this version
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

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);
... ... @@ -87,38 +87,32 @@
87 87   }
88 88   return Ember.RSVP.resolve();
89 89   },
97 +
90 90   saveAll: function(alldata) {
91 91   console.log("saveAll");
92 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);
108 - });
109 - }, function(jqXHR) {
110 - Ember.run(function() {
111 - reject(jqXHR);
112 - });
101 +
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);
110 + Ember.run(function() {
111 + resolve(data);
112 + });
113 + }, function(jqXHR) {
114 + console.error("SaveAll error:", jqXHR);
115 + Ember.run(function() {
116 + reject(jqXHR);
117 + });
118 + });
119 + });
120 + }
113 113   });
114 -});
115 115  
116 -
117 - // Register the adapter
118 - Todos.ApplicationAdapter.reopen({
119 - namespace: 'api'
120 - });
121 -
122 122   // Routing
123 123   Todos.Router.map(function() {
124 124   this.resource('todos', { path: '' }, function() {
... ... @@ -215,6 +215,8 @@
215 215   var title = this.get('newTitle');
216 216   if (!title || !title.trim()) { return; }
217 217  
219 + console.log("Creating new todo with title:", title);
220 +
218 218   // Create the new Todo model
219 219   var todo = this.store.createRecord('todo', {
220 220   title: title,
... ... @@ -227,11 +227,15 @@
227 227   this.set('newTitle', '');
228 228  
229 229   // Save the new model
230 - todo.save().then(function() {
233 + todo.save().then(function(savedTodo) {
234 + console.log("Todo saved successfully:", savedTodo);
231 231   // Force a refresh of the list after saving
232 232   Ember.run.later(function() {
237 + console.log("Refreshing todo list");
233 233   Todos.store.find('todo');
234 234   }, 100);
240 + }, function(error) {
241 + console.error("Failed to save todo:", error);
235 235   });
236 236   },
237 237