mirror of
https://github.com/qurator-spk/neat.git
synced 2025-06-11 12:49:53 +02:00
make ner.edith detect if user actually saved the file successfully
This commit is contained in:
parent
bcfb8220d3
commit
3173d0c2ff
1 changed files with 47 additions and 5 deletions
52
ner-edith.js
52
ner-edith.js
|
@ -48,23 +48,63 @@ function loadFile(evt, onComplete) {
|
|||
|
||||
function setupInterface(data, file, urls) {
|
||||
|
||||
var displayRows=30
|
||||
var startIndex=0;
|
||||
var endIndex=displayRows;
|
||||
let displayRows=30
|
||||
let startIndex=0;
|
||||
let endIndex=displayRows;
|
||||
|
||||
var has_changes = false;
|
||||
let has_changes = false;
|
||||
var save_timeout = null;
|
||||
|
||||
function notifyChange() {
|
||||
if (save_timeout != null) clearTimeout(save_timeout);
|
||||
has_changes = true;
|
||||
|
||||
$("#save").attr('disabled', false);
|
||||
}
|
||||
|
||||
function resetChanged() {
|
||||
if (save_timeout != null) clearTimeout(save_timeout);
|
||||
|
||||
$("#save").attr('disabled', true);
|
||||
has_changes = false;
|
||||
}
|
||||
|
||||
function checkForSave (csv) {
|
||||
|
||||
if (save_timeout != null) clearTimeout(save_timeout);
|
||||
|
||||
// This is a work-around that checks if the user actually saved the file or if the save dialog was cancelled.
|
||||
let counter = 0;
|
||||
let checker =
|
||||
function() {
|
||||
console.log('checker ...', counter);
|
||||
|
||||
if (counter > 20) return;
|
||||
|
||||
let reader = new FileReader();
|
||||
|
||||
reader.onload =
|
||||
function(event) {
|
||||
|
||||
let content = event.target.result;
|
||||
|
||||
if (content == csv) { // ok content of the file is actually equal to desired content.
|
||||
console.log('Save success ...');
|
||||
resetChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
counter++;
|
||||
save_timeout = setTimeout(checker, 3000);
|
||||
};
|
||||
|
||||
reader.readAsText(file);
|
||||
};
|
||||
|
||||
save_timeout = setTimeout(checker, 3000);
|
||||
};
|
||||
|
||||
// public interface
|
||||
var that =
|
||||
{
|
||||
hasChanges: function () { return has_changes; }
|
||||
|
@ -490,7 +530,9 @@ function setupInterface(data, file, urls) {
|
|||
|
||||
csv = csv.join('\n');
|
||||
|
||||
openSaveFileDialog (csv, file.name, null)
|
||||
openSaveFileDialog (csv, file.name, null);
|
||||
|
||||
checkForSave(csv);
|
||||
}
|
||||
|
||||
function openSaveFileDialog (data, filename, mimetype) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue