Laravel Backpack redirect delete operation to list view - laravel-backpack

I want to customize the delete operation such that whenever you delete an item, it goes back to the items list screen.
I have tried following; that I believed must work:
public function destroy($id)
{
$this->crud->hasAccessOrFail('delete');
$this->crud->delete($id);
return redirect('/admin/students');
}
But it gives 405 methods not allowed error. Does anyone have a better suggestion on how to achieve it?

Related

object to fluid.form on other page

Im trying to redirect from a list of entries to the edit page for these entries when an link.action is clicked.
I can't seem to get the values from the objects using the 'property' tag once I redirect to the editing page.
The action 'edit' is not getting executed on the page I redirect to. Instead it fires the standard action which is just listing all the entries.
public function toEditAction(Personenliste $person) {
$this->redirect('edit', 'Listen', 'testprivateext', ['personenliste' => $person], 43);
}
public function editAction(Personenliste $person) {
$this->view->assign('personenliste',$person);
return $this->htmlResponse();
}
The call is done via link.action. (I also tried directly redirecting the action with the 'pageUid'-tag)
<f:link.action action="toEdit" arguments="{person:'{person}'}" extensionName="testprivateext" controller="Listen" pluginName="pi1">&#128393</f:link.action>
This is not an answer to your question (because you already solved it), but a little info for more readable inline-fluid.
This:
arguments="{person:'{person}'}"
can be written:
arguments="{person: person}"
when you directly pass a variable, you can discard the quotes and curly braces.
but you will need it, when passing a VH:
arguments="{person:'{person -> f:format.raw()}'}"
Have a nice day :)

Can you delete google sheet row on http.post() method?

I make an http .put() call from FLutter app, to put my data on google sheet. I could not really implement .delete() method to delete row, so now trying to delete still using put method. When "delete" button is pressed I am changing all values of variables to "deleted" and changing value of "quantity" to the item which I want to delete and passing all this to google script with get(). ( I know...very hard coded :), trying to get it done anyway :D) So in my Google Scripts I'm putting condition:
code ex
function doPost(request){
var sheet = SpreadsheetApp.openById("1AVouGZs3U2I4xM941sKWqgfJzyiUgP8-1lTI4gTX4tg");
var name = request.parameter.name;
var product = request.parameter.product;
var quantity = request.parameter.quantity;
if (name != "delete") {
try{
sheet.appendRow([name, product, quantity]);
}
}
if (name == "delete" ) {
try{
sheet.deleteRow(quantity); // quantity indicates index of item that needs to be deleted
}
Is it mandatory to use http.delete() method or is there any mistake in my code? P.S.: Just a beginner!
Apps script restricts you to get or post – that's why the only available functions for receiving HTTP requests are doGet() and doPost(). You cannot use any of the other HTTP methods like delete, put, or patch.
You also have several errors in your code:
You can't have a try without a catch. Apps script shouldn't even allow you to save that.
The .deleteRow() method expects a row number, not a quantity. If you want to delete multiple rows, then use the .deleteRows(rowPosition, howMany) method.

odoo12 how to show success message without break

everybody, please help
in odoo, i know that the error message showing was use raise UserError(), but this function will break the function and rollback in database, what i want to do is just simplely show the successful message to user without break, like operation was successful!.
of course, i have try to use the wizard, but the footer is not working, the page always show the save and discard
appreciate if anybody can help me on this.
thanks.
In that, you can use the onchange API to work around this,
#api.onchange('my_field')
def my_field_change(self):
// warning message
return {
'warning': {'title': _('Error'), 'message': _('Error message'),},
}
With that, Perform the change with your case return the warning message and it does not break the process.You can find a similar behavior on Odoo Sale App on sale order line product change operation.
Thanks

Validation / Error Messages in ASP.Net MVC 2 View Unrelated to a Property

What pattern can I use to display errors on an MVC 2 view that are not related to a single property?
For example, when I call a web service to process form data, the web service may return an error or throw an exception. I would like to display a user-friendly version of that error, but have no logical means to relate the error to any given property of the model.
UPDATE:
Trying to use this code as suggested, but no summary message is displayed:
MyPage.spark:
Html.ValidationSummary(false, "Oopps it didn't work.");
Controller:
ViewData.ModelState.AddModelError("_FORM", "My custom error message.");
// Also tried this: ViewData.ModelState.AddModelError(string.Empty, "My custom error message.");
return View();
UPDATE 2
What does this mean?
next to each field.
Instead of always displaying all
validation errors, the
Html.ValidationSummary helper method
has a new option to display only
model-level errors. This enables
model-level errors to be displayed in
the validation summary and
field-specific errors to be displayed
next to each field.
Source: http://www.asp.net/learn/whitepapers/what-is-new-in-aspnet-mvc#_TOC3_14
Specifically, how does one add a model level error (as opposed to a field-specific error) to the model?
UPDATE 3:
I noticed this morning that Html.ValidationSummary is not displaying any errors at all, not even property errors. Trying to sort out why.
Simply adding a custom error to the ModelState object in conjunction with the ValidationSummary() extension method should do the trick. I use something like "_FORM" for the key... just so it won't conflict with any fields.
As far as patterns go, I have it setup so that my Business Logic Layer (called via services from the controller) will throw a custom exception if anything expected goes wrong that I want to display on the view. This custom exception contains a Dictionary<string, string> property that has any errors that I should add to ModelState.
HTHs,
Charles

MVC 2 partial for edit/create return error

I got a question about MVC 2 and returning views for partials:
I got two views for creating and editing a user, the views both uses a partial so i can reuse the form fields.
UserPartial.ascx, EditUser.aspx, CreateUser.aspx
I got some logic in the controller post method (EditCreateUser) which finds out if its a new or existing user which is beeing submitted and this works fine.
The problem is when I try to return the edited user: return View(user). MVC complains about EditCreateUser file not existing. But thats only the method name, i want to return the object to the EditUser view which I am already on.
I could use RedirectToAction but i rather not because this problem would occur also if i want to return the same object when some errors has occured.
Any ideas on how to do this or some pointers in the right direction would be awesome.
Thanks
Within an action method named EditCreateUser, the statement return View(user) will by default look for a view with the same name as the action. You need return View("EditUser", user)