Commit cbfebd0d authored by Boris Kocherov's avatar Boris Kocherov Committed by Eteri

erp5_officejs_ooffice: add onlyoffice text and his gadget

parent 21cc2ab8
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Jio Web Page View</title>
<link rel="stylesheet" href="gadget_erp5.css">
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="handlebars.js"></script>
<script class="view-web-page-template" type="text/x-handlebars-template">
<form class="view-web-page-form">
<div class="center">
<div class="ui-field-contain">
<label data-i18n="Title:">Title:</label>
<input type="text" name="title" value="{{title}}">
</div>
<button type="submit" data-i18n="Save" style="display:none;">
Save
</button>
</div>
<div class="ui-field-contain">
    
<fieldset data-role="collapsible">
        
<legend>Extra Properties</legend>
<div class="ui-field-contain">
<label data-i18n="Reference:">Reference:</label>
<input type="text" name="reference"
value="{{reference}}">
</div>
<div class="ui-field-contain">
<label data-i18n="Version:">Version:</label>
<input type="text" name="version"
value="{{version}}"></label>
</div>
<div class="ui-field-contain">
<label data-i18n="Language:">Language:</label>
<input type="text" name="language" value="{{language}}">
</div>
<div class="ui-field-contain">
<label data-i18n="Description:">Description:</label>
<textarea name="description">{{description}}</textarea>
</div>
</fieldset>
</div>
<div class='document-content'></div>
</form>
</script>
<script src="gadget_officejs_jio_text_view.js"></script>
</head>
<body>
</body>
</html>
/*globals window, rJS, Handlebars, RSVP, loopEventListener, console, document, jIO*/
/*jslint indent: 2, nomen: true, maxlen: 80*/
(function (window, document, RSVP, rJS, Handlebars, loopEventListener, jIO) {
"use strict";
function this_func_link(name) {
return function (opt) {
return this[name].apply(this, opt);
};
}
function renderOnlyOfficeGadget(gadget) {
var text_gadget;
return gadget.declareGadget(
"../../ooffice_text_gadget/development/",
{
scope: "my_text_content",
sandbox: "iframe",
element: gadget.props.element.querySelector(".document-content")
}
)
.push(function (text_content_gadget) {
text_gadget = text_content_gadget;
gadget.setFillStyle();
// switchMaximizeMode(gadget);
return text_content_gadget;
})
.push(function (text_content_gadget) {
return text_content_gadget.render({
"key": 'text_content',
"value": gadget.options.data
});
})
.push(function () {
return text_gadget.getElement();
});
}
function saveContent(gadget, submit_event) {
var i,
doc = gadget.options.doc;
doc.modification_date = (new Date()).toISOString();
for (i = 0; i < submit_event.target.length; i += 1) {
// XXX Should check input type instead
if (submit_event.target[i].name) {
doc[submit_event.target[i].name] = submit_event.target[i].value;
}
}
return new RSVP.Queue()
.push(function () {
if (gadget.options.doc.content_type === undefined ||
gadget.options.doc.content_type.indexOf("application/x-asc") === 0
) {
gadget.options.doc.content_type = "application/x-asc-spreadsheet";
return gadget.getDeclaredGadget("my_text_content");
}
return undefined;
})
.push(function (text_content_gadget) {
if (text_content_gadget !== undefined) {
return text_content_gadget.getContent();
}
return undefined;
})
.push(function(datauri) {
if (datauri !== undefined) {
return gadget.jio_putAttachment(gadget.options.jio_key, 'data',
jIO.util.dataURItoBlob(datauri.text_content));
}
return;
})
.push(function () {
return gadget.jio_put(gadget.options.jio_key, doc);
});
}
function getMaxHeight(wrap_obj) {
var height;
if (wrap_obj) {
height = window.innerHeight - wrap_obj.offsetTop;
} else {
height = window.innerHeight;
}
if (height < 400) {
height = 400;
}
return height + "px";
}
function setFillStyle(gadget) {
var iframe = gadget.props.element.querySelector('iframe'),
height = getMaxHeight(iframe),
width = "100%";
iframe.setAttribute(
'style',
'width: ' + width + '; border: 0 none; height: ' + height
);
return {height: height, width: width};
}
function switchMaximizeMode(gadget) {
var iframe = gadget.props.element.querySelector('iframe'),
iframe_class_string = iframe.getAttribute('class') || "",
class_name = "ui-content-maximize",
class_index = iframe_class_string.indexOf(class_name);
if (class_index === -1) {
iframe_class_string += ' ' + class_name;
iframe.setAttribute('style', 'background: white;');
iframe.setAttribute('class', iframe_class_string);
return true;
}
iframe_class_string = iframe_class_string.substring(0, class_index)
+ iframe_class_string.substring(class_index + class_name.length);
iframe.setAttribute('style', 'width:100%; border: 0 none; height: 600px');
iframe.setAttribute('class', iframe_class_string);
return false;
}
var gadget_klass = rJS(window),
source = gadget_klass.__template_element
.querySelector(".view-web-page-template")
.innerHTML,
template = Handlebars.compile(source);
gadget_klass
.ready(function (g) {
g.props = {};
g.options = null;
return g.getElement()
.push(function (element) {
g.props.element = element;
g.props.deferred = RSVP.defer();
});
})
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod('getSetting', 'getSetting')
.allowPublicAcquisition("getSetting", this_func_link("getSetting"))
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.allowPublicAcquisition('setFillStyle', function () {
return setFillStyle(this);
})
.declareMethod('setFillStyle', function () {
return setFillStyle(this);
})
.allowPublicAcquisition('triggerSubmit', function (option) {
if (option[0] === "maximize" || option === "maximize") {
var gadget = this;
return RSVP.Queue()
.push(function () {
return switchMaximizeMode(gadget);
});
}
return this.props.element.querySelector('button').click();
})
.declareMethod('triggerSubmit', function (option) {
if (option[0] === "maximize" || option === "maximize") {
var gadget = this;
return RSVP.Queue()
.push(function () {
return switchMaximizeMode(gadget);
});
}
return this.props.element.querySelector('button').click();
})
.declareMethod("render", function (options) {
var gadget = this;
gadget.options = options;
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.jio_get(options.jio_key),
gadget.jio_getAttachment(options.jio_key, "data")
.push(undefined, function (error) {
if (error.status_code === 404) {
return new Blob();
}
throw error;
})
]);
})
.push(function (result) {
return new RSVP.Queue()
.push(function () {
if (result[0].content_type === undefined ||
result[0].content_type.indexOf("application/x-asc") === 0) {
return jIO.util.readBlobAsDataURL(result[1]);
}
return jIO.util.readBlobAsText(result[1]);
})
.push(function (evt) {
result[1] = evt.target.result;
return result;
});
})
.push(function (list) {
var doc = list[0],
data = list[1];
gadget.options.doc = doc;
gadget.options.data = data;
gadget.options.doc.title = gadget.options.doc.title || "";
return new RSVP.Queue()
.push(function () {
return gadget.translateHtml(template(options.doc));
})
.push(function (html) {
gadget.props.element.innerHTML = html;
return gadget.updateHeader({
title: options.doc.title + " | " + options.doc.portal_type,
maximize_action: true,
maximized: (gadget.options.doc.title !== ""),
save_action: true
});
})
.push(function () {
return gadget.props.deferred.resolve();
});
});
})
/////////////////////////////////////////
// Render text content gadget
/////////////////////////////////////////
.declareService(function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return gadget.props.deferred.promise;
})
.push(function () {
var iframe;
if (gadget.options.doc.content_type === undefined
|| gadget.options.doc.content_type.indexOf("application/x-asc")
=== 0) {
return renderOnlyOfficeGadget(gadget);
}
iframe = document.createElement("iframe");
iframe.setAttribute(
"src",
"data:text/html," + gadget.options.data
);
gadget.props.element.querySelector(".document-content")
.appendChild(iframe);
return setFillStyle(gadget);
})
.push(function () {
if (gadget.options.doc.title !== "") {
return switchMaximizeMode(gadget);
}
return;
});
})
/////////////////////////////////////////
// Form submit
/////////////////////////////////////////
.declareService(function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
return gadget.props.deferred.promise;
})
.push(function () {
return loopEventListener(
gadget.props.element.querySelector('form'),
'submit',
true,
function (event) {
return saveContent(gadget, event);
}
);
});
});
}(window, document, RSVP, rJS, Handlebars, loopEventListener, jIO));
\ No newline at end of file
......@@ -173,7 +173,7 @@ gadget_officejs_webrtc_jio.js\n
gadget_officejs_widget_listbox.js\n
erp5_launcher.js\n
erp5_launcher.html\n
spreadsheet_landing_page.html\n
ooffice_spreadsheet_landing_page.html\n
gadget_officejs_spreadsheet_router.html\n
gadget_officejs_jio_spreadsheet_view.html\n
gadget_officejs_jio_spreadsheet_view.js\n
......@@ -321,7 +321,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>957.19305.42508.13943</string> </value>
<value> <string>957.19334.14243.5939</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -339,7 +339,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1486990670.96</float>
<float>1486994104.54</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -125,7 +125,7 @@ jiodev.js\n
jquerymobile.js\n
jquerymodile.css\n
jquery.js\n
spreadsheet_gadget_landing_page.html\n
ooffice_spreadsheet_gadget_landing_page.html\n
gadget_officejs_onlyoffice_landing.js\n
ooffice/apps/backbone.js\n
ooffice/apps/bootstrap.js\n
......@@ -647,7 +647,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>957.19334.13190.7321</string> </value>
<value> <string>957.19339.63272.48452</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -665,7 +665,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1486992717.87</float>
<float>1486994242.69</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -72,7 +72,7 @@
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>spreadsheet_gadget_landing_page.html</string> </value>
<value> <string>ooffice_spreadsheet_gadget_landing_page.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -100,7 +100,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Spreadsheet Gadget Landing Page</string> </value>
<value> <string>OnlyOffice Spreadsheet Gadget Landing Page</string> </value>
</item>
<item>
<key> <string>url_string</string> </key>
......@@ -237,7 +237,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>957.19317.26590.7014</string> </value>
<value> <string>957.19350.56466.65501</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -255,7 +255,7 @@
</tuple>
<state>
<tuple>
<float>1486991379.96</float>
<float>1486993380.05</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -35,7 +35,7 @@
data-gadget-scope="setting_gadget"
data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_officejs_spreadsheet_router.html"
<div data-gadget-url="gadget_officejs_ooffice_spreadsheet_router.html"
data-gadget-scope="router"
data-gadget-sandbox="public"></div>
......
......@@ -72,7 +72,7 @@
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>spreadsheet_landing_page.html</string> </value>
<value> <string>ooffice_spreadsheet_landing_page.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -100,7 +100,7 @@
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Spreadsheet Landing Page</string> </value>
<value> <string>OnlyOffice Spreadsheet Landing Page</string> </value>
</item>
<item>
<key> <string>url_string</string> </key>
......@@ -237,7 +237,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>957.19328.54739.65484</string> </value>
<value> <string>957.19350.17214.1450</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -255,7 +255,7 @@
</tuple>
<state>
<tuple>
<float>1486992074.92</float>
<float>1486993665.45</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -72,7 +72,7 @@
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_officejs_spreadsheet_router.html</string> </value>
<value> <string>gadget_officejs_ooffice_spreadsheet_router.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
......@@ -231,7 +231,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>957.19296.55203.14967</string> </value>
<value> <string>957.19299.52450.32273</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -249,7 +249,7 @@
</tuple>
<state>
<tuple>
<float>1486990148.07</float>
<float>1486993644.52</float>
<string>UTC</string>
</tuple>
</state>
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>OfficeJS Text Loader Gadget</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="jiodev.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_officejs_onlyoffice_landing.js" type="text/javascript"></script>
</head>
<body>
<script data-renderjs-configuration="portal_type" type="text/x-renderjs-configuration">Text</script>
<script data-renderjs-configuration="child-gadget" type="text/x-renderjs-configuration">ooffice/gadget_ooffice.html</script>
</body>
</html>
<!DOCTYPE html>
<html manifest="disabled.appcache">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="favicon.ico">
<title>Text</title>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="jquerymobile.css">
<link rel="stylesheet" href="gadget_erp5.css">
<script data-renderjs-configuration="application_title" type="text/x-renderjs-configuration">Text</script>
<script data-renderjs-configuration="panel_gadget" type="text/x-renderjs-configuration">gadget_officejs_application_panel.html</script>
<script data-renderjs-configuration="action_view" type="text/x-renderjs-configuration">object_view</script>
<script data-renderjs-configuration="default_view_reference" type="text/x-renderjs-configuration">view</script>
<script data-renderjs-configuration="hateoas_url" type="text/x-renderjs-configuration">hateoas/</script>
<script data-renderjs-configuration="frontpage_gadget" type="text/x-renderjs-configuration">worklist</script>
<script src="jquery.js"></script>
<script src="jquerymobile.js"></script>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="gadget_global.js" ></script>
<script src="erp5_launcher.js"></script>
</head>
<body>
<div data-role="page">
<div data-gadget-url="gadget_jio.html"
data-gadget-scope="setting_gadget"
data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_officejs_ooffice_text_router.html"
data-gadget-scope="router"
data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_translation.html"
data-gadget-scope="translation_gadget"
data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_officejs_header.html"
data-gadget-scope="header"
data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_officejs_jio.html"
data-gadget-scope="jio_gadget"
data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_erp5_editor_panel.html"
data-gadget-scope="editor_panel"
data-gadget-sandbox="public"></div>
<div data-gadget-url="gadget_officejs_application_panel.html"
data-gadget-scope="panel"
data-gadget-sandbox="public"></div>
<div role="main" class="ui-content gadget-content"></div>
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no" />
<title>OfficeJS Router Gadget</title>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script>
<!-- custom script -->
<script src="gadget_officejs_router.js" type="text/javascript"></script>
</head>
<body>
<script data-renderjs-configuration="portal_type" type="text/x-renderjs-configuration">Text</script>
<script data-renderjs-configuration="parent_relative_url" type="text/x-renderjs-configuration">document_module</script>
<script data-renderjs-configuration="document_title" type="text/x-renderjs-configuration">Text</script>
<script data-renderjs-configuration="document_title_plural" type="text/x-renderjs-configuration">Text documents</script>
<script data-renderjs-configuration="erp5_attachment_synchro" type="text/x-renderjs-configuration">/{+id}/Base_downloadWithCors</script>
<script data-renderjs-configuration="global_setting_gadget_url" type="text/x-renderjs-configuration">../officejs_setting_gadget/</script>
</body>
</html>
\ No newline at end of file
......@@ -425,7 +425,7 @@
</item>
<item>
<key> <string>configuration_landing_page</string> </key>
<value> <string>spreadsheet_landing_page.html</string> </value>
<value> <string>ooffice_spreadsheet_landing_page.html</string> </value>
</item>
<item>
<key> <string>configuration_latest_document_version</string> </key>
......@@ -700,7 +700,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>957.19331.52048.50670</string> </value>
<value> <string>957.19336.10281.56149</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -718,7 +718,7 @@
</tuple>
<state>
<tuple>
<float>1486992489.4</float>
<float>1486993348.66</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -425,7 +425,7 @@
</item>
<item>
<key> <string>configuration_landing_page</string> </key>
<value> <string>spreadsheet_gadget_landing_page.html</string> </value>
<value> <string>ooffice_spreadsheet_gadget_landing_page.html</string> </value>
</item>
<item>
<key> <string>configuration_latest_document_version</string> </key>
......@@ -700,7 +700,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>957.19326.20757.20889</string> </value>
<value> <string>957.19326.37932.19234</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -718,7 +718,7 @@
</tuple>
<state>
<tuple>
<float>1486991914.68</float>
<float>1486993395.7</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment