-
Notifications
You must be signed in to change notification settings - Fork 14
/
apiPlugins.js
171 lines (157 loc) · 6.18 KB
/
apiPlugins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* (c) Copyright Ascensio System SIA 2010-2024
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
"use strict";
(function(window)
{
/**
* @typedef {Object} ContentControl
* Content control object.
* @property {string} Tag - A tag assigned to the content control. The same tag can be assigned to several content controls so that it is possible to make reference to them in your code.
* @property {string} Id - A unique identifier of the content control. It can be used to search for a certain content control and make reference to it in the code.
* @property {ContentControlLock} Lock - A value that defines if it is possible to delete and/or edit the content control or not: 0 - only deleting, 1 - no deleting or editing, 2 - only editing, 3 - full access.
* @property {string} InternalId - A unique internal identifier of the content control. It is used for all operations with content controls.
* @see office-js-api/Examples/Plugins/Forms/Enumeration/ContentControl.js
*/
/**
* @typedef {(0 | 1 | 2 | 3)} ContentControlLock
* A value that defines if it is possible to delete and/or edit the content control or not:
* **0** - only deleting
* **1** - disable deleting or editing
* **2** - only editing
* **3** - full access
* @see office-js-api/Examples/Plugins/Forms/Enumeration/ContentControlLock.js
*/
/**
* Returns information about all the forms that have been added to the document.
* @memberof Api
* @typeofeditors ["CDE"]
* @alias GetAllForms
* @returns {ContentControl[]} - An array with all the forms from the document.
* @see office-js-api/Examples/Plugins/Forms/Api/Methods/GetAllForms.js
*/
window["asc_docs_api"].prototype["pluginMethod_GetAllForms"] = function()
{
let oFormsManager = this.private_GetFormsManager();
if (!oFormsManager)
return [];
let arrForms = oFormsManager.GetAllForms();
let arrResult = [];
for (let nIndex = 0, nCount = arrForms.length; nIndex < nCount; ++nIndex)
{
arrResult.push(arrForms[nIndex].GetContentControlPr().GetEventObject());
}
return arrResult;
};
/**
* Returns information about all the forms that have been added to the document with specified tag.
* @memberof Api
* @typeofeditors ["CDE"]
* @alias GetFormsByTag
* @param {string} tag - The form tag.
* @returns {ContentControl[]} - An array with all the forms from the document with the specified tag.
* @see office-js-api/Examples/Plugins/Forms/Api/Methods/GetFormsByTag.js
*/
window["asc_docs_api"].prototype["pluginMethod_GetFormsByTag"] = function(tag)
{
let oFormsManager = this.private_GetFormsManager();
if (!oFormsManager)
return [];
let arrForms = oFormsManager.GetAllForms();
let arrResult = [];
let oForm = null;
for (let nIndex = 0, nCount = arrForms.length; nIndex < nCount; ++nIndex)
{
oForm = arrForms[nIndex];
if (oForm.GetTag() === tag)
arrResult.push(oForm.GetContentControlPr().GetEventObject());
}
return arrResult;
};
/**
* Sets a value to the specified form.
* @memberof Api
* @typeofeditors ["CDE"]
* @alias SetFormValue
* @param {string} internalId - A unique internal identifier of the form.
* @param {string | boolean} value - Form value to be set. Its type depends on the form type.
* @see office-js-api/Examples/Plugins/Forms/Api/Methods/SetFormValue.js
*/
window["asc_docs_api"].prototype["pluginMethod_SetFormValue"] = function(internalId, value)
{
this.private_SetFormValue(internalId, value);
};
/**
* Returns a value of the specified form.
* @memberof Api
* @typeofeditors ["CDE"]
* @alias GetFormValue
* @param {string} internalId - A unique internal identifier of the form.
* @returns {null | string | boolean} The form value in the string or boolean format depending on the form type. The null value means that the form is filled with a placeholder.
* @see office-js-api/Examples/Plugins/Forms/Api/Methods/GetFormValue.js
*/
window["asc_docs_api"].prototype["pluginMethod_GetFormValue"] = function(internalId)
{
if (!AscCommon.g_oTableId)
return "";
let oForm = AscCommon.g_oTableId.GetClass(internalId);
if (!oForm
|| !(oForm instanceof AscWord.CInlineLevelSdt)
|| !oForm.IsForm())
return "";
if (oForm.IsPlaceHolder())
return null;
if (oForm.IsTextForm() || oForm.IsComboBox() || oForm.IsDropDownList())
{
return oForm.GetInnerText();
}
else if (oForm.IsCheckBox())
{
return oForm.IsCheckBoxChecked();
}
else if (oForm.IsPictureForm())
{
let oImg;
let allDrawings = oForm.GetAllDrawingObjects();
for (let nDrawing = 0; nDrawing < allDrawings.length; ++nDrawing)
{
if (allDrawings[nDrawing].IsPicture())
{
oImg = allDrawings[nDrawing].GraphicObj;
break;
}
}
if (oImg)
return oImg.getBase64Img();
}
return "";
};
})(window);