...
 
Commits (3)
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
<body> <body>
<section class="gitlab"> <section class="gitlab">
<label>Gitlab URL: <input type="url" id="gitlab-url" ></label> <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>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> <label>Gitlab label (optional) <input type="text" id="gitlab-label"></label>
<div> <div>
<b>Project ID: </b> <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 @@ ...@@ -3,6 +3,7 @@
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" href="save_page.css"/>
</head> </head>
<body> <body>
...@@ -11,33 +12,37 @@ ...@@ -11,33 +12,37 @@
<div class="text-section-header">Save Page to TODO</div> <div class="text-section-header">Save Page to TODO</div>
</header> </header>
<div id="issue-options" class="panel-section" style="display: none; padding-left: 1em; padding-right: 1em;"> <div id="issue-options" class="panel-section">
<p style="text-align: center;">Please configure the extension</p> <p>Please configure the extension</p>
<button style="float: right;" class="browser-style" id="show-options">Show Options</button> <button id="show-options" class="browser-style">Show Options</button>
</div> </div>
<div id="issue-details" class="panel-section panel-section-formElements"> <div id="issue-details" class="panel-section panel-section-formElements">
<div class="panel-formElements-item"> <div class="panel-formElements-item">
<label for="issue-title">Title:</label> <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>
<div class="panel-formElements-item"> <div class="panel-formElements-item">
<label for="issue-url">Link:</label> <label for="issue-url">Link:</label>
<input type="text" placeholder="URL" id="issue-url" /> <input id="issue-url" type="text" placeholder="URL"/>
</div> </div>
<div id="saving-page" class="panel-formElements-item" style="display: none;"> <div id="saving-page" class="panel-formElements-item">
<p>Saving page</p> <p>Saving page</p>
</div> </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"> <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>
</div> </div>
<footer id="issue-footer" class="panel-section panel-section-footer"> <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> </footer>
<script src="save_page.js"></script> <script src="save_page.js"></script>
......
...@@ -9,8 +9,15 @@ var gitlab_project_id = ""; ...@@ -9,8 +9,15 @@ var gitlab_project_id = "";
var gitlab_label = ""; var gitlab_label = "";
var gitlab_user_id = ""; 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); 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() { function savePage() {
...@@ -36,7 +43,6 @@ function savePage() { ...@@ -36,7 +43,6 @@ function savePage() {
save_button.style.display = 'none'; save_button.style.display = 'none';
save_text.style.display = 'block'; save_text.style.display = 'block';
/* TODO: Add an error handler to the below to show error if we can't submit */
fetch(url, { fetch(url, {
method: 'POST', method: 'POST',
headers: { headers: {
...@@ -47,8 +53,14 @@ function savePage() { ...@@ -47,8 +53,14 @@ function savePage() {
referrer: 'no-referrer', referrer: 'no-referrer',
body: data body: data
}) })
.then(function(response) { return response.json(); }) .then(function(response) {
.then(function(dat) { window.close(); }); if (response.status != 201) {
throw new Error('Failed')
}
window.close();
})
.catch(savePageFailed);
} }
function onClick(button) { function onClick(button) {
...@@ -94,6 +106,17 @@ function todoCountUpdate(data) { ...@@ -94,6 +106,17 @@ function todoCountUpdate(data) {
num_todos.innerHTML = txt; 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) { function dataLoad(data) {
gitlab_url = data.gitlab_url || ""; gitlab_url = data.gitlab_url || "";
gitlab_path = data.gitlab_path || ""; gitlab_path = data.gitlab_path || "";
...@@ -103,15 +126,7 @@ function dataLoad(data) { ...@@ -103,15 +126,7 @@ function dataLoad(data) {
gitlab_user_id = data.gitlab_user_id || ""; gitlab_user_id = data.gitlab_user_id || "";
if (gitlab_url == "" || gitlab_path == "" || gitlab_project_id == "") { if (gitlab_url == "" || gitlab_path == "" || gitlab_project_id == "") {
/* Hide our main sections and show the options */ showOptionsLink("");
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';
return; return;
} }
...@@ -139,6 +154,6 @@ function dataLoad(data) { ...@@ -139,6 +154,6 @@ function dataLoad(data) {
* When we open the options page, load the settings * When we open the options page, load the settings
*/ */
const stored_settings = browser.storage.local.get(); const stored_settings = browser.storage.local.get();
stored_settings.then(dataLoad, onError); stored_settings.then(dataLoad, showOptionsLink);
document.addEventListener("click", onClick); document.addEventListener("click", onClick);