|
@@ -12,7 +12,7 @@ AC.autoExit = true;
|
|
|
// Last Checked on 08-AUG-2017: No delete scope needed to delete drafts
|
|
|
// LATER: If delete scope is needed users must upgrade to the latest json
|
|
|
// Disabled. Flag to mute notifications for drafts is needed. 16-AUG-2017
|
|
|
-AC.draftEnabled = true; //Enabled with the new save that mute notifications for saving TODO is there notification for deleting a draft?
|
|
|
+AC.draftEnabled = false;
|
|
|
|
|
|
AC.getUrlParam = function(param, escape, url){
|
|
|
try{
|
|
@@ -30,32 +30,6 @@ AC.getMetaTag = function(name) {
|
|
|
return document.getElementsByTagName('meta')[name].getAttribute('content');
|
|
|
}
|
|
|
|
|
|
-//Code from: https://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript
|
|
|
-AC.b64toBlob = function(b64Data, contentType, sliceSize, isByteCharacters)
|
|
|
-{
|
|
|
- contentType = contentType || '';
|
|
|
- sliceSize = sliceSize || 512;
|
|
|
-
|
|
|
- var byteCharacters = isByteCharacters? b64Data : atob(b64Data);
|
|
|
- var byteArrays = [];
|
|
|
-
|
|
|
- for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
|
|
- var slice = byteCharacters.slice(offset, offset + sliceSize);
|
|
|
-
|
|
|
- var byteNumbers = new Array(slice.length);
|
|
|
- for (var i = 0; i < slice.length; i++) {
|
|
|
- byteNumbers[i] = slice.charCodeAt(i);
|
|
|
- }
|
|
|
-
|
|
|
- var byteArray = new Uint8Array(byteNumbers);
|
|
|
-
|
|
|
- byteArrays.push(byteArray);
|
|
|
- }
|
|
|
-
|
|
|
- var blob = new Blob(byteArrays, {type: contentType});
|
|
|
- return blob;
|
|
|
- }
|
|
|
-
|
|
|
AC.initAsync = function(baseUrl)
|
|
|
{
|
|
|
var link = document.createElement('a');
|
|
@@ -100,6 +74,7 @@ AC.initAsync = function(baseUrl)
|
|
|
var filename = null;
|
|
|
var theMacroData = null;
|
|
|
var pageId = null;
|
|
|
+ var draftPage = false;
|
|
|
var theLocation = null;
|
|
|
var attachments = null;
|
|
|
|
|
@@ -120,7 +95,7 @@ AC.initAsync = function(baseUrl)
|
|
|
{
|
|
|
if (initReceived && xmlReceived != null && draftHandled && !waitingForAttachments)
|
|
|
{
|
|
|
- AC.init(baseUrl, theLocation, pageId, editor, filename, xmlReceived, draftName, draftXml, theMacroData);
|
|
|
+ AC.init(baseUrl, theLocation, pageId, editor, filename, xmlReceived, draftName, draftXml, theMacroData, draftPage);
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -242,6 +217,7 @@ AC.initAsync = function(baseUrl)
|
|
|
if (data != null && data.target != null && data.context!= null &&
|
|
|
(data.target == 'contentedit' || data.target == 'contentcreate'))
|
|
|
{
|
|
|
+ draftPage = (data.target == 'contentcreate');
|
|
|
pageId = data.context.contentId;
|
|
|
}
|
|
|
|
|
@@ -409,7 +385,7 @@ AC.initAsync = function(baseUrl)
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-AC.init = function(baseUrl, location, pageId, editor, diagramName, initialXml, draftName, draftXml, macroData)
|
|
|
+AC.init = function(baseUrl, location, pageId, editor, diagramName, initialXml, draftName, draftXml, macroData, draftPage)
|
|
|
{
|
|
|
// Hides the logo
|
|
|
document.body.style.backgroundImage = 'none';
|
|
@@ -442,7 +418,7 @@ AC.init = function(baseUrl, location, pageId, editor, diagramName, initialXml, d
|
|
|
//console.trace('DRAFT: Save', draftName, xml);
|
|
|
|
|
|
AC.saveDiagram(pageId, draftName,
|
|
|
- xml,
|
|
|
+ btoa(unescape(encodeURIComponent(xml))),
|
|
|
function(res)
|
|
|
{
|
|
|
var obj = null;
|
|
@@ -496,7 +472,7 @@ AC.init = function(baseUrl, location, pageId, editor, diagramName, initialXml, d
|
|
|
err(obj);
|
|
|
}
|
|
|
}
|
|
|
- }, false, 'text/plain', 'Created by Draw.io');
|
|
|
+ }, false, 'text/plain', 'Created by Draw.io', false, draftPage);
|
|
|
};
|
|
|
|
|
|
function showTemplateDialog()
|
|
@@ -959,7 +935,7 @@ AC.init = function(baseUrl, location, pageId, editor, diagramName, initialXml, d
|
|
|
}
|
|
|
else if (drawMsg.event == 'save')
|
|
|
{
|
|
|
- diagramXml = drawMsg.xml;
|
|
|
+ diagramXml = btoa(unescape(encodeURIComponent(drawMsg.xml)));
|
|
|
|
|
|
if (diagramName == null)
|
|
|
{
|
|
@@ -1051,10 +1027,9 @@ AC.init = function(baseUrl, location, pageId, editor, diagramName, initialXml, d
|
|
|
|
|
|
// LATER: Get revision from metadata of attachment and check
|
|
|
// what condition makes the response not contain an URL
|
|
|
- //TODO Is prev comment still needed with REST API?
|
|
|
- if (resp != null && resp.results != null && resp.results[0])
|
|
|
+ if (resp != null && resp.url != null)
|
|
|
{
|
|
|
- revision = resp.results[0].version.number;
|
|
|
+ revision = resp.url.match(/version=(\d+)/i)[1];
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1115,7 +1090,7 @@ AC.init = function(baseUrl, location, pageId, editor, diagramName, initialXml, d
|
|
|
|
|
|
if (diagramName != null)
|
|
|
{
|
|
|
- AC.saveDiagram(pageId, diagramName + '.png', AC.b64toBlob(imageData, 'image/png'),
|
|
|
+ AC.saveDiagram(pageId, diagramName + '.png', imageData,
|
|
|
successPng, saveError, false, 'image/png');
|
|
|
}
|
|
|
};
|
|
@@ -1126,7 +1101,7 @@ AC.init = function(baseUrl, location, pageId, editor, diagramName, initialXml, d
|
|
|
show: true, messageKey: 'saving'}), '*');
|
|
|
|
|
|
AC.saveDiagram(pageId, diagramName, diagramXml,
|
|
|
- successXml, saveError, false, 'text/plain');
|
|
|
+ successXml, saveError, false, 'text/plain', 'draw.io diagram', false, draftPage);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1183,9 +1158,17 @@ AC.loadDiagram = function (pageId, diagramName, revision, success, error, owning
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-//TODO We can upload both the diagram and its png in one call if needed?
|
|
|
-AC.saveDiagram = function(pageId, diagramName, xml, success, error, newSave, mime, comment, sendNotif)
|
|
|
+AC.saveDiagram = function(pageId, diagramName, xml, success, error, newSave, mime, comment)
|
|
|
{
|
|
|
+ var attachment = {fileName: diagramName, contentType: mime};
|
|
|
+
|
|
|
+ if (comment != null)
|
|
|
+ {
|
|
|
+ attachment.comment = comment;
|
|
|
+ }
|
|
|
+
|
|
|
+ var params = [pageId, attachment, xml];
|
|
|
+
|
|
|
loadSucess = function(resp)
|
|
|
{
|
|
|
error({status: 409, message: 'File already exists'});
|
|
@@ -1209,7 +1192,7 @@ AC.saveDiagram = function(pageId, diagramName, xml, success, error, newSave, mim
|
|
|
{
|
|
|
var obj = JSON.parse(responseText);
|
|
|
|
|
|
- if (obj != null && obj.code == -32600) //TODO is the codes the same with new REST APIs
|
|
|
+ if (obj != null && obj.code == -32600)
|
|
|
{
|
|
|
error({status: 401});
|
|
|
|
|
@@ -1222,25 +1205,19 @@ AC.saveDiagram = function(pageId, diagramName, xml, success, error, newSave, mim
|
|
|
|
|
|
doSave = function()
|
|
|
{
|
|
|
+ // Workaround for encoding problems
|
|
|
+ var data = JSON.stringify(params);
|
|
|
+
|
|
|
AP.require(['request'], function(request)
|
|
|
{
|
|
|
- var blob = (xml instanceof Blob)? xml : new Blob([xml], {type: mime});
|
|
|
- var attFile = new File([blob], diagramName);
|
|
|
- var reqData = {file: attFile, minorEdit: sendNotif? false : true};
|
|
|
-
|
|
|
- if (comment != null)
|
|
|
- {
|
|
|
- reqData.comment = comment;
|
|
|
- }
|
|
|
-
|
|
|
- request({
|
|
|
- type: 'PUT',
|
|
|
- data: reqData,
|
|
|
- url: "/rest/api/content/"+ pageId +"/child/attachment",
|
|
|
- contentType: "multipart/form-data",
|
|
|
+ request({
|
|
|
+ type: 'POST',
|
|
|
+ data: data,
|
|
|
+ url: '/rpc/json-rpc/confluenceservice-v2/addAttachment',
|
|
|
+ contentType: 'application/json;charset=UTF-8',
|
|
|
success: sessionCheck,
|
|
|
error: error
|
|
|
- });
|
|
|
+ });
|
|
|
});
|
|
|
};
|
|
|
|
|
@@ -1296,42 +1273,4 @@ AC.getMacroData = function(fn) {
|
|
|
AP.require('confluence', function(confluence) {
|
|
|
confluence.getMacroData(fn);
|
|
|
});
|
|
|
-}
|
|
|
-
|
|
|
-//From mxUtils
|
|
|
-AC.htmlEntities = function(s, newline)
|
|
|
-{
|
|
|
- s = String(s || '');
|
|
|
-
|
|
|
- s = s.replace(/&/g,'&'); // 38 26
|
|
|
- s = s.replace(/"/g,'"'); // 34 22
|
|
|
- s = s.replace(/\'/g,'''); // 39 27
|
|
|
- s = s.replace(/</g,'<'); // 60 3C
|
|
|
- s = s.replace(/>/g,'>'); // 62 3E
|
|
|
-
|
|
|
- if (newline == null || newline)
|
|
|
- {
|
|
|
- s = s.replace(/\n/g, '
');
|
|
|
- }
|
|
|
-
|
|
|
- return s;
|
|
|
-};
|
|
|
-
|
|
|
-AC.fromHtmlEntities = function(s, newline)
|
|
|
-{
|
|
|
- s = String(s || '');
|
|
|
-
|
|
|
- s = s.replace(/&/g,'&'); // 38 26
|
|
|
- s = s.replace(/"/g,'"'); // 34 22
|
|
|
- s = s.replace(/'/g,'\\'); // 39 27
|
|
|
- s = s.replace(/</g,'<'); // 60 3C
|
|
|
- s = s.replace(/>/g,'>'); // 62 3E
|
|
|
-
|
|
|
- if (newline == null || newline)
|
|
|
- {
|
|
|
- s = s.replace(/
/g, '\n');
|
|
|
- }
|
|
|
-
|
|
|
- return s;
|
|
|
-};
|
|
|
-
|
|
|
+}
|