⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objmod80.ssc

📁 PowerBuilder8.0开发分散式应用所帶的例程
💻 SSC
📖 第 1 页 / 共 5 页
字号:
	{
		var numArgs = arguments.length;

        this.Trace("Redirect: to '" + destination + "'");
		// append arguments if necessary
		if (numArgs > 1) {
            this.TraceIndent();
            
			var index, arg;
			var seperatorChar = "?";
			// if there are already any args specified on destination
			if (destination.indexOf("?") != -1)
				// use proper seperator
				seperatorChar = "&";
			for (index = 1; index < numArgs; index++) {
				arg = arguments[index];

                this.Trace("arg[" + index + "] = '" + arg.toString() + "'");
				destination += seperatorChar + arg;
				
				// switch seperator
				seperatorChar = "&";
			}
            this.TraceOutdent();
		}

		// do the redirection
		this.didRedirect = true;
		document.redirect = destination;
	}

	// this function should be used to report processing errors
	// It will invoke the ServerError() event and then log it.
	// Errors will be displayed either just after the trace (default) or at the 
	// end of the page
	// message strings are expected to be valid HTML and will have a <BR> added after every message
	// in the output
	function ReportError(location, cause, message) {
		var bLogError = true;
    	if (this.checkForEvent("ServerError", location, cause, message)) {
    		this.TraceIndent();
    		bLogError = evtdef(this.ServerError(location, cause, message));
    		this.TraceOutdent();
	    	this.Trace("...returned " + bLogError);
    	}
    	
		if (bLogError) {
			var errorObj = new Object();
			errorObj.location = location;
			errorObj.cause = cause;
			errorObj.message = message;
			this.errors[this.errors.length] = errorObj;
		}
	}
	function WriteErrorsToDocument() {
		var index;

		for (index=0; index < this.errors.length; index++) {
			var errorObj = this.errors[index];
			psDocument.WriteLn (errorObj.location + ":" + errorObj.cause + ":" + errorObj.message + "<BR>");
		}
	}
	function WriteErrorsToAlert() {
		var index;

		for (index=0; index < this.errors.length; index++) {
			var errorObj = this.errors[index];
			if (this.alertMessage.length > 0)
				this.alertMessage += "\r\n";
			this.alertMessage += errorObj.location + ":" + errorObj.cause + ":" + errorObj.message;
		}
	}

	// return true if we had an error.
	function TestCompError(location) {
	    var error = site.GetErrorInfo ();
	    if (error != "") {
	    	this.ReportError (location, "Component Call Failed", error);
	    }

	    return error != "";
	}
	
	
	// this is used to dump messages into the document if tracing is enabled
	function Trace(message) {
		// save message until body prologue
		if (this.doTrace) {
			var index;
			var leader = "";
			for (index = 0; index < this.traceIndent ; index++)
				leader += "   ";
			this.traceMessages[this.traceMessages.length] = leader + message;
		}
	}
	function TraceIndent() {
		if (this.doTrace)
			this.traceIndent++;
	}
	function TraceOutdent() {
		if (this.doTrace)
			this.traceIndent--;
	}
	function TraceWriteToDocument() {
		var index;

		if (this.traceMessages.length > 0) {
			psDocument.WriteLn("<PRE>");
			for (index=0; index < this.traceMessages.length; index++) {
				psDocument.WriteLn (psEscapeForTrace(this.traceMessages[index]));
			}
			psDocument.WriteLn("</PRE>");

			// restore variables
			this.traceMessages.length = 0;
			this.traceIndent = 0;
		}
	}
	function SetTrace(bTraceOn) {
		this.doTrace = bTraceOn;
	}

	// bind the input data to the server side objects
	function performInputBinding() {
		var controlName, control;

    	this.Trace("performInputBinding: start");
    	this.TraceIndent();
    	
		if (this.doTrace) {
			var inputVarName;
	    	this.Trace("Input Data:");
	    	this.TraceIndent();
	    	for (inputVarName in document.value) {
	    		this.Trace(inputVarName + " = '" + document.value[inputVarName] + "'");
	    	}
	    	this.TraceOutdent();
	    }

		// default is no action control
		this.actionControl = null;
		// get name of control who caused the action
		this.actionControlName = psDocument.GetParamEx("__ActionControlName");
    	this.Trace("control '" + this.actionControlName + "' caused action.");

    	this.Trace("Input binding phase...");
    	this.TraceIndent();

		// run BeforeBinding() event
    	if (this.checkForEvent("BeforeBinding")) {
    		this.TraceIndent();
    		this.BeforeBinding();
    		this.TraceOutdent();
    	}

		// for each control, ...
		for (controlName in this.controls) {
			control = this.controls[controlName];
	    	this.Trace("Binding '" + control.name + "'");
			// tell it to do binding 
			// BindToInput() will set this.actionControl, if appropriate
			this.TraceIndent();
			control.BindToInput(this);
			this.TraceOutdent();
		}

		// run Validate() event
		var bValid = true;
    	if (this.checkForEvent("Validate")) {
    		this.TraceIndent();
    		bValid = evtdef(this.Validate());
    		this.TraceOutdent();
	    	this.Trace("...returned " + bValid);
    	}

		// if not valid, run ValidationError() event
		if (! bValid || this.hadValidationError) {
	    	if (this.checkForEvent("ValidationError")) {
	    		this.TraceIndent();
	    		this.ValidationError();
	    		this.TraceOutdent();
	    	}
			this.hadValidationError = true;
		}

		// run AfterBinding() event
    	if (this.checkForEvent("AfterBinding")) {
    		this.TraceIndent();
    		this.AfterBinding();
    		this.TraceOutdent();
    	}
		this.TraceOutdent();

		// do action processing (but not if we had any validation errors!)
		if (this.actionControl != null && ! this.hadValidationError) {
	    	this.Trace("Action phase...");
	    	this.TraceIndent();

			var bContinue = true;
			// run BeforeAction() event
	    	if (this.checkForEvent("BeforeAction")) {
	    		this.TraceIndent();
	    		bContinue = evtdef(this.BeforeAction());
	    		this.TraceOutdent();
		    	this.Trace("...returned " + bContinue);
	    	}

			// check if action caused by control
			if (bContinue) {
				this.actionControl.PerformAction(this);
			} else {
		    	this.Trace("performInputBinding: Action skipped because BeforeAction returned false");	
			}

			// run AfterAction() event
			if (bContinue) {
		    	if (this.checkForEvent("AfterAction")) {
		    		this.TraceIndent();
		    		this.AfterAction();
		    		this.TraceOutdent();
		    	}
			}
			this.TraceOutdent();
		} else if (this.actionControl == null) {
	    	this.Trace("Action phase skipped because there is no action control");	
		} else {
	    	this.Trace("Action phase skipped because of validation error");	
		}
		
    	this.TraceOutdent();
	}

	function initialzeInternalPageVars() {
		this.hadValidationError = false;
		this.didRedirect = false;
		this.bDidGenerate = false;
		this.alertMessage = "";

		// restore errors
		this.errors.length = 0;
	}
	
	// internal methods
    this.performInputBinding = performInputBinding;
    this.initialzeInternalPageVars = initialzeInternalPageVars;
    
    // define methods
    this.RunServerEventModel = RunServerEventModel;
    this.GenerateBodyPrologue = GenerateBodyPrologue;
    this.GenerateBodyEpilogue = GenerateBodyEpilogue;
    this.EndOfPage = EndOfPage;
    this.Redirect = Redirect;
    this.ReportError = ReportError;
    this.WriteErrorsToDocument = WriteErrorsToDocument;
    this.WriteErrorsToAlert = WriteErrorsToAlert;
	this.Trace = Trace;
	this.TraceIndent = TraceIndent;
	this.TraceOutdent = TraceOutdent;
	this.TraceWriteToDocument = TraceWriteToDocument;
	this.SetTrace = SetTrace;
	this.TestCompError = TestCompError;
	this.Alert = Alert;
	
	// error properties
	this.errors = new Array();
	this.showErrorsOnPage = true;
	this.showErrorsAtTop = true;
	this.showErrorsInAlert = false;

	// trace properties
	this.doTrace = doTrace;
	this.traceMessages = new Array();
	this.traceIndent = 0;
	
	// internal variables
    this.bCreateObjectModel = true;
	this.actionControl = null;		// this is the control that caused action to occur
	this.actionControlName = "";
	this.bDidGenerate = false;
	this.alertMessage = "";
	this.destination = null;
	
    // external variables
    this.name = "psPage"; // this name is used by event system
    this.pageName = pageName;
    this.firstTime = true;
    this.variables = new Object();
    this.parameters = new Object();
    this.jaguarObjects = new Object();
    this.controls = new Object();
	this.hadValidationError = false;
	this.didRedirect = false;
	
    // define event holders
    // internal events
    this.__CreateObjectModel = null;
    this.__InitializeVariables = null;
    this.__SaveVariables = null;

    // external events
    this.RequestStart = null;
    this.FirstTime = null;
    this.BeforeBinding = null;
    this.Validate = null;
    this.ValidationError = null;
    this.AfterBinding = null;
    this.BeforeAction = null;
    this.AfterAction = null;
    this.BeforeGenerate = null;
    this.AfterGenerate = null;
    this.RequestFinish = null;
    this.ServerError = null;

    this.Trace("psServerPage: Created new page object for '" + this.pageName + "'");
}

