Add inline content control and replace content

Integration questions/issues
Post Reply
uwohlfeil
Posts: 5
Joined: Mon Apr 29, 2019 8:53 am

Add inline content control and replace content

Post by uwohlfeil » Wed Jun 12, 2019 8:58 am

Hi,

I try to add a content control with a custom content.

Version Info:
Document Editor 5.3.0
Firefox 67.0..1

I try this calls:
AddContentControl
Request:

Code: Select all

[2, { "Id": 2885, "Lock": 0, "Tag": "{\"exp\":\"Expample\",\"wrap\":\"2\",\"lock\":\"0\",\"placeholderType\":\"text\",\"placeholder\":\"placeholder\"}" }]
Response:

Code: Select all

{"Tag": "{\"exp\":\"Expample\",\"wrap\":\"2\",\"lock\":\"0\",\"placeholderType\":\"text\",\"placeholder\":\"placeholder\"}", "Id": 2885, "Lock": 0, "InternalId": "2_2857"}
InsertAndReplaceContentControls
Then i try to update the new control content.
Request:

Code: Select all

[[ {"Props": { "InternalId": "2_2857", "Lock": 0, "Tag": "{\"exp\":\"Expample\",\"wrap\":\"2\",\"lock\":\"0\",\"placeholderType\":\"text\",\"placeholder\":\"placeholder\"}"  },  "Script": "var oDocument = Api.GetDocument();var oParagraph =  Api.CreateParagraph(); var oRun = oParagraph.AddText(\"Expample\"); oDocument.InsertContent([oParagraph], true);" } ]]
Response:

Code: Select all

[]
I also have the effect, that a delete seems not to delete the control correctly.
The control disappears on the editor but the GetContentControls still shows the control:

GetAllContentControls

Code: Select all

[{ "Tag": "{\"exp\":\"Expample\",\"wrap\":\"2\",\"lock\":\"0\",\"placeholderType\":\"text\",\"placeholder\":\"placeholder\"}", "Id": 2885,  "Lock": 0, "InternalId": "2_2857" } ]
RemoveContentControls
Request:

Code: Select all

[[ { "InternalId": "2_2857" } ] ]
Response
undefined

GetAllContentControls

Code: Select all

[
  {
    "Tag": "{\"exp\":\"Expample\",\"wrap\":\"2\",\"lock\":\"0\",\"placeholderType\":\"text\",\"placeholder\":\"placeholder\"}",
    "Id": 2885,
    "Lock": 0,
    "InternalId": "2_2857"
  },
  {
    "Tag": "{\"exp\":\"asdasd\",\"wrap\":\"2\",\"lock\":\"0\",\"placeholderType\":\"text\",\"placeholder\":\"as\"}",
    "Id": 1956,
    "Lock": 0,
    "InternalId": "2_3146"
  }
]

uwohlfeil
Posts: 5
Joined: Mon Apr 29, 2019 8:53 am

Re: Add inline content control and replace content

Post by uwohlfeil » Sat Jul 06, 2019 11:54 am

I found my mistake. The problem was not in the described calls.
It was a concurrent call from the.Asc.plugin.onExternalMouseUp window that executes a window.Asc.plugin.executeMethod('GetCurrentContentControl', []) while I add and update the new ContentControl as described.
The OnlyOffice documentation says: "For the plugin to work correctly, you must wait until the current method is executed before executing the next method". (https://api.onlyoffice.com/plugin/executemethod)
but I didn't see that effect in my code.

@OnlyOffice:
Can you mark this post as solved?
It would be great if the onlyoffice client generates some error messages for incorrectly executed concurrent calls like mine.

Maxim
Posts: 2017
Joined: Tue Oct 11, 2016 2:34 pm

Re: Add inline content control and replace content

Post by Maxim » Mon Jul 08, 2019 6:39 am

Hello uwohlfeil!
It would be great if the onlyoffice client generates some error messages for incorrectly executed concurrent calls like mine.
Thank you for your feedback.

uwohlfeil
Posts: 5
Joined: Mon Apr 29, 2019 8:53 am

Re: Add inline content control and replace content

Post by uwohlfeil » Wed Jul 24, 2019 3:27 pm

Hello Maxim,

I found a second "problem". If I create a field with the Lock 0 (Edit=No, Delete=yes) or 1 (Edit=No, Delete=no), also the Control Field methods will respect the defined lock rule in further calls.
This is of cause not a bug but in my case, I only want to prevent normal users to delete/edit the specified field controls but keep the possibility to editor delete them be power users.

The security check seems to be defined in the "CContentControlPluginWorker" which uses the method "Document_Is_SelectionLocked".

The content control function in the toolbar can unset this flag but it seems that there is no plugin method to do this.
The internally use function asc_SetContentControlProperties seems not be available from the plugin context.

Is there a way to call this method via CallCommand?

Best Regards
Uli

Post Reply