Compare commits

...

10 Commits

Author SHA1 Message Date
f66be53fd0 [builder] Added methods for creating forms (#9) 2022-04-25 21:00:54 +03:00
c5be1a3dbf Merge branch hotfix/v7.0.1 into release/v7.1.0 2022-03-23 10:27:40 +00:00
c8d9a38731 [bug] fix bug 55913: remove flip and rotation at adding image to form 2022-03-18 17:40:24 +03:00
470b4f90cf fix comment 2022-03-18 17:26:32 +03:00
9b93c07cad [bug] fix bug 55913 2022-03-18 08:53:52 +03:00
a3e8339c9b Fix bug #55868
Fix the problem with selection after undo/redo
2022-03-03 16:41:06 +03:00
8b5a088408 Fix bug #55866
Fix the problem with reverse selection when adding checkbox
2022-03-03 16:25:03 +03:00
1ed02174b2 For bug #55833
Fix the problem with creating non empty image form
2022-03-02 16:57:29 +03:00
be85148d32 Fix bug #55502
Fix the problem with adding checkboxes by text selection
2022-02-22 14:30:33 +03:00
d5a98c6335 For bug #55502 2022-02-16 15:11:16 +03:00
3 changed files with 403 additions and 13 deletions

128
api.js
View File

@ -75,27 +75,78 @@
isLoadFonts = true;
AscFonts.FontPickerByCharacter.getFontBySymbol(nUncheckedSymbol);
}
function private_ApplyPrToCheckBox(oCC)
{
if (!oCC)
return;
if (oFormPr)
{
oCC.SetFormPr(oFormPr);
oCC.UpdatePlaceHolderTextPrForForm();
}
if (oCommonPr)
oCC.SetContentControlPr(oCommonPr);
}
function private_PerformAddCheckBox()
{
oLogicDocument.RemoveTextSelection();
if (!oLogicDocument.IsSelectionLocked(AscCommon.changestype_Paragraph_Content))
{
oLogicDocument.StartAction(AscDFH.historydescription_Document_AddContentControlCheckBox);
var oCC = oLogicDocument.AddContentControlCheckBox(oPr);
if (oCC && oFormPr)
if (oLogicDocument.IsTextSelectionUse())
{
let arrSelectedParagraphs = oLogicDocument.GetSelectedParagraphs();
// Select entire paragraphs so that after the action all added checkboxes are included in the selection
let nSelectDirection = oLogicDocument.GetSelectDirection();
for (let nIndex = 0, nCount = arrSelectedParagraphs.length; nIndex < nCount; ++nIndex)
{
oCC.SetFormPr(oFormPr);
oCC.UpdatePlaceHolderTextPrForForm();
arrSelectedParagraphs[nIndex].SelectAll(nSelectDirection);
}
if (oCC && oCommonPr)
oCC.SetContentControlPr(oCommonPr);
let oState = oLogicDocument.SaveDocumentState(false);
oLogicDocument.UpdateInterface();
oLogicDocument.Recalculate();
oLogicDocument.FinalizeAction();
if (arrSelectedParagraphs.length > 0
&& !oLogicDocument.IsSelectionLocked(AscCommon.changestype_None, {
Type : AscCommon.changestype_2_ElementsArray_and_Type,
Elements : arrSelectedParagraphs,
CheckType : AscCommon.changestype_Paragraph_Content
}))
{
oLogicDocument.StartAction(AscDFH.historydescription_Document_AddContentControlCheckBox);
oLogicDocument.RemoveSelection();
for (let nIndex = 0, nCount = arrSelectedParagraphs.length; nIndex < nCount; ++nIndex)
{
let oCC = arrSelectedParagraphs[nIndex].AddCheckBoxToStartPos(oPr);
private_ApplyPrToCheckBox(oCC);
}
oLogicDocument.LoadDocumentState(oState);
oLogicDocument.UpdateInterface();
oLogicDocument.Recalculate();
oLogicDocument.FinalizeAction();
}
else
{
oLogicDocument.LoadDocumentState(oState);
}
}
else
{
oLogicDocument.RemoveTextSelection();
if (!oLogicDocument.IsSelectionLocked(AscCommon.changestype_Paragraph_Content))
{
oLogicDocument.StartAction(AscDFH.historydescription_Document_AddContentControlCheckBox);
var oCC = oLogicDocument.AddContentControlCheckBox(oPr);
private_ApplyPrToCheckBox(oCC);
oLogicDocument.UpdateInterface();
oLogicDocument.Recalculate();
oLogicDocument.FinalizeAction();
}
}
}
@ -130,6 +181,57 @@
oCC.UpdatePlaceHolderTextPrForForm();
oCC.ConvertFormToFixed();
oCC.SetPictureFormPr(new AscCommon.CSdtPictureFormPr());
var aDrawings = oCC.GetAllDrawingObjects();
for(var nDrawing = 0; nDrawing < aDrawings.length; ++nDrawing)
{
var oDrawing = aDrawings[nDrawing];
var oGraphic = oDrawing.GraphicObj;
if(oGraphic && oGraphic.getObjectType() === AscDFH.historyitem_type_ImageShape)
{
var oSpPr = oGraphic.spPr;
if(oSpPr)
{
if(oSpPr.Fill)
{
oSpPr.setFill(null);
}
if(oSpPr.ln)
{
oSpPr.setLn(null);
}
if(oSpPr.geometry)
{
oSpPr.setGeometry(null);
}
var oXfrm = oSpPr.xfrm;
if(oXfrm)
{
if(!AscFormat.fApproxEqual(oXfrm.rot, 0.0))
{
oXfrm.setRot(0);
}
if(oXfrm.flipH)
{
oXfrm.setFlipH(false);
}
if(oXfrm.flipH)
{
oXfrm.setFlipH(false);
}
if(oXfrm.flipV)
{
oXfrm.setFlipV(false);
}
}
}
}
}
if (!oCC.IsPlaceHolder())
{
oLogicDocument.Recalculate(true);
oCC.UpdatePictureFormLayout();
}
}
if (oCC && oCommonPr)

