📄 sforce.js
字号:
); return; } var ds = this.SControlDS; ds.fetchData( {Name:name}, function (dsResponse, data) { // name / code available due to JS closure behavior isc.SForce.installSControl(name, code, data, ds); } ); }, // installSControl() // Uses standard dataSource APIs to add or modify an SControl based on the code passed in installSControl : function (name, code, sControls, sControlDS) { // Code passed in is raw JS - wrap in HTML header/ footer var html = this.getSControlHTML(code); if (sControls.length > 0) { sControlDS.updateData({ Id : sControls[0].Id, HTMLWrapper : html }); } else { sControlDS.addData({ Name : name, HTMLWrapper : html }); } }, // getSControlHTML() // Helper method to convert arbitrary Javascript code to SmartClient-enabled HTML getSControlHTML : function (code) { if (this.htmlPrefix == null) { var dir = this.controlIsomorphicDir; this.htmlPrefix = [ "<HTML>\r<BODY>\r<SCRIPT>window.isomorphicDir = '", dir, "'</SCRIPT>\r", "<SCRIPT src='", dir, "system/modules/ISC_Core.js'></SCRIPT>\r", "<SCRIPT src='", dir, "system/modules/ISC_Foundation.js'></SCRIPT>\r", "<SCRIPT src='", dir, "system/modules/ISC_Containers.js'></SCRIPT>\r", "<SCRIPT src='", dir, "system/modules/ISC_Grids.js'></SCRIPT>\r", "<SCRIPT src='", dir, "system/modules/ISC_Forms.js'></SCRIPT>\r", "<SCRIPT src='", dir, "system/modules/ISC_DataBinding.js'></SCRIPT>\r", "<SCRIPT src='", dir, "system/modules/ISC_SalesForce.js'></SCRIPT>\r", "<SCRIPT src='", dir, "system/modules/ISC_Kapow.js'></SCRIPT>\r", "<SCRIPT src='", dir, "skins/", this.controlSkin, "/load_skin.js'></SCRIPT>\r", "<SCRIPT>\r", ' var service = isc.WebService.get("urn:partner.soap.sforce.com");\r', ' service.sessionId = "{!User_Session_ID}";\r', ' service.dataURL = "{!API_Partner_Server_URL_60}";\r\r' ].join(""); } return this.htmlPrefix + code + '</SCRIPT>\r</BODY></HTML>'; } });// use a custom ResultSet subclass to hold onto sForce's queryLocator, which is required when// making paged requests isc.defineClass("SFResultSet", "ResultSet");isc.SFResultSet.addMethods({ transformData : function (newData, dsResponse) { // place the queryLocator into the context to cause it to be sent with the next // dsRequest this.context = this.context || {}; this.context.queryLocator = dsResponse.queryLocator; }, setCriteria : function (newCriteria) { var changed = this.Super("setCriteria", arguments); if (changed) { //this.logWarn("criteria changed"); this.context = this.context || {}; this.context.queryLocator = null; } }});isc.defineClass("SFDataSource", "DataSource");isc.SFDataSource.addMethods({ serviceNamespace : "urn:partner.soap.sforce.com", operationBindings : [ { operationType:"fetch", wsOperation:"query", recordXPath: "//schema:records" }, { operationType:"fetch", operationId:"queryMore", wsOperation:"queryMore", recordXPath: "//schema:records" }, { operationType:"update", wsOperation:"update", recordName: "SaveResult" }, { operationType:"add", wsOperation:"create", recordName: "SaveResult" }, { operationType:"remove", wsOperation:"delete", recordName: "DeleteResult" } ], resultSetClass : "SFResultSet", transformRequest : function (dsRequest) { var data = dsRequest.data; if (!isc.isAn.Array(data)) data = [data]; // for removal, SForce wants only the ids of the objects, whereas because we support // multicolumn primary keys, we normally send an object per deleted object if (dsRequest.operationType == "remove") { return { ids : data.getProperty("Id") }; } if (dsRequest.operationType != "fetch") { // SForce allows multiple objects of different types to be saved at once and // expects "type" on each data.setProperty("type", this.sfName || this.ID); return { sObjects : data }; } // handling query vs queryMore: if (dsRequest.queryLocator) { // causes the "queryMore" operation to be used instead of "query" dsRequest.operationId = "queryMore"; // pass the locator returned with the original "query" message in lieue of a query // string return { queryLocator : dsRequest.queryLocator }; } // fetch operation: form SForce SOQL query string var criteria = dsRequest.data, queryString = "select " + this.getFieldNames().join(",") + " " + "from " + (this.sfName || this.ID); if (criteria != null && !isc.isAn.emptyObject(criteria)) { queryString += " where "; for (var fieldName in criteria) { queryString += fieldName + "='" + criteria[fieldName] + "' "; } } return { queryString : queryString }; }, transformResponse : function (dsResponse, dsRequest, xmlData) { var operationType = dsRequest.operationType; if (operationType != "fetch") { // check for failure on saves and set appropriate status code var success = xmlData.selectString("//default:success"); if (success != "true") { dsResponse.errors = this.convertValidationErrors(xmlData); this.logWarn("save failed, errors are: " + this.echo(dsResponse.errors)); dsResponse.status = -1; return dsResponse; } //this.logWarn("original response data: " + this.echoAll(dsResponse.data)); // NOTE: supporting singular add/update/remove only for now if (operationType != "remove") { // for add/update, since SForce backend doesn't send back updated data, use the // request data (NOTE this assumes no server formatting and no important // server-added values!) var updateData = isc.addProperties({}, dsRequest.oldValues, dsRequest.data.sObjects[0]); // on an "add", pick up the id returned by the SForce backend if (operationType == "add") { updateData.Id = dsResponse.data[0].id; } dsResponse.data = updateData; } else { // for remove, turn the returned id into a PK object // NOTE: deletion results aren't sObject typed; they return the deleted id as // the element "id" instead of "Id" as all SObjects use. var id = dsResponse.data[0].id; dsResponse.data = { Id : id }; this.logWarn("cache sync data on remove: " + this.echo(dsResponse.data)); } return dsResponse; } // paging: queryLocator is needed for 2nd+ requests with same criteria var queryLocator = xmlData.selectString("//default:queryLocator"); if (queryLocator != null && !isc.isAn.emptyString(queryLocator)) { dsResponse.queryLocator = queryLocator; } // size = total number of records dsResponse.totalRows = xmlData.selectNumber("//default:size"); // workaround: there seems to be a bonus ID element returned with entities //this.logWarn("removing duplicate Id field"); var data = dsResponse.data; for (var i = 0; i < data.length; i++) { if (isc.isAn.Array(data[i].Id)) data[i].Id = data[i].Id[0]; } return dsResponse; }, // log in automatically when data is first fetched if autoLogin:true is set autoLogin : true, fetchData : function (criteria, callback, requestProperties, loggedIn) { var ds = this; if (this.autoLogin && !loggedIn) { isc.SForce.ensureLoggedIn(function () { ds.fetchData(criteria, callback, requestProperties, true); }); return; } return this.Super("fetchData", arguments); }, convertValidationErrors : function (xmlData) { var errors = xmlData.selectNodes("//default:errors"), iscErrors = {}; for (var i = 0; i < errors.length; i++) { // convert each <errors> element to JS var error = errors[i]; error = isc.xml.toJS(error); // transform to ISC error format ( { field : message } ) iscErrors[error.fields] = error.message; } return iscErrors; }});}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -