DocumentServer/OnlineEditorsExample/OnlineEditorsExampleRuby/app/views/home/editor.html.erb
2015-04-29 19:10:50 +03:00

147 lines
4.7 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div class="form">
<div id="iframeEditor">
</div>
</div>
<script src="<%= Rails.configuration.urlApi %>"></script>
<script type="text/javascript" language="javascript">
var docEditor;
var fileName = "<%= @file.file_name %>";
var fileType = "<%= @file.file_ext.delete('.') %>";
var innerAlert = function (message) {
if (console && console.log)
console.log(message);
};
var onReady = function () {
innerAlert("Document editor ready");
};
var onBack = function () {
location.href = "<%= root_path %>";
};
var onDocumentStateChange = function (event) {
var title = document.title.replace(/\*$/g, "");
document.title = title + (event.data ? "*" : "");
};
var onRequestEditRights = function () {
if (typeof DocsAPI.DocEditor.version == "function") {
var version = DocsAPI.DocEditor.version();
if ((parseFloat(version) || 0) >= 3) {
location.href = location.href.replace(RegExp("action=view?&", "i"), "");
return;
}
}
docEditor.applyEditRights(true);
};
var onDocumentSave = function (event) {
SaveFileRequest(fileName, fileType, event.data);
};
var onError = function (event) {
if (console && console.log && event)
console.log(event.data);
};
var сonnectEditor = function () {
docEditor = new DocsAPI.DocEditor("iframeEditor",
{
width: "100%",
height: "100%",
type: "<%= @file.desktop_type ? 'desktop' : 'embedded' %>",
documentType: "<%= @file.document_type %>",
document: {
title: fileName,
url: "<%= @file.file_uri %>",
fileType: fileType,
key: "<%= @file.key %>",
vkey: "<%= @file.validate_key %>",
info: {
author: "Me",
created: "<%= Time.now.to_s %>"
},
permissions: {
edit: "<%= (DocumentHelper.edited_exts.include? @file.file_ext).to_s %>" == "true",
download: true
}
},
editorConfig: {
mode: "<%= (DocumentHelper.edited_exts.include? @file.file_ext) && @file.mode != 'view' ? 'edit' : 'view' %>",
lang: "en",
callbackUrl: "<%= raw @file.callback_url %>",
embedded: {
saveUrl: "<%= @file.file_uri %>",
embedUrl: "<%= @file.file_uri %>",
shareUrl: "<%= @file.file_uri %>",
toolbarDocked: "top"
}
},
events: {
'onReady': onReady,
'onBack': "<%= @file.desktop_type.to_s %>" == "true" ? onBack : undefined,
'onDocumentStateChange': onDocumentStateChange,
'onSave': onDocumentSave,
'onError': onError
}
});
};
if (window.addEventListener) {
window.addEventListener("load", сonnectEditor);
} else if (window.attachEvent) {
window.attachEvent("load", сonnectEditor);
}
function getXmlHttp() {
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (ex) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function SaveFileRequest(fileName, fileType, fileUri) {
var req = getXmlHttp();
if (console && console.log) {
req.onreadystatechange = function () {
if (req.readyState == 4) {
console.log(req.statusText);
if (req.status == 200) {
console.log(req.responseText);
}
}
};
}
var requestAddress = "<%= save_url %>"
+ "?filename=" + encodeURIComponent(fileName)
+ "&filetype=" + encodeURIComponent(fileType)
+ "&fileuri=" + encodeURIComponent(fileUri);
req.open('get', requestAddress, true);
req.send(fileUri);
}
</script>