var myBook = app.activeBook;
if ( !myBook.isValid )
{
alert('No open books');
exit();
}
var myBookContents = myBook.bookContents;
var w = new Window ("dialog","Сохранение книги");
var msg = w.add ("statictext");
msg.text = "Закрыть документы после сохранения?";
var BG = w.add ("group");
BG.alignment = "right";
BG.add ("button", undefined, "Да", {name: "Ok"});
var no = BG.add ("button", undefined, "Нет");
BG.add ("button", undefined, "Отмена", {name: "Cancel"});
no.onClick = function(){ w.close(3); }
var res = w.show();
var bClose= false;
if ( res == 1 ) { bClose = true; }
var can_close_book = true;
for ( var k = 0; k < myBookContents.length; k++ )
{
if ( myBookContents[k].status == BookContentStatus.DOCUMENT_IS_OPEN || myBookContents[k].status == BookContentStatus.DOCUMENT_OUT_OF_DATE )
{
var doc = app.documents.item(myBookContents[k].name);
doc.save();
if ( bClose ) { doc.close(); }
}
else if ( myBookContents[k].status == BookContentStatus.DOCUMENT_IN_USE )
{
alert("Document "+myBookContents[k].name+" in use, try later.");
can_close_book = false;
}
else if ( myBookContents[k].status == BookContentStatus.MISSING_DOCUMENT )
{
alert("Document "+myBookContents[k].name+" are missing.");
can_close_book = false;
}
}
if ( can_close_book && bClose ) myBook.close(SaveOptions.YES);
else if ( can_close_book ) myBook.save();