Javascript 动态 PDF 图章对话框不起作用
Javascript for a dynamic PDF stamp dialog box not working
我一直在尝试创建一个动态 PDF-XChange 图章,图章上有 4 个动态文本字段(Text1、Text2、Text3 和 Text4),用户可以在放置图章之前在对话框中进行编辑。我想要的是让用户 select 图章和对话框弹出窗口打开 4 个用户输入字段:
- RMA 状态 - 用户添加状态(命名为 RMAS)
- 供用户输入任何内容的自由文本字段(名为 FREE)
- 从用户的身份信息中提取的用户名和业务团队(名为 TEAM)
- 今天的日期,可编辑以防他们在事后标记某些东西(命名为 DATE)
我让它工作时弹出一个对话框 4 次连续询问用户每个问题,但要求的是一个带有 4 个文本字段的对话框。我似乎无法弄清楚我的下面的代码需要如何更改才能工作,但我对此很陌生。
目前它只打开最后一个问题(日期),在对话框激活之前没有被我的 JavaScript 日期代码填充,none 其他问题。如果我删除日期元素,它会询问它之前的问题(名称和业务单位),但它不会显示一个对话框,其中使用代码末尾处理的数据预先填充了所有 4 个问题,该代码已经过测试分开并正在工作。
我的代码在下面有注释。如果有人可以帮助我打开对话框并预填充 4 个文本字段,我很想看看我哪里出错了。如果你能帮我把数据添加到邮票的 Text1 到 Text4 框中,我会欣喜若狂!
// Dialog Definition
var oDlg = {
RMAStatus: "",
FreeText: "",
NameAndUnit: "",
TodaysDate: "",
description:
{
name: "Stamp details",
elements:
[
{
type: "view",
elements:
[
{
type: "view",
elements:
[
{
item_id: "lbl1",
type: "static_text",
name: "&RMA Stage",
},
{
width: 200,
height: 22,
type: "edit_text",
item_id: "rmas",
}
],
type: "view",
elements:
[
{
item_id: "lbl1",
type: "static_text",
name: "&Free text field",
},
{
width: 200,
height: 88,
type: "edit_text",
item_id: "free",
}
],
type: "view",
elements:
[
{
item_id: "lbl1",
type: "static_text",
name: "&Your name and team",
},
{
width: 200,
height: 22,
type: "edit_text",
item_id: "team",
}
],
type: "view",
elements:
[
{
item_id: "lbl1",
type: "static_text",
name: "&Stamp date",
},
{
width: 200,
height: 22,
type: "edit_text",
item_id: "date",
}
]
},
{
type: "ok_cancel",
}
]
}
]
},
initialize: function(dialog) { // where the data in dialog elements is set when the dialog is first activated
dialog.load({
"rmas":this.RMAStage,
"free":this.FreeText,
"team":this.CorrectName,
"date":this.todaysDate,
});
},
commit: function(dialog) { // where element data is acquired when the user presses the OK button
var data = dialog.store();
this.RMAStage = data["rmas"];
this.FreeText = data["free"];
this.CorrectName = data["team"];
this.todaysDate = data["date"];
}
};
/*
* Pre-fill the dialog text fields with the data below
*/
/* RMA STAGE (for RMAS to be populated) */
oDlg.RMAStage = "RMA Stage";
/* FREE TEXT FIELD (for FREE to be populated) */
oDlg.FreeText = "";
/* NAME AND UNIT (for TEAM to be populated) */
var IdentityName, IdentityNameSplit, Unit;
/* Set Organisation Unit */
Unit = "Parks & Landscapes Team"; // Unlikely to change
/* Find correctly formatted username from Identity info */
if((identity.name != null) && !/^\s*$/.test(identity.name))
IdentityName = identity.name;
else
IdentityName = identity.loginName.replace(/\./g," ").replace(/\./g," ").replace(/\b(\w)/g,function(Word,cFst){return cFst.toUpperCase()});
if (IdentityName.indexOf(', ') > -1) { // If the result is "Surname, Firstname" swap the names to make "Firstname Surname"
IdentityNameSplit = IdentityName.split(', ');
oDlg.NameAndUnit = IdentityNameSplit[1] + " " + IdentityNameSplit[0] + ", " + Unit;
}
else
oDlg.NameAndUnit = IdentityName + ", " + Unit;
/* FORMATTED DATE FIELD (for DATE to be populated) */
var stampDate;
stampDate = new Date();
oDlg.TodaysDate = util.printd("dd mmmm, yyyy", stampDate);
// Start dialog function
app.execDialog (oDlg);
搞定了!如果其他人想 copy/paste 自己解决这个问题:
var pagDlg =
{
result: "cancel",
DoDialog: function () { return app.execDialog(this); },
//definitions
strDefFmt: "dd-mm-yyyy",
strFmt: "dddd d mmmm, yyyy",
vDate: new Date,
strDate: "",
iOChecked: false,
abwChecked: false,
//
SetListSel: function (list, path) {
if (path.length == 0) return;
eval("list[\"" + ((path.join != "function") ? path : path.join("\"][\"")) + "\"] = 1");
},
GetListSel: function (oLstResult) {
for (var item in oLstResult) {
if ((typeof oLstResult[item] == "number") && (oLstResult[item] > 0))
return item;
}
return "";
},
formatDate: function (d, f) {
return util.printd(f, d);
},
//Initialize values that will be used in the pop-up dialogue
initialize: function (dialog) {
var unit = "Technical Services & Design";
this.strDate = this.formatDate(this.vDate, this.strDefFmt);
//this.strDate = this.formatDate(this.vDate, "dd mmmm, yyyy");
//
var dlgInit =
{
"date": this.strDate,
"free": "Enter your description text here.", //enable this checkbox option as default
"abw_2": IdentityName + ", " + unit,
"rma": "RMA Stage",
};
dialog.load(dlgInit);
iOChecked = dlgInit["free"]; // initialise and keep it the same as the value in dlgInit
abwChecked = dlgInit["abw_2"];
rmaChecked = dlgInit["rma"];
},
commit: function (dialog) { // Called when OK button is pressed
var oRslt = dialog.store();
var path = new Array();
var d = oRslt["date"]; //OK Go date
//
if (typeof d == "string")
d = util.scand(this.strDefFmt, d);
if (d != null)
{
var cur = new Date;
d = new Date(d.getFullYear(), d.getMonth(), d.getDate(), cur.getHours(), cur.getMinutes(), cur.getSeconds());
}
this.vDate = d;
//
this.rmaChecked = oRslt["rma"];
this.iOChecked = oRslt["free"];
this.abwChecked = oRslt["abw_2"];
this.strDate = oRslt["date"];
},
//Description of the layout of the Dialoge Window
description:
{
name: "Stamp details",
width: 450,
elements:
[
{
type: "view",
width: 450,
elements:
[
{
type: "view",
align_children: "align_row",
elements:
[
{
item_id: "lbl1",
name: "RMA Stage",
type: "static_text",
width: 100,
},
{
item_id: "rma",
type: "edit_text",
width: 300,
},
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
item_id: "lbl1",
name: "Free text",
type: "static_text",
width: 100,
alignment: "align_top",
align_children: "align_top",
},
{
item_id: "free",
type: "edit_text",
multiline: true,
width: 300,
height: 88,
},
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
item_id: "lbl1",
name: "Name and team",
type: "static_text",
width: 100,
},
{
item_id: "abw_2",
type: "edit_text",
width: 300,
},
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
item_id: "lbl1",
name: "Date",
type: "static_text",
width: 100,
},
{
item_id: "date",
type: "edit_text",
DateEdit: true,
width: 100,
}
]
},
{
type: "ok_cancel",
},
]
}
]
}
};
/* NAME */
var IdentityName, IdentityNameSplit;
/* Find correctly formatted username from Identity info */
if((identity.name != null) && !/^\s*$/.test(identity.name))
IdentityName = identity.name;
else
IdentityName = identity.loginName.replace(/\./g," ").replace(/\./g," ").replace(/\b(\w)/g,function(Word,cFst){return cFst.toUpperCase()});
if (IdentityName.indexOf(', ') > -1) { // If the result is "Surname, Firstname" swap the names to make "Firstname Surname"
IdentityNameSplit = IdentityName.split(', ');
IdentityName = IdentityNameSplit[1] + " " + IdentityNameSplit[0];
}
if (event.source.forReal && (event.source.stampName == "#T2CKw07Lo6sr42d6F3ao#0"))
{
if (pagDlg.DoDialog() == "ok")
{
var d = pagDlg.vDate;
this.getField("Text1").value = pagDlg.rmaChecked; // RMA Stage
this.getField("Text2").value = pagDlg.iOChecked; // Free text
this.getField("Text3").value = pagDlg.abwChecked; // Name and team
this.getField("Text4").value = util.printd(pagDlg.strFmt, d); // Date
}
else
{
app.alert("Stamp cancelled", 3);
}
}
else
{
var d = pagDlg.vDate;
event.value = util.printd(pagDlg.strFmt, d);
}
希望有人会觉得这有用。
我一直在尝试创建一个动态 PDF-XChange 图章,图章上有 4 个动态文本字段(Text1、Text2、Text3 和 Text4),用户可以在放置图章之前在对话框中进行编辑。我想要的是让用户 select 图章和对话框弹出窗口打开 4 个用户输入字段:
- RMA 状态 - 用户添加状态(命名为 RMAS)
- 供用户输入任何内容的自由文本字段(名为 FREE)
- 从用户的身份信息中提取的用户名和业务团队(名为 TEAM)
- 今天的日期,可编辑以防他们在事后标记某些东西(命名为 DATE)
我让它工作时弹出一个对话框 4 次连续询问用户每个问题,但要求的是一个带有 4 个文本字段的对话框。我似乎无法弄清楚我的下面的代码需要如何更改才能工作,但我对此很陌生。
目前它只打开最后一个问题(日期),在对话框激活之前没有被我的 JavaScript 日期代码填充,none 其他问题。如果我删除日期元素,它会询问它之前的问题(名称和业务单位),但它不会显示一个对话框,其中使用代码末尾处理的数据预先填充了所有 4 个问题,该代码已经过测试分开并正在工作。
我的代码在下面有注释。如果有人可以帮助我打开对话框并预填充 4 个文本字段,我很想看看我哪里出错了。如果你能帮我把数据添加到邮票的 Text1 到 Text4 框中,我会欣喜若狂!
// Dialog Definition
var oDlg = {
RMAStatus: "",
FreeText: "",
NameAndUnit: "",
TodaysDate: "",
description:
{
name: "Stamp details",
elements:
[
{
type: "view",
elements:
[
{
type: "view",
elements:
[
{
item_id: "lbl1",
type: "static_text",
name: "&RMA Stage",
},
{
width: 200,
height: 22,
type: "edit_text",
item_id: "rmas",
}
],
type: "view",
elements:
[
{
item_id: "lbl1",
type: "static_text",
name: "&Free text field",
},
{
width: 200,
height: 88,
type: "edit_text",
item_id: "free",
}
],
type: "view",
elements:
[
{
item_id: "lbl1",
type: "static_text",
name: "&Your name and team",
},
{
width: 200,
height: 22,
type: "edit_text",
item_id: "team",
}
],
type: "view",
elements:
[
{
item_id: "lbl1",
type: "static_text",
name: "&Stamp date",
},
{
width: 200,
height: 22,
type: "edit_text",
item_id: "date",
}
]
},
{
type: "ok_cancel",
}
]
}
]
},
initialize: function(dialog) { // where the data in dialog elements is set when the dialog is first activated
dialog.load({
"rmas":this.RMAStage,
"free":this.FreeText,
"team":this.CorrectName,
"date":this.todaysDate,
});
},
commit: function(dialog) { // where element data is acquired when the user presses the OK button
var data = dialog.store();
this.RMAStage = data["rmas"];
this.FreeText = data["free"];
this.CorrectName = data["team"];
this.todaysDate = data["date"];
}
};
/*
* Pre-fill the dialog text fields with the data below
*/
/* RMA STAGE (for RMAS to be populated) */
oDlg.RMAStage = "RMA Stage";
/* FREE TEXT FIELD (for FREE to be populated) */
oDlg.FreeText = "";
/* NAME AND UNIT (for TEAM to be populated) */
var IdentityName, IdentityNameSplit, Unit;
/* Set Organisation Unit */
Unit = "Parks & Landscapes Team"; // Unlikely to change
/* Find correctly formatted username from Identity info */
if((identity.name != null) && !/^\s*$/.test(identity.name))
IdentityName = identity.name;
else
IdentityName = identity.loginName.replace(/\./g," ").replace(/\./g," ").replace(/\b(\w)/g,function(Word,cFst){return cFst.toUpperCase()});
if (IdentityName.indexOf(', ') > -1) { // If the result is "Surname, Firstname" swap the names to make "Firstname Surname"
IdentityNameSplit = IdentityName.split(', ');
oDlg.NameAndUnit = IdentityNameSplit[1] + " " + IdentityNameSplit[0] + ", " + Unit;
}
else
oDlg.NameAndUnit = IdentityName + ", " + Unit;
/* FORMATTED DATE FIELD (for DATE to be populated) */
var stampDate;
stampDate = new Date();
oDlg.TodaysDate = util.printd("dd mmmm, yyyy", stampDate);
// Start dialog function
app.execDialog (oDlg);
搞定了!如果其他人想 copy/paste 自己解决这个问题:
var pagDlg =
{
result: "cancel",
DoDialog: function () { return app.execDialog(this); },
//definitions
strDefFmt: "dd-mm-yyyy",
strFmt: "dddd d mmmm, yyyy",
vDate: new Date,
strDate: "",
iOChecked: false,
abwChecked: false,
//
SetListSel: function (list, path) {
if (path.length == 0) return;
eval("list[\"" + ((path.join != "function") ? path : path.join("\"][\"")) + "\"] = 1");
},
GetListSel: function (oLstResult) {
for (var item in oLstResult) {
if ((typeof oLstResult[item] == "number") && (oLstResult[item] > 0))
return item;
}
return "";
},
formatDate: function (d, f) {
return util.printd(f, d);
},
//Initialize values that will be used in the pop-up dialogue
initialize: function (dialog) {
var unit = "Technical Services & Design";
this.strDate = this.formatDate(this.vDate, this.strDefFmt);
//this.strDate = this.formatDate(this.vDate, "dd mmmm, yyyy");
//
var dlgInit =
{
"date": this.strDate,
"free": "Enter your description text here.", //enable this checkbox option as default
"abw_2": IdentityName + ", " + unit,
"rma": "RMA Stage",
};
dialog.load(dlgInit);
iOChecked = dlgInit["free"]; // initialise and keep it the same as the value in dlgInit
abwChecked = dlgInit["abw_2"];
rmaChecked = dlgInit["rma"];
},
commit: function (dialog) { // Called when OK button is pressed
var oRslt = dialog.store();
var path = new Array();
var d = oRslt["date"]; //OK Go date
//
if (typeof d == "string")
d = util.scand(this.strDefFmt, d);
if (d != null)
{
var cur = new Date;
d = new Date(d.getFullYear(), d.getMonth(), d.getDate(), cur.getHours(), cur.getMinutes(), cur.getSeconds());
}
this.vDate = d;
//
this.rmaChecked = oRslt["rma"];
this.iOChecked = oRslt["free"];
this.abwChecked = oRslt["abw_2"];
this.strDate = oRslt["date"];
},
//Description of the layout of the Dialoge Window
description:
{
name: "Stamp details",
width: 450,
elements:
[
{
type: "view",
width: 450,
elements:
[
{
type: "view",
align_children: "align_row",
elements:
[
{
item_id: "lbl1",
name: "RMA Stage",
type: "static_text",
width: 100,
},
{
item_id: "rma",
type: "edit_text",
width: 300,
},
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
item_id: "lbl1",
name: "Free text",
type: "static_text",
width: 100,
alignment: "align_top",
align_children: "align_top",
},
{
item_id: "free",
type: "edit_text",
multiline: true,
width: 300,
height: 88,
},
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
item_id: "lbl1",
name: "Name and team",
type: "static_text",
width: 100,
},
{
item_id: "abw_2",
type: "edit_text",
width: 300,
},
]
},
{
type: "view",
align_children: "align_row",
elements:
[
{
item_id: "lbl1",
name: "Date",
type: "static_text",
width: 100,
},
{
item_id: "date",
type: "edit_text",
DateEdit: true,
width: 100,
}
]
},
{
type: "ok_cancel",
},
]
}
]
}
};
/* NAME */
var IdentityName, IdentityNameSplit;
/* Find correctly formatted username from Identity info */
if((identity.name != null) && !/^\s*$/.test(identity.name))
IdentityName = identity.name;
else
IdentityName = identity.loginName.replace(/\./g," ").replace(/\./g," ").replace(/\b(\w)/g,function(Word,cFst){return cFst.toUpperCase()});
if (IdentityName.indexOf(', ') > -1) { // If the result is "Surname, Firstname" swap the names to make "Firstname Surname"
IdentityNameSplit = IdentityName.split(', ');
IdentityName = IdentityNameSplit[1] + " " + IdentityNameSplit[0];
}
if (event.source.forReal && (event.source.stampName == "#T2CKw07Lo6sr42d6F3ao#0"))
{
if (pagDlg.DoDialog() == "ok")
{
var d = pagDlg.vDate;
this.getField("Text1").value = pagDlg.rmaChecked; // RMA Stage
this.getField("Text2").value = pagDlg.iOChecked; // Free text
this.getField("Text3").value = pagDlg.abwChecked; // Name and team
this.getField("Text4").value = util.printd(pagDlg.strFmt, d); // Date
}
else
{
app.alert("Stamp cancelled", 3);
}
}
else
{
var d = pagDlg.vDate;
event.value = util.printd(pagDlg.strFmt, d);
}
希望有人会觉得这有用。