Commit 6027d075 authored by Ilya Kirillov's avatar Ilya Kirillov

Added test variant of text form fields.

parent 85ec90f5
......@@ -1630,6 +1630,7 @@
//------------------------------------------------------------------------------------------------------------------
window['AscDFH'].historyitem_Field_AddItem = window['AscDFH'].historyitem_type_Field | 1;
window['AscDFH'].historyitem_Field_RemoveItem = window['AscDFH'].historyitem_type_Field | 2;
window['AscDFH'].historyitem_Field_FormFieldName = window['AscDFH'].historyitem_type_Field | 3;
//------------------------------------------------------------------------------------------------------------------
// Типы изменений в классе Footnotes
//------------------------------------------------------------------------------------------------------------------
......
......@@ -1205,6 +1205,19 @@ CDocumentFieldsManager.prototype.Restore_MailMergeTemplate = function()
}
}
};
CDocumentFieldsManager.prototype.GetAllFieldsByType = function(nType)
{
var arrFields = [];
for (var nIndex = 0, nCount = this.m_aFields.length; nIndex < nCount; ++nIndex)
{
var oField = this.m_aFields[nIndex];
if (nType === oField.Get_FieldType() && oField.Is_UseInDocument())
{
arrFields.push(oField);
}
}
return arrFields;
};
var selected_None = -1;
var selected_DrawingObject = 0;
......@@ -15991,6 +16004,30 @@ CDocument.prototype.RemoveTextSelection = function()
{
this.Controller.RemoveTextSelection();
};
CDocument.prototype.AddFormTextField = function(sName, sDefaultText)
{
if (false === this.Document_Is_SelectionLocked(AscCommon.changestype_Paragraph_Content))
{
this.Create_NewHistoryPoint(AscDFH.historydescription_Document_AddMailMergeField);
var oField = new ParaField(fieldtype_FORMTEXT);
var oRun = new ParaRun();
oField.SetFormFieldName(sName);
for (var nIndex = 0, nLen = sDefaultText.length; nIndex < nLen; ++nIndex)
{
oRun.Add_ToContent(nIndex, new ParaText(sDefaultText.charAt(nIndex)));
}
oField.Add_ToContent(0, oRun);
this.Register_Field(oField);
this.Paragraph_Add(oField);
this.Document_UpdateInterfaceState();
}
};
CDocument.prototype.GetAllFormTextFields = function()
{
return this.FieldsManager.GetAllFieldsByType(fieldtype_FORMTEXT);
};
function CDocumentSelectionState()
......
......@@ -39,6 +39,7 @@ var fieldtype_UNKNOWN = 0x0000;
var fieldtype_MERGEFIELD = 0x0001;
var fieldtype_PAGENUM = 0x0002;
var fieldtype_PAGECOUNT = 0x0003;
var fieldtype_FORMTEXT = 0x0004;
/**
*
......@@ -64,6 +65,8 @@ function ParaField(FieldType, Arguments, Switches)
this.Bounds = {};
this.FormFieldName = "";
// Добавляем данный класс в таблицу Id (обязательно в конце конструктора)
AscCommon.g_oTableId.Add( this, this.Id );
}
......@@ -246,6 +249,107 @@ ParaField.prototype.Draw_HighLights = function(PDSH)
PDSH.MMFields.Add(Y0, Y1, X0, X1, 0, 0, 0, 0 );
}
};
ParaField.prototype.Is_UseInDocument = function()
{
return (this.Paragraph && true === this.Paragraph.Is_UseInDocument() && true === this.Is_UseInParagraph() ? true : false);
};
ParaField.prototype.Is_UseInParagraph = function()
{
if (!this.Paragraph)
return false;
var ContentPos = this.Paragraph.Get_PosByElement(this);
if (!ContentPos)
return false;
return true;
};
ParaField.prototype.Get_LeftPos = function(SearchPos, ContentPos, Depth, UseContentPos)
{
if (false === UseContentPos && this.Content.length > 0)
{
// При переходе в новый контент встаем в его конец
var CurPos = this.Content.length - 1;
this.Content[CurPos].Get_EndPos(false, SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(CurPos, Depth);
SearchPos.Found = true;
return true;
}
ParaField.superclass.Get_LeftPos.call(this, SearchPos, ContentPos, Depth, UseContentPos);
};
ParaField.prototype.Get_RightPos = function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd)
{
if (false === UseContentPos && this.Content.length > 0)
{
// При переходе в новый контент встаем в его начало
this.Content[0].Get_StartPos(SearchPos.Pos, Depth + 1);
SearchPos.Pos.Update(0, Depth);
SearchPos.Found = true;
return true;
}
ParaField.superclass.Get_RightPos.call(this, SearchPos, ContentPos, Depth, UseContentPos, StepEnd);
};
CParagraphContentWithParagraphLikeContent.prototype.Get_LeftPos = function(SearchPos, ContentPos, Depth, UseContentPos)
{
if (this.Content.length <= 0)
return false;
var CurPos = ( true === UseContentPos ? ContentPos.Get(Depth) : this.Content.length - 1 );
this.Content[CurPos].Get_LeftPos(SearchPos, ContentPos, Depth + 1, UseContentPos);
SearchPos.Pos.Update( CurPos, Depth );
if ( true === SearchPos.Found )
return true;
CurPos--;
while ( CurPos >= 0 )
{
this.Content[CurPos].Get_LeftPos(SearchPos, ContentPos, Depth + 1, false);
SearchPos.Pos.Update( CurPos, Depth );
if ( true === SearchPos.Found )
return true;
CurPos--;
}
return false;
};
CParagraphContentWithParagraphLikeContent.prototype.Get_RightPos = function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd)
{
if (this.Content.length <= 0)
return false;
var CurPos = ( true === UseContentPos ? ContentPos.Get(Depth) : 0 );
this.Content[CurPos].Get_RightPos(SearchPos, ContentPos, Depth + 1, UseContentPos, StepEnd);
SearchPos.Pos.Update( CurPos, Depth );
if ( true === SearchPos.Found )
return true;
CurPos++;
var Count = this.Content.length;
while ( CurPos < this.Content.length )
{
this.Content[CurPos].Get_RightPos(SearchPos, ContentPos, Depth + 1, false, StepEnd);
SearchPos.Pos.Update( CurPos, Depth );
if ( true === SearchPos.Found )
return true;
CurPos++;
}
return false;
};
//----------------------------------------------------------------------------------------------------------------------
// Работа с данными поля
//----------------------------------------------------------------------------------------------------------------------
......@@ -375,6 +479,25 @@ ParaField.prototype.private_GetMappedRun = function(Value)
return oRun;
};
ParaField.prototype.SetFormFieldName = function(sName)
{
History.Add(new CChangesParaFieldFormFieldName(this, this.FormFieldName, sName));
this.FormFieldName = sName;
};
ParaField.prototype.GetFormFieldName = function()
{
return this.FormFieldName;
};
ParaField.prototype.GetValue = function()
{
var oText = new CParagraphGetText();
oText.SetBreakOnNonText(false);
oText.SetParaEndToSpace(true);
this.Get_Text(oText);
return oText.Text;
};
//----------------------------------------------------------------------------------------------------------------------
// Функции совместного редактирования
//----------------------------------------------------------------------------------------------------------------------
......
......@@ -39,12 +39,14 @@
AscDFH.changesFactory[AscDFH.historyitem_Field_AddItem] = CChangesParaFieldAddItem;
AscDFH.changesFactory[AscDFH.historyitem_Field_RemoveItem] = CChangesParaFieldRemoveItem;
AscDFH.changesFactory[AscDFH.historyitem_Field_FormFieldName] = CChangesParaFieldFormFieldName;
//----------------------------------------------------------------------------------------------------------------------
// Карта зависимости изменений
//----------------------------------------------------------------------------------------------------------------------
AscDFH.changesRelationMap[AscDFH.historyitem_Field_AddItem] = [AscDFH.historyitem_Field_AddItem, AscDFH.historyitem_Field_RemoveItem];
AscDFH.changesRelationMap[AscDFH.historyitem_Field_RemoveItem] = [AscDFH.historyitem_Field_AddItem, AscDFH.historyitem_Field_RemoveItem];
AscDFH.changesRelationMap[AscDFH.historyitem_Field_FormFieldName] = [AscDFH.historyitem_Field_FormFieldName];
//----------------------------------------------------------------------------------------------------------------------
/**
......@@ -175,3 +177,17 @@ CChangesParaFieldRemoveItem.prototype.CreateReverseChange = function()
{
return this.private_CreateReverseChange(CChangesParaFieldAddItem);
};
/**
* @constructor
* @extends {AscDFH.CChangesBaseStringProperty}
*/
function CChangesParaFieldFormFieldName(Class, Old, New)
{
CChangesParaFieldFormFieldName.superclass.constructor.call(this, Class, Old, New);
}
AscCommon.extendClass(CChangesParaFieldFormFieldName, AscDFH.CChangesBaseStringProperty);
CChangesParaFieldFormFieldName.prototype.Type = AscDFH.historyitem_Field_FormFieldName;
CChangesParaFieldFormFieldName.prototype.private_SetValue = function(Value)
{
this.Class.FormFieldName = Value;
};
\ No newline at end of file
......@@ -3714,7 +3714,7 @@ Paragraph.prototype =
}
// Если курсор находится в начале или конце гиперссылки, тогда выводим его из гиперссылки
while ( CurPos > 0 && para_Run !== this.Content[CurPos].Type && para_Math !== this.Content[CurPos].Type && true === this.Content[CurPos].Cursor_Is_Start() )
while ( CurPos > 0 && para_Run !== this.Content[CurPos].Type && para_Math !== this.Content[CurPos].Type && para_Field !== this.Content[CurPos].Type && true === this.Content[CurPos].Cursor_Is_Start() )
{
if ( false === this.Content[CurPos - 1].Is_CursorPlaceable() )
break;
......@@ -3723,7 +3723,7 @@ Paragraph.prototype =
this.Content[CurPos].Cursor_MoveToEndPos();
}
while ( CurPos < Count && para_Run !== this.Content[CurPos].Type && para_Math !== this.Content[CurPos].Type && true === this.Content[CurPos].Cursor_Is_End() )
while ( CurPos < Count && para_Run !== this.Content[CurPos].Type && para_Math !== this.Content[CurPos].Type && para_Field !== this.Content[CurPos].Type && true === this.Content[CurPos].Cursor_Is_End() )
{
if ( false === this.Content[CurPos + 1].Is_CursorPlaceable() )
break;
......@@ -4406,7 +4406,7 @@ Paragraph.prototype =
CurPos--;
if (CurPos >= 0 && para_Math === this.Content[CurPos + 1].Type)
if (CurPos >= 0 && (para_Math === this.Content[CurPos + 1].Type || para_Field === this.Content[CurPos + 1].Type))
{
// При выходе из формулы встаем в конец рана
this.Content[CurPos].Get_EndPos(false, SearchPos.Pos, Depth + 1);
......@@ -4443,7 +4443,7 @@ Paragraph.prototype =
CurPos++;
var Count = this.Content.length;
if (CurPos < Count && para_Math === this.Content[CurPos - 1].Type)
if (CurPos < Count && (para_Math === this.Content[CurPos - 1].Type || para_Field === this.Content[CurPos - 1].Type))
{
// При выходе из формулы встаем в конец рана
this.Content[CurPos].Get_StartPos(SearchPos.Pos, Depth + 1);
......
......@@ -6880,6 +6880,28 @@ background-repeat: no-repeat;\
this.WordControl.m_oLogicDocument.Create_NewHistoryPoint(AscDFH.historydescription_Document_AddSectionBreak);
return true;
};
//----------------------------------------------------------------------------------------------------------------------
// Работаем с полями
//----------------------------------------------------------------------------------------------------------------------
asc_docs_api.prototype.asc_GetAllFormTextFieldsContent = function()
{
var oLogicDocument = this.WordControl.m_oLogicDocument;
if (!oLogicDocument)
return [];
var arrFields = oLogicDocument.GetAllFormTextFields();
var arrResult = [];
for (var nIndex = 0, nCount = arrFields.length; nIndex < nCount; ++nIndex)
{
var oField = arrFields[nIndex];
var sName = oField.GetFormFieldName();
var sText = oField.GetValue();
arrResult.push({Name : sName, Text : sText});
}
return arrResult;
};
// input
asc_docs_api.prototype.Begin_CompositeInput = function()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment