RhoConnect.js API is implemented as public fields of a global RhoConnect object. Those are methods and ERRORS hash.
If you have properties in the class, list and define them here.
Returns a jQuery promise object.
Authenticates the RhoConnect application on the server. On success, the done handler is called. On failure, the fail handler is called with the following arguments:
errCode
- The error code value from RhoConnect.ERRORS.errorMessage
- More detailed error message if available.The syntax and parameters are as follows.
RhoConnect.login(username, password, doDataReset)
username |
The user name to authenticate with. |
password |
The password to authenticate with. |
doDataReset |
(optional) Boolean. If true, do a database reset before login. Default value is false. |
function loginRhoConnect(username, password) { persistence.store.rhoconnect.config(persistence); return $.Deferred(function(dfr){ // login with username, password, and a DB reset RhoConnect.login(username, password, new RhoConnect.SyncNotification(), true /*do db init*/).done(function(){ // Init DB for the user on success initRhoconnect(username, false).done(function(){ dfr.resolve(); }).fail(function(errCode, err){ alert('DB init error: ' +errCode); dfr.reject(errCode, err); }); }).fail(function(errCode, err){ //alert('RhoConnect login error: ' +errCode); dfr.reject(errCode, err); }); }).promise(); }
Performs rhoconnect.js and data API initialization.
Returns a jQuery promise object. On success, the done handler is called. On failure, the fail handler is called with the following arguments:
errCode
- The error code value from RhoConnect.ERRORS.errorMessage
- More detailed error message if available.The syntax and parameters are as follows.
RhoConnect.init(modelDefinitions, dataApiType, syncProgressCallback)
modelDefinitions |
Model definitions array. See Getting Started for a sample. | ||||||||||||
dataApiType |
(optional) - A string value: 'extjs', 'persistencejs', or 'custom' or null. 'extjs' - Do initialize ExtJS/SenchaTouch data API to use as application data storage. 'persistencejs' - Do initialize Persistence.js data API to use as application data storage. 'custom' or null - Don't initialize any data API, perform data API initialization in custom code. |
||||||||||||
syncProgressCallback |
(optional) Progress update callback function to use. Receives the argument notificationBody, which is a hash with the following fields.
|
// RhoConnect.js initialization function initRhoconnect(username, doReset) { return RhoConnect.init(modelDefinitions, 'persistencejs', doReset); }
modelDefinitions is a hash, such as:
var modelDefinitions = [ { name: 'User', fields: [ {name: 'username', type: 'string'}, {name: 'email', type: 'string'}, {name: 'first_name', type: 'string'}, {name: 'last_name', type: 'string'}, {name: 'title', type: 'string'}, {name: 'company', type: 'string'}, {name: 'created_at', type: 'string'}, {name: 'updated_at', type: 'string'} ] }, //...
Disconnects the RhoConnect application from the server.
Returns a jQuery promise object. On success, the done handler is called. On failure, the fail handler is called with the following arguments:
errCode
- The error code value from RhoConnect.ERRORS.errorMessage
- More detailed error message if available.The syntax is as follows.
RhoConnect.logout()
Returns true if the application is logged in on the server.
RhoConnect.isLoggedIn()
Synchronizes that application data with the RhoConnect server.
Returns a jQuery promise object. On success, the done handler is called. On failure, the fail handler is called with the following arguments:
errCode
- The error code value from RhoConnect.ERRORS.errorMessage
- More detailed error message if available.The syntax is as follows.
RhoConnect.syncAllSources()
function sync(){ RhoConnect.syncAllSources().done(function(){ alert('sync successful'); }).fail(function(errCode, err){ alert('Data sync error: ' +errCode); }); }
Returns the hash of data access objects which are data API specific. The returned hash contains:
key
- model name.value
- An instance of one of the following objects.The syntax is as follows.
RhoConnect.dataAccessObjects()
function pull_data(model) { // passed a model name, returns hash of data access objects. var store = RhoConnect.dataAccessObjects()[model]; current_model = model; persistence.loadFromRhoConnect(function() { storeLoaded(); });
Set the handler for the exact model synchronization notification.
RhoConnect.setModelNotification(modelName, callback, removeAfterFire)
modelName |
Name of the model to listen for notifications. | ||||||||||||
callback |
Handler function. Receives the only argument of notificationBody, which is a hash with the following fields.
|
||||||||||||
removeAfterFire |
Clear notification subscription after notification event if true. The same if handler function returns true. |
Resets the handler for the model synchronization notification.
RhoConnect.clearModelNotification(modelName)
modelName |
Name of the model to reset the handler. |
Sets the handler for all models synchronization notifications.
RhoConnect.setAllNotification(callback, removeAfterFire)
callback |
Handler function. Receives the only argument of notificationBody, which is a hash with the following fields.
|
||||||||
removeAfterFire |
Clear notification subscription after notification event if true. The same if handler function returns true. |
Reset handler for all models synchronization notifications.
RhoConnect.clearAllNotification()
Set handler for all object change notifications.
RhoConnect.setObjectsNotification(callback, removeAfterFire)
callback |
Handler function. Receives the only argument of notificationBody, which is a hash with fields.
|
||||||
removeAfterFire |
Clear notification subscription after notification event if true. The same if handler function returns true. |
Reset the handler for all object change notifications.
RhoConnect.clearObjectsNotification()
Subscribe an object for changes notification.
RhoConnect.addObjectNotify(modelName, objectId)
modelName |
The name of the object model. |
objectId |
The id of the object. |
Unsubscribe all objects from changes notification.
RhoConnect.clearObjectsNotify()
RhoConnect.ERRORS are defined as: