To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit d58e8a0d authored by Ian Boschung's avatar Ian Boschung
Browse files

Fixes issue #121

Instead of first submitting the images, the rest of the data is
submitted as JSON and afterwards the images with the new event
id (if a new event is created).
parent 3ee421bd
......@@ -194,11 +194,11 @@ export default class newEvent extends EditView {
if (Object.keys(images).length > 0) {
const imageForm = new FormData();
Object.keys(images).forEach(key => imageForm.append(key, images[key]));
imageForm.append('_id', this.form.data._id);
imageForm.append('_etag', this.form.data._etag);
// first upload the images as formData, then the rest as JSON
this.controller.handler.patch(imageForm).then(({ _etag }) => {
this.submit({ ...this.form.data, _etag });
// first upload the data as JSON, then the images as form data
this.submit(this.form.data).then(({ _id, _etag }) => {
imageForm.append('_id', _id);
imageForm.append('_etag', _etag);
this.controller.patch(imageForm, true);
});
} else this.submit(this.form.data);
} else {
......
......@@ -27,13 +27,17 @@ export default class ItemController {
this.handler.post(data).then((response) => {
this.id = response._id;
this.changeModus('view');
resolve(response);
}).catch(reject);
});
}
patch(data, formData = false) {
return new Promise((resolve, reject) => {
this.handler.patch(data, formData).then(() => { this.changeModus('view'); }).catch(reject);
this.handler.patch(data, formData).then((response) => {
this.changeModus('view');
resolve(response);
}).catch(reject);
});
}
......
......@@ -55,27 +55,33 @@ export default class EditView extends ItemView {
* changes.
*/
submit(data) {
let request;
if (this.controller.modus === 'edit') {
// this is a patch to an existing item
request = this.controller.patch(data);
} else {
request = this.controller.post(data);
}
request.catch((error) => {
console.log(error);
// Process the API error
if ('_issues' in error) {
// there are problems with some fields, display them
Object.keys(error._issues).forEach((field) => {
this.form.errors[field] = [error._issues[field]];
this.form.valid = false;
});
console.log(this.form.errors);
m.redraw();
return new Promise((resolve, reject) => {
let request;
if (this.controller.modus === 'edit') {
// this is a patch to an existing item
request = this.controller.patch(data);
} else {
console.log(error);
request = this.controller.post(data);
}
request.then((response) => {
console.log(response);
resolve(response);
}).catch((error) => {
console.log(error);
// Process the API error
if ('_issues' in error) {
// there are problems with some fields, display them
Object.keys(error._issues).forEach((field) => {
this.form.errors[field] = [error._issues[field]];
this.form.valid = false;
});
console.log(this.form.errors);
m.redraw();
reject(error);
} else {
console.log(error);
}
});
});
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment