Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,24 @@
this._afterCreate();
},
_loadGrants: function () {
// Mapbender.handleAjaxError only exists in Mapbender >= 4.2.5
const failListener = typeof Mapbender.handleAjaxError === 'function'
? (e) => Mapbender.handleAjaxError(e, () => this._loadGrants())
: this._onAjaxError.bind(this);

this.grantsRequest_ = $.getJSON(this.elementUrl + 'grants')
.then((mergeWith => allGrants => {
.then((allGrants) => {
const schemaNames = Object.keys(allGrants);
for (let schemaName of schemaNames) {
if (allGrants[schemaName] === false) {
delete mergeWith[schemaName];
delete this.options.schemes[schemaName];
} else {
Object.assign(mergeWith[schemaName], allGrants[schemaName]);
Object.assign(this.options.schemes[schemaName], allGrants[schemaName]);
}
}
})(this.options.schemes))
.fail(failListener)
})
.fail(this._createFailListener(() => this._loadGrants()))
.then(() => this.updateSchemaSelector_())
;
this.onGrantsLoadStarted();
},
onGrantsLoadStarted: function() {
// do nothing, can be overridden by digitizer
onGrantsLoadStarted: function () {
// do nothing, can be overridden by subclasses
},
_createFormRenderer: function () {
return new Mapbender.DataManager.FormRenderer();
Expand Down Expand Up @@ -626,10 +621,7 @@
this.$loadingIndicator_.css({opacity: 1});
this.fetchXhr = this.decorateXhr_(this.loadItems(this._getSelectRequestParams(schema)), this.$loadingIndicator_);

// Mapbender.handleAjaxError only exists in Mapbender >= 4.2.5
const failListener = typeof Mapbender.handleAjaxError === 'function'
? (e) => Mapbender.handleAjaxError(e, () => this._getData(schema))
: this._onAjaxError.bind(this);
const failListener = this._createFailListener(() => this._getData(schema));

return this.fetchXhr
.always(function () {
Expand Down Expand Up @@ -755,10 +747,7 @@
}
this.$loadingIndicator_.css({opacity: 1});

// Mapbender.handleAjaxError only exists in Mapbender >= 4.2.5
const failListener = typeof Mapbender.handleAjaxError === 'function'
? (e) => Mapbender.handleAjaxError(e, () => this.postJSON(uri, data, options, onSuccess))
: this._onAjaxError.bind(this);
const failListener = this._createFailListener(() => this.postJSON(uri, data, options, onSuccess));

let promise = this.decorateXhr_($.ajax(options_), this.$loadingIndicator_).fail(failListener);
if (onSuccess) promise = promise.then(onSuccess);
Expand All @@ -773,6 +762,13 @@
return jqXhr;
},
// TODO: this can be removed for Mapbender 5
_createFailListener: function (retryCallback) {
// Mapbender.handleAjaxError only exists in Mapbender >= 4.2.5
return typeof Mapbender.handleAjaxError === 'function'
? (e) => Mapbender.handleAjaxError(e, retryCallback)
: this._onAjaxError.bind(this);
},
// TODO: this can be removed for Mapbender 5
_onAjaxError: function (xhr) {
if (xhr.statusText === 'abort') {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
this._super();
this.styleEditor = this._createStyleEditor();
this.wktFormat_ = new ol.format.WKT();
// setup() called in onGrantsLoadStarted
// setup() and _start() called via onGrantsLoadStarted() → _onMapAndGrantsLoaded()
},
_createTableRenderer: function() {
return new Mapbender.Digitizer.TableRenderer(this, this.tableButtonsTemplate_);
Expand All @@ -55,7 +55,7 @@
// Invoked only by data manager _create
// do nothing; deliberately do NOT call parent method
},
onGrantsLoadStarted: function() {
onGrantsLoadStarted: function () {
$.when(Mapbender.elementRegistry.waitReady('.mb-element-map'), this.grantsRequest_)
.then((mbMap) => this._onMapAndGrantsLoaded(mbMap));
},
Expand Down Expand Up @@ -534,7 +534,7 @@
});
}
var widget = this;
var promise = this.postJSON('update-multiple', postData, undefined,(response) => {
var promise = this.postJSON('update-multiple', postData, undefined, (response) => {
var savedItems = response.saved;
for (var i = 0; i < savedItems.length; ++i) {
var savedItem = savedItems[i];
Expand Down