2020-10-01 20:57:23 +09:00
|
|
|
/* Copyright 2020 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-03-31 00:50:35 +09:00
|
|
|
import { createActionsMap, FieldType, getFieldType } from "./common.js";
|
2020-11-16 22:27:27 +09:00
|
|
|
import { Color } from "./color.js";
|
2020-10-01 20:57:23 +09:00
|
|
|
import { PDFObject } from "./pdf_object.js";
|
|
|
|
|
|
|
|
class Field extends PDFObject {
|
|
|
|
constructor(data) {
|
|
|
|
super(data);
|
|
|
|
this.alignment = data.alignment || "left";
|
|
|
|
this.borderStyle = data.borderStyle || "";
|
|
|
|
this.buttonAlignX = data.buttonAlignX || 50;
|
|
|
|
this.buttonAlignY = data.buttonAlignY || 50;
|
|
|
|
this.buttonFitBounds = data.buttonFitBounds;
|
|
|
|
this.buttonPosition = data.buttonPosition;
|
|
|
|
this.buttonScaleHow = data.buttonScaleHow;
|
|
|
|
this.ButtonScaleWhen = data.buttonScaleWhen;
|
|
|
|
this.calcOrderIndex = data.calcOrderIndex;
|
|
|
|
this.comb = data.comb;
|
|
|
|
this.commitOnSelChange = data.commitOnSelChange;
|
|
|
|
this.currentValueIndices = data.currentValueIndices;
|
|
|
|
this.defaultStyle = data.defaultStyle;
|
|
|
|
this.defaultValue = data.defaultValue;
|
|
|
|
this.doNotScroll = data.doNotScroll;
|
|
|
|
this.doNotSpellCheck = data.doNotSpellCheck;
|
|
|
|
this.delay = data.delay;
|
|
|
|
this.display = data.display;
|
2021-01-08 03:22:37 +09:00
|
|
|
this.doc = data.doc.wrapped;
|
2020-10-01 20:57:23 +09:00
|
|
|
this.editable = data.editable;
|
|
|
|
this.exportValues = data.exportValues;
|
|
|
|
this.fileSelect = data.fileSelect;
|
|
|
|
this.hidden = data.hidden;
|
|
|
|
this.highlight = data.highlight;
|
|
|
|
this.lineWidth = data.lineWidth;
|
|
|
|
this.multiline = data.multiline;
|
2020-11-19 02:54:26 +09:00
|
|
|
this.multipleSelection = !!data.multipleSelection;
|
2020-10-01 20:57:23 +09:00
|
|
|
this.name = data.name;
|
|
|
|
this.password = data.password;
|
|
|
|
this.print = data.print;
|
|
|
|
this.radiosInUnison = data.radiosInUnison;
|
|
|
|
this.readonly = data.readonly;
|
|
|
|
this.rect = data.rect;
|
|
|
|
this.required = data.required;
|
|
|
|
this.richText = data.richText;
|
|
|
|
this.richValue = data.richValue;
|
|
|
|
this.style = data.style;
|
|
|
|
this.submitName = data.submitName;
|
|
|
|
this.textFont = data.textFont;
|
|
|
|
this.textSize = data.textSize;
|
|
|
|
this.type = data.type;
|
|
|
|
this.userName = data.userName;
|
|
|
|
|
|
|
|
// Private
|
2020-12-08 03:22:14 +09:00
|
|
|
this._actions = createActionsMap(data.actions);
|
2021-01-08 03:22:37 +09:00
|
|
|
this._browseForFileToSubmit = data.browseForFileToSubmit || null;
|
|
|
|
this._buttonCaption = null;
|
|
|
|
this._buttonIcon = null;
|
2022-08-19 02:27:53 +09:00
|
|
|
this._charLimit = data.charLimit;
|
2021-01-08 03:22:37 +09:00
|
|
|
this._children = null;
|
2021-01-26 07:40:57 +09:00
|
|
|
this._currentValueIndices = data.currentValueIndices || 0;
|
|
|
|
this._document = data.doc;
|
2021-01-08 03:22:37 +09:00
|
|
|
this._fieldPath = data.fieldPath;
|
2020-12-03 07:02:11 +09:00
|
|
|
this._fillColor = data.fillColor || ["T"];
|
2021-01-26 07:40:57 +09:00
|
|
|
this._isChoice = Array.isArray(data.items);
|
|
|
|
this._items = data.items || [];
|
2022-10-13 22:48:01 +09:00
|
|
|
this._hasValue = data.hasOwnProperty("value");
|
2021-04-30 23:43:27 +09:00
|
|
|
this._page = data.page || 0;
|
2020-12-03 07:02:11 +09:00
|
|
|
this._strokeColor = data.strokeColor || ["G", 0];
|
|
|
|
this._textColor = data.textColor || ["G", 0];
|
2022-11-28 23:53:17 +09:00
|
|
|
this._value = null;
|
2021-03-31 00:50:35 +09:00
|
|
|
this._kidIds = data.kidIds || null;
|
|
|
|
this._fieldType = getFieldType(this._actions);
|
2021-04-21 02:21:52 +09:00
|
|
|
this._siblings = data.siblings || null;
|
2022-06-19 23:39:54 +09:00
|
|
|
this._rotation = data.rotation || 0;
|
2020-12-16 22:04:22 +09:00
|
|
|
|
|
|
|
this._globalEval = data.globalEval;
|
2021-03-31 00:50:35 +09:00
|
|
|
this._appObjects = data.appObjects;
|
2022-11-28 23:53:17 +09:00
|
|
|
|
|
|
|
// The value is set depending on the field type.
|
|
|
|
this.value = data.value || "";
|
2020-11-16 22:27:27 +09:00
|
|
|
}
|
|
|
|
|
2021-01-26 07:40:57 +09:00
|
|
|
get currentValueIndices() {
|
|
|
|
if (!this._isChoice) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return this._currentValueIndices;
|
|
|
|
}
|
|
|
|
|
|
|
|
set currentValueIndices(indices) {
|
|
|
|
if (!this._isChoice) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!Array.isArray(indices)) {
|
|
|
|
indices = [indices];
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
!indices.every(
|
|
|
|
i =>
|
|
|
|
typeof i === "number" &&
|
|
|
|
Number.isInteger(i) &&
|
|
|
|
i >= 0 &&
|
|
|
|
i < this.numItems
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
indices.sort();
|
|
|
|
|
|
|
|
if (this.multipleSelection) {
|
|
|
|
this._currentValueIndices = indices;
|
|
|
|
this._value = [];
|
|
|
|
indices.forEach(i => {
|
|
|
|
this._value.push(this._items[i].displayValue);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (indices.length > 0) {
|
|
|
|
indices = indices.splice(1, indices.length - 1);
|
|
|
|
this._currentValueIndices = indices[0];
|
|
|
|
this._value = this._items[this._currentValueIndices];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._send({ id: this._id, indices });
|
|
|
|
}
|
|
|
|
|
2020-11-16 22:27:27 +09:00
|
|
|
get fillColor() {
|
|
|
|
return this._fillColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
set fillColor(color) {
|
|
|
|
if (Color._isValidColor(color)) {
|
|
|
|
this._fillColor = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-20 23:23:54 +09:00
|
|
|
get bgColor() {
|
|
|
|
return this.fillColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
set bgColor(color) {
|
|
|
|
this.fillColor = color;
|
|
|
|
}
|
|
|
|
|
2022-08-19 02:27:53 +09:00
|
|
|
get charLimit() {
|
|
|
|
return this._charLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
set charLimit(limit) {
|
|
|
|
if (typeof limit !== "number") {
|
|
|
|
throw new Error("Invalid argument value");
|
|
|
|
}
|
|
|
|
this._charLimit = Math.max(0, Math.floor(limit));
|
|
|
|
}
|
|
|
|
|
2021-01-26 07:40:57 +09:00
|
|
|
get numItems() {
|
|
|
|
if (!this._isChoice) {
|
|
|
|
throw new Error("Not a choice widget");
|
|
|
|
}
|
|
|
|
return this._items.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
set numItems(_) {
|
|
|
|
throw new Error("field.numItems is read-only");
|
|
|
|
}
|
|
|
|
|
2020-11-16 22:27:27 +09:00
|
|
|
get strokeColor() {
|
|
|
|
return this._strokeColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
set strokeColor(color) {
|
|
|
|
if (Color._isValidColor(color)) {
|
|
|
|
this._strokeColor = color;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-20 23:23:54 +09:00
|
|
|
get borderColor() {
|
|
|
|
return this.strokeColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
set borderColor(color) {
|
|
|
|
this.strokeColor = color;
|
|
|
|
}
|
|
|
|
|
2021-04-30 23:43:27 +09:00
|
|
|
get page() {
|
|
|
|
return this._page;
|
|
|
|
}
|
|
|
|
|
|
|
|
set page(_) {
|
|
|
|
throw new Error("field.page is read-only");
|
|
|
|
}
|
|
|
|
|
2022-06-19 23:39:54 +09:00
|
|
|
get rotation() {
|
|
|
|
return this._rotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
set rotation(angle) {
|
|
|
|
angle = Math.floor(angle);
|
|
|
|
if (angle % 90 !== 0) {
|
|
|
|
throw new Error("Invalid rotation: must be a multiple of 90");
|
|
|
|
}
|
|
|
|
angle %= 360;
|
|
|
|
if (angle < 0) {
|
|
|
|
angle += 360;
|
|
|
|
}
|
|
|
|
this._rotation = angle;
|
|
|
|
}
|
|
|
|
|
2020-11-16 22:27:27 +09:00
|
|
|
get textColor() {
|
|
|
|
return this._textColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
set textColor(color) {
|
|
|
|
if (Color._isValidColor(color)) {
|
|
|
|
this._textColor = color;
|
|
|
|
}
|
2020-10-01 20:57:23 +09:00
|
|
|
}
|
|
|
|
|
2021-02-20 23:23:54 +09:00
|
|
|
get fgColor() {
|
|
|
|
return this.textColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
set fgColor(color) {
|
|
|
|
this.textColor = color;
|
|
|
|
}
|
|
|
|
|
2020-11-19 02:54:26 +09:00
|
|
|
get value() {
|
|
|
|
return this._value;
|
|
|
|
}
|
|
|
|
|
|
|
|
set value(value) {
|
2022-12-13 08:07:45 +09:00
|
|
|
if (this._isChoice) {
|
|
|
|
this._setChoiceValue(value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-31 00:50:35 +09:00
|
|
|
if (value === "") {
|
|
|
|
this._value = "";
|
|
|
|
} else if (typeof value === "string") {
|
|
|
|
switch (this._fieldType) {
|
2022-11-28 23:53:17 +09:00
|
|
|
case FieldType.none:
|
|
|
|
this._value = !isNaN(value) ? parseFloat(value) : value;
|
|
|
|
break;
|
2021-03-31 00:50:35 +09:00
|
|
|
case FieldType.number:
|
|
|
|
case FieldType.percent:
|
2022-11-28 23:53:17 +09:00
|
|
|
const number = parseFloat(value);
|
|
|
|
this._value = !isNaN(number) ? number : 0;
|
2021-03-31 00:50:35 +09:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
this._value = value;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this._value = value;
|
|
|
|
}
|
2022-12-13 08:07:45 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
_setChoiceValue(value) {
|
|
|
|
if (this.multipleSelection) {
|
|
|
|
if (!Array.isArray(value)) {
|
|
|
|
value = [value];
|
|
|
|
}
|
|
|
|
const values = new Set(value);
|
|
|
|
if (Array.isArray(this._currentValueIndices)) {
|
|
|
|
this._currentValueIndices.length = 0;
|
|
|
|
this._value.length = 0;
|
2021-01-26 07:40:57 +09:00
|
|
|
} else {
|
2022-12-13 08:07:45 +09:00
|
|
|
this._currentValueIndices = [];
|
|
|
|
this._value = [];
|
|
|
|
}
|
|
|
|
this._items.forEach((item, i) => {
|
|
|
|
if (values.has(item.exportValue)) {
|
|
|
|
this._currentValueIndices.push(i);
|
|
|
|
this._value.push(item.exportValue);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
value = value[0];
|
|
|
|
}
|
|
|
|
const index = this._items.findIndex(
|
|
|
|
({ exportValue }) => value === exportValue
|
|
|
|
);
|
|
|
|
if (index !== -1) {
|
|
|
|
this._currentValueIndices = index;
|
|
|
|
this._value = this._items[index].exportValue;
|
2021-01-26 07:40:57 +09:00
|
|
|
}
|
2020-11-19 02:54:26 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-18 22:59:57 +09:00
|
|
|
get valueAsString() {
|
2022-05-03 02:28:00 +09:00
|
|
|
return (this._value ?? "").toString();
|
2020-11-18 22:59:57 +09:00
|
|
|
}
|
|
|
|
|
2022-05-03 02:28:00 +09:00
|
|
|
set valueAsString(_) {
|
|
|
|
// Do nothing.
|
2020-11-18 22:59:57 +09:00
|
|
|
}
|
|
|
|
|
2021-01-08 03:22:37 +09:00
|
|
|
browseForFileToSubmit() {
|
|
|
|
if (this._browseForFileToSubmit) {
|
|
|
|
// TODO: implement this function on Firefox side
|
|
|
|
// we can use nsIFilePicker but open method is async.
|
|
|
|
// Maybe it's possible to use a html input (type=file) too.
|
|
|
|
this._browseForFileToSubmit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buttonGetCaption(nFace = 0) {
|
|
|
|
if (this._buttonCaption) {
|
|
|
|
return this._buttonCaption[nFace];
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
buttonGetIcon(nFace = 0) {
|
|
|
|
if (this._buttonIcon) {
|
|
|
|
return this._buttonIcon[nFace];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
buttonImportIcon(cPath = null, nPave = 0) {
|
|
|
|
/* Not implemented */
|
|
|
|
}
|
|
|
|
|
|
|
|
buttonSetCaption(cCaption, nFace = 0) {
|
|
|
|
if (!this._buttonCaption) {
|
|
|
|
this._buttonCaption = ["", "", ""];
|
|
|
|
}
|
|
|
|
this._buttonCaption[nFace] = cCaption;
|
|
|
|
// TODO: send to the annotation layer
|
2021-04-21 02:21:52 +09:00
|
|
|
// Right now the button is drawn on the canvas using its appearance so
|
|
|
|
// update the caption means redraw...
|
|
|
|
// We should probably have an html button for this annotation.
|
2021-01-08 03:22:37 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
buttonSetIcon(oIcon, nFace = 0) {
|
|
|
|
if (!this._buttonIcon) {
|
|
|
|
this._buttonIcon = [null, null, null];
|
|
|
|
}
|
|
|
|
this._buttonIcon[nFace] = oIcon;
|
|
|
|
}
|
|
|
|
|
2020-11-19 02:54:26 +09:00
|
|
|
checkThisBox(nWidget, bCheckIt = true) {}
|
|
|
|
|
2021-01-26 07:40:57 +09:00
|
|
|
clearItems() {
|
|
|
|
if (!this._isChoice) {
|
|
|
|
throw new Error("Not a choice widget");
|
|
|
|
}
|
|
|
|
this._items = [];
|
|
|
|
this._send({ id: this._id, clear: null });
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteItemAt(nIdx = null) {
|
|
|
|
if (!this._isChoice) {
|
|
|
|
throw new Error("Not a choice widget");
|
|
|
|
}
|
|
|
|
if (!this.numItems) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nIdx === null) {
|
|
|
|
// Current selected item.
|
|
|
|
nIdx = Array.isArray(this._currentValueIndices)
|
|
|
|
? this._currentValueIndices[0]
|
|
|
|
: this._currentValueIndices;
|
|
|
|
nIdx = nIdx || 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nIdx < 0 || nIdx >= this.numItems) {
|
|
|
|
nIdx = this.numItems - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._items.splice(nIdx, 1);
|
|
|
|
if (Array.isArray(this._currentValueIndices)) {
|
|
|
|
let index = this._currentValueIndices.findIndex(i => i >= nIdx);
|
|
|
|
if (index !== -1) {
|
|
|
|
if (this._currentValueIndices[index] === nIdx) {
|
|
|
|
this._currentValueIndices.splice(index, 1);
|
|
|
|
}
|
|
|
|
for (const ii = this._currentValueIndices.length; index < ii; index++) {
|
|
|
|
--this._currentValueIndices[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (this._currentValueIndices === nIdx) {
|
|
|
|
this._currentValueIndices = this.numItems > 0 ? 0 : -1;
|
|
|
|
} else if (this._currentValueIndices > nIdx) {
|
|
|
|
--this._currentValueIndices;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this._send({ id: this._id, remove: nIdx });
|
|
|
|
}
|
|
|
|
|
|
|
|
getItemAt(nIdx = -1, bExportValue = false) {
|
|
|
|
if (!this._isChoice) {
|
|
|
|
throw new Error("Not a choice widget");
|
|
|
|
}
|
|
|
|
if (nIdx < 0 || nIdx >= this.numItems) {
|
|
|
|
nIdx = this.numItems - 1;
|
|
|
|
}
|
|
|
|
const item = this._items[nIdx];
|
|
|
|
return bExportValue ? item.exportValue : item.displayValue;
|
|
|
|
}
|
|
|
|
|
2021-01-08 03:22:37 +09:00
|
|
|
getArray() {
|
2022-10-13 22:48:01 +09:00
|
|
|
// Gets the array of terminal child fields (that is, fields that can have
|
|
|
|
// a value for this Field object, the parent field).
|
2021-03-31 00:50:35 +09:00
|
|
|
if (this._kidIds) {
|
2022-10-13 22:48:01 +09:00
|
|
|
const array = [];
|
|
|
|
const fillArrayWithKids = kidIds => {
|
|
|
|
for (const id of kidIds) {
|
|
|
|
const obj = this._appObjects[id];
|
|
|
|
if (!obj) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (obj.obj._hasValue) {
|
|
|
|
array.push(obj.wrapped);
|
|
|
|
}
|
|
|
|
if (obj.obj._kidIds) {
|
|
|
|
fillArrayWithKids(obj.obj._kidIds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
fillArrayWithKids(this._kidIds);
|
|
|
|
return array;
|
2021-03-31 00:50:35 +09:00
|
|
|
}
|
|
|
|
|
2021-01-08 03:22:37 +09:00
|
|
|
if (this._children === null) {
|
2022-10-13 22:48:01 +09:00
|
|
|
this._children = this._document.obj._getTerminalChildren(this._fieldPath);
|
2021-01-08 03:22:37 +09:00
|
|
|
}
|
2022-10-13 22:48:01 +09:00
|
|
|
|
2021-01-08 03:22:37 +09:00
|
|
|
return this._children;
|
|
|
|
}
|
|
|
|
|
|
|
|
getLock() {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2020-11-19 02:54:26 +09:00
|
|
|
isBoxChecked(nWidget) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
isDefaultChecked(nWidget) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-26 07:40:57 +09:00
|
|
|
insertItemAt(cName, cExport = undefined, nIdx = 0) {
|
|
|
|
if (!this._isChoice) {
|
|
|
|
throw new Error("Not a choice widget");
|
|
|
|
}
|
|
|
|
if (!cName) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nIdx < 0 || nIdx > this.numItems) {
|
|
|
|
nIdx = this.numItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._items.some(({ displayValue }) => displayValue === cName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cExport === undefined) {
|
|
|
|
cExport = cName;
|
|
|
|
}
|
|
|
|
const data = { displayValue: cName, exportValue: cExport };
|
|
|
|
this._items.splice(nIdx, 0, data);
|
|
|
|
if (Array.isArray(this._currentValueIndices)) {
|
|
|
|
let index = this._currentValueIndices.findIndex(i => i >= nIdx);
|
|
|
|
if (index !== -1) {
|
|
|
|
for (const ii = this._currentValueIndices.length; index < ii; index++) {
|
|
|
|
++this._currentValueIndices[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (this._currentValueIndices >= nIdx) {
|
|
|
|
++this._currentValueIndices;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._send({ id: this._id, insert: { index: nIdx, ...data } });
|
|
|
|
}
|
|
|
|
|
2020-10-01 20:57:23 +09:00
|
|
|
setAction(cTrigger, cScript) {
|
|
|
|
if (typeof cTrigger !== "string" || typeof cScript !== "string") {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(cTrigger in this._actions)) {
|
|
|
|
this._actions[cTrigger] = [];
|
|
|
|
}
|
2020-12-16 22:04:22 +09:00
|
|
|
this._actions[cTrigger].push(cScript);
|
2020-10-01 20:57:23 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
setFocus() {
|
|
|
|
this._send({ id: this._id, focus: true });
|
|
|
|
}
|
|
|
|
|
2021-01-26 07:40:57 +09:00
|
|
|
setItems(oArray) {
|
|
|
|
if (!this._isChoice) {
|
|
|
|
throw new Error("Not a choice widget");
|
|
|
|
}
|
|
|
|
this._items.length = 0;
|
|
|
|
for (const element of oArray) {
|
|
|
|
let displayValue, exportValue;
|
|
|
|
if (Array.isArray(element)) {
|
|
|
|
displayValue = element[0]?.toString() || "";
|
|
|
|
exportValue = element[1]?.toString() || "";
|
|
|
|
} else {
|
|
|
|
displayValue = exportValue = element?.toString() || "";
|
|
|
|
}
|
|
|
|
this._items.push({ displayValue, exportValue });
|
|
|
|
}
|
|
|
|
this._currentValueIndices = 0;
|
|
|
|
|
|
|
|
this._send({ id: this._id, items: this._items });
|
|
|
|
}
|
|
|
|
|
2021-01-08 03:22:37 +09:00
|
|
|
setLock() {}
|
|
|
|
|
|
|
|
signatureGetModifications() {}
|
|
|
|
|
|
|
|
signatureGetSeedValue() {}
|
|
|
|
|
|
|
|
signatureInfo() {}
|
|
|
|
|
|
|
|
signatureSetSeedValue() {}
|
|
|
|
|
|
|
|
signatureSign() {}
|
|
|
|
|
|
|
|
signatureValidate() {}
|
|
|
|
|
2020-11-04 03:24:07 +09:00
|
|
|
_isButton() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-27 04:04:11 +09:00
|
|
|
_reset() {
|
2022-05-03 02:28:00 +09:00
|
|
|
this.value = this.defaultValue;
|
2021-09-27 04:04:11 +09:00
|
|
|
}
|
|
|
|
|
2020-10-01 20:57:23 +09:00
|
|
|
_runActions(event) {
|
|
|
|
const eventName = event.name;
|
2020-11-04 03:24:07 +09:00
|
|
|
if (!this._actions.has(eventName)) {
|
2020-10-01 20:57:23 +09:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-04 03:24:07 +09:00
|
|
|
const actions = this._actions.get(eventName);
|
2020-10-01 20:57:23 +09:00
|
|
|
try {
|
|
|
|
for (const action of actions) {
|
2020-12-16 22:04:22 +09:00
|
|
|
// Action evaluation must happen in the global scope
|
|
|
|
this._globalEval(action);
|
2020-10-01 20:57:23 +09:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
event.rc = false;
|
2020-12-04 08:39:50 +09:00
|
|
|
throw error;
|
2020-10-01 20:57:23 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-19 02:54:26 +09:00
|
|
|
class RadioButtonField extends Field {
|
|
|
|
constructor(otherButtons, data) {
|
|
|
|
super(data);
|
|
|
|
|
|
|
|
this.exportValues = [this.exportValues];
|
|
|
|
this._radioIds = [this._id];
|
|
|
|
this._radioActions = [this._actions];
|
|
|
|
|
|
|
|
for (const radioData of otherButtons) {
|
|
|
|
this.exportValues.push(radioData.exportValues);
|
|
|
|
this._radioIds.push(radioData.id);
|
|
|
|
this._radioActions.push(createActionsMap(radioData.actions));
|
|
|
|
if (this._value === radioData.exportValues) {
|
|
|
|
this._id = radioData.id;
|
|
|
|
}
|
|
|
|
}
|
2022-11-28 23:53:17 +09:00
|
|
|
|
|
|
|
this._hasBeenInitialized = true;
|
|
|
|
this._value = data.value || "";
|
2020-11-19 02:54:26 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
get value() {
|
|
|
|
return this._value;
|
|
|
|
}
|
|
|
|
|
|
|
|
set value(value) {
|
2022-11-28 23:53:17 +09:00
|
|
|
if (!this._hasBeenInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-21 02:21:52 +09:00
|
|
|
if (value === null || value === undefined) {
|
2021-03-07 01:19:57 +09:00
|
|
|
this._value = "";
|
|
|
|
}
|
2020-11-19 02:54:26 +09:00
|
|
|
const i = this.exportValues.indexOf(value);
|
|
|
|
if (0 <= i && i < this._radioIds.length) {
|
|
|
|
this._id = this._radioIds[i];
|
|
|
|
this._value = value;
|
|
|
|
} else if (value === "Off" && this._radioIds.length === 2) {
|
|
|
|
const nextI = (1 + this._radioIds.indexOf(this._id)) % 2;
|
|
|
|
this._id = this._radioIds[nextI];
|
|
|
|
this._value = this.exportValues[nextI];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
checkThisBox(nWidget, bCheckIt = true) {
|
|
|
|
if (nWidget < 0 || nWidget >= this._radioIds.length || !bCheckIt) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._id = this._radioIds[nWidget];
|
|
|
|
this._value = this.exportValues[nWidget];
|
|
|
|
this._send({ id: this._id, value: this._value });
|
|
|
|
}
|
|
|
|
|
|
|
|
isBoxChecked(nWidget) {
|
|
|
|
return (
|
|
|
|
nWidget >= 0 &&
|
|
|
|
nWidget < this._radioIds.length &&
|
|
|
|
this._id === this._radioIds[nWidget]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
isDefaultChecked(nWidget) {
|
|
|
|
return (
|
|
|
|
nWidget >= 0 &&
|
|
|
|
nWidget < this.exportValues.length &&
|
|
|
|
this.defaultValue === this.exportValues[nWidget]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_getExportValue(state) {
|
|
|
|
const i = this._radioIds.indexOf(this._id);
|
|
|
|
return this.exportValues[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
_runActions(event) {
|
|
|
|
const i = this._radioIds.indexOf(this._id);
|
|
|
|
this._actions = this._radioActions[i];
|
|
|
|
return super._runActions(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
_isButton() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CheckboxField extends RadioButtonField {
|
|
|
|
get value() {
|
|
|
|
return this._value;
|
|
|
|
}
|
|
|
|
|
|
|
|
set value(value) {
|
2021-04-21 02:21:52 +09:00
|
|
|
if (!value || value === "Off") {
|
2020-11-19 02:54:26 +09:00
|
|
|
this._value = "Off";
|
|
|
|
} else {
|
|
|
|
super.value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_getExportValue(state) {
|
|
|
|
return state ? super._getExportValue(state) : "Off";
|
|
|
|
}
|
|
|
|
|
|
|
|
isBoxChecked(nWidget) {
|
|
|
|
if (this._value === "Off") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return super.isBoxChecked(nWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
isDefaultChecked(nWidget) {
|
|
|
|
if (this.defaultValue === "Off") {
|
|
|
|
return this._value === "Off";
|
|
|
|
}
|
|
|
|
return super.isDefaultChecked(nWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
checkThisBox(nWidget, bCheckIt = true) {
|
|
|
|
if (nWidget < 0 || nWidget >= this._radioIds.length) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._id = this._radioIds[nWidget];
|
|
|
|
this._value = bCheckIt ? this.exportValues[nWidget] : "Off";
|
|
|
|
this._send({ id: this._id, value: this._value });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export { CheckboxField, Field, RadioButtonField };
|