PDF editor: share source code

This commit is contained in:
Raphael Michel
2017-06-28 18:36:45 +02:00
parent ea970be6f2
commit 80ad0e7f68
3 changed files with 56 additions and 0 deletions

View File

@@ -39,3 +39,16 @@ body {
.preload-font {
visibility: hidden;
}
#source-container {
position: absolute;
top: 0;
left: 0;
height: 100%;
background: white;
width: 100%;
text-align: center;
}
#source-container textarea {
width: 100%;
height: 250px;
}

View File

@@ -629,6 +629,20 @@ var editor = {
editor._load_pdf(d);
},
_source_show: function () {
$("#source-textarea").text(JSON.stringify(editor.dump()));
$("#source-container").show();
},
_source_close: function () {
$("#source-container").hide();
},
_source_save: function () {
editor.load(JSON.parse($("#source-textarea").val()));
$("#source-container").hide();
},
init: function () {
editor.$pdfcv = $("#pdf-canvas");
editor.pdf_url = editor.$pdfcv.attr("data-pdf-url");
@@ -646,6 +660,7 @@ var editor = {
return gettext("Do you really want to leave the editor without saving your changes?");
}
};
$("#source-container").hide();
$('#fileupload').fileupload({
@@ -704,6 +719,9 @@ var editor = {
$("#toolbox-paste").bind('click', editor._paste);
$("#toolbox-undo").bind('click', editor._undo);
$("#toolbox-redo").bind('click', editor._redo);
$("#toolbox-source").bind('click', editor._source_show);
$("#source-close").bind('click', editor._source_close);
$("#source-save").bind('click', editor._source_save);
}
};

View File

@@ -14,6 +14,10 @@
<div class="panel-heading">
<div class="pull-right">
<div class="btn-group">
<button type="button" class="btn btn-default btn-xs" id="toolbox-source"
title="{% trans "Code" %}">
<span class="fa fa-code"></span>
</button>
<button type="button" class="btn btn-default btn-xs" id="toolbox-paste"
title="{% trans "Paste" %}">
<span class="fa fa-paste"></span>
@@ -45,6 +49,27 @@
<canvas id="fabric-canvas">
</canvas>
</div>
<div id="source-container">
<div class="alert alert-warning">
<strong>
{% blocktrans trimmed %}
This feature is only intended for advanced users. We recommend to only use it
to copy and share ticket designs, not to modify the design source code.
{% endblocktrans %}
</strong>
</div>
<p>
<textarea id="source-textarea" class="form-control"></textarea>
</p>
<p class="text-right">
<button class="btn btn-default" id="source-close">
{% trans "Cancel" %}
</button>
<button class="btn btn-default" id="source-save">
{% trans "Save" %}
</button>
</p>
</div>
<div id="loading-container">
<div id="loading-upload">
<span class="fa fa-cog big-rotating-icon"></span>