var DYNAMIC_VALUE_CONSTANT = 1;		// argument is the value
var DYNAMIC_VALUE_PAGE_VAR = 2;		// argument is name of variable
var DYNAMIC_VALUE_SESSION_VAR = 3;	// argument is name of session var
var DYNAMIC_VALUE_CONTROL = 4;		// argument is name of the control
var DYNAMIC_VALUE_EXPRESSION = 5;	// argument is expression to evaluate

// dynamic values are used to allow a single value 
// to be dynamically evaluated when it is needed
// It also allows us to check if the value has changed since the last
// time we called GetValue().
class psDynamicValue(source, argument)
{
	function internalGetValue() {
		var result = null;
		if (this.source == DYNAMIC_VALUE_CONSTANT) {
			result = this.argument;
		} else if(this.source == DYNAMIC_VALUE_PAGE_VAR) {
			result = eval(this.argument);
		} else if(this.source == DYNAMIC_VALUE_SESSION_VAR) {
			result = psSession.GetValue(this.argument);
		} else if(this.source == DYNAMIC_VALUE_CONTROL) {
			result = eval(this.argument + ".value");
		} else if(this.source == DYNAMIC_VALUE_EXPRESSION) {
			result = eval(this.argument);
		}

		return result;
	}
	
	// returns the current value and saves that value so we
	// check if it changed.
	function GetValue() {
		this.lastValue = this.internalGetValue();
		return this.lastValue;
	}

