I am using an asset listing to list all the users in a group. I have a link to go to the _edit page. But i also want a link that will delete the user if it is clicked.
Is this possible?
Yes, this is possible. The trigger system in 3.12 supports conditions based off the url, so you can supply something like 'delete=yes' and use the create link trigger action to move the asset to a trash folder (it won't move it to the trash itself, but you can mimick the behaviour). I have implemented this using an ajax interface before and it seems to work quite well.
Although, of course, you will want to introduce conditions that detect if the user has write/admin permission before the trigger action will fire.
If anyone is interested in how I ended up doing this I will show you. It all seems to be working for me.
I setup a trigger as Anthony described.
In the asset listing put the following (on a div that only admins have permission to)
[quote]<a href="java script:deleteAsset('%asset_assetid%', '%asset_name%')">Delete</a>[/quote]
Then added the following javascript
[quote]function deleteAsset(assetid, assetname)
{
var refurl = unescape(window.location.pathname)
if(confirm('Are you sure you want to delete'+assetname+'?')==true)
{
this.location.href = '?a='+assetid+'&delete=yes';
this.location.href = refurl;
}
}[/quote]
Does anyone see this causing any problems?
What event would be used for this trigger?
You use the "Asset Accessed" event for this.
function deleteAsset(assetid, assetname)
{
var refurl = unescape(window.location.pathname)
if(confirm('Are you sure you want to delete'+assetname+'?')==true)
{
this.location.href = '?a='+assetid+'&delete=yes';
this.location.href = refurl;
}
}I am having trouble with the javascript not working when there is an apostrophe (') in the asset name that is being deleted. Is there a way around this?
On another issue, make sure your trigger has a condition for admin access, so the trigger will only fire if the current user has admin access to the user you are trying to delete. Otherwise, anyone can craft a URL to delete any user in the system.
Thanks Greg. I did have a write permission condition, but I changed that to be admin permission like you said.
You could just change it so it does not use the asset name in the javascript at all. All that is used for is to display to the user which asset is about to be removed.
Or try
Delete
note that javascript needs to be one word, not sure why this forum changes it.
For security. :) It's so that a user can't put javascript into a post and have it fire for forum readers.
Thanks guys! :)
Yip it works like a charm. The asset URL pattern trigger is a real winner in 3.14.
I agree! The only frustration I have now is I am using this javascript and trigger on some calendar pages, and when you perform the delete action, it works, but then takes me back the current months calendar page, rather than the date that I was doing the deletion on.
E.g.: on /events-all?SQ_CALENDAR_VIEW=month&SQ_CALENDAR_DATE=2007-09-01 when deleting, but after I delete the asset, it takes me back to /events-all , but I want to stay on the /events-all?SQ_CALENDAR_VIEW=month&SQ_CALENDAR_DATE=2007-09-01 page!
Try adding SQ_CALENDAR_VIEW and SQ_CALENDAR_DATE to your delete URL.
Just in case this one comes up again, you don't need to use location.href to call the assetid/url
/*
Sends the string delete=yes to the asset specified by assetid in matrix
Trigger system should be configured to look for this string and process a create
link action that unlinks the asset from it's current parent, and into a new location
*/
function deleteAsset(assetid) {
try {
request = new XMLHttpRequest();
} catch(e) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP")
} catch(e) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
request = false;
}// End try
}// End try
}// End try
request.open("GET","./?a=" + assetid + "&delete=yes&rand=" + parseInt(Math.random()*99999999999999),true);
request.onreadystatechange = function() {
if ( request.readystate = 4 ) {
// alert('ResponseText: ' + request.responseText);
// alert('Assetid #' + assetid + ' has been deleted');
}
}
request.send(null);
}Some simple http request trickery can fire off the request, without the browser actually loading the page.
[quote]Just in case this one comes up again, you don't need to use location.href to call the assetid/url
/*
Sends the string delete=yes to the asset specified by assetid in matrix
Trigger system should be configured to look for this string and process a create
link action that unlinks the asset from it's current parent, and into a new location
*/
function deleteAsset(assetid) {
try {
request = new XMLHttpRequest();
} catch(e) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP")
} catch(e) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
request = false;
}// End try
}// End try
}// End try
request.open("GET","./?a=" + assetid + "&delete=yes&rand=" + parseInt(Math.random()*99999999999999),true);
request.onreadystatechange = function() {
if ( request.readystate = 4 ) {
// alert('ResponseText: ' + request.responseText);
// alert('Assetid #' + assetid + ' has been deleted');
}
}
request.send(null);
}Some simple http request trickery can fire off the request, without the browser actually loading the page.[/quote]
Anthony, this is working well, only problem is that there is no indication that the asset has been deleted until the page is refreshed (which is what we were trying to avoid here). Is there a way to have the asset (in an asset listing) be removed from the list, without a page reload? Also, I am getting no alert dialog...
How about a way to use XMLHttpRequest to reload an asset listing without reloading the page? Is this possible?