Skip to content

Commit 5cb5250

Browse files
committed
fix: update crud functions to receive an array of objects as the response
1 parent b4c85a4 commit 5cb5250

File tree

2 files changed

+6
-759
lines changed

2 files changed

+6
-759
lines changed

test_files/CoCreate-action.js

Lines changed: 5 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
// -8
2-
const CoCreateAction = {
3-
attribute: 'actions',
4-
actions: {},
5-
selectedStage: [],
6-
stageIndex: 0,
7-
selectedElement: null,
8-
9-
completedEventName: 'completedEvent',
1+
2+
const CoCreateTest = {
103

114
/**
125
* @value_start
@@ -17,109 +10,9 @@ const CoCreateAction = {
1710
init: function(container) {
1811

1912
const __container = container || document
20-
if (!__container.querySelectorAll) {
21-
return;
22-
}
23-
24-
let buttons = __container.querySelectorAll("[actions]");
25-
26-
for (let i = 0; i < buttons.length; i++) {
27-
this.actionButtonEvent(buttons[i]);
28-
}
29-
},
30-
31-
actionButtonEvent: function(btn) {
32-
const _this = this;
33-
let checkActions = btn.getAttribute('actions') || "";
34-
checkActions = checkActions.replace(/\s/g, '').split(',');
35-
36-
if (checkActions.length == 0) {
37-
return;
38-
}
39-
40-
btn.addEventListener('click', function(event) {
41-
let actions = this.getAttribute(_this.attribute) || "";
42-
actions = actions.replace(/\s/g, '').split(',');
43-
_this.stageIndex = 0;
44-
_this.selectedStage = actions;
45-
46-
//. run function
47-
_this.selectedElement = btn;
48-
_this.__runActionFunc();
49-
50-
})
51-
},
52-
53-
/**
54-
* key: string
55-
* runFunc: function
56-
* instance: object
57-
* endEvent: string
58-
**/
59-
registerEvent: function(key, runFunc, instance, endEvent) {
60-
if (this.actions[key]) {
61-
return;
62-
}
63-
64-
this.actions[key] = {
65-
key: key,
66-
runFunc: runFunc,
67-
instance: instance || window,
68-
endEvent: endEvent
69-
}
70-
//. register events
71-
72-
for (let __key in this.actions) {
73-
if (__key != key && this.actions[__key]['endEvent'] === endEvent) {
74-
return;
75-
}
76-
}
77-
78-
//. register events
79-
const _this = this;
80-
document.addEventListener(endEvent, function(e) {
81-
_this.__nextAction(endEvent)
82-
});
83-
},
84-
85-
__runActionFunc: function() {
86-
87-
if (this.stageIndex >= this.selectedStage.length) {
88-
89-
//. if latest case, it will be run aTag
90-
if (this.stageIndex == this.selectedStage.length) {
91-
this.__runAtag(this.selectedElement);
92-
}
93-
return;
94-
}
95-
96-
const key = this.selectedStage[this.stageIndex];
97-
//. run function
98-
const action = this.actions[key];
99-
if (action && action.runFunc) {
100-
action.runFunc.call(action.instance, this.selectedElement);
101-
}
102-
},
103-
104-
__nextAction: function(eventName) {
105-
const key = this.selectedStage[this.stageIndex];
106-
if (!key) {
107-
return ;
108-
}
109-
if (eventName !== this.actions[key].endEvent) {
110-
return;
111-
}
112-
this.stageIndex ++;
113-
this.__runActionFunc();
114-
},
115-
116-
__runAtag: function(button) {
117-
var aTag = button.querySelector('a');
118-
119-
if (aTag) {
120-
CoCreateLogic.runLink(aTag)
121-
}
13+
12214
}
15+
12316
}
12417

125-
CoCreateAction.init();
18+
CoCreateTest.init();

0 commit comments

Comments
 (0)