Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions resources/vendor/ign/gpao.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,26 @@ function sendProject(json){
});
}

//Fonction qui définit si le json est correcte
function isJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
alert('JSON invalide')
return false;
}
return true;
}

// Fonction qui importe un projet via un fichier json
function jsonChanged(file) {
var reader = new FileReader();
reader.addEventListener('load', function(e) {
// contents of file in variable
var json = e.target.result;
sendProject(json);
if(isJsonString(json)) {
sendProject(json);
}
});
// read as text file
reader.readAsText(file);
Expand Down Expand Up @@ -52,7 +65,9 @@ function txtChanged(file, tags) {
reader.addEventListener('load', function(e) {
var text = e.target.result.split(/\r\n|\n/);
var json = createJson(file.name, text, tags);
sendProject(json);
if(isJsonString(json)) {
sendProject(json);
}
});
// read as text file
reader.readAsText(file);
Expand Down Expand Up @@ -304,4 +319,4 @@ function validateTags(domTags, btnSubmit) {
btn.disabled = false;
}
}
}
}