287
apiBuilder.js Normal file
View File

@ -0,0 +1,287 @@
/*
* (c) Copyright Ascensio System SIA 2010-2019
*
* 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-12 Ernesta Birznieka-Upisha
* 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, builder)
{
/**
* Base class
* @global
* @class
* @name Api
*/
var Api = window["Asc"]["asc_docs_api"] || window["Asc"]["spreadsheet_api"];
/**
* Checkbox form properties.
* @typedef {Object} CheckBoxFormPr
* @property {string} Key
* @property {string} Tip
* @property {boolean} Required
*/
/**
* Checkbox form properties.
* @typedef {Object} FormPr
* @property {string} Key
* @property {string} Tip
* @property {boolean} Required
* @property {string} Placeholder
*/
/**
* Checkbox form properties.
* @typedef {Object} PicFormPr
* @property {string} Key
* @property {string} Tip
* @property {boolean} Required
* @property {string} Placeholder
* @property {ScaleCase} Scale
*/
/**
* Condition when to scale image.
* @typedef {"always" | "never" | "tooBig" | "tooSmall"} ScaleCase
*/
/**
* Creates the checkbox (or radiobutton) form.
* @memberof Api
* @param {CheckBoxFormPr} [oFormPr={Key: "", Tip: "", Required: false}] - checkbox(radiobutton) form properties.
* @param {boolean} [isRadioButton=false] - indicates whether radiobutton form will be created.
* @returns {ApiCheckBoxForm}
*/
Api.prototype.CreateCheckBoxForm = function(oFormPr, isRadioButton)
{
if (!oFormPr)
oFormPr = {};
oFormPr.Placeholder = undefined;
if (isRadioButton === true)
{
oFormPr.GroupKey = oFormPr.Key && typeof(oFormPr.Key) === "string" && oFormPr.Key !== "" ? oFormPr.Key : "Group 1";
oFormPr.Key = undefined;
}
else
{
oFormPr.Key = oFormPr.Key && typeof(oFormPr.Key) === "string" && oFormPr.Key !== "" ? oFormPr.Key : undefined;
oFormPr.GroupKey = undefined;
}
var oCC;
var oCheckboxPr = new AscCommon.CSdtCheckBoxPr();
if (oFormPr.GroupKey)
{
oCheckboxPr.CheckedSymbol = 0x25C9;
oCheckboxPr.UncheckedSymbol = 0x25CB;
oCheckboxPr.GroupKey = oFormPr.GroupKey;
}
else
{
oCheckboxPr.CheckedSymbol = 0x2611;
oCheckboxPr.UncheckedSymbol = 0x2610;
}
oCheckboxPr.CheckedFont = "Segoe UI Symbol";
oCheckboxPr.UncheckedFont = "Segoe UI Symbol";
var nCheckedSymbol = oCheckboxPr && oCheckboxPr.CheckedSymbol ? oCheckboxPr.CheckedSymbol : Asc.c_oAscSdtCheckBoxDefaults.CheckedSymbol;
var nUncheckedSymbol = oCheckboxPr && oCheckboxPr.UncheckedSymbol ? oCheckboxPr.UncheckedSymbol : Asc.c_oAscSdtCheckBoxDefaults.UncheckedSymbol;
var sCheckedFont = oCheckboxPr && oCheckboxPr.CheckedFont ? oCheckboxPr.CheckedFont : Asc.c_oAscSdtCheckBoxDefaults.CheckedFont;
var sUncheckedFont = oCheckboxPr && oCheckboxPr.UncheckedFont ? oCheckboxPr && oCheckboxPr.UncheckedFont : Asc.c_oAscSdtCheckBoxDefaults.UncheckedFont;
var isLoadFonts = false;
if (!AscCommon.IsAscFontSupport(sCheckedFont, nCheckedSymbol))
{
isLoadFonts = true;
AscFonts.FontPickerByCharacter.getFontBySymbol(nCheckedSymbol);
}
if (!AscCommon.IsAscFontSupport(sUncheckedFont, nUncheckedSymbol))
{
isLoadFonts = true;
AscFonts.FontPickerByCharacter.getFontBySymbol(nUncheckedSymbol);
}
function private_PerformAddCheckBox()
{
oCC = private_CreateCommonForm(oFormPr);
oCC.ApplyCheckBoxPr(oCheckboxPr);
}
if (isLoadFonts)
{
var oFonts = {};
oFonts[sCheckedFont] = true;
oFonts[sUncheckedFont] = true;
AscCommon.Check_LoadingDataBeforePrepaste(this, oFonts, {}, private_PerformAddCheckBox);
}
else
{
private_PerformAddCheckBox();
}
return new AscBuilder.ApiCheckBoxForm(oCC);
};
/**
* Creates the text form.
* @memberof Api
* @param {FormPr} [oFormPr={Key: "", Tip: "", Required: false}] - form properties.
* @returns {ApiTextForm}
*/
Api.prototype.CreateTextForm = function(oFormPr)
{
if (!oFormPr)
oFormPr = {};
var oCC = private_CreateCommonForm(oFormPr);
var oPr = new AscCommon.CSdtTextFormPr();
oCC.ApplyTextFormPr(oPr);
return new AscBuilder.ApiTextForm(oCC);
};
/**
* Creates the combobox (or dropdown) form.
* @memberof Api
* @param {FormPr} [oFormPr={Key: "", Tip: "", Required: false}] - form properties.
* @param {boolean} [isDropDown=false] - indicates whether dropdown form will be created.
* @returns {ApiComboBoxForm}
*/
Api.prototype.CreateComboBoxForm = function(oFormPr, isDropDown)
{
if (!oFormPr)
oFormPr = {};
var oPr = new CSdtComboBoxPr();
oPr.AddItem(AscCommon.translateManager.getValue("Choose an item"), "");
var oCC = private_CreateCommonForm(oFormPr);
if (isDropDown === true)
{
if (typeof(oFormPr.Placeholder) !== "string" || oFormPr.Placeholder === "")
{
oCC.ApplyDropDownListPr(oPr);
}
else
{
oCC.SetDropDownListPr(oPr);
oCC.SelectListItem();
}
}
else
{
if (typeof(oFormPr.Placeholder) !== "string" || oFormPr.Placeholder === "")
{
oCC.ApplyComboBoxPr(oPr);
}
else
{
oCC.SetComboBoxPr(oPr);
oCC.SelectListItem();
}
}
return new AscBuilder.ApiComboBoxForm(oCC);
};
/**
* Creates the picture form.
* @memberof Api
* @param {PicFormPr} [oFormPr={Key: "", Tip: "", Required: false, Scale: "always"}] - picture form properties
* @returns {ApiPictureForm}
*/
Api.prototype.CreatePictureForm = function(oFormPr)
{
if (!oFormPr)
oFormPr = {};
if (typeof(oFormPr.Placeholder) !== "string" || oFormPr.Placeholder === "")
oFormPr.Placeholder = AscCommon.translateManager.getValue("Click to load image");
var oCC = private_CreateCommonForm(oFormPr);
oCC.ApplyPicturePr(true);
oCC.ConvertFormToFixed();
oCC.SetPictureFormPr(new AscCommon.CSdtPictureFormPr());
var oApiForm = new AscBuilder.ApiPictureForm(oCC);
if (typeof(oFormPr.Scale) === "string" || oFormPr.Scale !== "")
oApiForm.SetPictureScaleCase(oFormPr.Scale);
return oApiForm;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private area
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function private_CreateCommonForm(oFormPr)
{
if (!oFormPr)
oFormPr = {};
var oTempFormPr = new AscCommon.CSdtFormPr();
oTempFormPr.HelpText = oFormPr.Tip && typeof(oFormPr.Tip) === "string" && oFormPr.Tip !== "" ? oFormPr.Tip : undefined;
oTempFormPr.Required = oFormPr.Required && typeof(oFormPr.Required) === "boolean" ? oFormPr.Required : false;
oTempFormPr.Key = oFormPr.Key && typeof(oFormPr.Key) === "string" && oFormPr.Key !== "" ? oFormPr.Key : undefined;
var oCC = new AscCommonWord.CInlineLevelSdt();
if (typeof(oFormPr.Placeholder) === "string" && oFormPr.Placeholder !== "")
oCC.SetPlaceholderText(oFormPr.Placeholder);
else
oCC.SetPlaceholder(c_oAscDefaultPlaceholderName.Text);
oCC.ReplaceContentWithPlaceHolder(false);
oCC.SetFormPr(oTempFormPr);
oCC.UpdatePlaceHolderTextPrForForm();
return oCC;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Export
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Api.prototype["CreateTextForm"] = Api.prototype.CreateTextForm;
Api.prototype["CreatePictureForm"] = Api.prototype.CreatePictureForm;
Api.prototype["CreateCheckBoxForm"] = Api.prototype.CreateCheckBoxForm;
Api.prototype["CreateComboBoxForm"] = Api.prototype.CreateComboBoxForm;
}(window, null));

View File

@ -4,6 +4,7 @@
"api.js"
],
"common": [
"apiBuilder.js"
]
}
}