sdc_client 0.57.12 → 0.57.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.idea/workspace.xml +11 -20
- package/dist/index.js +7 -7
- package/dist/ugly.index.js +1 -1
- package/package.json +2 -2
- package/src/simpleDomControl/AbstractSDC.js +4 -4
- package/src/simpleDomControl/sdc_controller.js +69 -17
- package/src/simpleDomControl/sdc_dom_events.js +1 -1
- package/src/simpleDomControl/sdc_main.js +361 -367
- package/src/simpleDomControl/sdc_socket.js +7 -4
- package/src/simpleDomControl/sdc_utils.js +1 -1
- package/src/simpleDomControl/sdc_view.js +364 -311
- package/test/dist.test.js +1 -1
- package/test/view.test.js +18 -1
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
uploadFileFormData,
|
|
6
|
-
promiseDummyFactory
|
|
2
|
+
camelCaseToTagName,
|
|
3
|
+
getBody,
|
|
4
|
+
uploadFileFormData,
|
|
7
5
|
} from "./sdc_utils.js";
|
|
8
6
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
replaceTagElementsInContainer,
|
|
8
|
+
reloadHTMLController,
|
|
9
|
+
DATA_CONTROLLER_KEY,
|
|
10
|
+
CONTROLLER_CLASS, getController, cleanCache, refresh
|
|
13
11
|
} from "./sdc_view.js";
|
|
14
12
|
import {AbstractSDC} from "./AbstractSDC.js";
|
|
15
|
-
import {
|
|
16
|
-
|
|
13
|
+
import {
|
|
14
|
+
Global,
|
|
15
|
+
controllerList,
|
|
16
|
+
tagList,
|
|
17
|
+
resetChildren,
|
|
18
|
+
updateEventAndTriggerOnRefresh,
|
|
19
|
+
prepareRefreshProcess
|
|
20
|
+
} from "./sdc_controller.js";
|
|
21
|
+
import {initEvents, STD_EVENT_LIST, windowEventHandler} from "./sdc_dom_events.js";
|
|
17
22
|
import {reconcile} from "./sdc_view.js";
|
|
18
23
|
import {trigger} from "./sdc_events.js";
|
|
19
24
|
import {isConnected, close} from "./sdc_server_call.js";
|
|
@@ -21,389 +26,378 @@ import {isConnected, close} from "./sdc_server_call.js";
|
|
|
21
26
|
const PROPERTIES_UPDATE = {'classname': 'class'}
|
|
22
27
|
|
|
23
28
|
let sdcDomFragment = function (element, props) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
let $new_elem, is_self = false;
|
|
30
|
+
if (typeof element === 'string') {
|
|
31
|
+
$new_elem = $(document.createElement(element));
|
|
32
|
+
} else {
|
|
33
|
+
const tagName = `this.${element.name}`;
|
|
34
|
+
$new_elem = $(document.createElement(tagName));
|
|
35
|
+
$new_elem.data('handler', element);
|
|
36
|
+
is_self = true
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if (props) {
|
|
41
|
+
Object.entries(props).forEach(([k, v]) => {
|
|
42
|
+
if (k.startsWith('on')) {
|
|
43
|
+
$new_elem[0].addEventListener(k.substring(2).toLowerCase(), v);
|
|
44
|
+
} else {
|
|
45
|
+
if (PROPERTIES_UPDATE[k.toLowerCase()]) {
|
|
46
|
+
k = PROPERTIES_UPDATE[k.toLowerCase()];
|
|
47
|
+
}
|
|
48
|
+
$new_elem[0].setAttribute(k, v);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
47
52
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
53
|
+
if (is_self) {
|
|
54
|
+
$new_elem.addClass('_bind_to_update_handler _with_handler');
|
|
55
|
+
}
|
|
51
56
|
|
|
52
|
-
|
|
57
|
+
return $new_elem;
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
window.sdcDom = function (tagName, props, ...children) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
if (!tagName) {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
const $new_elem = sdcDomFragment(tagName, props);
|
|
65
|
+
for (const c of children) {
|
|
66
|
+
$new_elem.append(c);
|
|
67
|
+
}
|
|
68
|
+
return $new_elem;
|
|
64
69
|
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
export let app = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
app.updateJquery();
|
|
93
|
-
} else {
|
|
94
|
-
close();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
isConnected();
|
|
98
|
-
|
|
99
|
-
initEvents();
|
|
100
|
-
|
|
101
|
-
app.rootController = app.rootController || new AbstractSDC();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
app.tagNames = tagList();
|
|
105
|
-
|
|
106
|
-
for (let [tag, controller] of Object.entries(app.Global)) {
|
|
107
|
-
if (!controller.$container) Global[tag].$container = getBody();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return replaceTagElementsInContainer(app.tagNames, getBody(), app.rootController);
|
|
111
|
-
},
|
|
112
|
-
|
|
113
|
-
updateJquery: () => {
|
|
114
|
-
$.fn.safeReplace = function ($elem) {
|
|
115
|
-
return app.safeReplace($(this), $elem);
|
|
116
|
-
}
|
|
117
|
-
$.fn.safeEmpty = function () {
|
|
118
|
-
return app.safeEmpty($(this));
|
|
119
|
-
}
|
|
120
|
-
$.fn.safeRemove = function () {
|
|
121
|
-
return app.safeRemove($(this));
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
|
|
125
|
-
controllerToTag: (Controller) => {
|
|
126
|
-
let tagName = camelCaseToTagName(Controller.name);
|
|
127
|
-
return tagName.replace(/-controller$/, '');
|
|
128
|
-
},
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
*
|
|
132
|
-
* @param {AbstractSDC} Controller
|
|
133
|
-
*/
|
|
134
|
-
registerGlobal: (Controller) => {
|
|
135
|
-
let tagName = app.controllerToTag(Controller);
|
|
136
|
-
let globalController = new Controller();
|
|
137
|
-
controllerList[tagName] = [globalController, []];
|
|
138
|
-
globalController._tagName = tagName;
|
|
139
|
-
window[tagNameToCamelCase(tagName)] = Global[tagNameToCamelCase(tagName)] = globalController;
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
cleanCache: () => {
|
|
143
|
-
cleanCache();
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
*
|
|
148
|
-
* @param {AbstractSDC} Controller
|
|
149
|
-
*/
|
|
150
|
-
register: (Controller) => {
|
|
151
|
-
let tagName = app.controllerToTag(Controller);
|
|
152
|
-
controllerList[tagName] = [Controller, []];
|
|
153
|
-
Controller.prototype._tagName = tagName;
|
|
154
|
-
return {
|
|
155
|
-
/**
|
|
156
|
-
*
|
|
157
|
-
* @param {Array<string>} mixins Controller tag names
|
|
158
|
-
*/
|
|
159
|
-
addMixin: (...mixins) => {
|
|
160
|
-
for (let mixin of mixins) {
|
|
161
|
-
let mixinName;
|
|
162
|
-
if (typeof mixin === "string") {
|
|
163
|
-
mixinName = camelCaseToTagName(mixin);
|
|
164
|
-
} else if (mixin) {
|
|
165
|
-
mixinName = app.controllerToTag(mixin)
|
|
166
|
-
}
|
|
167
|
-
controllerList[tagName][1].push(mixinName);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
*
|
|
175
|
-
* @param {AbstractSDC} controller
|
|
176
|
-
* @param {string} url
|
|
177
|
-
* @param {object} args
|
|
178
|
-
* @return {Promise}
|
|
179
|
-
*/
|
|
180
|
-
post: (controller, url, args) => {
|
|
181
|
-
if (!args) {
|
|
182
|
-
args = {};
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
args.CSRF_TOKEN = app.CSRF_TOKEN;
|
|
186
|
-
return app.ajax(controller, url, params, $.post);
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
*
|
|
191
|
-
* @param {AbstractSDC} controller
|
|
192
|
-
* @param {string} url
|
|
193
|
-
* @param {object} args
|
|
194
|
-
* @return {Promise}
|
|
195
|
-
*/
|
|
196
|
-
get: (controller, url, args) => {
|
|
197
|
-
return app.ajax(controller, url, args, $.get);
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
*
|
|
202
|
-
* @param {AbstractSDC} controller
|
|
203
|
-
* @param {string} url
|
|
204
|
-
* @param {object} args
|
|
205
|
-
* @param {function} method $.get or $.post
|
|
206
|
-
* @return {Promise}
|
|
207
|
-
*/
|
|
208
|
-
ajax: (controller, url, args, method) => {
|
|
209
|
-
if (!args) {
|
|
210
|
-
args = {};
|
|
73
|
+
CSRF_TOKEN: window.CSRF_TOKEN || '',
|
|
74
|
+
LANGUAGE_CODE: window.LANGUAGE_CODE || 'en',
|
|
75
|
+
DEBUG: window.DEBUG || false,
|
|
76
|
+
VERSION: window.VERSION || '0.0',
|
|
77
|
+
tagNames: [],
|
|
78
|
+
Global: Global,
|
|
79
|
+
rootController: null,
|
|
80
|
+
globalRootController: null,
|
|
81
|
+
_isInit: false,
|
|
82
|
+
_origin_trigger: null,
|
|
83
|
+
_globalControllerClasses: [],
|
|
84
|
+
|
|
85
|
+
init_sdc: () => {
|
|
86
|
+
if (!app._isInit) {
|
|
87
|
+
app._isInit = true;
|
|
88
|
+
if (!app._origin_trigger) {
|
|
89
|
+
app._origin_trigger = $.fn.trigger;
|
|
90
|
+
$.fn.trigger = function (event) {
|
|
91
|
+
const ev_type = {}.hasOwnProperty.call(event, "type") ? event.type : event;
|
|
92
|
+
if (!STD_EVENT_LIST.includes(ev_type)) {
|
|
93
|
+
STD_EVENT_LIST.push(ev_type);
|
|
94
|
+
$(window).on(ev_type, windowEventHandler);
|
|
95
|
+
}
|
|
96
|
+
return app._origin_trigger.call(this, event);
|
|
211
97
|
}
|
|
212
98
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
return method(url, args).then((a, b, c) => {
|
|
218
|
-
resolve(a, b, c);
|
|
219
|
-
if (a.status === 'redirect') {
|
|
220
|
-
trigger('onNavLink', a['url-link']);
|
|
221
|
-
} else {
|
|
222
|
-
p.then(() => {
|
|
223
|
-
app.refresh(controller.$container);
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}).catch(reject);
|
|
227
|
-
});
|
|
99
|
+
app.updateJquery();
|
|
100
|
+
} else {
|
|
101
|
+
close();
|
|
102
|
+
}
|
|
228
103
|
|
|
229
|
-
|
|
230
|
-
},
|
|
104
|
+
isConnected();
|
|
231
105
|
|
|
232
|
-
|
|
233
|
-
let formData = new FormData(form);
|
|
234
|
-
const redirector = (a) => {
|
|
235
|
-
if (a['url-link']) {
|
|
236
|
-
trigger('onNavLink', a['url-link']);
|
|
237
|
-
} else {
|
|
238
|
-
window.location.href = a['url'];
|
|
239
|
-
}
|
|
106
|
+
initEvents();
|
|
240
107
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
uploadFileFormData(formData, (url || form.action), (method || form.method))
|
|
245
|
-
.then((a, b, c) => {
|
|
246
|
-
resolve(a, b, c);
|
|
247
|
-
if (a.status === 'redirect') {
|
|
248
|
-
redirector(a);
|
|
249
|
-
} else {
|
|
250
|
-
p.then(() => {
|
|
251
|
-
app.refresh(controller.$container);
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
})
|
|
255
|
-
.catch((a, b, c) => {
|
|
256
|
-
if (a.status === 301) {
|
|
257
|
-
a = a.responseJSON;
|
|
258
|
-
redirector(a);
|
|
259
|
-
resolve(a, b, c);
|
|
260
|
-
} else {
|
|
261
|
-
reject(a, b, c);
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
});
|
|
108
|
+
app.rootController = app.rootController || new AbstractSDC();
|
|
109
|
+
app.globalRootController = app.globalRootController || new AbstractSDC();
|
|
110
|
+
}
|
|
265
111
|
|
|
266
|
-
|
|
112
|
+
app.tagNames = tagList();
|
|
267
113
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
.then(resolve).catch(reject);
|
|
274
|
-
});
|
|
275
|
-
},
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
*
|
|
279
|
-
* @param {jquery} $elem
|
|
280
|
-
* @return {AbstractSDC}
|
|
281
|
-
*/
|
|
282
|
-
getController: ($elem) => getController($elem),
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* safeEmpty removes all content of a dom
|
|
286
|
-
* and deletes all child controller safely.
|
|
287
|
-
*
|
|
288
|
-
* @param $elem - jQuery DOM container to be emptyed
|
|
289
|
-
*/
|
|
290
|
-
safeEmpty: ($elem) => {
|
|
291
|
-
let $children = $elem.children();
|
|
292
|
-
$children.each(function (_, element) {
|
|
293
|
-
let $element = $(element);
|
|
294
|
-
app.safeRemove($element);
|
|
295
|
-
});
|
|
114
|
+
const $globalDiv = $('<div></div>');
|
|
115
|
+
Global.forEach((tagName) => {
|
|
116
|
+
const ControllerClass = controllerList[tagName][0];
|
|
117
|
+
$globalDiv.append(`<${ControllerClass.prototype._tagName}></${ControllerClass.prototype._tagName}>`);
|
|
118
|
+
});
|
|
296
119
|
|
|
297
|
-
|
|
298
|
-
},
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* safeReplace removes all content of a dom
|
|
302
|
-
* and deletes all child controller safely.
|
|
303
|
-
*
|
|
304
|
-
* @param $elem - jQuery DOM to be repleaced
|
|
305
|
-
* @param $new - jQuery new DOM container
|
|
306
|
-
*/
|
|
307
|
-
safeReplace: ($elem, $new) => {
|
|
308
|
-
$new.insertBefore($elem);
|
|
309
|
-
return app.safeRemove($elem);
|
|
310
|
-
},
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* safeRemove removes a dom and deletes all child controller safely.
|
|
315
|
-
*
|
|
316
|
-
* @param $elem - jQuery Dom
|
|
317
|
-
*/
|
|
318
|
-
safeRemove: ($elem) => {
|
|
319
|
-
$elem.each(function () {
|
|
320
|
-
let $this = $(this);
|
|
321
|
-
if ($this.data(`${DATA_CONTROLLER_KEY}`)) {
|
|
322
|
-
$this.data(`${DATA_CONTROLLER_KEY}`).remove();
|
|
323
|
-
}
|
|
324
|
-
});
|
|
120
|
+
const {refreshProcess} = prepareRefreshProcess(null, app.rootController);
|
|
325
121
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
122
|
+
return replaceTagElementsInContainer(app.tagNames, $globalDiv, app.globalRootController, refreshProcess).then(() => {
|
|
123
|
+
return replaceTagElementsInContainer(app.tagNames, getBody(), app.rootController, refreshProcess).then((res) => {
|
|
124
|
+
updateEventAndTriggerOnRefresh(refreshProcess);
|
|
125
|
+
return res;
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
},
|
|
330
129
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
130
|
+
updateJquery: () => {
|
|
131
|
+
$.fn.safeReplace = function ($elem) {
|
|
132
|
+
return app.safeReplace($(this), $elem);
|
|
133
|
+
}
|
|
134
|
+
$.fn.safeEmpty = function () {
|
|
135
|
+
return app.safeEmpty($(this));
|
|
136
|
+
}
|
|
137
|
+
$.fn.safeRemove = function () {
|
|
138
|
+
return app.safeRemove($(this));
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
controllerToTag: (Controller) => {
|
|
143
|
+
let tagName = camelCaseToTagName(Controller.name);
|
|
144
|
+
return tagName.replace(/-controller$/, '');
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
*
|
|
149
|
+
* @param {AbstractSDC} Controller
|
|
150
|
+
*/
|
|
151
|
+
registerGlobal: (Controller) => {
|
|
152
|
+
app.register(Controller);
|
|
153
|
+
let tagName = Controller.prototype._tagName;
|
|
154
|
+
Global.push(tagName);
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
cleanCache: () => {
|
|
158
|
+
cleanCache();
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
*
|
|
163
|
+
* @param {AbstractSDC} Controller
|
|
164
|
+
*/
|
|
165
|
+
register: (Controller) => {
|
|
166
|
+
let tagName = app.controllerToTag(Controller);
|
|
167
|
+
controllerList[tagName] = [Controller, []];
|
|
168
|
+
Controller.prototype._tagName = tagName;
|
|
169
|
+
return {
|
|
170
|
+
/**
|
|
171
|
+
*
|
|
172
|
+
* @param {Array<string>} mixins Controller tag names
|
|
173
|
+
*/
|
|
174
|
+
addMixin: (...mixins) => {
|
|
175
|
+
for (let mixin of mixins) {
|
|
176
|
+
let mixinName;
|
|
177
|
+
if (typeof mixin === "string") {
|
|
178
|
+
mixinName = camelCaseToTagName(mixin);
|
|
179
|
+
} else if (mixin) {
|
|
180
|
+
mixinName = app.controllerToTag(mixin)
|
|
181
|
+
}
|
|
182
|
+
controllerList[tagName][1].push(mixinName);
|
|
360
183
|
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
*
|
|
190
|
+
* @param {AbstractSDC} controller
|
|
191
|
+
* @param {string} url
|
|
192
|
+
* @param {object} args
|
|
193
|
+
* @return {Promise}
|
|
194
|
+
*/
|
|
195
|
+
post: (controller, url, args) => {
|
|
196
|
+
if (!args) {
|
|
197
|
+
args = {};
|
|
198
|
+
}
|
|
361
199
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
200
|
+
args.CSRF_TOKEN = app.CSRF_TOKEN;
|
|
201
|
+
return app.ajax(controller, url, params, $.post);
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
*
|
|
206
|
+
* @param {AbstractSDC} controller
|
|
207
|
+
* @param {string} url
|
|
208
|
+
* @param {object} args
|
|
209
|
+
* @return {Promise}
|
|
210
|
+
*/
|
|
211
|
+
get: (controller, url, args) => {
|
|
212
|
+
return app.ajax(controller, url, args, $.get);
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
*
|
|
217
|
+
* @param {AbstractSDC} controller
|
|
218
|
+
* @param {string} url
|
|
219
|
+
* @param {object} args
|
|
220
|
+
* @param {function} method $.get or $.post
|
|
221
|
+
* @return {Promise}
|
|
222
|
+
*/
|
|
223
|
+
ajax: (controller, url, args, method) => {
|
|
224
|
+
if (!args) {
|
|
225
|
+
args = {};
|
|
226
|
+
}
|
|
369
227
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
228
|
+
args.VERSION = app.VERSION;
|
|
229
|
+
args._method = args._method || 'api';
|
|
230
|
+
|
|
231
|
+
const p = new Promise((resolve, reject) => {
|
|
232
|
+
return method(url, args).then((a, b, c) => {
|
|
233
|
+
resolve(a, b, c);
|
|
234
|
+
if (a.status === 'redirect') {
|
|
235
|
+
trigger('onNavLink', a['url-link']);
|
|
236
|
+
} else {
|
|
237
|
+
p.then(() => {
|
|
238
|
+
app.refresh(controller.$container);
|
|
239
|
+
});
|
|
382
240
|
}
|
|
241
|
+
}).catch(reject);
|
|
242
|
+
});
|
|
383
243
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
244
|
+
return p;
|
|
245
|
+
},
|
|
387
246
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
247
|
+
submitFormAndUpdateView: (controller, form, url, method) => {
|
|
248
|
+
let formData = new FormData(form);
|
|
249
|
+
const redirector = (a) => {
|
|
250
|
+
if (a['url-link']) {
|
|
251
|
+
trigger('onNavLink', a['url-link']);
|
|
252
|
+
} else {
|
|
253
|
+
window.location.href = a['url'];
|
|
254
|
+
}
|
|
395
255
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
return replaceTagElementsInContainer(app.tagNames, $dom, leafController).then(() => {
|
|
399
|
-
reloadMethodHTML(leafController, $dom).then(() => {
|
|
400
|
-
for (let con of controllerList) {
|
|
401
|
-
setControllerEvents(con);
|
|
402
|
-
}
|
|
256
|
+
}
|
|
403
257
|
|
|
404
|
-
|
|
258
|
+
const p = new Promise((resolve, reject) => {
|
|
259
|
+
uploadFileFormData(formData, (url || form.action), (method || form.method))
|
|
260
|
+
.then((a, b, c) => {
|
|
261
|
+
resolve(a, b, c);
|
|
262
|
+
if (a.status === 'redirect') {
|
|
263
|
+
redirector(a);
|
|
264
|
+
} else {
|
|
265
|
+
p.then(() => {
|
|
266
|
+
app.refresh(controller.$container, controller);
|
|
405
267
|
});
|
|
406
|
-
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
.catch((a, b, c) => {
|
|
271
|
+
if (a.status === 301) {
|
|
272
|
+
a = a.responseJSON;
|
|
273
|
+
redirector(a);
|
|
274
|
+
resolve(a, b, c);
|
|
275
|
+
} else {
|
|
276
|
+
reject(a, b, c);
|
|
277
|
+
}
|
|
407
278
|
});
|
|
408
|
-
}
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
return p;
|
|
282
|
+
|
|
283
|
+
},
|
|
284
|
+
|
|
285
|
+
submitForm: (form, url, method) => {
|
|
286
|
+
let formData = new FormData(form);
|
|
287
|
+
return new Promise((resolve, reject) => {
|
|
288
|
+
uploadFileFormData(formData, (url || form.action), (method || form.method))
|
|
289
|
+
.then(resolve).catch(reject);
|
|
290
|
+
});
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
*
|
|
295
|
+
* @param {jquery} $elem
|
|
296
|
+
* @return {AbstractSDC}
|
|
297
|
+
*/
|
|
298
|
+
getController: ($elem) => getController($elem),
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* safeEmpty removes all content of a dom
|
|
302
|
+
* and deletes all child controller safely.
|
|
303
|
+
*
|
|
304
|
+
* @param $elem - jQuery DOM container to be emptyed
|
|
305
|
+
*/
|
|
306
|
+
safeEmpty: ($elem) => {
|
|
307
|
+
let $children = $elem.children();
|
|
308
|
+
$children.each(function (_, element) {
|
|
309
|
+
let $element = $(element);
|
|
310
|
+
app.safeRemove($element);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
return $elem;
|
|
314
|
+
},
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* safeReplace removes all content of a dom
|
|
318
|
+
* and deletes all child controller safely.
|
|
319
|
+
*
|
|
320
|
+
* @param $elem - jQuery DOM to be repleaced
|
|
321
|
+
* @param $new - jQuery new DOM container
|
|
322
|
+
*/
|
|
323
|
+
safeReplace: ($elem, $new) => {
|
|
324
|
+
$new.insertBefore($elem);
|
|
325
|
+
return app.safeRemove($elem);
|
|
326
|
+
},
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* safeRemove removes a dom and deletes all child controller safely.
|
|
331
|
+
*
|
|
332
|
+
* @param $elem - jQuery Dom
|
|
333
|
+
*/
|
|
334
|
+
safeRemove: ($elem) => {
|
|
335
|
+
$elem.each(function () {
|
|
336
|
+
let $this = $(this);
|
|
337
|
+
if ($this.data(`${DATA_CONTROLLER_KEY}`)) {
|
|
338
|
+
$this.data(`${DATA_CONTROLLER_KEY}`).remove();
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
$elem.find(`.${CONTROLLER_CLASS}`).each(function () {
|
|
343
|
+
const controller = $(this).data(`${DATA_CONTROLLER_KEY}`);
|
|
344
|
+
controller && controller.remove();
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
return $elem.remove();
|
|
348
|
+
},
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
*
|
|
352
|
+
* @param {AbstractSDC} controller
|
|
353
|
+
* @return {Promise<jQuery>}
|
|
354
|
+
*/
|
|
355
|
+
reloadController: (controller) => {
|
|
356
|
+
return reloadHTMLController(controller).then((html) => {
|
|
357
|
+
let $html = $(html);
|
|
358
|
+
return app.reconcile(controller, $html);
|
|
359
|
+
});
|
|
360
|
+
},
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
*
|
|
365
|
+
* @param {AbstractSDC} controller
|
|
366
|
+
* @param {jquery} $virtualNode
|
|
367
|
+
* @param {jquery} $realNode
|
|
368
|
+
* @param {Object} process - Process object containing the refresh process
|
|
369
|
+
*/
|
|
370
|
+
reconcile: (controller, $virtualNode, $realNode = null, process = null) => {
|
|
371
|
+
if (!$realNode) {
|
|
372
|
+
let $temp = controller.$container.clone().empty();
|
|
373
|
+
$temp.data(DATA_CONTROLLER_KEY, null);
|
|
374
|
+
$temp.removeClass(CONTROLLER_CLASS);
|
|
375
|
+
$temp.append($virtualNode);
|
|
376
|
+
$virtualNode = $temp;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
$realNode = $realNode ?? controller.$container;
|
|
380
|
+
|
|
381
|
+
const {refreshProcess, isRunningProcess} = prepareRefreshProcess(process, controller);
|
|
382
|
+
|
|
383
|
+
return refresh($virtualNode, controller, refreshProcess).then(() => {
|
|
384
|
+
reconcile($virtualNode, $realNode);
|
|
385
|
+
resetChildren(controller);
|
|
386
|
+
if (!isRunningProcess) {
|
|
387
|
+
updateEventAndTriggerOnRefresh(refreshProcess);
|
|
388
|
+
}
|
|
389
|
+
return controller;
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
},
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
*
|
|
396
|
+
* @param {jquery} $dom
|
|
397
|
+
* @param {AbstractSDC} leafController
|
|
398
|
+
* @return {Promise<void>}
|
|
399
|
+
*/
|
|
400
|
+
refresh: ($dom, leafController) => {
|
|
401
|
+
return refresh($dom, leafController);
|
|
402
|
+
},
|
|
409
403
|
};
|