The first block is shown to all users all the time. The next 2 blocks are only shown if the logged in user is from the IT department or an Admin respectively.
This all depends on what data is set against each user in the data source. In this example I have the following details set but it can obviously be anything specific to your app.
The following JS is need to show the elements based on the logged in users data:
Fliplet.User.getCachedSession().then(function (session) {
var user = _.get(session, 'entries.dataSource.data');
if (!user) {
return; // user is not logged in
}
if (user.Department === 'IT'){
$('.fl-widget-instance.IT-user').attr('style','display: block !important');
}
if (user.Admin === 'Yes'){
$('.fl-widget-instance.admin-user').attr('style','display: block !important');
}
});
My previous post was for list item style menu. That one is a little simpler to use. This following example is for Metro style grids. Showing/hiding this is a little more complex due to the dynamic sizing nature of this metro menu type. In order to achieve you will need the following:
First add all the metro grids to your screen as separate components intended for different groups of logged in users. Then wrap each metro grid in a div whose class name you can set relevant to what is being hidden for e.g. in my case there are 3 separate grids aimed for different departments.
//this will make the div's above invisible on load
.IT, .HR, .Marketing{
opacity: 0;
}
//this will ensure that all grids are visible in edit mode in Fliplet Studio.
.mode-interact .IT, .mode-interact .HR, .mode-interact .Marketing{
opacity: 1;
}
Then in the page JS you need to write IF statement’s as above to both set the desired div to visible and hide all the others.
Fliplet.User.getCachedSession().then(function(session) {
var user = _.get(session, 'entries.dataSource.data');
if (user.Department === 'IT') {
//show IT menu
$('.IT').css('opacity', 1);
//hide all others
$('.admin').hide();
$('.HR').hide();
$('.Marketing').hide();
}
if (user.Department === 'HR') {
//show HR menu
$('.HR').css('opacity', 1);
//hide all others
$('.admin').hide();
$('.IT').hide();
$('.Marketing').hide();
}
if (user.Department === 'Marketing') {
//show marketing menu
$('.Marketing').css('opacity', 1);
//hide all others
$('.admin').hide();
$('.IT').hide();
$('.HR').hide();
}
});