Try the fastest and simplest way to install ONLYOFFICE

working with the web browser and docEditor

Integration questions/issues

working with the web browser and docEditor

Postby robertotomas » Thu Sep 28, 2017 9:41 pm

I want to be able to insert text into a document from a rich user interface in the page that holds the docEditor element. Imagine sliders and things, with buttons, all outside of docEditor. When a button is pressed, configuration from the other controls on the rich user interface build a template partial, which should be inserted into the document. This is basically just supporting a copy/paste function, so the helloworld plugin looked like a good place to start.

I thought a plugin like this would be good:
Code: Select all
(function (window, undefined) {
    window.Asc.plugin.init = function () {
        var sScript = 'var oDocument = Api.GetDocument();';
        sScript += 'oDocument.CreateNewHistoryPoint();';
        sScript += 'oParagraph = Api.CreateParagraph();';
        sScript += `oParagraph.AddText('${window.addTag}');`;
        sScript += 'oDocument.InsertContent([oParagraph]);';
        window.Asc.plugin.info.recalculate = true;
        this.executeCommand("close", sScript);
    };

    window.Asc.plugin.button = function (id) {
    };

    window.addTag = window.addTag || 'Hello world!'
})(window, undefined);


By looking at window.addTag, and building the sScript message as needed, I hoped to insert dynamic text from the client into the document. However, this doesn't seem to be the right way to go. The iframe's window is not accessible without using postMessage, and that means changing 'web-apps/apps/api/documents/api.js'.

I was thinking it would be good to try adding somethin like this:
Code: Select all
window.addEventListener("addTag",
  tag => tag?
    window.addTag = tag:
    window.Asc.plugin.button.onClick(),
false)


Changing this produces "The editor version has been updated. The page will be reloaded to apply the changes." in the document Editor. It seems like I must restart the onlyoffice server.

However, I'm using the docker image. I don't know how to restart it there. I don't see onlyoffice in the services list:
Code: Select all
root@bada9d46bdc6:/var/www/onlyoffice/documentserver/web-apps/apps/api/documents# service --status-all
 [ ? ]  console-setup
 [ + ]  cron
 [ ? ]  killprocs
 [ ? ]  kmod
 [ ? ]  networking
 [ + ]  nginx
 [ ? ]  ondemand
 [ + ]  postgresql
 [ - ]  procps
 [ + ]  rabbitmq-server
 [ ? ]  rc.local
 [ + ]  redis-server
 [ + ]  resolvconf
 [ - ]  rsyslog
 [ ? ]  sendsigs
 [ - ]  sudo
 [ + ]  supervisor
 [ + ]  udev
 [ ? ]  umountfs
 [ ? ]  umountnfs.sh
 [ ? ]  umountroot
 [ - ]  unattended-upgrades
 [ - ]  urandom
 [ - ]  x11-common
root@bada9d46bdc6:/var/www/onlyoffice/documentserver/web-apps/apps/api/documents#
robertotomas
 
Posts: 17
Joined: Thu Aug 31, 2017 4:05 pm

Return to API

Who is online

Users browsing this forum: No registered users and 1 guest