📄 objmod80.ssc
字号:
index = result.indexOf(".");
while (index != -1) {
result = result.substring(0, index - 1) + "_" + result.substring(index + 1);
index = result.indexOf(".", index + 1);
}
return result;
}
function psEscapeString( inString )
{
var index;
var outString = "";
var tempChar;
// force to string type or charAt will fail!
if (typeof inString != "string")
inString = inString + "";
var strLength = inString.length;
for ( index=0; index < strLength; index++ )
{
tempChar = inString.charAt( index );
if (tempChar == "\"" || tempChar == "'")
outString += "\\" + tempChar;
else if (tempChar == "\r")
outString += "\\r";
else if (tempChar == "\n")
outString += "\\n";
else
outString += tempChar;
}
return outString;
}
function psEscapeForTrace( inString )
{
var index;
var outString = "";
var tempChar;
// force to string type or charAt will fail!
if (typeof inString != "string")
inString = inString + "";
var strLength = inString.length;
for ( index=0; index < strLength; index++ )
{
tempChar = inString.charAt( index );
if (tempChar == "\r")
outString += "\\r";
else if (tempChar == "\n")
outString += "\\n";
else if (tempChar == "<")
outString += "<"
else if (tempChar == ">")
outString += ">"
else if (tempChar == "&")
outString += "&"
else if (tempChar == "\"")
outString += """
else
outString += tempChar;
}
return outString;
}
// this function is used to get the server object for the passed page name
function psGetServerPage(pageName, doTrace) {
var result;
var sessionVarName = "page_" + psRemoveDots (pageName);
if (arguments.length < 2)
doTrace = false;
// check if trace is globally overridden
if (exists(PSPAGETRACE))
doTrace = PSPAGETRACE == 1;
var fromPageName = psDocument.GetParam("__GeneratedFromPage");
// check if we are doing a self navigation,
if(fromPageName != null && fromPageName == pageName)
// if so, check if page is still stored in the session
result = psSession.GetValue(sessionVarName);
// otherwise, treat it like we didn't have it in the session.
else
result = null;
// if not, then we create a new one
if (result == null) {
result = new PSServerPageClass(pageName, doTrace);
if (doTrace) result.Trace("psGetServerPage: created new page '" + pageName + "'");
// stick it into the session so we can get it back again
psSession.SetValue(sessionVarName, result);
} else {
if (doTrace) result.Trace("psGetServerPage: got page '" + pageName + "' out of session");
}
return result;
}
// this is used to allow for defaulting of event results
function evtdef(result, defResult)
{
if (arguments.length < 2)
defResult = true;
if (result + "" == "undefined")
result = defResult;
return result;
}
class PSServerObjectWithEventsClass()
{
function checkForEvent(eventName, parm1, parm2, parm3, parm4, parm5) {
var eventFuncObj = null;
var foundEvent = false;
var traceLine = "";
// we are using global state in order to do tracing
if (psPage.doTrace) {
traceLine = "event " + this.name + "." + eventName + "(";
if (arguments.length > 2)
traceLine += "'" + parm1 + "'";
if (arguments.length > 3)
traceLine += ",'" + parm2 + "'";
if (arguments.length > 4)
traceLine += ",'" + parm3 + "'";
if (arguments.length > 5)
traceLine += ",'" + parm4 + "'";
if (arguments.length > 6)
traceLine += ",'" + parm5 + "'";
traceLine += ") ";
}
// check if we already have something
if (exists(this[eventName]))
eventFuncObj = this[eventName];
// if event not already discovered...
if (eventFuncObj == null) {
// check for a function with default name
var testName = this.name + '_' + eventName;
// if we got one, then we use it.
if (eval('exists(' + testName + ') && (typeof ' + testName + ' == "function")')) {
eventFuncObj = eval(testName);
this[eventName] = eventFuncObj
}
}
if (eventFuncObj != null) {
psPage.Trace(traceLine + "(found)");
foundEvent = true;
} else {
psPage.Trace(traceLine + "(NOT FOUND)");
foundEvent = false;
}
return foundEvent;
}
this.checkForEvent = checkForEvent;
}
class PSServerPageClass(pageName, doTrace) extends PSServerObjectWithEventsClass
{
// this is the main function that runs the server side event model
function RunServerEventModel() {
var bContinue = true;
var bExit = false;
// start off initialization
this.initialzeInternalPageVars();
this.Trace("RunServerEventModel: start");
this.TraceIndent();
// run RequestStart() event
if (this.checkForEvent("RequestStart")) {
this.TraceIndent();
bContinue = evtdef(this.RequestStart());
this.TraceOutdent();
this.Trace("...returned " + bContinue);
if (! bContinue)
this.Trace("Skipping rest of processing because RequestStart returned false");
}
if (bContinue) {
// check if we need to create the object model
if (this.bCreateObjectModel) {
// create object model
if (this.checkForEvent("__CreateObjectModel")) {
this.TraceIndent();
this.__CreateObjectModel();
this.TraceOutdent();
}
this.bCreateObjectModel = false;
}
// initialize the page variables
if (this.checkForEvent("__InitializeVariables")) {
this.TraceIndent();
this.__InitializeVariables();
this.TraceOutdent();
}
// if the first time in,
if (this.firstTime) {
// run FirstTime() event
if (this.checkForEvent("FirstTime")) {
this.TraceIndent();
bContinue = evtdef(this.FirstTime());
this.TraceOutdent();
if (! bContinue)
this.Trace("Skipping rest of processing because FirstTime returned false");
}
} else {
// otherwise, perform binding
this.performInputBinding();
}
}
// do component binding
if (bContinue) {
this.Trace("Binding to component properties:");
this.TraceIndent();
// for each control, ...
for (controlName in this.controls) {
control = this.controls[controlName];
this.Trace("Component Binding '" + control.name + "'");
// tell it to do component value binding
this.TraceIndent();
control.BindToComponent(this);
this.TraceOutdent();
}
this.TraceOutdent();
}
// run BeforeGenerate() event
if (bContinue && ! this.didRedirect) {
this.bDidGenerate = true;
if (this.checkForEvent("BeforeGenerate")) {
this.TraceIndent();
bContinue = evtdef(this.BeforeGenerate());
this.TraceOutdent();
this.Trace("...returned " + bContinue);
if (! bContinue)
this.Trace("Skipping generation because BeforeGenerate returned false");
}
}
// if we canceled based on events or did a redirect,
// run EndOfPage() now and exit
if (!bContinue || this.didRedirect) {
this.EndOfPage();
bExit = true;
}
this.TraceOutdent();
this.Trace("RunServerEventModel: end");
// check if we should stop processing.
if (bExit)
exit;
return bContinue;
}
// this should be called just after the <BODY> tag to generate the forms that are used
function GenerateBodyPrologue() {
var actionURL = document.name;
var variableName, variable, controlName, control, parameterName, parameter;
// check if destination provided,
if (this.destination != null)
actionURL = this.destination;
// otherwise, we are self navigating
else
actionURL = document.name;
// SUBMIT FORM
psDocument.WriteLn("<FORM NAME=\"__submitForm\" METHOD=\"POST\" ACTION=\"" + actionURL + "\">");
psDocument.WriteLn(" <INPUT TYPE=\"hidden\" NAME=\"__ActionControlName\" VALUE=\"\">");
psDocument.WriteLn(" <INPUT TYPE=\"hidden\" NAME=\"__GeneratedFromPage\" VALUE=\"" + this.pageName + "\">");
// for each parameter
for (parameterName in this.parameters) {
parameter = this.parameters[parameterName];
parameter.GenerateClientFormFragment(this);
}
// for each control
for (controlName in this.controls) {
control = this.controls[controlName];
control.GenerateClientFormFragment(this);
}
// for each variable
for (variableName in this.variables) {
variable = this.variables[variableName];
variable.GenerateClientFormFragment(this);
}
psDocument.WriteLn("</FORM>");
psDocument.WriteLn("<SCRIPT LANGUAGE=\"JavaScript\">");
// OnSubmit EVENT
psDocument.WriteLn("function __submitForm_onSubmit(submitForm) {");
psDocument.WriteLn(" // Generate some kind of user defined client side OnSubmit???");
// for each control
for (controlName in this.controls) {
control = this.controls[controlName];
control.GenerateClientOnSubmitFragment(this);
}
// for each variable
for (variableName in this.variables) {
variable = this.variables[variableName];
variable.GenerateClientOnSubmitFragment(this);
}
psDocument.WriteLn(" return true;");
psDocument.WriteLn("}");
// VARIABLE AND psPage DECLARATIONS
psDocument.WriteLn(" var psPage = new Object();");
psDocument.WriteLn(" psPage.submitForm = document.__submitForm;");
psDocument.WriteLn("");
psDocument.WriteLn(" function psPage___ButtonPress(buttonName) {");
psDocument.WriteLn(" this.submitForm.__ActionControlName.value = buttonName;");
psDocument.WriteLn(" this.Submit();");
psDocument.WriteLn(" }");
psDocument.WriteLn(" function psPage___Submit() {");
psDocument.WriteLn(" if(__submitForm_onSubmit(this.submitForm))");
psDocument.WriteLn(" this.submitForm.submit();");
psDocument.WriteLn(" }");
psDocument.WriteLn(" psPage.ButtonPress = psPage___ButtonPress;");
psDocument.WriteLn(" psPage.Submit = psPage___Submit;");
// for each variable
for (variableName in this.variables) {
variable = this.variables[variableName];
variable.GenerateClientVariableDefinitionFragment(this);
}
psDocument.WriteLn("</SCRIPT>");
// write out any trace messages
this.TraceWriteToDocument();
if (this.showErrorsOnPage && this.showErrorsAtTop)
this.WriteErrorsToDocument();
// DATA FORM (take care of case where someone trys to submit the form anyways)
psDocument.WriteLn("<FORM NAME=\"__dataForm\" ACTION=\"don't submit this form\" OnSubmit=\"psPage.Submit(); return false;\">");
}
// this should be called just before the </BODY> tag to close off any tags generated above
function GenerateBodyEpilogue() {
var control, controlName;
// close up data form
psDocument.WriteLn("</FORM>");
// this needs to come after the data form is closed because we could reference
// elements of the data form
psDocument.WriteLn("<SCRIPT LANGUAGE=\"JavaScript\">");
psDocument.WriteLn(" psPage.dataForm = document.__dataForm;");
// for each control
for (controlName in this.controls) {
control = this.controls[controlName];
control.GenerateClientVariableDefinitionFragment(this);
}
psDocument.WriteLn(" function psPage___OnLoad() {");
// check if we want to dump errors into alert
if (this.showErrorsInAlert)
this.WriteErrorsToAlert();
// check if we have an alert message and write it out
if (this.alertMessage.length > 0) {
psDocument.WriteLn(" alert(\"" + psEscapeString(this.alertMessage) + "\");");
}
psDocument.WriteLn(" }");
psDocument.WriteLn(" psPage.OnLoad = psPage___OnLoad;");
psDocument.WriteLn("</SCRIPT>");
if (this.showErrorsOnPage && ! this.showErrorsAtTop)
this.WriteErrorsToDocument();
}
// this should be called at the very end of a template to do any cleanup
function EndOfPage() {
if (this.bDidGenerate) {
if (this.checkForEvent("AfterGenerate")) {
this.TraceIndent();
this.AfterGenerate();
this.TraceOutdent();
}
}
// run RequestFinish() event
if (this.checkForEvent("RequestFinish")) {
this.TraceIndent();
this.RequestFinish();
this.TraceOutdent();
}
// save the value of all session variables (but only if we have an object model!)
if (! this.bCreateObjectModel && this.checkForEvent("__SaveVariables")) {
this.TraceIndent();
this.__SaveVariables();
this.TraceOutdent();
}
this.firstTime = false;
}
function Alert(message, appendToCurrent)
{
if (arguments.length < 2)
appendToCurrent = false;
if (appendToCurrent) {
// add line terminator is message already present
if (this.alertMessage.length > 0)
this.alertMessage += "\r\n";
this.alertMessage += message;
} else
this.alertMessage = message;
}
// this function is expecting any arguments to the URL to be passed as strings,
// in the form <varName>=escape(<value>)
function Redirect(destination)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -