-
Notifications
You must be signed in to change notification settings - Fork 0
/
page-context.js
92 lines (79 loc) · 2.7 KB
/
page-context.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
var jsgui = require('jsgui3-html');
// Not extend the client page context would be best....
// This should be running in node.js
var stringify = jsgui.stringify, each = jsgui.each, arrayify = jsgui.arrayify, tof = jsgui.tof;
var filter_map_by_regex = jsgui.filter_map_by_regex;
var Class = jsgui.Class, Data_Object = jsgui.Data_Object;
var fp = jsgui.fp, is_defined = jsgui.is_defined;
var get_a_sig = jsgui.get_a_sig;
// Server_Static_Page_Context could help just by the more explicit name.
// Used for a single rendering.
// Will not be in the context of a request and response.
// Though could help with creating a response that can be reused.
// Think we should continue making the various (very specific) bits and pieces that represent all parts of the process.
//
// Need to find out what this one requires to put it in its own module.
class Server_Page_Context extends jsgui.Page_Context {
constructor(spec) {
spec = spec || {};
super(spec);
if (spec.req) {
this.req = spec.req;
this.request = spec.req;
} else if (spec.request) {
this.req = spec.request;
this.request = spec.request;
};
if (this.req && this.req.auth) {
this.auth = this.req.auth;
}
if (spec.res) {
this.res = spec.res;
this.response = spec.res;
} else if (spec.response) {
this.res = spec.response;
this.response = spec.response;
};
// would need to create the Page_Context with the server in the spec.
if (spec.server) {
this.server = spec.server;
}
this.selection_scope_count = 0;
// Perhaps things could be more sandboxed, so that controls don't get access to the resource pool by default.
// Maybe only a small number of controls should have access to this.
if (spec.pool) {
this.pool = spec.pool;
}
this.rendering_mode = spec.rendering_mode || 'html5';
// The item IDs could be handled here... use the local variable closure here.
var map_new_ids = {};
// and have the objects registered within the context too.
var map_objects = {};
var _get_new_typed_object_id = function(type_name) {
if (!is_defined(map_new_ids[type_name])) {
map_new_ids[type_name] = 0;
}
//if (!is_defined(map_new_ids[type_name]) {
// map_new_ids[type_name] = 0;
//}
var res = type_name + '_' + map_new_ids[type_name];
map_new_ids[type_name]++;
return res;
}
this.new_id = _get_new_typed_object_id;
}
'get_dtd'() {
if (this.rendering_mode === 'html5') {
return '<!DOCTYPE html>';
}
}
'new_selection_scope'(ctrl) {
let res = super.new_selection_scope(ctrl);
//var num = this.selection_scope_count++;
//ctrl.selection_scope = num;
ctrl._fields = ctrl._fields || {};
ctrl._fields.selection_scope = res.id;
return res;
}
};
module.exports = Server_Page_Context;