📄 docsched.ssc
字号:
<!--SCRIPT PSOBJMOD
import( site.GetRootDocument().location + "/ObjMod80.ssc" );
session.active = true;
InitObjects(session);
-->
<!--SCRIPT // {{ SCRIPT()
/* Schedule a document to be periodically generated */
var webRoot = site.GetRootDocument();
import ( webRoot.location + '/system/utils/strtable.ssc' );
import ( webRoot.location + '/system/utils/wizard.ssc' );
// First check that the document has file extension .ssc or .stm
var docname = document.location;
var result = false;
var index = docname.lastIndexOf( '.' );
if( index != -1 ) {
var extension = docname.substring( index + 1, docname.length );
if( extension == 'ssc' || extension == 'stm' ) {
result = true;
}
}
if( !result ) {
document.writeln( IntlStr.wizSched.mustBeScript );
return;
}
/* general use functions */
function skip_spaces( space_str )
{
start = 0;
// skip leading spaces
while( space_str.charAt(start) == ' ' ) {
start++;
}
// skip trailing spaces
end = space_str.length - 1;
while( space_str.charAt(end) == ' ' ) {
end--;
}
if( start > end ) {
return "";
} else {
return space_str.substring( start, end + 1 );
}
}
/* data validation functions */
function validate_minute( str )
{
str = skip_spaces( str );
if( 0 > str || 59 < str ) {
return false;
}
return true;
}
function validate_time( str )
{
str = skip_spaces( str );
var colon = str.indexOf( ":" );
if( colon < 1 || colon > 2 ) {
return false;
}
if( str.length > colon + 2 + 1 ) {
return false;
}
var hour = str.substring( 0, colon );
var minute = str.substring( colon + 1, str.length );
if( 0 > hour || 23 < hour ) {
return false;
}
return validate_minute( minute );
}
function validate_day( str ) {
str = skip_spaces( str );
low = str.toLowerCase();
if( low == IntlStr.Weekdays.Monday
|| low == IntlStr.Weekdays.Tuesday
|| low == IntlStr.Weekdays.Wednesday
|| low == IntlStr.Weekdays.Thursday
|| low == IntlStr.Weekdays.Friday
|| low == IntlStr.Weekdays.Saturday
|| low == IntlStr.Weekdays.Sunday ) {
return true;
}
return false;
}
function validate_date( str )
{
str = skip_spaces( str );
if( 0 > str || 31 < str ) {
return false;
}
return true;
}
function validate_month( str )
{
str = skip_spaces( str );
low = str.toLowerCase();
if( low == IntlStr.Months.January
|| low == IntlStr.Months.February
|| low == IntlStr.Months.March
|| low == IntlStr.Months.April
|| low == IntlStr.Months.May
|| low == IntlStr.Months.June
|| low == IntlStr.Months.July
|| low == IntlStr.Months.August
|| low == IntlStr.Months.September
|| low == IntlStr.Months.October
|| low == IntlStr.Months.November
|| low == IntlStr.Months.December ) {
return true;
}
return false;
}
/* wizard page "next" functions */
function next() {
return wiz.interval_length.selected + 1;
}
function validate_hourly() {
if( !validate_minute( wiz.interval_hourly.value ) ) {
site.ShowMessage( "PowerDynamo", IntlStr.wizSched.badFormat );
return "interval_hourly";
}
return "pregen_now";
}
function validate_daily() {
if( !validate_time( wiz.interval_daily.value ) ) {
site.ShowMessage( "PowerDynamo", IntlStr.wizSched.badFormat );
return "interval_daily";
}
return "pregen_now";
}
function validate_weekly() {
var temp = skip_spaces( wiz.interval_weekly.value );
var space = temp.indexOf( ' ' );
if( space != -1 ) {
var day = temp.substring( 0, space );
var time = temp.substring( space + 1, temp.length );
if( validate_day( day ) && validate_time( time ) ) {
return "pregen_now";
}
}
site.ShowMessage( "PowerDynamo", IntlStr.wizSched.badFormat );
return "interval_weekly";
}
function validate_monthly() {
var temp = skip_spaces( wiz.interval_monthly.value );
var space = temp.indexOf( ' ' );
if( space == 1 || space == 2 ) {
var date = temp.substring( 0, space );
var time = temp.substring( space + 1, temp.length );
if( validate_date( date ) && validate_time( time ) ) {
return "pregen_now";
}
}
site.ShowMessage( "PowerDynamo", IntlStr.wizSched.badFormat );
return "interval_monthly";
}
function validate_yearly() {
var temp = skip_spaces( wiz.interval_yearly.value );
var space = temp.indexOf( ' ' );
if( space != -1 ) {
var month = temp.substring( 0, space );
temp = temp.substring( space + 1, temp.length );
temp = skip_spaces( temp );
var space2 = temp.indexOf( ' ' );
if( space2 != -1 ) {
var date = temp.substring( 0, space2 );
var time = temp.substring( space2 + 1, temp.length );
if( validate_month( month ) && validate_date( date )
&& validate_time( time ) ) {
return "pregen_now";
}
}
}
site.ShowMessage( "PowerDynamo", IntlStr.wizSched.badFormat );
return "interval_yearly";
}
function build_translated_weekly_text( current_interval ) {
var intlDay;
var englishDay;
var pos;
pos = current_interval.indexOf( " " );
if( pos < 0 ) {
return current_interval;
}
intlDay = current_interval.substring( 0, pos );
intlDay = intlDay.toLowerCase();
if( intlDay == IntlStr.Weekdays.Monday ) {
englishDay = "Monday";
} else if( intlDay == IntlStr.Weekdays.Tuesday ) {
englishDay = "Tuesday"
} else if( intlDay == IntlStr.Weekdays.Wednesday ) {
englishDay = "Wednesday";
} else if( intlDay == IntlStr.Weekdays.Thursday ) {
englishDay = "Thursday";
} else if( intlDay == IntlStr.Weekdays.Friday ) {
englishDay = "Friday";
} else if( intlDay == IntlStr.Weekdays.Saturday ) {
englishDay = "Saturday";
} else if( intlDay == IntlStr.Weekdays.Sunday ) {
englishDay = "Sunday";
}
return englishDay + current_interval.substring( pos, current_interval.length );
}
function build_translated_yearly_text( current_interval ) {
var intlMonth;
var englishMonth;
var pos;
pos = current_interval.indexOf( " " );
if( pos < 0 ) {
return current_interval;
}
intlMonth = current_interval.substring( 0, pos );
intlMonth = intlMonth.toLowerCase();
if( intlMonth == IntlStr.Months.January ) {
englishMonth = "January";
} else if( intlMonth == IntlStr.Months.February ) {
englishMonth = "February"
} else if( intlMonth == IntlStr.Months.March ) {
englishMonth = "March";
} else if( intlMonth == IntlStr.Months.April ) {
englishMonth = "April";
} else if( intlMonth == IntlStr.Months.May ) {
englishMonth = "May";
} else if( intlMonth == IntlStr.Months.June ) {
englishMonth = "June";
} else if( intlMonth == IntlStr.Months.July ) {
englishMonth = "July";
} else if( intlMonth == IntlStr.Months.August ) {
englishMonth = "August";
} else if( intlMonth == IntlStr.Months.September ) {
englishMonth = "September";
} else if( intlMonth == IntlStr.Months.October ) {
englishMonth = "October";
} else if( intlMonth == IntlStr.Months.November ) {
englishMonth = "November";
} else if( intlMonth == IntlStr.Months.December ) {
englishMonth = "December";
}
return englishMonth + current_interval.substring( pos, current_interval.length );
}
var wiz;
wiz.interval_length = new wizardPage(
'Choice',
IntlStr.wizSched.p1.title,
IntlStr.wizSched.p1.explanation,
IntlStr.wizSched.p1.question,
IntlStr.wizSched.p1.choices,
0,
next
);
wiz.interval_hourly = new wizardPage(
'Text',
IntlStr.wizSched.p2.title,
IntlStr.wizSched.p2.hourly.explanation,
IntlStr.wizSched.p2.question,
null,
0,
validate_hourly
);
wiz.interval_daily = new wizardPage(
'Text',
IntlStr.wizSched.p2.title,
IntlStr.wizSched.p2.daily.explanation,
IntlStr.wizSched.p2.question,
null,
0,
validate_daily
);
wiz.interval_weekly = new wizardPage(
'Text',
IntlStr.wizSched.p2.title,
IntlStr.wizSched.p2.weekly.explanation,
IntlStr.wizSched.p2.question,
null,
0,
validate_weekly
);
wiz.interval_monthly = new wizardPage(
'Text',
IntlStr.wizSched.p2.title,
IntlStr.wizSched.p2.monthly.explanation,
IntlStr.wizSched.p2.question,
null,
0,
validate_monthly
);
wiz.interval_yearly = new wizardPage(
'Text',
IntlStr.wizSched.p2.title,
IntlStr.wizSched.p2.yearly.explanation,
IntlStr.wizSched.p2.question,
null,
0,
validate_yearly
);
wiz.pregen_now = new wizardPage(
'Choice',
IntlStr.wizSched.p3.title,
IntlStr.wizSched.p3.explanation,
IntlStr.wizSched.p3.question,
IntlStr.wizSched.p3.choices,
1
);
// Display the wizard
if( site.CreateWizard( wiz ) ) {
var interval_time;
var intl_interval_time;
var international_interval_length = wiz.interval_length.value;
// translate the wiz.interval_length since the value returned may not be
// in english
if( wiz.interval_length.value == IntlStr.wizSched.p1.choices.hourly ) {
wiz.interval_length.value = 'Hourly';
intl_interval_time = wiz.interval_hourly.value;
interval_time = intl_interval_time;
} else if( wiz.interval_length.value == IntlStr.wizSched.p1.choices.daily ) {
wiz.interval_length.value = 'Daily';
intl_interval_time = wiz.interval_daily.value;
interval_time = intl_interval_time;
} else if( wiz.interval_length.value == IntlStr.wizSched.p1.choices.weekly ) {
wiz.interval_length.value = 'Weekly';
intl_interval_time = wiz.interval_weekly.value;
interval_time = build_translated_weekly_text( intl_interval_time );
} else if( wiz.interval_length.value == IntlStr.wizSched.p1.choices.monthly ) {
wiz.interval_length.value = 'Monthly';
intl_interval_time = wiz.interval_monthly.value;
interval_time = intl_interval_time;
} else {
wiz.interval_length.value = 'Yearly';
intl_interval_time = wiz.interval_yearly.value;
interval_time = build_translated_yearly_text( intl_interval_time );
}
// Change the file extension
var fullname = docname.substring( 0, docname.length - 1 ) + 's';
// Create a new document that will hold the original script and generate the output
var newtext = '<!--SCRIPT\r\n /*\r\n * '
+ formatString( IntlStr.wizSched.docSchedAt, international_interval_length, intl_interval_time )
+ '.\r\n * '
+ formatString( IntlStr.wizSched.docSchedAt2, document.location )
+ '\r\n */\r\n ;\r\n-' + '->\r\n';
newtext += document.source;
var savedoc = site.CreateDocument( fullname, document.type, document.description, newtext, document.connectionId );
if( savedoc == null ) {
document.writeln( formatString(IntlStr.wizSched.unableToSaveOriginal, fullname ) );
return;
}
// Add the document to the list of scheduled documents. This is done explicity
// because the autoexec has already run at this point.
site.Schedule( fullname, wiz.interval_length.value, interval_time );
// Now alter the schedule.ssc script so that the scheduling will happen the next
// time the autoexec is run.
var schedulename = webRoot.location + '/system/schedule.ssc';
var scheduledoc = site.GetDocument( schedulename );
// Create the schedule.ssc file if it doesn't already exist
if( scheduledoc == null ) {
newtext = '<!--SCRIPT\r\n';
newtext += IntlStr.scriptGenerated;
newtext += 'function schedule( site ) {\r\n';
newtext += ' /* ' + IntlStr.wizSched.listFollows + ' */\r\n';
newtext += '}\r\n';
newtext += '--' + '>'; // have to split the end tag string
scheduledoc = site.CreateDocument( schedulename, 'script',
IntlStr.wizSched.listOfSched, newtext );
if( scheduledoc == null ) {
document.writeln( IntlStr.wizSched.cantCreateSched );
return;
}
}
// add the site.Schedule call to schedule.ssc before the closing '}'
// make a relative path name so that the root folder name and the mapping
// name don't need to match
index = scheduledoc.source.lastIndexOf( '}' );
var relativeName = fullname;
if( fullname.indexOf( webRoot.location ) != -1 ) {
var relativeName = fullname.substring( webRoot.location.length, fullname.length );
}
newtext = ' site.Schedule( site.GetRootDocument().location + "'
+ relativeName + '", "' + wiz.interval_length.value
+ '", "' + interval_time + '" );\r\n';
scheduledoc.source = scheduledoc.source.substring( 0, index ) + newtext
+ scheduledoc.source.substring( index, scheduledoc.source.length );
// alter the original document so that it contains a reference to the
// new file
document.source = '<!-' + '-SCRIPT\r\n /* '
+ formatString( IntlStr.wizSched.genSource, fullname )
+ ' */\r\n document.writeln( "'
+ IntlStr.wizSched.genSource2
+ '" );\r\n-' + '->\r\n';
// if requested, pregenerate the first set of output now
if( wiz.pregen_now.value == IntlStr.wizSched.p3.choices.yes ) {
document.source = savedoc.GetGenerated();
if( document.source.length == 0 ) {
site.DeleteDocument( document.location );
}
}
}
// }}
-->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -