Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete modal #251

Closed
asivaneswaran opened this issue Nov 19, 2013 · 20 comments
Closed

Delete modal #251

asivaneswaran opened this issue Nov 19, 2013 · 20 comments

Comments

@asivaneswaran
Copy link

Hi,

The delete modal seems to be not working.

Everytime I try to delete a role, the popup closes when I click the button but it doesn't delete anything... it's just like if the redirect via post never happens...

Thanks,
Ara

@pascal08
Copy link

Hi,

I can confirm this issue. All given solutions in #178 are not solving this issue.

Pascal

@xhezairbey
Copy link

Truth is, combining the proposed workarounds from issue #178 does actually work.
See the changes and additions here https://gist.github.com/xhezairi/7550419, which is what currently works flawlessly.

@pascal08
Copy link

@xhezairi

Thanks for your response. I tried your fix but I still have the same problem: the modal is closing before the post-action could complete.

    $('.close_popup').click(function(){
      parent.oTable.fnReloadAjax();
      parent.jQuery.fn.colorbox.close();
      return false;
    });
    $('#deleteForm').submit(function(event) {
      var form = $(this);
      $.ajax({
        type: form.attr('method'),
        url: form.attr('action'),
        data: form.serialize()
      }).done(function() {
        parent.jQuery.colorbox.close();
        parent.oTable.fnReloadAjax();
      }).fail(function() {

      });
      event.preventDefault();
    });

I think that the problem is that two events are fired at the same time when clicking the delete button. The .close_popup event is obviously executed faster than the deleteForm AJAX-request and therefore the AJAX-request will never be sumbitted.

@xhezairbey
Copy link

@pascal08 Did you update your delete.blade.php?

See I ditched the close_popup class from Delete button, and in addition to that I've also put the respective action.
With the above jQuery snippet, the deletion and closing the modal is being done through AJAX, therefore you need to provide the form action value for it to go through.

@pascal08
Copy link

@xhezairi

Oh, my bad. I forgot to delete the close-popup class from the delete button. Now it's working fine. Thanks a lot for your help! Much appreciated.

@asivaneswaran
Copy link
Author

It doesn't work for me...

This is my delete.blade.php:

@extends('admin.layouts.modal')

 {{-- Content --}}
 @section('content')

{{-- Delete Dish Form --}}
<form id="deleteForm" class="form-horizontal" method="post" action="@if (isset($dish)){{ URL::to('admin/dishes/' . $dish->id . '/delete') }}@endif" autocomplete="off">

    <!-- CSRF Token -->
    <input type="hidden" name="_token" value="{{{ csrf_token() }}}" />
    <input type="hidden" name="id" value="{{ $dish->id }}" />
    <!-- <input type="hidden" name="_method" value="DELETE" /> -->
    <!-- ./ csrf token -->

    <!-- Form Actions -->
    <div class="control-group">
        <div class="controls">
            Are you sure you want to delete {{$dish->name }}?<br/>
            <element class="btn-cancel close_popup">Cancel</element>
            <button type="submit" class="btn btn-danger">Delete</button>
        </div>
    </div>
    <!-- ./ form actions -->
</form>
@stop

And here is the script in modal.blade.php:

<!-- File truncated -->
<script type="text/javascript">
    $(document).ready(function(){
    $('.close_popup').click(function(){
        parent.oTable.fnReloadAjax();
        parent.jQuery.fn.colorbox.close();
        return false;
    });
    $('#deleteForm').submit(function(event) {
        var form = $(this);
        $.ajax({
            type: form.attr('method'),
            url: form.attr('action'),
            data: form.serialize()
        }).done(function() {
            parent.jQuery.colorbox.close();
            parent.oTable.fnReloadAjax();
        }).fail(function() {

        });
        event.preventDefault();
    });
});
$('.wysihtml5').wysihtml5();
$(prettyPrint)
</script>

The popup closes but the table is not refreshed tho...

@xhezairbey
Copy link

@asivaneswaran is this @if (isset($dish)) returning true? I'm just trying to think where the problem is.

@asivaneswaran
Copy link
Author

It returns 1 ( so true )....

@xhezairbey
Copy link

I'm curious how you got it to return 1 instead of ture, for a second there I thought isset() should return true.
Anyways, it if is so than the URL should be rendered correctly into the action attribute.
Therefore, I would suggest you check Chrome Inspect for potential console errors and you may be able to locate why it's not working for you.

@asivaneswaran
Copy link
Author

The action is correct.
And I am not getting any errors in the console...

@xhezairbey
Copy link

So what is actually happening when you click Delete?

@asivaneswaran
Copy link
Author

The modal closes but the dish is not deleted...
I am getting no error what so ever...

@xhezairbey
Copy link

You have to excuse me on this, silly question I know, but have you set your delete() methods accordingly?!

Dish Controller
public function postDelete($dish)

Dish Model
public function delete()

@asivaneswaran
Copy link
Author

EDIT:

NVM, I fixed the not found. But it's still not working...

I have the same issue as before.

@xhezairbey
Copy link

I run out of suggestions, sorry. Can't say much without knowing the contents of your Dish model and controller.

@asivaneswaran
Copy link
Author

Here is my controller:

     public function postDelete($dish)
     {
       $id = $dish->id;
       $dish->delete();

    // Was the comment post deleted?
    $dish = Dish::find($id);
    if ( empty($dish) )
    {
        // TODO needs to delete all of that dish's content
        return Redirect::back()->with('success', Lang::get('admin/dishs/messages.delete.success'));
    }
    else
    {
        // There was a problem deleting the dish
        return Redirect::back()->with('error', Lang::get('admin/dishs/messages.delete.error'));
    }
}

And I declared this in my routes;

 Route::model('dish', 'Dish');

Right now, I took out the dd($dish) and now I am getting this error:

{"error":{"type":"Symfony\Component\HttpKernel\Exception\NotFoundHttpException","message":"","file":"C:\wamp\www\ecole\vendor\laravel\framework\src\Illuminate\Routing\Router.php","line":1366}}

@xhezairbey
Copy link

Can you provide the full code of your routes.php, and Dish Model.
Btw, what's the name of your Dish admin controller file?.

@asivaneswaran
Copy link
Author

Routes:

     # Dish Management
     Route::get('dishes/{dish}/delete', 'AdminDishController@getDelete')
         ->where('dish', '[0-9]+');
    Route::post('dishes/{dish}/delete', 'AdminDishController@postDelete')
        ->where('dish', '[0-9]+');
    Route::controller('dishes', 'AdminDishController');
'required|numeric', 'name' => 'required|between:4,25|unique:dishes,name', 'description' => 'between:5,25', 'price' => 'required|numeric', ); public function menu() { return $this->belongsTo('Menu', 'id'); } } ``` The Controller name is AdminDishController

@andrewelkins
Copy link
Owner

Closing this as a duplicate. Soon this code will be replaced with Bootstrap 3 modal instead of the crappy iframe. Closing for now. Look for updates this week.

@gayanhewa
Copy link

Is this fixed ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants