ONLYOFFICE / sdkjs-plugins

The add-ons for ONLYOFFICE Document Server and ONLYOFFICE Desktop Editors.
https://www.onlyoffice.com
Apache License 2.0
136 stars 134 forks source link

window.Asc.plugin.executeMethod("AddContentControl", [args], callback) #34

Closed ccruson closed 6 years ago

ccruson commented 6 years ago

This is more of a question than an issue. Is there a way to create more than one content control at a time? It would be nice if I could pass an array to this function and have them added all at once.

flaminestone commented 6 years ago

Hello @ccruson. You can use InsertAndReplaceContentControls method for create more than one content control at a time (documentation)

(function(window, undefined){
    window.Asc.plugin.init = function()
    {
        window.Asc.plugin.executeMethod("InsertAndReplaceContentControls", [
            [   
                {
                    "Props":
                    {
                        "Id": 7,
                        "Tag":
                        "{String}",
                        "Lock": 0 
                    },          
                    "Script":   "var oDocument = Api.GetDocument();\
                                var oParagraph = Api.CreateParagraph();\
                                oParagraph.AddText('Hello world!');\
                                oDocument.InsertContent([oParagraph]);"
                },
                {
                    "Props":
                    {
                        "Id": 8,
                        "Tag": "{String}",
                        "Lock": 0 
                    },
                    "Script":   "var oDocument = Api.GetDocument();\
                                var oParagraph = Api.CreateParagraph();\
                                oParagraph.AddText('Hello world!');\
                                oDocument.InsertContent([oParagraph]);" 
                }   ]
        ]);
        window.Asc.plugin.onMethodReturn = function(returnValue)
            {
                var _plugin = window.Asc.plugin;
                if (_plugin.info.methodName == "InsertAndReplaceContentControls")
                    {
                           this.executeCommand("close", '');
                    }
            };
    };
})(window, undefined);
ShockwaveNN commented 6 years ago

Closing due no responce