Merge remote-tracking branch 'remotes/origin/release/v7.4.0' into develop

This commit is contained in:
KirillovIlya
2023-05-17 19:37:14 +05:00
3 changed files with 265 additions and 149 deletions

191
api.js
View File

@ -87,7 +87,6 @@ window["AscOForm"] = window.AscOForm = AscOForm;
if (oFormPr)
{
private_ApplyFormPr(oCC, oFormPr, oLogicDocument);
oCC.UpdatePlaceHolderTextPrForForm();
private_CheckFormKey(oCC, oLogicDocument);
}
@ -442,6 +441,154 @@ window["AscOForm"] = window.AscOForm = AscOForm;
return AscWord.FormToJson(form);
};
window['Asc']['asc_docs_api'].prototype['asc_SetFormValue'] = window['Asc']['asc_docs_api'].prototype.asc_SetFormValue = function(value, formId)
{
let logicDocument = this.private_GetLogicDocument();
if (!logicDocument)
return;
let form = logicDocument.GetContentControl(formId);
if (!form || !form.IsForm())
return;
return this.private_SetFormValue(form.GetId(), value);
};
window['Asc']['asc_docs_api'].prototype['asc_GetFormValue'] = window['Asc']['asc_docs_api'].prototype.asc_GetFormValue = function(formId)
{
let logicDocument = this.private_GetLogicDocument();
if (!logicDocument)
return "";
let form = logicDocument.GetContentControl(formId);
if (!form || !form.IsForm())
return "";
if (form.IsPictureForm())
return "";
else if (form.IsCheckBox())
return form.IsCheckBoxChecked();
else if (form.IsPlaceHolder())
return "";
return form.GetInnerText();
};
window['Asc']['asc_docs_api'].prototype.private_SetFormValue = function(internalId, value)
{
let oLogicDocument = this.private_GetLogicDocument();
if (!AscCommon.g_oTableId
|| !oLogicDocument
|| !oLogicDocument.IsDocumentEditor())
return;
let oForm = AscCommon.g_oTableId.GetClass(internalId);
if (!oForm
|| !(oForm instanceof AscWord.CInlineLevelSdt)
|| !oForm.IsForm())
return;
let oParagraph = oForm.GetParagraph();
oForm.SkipFillingFormModeCheck(true);
oForm.SkipSpecialContentControlLock(true);
if (!oParagraph
|| oLogicDocument.IsSelectionLocked(AscCommon.changestype_None, {
Type : AscCommon.changestype_2_ElementsArray_and_Type,
Elements : [oParagraph],
CheckType : AscCommon.changestype_Paragraph_Content
}, true, oLogicDocument.IsFillingFormMode()))
{
oForm.SkipFillingFormModeCheck(false);
oForm.SkipSpecialContentControlLock(false);
return;
}
oForm.SkipFillingFormModeCheck(false);
oForm.SkipSpecialContentControlLock(false);
oLogicDocument.StartAction(AscDFH.historydescription_Document_FillFormInPlugin);
let isClear = false;
if (null === value)
{
isClear = true;
}
else if (oForm.IsTextForm() || oForm.IsComboBox())
{
let sValue = AscBuilder.GetStringParameter(value, "");
if (!sValue)
isClear = true;
else
oForm.SetInnerText(sValue);
}
else if (oForm.IsDropDownList())
{
let sValue = AscBuilder.GetStringParameter(value, "");
let oPr = oForm.GetDropDownListPr();
let nIndex = oPr.FindByText(sValue);
if (-1 !== nIndex)
oForm.SelectListItem(oPr.GetItemValue(nIndex));
else
isClear = true;
}
else if (oForm.IsCheckBox())
{
let isChecked = value === "true" ? true : value === "false" ? false : AscBuilder.GetBoolParameter(value, null);
if (null !== isChecked)
oForm.SetCheckBoxChecked(isChecked);
else
isClear = true;
}
else if (oForm.IsPictureForm())
{
let sValue = AscBuilder.GetStringParameter(value, "");
if (!sValue)
return;
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)
{
oForm.SetShowingPlcHdr(false);
oImg.setBlipFill(AscFormat.CreateBlipFillRasterImageId(sValue));
}
else
{
isClear = true;
}
}
else if (oForm.IsDatePicker())
{
let sValue = AscBuilder.GetStringParameter(value, "");
if (!sValue)
isClear = true;
else
oForm.SetInnerText(sValue);
// TODO: Надо FullDate попытаться выставить по заданному значение. Сейчас мы всегда сбрасываем на текущую дату
let datePickerPr = oForm.GetDatePickerPr().Copy();
datePickerPr.SetFullDate(null);
oForm.SetDatePickerPr(datePickerPr);
}
if (isClear)
oForm.ClearContentControlExt();
oLogicDocument.OnChangeForm(oForm);
oLogicDocument.Recalculate();
oLogicDocument.UpdateTracks();
oLogicDocument.UpdateInterface();
oLogicDocument.FinalizeAction();
};
function private_CheckFormKey(form, logicDocument)
{
@ -471,37 +618,55 @@ window["AscOForm"] = window.AscOForm = AscOForm;
form.SetFormPr(formPr.Copy());
let docPartId = form.GetPlaceholder();
let glossary = logicDocument.GetGlossaryDocument();
if ((form.IsTextForm()
|| form.IsDropDownList()
|| form.IsComboBox()
|| form.IsDatePicker())
&&
(docPartId === c_oAscDefaultPlaceholderName.Text
|| docPartId === c_oAscDefaultPlaceholderName.List
|| docPartId === c_oAscDefaultPlaceholderName.DateTime))
(docPartId === glossary.GetDefaultPlaceholderTextDocPartId()
|| docPartId === glossary.GetDefaultPlaceholderListDocPartId()
|| docPartId === glossary.GetDefaultPlaceholderDateTimeDocPartId()))
{
if (docPartId === c_oAscDefaultPlaceholderName.Text)
form.SetPlaceholder(c_oAscDefaultPlaceholderName.TextOform);
else if (docPartId === c_oAscDefaultPlaceholderName.List)
form.SetPlaceholder(c_oAscDefaultPlaceholderName.ListOform);
else if (docPartId === c_oAscDefaultPlaceholderName.DateTime)
form.SetPlaceholder(c_oAscDefaultPlaceholderName.DateOform);
if (docPartId === glossary.GetDefaultPlaceholderTextDocPartId())
form.SetPlaceholder(glossary.GetDefaultPlaceholderTextOformDocPartId());
else if (docPartId === glossary.GetDefaultPlaceholderListDocPartId())
form.SetPlaceholder(glossary.GetDefaultPlaceholderListOformDocPartId());
else if (docPartId === glossary.GetDefaultPlaceholderDateTimeDocPartId())
form.SetPlaceholder(glossary.GetDefaultPlaceholderDateTimeOformDocPartId());
if (form.IsPlaceHolder())
form.private_FillPlaceholderContent();
}
if (form.IsMainForm() && formPr.GetFixed())
let paragraph = form.GetParagraph();
if (form.IsMainForm() && formPr.GetFixed() && (!paragraph || !paragraph.GetParentShape()))
{
logicDocument.Recalculate(true);
let drawing = form.ConvertFormToFixed();
if (drawing)
{
logicDocument.Recalculate(true);
let x = drawing.Internal_Position.Calculate_X_Value(Asc.c_oAscRelativeFromH.Page);
let y = drawing.Internal_Position.Calculate_Y_Value(Asc.c_oAscRelativeFromV.Page);
let drawingPr = new Asc.asc_CImgProperty();
drawingPr.asc_putWrappingStyle(Asc.c_oAscWrapStyle2.Square);
drawing.Set_Props(drawingPr);
form.MoveCursorToContentControl(false);
let positionH = new Asc.CImagePositionH();
drawingPr.asc_putPositionH(positionH);
positionH.put_UseAlign(false);
positionH.put_RelativeFrom(Asc.c_oAscRelativeFromH.Page);
positionH.put_Value(x);
let positionV = new Asc.CImagePositionV();
drawingPr.asc_putPositionV(positionV);
positionV.put_UseAlign(false);
positionV.put_RelativeFrom(Asc.c_oAscRelativeFromV.Page);
positionV.put_Value(y);
drawing.Set_Props(drawingPr);
drawing.SelectAsDrawing();
}
}
}

View File

@ -38,6 +38,7 @@
// Import
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const AscBuilder = window["AscBuilder"];
const ApiDocument = AscBuilder.ApiDocument;
const GetStringParameter = AscBuilder.GetStringParameter;
const GetBoolParameter = AscBuilder.GetBoolParameter;
const GetNumberParameter = AscBuilder.GetNumberParameter;
@ -75,6 +76,19 @@
* Text field properties.
* @typedef {FormPrBase | TextFormPrBase} TextFormPr
*/
/**
* Form insertion specific properties.
* @typedef {Object} FormInsertPr
* @property {boolean} [placeholderFromSelection=false] - Specifies if the currently selected text should be saved as a placeholder of the inserted form.
* @property {boolean} [keepSelectedTextInForm=true] - Specifies if the currently selected text should be saved as the content of the inserted form.
*/
/**
* Properties for inserting a text field.
* @typedef {FormPrBase | TextFormPrBase | FormInsertPr} TextFormInsertPr
*/
/**
* Specific checkbox / radio button properties.
@ -146,18 +160,10 @@
if (!oFormPr)
oFormPr = {};
let oCC = CreateCommonForm(oFormPr);
let oPr = new AscCommon.CSdtTextFormPr();
oPr.SetComb(GetBoolParameter(oFormPr["comb"], false));
oPr.SetMaxCharacters(GetNumberParameter(oFormPr["maxCharacters"], -1));
oPr.SetMultiLine(GetBoolParameter(oFormPr["multiLine"], false));
oPr.SetAutoFit(GetBoolParameter(oFormPr["autoFit"], false));
oPr.SetWidth((GetNumberParameter(oFormPr["cellWidth"], 0) * 72 * 20 / 25.4) | 0);
oCC.ApplyTextFormPr(oPr);
CheckFormKey(oCC);
return new AscBuilder.ApiTextForm(oCC);
let form = CreateCommonForm(oFormPr);
ApplyTextFormPr(form, oFormPr);
CheckFormKey(form);
return new AscBuilder.ApiTextForm(form);
};
/**
* Creates a checkbox / radio button with the specified checkbox / radio button properties.
@ -333,32 +339,78 @@
CheckFormKey(oCC);
return new AscBuilder.ApiPictureForm(oCC);
};
/**
* Inserts a text box with the specified text box properties over the selected text.
* @memberof ApiDocument
* @param {TextFormInsertPr} oFormPr - Properties for inserting a text field.
* @returns {ApiTextForm}
*/
ApiDocument.prototype.InsertTextForm = function(oFormPr)
{
if (!oFormPr)
oFormPr = {};
let logicDocument = this.Document;
let placeholder = GetStringParameter(oFormPr["placeholder"], undefined);
if (GetBoolParameter(oFormPr["placeholderFromSelection"], false))
placeholder = logicDocument.GetSelectedText();
if (!GetBoolParameter(oFormPr["keepSelectedTextInForm"], true))
logicDocument.RemoveBeforePaste();
let contentControl = logicDocument.AddContentControl(c_oAscSdtLevelType.Inline);
if (!contentControl)
return null;
ApplyCommonFormPr(contentControl, oFormPr);
SetFormPlaceholder(contentControl, placeholder);
ApplyTextFormPr(contentControl, oFormPr, true);
CheckFormKey(contentControl);
return new AscBuilder.ApiTextForm(contentControl);
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Private area
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function CreateCommonForm(oFormPr)
{
if (!oFormPr)
oFormPr = {};
let contentControl = new AscCommonWord.CInlineLevelSdt();
var oTempFormPr = new AscCommon.CSdtFormPr();
oTempFormPr.SetHelpText(GetStringParameter(oFormPr["tip"], undefined));
oTempFormPr.SetRequired(GetBoolParameter(oFormPr["required"], false));
oTempFormPr.SetKey(GetStringParameter(oFormPr["key"], undefined));
var oCC = new AscCommonWord.CInlineLevelSdt();
let sPlaceHolder = GetStringParameter(oFormPr["placeholder"], undefined);
if (sPlaceHolder)
oCC.SetPlaceholderText(sPlaceHolder);
ApplyCommonFormPr(contentControl, oFormPr);
let placeholder = oFormPr ? GetStringParameter(oFormPr["placeholder"], undefined) : undefined;
SetFormPlaceholder(contentControl, placeholder);
contentControl.ReplaceContentWithPlaceHolder(false);
contentControl.UpdatePlaceHolderTextPrForForm();
return contentControl;
}
function SetFormPlaceholder(form, text)
{
if (text)
form.SetPlaceholderText(text);
else
oCC.SetPlaceholder(c_oAscDefaultPlaceholderName.Text);
oCC.ReplaceContentWithPlaceHolder(false);
oCC.SetFormPr(oTempFormPr);
oCC.UpdatePlaceHolderTextPrForForm();
return oCC;
form.SetPlaceholder(c_oAscDefaultPlaceholderName.Text);
}
function ApplyCommonFormPr(form, formPr)
{
if (!formPr)
formPr = {};
let sdtFormPr = new AscCommon.CSdtFormPr();
sdtFormPr.SetHelpText(GetStringParameter(formPr["tip"], undefined));
sdtFormPr.SetRequired(GetBoolParameter(formPr["required"], false));
sdtFormPr.SetKey(GetStringParameter(formPr["key"], undefined));
form.SetFormPr(sdtFormPr);
}
function ApplyTextFormPr(form, formPr, keepContent)
{
let textFormPr = new AscCommon.CSdtTextFormPr();
textFormPr.SetComb(GetBoolParameter(formPr["comb"], false));
textFormPr.SetMaxCharacters(GetNumberParameter(formPr["maxCharacters"], -1));
textFormPr.SetMultiLine(GetBoolParameter(formPr["multiLine"], false));
textFormPr.SetAutoFit(GetBoolParameter(formPr["autoFit"], false));
textFormPr.SetWidth((GetNumberParameter(formPr["cellWidth"], 0) * 72 * 20 / 25.4) | 0);
form.ApplyTextFormPr(textFormPr, keepContent);
}
function CheckFormKey(form)
{
@ -387,6 +439,8 @@
Api.prototype["CreateTextForm"] = Api.prototype.CreateTextForm;
Api.prototype["CreatePictureForm"] = Api.prototype.CreatePictureForm;
Api.prototype["CreateCheckBoxForm"] = Api.prototype.CreateCheckBoxForm;
Api.prototype["CreateComboBoxForm"] = Api.prototype.CreateComboBoxForm;
Api.prototype["CreateComboBoxForm"] = Api.prototype.CreateComboBoxForm;
ApiDocument.prototype["InsertTextForm"] = ApiDocument.prototype.InsertTextForm;
}(window, null));

View File

@ -114,110 +114,7 @@
*/
window["asc_docs_api"].prototype["pluginMethod_SetFormValue"] = function(internalId, value)
{
let oLogicDocument = this.private_GetLogicDocument();
if (!AscCommon.g_oTableId
|| !oLogicDocument
|| !oLogicDocument.IsDocumentEditor())
return;
let oForm = AscCommon.g_oTableId.GetClass(internalId);
if (!oForm
|| !(oForm instanceof AscWord.CInlineLevelSdt)
|| !oForm.IsForm())
return;
// При проверке лока внутри параграфа мы ориентируемся на выделение внутри этого параграфа
// поэтому нужно выделить форму
let state = oLogicDocument.SaveDocumentState();
oForm.SelectContentControl();
let oParagraph = oForm.GetParagraph();
oForm.SkipSpecialContentControlLock(true);
if (!oParagraph
|| oLogicDocument.IsSelectionLocked(AscCommon.changestype_None, {
Type : AscCommon.changestype_2_ElementsArray_and_Type,
Elements : [oParagraph],
CheckType : AscCommon.changestype_Paragraph_Content
}, true, oLogicDocument.IsFillingFormMode()))
{
oLogicDocument.LoadDocumentState(state);
oForm.SkipSpecialContentControlLock(false);
return;
}
oLogicDocument.LoadDocumentState(state);
oForm.SkipSpecialContentControlLock(false);
oLogicDocument.StartAction(AscDFH.historydescription_Document_FillFormInPlugin);
let isClear = false;
if (null === value)
{
isClear = true;
}
else if (oForm.IsTextForm() || oForm.IsComboBox())
{
let sValue = AscBuilder.GetStringParameter(value, "");
if (!value)
isClear = true;
else
oForm.SetInnerText(sValue);
}
else if (oForm.IsDropDownList())
{
let sValue = AscBuilder.GetStringParameter(value, "");
let oPr = oForm.GetDropDownListPr();
let nIndex = oPr.FindByText(sValue);
if (-1 !== nIndex)
oForm.SelectListItem(oPr.GetItemValue(nIndex));
else
isClear = true;
}
else if (oForm.IsCheckBox())
{
let isChecked = value === "true" ? true : value === "false" ? false : AscBuilder.GetBoolParameter(value, null);
if (null !== isChecked)
oForm.SetCheckBoxChecked(isChecked);
else
isClear = true;
}
else if (oForm.IsPictureForm())
{
let sValue = AscBuilder.GetStringParameter(value, "");
if (!sValue)
return;
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)
{
oForm.SetShowingPlcHdr(false);
oImg.setBlipFill(AscFormat.CreateBlipFillRasterImageId(sValue));
}
else
{
isClear = true;
}
}
if (isClear)
oForm.ClearContentControlExt();
oLogicDocument.OnChangeForm(oForm);
oLogicDocument.Recalculate();
oLogicDocument.UpdateTracks();
oLogicDocument.FinalizeAction();
this.private_SetFormValue(internalId, value);
};
/**
* Returns a value of the specified form.