	// if the value's don't match, then it has changed!
	function ValueChanged() {
		return this.lastValue != this.internalGetValue();
	}
	
	function toString() {
		return this.GetValue() + "";
	}

	this.internalGetValue = internalGetValue;
	this.GetValue = GetValue;
	this.ValueChanged = ValueChanged;
	this.toString = toString;

	this.source = source;
	this.argument = argument;

	var undefinedValue;
	this.lastValue = undefinedValue;
}

function psParam(name, value)
{
	return name + "=" + escape(value + "");
}

var LIFETIME_PAGE = 1;
var LIFETIME_SESSION = 2;

class PSJaguarObjectClass(variableName, lifetime, sessionVarName, serverName, userId, password, componentName, interfaceName)
{
	function evaluateValue(stringOrObject) {
		var result;
		if (typeof(stringOrObject) == "object")
			result = stringOrObject.GetValue();
		else
			result = stringOrObject;

		return result;
	}

	function replaceDoubleColon(inString) {
		var outString;

		var loc = inString.indexOf("::");
		if (loc != -1)
			outString = inString.substring(0, loc) + "/" + inString.substring(loc + 2, inString.length);
		else
			outString = inString;

		return outString;
	}

	function Initialize (page) {
		var componentObj = null;
		
		if (this.lifetime == LIFETIME_SESSION) {
			page.Trace(this.name + ".Initialize(Jag): Getting component out of session var '" + this.sessionVarName + "'");

			// try to get value out of session, (null returned otherwise)
			componentObj = psSession.GetValue(this.sessionVarName);
		}

		// if not found yet,...
		if (componentObj == null) {
			// create it
			componentObj = this.CreateComponent(page);
		}
		
		return componentObj;
	}

	function Save (page, value) {
		// only save session variables
		if (this.lifetime == LIFETIME_SESSION)
			psSession.SetValue(this.sessionVarName, value);
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -