Skip to content

Commit

Permalink
Add support of block level sdt in the Builder
Browse files Browse the repository at this point in the history
Also add a function for receiving all content controls in the document.
  • Loading branch information
KirillovIlya committed May 24, 2018
1 parent 1cd937a commit 303b9fa
Show file tree
Hide file tree
Showing 3 changed files with 233 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Selection
## 5.1.1
### All Editors
* Fix error with repeated reconnection
* Add support of a block-level content controls
* Add function for receiving all content controls in the document

### Document Editor
*
Expand Down
8 changes: 8 additions & 0 deletions word/Editor/StructuredDocumentTags/BlockLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ CBlockLevelSdt.prototype.GetType = function()
{
return type_BlockLevelSdt;
};
/**
* Получаем содержимое данного контейнера
* @returns {CDocumentContent}
*/
CBlockLevelSdt.prototype.GetContent = function()
{
return this.Content;
};
CBlockLevelSdt.prototype.Is_Inline = function()
{
return true;
Expand Down
227 changes: 223 additions & 4 deletions word/apiBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,22 @@
this.Sdt = Sdt;
}

/**
* Class represent a container for the content of the document
* @constructor
*/
function ApiBlockLvlSdt(Sdt)
{
this.Sdt = Sdt;
}

/**
* Twentieths of a point (equivalent to 1/1440th of an inch).
* @typedef {number} twips
*/

/**
* @typedef {(ApiParagraph | ApiTable)} DocumentElement
* @typedef {(ApiParagraph | ApiTable | ApiBlockLvlSdt)} DocumentElement
*/

/**
Expand Down Expand Up @@ -1101,6 +1110,15 @@
oSdt.Add_ToContent(0, new ParaRun(null, false));
return new ApiInlineLvlSdt(oSdt);
};

/**
* Create a new block level container
* @returns {ApiBlockLvlSdt}
*/
Api.prototype.CreateBlockLvlSdt = function()
{
return new ApiBlockLvlSdt(new CBlockLvlSdt());
};
//------------------------------------------------------------------------------------------------------------------
//
// ApiUnsupported
Expand Down Expand Up @@ -1147,11 +1165,13 @@
if (!this.Document.Content[nPos])
return null;

var Type = this.Document.Content[nPos].Get_Type();
var Type = this.Document.Content[nPos].GetType();
if (type_Paragraph === Type)
return new ApiParagraph(this.Document.Content[nPos]);
else if (type_Table === Type)
return new ApiTable(this.Document.Content[nPos]);
else if (type_BlockLevelSdt === Type)
return new ApiBlockLvlSdt(this.Document.Content[nPos]);

return null;
};
Expand All @@ -1162,7 +1182,7 @@
*/
ApiDocumentContent.prototype.AddElement = function(nPos, oElement)
{
if (oElement instanceof ApiParagraph || oElement instanceof ApiTable)
if (oElement instanceof ApiParagraph || oElement instanceof ApiTable || oElement instanceof ApiBlockLvlSdt)
{
this.Document.Internal_Content_Add(nPos, oElement.private_GetImpl());
}
Expand Down Expand Up @@ -1540,6 +1560,26 @@

this.Document.Search_Replace(sReplace, true, null, false);
};
/**
* Get the list of all content controls in the document
* @returns {ApiBlockLvlSdt[] | ApiInlineLvlSdt[]}
*/
ApiDocument.prototype.GetAllContentControls = function()
{
var arrResult = [];
var arrControls = this.Document.GetAllContentControls();
for (var nIndex = 0, nCount = arrControls.length; nIndex < nCount; ++nIndex)
{
var oControl = arrControls[nIndex];

if (oControl instanceof CBlockLevelSdt)
arrResult.push(new ApiBlockLvlSdt(oControl));
else if (oControl instanceof CInlineLevelSdt)
arrResult.push(new ApiInlineLvlSdt(oControl));
}

return arrResult;
};
//------------------------------------------------------------------------------------------------------------------
//
// ApiParagraph
Expand Down Expand Up @@ -4544,6 +4584,25 @@

this.Sdt.SetContentControlLock(nLock);
};
/**
* Get the lock type of this container
* @returns {SdtLock}
*/
ApiInlineLvlSdt.prototype.GetLock = function()
{
var nLock = this.Sdt.GetContentControlLock();

var sResult = "unlocked";

if (sdtlock_ContentLocked === nLock)
sResult = "contentLocked";
else if (sdtlock_SdtContentLocked === nLock)
sResult = "sdtContentLocked";
else if (sdtlock_SdtLocked === nLock)
sResult = "sdtLocked";

return sResult;
};
/**
* Set the tag attribute for this container
* @param {string} sTag
Expand All @@ -4552,6 +4611,14 @@
{
this.Sdt.SetTag(sTag);
};
/**
* Get the tag attribute for this container
* @returns {string}
*/
ApiInlineLvlSdt.prototype.GetTag = function()
{
return this.Sdt.GetTag();
};
/**
* Set the label attribute for this container
* @param {string} sLabel
Expand All @@ -4560,6 +4627,30 @@
{
this.Sdt.SetLabel(sLabel);
};
/**
* Get the label attribute for this container
* @returns {string}
*/
ApiInlineLvlSdt.prototype.GetLabel = function()
{
return this.Sdt.GetLabel();
};
/**
* Set the alias attribute for this container
* @param {string} sAlias
*/
ApiInlineLvlSdt.prototype.SetAlias = function(sAlias)
{
this.Sdt.SetAlias(sAlias);
};
/**
* Get the alias attribute for this container
* @returns {string}
*/
ApiInlineLvlSdt.prototype.GetAlias = function()
{
return this.Sdt.GetAlias();
};
/**
* Get the number of elements in the current container.
* @returns {number}
Expand Down Expand Up @@ -4623,7 +4714,112 @@

return true;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//------------------------------------------------------------------------------------------------------------------
//
// ApiBlockLvlSdt
//
//------------------------------------------------------------------------------------------------------------------
/**
* Get the type of this class.
* @returns {"blockLvlSdt"}
*/
ApiBlockLvlSdt.prototype.GetClassType = function()
{
return "blockLvlSdt";
};
/**
* Set the lock type of this container
* @param {SdtLock} sLockType
*/
ApiBlockLvlSdt.prototype.SetLock = function(sLockType)
{
var nLock = sdtlock_Unlocked;
if ("contentLocked" === sLockType)
nLock = sdtlock_ContentLocked;
else if ("sdtContentLocked" === sLockType)
nLock = sdtlock_SdtContentLocked;
else if ("sdtLocked" === sLockType)
nLock = sdtlock_SdtLocked;

this.Sdt.SetContentControlLock(nLock);
};
/**
* Get the lock type of this container
* @returns {SdtLock}
*/
ApiBlockLvlSdt.prototype.GetLock = function()
{
var nLock = this.Sdt.GetContentControlLock();

var sResult = "unlocked";

if (sdtlock_ContentLocked === nLock)
sResult = "contentLocked";
else if (sdtlock_SdtContentLocked === nLock)
sResult = "sdtContentLocked";
else if (sdtlock_SdtLocked === nLock)
sResult = "sdtLocked";

return sResult;
};
/**
* Set the tag attribute for this container
* @param {string} sTag
*/
ApiBlockLvlSdt.prototype.SetTag = function(sTag)
{
this.Sdt.SetTag(sTag);
};
/**
* Get the tag attribute for this container
* @returns {string}
*/
ApiBlockLvlSdt.prototype.GetTag = function()
{
return this.Sdt.GetTag();
};
/**
* Set the label attribute for this container
* @param {string} sLabel
*/
ApiBlockLvlSdt.prototype.SetLabel = function(sLabel)
{
this.Sdt.SetLabel(sLabel);
};
/**
* Get the label attribute for this container
* @returns {string}
*/
ApiBlockLvlSdt.prototype.GetLabel = function()
{
return this.Sdt.GetLabel();
};
/**
* Set the alias attribute for this container
* @param {string} sAlias
*/
ApiBlockLvlSdt.prototype.SetAlias = function(sAlias)
{
this.Sdt.SetAlias(sAlias);
};
/**
* Get the alias attribute for this container
* @returns {string}
*/
ApiBlockLvlSdt.prototype.GetAlias = function()
{
return this.Sdt.GetAlias();
};
/**
* Get the content of this container
* @returns {ApiDocumentContent}
*/
ApiBlockLvlSdt.prototype.GetContent = function()
{
return new ApiDocumentContent(this.Sdt.GetContent());
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Export
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Api.prototype["GetDocument"] = Api.prototype.GetDocument;
Expand All @@ -4647,6 +4843,7 @@
Api.prototype["CreateBullet"] = Api.prototype.CreateBullet;
Api.prototype["CreateNumbering"] = Api.prototype.CreateNumbering;
Api.prototype["CreateInlineLvlSdt"] = Api.prototype.CreateInlineLvlSdt;
Api.prototype["CreateBlockLvlSdt"] = Api.prototype.CreateBlockLvlSdt;

ApiUnsupported.prototype["GetClassType"] = ApiUnsupported.prototype.GetClassType;

Expand Down Expand Up @@ -4674,6 +4871,7 @@
ApiDocument.prototype["GetReviewReport"] = ApiDocument.prototype.GetReviewReport;
ApiDocument.prototype["InsertWatermark"] = ApiDocument.prototype.InsertWatermark;
ApiDocument.prototype["SearchAndReplace"] = ApiDocument.prototype.SearchAndReplace;
ApiDocument.prototype["GetAllContentControls"] = ApiDocument.prototype.GetAllContentControls;

ApiParagraph.prototype["GetClassType"] = ApiParagraph.prototype.GetClassType;
ApiParagraph.prototype["AddText"] = ApiParagraph.prototype.AddText;
Expand Down Expand Up @@ -4913,14 +5111,31 @@

ApiInlineLvlSdt.prototype["GetClassType"] = ApiInlineLvlSdt.prototype.GetClassType;
ApiInlineLvlSdt.prototype["SetLock"] = ApiInlineLvlSdt.prototype.SetLock;
ApiInlineLvlSdt.prototype["GetLock"] = ApiInlineLvlSdt.prototype.GetLock;
ApiInlineLvlSdt.prototype["SetTag"] = ApiInlineLvlSdt.prototype.SetTag;
ApiInlineLvlSdt.prototype["GetTag"] = ApiInlineLvlSdt.prototype.GetTag;
ApiInlineLvlSdt.prototype["SetLabel"] = ApiInlineLvlSdt.prototype.SetLabel;
ApiInlineLvlSdt.prototype["GetLabel"] = ApiInlineLvlSdt.prototype.GetLabel;
ApiInlineLvlSdt.prototype["SetAlias"] = ApiInlineLvlSdt.prototype.SetAlias;
ApiInlineLvlSdt.prototype["GetAlias"] = ApiInlineLvlSdt.prototype.GetAlias;
ApiInlineLvlSdt.prototype["GetElementsCount"] = ApiInlineLvlSdt.prototype.GetElementsCount;
ApiInlineLvlSdt.prototype["GetElement"] = ApiInlineLvlSdt.prototype.GetElement;
ApiInlineLvlSdt.prototype["RemoveElement"] = ApiInlineLvlSdt.prototype.RemoveElement;
ApiInlineLvlSdt.prototype["RemoveAllElements"] = ApiInlineLvlSdt.prototype.RemoveAllElements;
ApiInlineLvlSdt.prototype["AddElement"] = ApiInlineLvlSdt.prototype.AddElement;


ApiBlockLvlSdt.prototype["GetClassType"] = ApiBlockLvlSdt.prototype.GetClassType;
ApiBlockLvlSdt.prototype["SetLock"] = ApiBlockLvlSdt.prototype.SetLock;
ApiBlockLvlSdt.prototype["GetLock"] = ApiBlockLvlSdt.prototype.GetLock;
ApiBlockLvlSdt.prototype["SetTag"] = ApiBlockLvlSdt.prototype.SetTag;
ApiBlockLvlSdt.prototype["GetTag"] = ApiBlockLvlSdt.prototype.GetTag;
ApiBlockLvlSdt.prototype["SetLabel"] = ApiBlockLvlSdt.prototype.SetLabel;
ApiBlockLvlSdt.prototype["GetLabel"] = ApiBlockLvlSdt.prototype.GetLabel;
ApiBlockLvlSdt.prototype["SetAlias"] = ApiBlockLvlSdt.prototype.SetAlias;
ApiBlockLvlSdt.prototype["GetAlias"] = ApiBlockLvlSdt.prototype.GetAlias;
ApiBlockLvlSdt.prototype["GetContent"] = ApiBlockLvlSdt.prototype.GetContent;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private area
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -5504,6 +5719,10 @@
{
return this.Sdt;
};
ApiBlockLvlSdt.prototype.private_GetImpl = function()
{
return this.Sdt;
};

Api.prototype.private_CreateApiParagraph = function(oParagraph){
return new ApiParagraph(oParagraph);
Expand Down

0 comments on commit 303b9fa

Please sign in to comment.