mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02:00
JS -- Add few missing constants in global scope
- these constants are available in pdfium implementation too - fix error code in aform.js
This commit is contained in:
parent
631bada0df
commit
8e6bec6e2e
4 changed files with 138 additions and 20 deletions
|
@ -13,13 +13,14 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* global color */
|
||||
import { GlobalConstants } from "./constants.js";
|
||||
|
||||
class AForm {
|
||||
constructor(document, app, util) {
|
||||
constructor(document, app, util, color) {
|
||||
this._document = document;
|
||||
this._app = app;
|
||||
this._util = util;
|
||||
this._color = color;
|
||||
this._dateFormats = [
|
||||
"m/d",
|
||||
"m/d/yy",
|
||||
|
@ -47,6 +48,10 @@ class AForm {
|
|||
);
|
||||
}
|
||||
|
||||
_mkTargetName(event) {
|
||||
return event.target ? `[ ${event.target.name} ]` : "";
|
||||
}
|
||||
|
||||
_parseDate(cFormat, cDate) {
|
||||
const ddate = Date.parse(cDate);
|
||||
if (isNaN(ddate)) {
|
||||
|
@ -171,7 +176,7 @@ class AForm {
|
|||
}
|
||||
|
||||
if (negStyle === 1 || negStyle === 3) {
|
||||
event.target.textColor = sign === 1 ? color.black : color.red;
|
||||
event.target.textColor = sign === 1 ? this._color.black : this._color.red;
|
||||
}
|
||||
|
||||
if ((negStyle !== 0 || bCurrencyPrepend) && sign === -1) {
|
||||
|
@ -212,14 +217,17 @@ class AForm {
|
|||
|
||||
if (!pattern.test(value)) {
|
||||
if (event.willCommit) {
|
||||
if (event.target) {
|
||||
this._app.alert(`Invalid number in [ ${event.target.name} ]`);
|
||||
} else {
|
||||
this._app.alert(`Invalid number`);
|
||||
}
|
||||
const err = `${GlobalConstants.IDS_INVALID_VALUE} ${this._mkTargetName(
|
||||
event
|
||||
)}`;
|
||||
this._app.alert(err);
|
||||
}
|
||||
event.rc = false;
|
||||
}
|
||||
|
||||
if (event.willCommit && sepStyle > 1) {
|
||||
event.value = parseFloat(value.replace(",", "."));
|
||||
}
|
||||
}
|
||||
|
||||
AFPercent_Format(nDec, sepStyle, percentPrepend = false) {
|
||||
|
@ -289,13 +297,18 @@ class AForm {
|
|||
return;
|
||||
}
|
||||
|
||||
const value = event.value;
|
||||
const value = this.AFMergeChange(event);
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._parseDate(cFormat, value) === null) {
|
||||
this._app.alert("Invalid date");
|
||||
const invalid = GlobalConstants.IDS_INVALID_DATE;
|
||||
const invalid2 = GlobalConstants.IDS_INVALID_DATE2;
|
||||
const err = `${invalid} ${this._mkTargetName(
|
||||
event
|
||||
)}${invalid2}${cFormat}`;
|
||||
this._app.alert(err);
|
||||
event.rc = false;
|
||||
}
|
||||
}
|
||||
|
@ -337,14 +350,18 @@ class AForm {
|
|||
let err = "";
|
||||
if (bGreaterThan && bLessThan) {
|
||||
if (value < nGreaterThan || value > nLessThan) {
|
||||
err = `${event.value} is not between ${nGreaterThan} and ${nLessThan}`;
|
||||
err = this._util.printf(
|
||||
GlobalConstants.IDS_GT_AND_LT,
|
||||
nGreaterThan,
|
||||
nLessThan
|
||||
);
|
||||
}
|
||||
} else if (bGreaterThan) {
|
||||
if (value < nGreaterThan) {
|
||||
err = `${event.value} is not greater or equal than ${nGreaterThan}`;
|
||||
err = this._util.printf(GlobalConstants.IDS_GREATER_THAN, nGreaterThan);
|
||||
}
|
||||
} else if (value > nLessThan) {
|
||||
err = `${event.value} is not less or equal than ${nLessThan}`;
|
||||
err = this._util.printf(GlobalConstants.IDS_LESS_THAN, nLessThan);
|
||||
}
|
||||
if (err) {
|
||||
this._app.alert(err);
|
||||
|
@ -492,24 +509,27 @@ class AForm {
|
|||
return;
|
||||
}
|
||||
|
||||
const err = `${GlobalConstants.IDS_INVALID_VALUE} = "${cMask}"`;
|
||||
|
||||
if (value.length > cMask.length) {
|
||||
this._app.alert("Value is too long");
|
||||
this._app.alert(err);
|
||||
event.rc = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.willCommit) {
|
||||
if (value.length < cMask.length) {
|
||||
this._app.alert("Value is too short");
|
||||
this._app.alert(err);
|
||||
event.rc = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_checkValidity(value, cMask)) {
|
||||
this._app.alert("Value doesn't fit the specified format");
|
||||
this._app.alert(err);
|
||||
event.rc = false;
|
||||
return;
|
||||
}
|
||||
event.value += cMask.subString(value.length);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -518,6 +538,7 @@ class AForm {
|
|||
}
|
||||
|
||||
if (!_checkValidity(value, cMask)) {
|
||||
this._app.alert(err);
|
||||
event.rc = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue