Skip to content

Commit

Permalink
[de] Refactor applying content control properties
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillovIlya committed Feb 8, 2025
1 parent b85fae5 commit 044949c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 61 deletions.
42 changes: 6 additions & 36 deletions word/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,10 @@
}

_content_control_pr = new AscCommon.CContentControlPr();
_content_control_pr.Id = _current["Props"]["Id"];
_content_control_pr.Tag = _current["Props"]["Tag"];
_content_control_pr.Lock = c_oAscSdtLockType.Unlocked;
_content_control_pr.InternalId = _current["Props"]["InternalId"];
_content_control_pr.Alias = _current["Props"]["Alias"];
_content_control_pr.PlaceholderText = _current["Props"]["PlaceHolderText"];
AscCommon.readContentControlCommonPr(_content_control_pr, _current["Props"]);

_content_control_pr.Lock = c_oAscSdtLockType.Unlocked;
_content_control_pr.InternalId = _current["Props"]["InternalId"];

// Page break
if (undefined !== _current["Props"]["SectionBreak"])
Expand Down Expand Up @@ -568,18 +566,6 @@
LogicDocument.SetDocumentMargin(oMargins);
}

if (undefined !== _current["Props"]["Appearance"])
_content_control_pr.Appearance = _current["Props"]["Appearance"];

if (undefined !== _current["Props"]["Color"])
_content_control_pr.Color = new Asc.asc_CColor(_current["Props"]["Color"]["R"], _current["Props"]["Color"]["G"], _current["Props"]["Color"]["B"]);

if (undefined !== _current["Props"]["ShdColor"])
_content_control_pr.ShdColor = new Asc.asc_CColor(_current["Props"]["ShdColor"]["R"], _current["Props"]["ShdColor"]["G"], _current["Props"]["ShdColor"]["B"], _current["Props"]["ShdColor"]["A"]);

if (undefined !== _current["Props"]["BorderColor"])
_content_control_pr.BorderColor = new Asc.asc_CColor(_current["Props"]["BorderColor"]["R"], _current["Props"]["BorderColor"]["G"], _current["Props"]["BorderColor"]["B"], _current["Props"]["BorderColor"]["A"]);

if (null === _blockStd)
{
let curPara = LogicDocument.GetCurrentParagraph();
Expand Down Expand Up @@ -729,24 +715,8 @@
if (_blockStd)
{
_content_control_pr = new AscCommon.CContentControlPr();
_content_control_pr.Id = _current["Props"]["Id"];
_content_control_pr.Tag = _current["Props"]["Tag"];
_content_control_pr.Lock = _current["Props"]["Lock"];
_content_control_pr.InternalId = _current["Props"]["InternalId"];
_content_control_pr.Alias = _current["Props"]["Alias"];
_content_control_pr.PlaceholderText = _current["Props"]["PlaceHolderText"];

if (undefined !== _current["Props"]["Appearance"])
_content_control_pr.Appearance = _current["Props"]["Appearance"];

if (undefined !== _current["Props"]["Color"])
_content_control_pr.Color = new Asc.asc_CColor(_current["Props"]["Color"]["R"], _current["Props"]["Color"]["G"], _current["Props"]["Color"]["B"]);

if (undefined !== _current["Props"]["ShdColor"])
_content_control_pr.ShdColor = new Asc.asc_CColor(_current["Props"]["ShdColor"]["R"], _current["Props"]["ShdColor"]["G"], _current["Props"]["ShdColor"]["B"], _current["Props"]["ShdColor"]["A"]);

if (undefined !== _current["Props"]["BorderColor"])
_content_control_pr.BorderColor = new Asc.asc_CColor(_current["Props"]["BorderColor"]["R"], _current["Props"]["BorderColor"]["G"], _current["Props"]["BorderColor"]["B"], _current["Props"]["BorderColor"]["A"]);
AscCommon.readContentControlCommonPr(_content_control_pr, _current["Props"]);
_content_control_pr.InternalId = _current["Props"]["InternalId"];

_blockStd.SetContentControlPr(_content_control_pr);
LogicDocument.Recalculate();
Expand Down
70 changes: 45 additions & 25 deletions word/api_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,13 @@
* @property {string} PlaceHolderText - The content control placeholder text.
* @property {number} Appearance - Defines if the content control is shown as the bounding box (**1**) or not (**2**).
* @property {Color} Color - The color for the current content control in the RGB format.
* @property {Color} ShdColor - The background color for the current content control in the RGBA format.
* @property {Color} BorderColor - The border color for the current content control in the RGBA format.
* @property {Object} Shd - Background shading properties
* @property {Color} Shd.Color - Shading color in RGBA format
* @property {Object} Border - Border properties
* @property {Color} Border.Color - Border color in RGBA format
* @see office-js-api/Examples/Plugins/{Editor}/Enumeration/ContentControlProperties.js
*/

/**
* @typedef {('none' | 'comments' | 'forms' | 'readOnly')} DocumentEditingRestrictions
* The document editing restrictions:
Expand Down Expand Up @@ -630,7 +632,7 @@
*/
window["asc_docs_api"].prototype["pluginMethod_AddContentControl"] = function(type, commonPr)
{
var _content_control_pr = private_ReadContentControlCommonPr(commonPr);
var _content_control_pr = readContentControlCommonPr(commonPr);

var _obj = this.asc_AddContentControl(type, _content_control_pr);
if (!_obj)
Expand Down Expand Up @@ -1294,30 +1296,45 @@
if (commonPr)
{
resultPr = new AscCommon.CContentControlPr();

resultPr.Id = commonPr["Id"];
resultPr.Tag = commonPr["Tag"];
resultPr.Lock = commonPr["Lock"];
resultPr.Alias = commonPr["Alias"];

if (undefined !== commonPr["Appearance"])
resultPr.Appearance = commonPr["Appearance"];

if (undefined !== commonPr["Color"])
resultPr.Color = new Asc.asc_CColor(commonPr["Color"]["R"], commonPr["Color"]["G"], commonPr["Color"]["B"]);

if (undefined !== commonPr["PlaceHolderText"])
resultPr.SetPlaceholderText(commonPr["PlaceHolderText"]);

if (undefined !== commonPr["ShdColor"])
resultPr.ShdColor = new Asc.asc_CColor(commonPr["ShdColor"]["R"], commonPr["ShdColor"]["G"], commonPr["ShdColor"]["B"], commonPr["ShdColor"]["A"]);

if (undefined !== commonPr["BorderColor"])
resultPr.BorderColor = new Asc.asc_CColor(commonPr["BorderColor"]["R"], commonPr["BorderColor"]["G"], commonPr["BorderColor"]["B"], commonPr["BorderColor"]["A"]);
resultPr = readContentControlCommonPr(contentControlPr, commonPr);
}

return resultPr;
}
function readContentControlCommonPr(ccPr, commonPr)
{
if (!ccPr || !commonPr)
return ccPr;

ccPr.Id = commonPr["Id"];
ccPr.Tag = commonPr["Tag"];
ccPr.Lock = commonPr["Lock"];
ccPr.Alias = commonPr["Alias"];

if (undefined !== commonPr["Appearance"])
ccPr.Appearance = commonPr["Appearance"];

if (undefined !== commonPr["Color"])
ccPr.Color = new Asc.asc_CColor(commonPr["Color"]["R"], commonPr["Color"]["G"], commonPr["Color"]["B"]);

if (undefined !== commonPr["PlaceHolderText"])
ccPr.SetPlaceholderText(commonPr["PlaceHolderText"]);

let shd = commonPr["Shd"];
if (shd)
{
if (undefined !== shd["Color"])
ccPr.ShdColor = new Asc.asc_CColor(shd["Color"]["R"], shd["Color"]["G"], shd["Color"]["B"], shd["Color"]["A"]);
}

let border = commonPr["Border"];
if (border)
{
if (undefined !== border["Color"])
ccPr.BorderColor = new Asc.asc_CColor(border["Color"]["R"], border["Color"]["G"], border["Color"]["B"], border["Color"]["A"]);
}

return ccPr;
}
function private_GetTextDirection(type)
{
let direction = 0;
Expand All @@ -1336,6 +1353,9 @@
}
return direction;
}

window["AscCommon"] = window["AscCommon"] || {};
window["AscCommon"].readContentControlCommonPr = readContentControlCommonPr;

})(window);

Expand Down

0 comments on commit 044949c

Please sign in to comment.