forked from ONLYOFFICE/sdkjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathField.js
821 lines (727 loc) · 24.7 KB
/
Field.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
/*
* (c) Copyright Ascensio System SIA 2010-2024
*
* 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-6 Ernesta Birznieka-Upish
* 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";
// Import
var History = AscCommon.History;
/**
*
* @param FieldType
* @param Arguments
* @param Switches
* @constructor
* @extends {CParagraphContentWithParagraphLikeContent}
*/
function ParaField(FieldType, Arguments, Switches)
{
CParagraphContentWithParagraphLikeContent.call(this);
this.Id = AscCommon.g_oIdCounter.Get_NewId();
this.Type = para_Field;
this.Istruction = null;
this.FieldType = (undefined === FieldType ? AscWord.fieldtype_UNKNOWN : FieldType);
this.Arguments = (undefined === Arguments ? [] : Arguments);
this.Switches = (undefined === Switches ? [] : Switches);
this.TemplateContent = this.Content;
this.Bounds = {};
this.FormFieldName = "";
this.FormFieldDefaultText = "";
// Добавляем данный класс в таблицу Id (обязательно в конце конструктора)
AscCommon.g_oTableId.Add( this, this.Id );
}
ParaField.prototype = Object.create(CParagraphContentWithParagraphLikeContent.prototype);
ParaField.prototype.constructor = ParaField;
ParaField.prototype.Get_Id = function()
{
return this.Id;
};
ParaField.prototype.Copy = function(Selected, oPr)
{
let newField = CParagraphContentWithParagraphLikeContent.prototype.Copy.apply(this, arguments);
if (oPr && oPr.SkipFldSimple)
{
let newItems = this.Content.slice();
this.RemoveAll();
return newItems;
}
else
{
// TODO: Сделать функциями с иторией
newField.FieldType = this.FieldType;
newField.Arguments = this.Arguments;
newField.Switches = this.Switches;
if (editor)
editor.WordControl.m_oLogicDocument.Register_Field(newField);
return newField;
}
};
ParaField.prototype.GetSelectedElementsInfo = function(Info, ContentPos, Depth)
{
Info.SetField(this);
CParagraphContentWithParagraphLikeContent.prototype.GetSelectedElementsInfo.apply(this, arguments);
};
ParaField.prototype.Get_Bounds = function()
{
var oParagraph = this.GetParagraph();
if (!oParagraph)
return [];
var arrBounds = [];
for (var Place in this.Bounds)
{
this.Bounds[Place].PageIndex = oParagraph.GetAbsolutePage(this.Bounds[Place].PageInternal);
arrBounds.push(this.Bounds[Place]);
}
return arrBounds;
};
ParaField.prototype.Add_ToContent = function(Pos, Item, UpdatePosition)
{
History.Add(new CChangesParaFieldAddItem(this, Pos, [Item]));
CParagraphContentWithParagraphLikeContent.prototype.Add_ToContent.apply(this, arguments);
};
ParaField.prototype.Remove_FromContent = function(Pos, Count, UpdatePosition)
{
if (Count <= 0)
return;
// Получим массив удаляемых элементов
var DeletedItems = this.Content.slice(Pos, Pos + Count);
History.Add(new CChangesParaFieldRemoveItem(this, Pos, DeletedItems));
CParagraphContentWithParagraphLikeContent.prototype.Remove_FromContent.apply(this, arguments);
};
ParaField.prototype.Add = function(Item)
{
if (para_Field === Item.Type)
{
// Вместо добавления самого элемента добавляем его содержимое
var Count = Item.Content.length;
if (Count > 0)
{
var CurPos = this.State.ContentPos;
var CurItem = this.Content[CurPos];
var CurContentPos = new AscWord.CParagraphContentPos();
CurItem.Get_ParaContentPos(false, false, CurContentPos);
var NewItem = CurItem.Split(CurContentPos, 0);
for (var Index = 0; Index < Count; Index++)
{
this.Add_ToContent(CurPos + Index + 1, Item.Content[Index], false);
}
this.Add_ToContent(CurPos + Count + 1, NewItem, false);
this.State.ContentPos = CurPos + Count;
this.Content[this.State.ContentPos].MoveCursorToEndPos();
}
}
else
{
CParagraphContentWithParagraphLikeContent.prototype.Add.apply(this, arguments);
}
};
ParaField.prototype.Split = function (ContentPos, Depth)
{
// Не даем разделять поле
return null;
};
ParaField.prototype.CanSplit = function()
{
return false;
};
ParaField.prototype.Recalculate_Range_Spaces = function(PRSA, _CurLine, _CurRange, _CurPage)
{
var CurLine = _CurLine - this.StartLine;
var CurRange = (0 === _CurLine ? _CurRange - this.StartRange : _CurRange);
if (0 === CurLine && 0 === CurRange && true !== PRSA.RecalcFast)
this.Bounds = {};
var X0 = PRSA.X;
var Y0 = PRSA.Y0;
var Y1 = PRSA.Y1;
CParagraphContentWithParagraphLikeContent.prototype.Recalculate_Range_Spaces.apply(this, arguments);
var X1 = PRSA.X;
this.Bounds[((CurLine << 16) & 0xFFFF0000) | (CurRange & 0x0000FFFF)] = {
X0 : X0,
X1 : X1,
Y0 : Y0,
Y1 : Y1,
PageIndex : PRSA.Paragraph.Get_AbsolutePage(_CurPage),
PageInternal : _CurPage
};
};
ParaField.prototype.Draw_HighLights = function(PDSH)
{
var X0 = PDSH.X;
var Y0 = PDSH.Y0;
var Y1 = PDSH.Y1;
CParagraphContentWithParagraphLikeContent.prototype.Draw_HighLights.apply(this, arguments);
var X1 = PDSH.X;
if (Math.abs(X0 - X1) > 0.001 && (true === PDSH.DrawMMFields || AscWord.fieldtype_FORMTEXT === this.Get_FieldType()))
{
PDSH.MMFields.Add(Y0, Y1, X0, X1, 0, 0, 0, 0 );
}
};
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;
}
CParagraphContentWithParagraphLikeContent.prototype.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;
}
CParagraphContentWithParagraphLikeContent.prototype.Get_RightPos.call(this, SearchPos, ContentPos, Depth, UseContentPos, StepEnd);
};
ParaField.prototype.Remove = function(nDirection, bOnAddText)
{
CParagraphContentWithParagraphLikeContent.prototype.Remove.call(this, nDirection, bOnAddText);
if (this.Is_Empty() && !bOnAddText && AscWord.fieldtype_FORMTEXT === this.Get_FieldType() && this.Paragraph && this.Paragraph.LogicDocument && true === this.Paragraph.LogicDocument.IsFillingFormMode())
{
var sDefaultText = this.FormFieldDefaultText == "" ? " " : this.FormFieldDefaultText;
this.SetValue(sDefaultText);
}
};
ParaField.prototype.Shift_Range = function(Dx, Dy, _CurLine, _CurRange, _CurPage)
{
CParagraphContentWithParagraphLikeContent.prototype.Shift_Range.call(this, Dx, Dy, _CurLine, _CurRange, _CurPage);
var CurLine = _CurLine - this.StartLine;
var CurRange = ( 0 === CurLine ? _CurRange - this.StartRange : _CurRange );
var oRangeBounds = this.Bounds[((CurLine << 16) & 0xFFFF0000) | (CurRange & 0x0000FFFF)];
if (oRangeBounds)
{
oRangeBounds.X0 += Dx;
oRangeBounds.X1 += Dx;
oRangeBounds.Y0 += Dy;
oRangeBounds.Y1 += Dy;
}
};
ParaField.prototype.Get_LeftPos = function(SearchPos, ContentPos, Depth, UseContentPos)
{
var bResult = CParagraphContentWithParagraphLikeContent.prototype.Get_LeftPos.call(this, SearchPos, ContentPos, Depth, UseContentPos);
if (true !== bResult && this.Paragraph && this.Paragraph.LogicDocument && true === this.Paragraph.LogicDocument.IsFillingFormMode())
{
this.Get_StartPos(SearchPos.Pos, Depth);
SearchPos.Found = true;
return true;
}
return bResult;
};
ParaField.prototype.Get_RightPos = function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd)
{
var bResult = CParagraphContentWithParagraphLikeContent.prototype.Get_RightPos.call(this, SearchPos, ContentPos, Depth, UseContentPos, StepEnd);
if (true !== bResult && this.Paragraph && this.Paragraph.LogicDocument && true === this.Paragraph.LogicDocument.IsFillingFormMode())
{
this.Get_EndPos(false, SearchPos.Pos, Depth);
SearchPos.Found = true;
return true;
}
return bResult;
};
ParaField.prototype.Get_WordStartPos = function(SearchPos, ContentPos, Depth, UseContentPos)
{
CParagraphContentWithParagraphLikeContent.prototype.Get_WordStartPos.call(this, SearchPos, ContentPos, Depth, UseContentPos);
if (true !== SearchPos.Found && this.Paragraph && this.Paragraph.LogicDocument && true === this.Paragraph.LogicDocument.IsFillingFormMode())
{
this.Get_StartPos(SearchPos.Pos, Depth);
SearchPos.UpdatePos = true;
SearchPos.Found = true;
}
};
ParaField.prototype.Get_WordEndPos = function(SearchPos, ContentPos, Depth, UseContentPos, StepEnd)
{
CParagraphContentWithParagraphLikeContent.prototype.Get_WordEndPos.call(this, SearchPos, ContentPos, Depth, UseContentPos, StepEnd);
if (true !== SearchPos.Found && this.Paragraph && this.Paragraph.LogicDocument && true === this.Paragraph.LogicDocument.IsFillingFormMode())
{
this.Get_EndPos(false, SearchPos.Pos, Depth);
SearchPos.UpdatePos = true;
SearchPos.Found = true;
}
};
ParaField.prototype.SetCurrent = function(isCurrent)
{
};
ParaField.prototype.IsCurrent = function()
{
return false;
};
ParaField.prototype.SelectField = function()
{
this.SelectThisElement();
};
ParaField.prototype.GetAllFields = function(isUseSelection, arrFields)
{
arrFields.push(this);
return CParagraphContentWithParagraphLikeContent.prototype.GetAllFields.apply(this, arguments);
};
ParaField.prototype.GetAllSeqFieldsByType = function(sType, aFields)
{
if (this.FieldType === AscWord.fieldtype_SEQ
&& this.Arguments.length
&& this.Arguments[0].toLowerCase
&& sType.toLowerCase
&& this.Arguments[0].toLowerCase() === sType.toLowerCase())
{
aFields.push(this);
}
};
//----------------------------------------------------------------------------------------------------------------------
// Работа с данными поля
//----------------------------------------------------------------------------------------------------------------------
ParaField.prototype.Get_Argument = function(Index)
{
return this.Arguments[Index];
};
ParaField.prototype.Get_FieldType = function()
{
return this.FieldType;
};
ParaField.prototype.GetFieldType = function()
{
return this.FieldType;
};
ParaField.prototype.Map_MailMerge = function(_Value)
{
// Пока у нас в Value может быть только текст, в будущем планируется, чтобы могли быть картинки.
var Value = _Value;
if (undefined === Value || null === Value)
Value = "";
History.TurnOff();
var oRun = this.private_GetMappedRun(Value);
// Подменяем содержимое поля
this.Content = [];
this.Content[0] = oRun;
this.MoveCursorToStartPos();
History.TurnOn();
};
ParaField.prototype.Restore_StandardTemplate = function()
{
// В любом случае сначала восстанавливаем исходное содержимое.
this.Restore_Template();
if (AscWord.fieldtype_MERGEFIELD === this.FieldType && true === AscCommon.CollaborativeEditing.Is_SingleUser() && 1 === this.Arguments.length)
{
var oRun = this.private_GetMappedRun("«" + this.Arguments[0] + "»");
this.Remove_FromContent(0, this.Content.length);
this.Add_ToContent(0, oRun);
this.MoveCursorToStartPos();
this.TemplateContent = this.Content;
}
};
ParaField.prototype.Restore_Template = function()
{
// Восстанавливаем содержимое поля.
this.Content = this.TemplateContent;
this.MoveCursorToStartPos();
};
ParaField.prototype.Is_NeedRestoreTemplate = function()
{
if (1 !== this.TemplateContent.length)
return true;
var oRun = this.TemplateContent[0];
if (AscWord.fieldtype_MERGEFIELD === this.FieldType)
{
var sStandardText = "«" + this.Arguments[0] + "»";
var oRunText = new CParagraphGetText();
oRun.Get_Text(oRunText);
if (sStandardText === oRunText.Text)
return false;
return true;
}
return false;
};
ParaField.prototype.Replace_MailMerge = function(_Value)
{
// Пока у нас в Value может быть только текст, в будущем планируется, чтобы могли быть картинки.
var Value = _Value;
if (undefined === Value || null === Value)
Value = "";
var Paragraph = this.Paragraph;
if (!Paragraph)
return false;
// Получим ран, на который мы подменяем поле
var oRun = this.private_GetMappedRun(Value);
// Ищем расположение данного поля в параграфе
var ParaContentPos = Paragraph.Get_PosByElement(this);
if (null === ParaContentPos)
return false;
var Depth = ParaContentPos.GetDepth();
var FieldPos = ParaContentPos.Get(Depth);
if (Depth < 0)
return false;
ParaContentPos.DecreaseDepth(1);
var FieldContainer = Paragraph.Get_ElementByPos(ParaContentPos);
if (!FieldContainer || !FieldContainer.Content || FieldContainer.Content[FieldPos] !== this)
return false;
FieldContainer.Remove_FromContent(FieldPos, 1);
FieldContainer.Add_ToContent(FieldPos, oRun);
return true;
};
ParaField.prototype.private_GetMappedRun = function(sValue)
{
return this.CreateRunWithText(sValue);
};
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.SetFormFieldDefaultText = function(sText)
{
History.Add(new CChangesParaFieldFormFieldDefaultText(this, this.FormFieldDefaultText, sText));
this.FormFieldDefaultText = sText;
};
ParaField.prototype.GetValue = function()
{
var oText = new CParagraphGetText();
oText.SetBreakOnNonText(false);
this.Get_Text(oText);
return oText.Text;
};
ParaField.prototype.SetValue = function(sValue)
{
this.ReplaceAllWithText(sValue);
};
ParaField.prototype.IsFillingForm = function()
{
if (AscWord.fieldtype_FORMTEXT === this.Get_FieldType())
return true;
return false;
};
ParaField.prototype.FindNextFillingForm = function(isNext, isCurrent, isStart)
{
var oParagraph = this.GetParagraph();
if (!oParagraph)
return null;
var oLogicDocument = oParagraph.GetLogicDocument();
if (!oLogicDocument)
return null;
if (!this.IsFillingForm() || oLogicDocument.IsFillingOFormMode())
return CParagraphContentWithParagraphLikeContent.prototype.FindNextFillingForm.apply(this, arguments);
if (isCurrent && true === this.IsSelectedAll())
{
if (isNext)
return CParagraphContentWithParagraphLikeContent.prototype.FindNextFillingForm.apply(this, arguments);
return null;
}
if (!isCurrent && isNext)
return this;
var oRes = CParagraphContentWithParagraphLikeContent.prototype.FindNextFillingForm.apply(this, arguments);
if (!oRes && !isNext)
return this;
return null;
};
ParaField.prototype.Update = function(isCreateHistoryPoint, isRecalculate)
{
if (!this.Paragraph && !this.Paragraph.Parent)
return;
var sReplaceString = null;
if (this.FieldType === AscWord.fieldtype_SEQ)
{
var oInstruction = new CFieldInstructionSEQ();
oInstruction.ComplexField = this;
oInstruction.ParentContent = this.Paragraph.Parent;
oInstruction.Id = this.Arguments[0];
sReplaceString = oInstruction.GetText();
}
else if (this.FieldType === AscWord.fieldtype_STYLEREF)
{
var oInstruction = new CFieldInstructionSTYLEREF();
oInstruction.ComplexField = this;
oInstruction.ParentContent = this.Paragraph.Parent;
oInstruction.ParentParagraph = this.Paragraph;
oInstruction.StyleName = this.Arguments[0];
sReplaceString = oInstruction.GetText();
}
if (sReplaceString)
{
var oRun = this.private_GetMappedRun(sReplaceString);
this.Remove_FromContent(0, this.Content.length);
this.Add_ToContent(0, oRun);
}
};
ParaField.prototype.GetInstructionLine = function()
{
let Instr = "";
let name;
switch (this.FieldType)
{
case AscWord.fieldtype_MERGEFIELD :
{
name = "MERGEFIELD";
break;
}
case AscWord.fieldtype_PAGE :
{
name = "PAGE";
break;
}
case AscWord.fieldtype_NUMPAGES :
{
name = "NUMPAGES";
break;
}
case AscWord.fieldtype_FORMTEXT :
{
name = "FORMTEXT";
break;
}
case AscWord.fieldtype_TOC :
{
name = "TOC";
break;
}
case AscWord.fieldtype_PAGEREF :
{
name = "PAGEREF";
break;
}
case AscWord.fieldtype_ASK :
{
name = "ASK";
break;
}
case AscWord.fieldtype_REF :
{
name = "REF";
break;
}
case AscWord.fieldtype_HYPERLINK :
{
name = "HYPERLINK";
break;
}
case AscWord.fieldtype_TIME :
{
name = "TIME";
break;
}
case AscWord.fieldtype_DATE :
{
name = "DATE";
break;
}
case AscWord.fieldtype_FORMULA :
{
name = "FORMULA";
break;
}
case AscWord.fieldtype_SEQ :
{
name = "SEQ";
break;
}
case AscWord.fieldtype_STYLEREF :
{
name = "STYLEREF";
break;
}
case AscWord.fieldtype_NOTEREF :
{
name = "NOTEREF";
break;
}
}
if (name)
{
Instr += name;
for (let i = 0; i < this.Arguments.length; ++i)
{
let argument = this.Arguments[i];
argument = argument.replace(/(\\|")/g, "\\$1");
if (-1 != argument.indexOf(' '))
{
argument = "\"" + argument + "\"";
}
Instr += " " + argument;
}
Instr += this.Switches.join(" ")
}
return Instr;
};
ParaField.prototype.GetInstruction = function()
{
let instructionLine = this.GetInstructionLine();
let parser = new CFieldInstructionParser();
let instruction = parser.GetInstructionClass(instructionLine);
instruction.SetInstructionLine(instructionLine);
return instruction;
};
ParaField.prototype.ReplaceWithComplexField = function()
{
let oParent = this.GetParent();
let nPosInParent = this.GetPosInParent(oParent);
let oParagraph = this.GetParagraph();
let oLogicDocument = oParagraph ? oParagraph.GetLogicDocument() : null;
if (!oLogicDocument || !oParent || -1 === nPosInParent)
return null;
let oBeginChar = new ParaFieldChar(fldchartype_Begin, oLogicDocument);
let oSeparateChar = new ParaFieldChar(fldchartype_Separate, oLogicDocument);
let oEndChar = new ParaFieldChar(fldchartype_End, oLogicDocument);
let sInstruction = this.GetInstructionLine();
let oRun = this.CreateRunWithText("");
oRun.AddToContent(-1, oBeginChar);
oRun.AddInstrText(sInstruction);
oRun.AddToContent(-1, oSeparateChar);
oRun.AddToContent(-1, oEndChar);
oParent.RemoveFromContent(nPosInParent, 1);
oParent.AddToContent(nPosInParent, oRun);
oBeginChar.SetRun(oRun);
oSeparateChar.SetRun(oRun);
oEndChar.SetRun(oRun);
var oComplexField = oBeginChar.GetComplexField();
oComplexField.SetBeginChar(oBeginChar);
oComplexField.SetInstructionLine(sInstruction);
oComplexField.SetSeparateChar(oSeparateChar);
oComplexField.SetEndChar(oEndChar);
oComplexField.Update(false);
return oComplexField;
};
ParaField.prototype.GetRunWithPageField = function(paragraph)
{
let res = null;
if (AscWord.fieldtype_PAGENUM == this.FieldType || AscWord.fieldtype_PAGECOUNT == this.FieldType) {
res = new ParaRun(paragraph);
let run = this.GetFirstRunNonEmpty();
let rPr = run && run.Get_FirstTextPr();
if (rPr) {
res.Set_Pr(rPr);
}
if (AscWord.fieldtype_PAGENUM == this.FieldType) {
res.AddToContentToEnd(new AscWord.CRunPageNum());
} else {
var pageCount = parseInt(this.GetSelectedText(true));
res.AddToContentToEnd(new AscWord.CRunPagesCount(isNaN(pageCount) ? undefined : pageCount));
}
}
return res;
}
ParaField.prototype.IsValid = function()
{
return true;
};
ParaField.prototype.CheckType = function(type)
{
return this.FieldType === type;
};
ParaField.prototype.IsAddin = function()
{
return this.CheckType(AscWord.fieldtype_ADDIN);
};
ParaField.prototype.IsFormCheckBox = function()
{
return this.CheckType(AscWord.fieldtype_FORMCHECKBOX);
};
//----------------------------------------------------------------------------------------------------------------------
// Функции совместного редактирования
//----------------------------------------------------------------------------------------------------------------------
ParaField.prototype.Write_ToBinary2 = function(Writer)
{
Writer.WriteLong(AscDFH.historyitem_type_Field);
// String : Id
// Long : FieldType
// Long : Количество аргументов
// Array of Strings : массив аргументов
// Long : Количество переключателей
// Array of Strings : массив переключателей
// Long : Количество элементов
// Array of Strings : массив с Id элементов
Writer.WriteString2(this.Id);
Writer.WriteLong(this.FieldType);
var ArgsCount = this.Arguments.length;
Writer.WriteLong(ArgsCount);
for (var Index = 0; Index < ArgsCount; Index++)
Writer.WriteString2(this.Arguments[Index]);
var SwitchesCount = this.Switches.length;
Writer.WriteLong(SwitchesCount);
for (var Index = 0; Index < SwitchesCount; Index++)
Writer.WriteString2(this.Switches[Index]);
var Count = this.Content.length;
Writer.WriteLong(Count);
for (var Index = 0; Index < Count; Index++)
Writer.WriteString2(this.Content[Index].Get_Id());
};
ParaField.prototype.Read_FromBinary2 = function(Reader)
{
// String : Id
// Long : FieldType
// Long : Количество аргументов
// Array of Strings : массив аргументов
// Long : Количество переключателей
// Array of Strings : массив переключателей
// Long : Количество элементов
// Array of Strings : массив с Id элементов
this.Id = Reader.GetString2();
this.FieldType = Reader.GetLong();
var Count = Reader.GetLong();
this.Arguments = [];
for (var Index = 0; Index < Count; Index++)
this.Arguments.push(Reader.GetString2());
Count = Reader.GetLong();
this.Switches = [];
for (var Index = 0; Index < Count; Index++)
this.Switches.push(Reader.GetString2());
Count = Reader.GetLong();
this.Content = [];
for (var Index = 0; Index < Count; Index++)
{
var Element = AscCommon.g_oTableId.Get_ById(Reader.GetString2());
if (null !== Element)
this.Content.push(Element);
}
this.TemplateContent = this.Content;
if (editor)
editor.WordControl.m_oLogicDocument.Register_Field(this);
};
//----------------------------------------------------------------------------------------------------------------------
ParaField.prototype.IsStopCursorOnEntryExit = function()
{
return true;
};
ParaField.prototype.CheckSpelling = function(oCollector, nDepth)
{
if (oCollector.IsExceedLimit())
return;
oCollector.FlushWord();
};
//--------------------------------------------------------export----------------------------------------------------
window['AscCommonWord'] = window['AscCommonWord'] || {};
window['AscCommonWord'].ParaField = ParaField;
window['AscWord'].CSimpleField = ParaField;