Skip to content
Carl Philipp Sporon edited this page Jan 23, 2018 · 44 revisions

To implement dynamic content or to use function like a login or native smartphone functions, you can use the JavaScript Library. With the binding of the JavaScript file, you will be able to get access to several chayns® functions. This list contains basic chayns functions.

Table of Contents

All functions listed below are supported on Android, iOS and in the chaynsWeb, if not mentioned separately.


This method will show a login dialog where the user has the opportunity to log in. After a successful login, the tapp will perform a reload by default. Check our snippet for a solution without reloading.

Parameter

  • parameters : string[] - The parameters that will be passed to the chayns.env after logging in (use chayns.env.parameters).
chayns.login(["parameter=append"]);

This method returns user information for a specific user. You have to provide one of the parameters listed below.

Parameter

  • config : object - Has to contain one of the following parameters.
  • accessToken : string - Use chayns.env.user.tobitAccessToken.
  • userId : int - Use chayns.env.user.id.
  • fbId : string - Only works if logged in via facebook. Use chayns.env.user.facebookId.
  • personId : string - Use chayns.env.user.personId.

Result

  • FacebookID : string - The id of the users facebook profile. Chayns users will get an empty string at this point.
  • FirstName : string - The first name of the user.
  • LastName : string - The last name of the user.
  • PersonID : string - The personId of the user.
  • UserFullName : string - Returns the full name.
  • UserID : int - The userId of the user.
chayns.getUser({
  'userId': chayns.env.user.id
}).then(function(result) {
  console.log(result);
});

This method returns all custom UAC groups of a location in an array.

Parameter

  • siteId : string - Use chayns.env.site.id.
  • updateCache (optional) : boolean - If true, the cache will be cleared.

Result

  • groups : object[] - Contains all custom groups with the following properties.
  • id : int - The identifier of a group.
  • name : string - The internal name of a group.
  • showName : string - The public name of a group.
chayns.getUacGroups(chayns.env.site.id, false).then(function(result) {
  console.log(result);
});

Shows a progress bar that expires after a specified amount of time. It's timer resets on user interaction. After expiring, a callback will be executed.

Supported Platforms

Parameter

  • config : object - Containing the following parameters.
  • duration : int - Time in ms. The duration until expiration.
  • delay (optional) : int - Time in ms. Delay of the callback.
  • callback : function - Will be called on expiration.
  • resetOnInteraction (optional) : boolean - Default true. If false the timer won't reset.
  • foregroundColor : string - Hex value of the color of the progress bar.
  • backgroundColor (optional) : string - Default "#000". Hex value.
chayns.startInteractionIdentification({
  "duration": 10000,
  "foregroundColor": "#1abc9c",
  "backgroundColor": "#FFFFFF",
  "callback": chayns.dialog.alert(null, 'The timer was resetted')
});

Hides and disables the progress bar activated using chayns.startInteractionIdentification().

Supported Platforms

chayns.stopInteractionIdentification();

Enables pull down to refresh, if disabled using chayns.disallowRefreshScroll().

Supported Platforms

  • Android
  • iOS
chayns.allowRefreshScroll();

Disables pull down to refresh. Re-enable it using chayns.allowRefreshScroll().

Supported Platforms

  • Android
  • iOS
chayns.disallowRefreshScroll();

Shows the title image in Apps, if hidden using chayns.hideTitleImage().

Supported Platforms

  • Android
  • iOS
chayns.showTitleImage();

Hides the title image in Apps. Unhide it using chayns.showTitleImage().

Supported Platforms

  • Android
  • iOS
chayns.hideTitleImage();

This method will let you execute a callback, when the tapp gets displayed or hidden. It returns an int value that lets you specify the event.

Supported Platforms

  • Android
  • iOS

Parameter

  • callback : function - Will be executed if the tapp gets displayed or hidden.

Result

  • tappEvent : int - Values: Displayed(0), Hidden(1)
chayns.setOnActivateCallback(function(result) {
  if (result.retVal.tappEvent === chayns.tappEvent.ON_SHOW) {
    chayns.dialog.alert('', 'The Tapp is now displayed.');
  } else if (result.retVal.tappEvent === chayns.tappEvent.ON_HIDE) {
    chayns.dialog.alert('', 'The Tapp is no longer displayed.');
  }
});

This method allows you to watch the current network type and especially whether the user is connected to the internet. If ongoing is true, this will happen continuously. See chayns.networkType for the different result values.

Supported Platforms

  • Android
  • iOS

Parameter

  • callback : function - Will be executed if the tapp gets displayed or hidden.
  • ongoing : boolean - Will continuously return the network type and online status.

Result

  • isConnected : boolean - Values: Connected(1), Disconnected(0)
  • type : int - Values: No_Network(0), Network(1 to 17)
chayns.setNetworkChangeCallback(function(result) {
  if (result.isConnected === false) {
    chayns.dialog.alert('', 'There is no network connection!');
  }
}, true);

Sets a callback function, that will be called when a NFC device or card is getting in contact to the smartphone.

Supported Platforms

  • Android

Parameter

  • callback : function(result) - Will be executed on nfc detection. It returns the detected id.

Result

  • isConnected : boolean - Values: Connected(1), Disconnected(0)
  • type : int - Values: No_Network(0), Network(1 to 17)
chayns.setNfcCallback(function(result) {
  chayns.dialog.alert(result);
});

Removes the callback for NFC.

Supported Platforms

  • Android
chayns.removeNfcCallback();

This function actively scans for NFC Cards. It gives a callback every interval to show the actual status. So it is possible to get feedback about and how long the nfc device/card is on contact.

Supported Platforms

  • Android

Parameter

  • callback : function - The function that should be executed.
  • interval : int - Sets the interval for checking for NFC.
  • vibrate : boolean - Set to true if the device should vibrate on change.

Result

  • connected : boolean - Is NFCcard connected to your device
  • rfid : string - Rfid code with 14 digits
chayns.startNfcDetection(function(result) {
  chayns.dialog.alert(null, result);
}, 100, true);

This function stops the NFC detection

Supported Platforms

  • Android
chayns.stopNfcDetection();

This function activates the camera to scan a QR-Code. As result the QR-Code value will be returned in a promise.

Supported Platforms

  • Android
  • iOS

Parameter

  • cameraType (optional) : int - Define which camera to use. (0: default, 1: back, 2: front)
  • timeout (optional) : int - Timeout in seconds after which the QR scan will be canceled.
//Use frontcamera(type: 1), cancel after 60 seconds
chayns.scanQRCode(1, 60).then(function(result) {
  chayns.dialog.alert(null, result);
});

Creates a QR code from a string that, for example, contains an URL to your website. In the web version it returns the Url to the generated image and in the apps the result will be a base64 encoded string-image.

Parameter

  • text : string - The text to generate as qr code.
chayns.createQRCode('www.tobit.software').then(function(result) {
  chayns.dialog.alert(null, result);
});

Shows a QR code that represents the user account. In the web version the user will be forwarded to his account.

Supported Platforms

  • Android
  • iOS
chayns.showFinetradingQRCode();

App switches to another Tapp.

Parameter

  • tapp : object - The id, internalName, showName or position of the tapp to switch to.
  • parameter (optional) : string - Parameters that will be passed to the new tapp.
chayns.selectTapp({
  'showName': 'Welcome!'
}, "parameter=set");

Opens an URL in the chayns environment.

Parameter

  • config : object - Containing the following parameters.
  • url : string - The URL of the website.
  • title - (optional) : string - The title that will be showed on the top of the content of the Url.
  • exclusiveView - (optional) : boolean - View without bars.
  • darkenBackground - (optional/ only web) : boolean - Defines wether the background should be dark or not.
  • fullSize - (optional/ only web) : boolean - Defines wether the Url should be opened in an full size or not.
  • width - (optional/ only web) : number - Width of the opened window.
chayns.openUrl({
  url: 'https://en.tobit.software/chayns?tappId=1'
});

This method allows you to close an url that was opened by openUrl().

Supported Platforms

  • Android
  • iOS
chayns.closeUrl();

Opens a URL in the default browser.

Parameter

  • url : string - The url of the resource to open.
chayns.openUrlInBrowser('https://tobit.software/');

This method determines your location. If you want to track a route, just execute the function in intervals.

Result

  • longitude : double - The longitude of the current position.
  • latitude : double - The latitude of the crrent position.
chayns.getGeoLocation().then(function(result) {
  chayns.dialog.alert(null, JSON.stringify(result));
});

Returns an array that contains all beacons that are registered to the current location.

Supported Platforms

  • Android
  • iOS

Parameter

  • forceReload : string - If true, the beacons will be refreshed for every use of this function, otherwise they will be loaded from cache.

Result

  • id : int - The longitude of the current position.
  • pushMessage : string -
  • latitude : double - The latitude of the beacons position.
  • longitude : double - The longitude of the beacons position.
chayns.getLocationBeacons(true).then(function(result) {
  chayns.dialog.alert(null, JSON.stringify(result));
});

Returns the history of visited beacons in an array. If subNumber is set, this method returns beacons with the given subNumber only.

Supported Platforms

  • Android
  • iOS

Parameter

  • subNumber (optional) : int - SubNumber to get beacon history for specific beacons.

Result

  • id : int - The longitude of the current position.
  • timestamp : timestamp - The time the beacon was visited.
chayns.getBeaconHistory(6).then(function(result) {
  chayns.dialog.alert(null, JSON.stringify(result));
});

Returns the base color of the current chayns color scheme.

Parameter

  • color (optional) : string - Hex value. The color you want to get its chayns® base color of. (Default = current chayns color)
  • colorMode (optional) : int - Determines the color mode of which you want to get the color. (Default = 0)

Result

  • Color : string - The calculated color code.
console.log(chayns.getBaseColor('#12ff78', 0));

This method allows you to share an image or a text. SharingApps can be found in chayns.sharingApp or by using chayns.getAvailableSharingServices().

Supported Platforms

  • Android
  • iOS

Parameter

  • config : object - An object containing the following parameters.
  • title (optional) : string - Title of the message.
  • text : string - Message body.
  • imageUrl (optional) : string - Title of the message.
  • sharingApp : int - App to share. See chayns.sharingApp.
  • sharingAndroidApp (optional) : string - To share on specific application. Only for Android.
chayns.getAvailableSharingServices().then(function(result) { 
  chayns.share({
    title: 'Title',
    text: 'Text',
    imageUrl: 'https://chayns.tobit.com/storage/60038-22141/Images/icon-57.png',
    sharingApp: result.retVal.availableSharingApps[0]
  });
});

This method returns a list of installed share/social media apps.

Supported Platforms

  • Android
  • iOS

Result

  • availableSharingApps : int[] - An array containing internal ids for different sharing apps.
chayns.getAvailableSharingServices().then(function(result) {
  chayns.dialog.alert(null, JSON.stringify(result));
});

Sends an intercom message to the user that belongs to the ID.

Parameter

  • userId : string - The id of the user you want to contact.
  • object : object - Has to contain the property text.
  • text : string - The message you want to send.
chayns.intercom.sendMessageToUser(chayns.env.user.id, {
  text: 'Hi this is a message.'
}).then(function(data){            
   if(data.status == 200)
       chayns.dialog.alert('','thank you');
});

Sends an intercom message to the user that belongs to the ID.

Parameter

  • groupId : string - The id of a group of the current site.
  • object : object - Has to contain the property text.
  • text : string - The message you want to send.
chayns.intercom.sendMessageToGroup(1, text: { //groupId 1 = chayns manager
  'Hi this is a message.'
}).then(function(data){            
   if(data.status == 200)
       chayns.dialog.alert('','thank you');
});

Sends an intercom message to the staff of the page.

Parameter

  • object : object - Has to contain the property text.
  • text : string - The message you want to send.
chayns.intercom.sendMessageToPage({ 
            text: 'Hi this is a message.'
        }).then(function(data){            
            if(data.status == 200)
               chayns.dialog.alert('','thank you');
        });

This function navigates you to the previous site.

chayns.navigateBack();

This method allows you to update the navigation menu. If new Tapps were added, they will appear in the menu. If tappId is set, you may also switch to a specific Tapp after the refresh.

Parameter

  • tappId - (optional) : int - Switches to the given Tapp after refreshing the navigation.
  • config - (optional) : object - Contains the following parameters.
  • stateOnly - (optional) : boolean - Only refreshs special tapps. Default: false
  • updateTapp - (optional) : boolean - If false this method wont refresh the site after updating the navigation. Default: true.
chayns.updateNavigation(1, {
  'stateOnly': false, 
  'updateTapp': true 
});

Re-enables the display timeout, so it will turn off after the system display timeout is reached. (If you have used chayns.disableDisplayTimeout() before)

Supported Platforms

  • Android
  • iOS
chayns.enableDisplayTimeout()

Disables the display timeout and keeps the display active. Re-enable it using chayns.enableDisplayTimeout().

Supported Platforms

  • Android
  • iOS
chayns.disableDisplayTimeout()

Starts the voice-recognition. Returns the spoken language and a list of recognized sentences or words.

Supported Platforms

  • Android

Parameter

  • title (optional) : string - Title for the speech-to-text dialog.
  • callback : function - Returns the spoken language and a list of recognized sentences or words.

Result

  • languageCode : string - The language code of the recognized words.
  • string[]: text - The recognized words/text.
chayns.setSpeechToText('', function(result) {
 chayns.dialog.alert('', 'Did you say: ' + result.text[0] + ' ?');
});

Creates a shortcut for the Tapp on the home screen.

Supported Platforms

  • Android
  • iOS

Parameter

  • name : string - Name for the shortcut.
  • imageUrl : string - URL for an image as shortcut icon.
chayns.createTappShortcut('Tapp-Name', 'https://chayns.tobit.com/storage/60038-22141/Images/icon-57.png');

Creates and updates a new, temporary Tapp.

Parameter

  • config : object - Containg the following parameters.

  • tappID : int - ID for the new sub tapp

  • name : string - Name for Title

  • color : string - Color for the navigation

  • colorText - (optional) : string - Colortext for the navigation

  • sortID : int - To sort the Tapp on a specific place on the navigation. -1 sorts the Tapp to first position

  • icon : string - Use FontAwesome or FontTS as icon. Reference: http://fortawesome.github.io/Font-Awesome/3.2.1/icons/

  • callbackURL - (optional) : function(result) - After startup it will be checked, if the Tapp should be shown. If no callbackURL is added, the Tapp will removed on the next start

  • url : string - URL of the Tapp

  • buttonName : string - Name for the navigation button

  • isExclusiveView - (optional) : boolean - True for exclusive view. Default: false

  • replaceParent - (optional) : boolean - If this value is true, the executing Tapp will be replaced. After removing the sub Tapp, it will be shown again

  • boldText - (optional) : boolean - To show the navigation text in bold

chayns.setSubTapp({
 'tappID': 76543,
 'url': 'http://developers.chayns.net/FrontendSnippets',
 'name': 'Snippets-Subtapp',
 'color': '#ffff00',
 'sortID': 8989,
 'icon': 'fa-plus',
 'buttonName': 'Button',
 'replaceParent': true
});

Removes a sub Tapp with specified id.

Parameter

  • config : object - Contains the following parameters.
  • tappID : int - The id of the subtapp you want to close or remove.
  • close : boolean - Set to true to close the subtapp.
  • remove : boolean - Set to true to remove the subtapp.
chayns.removeSubTapp({
 'tappID': 76543,
 'close': true,
 'remove': true
});

This method lets a snmartphone vibrate for the given time.

Supported Platforms

  • Android
  • iOS

Parameter

  • ms : int[] - Vibration duration in ms. Default is 150ms. If you provide more than one value, the device will stop vibrating for a moment before each interval.
chayns.vibrate([1000, 100, 1000]);

Function to set the height of the iframe.

Supported Platforms

  • ChaynsWeb

Parameter

  • config : object - Containing the following parameters.
  • height : int - Sets the height of the iframe.
  • growOnly (optional) : boolean - If true, the iframe wont shrink if the content gets less.
  • full (optional) : boolean - Overriding height with the mx height.
  • fullViewport (optional) : boolean - Sets dynamic height.
chayns.setHeight({
  'height': 500,
  'growOnly': false
});

This method allows you to scroll vertically to a specific position in a tapp.

Supported Platforms

  • ChaynsWeb

Parameter

  • position : int - Y-position to scroll to
chayns.scrollToY(200);

Adds a passbook to the iOS wallet.

Supported Platforms

  • iOS

Parameter

  • passbook : file - A .pkpass file. For how to generate a .pkpass file, take a look at this page.
chayns.addToWallet('url-to-the-.pkpass');

Shows all passbooks installed for the app.

Supported Platforms

  • iOS
chayns.passKit.getInstalled().then(function(result) {
 chayns.dialog.alert('Passbooks', JSON.stringify(result));
});

Checks if a specific passbook is installed.

Supported Platforms

  • iOS

Parameter

  • identifier: string - Passbook identifier.
chayns.passKit.isInstalled(identifier).then(function(result) {
 chayns.dialog.alert('Passbooks', JSON.stringify(result));
});

Adds a listener for scroll event by user.

Supported Platforms

  • ChaynsWeb

Parameter

  • callback : function - The function that will get executed on scroll.
  • throttle (Optional) : int - Event will be fired all (default 200) ms only.
chayns.addScrollListener(function(data) {
 console.log(JSON.stringify(data));
});

Sets the orientation of the screen.

Supported Platforms

  • Android
  • iOS

Parameter

  • orientation : int - Default: 0, Portrait: 1, Landscape: 2
chayns.setScreenOrientation(2)

This method allows you to search for chayns sites by name. It will return an array containing site objects.

Parameter

  • name : string - The name or a part of the name of the site you are looking for.
  • skip (optional) : int - Skips the specified number of the first results.
  • take (otpional) : int - The max number of results you want to get.

Result

  • appstoreName : string - The name of the site.
  • facebookId : string - The id of the facebook site the chayns site belongs to.
  • siteId : string - The identifier of the chayns site.
  • locationId : int - Another identifier of the chayns site.
chayns.findSite('Tobit.Software', 0, 5).then(function(data) {
 console.log(data);
});