Skip to content

Commit

Permalink
fix #8
Browse files Browse the repository at this point in the history
  • Loading branch information
Paolo Greppi committed Jul 3, 2018
1 parent 41e19c7 commit 3b0ec36
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
all:
cp fatturaPA_1.2_schema.json www/.
cp fatturaPA_1.2.hbs www/.
cp samples/IT01234567890_FPA01.json www/.
cp samples/IT01234567890_FPA01-js.json www/.
mkdir -p www/js
cp node_modules/@json-editor/json-editor/dist/jsoneditor.min.js www/js/.
cp node_modules/handlebars/dist/handlebars.min.js www/js/.
File renamed without changes.
44 changes: 37 additions & 7 deletions www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,24 @@ <h1>Editor per fattura elettronica basato sullo schema JSON</h1>
<p>
Codice sorgente: <a href="https://github.com/simevo/fattura-elettronica-json">https://github.com/simevo/fattura-elettronica-json</a>
</p>
<button id='json'>Carica una fattura in formato JSON</button>
<button id='genera'>Genera e visualizza la fattura in formato XML</button>
<div>
<button id='carica_json'>Carica una fattura di esempio in formato JSON</button>
</div>
<hr/>
<div>
<form enctype="multipart/form-data" method="post" id="xml_fileinfo">
<label>File fattura in formato XML:</label>
<input type="file" name="xml" required id="xml"/>
</form>
<button id='carica_xml'>Carica fattura XML</button>
</div>
<hr/>
<div>
<button id='genera'>Genera e visualizza la fattura in formato XML</button>
</div>
<hr/>
<button id='resetta'>Resetta il form</button>
<pre id="xml"></pre>
<pre id="xml_result"></pre>
<hr/>
<div id='editor_holder'></div>
<script type="text/javascript">
Expand All @@ -44,15 +58,15 @@ <h1>Editor per fattura elettronica basato sullo schema JSON</h1>
var template = Handlebars.compile(source);
var context = editor.getValue();
var xml = template(context);
document.getElementById("xml").innerText = xml;
document.getElementById("xml_result").innerText = xml;
}
}
};
request.send();
};
document.getElementById("json").onclick = function() {
document.getElementById("carica_json").onclick = function() {
var request = new XMLHttpRequest();
request.open("GET", "IT01234567890_FPA01.json");
request.open("GET", "IT01234567890_FPA01-js.json");
request.onload = function() {
if (request.status == 200) {
if (request.responseText) {
Expand All @@ -63,9 +77,25 @@ <h1>Editor per fattura elettronica basato sullo schema JSON</h1>
};
request.send();
};
document.getElementById("carica_xml").onclick = function() {
var request = new XMLHttpRequest();
request.open("POST", "/xml2json.php");
var form = document.getElementById("xml_fileinfo");
var data_to = new FormData(form);
console.log(data_to);
request.onload = function() {
if (request.status == 200) {
if (request.responseText) {
var json = JSON.parse(request.responseText);
editor.setValue(json);
}
}
};
request.send(data_to);
};
document.getElementById("resetta").onclick = function() {
var context = editor.setValue({});
document.getElementById("xml").innerText = '';
document.getElementById("xml_result").innerText = '';
};
</script>
</body>
Expand Down

0 comments on commit 3b0ec36

Please sign in to comment.