Add support methods/commands in windows

This commit is contained in:
Oleg Korshul
2024-04-16 23:55:39 +03:00
parent f1deda9101
commit f9894f9491
3 changed files with 56 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@ -832,7 +832,29 @@
case "onWindowEvent":
{
if (window.Asc.plugin._windows && pluginData.windowID && window.Asc.plugin._windows[pluginData.windowID])
window.Asc.plugin._windows[pluginData.windowID]._oncommand(pluginData.eventName, pluginData.eventData);
{
if ("private_window_method" === pluginData.eventName)
{
var _windowID = pluginData.windowID;
window.Asc.plugin.executeMethod(pluginData.eventData.name, pluginData.eventData.params, function(retValue){
if (window.Asc.plugin._windows && window.Asc.plugin._windows[_windowID])
window.Asc.plugin._windows[_windowID].command("on_private_window_method", retValue);
});
}
else if ("private_window_command" === pluginData.eventName)
{
var _windowID = pluginData.windowID;
window.Asc.plugin.info.recalculate = (false === pluginData.eventData.isCalc) ? false : true;
window.Asc.plugin.executeCommand("command", pluginData.eventData.code, function(retValue){
if (window.Asc.plugin._windows && window.Asc.plugin._windows[_windowID])
window.Asc.plugin._windows[_windowID].command("on_private_window_command", retValue);
});
}
else
{
window.Asc.plugin._windows[pluginData.windowID]._oncommand(pluginData.eventName, pluginData.eventData);
}
}
break;
}
default:

View File

@ -451,6 +451,25 @@ window.startPluginApi = function() {
return false;
};
Plugin._pushWindowMethodCommandCallback = function(callback)
{
if (this.windowCallbacks === undefined)
{
this.windowCallbacks = [];
this.attachEvent("on_private_window_method", function(retValue) {
var _retCallback = window.Asc.plugin.windowCallbacks.shift();
if (_retCallback)
_retCallback(retValue);
});
this.attachEvent("on_private_window_command", function(retValue) {
var _retCallback = window.Asc.plugin.windowCallbacks.shift();
if (_retCallback)
_retCallback(retValue);
});
}
this.windowCallbacks.push(callback);
};
/***********************************************************************
* METHODS
*/
@ -522,7 +541,12 @@ window.startPluginApi = function() {
*/
Plugin.executeMethod = function(name, params, callback)
{
if (this._checkPluginOnWindow()) return;
if (this.windowID)
{
this._pushWindowMethodCommandCallback(callback);
this.sendToPlugin("private_window_method", { name : name, params : params });
return;
}
if (window.Asc.plugin.isWaitMethod === true)
{
@ -618,9 +642,14 @@ window.startPluginApi = function() {
*/
Plugin.callCommand = function(func, isClose, isCalc, callback)
{
if (this._checkPluginOnWindow()) return;
var _txtFunc = "var Asc = {}; Asc.scope = " + JSON.stringify(window.Asc.scope) + "; var scope = Asc.scope; (" + func.toString() + ")();";
if (this.windowID)
{
this._pushWindowMethodCommandCallback(callback);
this.sendToPlugin("private_window_command", { code : _txtFunc, isCalc : isCalc });
return;
}
var _txtFunc = "var Asc = {}; Asc.scope = " + JSON.stringify(window.Asc.scope) + "; var scope = Asc.scope; (" + func.toString() + ")();";
var _type = (isClose === true) ? "close" : "command";
window.Asc.plugin.info.recalculate = (false === isCalc) ? false : true;
window.Asc.plugin.executeCommand(_type, _txtFunc, callback);