21.30. У разі, якщо файл документа в образі документа і при цьому він не підписаний, при збереженні документа автоматично викликається функція підписання файлу.
|
module.exports = {
beforeSave(event) {
const file = event.document.getNativeFileAttribute()
if (file.fileInfo && !file.isSigned) {
event.cancelSave()
const fileAttributeNodeID = 8
const fileAttributeControl =
event.form.getNodeControl(fileAttributeNodeID)
fileAttributeControl.openSignWindow()
}
}
}
|
21.31. Подібний приклад, але для файлового атрибута документа.
|
module.exports = {
beforeSave(event) {
const file = event.document.getFileAttribute(‘a001’)
if (file.fileInfo && !file.isSigned) {
event.cancelSave()
const fileAttributeNodeID = 9
const fileAttributeControl = event.form.getNodeControl(fileAttributeNodeID)
fileAttributeControl.openSignWindow()
}
}
}
|
12.32. Подібний приклад, але для файлового атрибута таблиці.
|
module.exports = {
beforeSave(event) {
const file = event.documentItem.getFileAttribute(‘a001’)
if (file.fileInfo && !file.isSigned) {
event.cancelSave()
const fileAttributeNodeID = 2
const fileAttributeControl = event.form.getNodeControl(fileAttributeNodeID)
fileAttributeControl.openSignWindow()
}
}
}
|
12.33. Якщо в образі документа файл не заданий, то при спробі збереження документа автоматично запускається сканування.
|
module.exports = {
beforeSave(event) {
const file = event.document.getNativeFileAttribute()
if (!file.fileInfo) {
event.cancelSave()
const fileAttributeNodeID = 8
const fileAttributeControl = event.form.getNodeControl(fileAttributeNodeID)
fileAttributeControl.openScanWindow()
}
}
}
|
12.34. Якщо в образі документа файл не заданий, то при спробі збереження документа автоматично запускається генерація файлу за налаштованим шаблоном. Якщо шаблон не налаштований, метод нічого не робить.
|
module.exports = {
beforeSave(event) {
const file = event.document.getNativeFileAttribute()
if (!file.fileInfo) {
event.cancelSave()
const fileAttributeNodeID = 8
const fileAttributeControl = event.form.getNodeControl(fileAttributeNodeID)
fileAttributeControl.generateByTemplate()
}
}
}
|
12.35. Те саме, але для файлового атрибуту таблиці.
|
module.exports = {
beforeSave(event) {
const file = event.documentItem.getFileAttribute(‘a001’)
if (!file.fileInfo) {
event.cancelSave()
const fileAttributeNodeID = 3
const fileAttributeControl = event.form.getNodeControl(fileAttributeNodeID)
fileAttributeControl.openScanWindow()
}
}
}
|
12.36. Завантаження файлу з документа при збереженні документа.
|
module.exports = {
beforeSave(event) {
const file = event.document.getNativeFileAttribute()
if (file.fileInfo) {
const fileAttributeNodeID = 8
const fileAttributeControl = event.form.getNodeControl(fileAttributeNodeID)
fileAttributeControl.downloadFile()
}
}
}
|
12.37. Те саме, але для файлового атрибуту таблиці.
|
module.exports = {
beforeSave(event) {
const file = event.documentItem.getFileAttribute(‘Attrfile22_20Mb’)
if (file.fileInfo) {
const fileAttributeNodeID = 3
const fileAttributeControl = event.form.getNodeControl(fileAttributeNodeID)
fileAttributeControl.downloadFile()
}
}
}
|
12.38. Якщо файл не задано в образі документа, при спробі збереження документа з’являється форма для завантаження файлу.
|
module.exports = {
beforeSave(event) {
const file = event.document.getNativeFileAttribute()
if (!file.fileInfo) {
event.cancelSave()
const fileAttributeNodeID = 8
const fileAttributeControl = event.form.getNodeControl(fileAttributeNodeID)
fileAttributeControl.openUploadFileWindow()
}
}
}
|
12.39. Приклад для Завдання за допомогою кнопки. Якщо в образі файл заданий, то при спробі затвердження завдання буде виконано автоматичне підписання файлу.
|
module.exports = {
action_beforeExecute_approve(event) {
const file = event.document.getNativeFileAttribute()
if (file.fileInfo && !file.isSigned) {
const fileAttributeNodeID = 9
const fileAttributeControl = event.form.getNodeControl(fileAttributeNodeID)
fileAttributeControl.openSignWindow()
}
}
}
|
12.40. Приклад аналогічний попередньому але з вбудованим таймером, який дає час на підпис.
|
module.exports = {
async action_beforeExecute_approve(event) {
const sleep = (mls) => new Promise(res => setTimeout(res, mls))
const timeout = 30000
const step = 3000
const file = event.document.getNativeFileAttribute()
if (file.fileInfo && !file.isSigned) {
event.skipStandardConfirmDialog() //Не показывать диалог подтверждения действия над задачей
const fileAttributeNodeID = 4
const fileAttributeControl = event.form.getNodeControl(fileAttributeNodeID)
fileAttributeControl.openSignWindow()
const fileupdate = event.document.getNativeFileAttribute() //Повторная проверка подписан ли файл и цикл
let awaitedTime = 0
while (awaitedTime < timeout) {
if (fileupdate.isSigned) {
return
}
await sleep(step)
awaitedTime = awaitedTime + step
}
event.cancelAction()
}
}
}
|