Skip to content

Commit 5afe7e5

Browse files
committed
WIP: move ajax related code to srr/ folder
1 parent bc59146 commit 5afe7e5

20 files changed

+1427
-1339
lines changed

src/ajax.js

Lines changed: 0 additions & 1129 deletions
This file was deleted.

src/bundle.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import $ from 'jquery';
2-
import {ajax} from './ajax.js';
2+
import {ajax} from './ssr/ajax.js';
3+
4+
export * from './ssr/ajax.js';
5+
export * from './ssr/action.js';
6+
export * from './ssr/destroy.js';
7+
export * from './ssr/dispatcher.js';
8+
export * from './ssr/event.js';
9+
export * from './ssr/form.js';
10+
export * from './ssr/handle.js';
11+
export * from './ssr/overlay.js';
12+
export * from './ssr/parser.js';
13+
export * from './ssr/path.js';
14+
export * from './ssr/util.js';
315

4-
export * from './ajax.js';
516
export * from './clock.js';
617
export * from './events.js';
718
export * from './form.js';

src/overlay.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
set_default,
66
uuid4
77
} from './utils.js';
8-
import {ajax_destroy} from './ajaxdestroy.js';
8+
import {ajax_destroy} from './ssr/destroy.js';
99

1010
export class Overlay extends Events {
1111

src/ssr/action.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import {show_error} from '../overlay.js';
2+
import {
3+
parse_url,
4+
set_default
5+
} from '../utils.js';
6+
import {AjaxOperation} from './util.js';
7+
8+
9+
/**
10+
* Handle for action operation.
11+
*/
12+
export class AjaxAction extends AjaxOperation {
13+
14+
constructor(opts) {
15+
set_default(opts, 'event', 'on_action');
16+
super(opts);
17+
this.spinner = opts.spinner;
18+
this._handle = opts.handle;
19+
this._request = opts.request;
20+
}
21+
22+
execute(opts) {
23+
opts.success = this.complete.bind(this);
24+
this.request(opts);
25+
}
26+
27+
request(opts) {
28+
opts.params['ajax.action'] = opts.name;
29+
opts.params['ajax.mode'] = opts.mode;
30+
opts.params['ajax.selector'] = opts.selector;
31+
this._request.execute({
32+
url: parse_url(opts.url) + '/ajaxaction',
33+
type: 'json',
34+
params: opts.params,
35+
success: opts.success
36+
});
37+
}
38+
39+
complete(data) {
40+
if (!data) {
41+
show_error('Empty Response');
42+
this.spinner.hide();
43+
} else {
44+
this._handle.update(data);
45+
this._handle.next(data.continuation);
46+
}
47+
}
48+
49+
handle(inst, opts) {
50+
let target = opts.target,
51+
action = opts.action;
52+
for (let action_ of this.parse_definition(action)) {
53+
let defs = action_.split(':');
54+
this.execute({
55+
name: defs[0],
56+
selector: defs[1],
57+
mode: defs[2],
58+
url: target.url,
59+
params: target.params
60+
});
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)