Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
updated component documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Akhilesh Gupta committed May 18, 2015
1 parent 4bded03 commit 547df23
Show file tree
Hide file tree
Showing 16 changed files with 607 additions and 167 deletions.
1 change: 1 addition & 0 deletions elements/force-signin/force-signin.html
Expand Up @@ -124,6 +124,7 @@
*
* @attribute userInfo
* @type Object
* @readOnly
*/
userInfo: {
type: Object,
Expand Down
28 changes: 14 additions & 14 deletions elements/force-sobject-collection/force-sobject-collection.html
@@ -1,21 +1,21 @@
<!--
force-sobject-collection element wraps the SmartSync Force.SObjectCollection into a polymer element.
Why: a) Auto manages the offline store for caching.
b) Provides a simple DOM based interface to interact with Smartsync.
c) Allows other polymer elements to easily comsume smartsync.
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
This code may only be used under the BSD style license found at https://github.com/ForceDotComLabs/mobile-ui-elements/LICENSE
-->

<!--
force-sobject-collection element provides a custom component for Force.SObjectCollection from Mobile SDK's SmartSync JS. It allows apps to easily fetch a list of records from a salesforce sobject in both online & offline modes. For Offline use, the application should first create a Smartstore soup with same name as the target sobject.
To use this component, specify the sobject name and the query for fetching data.
@attributes:
sobject: (Required) Type of sobject on which you want to render a list
query: (Optional) SOQL/SOSL/SmartSQL statement to fetch the records. Required when querytype is soql, sosl or cache.
querytype: (Optional) Default: mru. Type of query (mru, soql, sosl, cache). Required if query attribute is specified.
autosync: (Optional) Default: true. Auto synchronize (fetch/save) changes to the model with the remote server/local store. If false, use fetch/save methods to commit changes to server or local store.
maxsize: (Optional) Default: -1. If positive, limits the maximum number of records fetched.
Example:
@methods:
fetch: Initiates the fetching of records from the relevant data store (server/offline store).
reset: Replaces all the existing contents of the collection and initiates autosync if enabled.
<force-sobject-collection sobject="Account" query="Select id, name from Account" querytype="soql" autosync></force-sobject-collection>
@events:
@group Salesforce Mobile Elements
@element force-sobject-collection
@events:
reset: when the collection's entire contents have been replaced.
sync: when the collection has been successfully synced with the server
error: when a request to remote server has failed.
Expand Down
64 changes: 59 additions & 5 deletions elements/force-sobject-collection/force-sobject-collection.js
Expand Up @@ -3,24 +3,59 @@
"use strict";

var viewProps = {

/**
* (Required) Name of Salesforce sobject against which fetch operations will be performed.
*
* @attribute sobject
* @type String
*/
sobject: String,

/**
* (Optional) SOQL/SOSL/SmartSQL statement to fetch the records. Required when querytype is soql, sosl or cache.
*
* @attribute query
* @type String
* @default null
*/
query: {
type: String,
value: null
},

/**
* (Optional) Type of query (mru, soql, sosl, cache). Required if query attribute is specified.
*
* @attribute querytype
* @type String
* @default mru
*/
querytype: {
type: String,
value: "mru"
},

/**
* (Optional) Auto synchronize (fetch/save) changes to the model with the remote server/local store. If false, use fetch/save methods to commit changes to server or local store.
*
* @attribute autosync
* @type Boolean
* @default false
*/
autosync: Boolean,

/**
* (Optional) If positive, limits the maximum number of records fetched.
*
* @attribute maxsize
* @type Number
* @default -1
*/
maxsize: {
type: Number,
value: -1
},
autosync: {
type: Boolean,
value: true
}
/* async: false */ // Optional property to perform fetch as a web worker operation. Useful for data priming.
};

var generateConfig = function(props) {
Expand Down Expand Up @@ -52,6 +87,13 @@
Polymer({
is: 'force-sobject-collection',
properties: _.extend({

/**
* Returns an instance of Force.SObjectCollection containing the list of records fetched by the query.
*
* @attribute collection
* @type Object
*/
collection: {
type: Object,
value: function() {
Expand All @@ -67,11 +109,23 @@
observers: [
"reset(sobject, query, querytype)"
],

/**
* Replaces all the existing contents of the collection and initiates autosync if enabled.
*
* @method reset
*/
reset: function() {
this.collection.config = generateConfig(_.pick(this, _.keys(viewProps)));
this.collection.reset();
if (this.autosync) this.fetch();
},

/**
* Initiates the fetching of records from the relevant data store (server/offline store).
*
* @method fetch
*/
fetch: function() {

var onFetch = function() {
Expand Down
29 changes: 16 additions & 13 deletions elements/force-sobject-layout/force-sobject-layout.html
@@ -1,19 +1,22 @@
<!--
force-sobject-layout element provides the layout information for a particular sobject record.
Why: a) Wraps the describeLayout API call.
b) Layout information is cached in memory for existing session and stored in smartstore for offline consumption.
c) Provides a base definition for elements that depend on page layouts, such as force-ui-detail and force-sobject-related.
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
This code may only be used under the BSD style license found at https://github.com/ForceDotComLabs/mobile-ui-elements/LICENSE
-->

<!--
force-sobject-layout web component provides the layout information for a particular sobject type or record. Layout information is cached in memory for existing session and is also stored in smartstore if used with Mobile SDK. `force-ui-detail` and `force-sobject-related` use this web component to obtain layout information.
To use this component just specify the sobject name.
Example:
@attributes:
sobject: (Required) Type of sobject on which you want to fetch the layout
hasrecordtypes: (Optional) Default: false. If false, the element returns the default layout. Set true if the sobject has recordtypes or if you are unsure. If set to true, "recordid" or "recordtypeid" must be provided.
recordtypeid: (Optional) Default: null. Id of the record type for which layout has to be fetched. Required if "hasrecordtypes" is true and "recordid" is not provided.
recordid: (Optional) Default: null. Id of the record for which layout has to be fetched. Required if "hasrecordtypes" is true and "recordtypeid" is not provided.
<force-sobject-layout sobject="Account"></force-sobject-layout>
@methods:
whenDetailSections: Initiate the fetching of layout's detail view sections data from the relevant data store (server/offline store). Returns a promise, when complete, returns an array of all detail sections.
whenEditSections: Initiate the fetching of layout's edit view sections data from the relevant data store (server/offline store). Returns a promise, when complete, returns an array of all edit sections.
whenRelatedLists: Initiate the fetching of layout's related lists data from the relevant data store (server/offline store). Returns a promise, when complete, returns an array of all related list infos.
@group Salesforce Mobile Elements
@element force-sobject-layout
@events:
layout-change:
-->
<link rel="import" href="../../dependencies/polymer/polymer.html">
<link rel="import" href="../force-app/force-app.html">
Expand Down
45 changes: 45 additions & 0 deletions elements/force-sobject-layout/force-sobject-layout.js
Expand Up @@ -44,19 +44,58 @@
Polymer({
is: 'force-sobject-layout',
properties: {

/**
* (Required) Name of Salesforce sobject for which layout info will be fetched.
*
* @attribute sobject
* @type String
*/
sobject: String,

/**
* (Optional) If false, the element returns the default layout. Set true if the sobject has recordtypes or if you are unsure. If set to true, "recordid" or "recordtypeid" must be provided.
*
* @attribute hasrecordtypes
* @type Boolean
* @default false
*/
hasrecordtypes: {
type: Boolean,
value: false
},

/**
* (Optional) Id of the record type for which layout has to be fetched. Required if "hasrecordtypes" is true and "recordid" is not provided.
*
* @attribute recordtypeid
* @type String
* @default null
*/
recordtypeid: {
type: String,
value: null
},

/**
* (Optional) Id of the record for which layout has to be fetched. Required if "hasrecordtypes" is true and "recordtypeid" is not provided.
*
* @attribute recordid
* @type String
* @default null
*/
recordid: {
type: String,
value: null
},

/**
* Returns an object with the complete layout information.
*
* @attribute fields
* @type Object
* @readOnly
*/
layout: {
type: Object,
readOnly: true,
Expand All @@ -73,6 +112,12 @@
this.debounce("fetch-layout", this.fetch.bind(this));
}
},

/**
* Method to manually initiate the fetching of layout information.
*
* @method fetch
*/
fetch: function() {
if (this.layout && !this.hasrecordtypes) return;
if (this.sobject && typeof this.sobject === 'string') {
Expand Down
28 changes: 13 additions & 15 deletions elements/force-sobject-store/force-sobject-store.html
@@ -1,23 +1,21 @@
<!--
force-sobject-store element wraps the SmartSync Force.StoreCache into a polymer element.
Why: a) Auto manages the lifecycle of the smartstore soup for each sobject type.
b) Auto creates index spec based on the lookup relationships on the sobject.
c) Provides a simpler DOM based interface to interact with Smartsync SObject Model.
d) Allows other polymer elements to easily comsume smartstore.
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
This code may only be used under the BSD style license found at https://github.com/ForceDotComLabs/mobile-ui-elements/LICENSE
-->

<!--
force-sobject-store element provides a custom component for Force.StoreCache from Mobile SDK's SmartSync JS. It allows an app to quickly create and manage Smartstore soup for a salesforce sobject.
@attributes:
sobject: (Required) Type of sobject that you would like to store in this cache.
fieldstoindex: (Optional) Addition fields (given by their name) that you want to have indexes on.
To use this component just specify the sobject name.
@properties:
cacheReady: Returns a promise to track store cache creation progress.
cache: Returns an instance of Force.StoreCache when it's ready to store/retrieve data.
cacheForOriginals: Returns an instance of Force.StoreCache to be used to keep data copy for conflict resolution.
Example:
@methods:
destroy: Removes the soup from smartstore. Returns a promise to track the completion of process.
<force-sobject-store sobject="Account"></force-sobject-store>
@events:
@group Salesforce Mobile Elements
@element force-sobject-store
@events:
store-ready: Fires this event when the store cache has been successfully created and ready to use.
store-destroy: Fires this event when the store cache has been successfully removed.
-->
Expand Down
24 changes: 24 additions & 0 deletions elements/force-sobject-store/force-sobject-store.js
Expand Up @@ -71,7 +71,23 @@
Polymer({
is: 'force-sobject-store',
properties: {

/**
* (Required) Type of sobject that you would like to store in this cache.
*
* @attribute sobject
* @type String
*/
sobject: String,

/**
* (Optional) Addition fields (given by their name) that you want to have indexes on.
* Provide a space delimited list. Also the field names are case sensitive.
*
* @attribute fieldstoindex
* @type String
* @default null
*/
fieldstoindex: {
type: String, /*TBD: Should switch to array */
value: null
Expand All @@ -80,14 +96,17 @@
observers: [
"init(sobject, fieldstoindex)"
],
// cacheReady: Returns a promise to track store cache creation progress.
/* TBD: Evaluate moving to computed properties */
get cacheReady() {
return this.init();
},
// cache: Returns an instance of Force.StoreCache when it's ready to store/retrieve data.
get cache() {
var cache = sobjectStores[processName(this.sobject)];
if (cache instanceof Force.StoreCache) return cache;
},
// cacheForOriginals: Returns an instance of Force.StoreCache to be used to keep data copy for conflict resolution.
get cacheForOriginals() {
var cache = originalSObjectStores[processName(this.sobject)];
if (cache instanceof Force.StoreCache) return cache;
Expand All @@ -110,6 +129,11 @@
});
}
},
/**
* Removes the soup from smartstore. Returns a promise to track the completion of process.
*
* @method destroy
*/
destroy: function() {
var cacheDestroy, cacheForOriginalsDestroy;
var that = this;
Expand Down
29 changes: 14 additions & 15 deletions elements/force-sobject/force-sobject.html
@@ -1,22 +1,21 @@
<!--
force-sobject element wraps the SmartSync Force.SObject into a polymer element.
Why: a) Auto manages the offline store for caching.
b) Provides a simpler DOM based interface to interact with Smartsync SObject Model.
c) Allows other polymer elements to easily comsume smartsync.
Copyright (c) 2015, salesforce.com, inc. All rights reserved.
This code may only be used under the BSD style license found at https://github.com/ForceDotComLabs/mobile-ui-elements/LICENSE
-->

<!--
force-sobject element provides a custom component for Force.SObject from Mobile SDK's SmartSync JS. It allows apps to easily perform CRUD operations against a salesforce sobject in both online & offline modes. For Offline use, the application should first create a Smartstore soup with same name as the target sobject.
To use this component, specify the sobject name and the recordid.
@attributes:
sobject: (Required) Type of sobject on which you want to fetch the record
recordid: (Required) Id of the record that needs to be fetched.
fieldlist: (Optional) Default: All fields. List of field names that need to be fetched for the record.
autosync: (Optional) Default: true. Auto synchronize (fetch/save) changes to the model with the remote server/local store. If false, use fetch/save methods to commit changes to server or local store. (TBD: autosync not working for "save" operations)
mergemode: (Optional) Default: "Overwrite". The merge model to use when saving record changes to salesforce.
Example:
@methods:
fetch: Initiate the fetching of record data from the relevant data store (server/offline store).
save: Initiate the saving of record data to the relevant data store (server/offline store).
destroy: Initiate the deleting of record data from the relevant data store (server/offline store).
<force-sobject sobject="Account" recordid="0010000000AAA" autosync></force-sobject>
@events:
@group Salesforce Mobile Elements
@element force-sobject
@events:
save: when the data has been successfully saved to the server.
sync: when the data has been successfully synced with the server.
destroy: when a record is deleted.
Expand Down

0 comments on commit 547df23

Please sign in to comment.