Hello Everyone,
I have buttons on repeater which shows only to the user who created it. Code works just fine. Now I would like to show these buttons for admin (Myself) so even I can modify the content without accessing the Database. Could anyone please help?
Here below is the working code to show buttons only to item owner.
$w("#repeater9").onItemReady(($item, itemData, index) => {
if (itemData._owner === wixUsers.currentUser.id) {
$item('#vectorImage4').show();
$item('#vectorImage3').show();
} else {
$item('#vectorImage4').collapse();
$item('#vectorImage3').collapse();
}
});
Thanks in advance 
Could anyone help please?
When you add a console-log on the following line…
$w("#repeater9").onItemReady(($item,itemData,index)=>{
console.log("Item-Data: ", itemData);
//....
//...
…what do you get as RESULTS ???
Another question, do you work with DATASET ?
Did you code the rest of your setupt ?
Did you use PROPERTY-PANEL ?
Where is the wix-users-API-import → not shown in your code! Did you show your whole related code?
Why do you use the old and depricated USERS-API ???
Why you do not use the new one → MEMBERS-API ?
Hi Here is my entire code on my page.
Yes I work with Data set.
Yes I used property panel.
The code was written by someone else and I did few modification to the code to suit my requirement.
I have imported wix users in another part in the same page. The code is very lengthy I am not able to copy everything here.
import wixUsers from 'wix-users';
I tried to write below code but it does not work. I am not sure how to write async as I am still beginner.
Everything works now. Only owner can delete and edit the comment. It would be better if admin has to access to this functionality.
let roleName = ‘’
wixUser.currentUser.getRoles()
.then( (roles) => {
let firstRole = roles[0];
roleName = firstRole.name;
} );
if (itemData._owner === wixUsers.currentUser.id || roleName == ‘Admin’) {…}
import wixData from 'wix-data';
import FilterWords from 'bad-words';
import wixWindow from 'wix-window';
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
import wixUsers from 'wix-users';
let filterWords = new FilterWords();
$w.onReady(() => {
$w('#checkbox1').checked = false
if ($w('#checkbox1').checked === true) {
$w('#button16').enable();
} else $w('#button16').disable();
$w('#dynamicDataset').onReady(() => {
let currentItem = $w('#dynamicDataset').getCurrentItem()
if (currentItem.commentsDisabled) {
//handle what happens if comments is disabled. For example you can collapse the input
$w('#addCommentButton').disable()
$w('#addCommentButton').label = "RSVP Closed";
$w('#textBox1').disable()
$w('#textBox2').disable()
$w('#textBox3').disable()
$w('#textBox4').disable()
$w('#columnStrip24').collapse()
$w('#text253').text = ""
$w('#text252').text = ""
$w('#text245').text = "RSVP Closed"
$w('#text246').text = "RSVP Closed"
$w('#text251').text = "The required flock size has been met, hence RSVP is closed for this travel flock."
$w('#image6').show()
$w("#errorText").text = "Comments disabled"
$w("#errorText").show()
console.log("disabled")
}
})
$w("#repeater9").onItemReady (($item, itemData, index) => {
if (itemData._owner === wixUsers.currentUser.id) {
$item('#vectorImage4').show();
$item('#vectorImage3').show();
} else {
$item('#vectorImage4').collapse();
$item('#vectorImage3').collapse();
}
$item('#vectorImage3').onClick((event) => {
$item('#vectorImage3').collapse();
$item('#vectorImage4').collapse();
$item('#thankssmiley').collapse();
$item('#group71').expand();
});
$item('#button28').onClick((event) => {
$item('#vectorImage3').expand();
$item('#vectorImage4').expand();
$item("#thankssmiley").expand()
setTimeout(() => {
$item("#thankssmiley").collapse()
}, 5000);
$item('#group71').collapse();
});
$item('#deletebutton').onClick((event) => {
$item('#deleteloader').expand();
$item('#group71').collapse();
let id = itemData._id;
wixData.remove("comments", id)
.then(() => {
setTimeout(function () {
let totalCount = $w("#dataset1").getTotalCount();
$w('#text250').text = totalCount.toString() + " TRAVELERS JOINED"
$w("#dynamicDataset").setFieldValue("rsvpCount", totalCount)
$w('#dynamicDataset').setFieldValue("repeaterStatus", "OPEN TO JOIN");
$w('#dynamicDataset').save();
}, 2000);
console.log("OPEN TO JOIN")
$w('#dataset1').refresh();
});
});
$item("#vectorImage4").onClick((event) => {
const repeaterItem = itemData;
wixWindow.openLightbox("Join Flock Now 1", {
"_id": itemData._id,
"excitement": $item("#text255").text,
"other": repeaterItem
})
.then((data) => {
//REFRESH THE DATASET WHEN LIGHTBOX CLOSES
$w('#dataset1').refresh()
$w('#dynamicDataset').refresh()
if (data._id) {
scrollToUpdatedItem(data._id)
}
})
})
});
})
export function checkbox1_click_1(event) {
if ($w('#checkbox1').checked === true) {
$w('#button16').enable();
} else $w('#button16').disable();
}
Since you use the old wix-users-API, try this one…
import wixUsers from ‘wix-users’ ;
$w.onReady(function() {
let currentUser = wixUsers.currentUser;
console.log("Current-User: ", currentUser);
let userRole = wixUsers.currentUser.role;
console.log("User-Role: ", userRole);
});
To make sure that it runs asynchronous…(but don’t think it is neccessary in this case…
$w.onReady(async function() {
let currentUser = await wixUsers.currentUser;
console.log("Current-User: ", currentUser);
let userRole = await wixUsers.currentUser.role;
console.log("User-Role: ", userRole);
});
You normaly should get some results inside of console-logs.
…something like…
Once you got the role of the current user ----> continue with your own code…
I followed your instructions. Now the admin and owner can delete or edit the comments. Thank you very much for your support.