mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-02-10 18:05:10 +08:00
308 lines
11 KiB
JavaScript
308 lines
11 KiB
JavaScript
/*
|
|
*
|
|
* (c) Copyright Ascensio System Limited 2010-2016
|
|
*
|
|
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
|
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
|
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
|
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
|
*
|
|
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
|
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
|
*
|
|
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
|
*
|
|
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
|
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
|
*
|
|
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
|
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
|
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
|
* in every copy of the program you distribute.
|
|
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
|
*
|
|
*/
|
|
|
|
var language;
|
|
var userid;
|
|
var firstname;
|
|
var lastname;
|
|
|
|
if (typeof jQuery != "undefined") {
|
|
jq = jQuery.noConflict();
|
|
|
|
firstname = getUrlVars()["firstname"];
|
|
lastname = getUrlVars()["lastname"];
|
|
userid = getUrlVars()["userid"];
|
|
language = getUrlVars()["lang"];
|
|
|
|
if ("" != language && undefined != language)
|
|
jq("#language").val(language);
|
|
else
|
|
language = jq("#language").val();
|
|
|
|
|
|
jq("#language").change(function() {
|
|
var user = jq('#user option:selected').text();
|
|
var arUser = user.split(' ');
|
|
firstname = arUser[0];
|
|
//alert(language);
|
|
lastname = arUser[1];
|
|
window.location = "?lang=" + jq(this).val() + "&userid=" + userid + "&firstname=" + firstname + "&lastname=" + lastname;
|
|
});
|
|
|
|
|
|
if ("" != userid && undefined != userid)
|
|
jq("#user").val(userid);
|
|
else
|
|
userid = jq("#user").val();
|
|
|
|
if ("" != firstname && undefined != firstname)
|
|
firstname=getUrlVars()["firstname"];
|
|
else{
|
|
var user = jq('#user option:selected').text();
|
|
var arUser = user.split(' ');
|
|
firstname = arUser[0];
|
|
}
|
|
if ("" != lastname && undefined != lastname)
|
|
lastname=getUrlVars()["lastname"];
|
|
else{
|
|
var user = jq('#user option:selected').text();
|
|
var arUser = user.split(' ');
|
|
lastname = arUser[1];
|
|
}
|
|
|
|
jq("#user").change(function() {
|
|
var user = jq('#user option:selected').text();
|
|
var arUser = user.split(' ');
|
|
firstname = arUser[0];
|
|
lastname = arUser[1];
|
|
|
|
//var fn = jq('#user option:selected').attr('value-fn');
|
|
window.location = "?lang=" + language + "&userid=" + jq(this).val() + "&firstname=" + arUser[0] + "&lastname=" + arUser[1];
|
|
});
|
|
|
|
jq(function () {
|
|
jq('#fileupload').fileupload({
|
|
dataType: 'json',
|
|
add: function (e, data) {
|
|
jq(".error").removeClass("error");
|
|
jq(".done").removeClass("done");
|
|
jq(".current").removeClass("current");
|
|
jq("#step1").addClass("current");
|
|
jq("#mainProgress .error-message").hide().find("span").text("");
|
|
jq("#mainProgress").removeClass("embedded");
|
|
|
|
jq.blockUI({
|
|
theme: true,
|
|
title: "Getting ready to load the file" + "<div class=\"dialog-close\"></div>",
|
|
message: jq("#mainProgress"),
|
|
overlayCSS: { "background-color": "#aaa" },
|
|
themedCSS: { width: "656px", top: "20%", left: "50%", marginLeft: "-328px" }
|
|
});
|
|
jq("#beginEdit, #beginView, #beginEmbedded").addClass("disable");
|
|
|
|
data.submit();
|
|
},
|
|
always: function (e, data) {
|
|
if (!jq("#mainProgress").is(":visible")) {
|
|
return;
|
|
}
|
|
var response = data.result;
|
|
if (!response || response.error) {
|
|
jq(".current").removeClass("current");
|
|
jq(".step:not(.done)").addClass("error");
|
|
jq("#mainProgress .error-message").show().find("span").text(response ? response.error : "Upload error");
|
|
jq('#hiddenFileName').val("");
|
|
return;
|
|
}
|
|
|
|
jq("#hiddenFileName").val(response.filename);
|
|
|
|
jq("#step1").addClass("done").removeClass("current");
|
|
jq("#step2").addClass("current");
|
|
|
|
checkConvert();
|
|
}
|
|
});
|
|
});
|
|
|
|
var timer = null;
|
|
var checkConvert = function () {
|
|
if (timer != null) {
|
|
clearTimeout(timer);
|
|
}
|
|
|
|
if (!jq("#mainProgress").is(":visible")) {
|
|
return;
|
|
}
|
|
|
|
var fileName = jq("#hiddenFileName").val();
|
|
var posExt = fileName.lastIndexOf('.');
|
|
posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : '';
|
|
|
|
if (ConverExtList.indexOf(posExt) == -1) {
|
|
loadScripts();
|
|
return;
|
|
}
|
|
|
|
if (jq("#checkOriginalFormat").is(":checked")) {
|
|
loadScripts();
|
|
return;
|
|
}
|
|
|
|
timer = setTimeout(function () {
|
|
var requestAddress = UrlConverter + "?filename=" + encodeURIComponent(jq("#hiddenFileName").val());
|
|
|
|
jq.ajax({
|
|
async: true,
|
|
contentType: "text/xml",
|
|
type: "get",
|
|
url: requestAddress,
|
|
complete: function (data) {
|
|
var responseText = data.responseText;
|
|
var response = jq.parseJSON(responseText);
|
|
if (response.error) {
|
|
jq(".current").removeClass("current");
|
|
jq(".step:not(.done)").addClass("error");
|
|
jq("#mainProgress .error-message").show().find("span").text(response.error);
|
|
jq('#hiddenFileName').val("");
|
|
return;
|
|
}
|
|
|
|
jq("#hiddenFileName").val(response.filename);
|
|
|
|
if (typeof response.step != "undefined" && response.step < 100) {
|
|
checkConvert();
|
|
} else {
|
|
loadScripts();
|
|
}
|
|
}
|
|
});
|
|
}, 1000);
|
|
};
|
|
|
|
var loadScripts = function () {
|
|
if (!jq("#mainProgress").is(":visible")) {
|
|
return;
|
|
}
|
|
jq("#step2").addClass("done").removeClass("current");
|
|
jq("#step3").addClass("current");
|
|
|
|
if (jq("#loadScripts").is(":empty")) {
|
|
var urlScripts = jq("#loadScripts").attr("data-docs");
|
|
var frame = '<iframe id="iframeScripts" width=1 height=1 style="position: absolute; visibility: hidden;" ></iframe>';
|
|
jq("#loadScripts").html(frame);
|
|
document.getElementById("iframeScripts").onload = onloadScripts;
|
|
jq("#loadScripts iframe").attr("src", urlScripts);
|
|
} else {
|
|
onloadScripts();
|
|
}
|
|
};
|
|
|
|
var onloadScripts = function () {
|
|
if (!jq("#mainProgress").is(":visible")) {
|
|
return;
|
|
}
|
|
jq("#step3").addClass("done").removeClass("current");
|
|
jq("#beginView, #beginEmbedded").removeClass("disable");
|
|
|
|
var fileName = jq("#hiddenFileName").val();
|
|
var posExt = fileName.lastIndexOf('.');
|
|
posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : '';
|
|
|
|
if (EditedExtList.indexOf(posExt) != -1) {
|
|
jq("#beginEdit").removeClass("disable");
|
|
}
|
|
};
|
|
|
|
jq(document).on("click", "#beginEdit:not(.disable)", function () {
|
|
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
|
|
var url = UrlEditor + "?fileName=" + fileId + "&lang=" + language + "&userid=" + userid + "&firstname=" +firstname +"&lastname=" + lastname;
|
|
window.open(url, "_blank");
|
|
jq('#hiddenFileName').val("");
|
|
jq.unblockUI();
|
|
document.location.reload();
|
|
});
|
|
|
|
jq(document).on("click", "#beginView:not(.disable)", function () {
|
|
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
|
|
var url = UrlEditor + "?mode=view&fileName=" + fileId + "&lang=" + language + "&userid=" + userid + "&firstname=" +firstname +"&lastname=" + lastname;
|
|
window.open(url, "_blank");
|
|
jq('#hiddenFileName').val("");
|
|
jq.unblockUI();
|
|
document.location.reload();
|
|
});
|
|
|
|
jq(document).on("click", "#beginEmbedded:not(.disable)", function () {
|
|
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
|
|
var url = UrlEditor + "?type=embedded&fileName=" + fileId + "&lang=" + language + "&userid=" + userid + "&firstname=" +firstname +"&lastname=" + lastname;
|
|
|
|
jq("#mainProgress").addClass("embedded");
|
|
jq("#beginEmbedded").addClass("disable");
|
|
|
|
jq("#embeddedView").attr("src", url);
|
|
});
|
|
|
|
jq(document).on("click", ".reload-page", function () {
|
|
setTimeout(function () { document.location.reload(); }, 1000);
|
|
return true;
|
|
});
|
|
|
|
jq(document).on("mouseup", ".reload-page", function (event) {
|
|
if (event.which == 2) {
|
|
setTimeout(function () { document.location.reload(); }, 1000);
|
|
}
|
|
return true;
|
|
});
|
|
|
|
jq(document).on("click", "#cancelEdit, .dialog-close", function () {
|
|
jq('#hiddenFileName').val("");
|
|
jq("#embeddedView").attr("src", "");
|
|
jq.unblockUI();
|
|
});
|
|
|
|
jq(document).on("click", ".delete-file", function () {
|
|
var fileName = jq(this).attr("data");
|
|
|
|
var requestAddress = "file?filename=" + fileName;
|
|
|
|
jq.ajax({
|
|
async: true,
|
|
contentType: "text/xml",
|
|
type: "delete",
|
|
url: requestAddress,
|
|
complete: function (data) {
|
|
document.location.reload();
|
|
}
|
|
});
|
|
});
|
|
|
|
jq("#createSample").click(function () {
|
|
jq(".try-editor").each(function () {
|
|
var href = jq(this).attr("href");
|
|
if (jq("#createSample").is(":checked")) {
|
|
href += "&sample=true";
|
|
} else {
|
|
href = href.replace("&sample=true", "");
|
|
}
|
|
jq(this).attr("href", href);
|
|
});
|
|
});
|
|
|
|
jq.dropdownToggle({
|
|
switcherSelector: ".question",
|
|
dropdownID: "hint"
|
|
});
|
|
}
|
|
|
|
function getUrlVars() {
|
|
var vars = [], hash;
|
|
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
|
|
for (var i = 0; i < hashes.length; i++) {
|
|
hash = hashes[i].split('=');
|
|
vars.push(hash[0]);
|
|
vars[hash[0]] = hash[1];
|
|
}
|
|
return vars;
|
|
}; |