diff --git a/share/static/js/libs/svg-edit/extensions/ext-server_opensave.js b/share/static/js/libs/svg-edit/extensions/ext-server_opensave.js
index 8e1849c881..9f2aa82876 100644
--- a/share/static/js/libs/svg-edit/extensions/ext-server_opensave.js
+++ b/share/static/js/libs/svg-edit/extensions/ext-server_opensave.js
@@ -29,8 +29,8 @@ svgEditor.addExtension("server_opensave", {
return true;
}
}
- var open_svg_action, import_svg_action, import_img_action,
- open_svg_form, import_svg_form, import_img_form,
+ var open_svg_action, import_svg_action, import_img_action, reimport_img_action,
+ open_svg_form, import_svg_form, import_img_form, reimport_img_form,
save_svg_action = svgEditor.curConfig.extPath + 'filesave.php',
save_img_action = svgEditor.curConfig.extPath + 'filesave.php',
// Create upload target (hidden iframe)
@@ -114,6 +114,7 @@ svgEditor.addExtension("server_opensave", {
import_svg_action = svgEditor.curConfig.extPath + 'fileopen.php?type=import_svg';
//import_img_action = svgEditor.curConfig.extPath + 'fileopen.php?type=import_img';
import_img_action = '/invoicetemplate/embedimage?type=import_img';
+ reimport_img_action = '/invoicetemplate/embedimage?type=reimport_img';
// Set up function for PHP uploader to use
svgEditor.processFile = function(str64, type) {
@@ -124,7 +125,7 @@ svgEditor.addExtension("server_opensave", {
}
$('#dialog_box').hide();
- if (type !== 'import_img') {
+ if (type !== 'import_img' && type !== 'reimport_img') {
xmlstr = svgedit.utilities.decode64(str64);
}
@@ -141,6 +142,9 @@ svgEditor.addExtension("server_opensave", {
case 'import_img':
svgCanvas.setGoodImage(str64);
break;
+ case 'reimport_img':
+ svgEditor.setImageURL(str64);
+ break;
}
};
@@ -158,6 +162,7 @@ svgEditor.addExtension("server_opensave", {
// Create image form
import_img_form = open_svg_form.clone().attr('action', import_img_action);
+ reimport_img_form = open_svg_form.clone().attr({'action': reimport_img_action,style: "visibility:hidden;width: 20px; height: 1px;"});
// It appears necessary to rebuild this input every time a file is
// selected so the same file can be picked and the change event can fire.
@@ -200,11 +205,13 @@ svgEditor.addExtension("server_opensave", {
rebuildInput(open_svg_form);
rebuildInput(import_svg_form);
rebuildInput(import_img_form);
+ rebuildInput(reimport_img_form);
// Add forms to buttons
$("#tool_open").show().prepend(open_svg_form);
$("#tool_import").show().prepend(import_svg_form);
$("#tool_image").prepend(import_img_form);
+ $("#change_image_url").prepend(reimport_img_form);
}
});
diff --git a/share/static/js/libs/svg-edit/svg-editor.htm b/share/static/js/libs/svg-edit/svg-editor.htm
index cb567ac410..f8339f4a3e 100644
--- a/share/static/js/libs/svg-edit/svg-editor.htm
+++ b/share/static/js/libs/svg-edit/svg-editor.htm
@@ -293,12 +293,13 @@ by creating the following file and adding by calls to svgEditor.setConfig -->
diff --git a/share/static/js/libs/svg-edit/svg-editor.js b/share/static/js/libs/svg-edit/svg-editor.js
index 4c94662c2a..1f856472ac 100644
--- a/share/static/js/libs/svg-edit/svg-editor.js
+++ b/share/static/js/libs/svg-edit/svg-editor.js
@@ -1144,27 +1144,114 @@ TO-DOS
}
};
- var setImageURL = editor.setImageURL = function(url) {
+ var setImageURL = editor.setImageURL = function(url, useImageData) {
if (!url) {
url = defaultImageURL;
}
- svgCanvas.setImageURL(url);
- $('#image_url').val(url);
-
- if (url.indexOf('data:') === 0) {
- // data URI found
- $('#image_url').hide();
- $('#change_image_url').show();
- } else {
- // regular URL
- svgCanvas.embedImage(url, function(dataURI) {
- // Couldn't embed, so show warning
- $('#url_notice').toggle(!dataURI);
- defaultImageURL = url;
- });
- $('#image_url').show();
- $('#change_image_url').hide();
- }
+ useImageData = 0;
+ var setImageUrlOrData = function(url){
+ svgCanvas.setImageURL(url);
+ $('#image_url').val(url);
+
+ if (url.indexOf('data:') === 0) {
+ // data URI found
+ $('#image_url').hide();
+ $('#change_image_url').show();
+ } else {
+ // regular URL
+ svgCanvas.embedImage(url, function(dataURI) {
+ // Couldn't embed, so show warning
+ $('#url_notice').toggle(!dataURI);
+ defaultImageURL = url;
+ });
+ $('#image_url').show();
+ $('#change_image_url').hide();
+ }
+ };
+ //all solution ideas are from https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data
+ //It is more reliable not to store original link and get image content on stage od saving to DB or even generation, as backend and moreover generation script may doesn't have access to the image url (which can be accessed using cookies and so on)
+ if(useImageData){
+ var loadBinary = function(url,callback) {
+ var xmlHttpReq = false;
+ //alert(q);
+
+ if (window.XMLHttpRequest) {
+ xmlHttpReq = new XMLHttpRequest();
+ } else if (window.ActiveXObject) {
+ xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
+ }
+
+ xmlHttpReq.open('GET', url, true);
+ //XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com]
+ //this doesn't work - data are broken anyway
+ //if(xmlHttpReq.overrideMimeType){
+ // xmlHttpReq.overrideMimeType('text\/plain; charset=x-user-defined');
+ //}
+ xmlHttpReq.responseType = "arraybuffer";
+
+ if(callback){
+ xmlHttpReq.onreadystatechange = function(){
+ if (xmlHttpReq.readyState == 4) {
+ if(typeof callback == 'function'){
+ callback(xmlHttpReq);
+ }else{
+ eval(callback);
+ }
+ }
+ }
+ }
+ xmlHttpReq.send(null);
+ };
+ //two functions from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding#Solution_.232_.E2.80.93_rewriting_atob()_and_btoa()_using_TypedArrays_and_UTF-8
+ function uint6ToB64 (nUint6) {
+ return nUint6 < 26 ?
+ nUint6 + 65
+ : nUint6 < 52 ?
+ nUint6 + 71
+ : nUint6 < 62 ?
+ nUint6 - 4
+ : nUint6 === 62 ?
+ 43
+ : nUint6 === 63 ?
+ 47
+ :
+ 65;
+ };
+ function base64EncArr (aBytes) {
+ var nMod3 = 2, sB64Enc = "";
+ for (var nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {
+ nMod3 = nIdx % 3;
+ if (nIdx > 0 && (nIdx * 4 / 3) % 76 === 0) { sB64Enc += "\r\n"; }
+ nUint24 |= aBytes[nIdx] << (16 >>> nMod3 & 24);
+ if (nMod3 === 2 || aBytes.length - nIdx === 1) {
+ sB64Enc += String.fromCharCode(uint6ToB64(nUint24 >>> 18 & 63), uint6ToB64(nUint24 >>> 12 & 63), uint6ToB64(nUint24 >>> 6 & 63), uint6ToB64(nUint24 & 63));
+ nUint24 = 0;
+ }
+ }
+ return sB64Enc.substr(0, sB64Enc.length - 2 + nMod3) + (nMod3 === 2 ? '' : nMod3 === 1 ? '=' : '==');
+ };
+
+ var imageDataCallback = function(request){
+ var contentType = ''+request.getResponseHeader('Content-Type');
+ contentType = contentType.replace(/image\/x\-/i,'image/');
+ var content = '';
+ //if(request.responseBody){//ie
+ // content = request.responseBody;
+ // url = 'data:'+contentType+';base64,'+svgedit.utilities.encode64(content);
+ //}else if(request.response){
+ content = request.response;
+ var byteArray = new Uint8Array(content);
+ url = 'data:'+contentType+';base64,'+base64EncArr(byteArray);
+ //}else{
+ // content = request.responseText;
+ // url = 'data:'+contentType+';base64,'+svgedit.utilities.encode64(content);
+ //}
+ setImageUrlOrData(url);
+ };
+ loadBinary(url,imageDataCallback);
+ }else{
+ setImageUrlOrData(url);
+ }
};
function setBackground (color, url) {
@@ -1180,7 +1267,7 @@ TO-DOS
var curhref = svgCanvas.getHref(selectedElement);
curhref = curhref.indexOf('data:') === 0 ? '' : curhref;
$.prompt(uiStrings.notification.enterNewImgURL, curhref, function(url) {
- if (url) {setImageURL(url);}
+ if (url) {setImageURL(url, 1);}//useImageData=1
});
}
@@ -2962,7 +3049,7 @@ TO-DOS
});
$('#image_url').change(function() {
- setImageURL(this.value);
+ setImageURL(this.value, 1);//useImageData = 1
});
$('#link_url').change(function() {
@@ -3920,7 +4007,7 @@ TO-DOS
$.alert(this.title);
});
- $('#change_image_url').click(promptImgURL);
+ //$('#change_image_url').click(promptImgURL);
// added these event handlers for all the push buttons so they
// behave more like buttons being pressed-in and not images
diff --git a/share/templates/invoice/template_editor_aux_embedimage.tt b/share/templates/invoice/template_editor_aux_embedimage.tt
index d36ec7081c..b1e58945b8 100644
--- a/share/templates/invoice/template_editor_aux_embedimage.tt
+++ b/share/templates/invoice/template_editor_aux_embedimage.tt
@@ -3,7 +3,7 @@