infopark_fiona7 1.5.5.5.1 → 1.6.1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +17 -0
- data/app/assets/javascripts/fiona7/task_list_dialog.js +2 -2
- data/app/assets/javascripts/fiona7/templates.js +1 -16
- data/app/assets/javascripts/fiona7/translations.js +22 -23
- data/app/assets/javascripts/fiona7_ui.js +56 -59
- data/app/assets/javascripts/scrivito_patches/base_obj_path.js +11 -5
- data/app/assets/javascripts/scrivito_patches/binary_request.js +53 -0
- data/app/assets/javascripts/scrivito_patches/client/ajax.js +122 -0
- data/app/assets/javascripts/scrivito_patches/{models/api → client}/basic_obj.js +150 -243
- data/app/assets/javascripts/scrivito_patches/client/cms_rest_api.js +209 -0
- data/app/assets/javascripts/scrivito_patches/components/sidebar/workspaces_panel.js +325 -0
- data/app/assets/javascripts/scrivito_patches/components/sidebar/workspaces_panel.js.jsx +294 -0
- data/app/assets/javascripts/scrivito_patches/models/{obj.js → legacy_obj.js} +27 -54
- data/app/assets/stylesheets/fiona7_ui.css.scss +2 -0
- data/app/controllers/fiona7/release_controller.rb +7 -6
- data/app/controllers/fiona7/sessions_controller.rb +10 -2
- data/app/controllers/fiona7/uploads_controller.rb +22 -0
- data/app/controllers/fiona7_login_page_controller.rb +3 -0
- data/app/controllers/scrivito/obj_class_controller.rb +28 -5
- data/app/views/fiona7/release/preview.html.erb +5 -38
- data/app/views/fiona7_login_page/index.html.erb +6 -0
- data/config/precedence_routes.rb +7 -7
- data/infopark_fiona7.gemspec +2 -2
- data/lib/fiona7/attribute_readers/number_as_string.rb +6 -1
- data/lib/fiona7/attribute_writers/binary_as_binary.rb +4 -2
- data/lib/fiona7/attribute_writers/binary_as_linklist.rb +4 -2
- data/lib/fiona7/builder/container_chain_builder.rb +50 -0
- data/lib/fiona7/builder/indirect_blob_builder.rb +7 -47
- data/lib/fiona7/builder/indirect_blob_builder_for_obj.rb +14 -0
- data/lib/fiona7/builder/lazy_blob_copier.rb +68 -14
- data/lib/fiona7/builder/obj_builder.rb +6 -32
- data/lib/fiona7/builder/obj_updater.rb +12 -4
- data/lib/fiona7/builder/widget_builder.rb +1 -1
- data/lib/fiona7/controllers/rest_api/blob_controller.rb +8 -2
- data/lib/fiona7/controllers/rest_api/obj_controller.rb +12 -8
- data/lib/fiona7/controllers/rest_api/workspace_controller.rb +6 -0
- data/lib/fiona7/engine.rb +49 -3
- data/lib/fiona7/forbidden_obj_classes.rb +14 -3
- data/lib/fiona7/linked_id_finder.rb +44 -0
- data/lib/fiona7/name_and_parent_from_path.rb +11 -0
- data/lib/fiona7/referenced_id_finder.rb +24 -0
- data/lib/fiona7/release_collector.rb +85 -0
- data/lib/fiona7/routers/rest_api.rb +2 -0
- data/lib/fiona7/scrivito_patches/cms_field_tag.rb +1 -0
- data/lib/fiona7/scrivito_patches/cms_rest_api.rb +16 -16
- data/lib/fiona7/scrivito_patches/cms_routing.rb +1 -0
- data/lib/fiona7/scrivito_patches/link_parser.rb +10 -7
- data/lib/fiona7/scrivito_patches/workspace.rb +0 -5
- data/lib/fiona7/super_id_finder.rb +68 -0
- data/lib/fiona7/super_object_finder.rb +5 -20
- data/lib/fiona7/temporary_uploader.rb +33 -0
- data/lib/fiona7/upload_path_selector.rb +17 -0
- data/lib/fiona7/verity_search_engine.rb +25 -12
- data/lib/fiona7/version.rb +1 -1
- metadata +23 -19
- data/app/assets/javascripts/fiona7/task_list_command.js +0 -15
- data/app/assets/javascripts/fiona7/task_list_menu_item.js +0 -30
- data/app/assets/javascripts/scrivito_patches/ajax.js +0 -225
- data/app/assets/javascripts/scrivito_patches/attribute_serializer.js +0 -259
- data/app/assets/javascripts/scrivito_patches/binary_utils.js +0 -33
- data/app/assets/javascripts/scrivito_patches/cms_rest_api.js +0 -371
- data/app/assets/javascripts/scrivito_patches/models/binary_field_element.js +0 -53
- data/app/assets/javascripts/scrivito_patches/obj_serializer.js +0 -91
- data/lib/fiona7/scrivito_patches/attribute_serializer.rb +0 -37
- data/lib/fiona7/scrivito_patches/model_library.rb +0 -19
- data/lib/fiona7/scrivito_patches/obj_params_parser.rb +0 -20
@@ -1,259 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
(function () {
|
4
|
-
scrivito.AttributeSerializer = {
|
5
|
-
serialize: function serialize(objClass, attributes) {
|
6
|
-
return _.mapObject(attributes, function (value, name) {
|
7
|
-
if (scrivito.Attribute.isSystemAttribute(name)) {
|
8
|
-
return value;
|
9
|
-
}
|
10
|
-
|
11
|
-
var attribute = objClass && objClass.attribute(name);
|
12
|
-
|
13
|
-
if (!attribute) {
|
14
|
-
throw new scrivito.ScrivitoError('Attribute "' + name + '" is not defined for obj class "' + objClass.name + '".');
|
15
|
-
}
|
16
|
-
|
17
|
-
return [serializeAttributeType(attribute.type, name), serializeAttributeValue(attribute, value, name)];
|
18
|
-
});
|
19
|
-
}
|
20
|
-
};
|
21
|
-
|
22
|
-
function serializeAttributeType(type, name) {
|
23
|
-
switch (type) {
|
24
|
-
case 'enum':
|
25
|
-
return 'string';
|
26
|
-
case 'float':
|
27
|
-
case 'integer':
|
28
|
-
return 'number';
|
29
|
-
case 'multienum':
|
30
|
-
return 'stringlist';
|
31
|
-
case 'binary':
|
32
|
-
case 'date':
|
33
|
-
case 'html':
|
34
|
-
case 'link':
|
35
|
-
case 'linklist':
|
36
|
-
case 'reference':
|
37
|
-
case 'referencelist':
|
38
|
-
case 'string':
|
39
|
-
case 'stringlist':
|
40
|
-
case 'widgetlist':
|
41
|
-
return type;
|
42
|
-
default:
|
43
|
-
throw new scrivito.ScrivitoError('Attribute "' + name + '" is of unsupported type "' + type + '".');
|
44
|
-
}
|
45
|
-
}
|
46
|
-
|
47
|
-
function serializeAttributeValue(attribute, value, name) {
|
48
|
-
if (value === null) {
|
49
|
-
return value;
|
50
|
-
}
|
51
|
-
|
52
|
-
switch (attribute.type) {
|
53
|
-
case 'binary':
|
54
|
-
return serializeBinaryAttributeValue(value, name);
|
55
|
-
case 'date':
|
56
|
-
return serializeDateAttributeValue(value, name);
|
57
|
-
case 'enum':
|
58
|
-
return serializeEnumAttributeValue(attribute, value, name);
|
59
|
-
case 'float':
|
60
|
-
return serializeFloatAttributeValue(value, name);
|
61
|
-
case 'integer':
|
62
|
-
return serializeIntegerAttributeValue(value, name);
|
63
|
-
case 'link':
|
64
|
-
return serializeLinkAttributeValue(value, name);
|
65
|
-
case 'linklist':
|
66
|
-
return serializeLinklistAttributeValue(value, name);
|
67
|
-
case 'multienum':
|
68
|
-
return serializeMultienumAttributeValue(attribute, value, name);
|
69
|
-
case 'reference':
|
70
|
-
return serializeReferenceAttributeValue(value, name);
|
71
|
-
case 'referencelist':
|
72
|
-
return serializeReferencelistAttributeValue(value, name);
|
73
|
-
case 'widgetlist':
|
74
|
-
return serializeWidgetlistAttributeValue(value);
|
75
|
-
default:
|
76
|
-
return value;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
function invalidAttributeValue(value, name, expected) {
|
81
|
-
throw new scrivito.ScrivitoError('Unexpected value ' + scrivito.prettyPrint(value) + ' for' + (' attribute "' + name + '". Expected: ' + expected));
|
82
|
-
}
|
83
|
-
|
84
|
-
function serializeBinaryAttributeValue(_x, _x2) {
|
85
|
-
var _again = true;
|
86
|
-
|
87
|
-
_function: while (_again) {
|
88
|
-
var value = _x,
|
89
|
-
name = _x2;
|
90
|
-
_again = false;
|
91
|
-
|
92
|
-
// -- PATCH BEGINS HERE --
|
93
|
-
if (value instanceof scrivito.Binary) {
|
94
|
-
return { id: value.id };
|
95
|
-
} else if (value === null) {
|
96
|
-
return null;
|
97
|
-
} else if (value instanceof scrivito.UploadedBlob) {
|
98
|
-
_x = value.copy();
|
99
|
-
_x2 = name;
|
100
|
-
_again = true;
|
101
|
-
continue _function;
|
102
|
-
} else if (value instanceof scrivito.FutureBinary) {
|
103
|
-
var futureBinary = value;
|
104
|
-
|
105
|
-
if (futureBinary.idToCopy) {
|
106
|
-
var blob = {
|
107
|
-
id_to_copy: futureBinary.idToCopy
|
108
|
-
};
|
109
|
-
if (futureBinary.filename) blob.filename = futureBinary.filename;
|
110
|
-
if (futureBinary.contentType) blob.content_type = futureBinary.contentType;
|
111
|
-
|
112
|
-
return blob;
|
113
|
-
} else if (futureBinary.source) {
|
114
|
-
return { blob_to_upload: futureBinary.source, filename: futureBinary.filename };
|
115
|
-
}
|
116
|
-
} else if (scrivito.BinaryUtils.isFile(value) || scrivito.BinaryUtils.isBlob(value)) {
|
117
|
-
return value;
|
118
|
-
} else if (value && typeof value === 'object' && value.id_to_copy) {
|
119
|
-
return value;
|
120
|
-
} else {
|
121
|
-
invalidAttributeValue(value, name, 'A Binary.');
|
122
|
-
}
|
123
|
-
// -- PATCH ENDS HERE --
|
124
|
-
}
|
125
|
-
}
|
126
|
-
|
127
|
-
function serializeDateAttributeValue(value, name) {
|
128
|
-
if (_.isDate(value)) {
|
129
|
-
return scrivito.types.formatDateToString(value);
|
130
|
-
}
|
131
|
-
if (scrivito.types.isValidDateString(value)) {
|
132
|
-
return value;
|
133
|
-
}
|
134
|
-
|
135
|
-
invalidAttributeValue(value, name, 'A Date.');
|
136
|
-
}
|
137
|
-
|
138
|
-
function serializeEnumAttributeValue(attribute, value, name) {
|
139
|
-
var validValues = attribute.validValues();
|
140
|
-
if (!_.contains(validValues, value)) {
|
141
|
-
var e = 'Valid attribute values are contained in its "validValues" array [' + validValues + '].';
|
142
|
-
invalidAttributeValue(value, name, e);
|
143
|
-
}
|
144
|
-
return value;
|
145
|
-
}
|
146
|
-
|
147
|
-
function serializeFloatAttributeValue(value, name) {
|
148
|
-
if (!scrivito.types.isValidFloat(value)) {
|
149
|
-
var invalidValue = value;
|
150
|
-
if (_.isNumber(value)) {
|
151
|
-
invalidValue = String(value);
|
152
|
-
}
|
153
|
-
invalidAttributeValue(invalidValue, name, 'A Number, that is #isFinite().');
|
154
|
-
}
|
155
|
-
return value;
|
156
|
-
}
|
157
|
-
|
158
|
-
function serializeIntegerAttributeValue(value, name) {
|
159
|
-
if (!scrivito.types.isValidInteger(value)) {
|
160
|
-
invalidAttributeValue(value, name, 'A Number, that is #isSafeInteger().');
|
161
|
-
}
|
162
|
-
return value;
|
163
|
-
}
|
164
|
-
|
165
|
-
function serializeLinkAttributeValue(value, name) {
|
166
|
-
if (!validLinkObject(value)) {
|
167
|
-
invalidAttributeValue(value, name, 'A scrivito.Link instance.');
|
168
|
-
}
|
169
|
-
|
170
|
-
return convertLinkToCmsApi(value);
|
171
|
-
}
|
172
|
-
|
173
|
-
function serializeLinklistAttributeValue(value, name) {
|
174
|
-
if (!Array.isArray(value) || !_.all(value, validLinkObject)) {
|
175
|
-
invalidAttributeValue(value, name, 'An array of scrivito.Link instances.');
|
176
|
-
}
|
177
|
-
|
178
|
-
return _.map(value, convertLinkToCmsApi);
|
179
|
-
}
|
180
|
-
|
181
|
-
function validLinkObject(value) {
|
182
|
-
if (value instanceof scrivito.Link) {
|
183
|
-
return true;
|
184
|
-
}
|
185
|
-
|
186
|
-
// check if value is backend compatible
|
187
|
-
if (!_.isObject(value)) {
|
188
|
-
return false;
|
189
|
-
}
|
190
|
-
var invalidKeys = _.without(_.keys(value), 'fragment', 'obj_id', 'query', 'target', 'title', 'url');
|
191
|
-
return _.isEmpty(invalidKeys);
|
192
|
-
}
|
193
|
-
|
194
|
-
function convertLinkToCmsApi(value) {
|
195
|
-
var backendLink = {
|
196
|
-
fragment: value.fragment,
|
197
|
-
query: value.query,
|
198
|
-
target: value.target,
|
199
|
-
title: value.title,
|
200
|
-
url: value.url
|
201
|
-
};
|
202
|
-
backendLink.obj_id = value.objId || value.obj_id;
|
203
|
-
|
204
|
-
return _.mapObject(backendLink, function (v) {
|
205
|
-
return v || null;
|
206
|
-
});
|
207
|
-
}
|
208
|
-
|
209
|
-
function serializeMultienumAttributeValue(attribute, value, name) {
|
210
|
-
var validValues = attribute.validValues();
|
211
|
-
var errorMessage = 'An array with values from ' + scrivito.prettyPrint(validValues) + '.';
|
212
|
-
|
213
|
-
if (!Array.isArray(value) || !_.all(value, _.isString)) {
|
214
|
-
invalidAttributeValue(value, name, errorMessage);
|
215
|
-
}
|
216
|
-
|
217
|
-
var forbiddenValues = _.difference(value, validValues);
|
218
|
-
if (forbiddenValues.length) {
|
219
|
-
var e = errorMessage + ' Forbidden values: ' + scrivito.prettyPrint(forbiddenValues) + '.';
|
220
|
-
invalidAttributeValue(value, name, e);
|
221
|
-
}
|
222
|
-
return value;
|
223
|
-
}
|
224
|
-
|
225
|
-
function serializeReferenceAttributeValue(value, name) {
|
226
|
-
if (!isValidReference(value)) {
|
227
|
-
invalidAttributeValue(value, name, 'A BasicObj or a String ID.');
|
228
|
-
}
|
229
|
-
return serializeSingleReferenceValue(value);
|
230
|
-
}
|
231
|
-
|
232
|
-
function serializeReferencelistAttributeValue(value, name) {
|
233
|
-
if (!isValidReferencelistValue(value)) {
|
234
|
-
invalidAttributeValue(value, name, 'An array with BasicObjs or String IDs.');
|
235
|
-
}
|
236
|
-
return _.map(value, serializeSingleReferenceValue);
|
237
|
-
}
|
238
|
-
|
239
|
-
function serializeSingleReferenceValue(value) {
|
240
|
-
if (value instanceof scrivito.BasicObj) {
|
241
|
-
return value.id;
|
242
|
-
}
|
243
|
-
return value;
|
244
|
-
}
|
245
|
-
|
246
|
-
function isValidReference(value) {
|
247
|
-
return _.isString(value) || _.isNumber(value) || value instanceof scrivito.BasicObj;
|
248
|
-
}
|
249
|
-
|
250
|
-
function isValidReferencelistValue(value) {
|
251
|
-
return _.isArray(value) && _.every(value, function (v) {
|
252
|
-
return isValidReference(v);
|
253
|
-
});
|
254
|
-
}
|
255
|
-
|
256
|
-
function serializeWidgetlistAttributeValue(value) {
|
257
|
-
return _.pluck(value, 'id');
|
258
|
-
}
|
259
|
-
})();
|
@@ -1,33 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
(function () {
|
4
|
-
scrivito.BinaryUtils = {
|
5
|
-
validateBinaryOptions: function validateBinaryOptions(options) {
|
6
|
-
if (_.has(options, 'filename') && !options.filename) {
|
7
|
-
throw new scrivito.ArgumentError('filename cannot be blank');
|
8
|
-
}
|
9
|
-
|
10
|
-
if (_.has(options, 'content_type') && !options.content_type) {
|
11
|
-
throw new scrivito.ArgumentError('content_type cannot be blank');
|
12
|
-
}
|
13
|
-
|
14
|
-
if (_.has(options, 'contentType') && !options.contentType) {
|
15
|
-
throw new scrivito.ArgumentError('contentType cannot be blank');
|
16
|
-
}
|
17
|
-
},
|
18
|
-
|
19
|
-
isBlob: function isBlob(obj) {
|
20
|
-
return !!obj && _.isNumber(obj.size) && _.isString(obj.type);
|
21
|
-
},
|
22
|
-
|
23
|
-
isFile: function isFile(obj) {
|
24
|
-
return this.isBlob(obj) && _.isDate(obj.lastModifiedDate) && _.isString(obj.name);
|
25
|
-
},
|
26
|
-
|
27
|
-
// -- PATCH BEGINS HERE --
|
28
|
-
isBlobWithName: function isBlobWithName(obj) {
|
29
|
-
return obj && typeof obj === 'object' && this.isBlob(obj.blob_to_upload);
|
30
|
-
}
|
31
|
-
};
|
32
|
-
})();
|
33
|
-
// -- PATCH ENDS HERE --
|
@@ -1,371 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
|
4
|
-
|
5
|
-
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
6
|
-
|
7
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
8
|
-
|
9
|
-
(function () {
|
10
|
-
var MIN_REQUEST_TIME = 5;
|
11
|
-
var DEFAULT_REQUEST_TIMEOUT = 120000; // <-- PATCH HERE
|
12
|
-
var backendEndpoint = undefined;
|
13
|
-
var tenant = undefined;
|
14
|
-
|
15
|
-
scrivito.CmsRestApi = {
|
16
|
-
init: function init(endpoint, initTenant) {
|
17
|
-
backendEndpoint = endpoint;
|
18
|
-
tenant = initTenant;
|
19
|
-
},
|
20
|
-
|
21
|
-
get: function get(path, requestParams) {
|
22
|
-
return fetch('GET', path, requestParams);
|
23
|
-
},
|
24
|
-
|
25
|
-
put: function put(path, requestParams) {
|
26
|
-
return fetch('PUT', path, requestParams);
|
27
|
-
},
|
28
|
-
|
29
|
-
post: function post(path, requestParams) {
|
30
|
-
return fetch('POST', path, requestParams);
|
31
|
-
},
|
32
|
-
|
33
|
-
'delete': function _delete(path) {
|
34
|
-
return fetch('DELETE', path);
|
35
|
-
}
|
36
|
-
};
|
37
|
-
|
38
|
-
var Timer = (function () {
|
39
|
-
function Timer() {
|
40
|
-
var timeout = arguments.length <= 0 || arguments[0] === undefined ? DEFAULT_REQUEST_TIMEOUT : arguments[0];
|
41
|
-
|
42
|
-
_classCallCheck(this, Timer);
|
43
|
-
|
44
|
-
this.timesOutAt = Date.now() + timeout;
|
45
|
-
}
|
46
|
-
|
47
|
-
_createClass(Timer, [{
|
48
|
-
key: 'timedOut',
|
49
|
-
value: function timedOut() {
|
50
|
-
return this.remainingTime() < MIN_REQUEST_TIME;
|
51
|
-
}
|
52
|
-
}, {
|
53
|
-
key: 'remainingTime',
|
54
|
-
value: function remainingTime() {
|
55
|
-
return Math.max(this.timesOutAt - Date.now(), 0);
|
56
|
-
}
|
57
|
-
}, {
|
58
|
-
key: 'cover',
|
59
|
-
value: function cover(time) {
|
60
|
-
return time <= this.timesOutAt - MIN_REQUEST_TIME;
|
61
|
-
}
|
62
|
-
}]);
|
63
|
-
|
64
|
-
return Timer;
|
65
|
-
})();
|
66
|
-
|
67
|
-
function fetch(method, path, requestParams) {
|
68
|
-
return request(method, path, requestParams).then(function (result) {
|
69
|
-
if (result && result.task && _.size(result) === 1) {
|
70
|
-
return handleTask(result.task);
|
71
|
-
}
|
72
|
-
return result;
|
73
|
-
});
|
74
|
-
}
|
75
|
-
|
76
|
-
function request(method, path, requestParams) {
|
77
|
-
var timer = new Timer();
|
78
|
-
return retryOnceOnError(timer, method, function () {
|
79
|
-
return retryOnRateLimit(timer, function () {
|
80
|
-
return scrivito.SessionKeeper.performWithToken(function (token) {
|
81
|
-
var ajaxDeferred = ajax(method, path, requestParams, timer.remainingTime(), token);
|
82
|
-
return scrivito.Promise.resolve(ajaxDeferred)['catch'](checkAuthorization);
|
83
|
-
});
|
84
|
-
})['catch'](function (error) {
|
85
|
-
return raiseError(error);
|
86
|
-
});
|
87
|
-
});
|
88
|
-
}
|
89
|
-
|
90
|
-
function retryOnceOnError(timer, method, requestCallback) {
|
91
|
-
if (method === 'POST') {
|
92
|
-
return requestCallback();
|
93
|
-
}
|
94
|
-
|
95
|
-
return requestCallback()['catch'](function (error) {
|
96
|
-
if (!timer.timedOut()) {
|
97
|
-
if (error instanceof scrivito.BackendError) {
|
98
|
-
return requestCallback();
|
99
|
-
}
|
100
|
-
if (error instanceof scrivito.NetworkError) {
|
101
|
-
return requestCallback();
|
102
|
-
}
|
103
|
-
}
|
104
|
-
throw error;
|
105
|
-
});
|
106
|
-
}
|
107
|
-
|
108
|
-
function retryOnRateLimit(timer, requestCallback) {
|
109
|
-
var retry = function retry(retryCount) {
|
110
|
-
return requestCallback()['catch'](function (error) {
|
111
|
-
if (error.status === 429) {
|
112
|
-
var timeout = calculateTimeout(error.getResponseHeader('Retry-After'), retryCount);
|
113
|
-
if (timer.cover(Date.now() + timeout)) {
|
114
|
-
return scrivito.Promise.resolve(scrivito.waitMs(timeout)).then(function () {
|
115
|
-
return retry(retryCount + 1);
|
116
|
-
});
|
117
|
-
}
|
118
|
-
throw new scrivito.RateLimitExceededError('rate limit exceeded', 429);
|
119
|
-
}
|
120
|
-
throw error;
|
121
|
-
});
|
122
|
-
};
|
123
|
-
|
124
|
-
return retry(0);
|
125
|
-
}
|
126
|
-
|
127
|
-
function calculateTimeout(retryAfter, retryCount) {
|
128
|
-
var calculatedTimeout = Math.pow(2, retryCount) * 0.5 * 1000;
|
129
|
-
return Math.max(calculatedTimeout, retryAfter * 1000);
|
130
|
-
}
|
131
|
-
|
132
|
-
function raiseError(error) {
|
133
|
-
if (error.status === undefined || !_.isNumber(error.status)) {
|
134
|
-
throw error;
|
135
|
-
} else if (error.status === 0) {
|
136
|
-
throw new scrivito.NetworkError(error.statusText, error.status);
|
137
|
-
}
|
138
|
-
|
139
|
-
var errorBody = parseError(error);
|
140
|
-
var specificOutput = errorBody.error;
|
141
|
-
|
142
|
-
if (error.status === 403) {
|
143
|
-
throw new scrivito.AccessDeniedError(specificOutput, error.status, errorBody.code);
|
144
|
-
} else if (error.status.toString()[0] === '4' && specificOutput) {
|
145
|
-
throw new scrivito.ClientError(specificOutput, error.status, errorBody.code);
|
146
|
-
} else if (error.status === 500 && specificOutput) {
|
147
|
-
throw new scrivito.BackendError(specificOutput, error.status);
|
148
|
-
}
|
149
|
-
throw new scrivito.NetworkError(error.responseText, error.status);
|
150
|
-
}
|
151
|
-
|
152
|
-
function checkAuthorization(error) {
|
153
|
-
if (error.status === 401) {
|
154
|
-
var errorBody = parseError(error);
|
155
|
-
var specificOutput = errorBody.error;
|
156
|
-
throw new scrivito.UnauthorizedError(specificOutput, error.status, errorBody.code);
|
157
|
-
}
|
158
|
-
throw error;
|
159
|
-
}
|
160
|
-
|
161
|
-
function parseError(error) {
|
162
|
-
try {
|
163
|
-
return JSON.parse(error.responseText);
|
164
|
-
} catch (err) {
|
165
|
-
if (err instanceof SyntaxError) {
|
166
|
-
throw new scrivito.NetworkError(error.responseText, error.status);
|
167
|
-
}
|
168
|
-
throw err;
|
169
|
-
}
|
170
|
-
}
|
171
|
-
|
172
|
-
function prepareAjaxParams(method, path) {
|
173
|
-
var requestParams = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
|
174
|
-
|
175
|
-
var ajaxParams = {
|
176
|
-
path: path,
|
177
|
-
verb: method,
|
178
|
-
params: requestParams
|
179
|
-
};
|
180
|
-
|
181
|
-
return {
|
182
|
-
data: JSON.stringify(ajaxParams)
|
183
|
-
};
|
184
|
-
}
|
185
|
-
|
186
|
-
function ajax(method, path, requestParams, timeout, token) {
|
187
|
-
// -- PATCH BEGINS HERE --
|
188
|
-
if (ajaxWithFormDataRequired(requestParams) /* || true */) {
|
189
|
-
return ajaxWithFormData(method, path, requestParams, timeout, token);
|
190
|
-
}
|
191
|
-
// -- PATCH ENDS HERE --
|
192
|
-
|
193
|
-
var ajaxParams = prepareAjaxParams(method, path, requestParams);
|
194
|
-
var ajaxMethod = method === 'POST' ? 'POST' : 'PUT';
|
195
|
-
var url = '/_f7/tenants/' + tenant + '/perform'; // <-- PATCH HERE
|
196
|
-
|
197
|
-
return $.ajax(_.extend({
|
198
|
-
url: url,
|
199
|
-
method: ajaxMethod,
|
200
|
-
contentType: 'application/json; charset=utf-8',
|
201
|
-
dataType: 'json',
|
202
|
-
//headers: { Authorization: `Session ${token}` }, // <-- PATCH HERE
|
203
|
-
timeout: timeout,
|
204
|
-
cache: false, // Don't cache GET requests.
|
205
|
-
xhrFields: { withCredentials: true }
|
206
|
-
}, ajaxParams)).then(function (result, textStatus, xhr) {
|
207
|
-
return $.Deferred().resolve(result);
|
208
|
-
}, function (xhr, textStatus, xhrError) {
|
209
|
-
return $.Deferred().reject(xhr);
|
210
|
-
});
|
211
|
-
}
|
212
|
-
|
213
|
-
// -- PATCH BEGINS HERE --
|
214
|
-
function ajaxWithFormDataRequired(params) {
|
215
|
-
var objParams = params && params.obj;
|
216
|
-
var result = false;
|
217
|
-
|
218
|
-
if (!objParams) {
|
219
|
-
return result;
|
220
|
-
}
|
221
|
-
|
222
|
-
for (var k in objParams) {
|
223
|
-
// if objParams[k] is an array
|
224
|
-
if (objParams.hasOwnProperty(k) && objParams[k] && typeof objParams[k] === 'object' && objParams[k].pop) {
|
225
|
-
// file uploads require form data
|
226
|
-
result = objParams[k][1] && (scrivito.BinaryUtils.isFile(objParams[k][1]) || scrivito.BinaryUtils.isBlob(objParams[k][1]) || scrivito.BinaryUtils.isBlobWithName(objParams[k][1]));
|
227
|
-
if (result) {
|
228
|
-
return result;
|
229
|
-
}
|
230
|
-
}
|
231
|
-
}
|
232
|
-
return result;
|
233
|
-
}
|
234
|
-
|
235
|
-
function ajaxWithFormData(method, path, requestParams, timeout, token) {
|
236
|
-
var formData = paramsToFormData(method, path, requestParams);
|
237
|
-
var ajaxMethod = method === 'POST' ? 'POST' : 'PUT';
|
238
|
-
var url = '/_f7/tenants/' + tenant + '/perform';
|
239
|
-
|
240
|
-
return $.ajax(_.extend({
|
241
|
-
url: url,
|
242
|
-
method: ajaxMethod,
|
243
|
-
contentType: false,
|
244
|
-
processData: false,
|
245
|
-
data: formData,
|
246
|
-
timeout: timeout,
|
247
|
-
cache: false, // Don't cache GET requests.
|
248
|
-
xhrFields: { withCredentials: true }
|
249
|
-
})).then(function (result, textStatus, xhr) {
|
250
|
-
return $.Deferred().resolve(result);
|
251
|
-
}, function (xhr, textStatus, xhrError) {
|
252
|
-
return $.Deferred().reject(xhr);
|
253
|
-
});
|
254
|
-
}
|
255
|
-
|
256
|
-
function paramsToFormData(verb, path, params) {
|
257
|
-
var objParams = params && params.obj || {};
|
258
|
-
var fd = new FormData();
|
259
|
-
fd.append('verb', verb);
|
260
|
-
fd.append('path', path);
|
261
|
-
|
262
|
-
for (var attr in objParams) {
|
263
|
-
// attr is a [type, value] pair
|
264
|
-
if (objParams.hasOwnProperty(attr) && objParams[attr] && typeof objParams[attr] === 'object' && objParams[attr].pop) {
|
265
|
-
var _objParams$attr = _slicedToArray(objParams[attr], 2);
|
266
|
-
|
267
|
-
var type = _objParams$attr[0];
|
268
|
-
var value = _objParams$attr[1];
|
269
|
-
|
270
|
-
if (typeof value === 'object' && value && value.pop) {
|
271
|
-
// multienum / stringlist / widgetlist
|
272
|
-
fd.append('params[obj][' + attr + '[]', type);
|
273
|
-
for (var i = 0; i < value.length; ++i) {
|
274
|
-
fd.append('params[obj][' + attr + '[][formdata$workaround][]', value[i]);
|
275
|
-
}
|
276
|
-
} else if (scrivito.BinaryUtils.isFile(value) || scrivito.BinaryUtils.isBlob(value)) {
|
277
|
-
// upload
|
278
|
-
fd.append('params[obj][' + attr + '][]', type);
|
279
|
-
fd.append('params[obj][' + attr + '][]', value);
|
280
|
-
} else if (scrivito.BinaryUtils.isBlobWithName(value)) {
|
281
|
-
fd.append('params[obj][' + attr + '][]', type);
|
282
|
-
fd.append('params[obj][' + attr + '][]', value.blob_to_upload, value.filename);
|
283
|
-
} else if (value && typeof value === 'object') {
|
284
|
-
// blob/copy rename
|
285
|
-
fd.append('params[obj][' + attr + '[]', type);
|
286
|
-
for (var l in value) {
|
287
|
-
if (value.hasOwnProperty(l)) {
|
288
|
-
fd.append('params[obj][' + attr + '][][' + l + ']', value[l]);
|
289
|
-
}
|
290
|
-
}
|
291
|
-
} else if (typeof value !== 'undefined') {
|
292
|
-
fd.append('params[obj][' + attr + '][]', type);
|
293
|
-
fd.append('params[obj][' + attr + '][]', value);
|
294
|
-
}
|
295
|
-
// special handling for widget pool
|
296
|
-
} else if (attr === '_widget_pool') {
|
297
|
-
var value = objParams[attr];
|
298
|
-
for (var widgetId in value) {
|
299
|
-
if (value.hasOwnProperty(widgetId)) {
|
300
|
-
var widget = value[widgetId];
|
301
|
-
for (var widgetAttr in widget) {
|
302
|
-
if (widget.hasOwnProperty(widgetAttr)) {
|
303
|
-
if (widget[widgetAttr] && widget[widgetAttr].pop) {
|
304
|
-
var _widget$widgetAttr = _slicedToArray(widget[widgetAttr], 2);
|
305
|
-
|
306
|
-
var widgetAttrType = _widget$widgetAttr[0];
|
307
|
-
var widgetValue = _widget$widgetAttr[1];
|
308
|
-
|
309
|
-
// FIXME: Duplication
|
310
|
-
if (widgetValue && typeof widgetValue === 'object' && widgetValue.pop) {
|
311
|
-
// multienum / stringlist / widgetlist
|
312
|
-
fd.append('params[obj][' + attr + '][' + widgetId + '][' + widgetAttr + '][]', widgetAttrType);
|
313
|
-
for (var i = 0; i < widgetValue.length; ++i) {
|
314
|
-
fd.append('params[obj][' + attr + '][' + widgetId + '][' + widgetAttr + '][][formdata$workaround][]', widgetValue[i]);
|
315
|
-
}
|
316
|
-
} else if (scrivito.BinaryUtils.isFile(widgetValue) || scrivito.BinaryUtils.isBlob(widgetValue)) {
|
317
|
-
// upload
|
318
|
-
fd.append('params[obj][' + attr + '][' + widgetId + '][' + widgetAttr + '][]', widgetAttrType);
|
319
|
-
fd.append('params[obj][' + attr + '][' + widgetId + '][' + widgetAttr + '][]', widgetValue);
|
320
|
-
} else if (scrivito.BinaryUtils.isBlobWithName(widgetValue)) {
|
321
|
-
fd.append('params[obj][' + attr + '][' + widgetId + '][' + widgetAttr + '][]', widgetAttrType);
|
322
|
-
fd.append('params[obj][' + attr + '][' + widgetId + '][' + widgetAttr + '][]', widgetValue.blob_to_upload, widgetValue.filename);
|
323
|
-
} else if (widgetValue && typeof widgetValue === 'object') {
|
324
|
-
// blob/copy rename
|
325
|
-
fd.append('params[obj][' + attr + '][' + widgetId + '][' + widgetAttr + '][]', widgetAttrType);
|
326
|
-
for (var l in widgetValue) {
|
327
|
-
if (widgetValue.hasOwnProperty(l)) {
|
328
|
-
fd.append('params[obj][' + attr + '][' + widgetId + '][' + widgetAttr + '][][' + l + ']', widgetValue[l]);
|
329
|
-
}
|
330
|
-
}
|
331
|
-
} else {
|
332
|
-
// normal value
|
333
|
-
fd.append('params[obj][' + attr + '][' + widgetId + '][' + widgetAttr + '][]', widgetAttrType);
|
334
|
-
fd.append('params[obj][' + attr + '][' + widgetId + '][' + widgetAttr + '][]', widgetValue);
|
335
|
-
}
|
336
|
-
} else {
|
337
|
-
// hopefully a built-in attribute :-)
|
338
|
-
fd.append('params[obj][' + attr + '][' + widgetId + '][' + widgetAttr + ']', widget[widgetAttr]);
|
339
|
-
}
|
340
|
-
}
|
341
|
-
}
|
342
|
-
} else {
|
343
|
-
// hopefully a built-in attribute :-)
|
344
|
-
fd.append('params[obj][' + attr + ']', objParams[attr]);
|
345
|
-
}
|
346
|
-
}
|
347
|
-
}
|
348
|
-
}
|
349
|
-
|
350
|
-
return fd;
|
351
|
-
}
|
352
|
-
|
353
|
-
// -- PATCH ENDS HERE --
|
354
|
-
|
355
|
-
function handleTask(task) {
|
356
|
-
switch (task.status) {
|
357
|
-
case 'success':
|
358
|
-
return task.result;
|
359
|
-
case 'error':
|
360
|
-
throw new scrivito.ClientError(task.message, undefined, task.code);
|
361
|
-
case 'open':
|
362
|
-
return scrivito.wait(2).then(function () {
|
363
|
-
return request('GET', 'tasks/' + task.id).then(function (result) {
|
364
|
-
return handleTask(result);
|
365
|
-
});
|
366
|
-
});
|
367
|
-
default:
|
368
|
-
throw new scrivito.ScrivitoError('Invalid task response (unknown status)');
|
369
|
-
}
|
370
|
-
}
|
371
|
-
})();
|