📄 sforce.js
字号:
/*
* Isomorphic SmartClient
* Version 6.5 (2008-04-30)
* Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
* "SmartClient" is a trademark of Isomorphic Software, Inc.
*
* licensing@smartclient.com
*
* http://smartclient.com/license
*/
//> @class SForce// WebService object representing the SForce (aka AppForce) web service.//// @visibility sforce//<isc.SForce = isc.WebService.get("urn:partner.soap.sforce.com");if (isc.SForce) {isc.SForce.addMethods({ getHeaderData : function (dsRequest) { var headerData = {}; if (dsRequest.operationType == "fetch") headerData.QueryOptions = { batchSize : 75 }; if (this.sessionId != null) headerData.SessionHeader = { sessionId:this.sessionId }; return headerData; }, //> @classMethod SForce.login() // Log in to SForce service. // @param userName (String) username to use // @param password (String) password to use // @param callback (Callback) callback to fire on completion. Recieves the loginData block // returned by the SForce service, as an Object, or boolean // false if login failed // @visibility sforce //< login : function (userName, password, callback) { this.callOperation("login", { username: userName, password: password }, "//default:result", { target : this, methodName : "loginReply" }, { willHandleError:true, _loginCallback:callback, showPrompt:true, prompt:"Logging into SalesForce.." }); }, loginReply : function (data, xmlDoc, rpcResponse, wsRequest) { if (rpcResponse.status < 0) { return this.fireCallback(wsRequest._loginCallback, "loginData", [false]); } var loginData = data[0]; this.logDebug("login data: " + this.echo(loginData)); // change the URL to point to the dynamically returned server URL this.dataURL = loginData.serverUrl; // store the sessionId on the service - this causes all operations invoked through this // web service to send a sessionId header this.sessionId = loginData.sessionId; this.logInfo("got sessionID: " + this.sessionId); this.fireCallback(wsRequest._loginCallback, "loginData", [loginData]); }, ensureLoggedIn : function (callback, dismissable) { // NOTE: doesn't handle session timeout if (this.sessionId) return this.fireCallback(callback); var service = this; isc.showLoginDialog(function (credentials, dialogCallback) { if (credentials == null) return; // dismissed service.login(credentials.username, credentials.password, function (loginData) { dialogCallback(loginData); if (loginData) isc.Class.fireCallback(callback); }) }, { title:"Please log in to SalesForce", dismissable:dismissable}); }, //> @classMethod SForce.getEntityList() // Get the list of SForce entities accessible to currently logged in user. // @param callback (Callback) callback to fire on completion. Receives the list of // entities as an Array of Strings as the variable "list" // @visibility sforce //< getEntityList : function (callback) { this._describeGlobalCallback = callback; this.callOperation("describeGlobal", null, "//default:types", { target : this, methodName : "describeGlobalReply" }); }, describeGlobalReply : function (data) { // NOTE: this callback exists only to rename "data" to the more specific "list" this.fireCallback(this._describeGlobalCallback, "list", [data]); }, //> @classMethod SForce.getEntity() // Get a DataSource describing an SForce Object type (SObject). The returned DataSource is // capable of all DataSource operations (fetch, add, update, remove). // // @param callback (Callback) callback to fire on completion. Receives the DataSource // derived as the variable "schema" // @visibility sforce //< getEntity : function (objectType, callback) { var service = this; this.callOperation("describeSObjects", { sObjectType : objectType }, null, function (data) { service.describeObjectReply(data, objectType, callback); }); }, describeObjectReply : function (data, objectType, callback) { var sfSchema = data.result, sfFields = sfSchema.fields; var ds = this.convertSchema(sfSchema, objectType); if (this.logIsDebugEnabled()) { this.logDebug("converted schema: " + this.echoAll(ds.getFields())); } ds.sfFields = sfSchema.fields; this.fireCallback(callback, "schema", [ds]); }, // convert SalesForce schema (which is returned in a custom format that doesn't match XML // Schema) to SmartClient DataSources detailFields : [ "Id", "Type", "ParentId", "LastModifiedDate", "LastModifiedById", "LastActivityDate", "CreatedDate", "CreatedById" ], hiddenFields : [ "SystemModstamp" ], convertSchema : function (sfSchema, ID) { var sfFields = sfSchema.fields, dsFields = []; // top level: // - childRelationships // - childSObject // - field // - cascadeDelete: boolean // - createable, custom, deleteable, activateable : boolean for (var i = 0; i < sfFields.length; i++) { var sfField = sfFields[i], dsField = {}; // custom, createable, defaultedOnCreate, filterable, dsField.name = sfField.name; if (this.detailFields.contains(dsField.name)) dsField.detail = true; if (this.hiddenFields.contains(dsField.name)) dsField.hidden = true; // type, soapType // type is sforce type, a mix of derived types (currency, url) and // editor types (picklist, textArea). // type:date and datetime exist, both mapping to soap dateTime var type = sfField.soapType; if (type.contains(":")) type = type.substring(type.indexOf(":") + 1); dsField.type = type; dsField.title = sfField.label; dsField.canEdit = sfField.updateable; if (sfField.type == "id") dsField.primaryKey = true; // bytelength? consistently 3x length for user-visible text, same as length for ids // length/byteLength is sent as 0 for numeric types if (sfField.length != 0) dsField.length = sfField.length; // digits, precision, scale // currency has precision 18 // pickListValues -> valueMap // restrictedPicklist dsFields.add(dsField); }/* <childRelationships> <cascadeDelete>false</cascadeDelete> <childSObject>Account</childSObject> <field>ParentId</field> </childRelationships>*/ var relations = sfSchema.childRelationships, childRelations = []; if (relations) { for (var i = 0; i < relations.length; i++) { var sfRelation = relations[i]; childRelations.add({ dsName : sfRelation.childSObject, fieldName : sfRelation.field }); } } //this.logWarn(isc.Comm.serialize(sfSchema, true)); return isc.SFDataSource.create({ sfName:sfSchema.name, ID:ID, childRelations : childRelations, fields : dsFields }); }, //> @classMethod SForce.deploySControl() // Create and deploy an SForce Object (SObject) from the javascript code passed in. // @param name (string) Name for the SForce object to be created // @param code (string) Javascript code to create the control object. // // @visibility sforce //< deploySControl : function (name, code) { // If necessary get the SObject dataSource (asynchronous), and re-run this method if (this.SControlDS == null) { this.getEntity( "SControl", function (ds) { isc.SForce.SControlDS = ds; isc.SForce.deploySControl(name, code); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -