Keep put-form open on error
This commit is contained in:
1 parent
cae54613a2
commit
14c629689f
5 files changed
+167
-59
No files matched your search
+15
-6
@@ -52,13 +52,14 @@ const unpackSmartQuery = memoize(query => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function putActionHandler(action, object) {
|
function putActionHandler(action, _object) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
const object = Object.assign({}, _object);
|
||||||
if (action === "save") {
|
if (action === "save") {
|
||||||
const file = object["file"] ? object["file"][0] : null;
|
const file = object["file"] ? object["file"][0] : null;
|
||||||
delete object["file"];
|
delete object["file"];
|
||||||
|
|
||||||
if (!file) return void reject(new Error("File not selected"));
|
if (!file) return void resolve({ file: "File not selected" });
|
||||||
|
|
||||||
const id = file.name;
|
const id = file.name;
|
||||||
|
|
||||||
@@ -67,7 +68,7 @@ function putActionHandler(action, object) {
|
|||||||
.then(exists => {
|
.then(exists => {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
return void reject(new Error("File already exists"));
|
return void resolve({ file: "File already exists" });
|
||||||
}
|
}
|
||||||
const headers = Object.assign(
|
const headers = Object.assign(
|
||||||
{
|
{
|
||||||
@@ -277,14 +278,22 @@ function renderTable(
|
|||||||
Object.assign(
|
Object.assign(
|
||||||
{
|
{
|
||||||
actionHandler: (action, object) => {
|
actionHandler: (action, object) => {
|
||||||
|
return new Promise(resolve => {
|
||||||
putActionHandler(action, object)
|
putActionHandler(action, object)
|
||||||
.then(() => {
|
.then(errors => {
|
||||||
|
errors = errors ? Object.values(errors) : [];
|
||||||
|
if (errors.length) {
|
||||||
|
for (const err of errors)
|
||||||
|
notifications.push("error", err);
|
||||||
|
} else {
|
||||||
overlay.close(cb);
|
overlay.close(cb);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
notifications.push("error", err.message);
|
notifications.push("error", err.message);
|
||||||
overlay.close(cb);
|
resolve();
|
||||||
m.redraw();
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+50
-16
@@ -37,26 +37,31 @@ const unpackSmartQuery = memoize(query => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function putActionHandler(action, object, isNew) {
|
function putActionHandler(action, _object, isNew) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const object = Object.assign({}, _object);
|
||||||
if (action === "save") {
|
if (action === "save") {
|
||||||
const id = object["_id"];
|
const id = object["_id"];
|
||||||
delete object["_id"];
|
delete object["_id"];
|
||||||
|
|
||||||
if (!id) return void notifications.push("error", "ID can not be empty");
|
const errors = {};
|
||||||
|
|
||||||
|
if (!id) errors["_id"] = "ID can not be empty";
|
||||||
|
if (!object.provision) errors.provision = "Provision not selected";
|
||||||
|
|
||||||
|
if (Object.keys(errors).length) return void resolve(errors);
|
||||||
|
|
||||||
store
|
store
|
||||||
.resourceExists("presets", id)
|
.resourceExists("presets", id)
|
||||||
.then(exists => {
|
.then(exists => {
|
||||||
if (exists && isNew) {
|
if (exists && isNew) {
|
||||||
notifications.push("error", "Preset already exists");
|
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
return;
|
return void resolve({ _id: "Preset already exists" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exists && !isNew) {
|
if (!exists && !isNew) {
|
||||||
notifications.push("error", "Preset already deleted");
|
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
return;
|
return void resolve({ _id: "Preset does not exist" });
|
||||||
}
|
}
|
||||||
|
|
||||||
store
|
store
|
||||||
@@ -67,28 +72,27 @@ function putActionHandler(action, object, isNew) {
|
|||||||
`Preset ${exists ? "updated" : "created"}`
|
`Preset ${exists ? "updated" : "created"}`
|
||||||
);
|
);
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(reject);
|
||||||
notifications.push("error", err.message);
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(reject);
|
||||||
notifications.push("error", err.message);
|
|
||||||
});
|
|
||||||
} else if (action === "delete") {
|
} else if (action === "delete") {
|
||||||
store
|
store
|
||||||
.deleteResource("presets", object["_id"])
|
.deleteResource("presets", object["_id"])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
notifications.push("success", "Preset deleted");
|
notifications.push("success", "Preset deleted");
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
notifications.push("error", err.message);
|
reject(err);
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Undefined action");
|
reject(new Error("Undefined action"));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const formData = {
|
const formData = {
|
||||||
@@ -220,8 +224,23 @@ function renderTable(
|
|||||||
{
|
{
|
||||||
base: preset,
|
base: preset,
|
||||||
actionHandler: (action, object) => {
|
actionHandler: (action, object) => {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
putActionHandler(action, object, false)
|
||||||
|
.then(errors => {
|
||||||
|
errors = errors ? Object.values(errors) : [];
|
||||||
|
if (errors.length) {
|
||||||
|
for (const err of errors)
|
||||||
|
notifications.push("error", err);
|
||||||
|
} else {
|
||||||
overlay.close(cb);
|
overlay.close(cb);
|
||||||
putActionHandler(action, object, false);
|
}
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
notifications.push("error", err.message);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
formData
|
formData
|
||||||
@@ -323,9 +342,24 @@ function renderTable(
|
|||||||
Object.assign(
|
Object.assign(
|
||||||
{
|
{
|
||||||
actionHandler: (action, object) => {
|
actionHandler: (action, object) => {
|
||||||
putActionHandler(action, object, true);
|
return new Promise(resolve => {
|
||||||
|
putActionHandler(action, object, true)
|
||||||
|
.then(errors => {
|
||||||
|
errors = errors ? Object.values(errors) : [];
|
||||||
|
if (errors.length) {
|
||||||
|
for (const err of errors)
|
||||||
|
notifications.push("error", err);
|
||||||
|
} else {
|
||||||
overlay.close(cb);
|
overlay.close(cb);
|
||||||
}
|
}
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
notifications.push("error", err.message);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
formData
|
formData
|
||||||
)
|
)
|
||||||
|
|||||||
+45
-16
@@ -32,26 +32,26 @@ const unpackSmartQuery = memoize(query => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function putActionHandler(action, object, isNew) {
|
function putActionHandler(action, _object, isNew) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const object = Object.assign({}, _object);
|
||||||
if (action === "save") {
|
if (action === "save") {
|
||||||
const id = object["_id"];
|
const id = object["_id"];
|
||||||
delete object["_id"];
|
delete object["_id"];
|
||||||
|
|
||||||
if (!id) return void notifications.push("error", "ID can not be empty");
|
if (!id) return void resolve({ _id: "ID can not be empty" });
|
||||||
|
|
||||||
store
|
store
|
||||||
.resourceExists("provisions", id)
|
.resourceExists("provisions", id)
|
||||||
.then(exists => {
|
.then(exists => {
|
||||||
if (exists && isNew) {
|
if (exists && isNew) {
|
||||||
notifications.push("error", "Provision already exists");
|
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
return;
|
return void resolve({ _id: "Provision already exists" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exists && !isNew) {
|
if (!exists && !isNew) {
|
||||||
notifications.push("error", "Provision already deleted");
|
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
return;
|
return void resolve({ _id: "Provision does not exist" });
|
||||||
}
|
}
|
||||||
|
|
||||||
store
|
store
|
||||||
@@ -62,28 +62,27 @@ function putActionHandler(action, object, isNew) {
|
|||||||
`Provision ${exists ? "updated" : "created"}`
|
`Provision ${exists ? "updated" : "created"}`
|
||||||
);
|
);
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(reject);
|
||||||
notifications.push("error", err.message);
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(reject);
|
||||||
notifications.push("error", err.message);
|
|
||||||
});
|
|
||||||
} else if (action === "delete") {
|
} else if (action === "delete") {
|
||||||
store
|
store
|
||||||
.deleteResource("provisions", object["_id"])
|
.deleteResource("provisions", object["_id"])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
notifications.push("success", "Provision deleted");
|
notifications.push("success", "Provision deleted");
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
notifications.push("error", err.message);
|
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
|
reject(err);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Undefined action");
|
reject(new Error("Undefined action"));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const formData = {
|
const formData = {
|
||||||
@@ -207,8 +206,23 @@ function renderTable(
|
|||||||
{
|
{
|
||||||
base: provision,
|
base: provision,
|
||||||
actionHandler: (action, object) => {
|
actionHandler: (action, object) => {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
putActionHandler(action, object, false)
|
||||||
|
.then(errors => {
|
||||||
|
errors = errors ? Object.values(errors) : [];
|
||||||
|
if (errors.length) {
|
||||||
|
for (const err of errors)
|
||||||
|
notifications.push("error", err);
|
||||||
|
} else {
|
||||||
overlay.close(cb);
|
overlay.close(cb);
|
||||||
putActionHandler(action, object, false);
|
}
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
notifications.push("error", err.message);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
formData
|
formData
|
||||||
@@ -316,9 +330,24 @@ function renderTable(
|
|||||||
Object.assign(
|
Object.assign(
|
||||||
{
|
{
|
||||||
actionHandler: (action, object) => {
|
actionHandler: (action, object) => {
|
||||||
putActionHandler(action, object, true);
|
return new Promise(resolve => {
|
||||||
|
putActionHandler(action, object, true)
|
||||||
|
.then(errors => {
|
||||||
|
errors = errors ? Object.values(errors) : [];
|
||||||
|
if (errors.length) {
|
||||||
|
for (const err of errors)
|
||||||
|
notifications.push("error", err);
|
||||||
|
} else {
|
||||||
overlay.close(cb);
|
overlay.close(cb);
|
||||||
}
|
}
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
notifications.push("error", err.message);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
formData
|
formData
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -138,7 +138,9 @@ const component = {
|
|||||||
onclick: e => {
|
onclick: e => {
|
||||||
e.redraw = false;
|
e.redraw = false;
|
||||||
e.target.disabled = true;
|
e.target.disabled = true;
|
||||||
actionHandler("delete", current.object);
|
actionHandler("delete", current.object).then(() => {
|
||||||
|
e.target.disabled = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Delete"
|
"Delete"
|
||||||
@@ -155,11 +157,16 @@ const component = {
|
|||||||
{
|
{
|
||||||
onsubmit: e => {
|
onsubmit: e => {
|
||||||
e.redraw = false;
|
e.redraw = false;
|
||||||
e.target.onsubmit = null;
|
// const onsubmit = e.target.onsubmit;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
for (const elem of e.target.elements) elem.disabled = true;
|
// e.target.onsubmit = null;
|
||||||
submit.dom.textContent = "Loading ...";
|
submit.dom.disabled = true;
|
||||||
actionHandler("save", current.object);
|
// submit.dom.textContent = "Loading ...";
|
||||||
|
actionHandler("save", current.object).then(() => {
|
||||||
|
// submit.dom.textContent = "Save";
|
||||||
|
// e.target.onsubmit = onsubmit;
|
||||||
|
submit.dom.disabled = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
form
|
form
|
||||||
|
|||||||
@@ -32,26 +32,26 @@ const unpackSmartQuery = memoize(query => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function putActionHandler(action, object, isNew) {
|
function putActionHandler(action, _object, isNew) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const object = Object.assign({}, _object);
|
||||||
if (action === "save") {
|
if (action === "save") {
|
||||||
const id = object["_id"];
|
const id = object["_id"];
|
||||||
delete object["_id"];
|
delete object["_id"];
|
||||||
|
|
||||||
if (!id) return void notifications.push("error", "ID can not be empty");
|
if (!id) return void resolve({ _id: "ID can not be empty" });
|
||||||
|
|
||||||
store
|
store
|
||||||
.resourceExists("virtualParameters", id)
|
.resourceExists("virtualParameters", id)
|
||||||
.then(exists => {
|
.then(exists => {
|
||||||
if (exists && isNew) {
|
if (exists && isNew) {
|
||||||
notifications.push("error", "Virtual parameter already exists");
|
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
return;
|
return void resolve({ _id: "Virtual parameter already exists" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exists && !isNew) {
|
if (!exists && !isNew) {
|
||||||
notifications.push("error", "Virtual parameter already deleted");
|
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
return;
|
return void resolve({ _id: "Virtual parameter does not exist" });
|
||||||
}
|
}
|
||||||
|
|
||||||
store
|
store
|
||||||
@@ -62,28 +62,27 @@ function putActionHandler(action, object, isNew) {
|
|||||||
`Virtual parameter ${exists ? "updated" : "created"}`
|
`Virtual parameter ${exists ? "updated" : "created"}`
|
||||||
);
|
);
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(reject);
|
||||||
notifications.push("error", err.message);
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(reject);
|
||||||
notifications.push("error", err.message);
|
|
||||||
});
|
|
||||||
} else if (action === "delete") {
|
} else if (action === "delete") {
|
||||||
store
|
store
|
||||||
.deleteResource("virtualParameters", object["_id"])
|
.deleteResource("virtualParameters", object["_id"])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
notifications.push("success", "Virtual parameter deleted");
|
notifications.push("success", "Virtual parameter deleted");
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
|
resolve();
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
notifications.push("error", err.message);
|
|
||||||
store.fulfill(0, Date.now());
|
store.fulfill(0, Date.now());
|
||||||
|
reject(err);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Undefined action");
|
reject(new Error("Undefined action"));
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const formData = {
|
const formData = {
|
||||||
@@ -208,8 +207,23 @@ function renderTable(
|
|||||||
{
|
{
|
||||||
base: virtualParameter,
|
base: virtualParameter,
|
||||||
actionHandler: (action, object) => {
|
actionHandler: (action, object) => {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
putActionHandler(action, object, false)
|
||||||
|
.then(errors => {
|
||||||
|
errors = errors ? Object.values(errors) : [];
|
||||||
|
if (errors.length) {
|
||||||
|
for (const err of errors)
|
||||||
|
notifications.push("error", err);
|
||||||
|
} else {
|
||||||
overlay.close(cb);
|
overlay.close(cb);
|
||||||
putActionHandler(action, object, false);
|
}
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
notifications.push("error", err.message);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
formData
|
formData
|
||||||
@@ -326,9 +340,24 @@ function renderTable(
|
|||||||
Object.assign(
|
Object.assign(
|
||||||
{
|
{
|
||||||
actionHandler: (action, object) => {
|
actionHandler: (action, object) => {
|
||||||
putActionHandler(action, object, true);
|
return new Promise(resolve => {
|
||||||
|
putActionHandler(action, object, true)
|
||||||
|
.then(errors => {
|
||||||
|
errors = errors ? Object.values(errors) : [];
|
||||||
|
if (errors.length) {
|
||||||
|
for (const err of errors)
|
||||||
|
notifications.push("error", err);
|
||||||
|
} else {
|
||||||
overlay.close(cb);
|
overlay.close(cb);
|
||||||
}
|
}
|
||||||
|
resolve();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
notifications.push("error", err.message);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
formData
|
formData
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user