...
 
Commits (3)
......@@ -9,8 +9,8 @@
<body>
<section class="gitlab">
<label>Gitlab URL: <input type="url" id="gitlab-url" ></label>
<label>Project path: <input type="text" id="gitlab-path"></label>
<label>Gitlab token <input type="text" id="gitlab-token"></label>
<label>Project path: <input type="text" id="gitlab-path"></label>
<label>Gitlab label (optional) <input type="text" id="gitlab-label"></label>
<div>
<b>Project ID: </b>
......
#issue-options {
display: none;
padding-left: 1em;
padding-right: 1em;
}
#issue-options > p {
text-align: center;
}
#issue-options > button {
float: right;
}
#saving-page {
display: none;
}
#saving-page-failed {
display: none;
color: #f00;
}
#save-page {
margin-left: auto;
margin-right: 0px;
}
#todo-count {
width: 100%;
text-align: center;
padding: 1em;
}
......@@ -3,6 +3,7 @@
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="save_page.css"/>
</head>
<body>
......@@ -11,33 +12,37 @@
<div class="text-section-header">Save Page to TODO</div>
</header>
<div id="issue-options" class="panel-section" style="display: none; padding-left: 1em; padding-right: 1em;">
<p style="text-align: center;">Please configure the extension</p>
<button style="float: right;" class="browser-style" id="show-options">Show Options</button>
<div id="issue-options" class="panel-section">
<p>Please configure the extension</p>
<button id="show-options" class="browser-style">Show Options</button>
</div>
<div id="issue-details" class="panel-section panel-section-formElements">
<div class="panel-formElements-item">
<label for="issue-title">Title:</label>
<input size="40" type="text" placeholder="Title" id="issue-title" />
<input id="issue-title" type="text" placeholder="Title" size="40"/>
</div>
<div class="panel-formElements-item">
<label for="issue-url">Link:</label>
<input type="text" placeholder="URL" id="issue-url" />
<input id="issue-url" type="text" placeholder="URL"/>
</div>
<div id="saving-page" class="panel-formElements-item" style="display: none;">
<div id="saving-page" class="panel-formElements-item">
<p>Saving page</p>
</div>
<div id="saving-page-failed" class="panel-formElements-item">
<p>Failed to save page (check options or debug log)</p>
</div>
<div class="panel-formElements-item">
<button style="margin-left: auto; margin-right: 0px;" class="browser-style" id="save-page">Save Page</button>
<button id="save-page" class="browser-style">Save Page</button>
</div>
</div>
<footer id="issue-footer" class="panel-section panel-section-footer">
<div style="width: 100%; text-align: center; padding: 1em;" id="todo-count">Counting TODOs</div>
<div id="todo-count">Counting TODOs</div>
</footer>
<script src="save_page.js"></script>
......
......@@ -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);