Trying to add notifications to a crud operation in list view - laravel-backpack

I'm trying to add some notifications to the delete operation on one of my cruds, basically to inform the admin that while successful, the model has some lingering relationships that they may want to remove/deal with.
I've tried adding \Alert::add('warning', 'The text of the notification')->flash(); into the delete operation (and this does show up if the page is then refreshed) but isn't shown in the same way the "Item deleted successfully" one is.
The only option I can see is to not use $this->crud->delete($id); and build out all the functionality there on my own.

I also had a similar situation to you. What I did is, First I have written my condition in destroy function I have created if and in else conditions in if my conditional logic and in else "$this->crud->delete($id)". In my code, if the condition is not met then I have simply return a boolean('true|false') in the form of a string and catch that as result in "resources/views/vendor/backpack/crud/buttons/delete.blade.php" and make your custom notification in if condition.

Related

I'm wanting to create a separate file of every member who joins the server and then be able to chose them randomly for a 'winner' command sorta thing

So I am using discord.js or Visual studio code or whatever. and I've made a random hug command. And I would like to be able to have it so that the one that gets hugged doesn't get # and it's just their name. I've successfully made a command similar to it, but i don't want to have to keep adding in names manually and theres no promise that the member won't change their name so it's not very reliable.
So I guess what's in my mind is having a file that automatically updates with users leaving or joining or changing their names and then to be able to call on them randomly without #ing them.
So does anybody know how to do this and how i can call on them?
I've done it with the #, and now im at where I manually write in every member's name but I know that is going to end up tedious and their name might change and I don't want to have to worry about them changing their name.
case 'randhug':
var user = message.guild.members.random();
let dismember = ["Klemon", "Second sofira", "CloudBot"]
let disresults = Math.floor((Math.random() * dismember.length));
message.channel.send(`${message.author} SURPRISE huggies you, ${dismember[disresults]}!!!!!`);
if (message.author.bot) return;
break;
The code I have now works, but isn't reliable in the sense that things change.
It sounds like you might find the tag or username properties of a User very valuable in this situation.
User.tag would return Username#1234.
User.username would return Username.
const member = message.guild.members.random();
message.channel.send(`${message.author} surprise huggies you, **${member.user.username}**!`)
.catch(console.error);

Automatically send email about editing google spreadsheet

I'm working on a rather simple script which should handle new values in the spreadsheet and then send emails to specified addresses. And I faced with the problem. My code is listed below:
function onEdit(e) {
//part of the code for checking e.range to process only updated values
sendEmail();
}
function sendEmail() {
// arguments are missed only for demo
GmailApp.sendEmail();
}
While I'm using "simple trigger", my function "sendEmail()" works only if I start it from script editor. I allowed sending emails on behalf of my at first time and then function works fine. But if I'm changing the value in the spreadsheet - function "onEdit(e)" processes new data but function "sendEmail()" does nothing.
I partly solved this problem by using project's triggers from "current project's triggers" menu. In that case, function "sendEmail()" works properly, but I have no access to the information about update.
For my purposes I could use just second way and find new values "manually" every time, but I wish to optimize this work.
So, my questions are:
Is the process I described above proper or I made a mistake
anywhere?
If process proper, is where a way to combine both cases?
Thanks!
You correctly understood that (as the docs say) simple triggers cannot send an email, because they run without authorization. An installable trigger, created via Resources menu, can: it has the same rights as the user who created the trigger. If it is set to fire on edit, it will get the same type of event object as a simple trigger does.
So, a minimal example would be like this, set to run "on edit":
function sendMail(e) {
MailApp.sendEmail('user#gmail.com', 'sheet edited', JSON.stringify(e));
}
It emails the whole event object in JSON format.
Aside: if your script only needs to send email but not read it, use MailApp instead of GmailApp to keep the scope of permissions more narrow.

Grails: Radio button doesn't populate command obj when not selected

When I submit my form, if I do not select a value for my radio box then nothing is sent over to my command object for validation. I don't have issues with textFields or other input types.
class ApplicationCommand implements Validateable {
Map<String,String[]> questions = new LinkedHashMap<String,String[]>();
static constraints = {
questions validator: {val, obj, errors ->
for(String key : val.keySet()) {
errors.rejectValue("questions[${key}]",'required');
}
}
}
}
<g:radioGroup name="cmd.questions[1]" values="['Yes']" labels="['Yes']">
${it.radio}${it.label}
</g:radioGroup>
<g:textField name="cmd.questions[2]" />
With the above example, If i leave both fields empty and I submit I get the following
qusetions = [2: String[0]]
What I expect to see is
questions = [1: String[0], 2: String[0]]
Due to this issue, in my questions validator since key=1 is not populated I cannot validate it. The questions are dynamic all pulled from a DB so I cant hard-code anything in the validator such as if !questions.contains(1). Whatever data is populated into questions upon submission is what I have to assume the data is.
I have found 2 work-arounds, neither of which I like
1) Only for radio buttons, add a hidden field that will force a value to be populated if a radio is not selected. Horribly ugly
<g:hiddenField name="cmd.questions[1]" value="-" />
2) In my validator, I query the DB for all my questions and manually check for the existence of each one in the questions map. I want to avoid DB queries in my validators.
So while my 2 work-around options do work, I don't feel like I should have to resort to them.
I don't think this is a limitation of command objects or Grails; I think it's a limitation of HTML. I see the same question popping up in PHP.
The essential problem is that your command object doesn't know how many questions there are, but is responsible for making sure they are all there. I can think of a couple of (additional) ways to deal with this limitation:
The quick and easy way would be to put a single hidden input with the number of questions into your form. Also ugly, and open to alteration by the end-user.
The other option is to promote questions into a Domain so that the number of questions is known ahead of time, and is made available to your command object via a field or method. Then your command object can ask your questions, "How many are there supposed to be? Okay, did I get that many from the view?" This is similar to your #2 but without having to retrieve an entire collection and iterate it. This also opens up a path to perform further validation on each question (e.g., don't allow text into a numbers-only answer).
This does require hitting the DB, but it's the only way I can think of to validate the number of questions without relying on input from the view. The nice thing is that you can make it a very shallow hit, and hitting the DB can be very quick if you do it properly.

Alfresco: How to see the data of a finished task in the next task?

I need pass data of a task1 (form of task1) to other task (form of task2), and see this data in the form of task2. I use one aspect for this and I have the next code (a part) for the taskListener (event: complete) in task1:
execution.setVariable('wf_data1', task.getVariable('wf_data1'));
In my task2, in the share-config-custom.xml, I have the wf_data1 in the form, but this shows empty.
Why happen this? How to see the wf_data1 in task2?
UPDATE:
The reason of why this not working is which in the file service-context.xml, the redeploy key is "false". I changed this to "true" and all is working.
Greetings,
Arak.
I'm not going to dive into your model and ways of showing it. Alfresco keeps track of the workflow history. I'm not sure till what detail(with/without aspects) is available, but it's quite easy to find out.
With this you can access workflow data in a next task. Just create a custom workflow form controller which retrieves data.

Refresh or Clear GUI (Apps Script Gadget Embedded in Google Site)

I have a small form that my colleagues and I often fill out that can be seen here, with source code (view-only) here. The spreadsheet that this form posts to can be seen (view-only) here.
Basically, the apps script is solely for preventing my coworkers from having to scroll through thousands of rows of a spreadsheet (this is also used for our film collection) to check in/out inventory. It will also, soon, post detailed history of the checkout in an audit spreadsheet.
I have attempted, with no success, to clear the values of the text fields after the data has been posted to the spreadsheet. What I essentially want to do is restart the GUI so that the fields are once again blank.
I have tried accessing the text fields by id but the return type is a Generic widget, which I of course can't do anything with. And since control is passed to the handler functions, the text fields can't be accessed, or at least I can't figure out how (and I looked through the documentation and online solutions for hours last night).
So the question: how can I erase/clear the values of the text fields in the GUI after values have been posted to the spreadsheet? (return from handler function to access text fields again, or restart the GUI?
I can accomplish restarting the script runs on a spreadsheet, but I have not been able to do this when it is embedded in a Google site.
The getElementById('xxxxx').setText('') approach was the right way to do it. but the way you tried to test it doesn't work... the new value would only be available in the next handler call.
/*
This function only has the desired effect if it is called within the handler
function (not within a nested function in the handler function).
*/
function restartGUI() {
var gui = UiApp.getActiveApplication();
gui.getElementById('equipmentIDField1').setText('');
gui.getElementById('equipmentIDField2').setText('');
gui.getElementById('equipmentIDField3').setText('');
gui.getElementById('studentLastNameField').setText('');
gui.getElementById('labasstLastNameField').setText('');
return gui;
}