Skip to content

Commit

Permalink
Add alert dialogs for import error/success
Browse files Browse the repository at this point in the history
  • Loading branch information
proginosko committed Dec 17, 2017
1 parent 303cfd5 commit d8d1065
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@
<div id="alertNoImportFile" title="LeechBlock Options">
<p>Please select a file containing the options to import.</p>
</div>
<div id="alertImportError" title="LeechBlock Options">
<p><strong>Error:</strong> Unable to import options from file.</p>
</div>
<div id="alertImportSuccess" title="LeechBlock Options">
<p>The options have been imported successfully.</p>
</div>
<div id="alertLockdownCancel" title="LeechBlock Options">
<p>The active lockdown has been canceled.</p>
</div>
Expand Down
11 changes: 10 additions & 1 deletion options.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ function importOptions() {
function processImportFile(event) {
let text = event.target.result;
if (!text) {
warn("Cannot import options from file.");
$("#alertImportError").dialog("open");
return;
}

Expand All @@ -444,13 +444,20 @@ function importOptions() {
let regexp = /^(\w+)=(.*)$/;
let lines = text.split(/[\n\r]+/);
let options = {};
let hasOptions = false;
for (let line of lines) {
let results = regexp.exec(line);
if (results) {
options[results[1]] = results[2];
hasOptions = true;
}
}

if (!hasOptions) {
$("#alertImportError").dialog("open");
return;
}

for (let set = 1; set <= NUM_SETS; set++) {
// Get option values
let setName = options[`setName${set}`];
Expand Down Expand Up @@ -610,6 +617,8 @@ function importOptions() {
if (contextMenu != undefined) {
getElement("contextMenu").checked = contextMenu;
}

$("#alertImportSuccess").dialog("open");
}
}

Expand Down

0 comments on commit d8d1065

Please sign in to comment.