Commit 3e46007a authored by Mark Hymers's avatar Mark Hymers

Tidy up code

Signed-off-by: Mark Hymers's avatarMark Hymers <mark.hymers@ynic.york.ac.uk>
parent aa0065a0
......@@ -32,7 +32,7 @@
</div>
<div id="saving-page-failed" class="panel-formElements-item">
<p>Failed to save page (check options)</p>
<p>Failed to save page (check options or debug log)</p>
</div>
<div class="panel-formElements-item">
......
......@@ -9,8 +9,15 @@ var gitlab_project_id = "";
var gitlab_label = "";
var gitlab_user_id = "";
function onError(e) {
function savePageFailed(e) {
/* Log the failure and display the failed message */
/* Don't close the popup window at the end */
console.log(e);
const save_text = document.querySelector("#saving-page");
const failed = document.querySelector("#saving-page-failed");
save_text.style.display = 'none';
failed.style.display = 'block';
}
function savePage() {
......@@ -36,7 +43,6 @@ function savePage() {
save_button.style.display = 'none';
save_text.style.display = 'block';
/* TODO: Add an error handler to the below to show error if we can't submit */
fetch(url, {
method: 'POST',
headers: {
......@@ -47,8 +53,14 @@ function savePage() {
referrer: 'no-referrer',
body: data
})
.then(function(response) { return response.json(); })
.then(function(dat) { window.close(); });
.then(function(response) {
if (response.status != 201) {
throw new Error('Failed')
}
window.close();
})
.catch(savePageFailed);
}
function onClick(button) {
......@@ -94,6 +106,17 @@ function todoCountUpdate(data) {
num_todos.innerHTML = txt;
}
function showOptionsLink(e) {
/* Hide our main sections and show the options */
const issues_div = document.querySelector("#issue-details");
const issues_footer = document.querySelector("#issue-footer");
const issues_options = document.querySelector("#issue-options");
issues_div.style.display = 'none';
issues_footer.style.display = 'none';
issues_options.style.display = 'block';
}
function dataLoad(data) {
gitlab_url = data.gitlab_url || "";
gitlab_path = data.gitlab_path || "";
......@@ -103,15 +126,7 @@ function dataLoad(data) {
gitlab_user_id = data.gitlab_user_id || "";
if (gitlab_url == "" || gitlab_path == "" || gitlab_project_id == "") {
/* Hide our main sections and show the options */
const issues_div = document.querySelector("#issue-details");
const issues_footer = document.querySelector("#issue-footer");
const issues_options = document.querySelector("#issue-options");
issues_div.style.display = 'none';
issues_footer.style.display = 'none';
issues_options.style.display = 'block';
showOptionsLink("");
return;
}
......@@ -139,6 +154,6 @@ function dataLoad(data) {
* When we open the options page, load the settings
*/
const stored_settings = browser.storage.local.get();
stored_settings.then(dataLoad, onError);
stored_settings.then(dataLoad, showOptionsLink);
document.addEventListener("click", onClick);
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