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

Use bootstrap modals instead of javascript confirm #263

Merged
merged 1 commit into from
Mar 31, 2016

Conversation

calvera
Copy link
Contributor

@calvera calvera commented Mar 3, 2016

I'm not sure if you are interested in...

this PR does not introduce BC break... nothing needs to be changed in the code...

please comment...

@sescandell
Copy link
Member

Hi @calvera

Sounds like a good idea!

I'll check the PR ASAP ;)

Thanks,

</div>
</div>
</div>
{{ echo_endblock() }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a duplication of the code in the ListBuilderTemplate. So, it would be better to create a separate template which is included here: also makes it easier to customize :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I will deduplicate

@sescandell
Copy link
Member

Hi,

I've seen some little things you need to change to make this working as expected.

csrf-token does not always exist. The action is not necessaraly protected. If you look at the previous code, we used a custom form only if the action is protected.

Previous behavior was:

  • If action is protected: prevent default event, generate a dynamic form and submit it
  • If action is not protected: let default behavior continue

If I'm not wrong, in your new implementation:

  • If the action need a confirmation, you will always use a dynamic form: it might not be the necessary if the action is not protected
  • If the action doesn't need a confirmation but is protected, it doesn't use the dynamic form (whereas it should)

@@ -35,17 +35,23 @@

{% spaceless %}
{{ echo_spaceless() }}
<div {% if builder.yamlKey is same as('list') or builder.yamlKey is same as('nested_list') %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this new "parent" doesn't break buttons display?
Given that object actions are wrapped by this code:

<div class="col-md-12 btn-group">
    {{ block('object_actions') }}
</div>

I'm wondering if:

<div class="col-md-12 btn-group">
    <div>
        <a class="btn btn-default">button1</a>
        <a class="btn btn-default">button2</a>
        <a class="btn btn-default">button3</a>
    <div>
</div>

Would be rendered the same as:

<div class="col-md-12 btn-group">
    <a class="btn btn-default">button1</a>
    <a class="btn btn-default">button2</a>
    <a class="btn btn-default">button3</a>
</div>

(Just a question, I don't remember how BS handle btn-group)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addition div is wrong, span would be better, but i will remove addional tag at all, which is the best

about dynamic forms:
I think, the correct behavior would be:

  1. confirmation is needed -> show bs modal and POST a form with or without csrf protection if confirmed
  2. no confirmation and csrf protection -> POST a dynamic form with csrf
  3. no confirmation and no protection -> do not change, href link is followed

Do you agree?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@calvera
Copy link
Contributor Author

calvera commented Mar 4, 2016

thank you for your comments, i'll improve the PR

@calvera
Copy link
Contributor Author

calvera commented Mar 5, 2016

so, now all should work, object actions, batch actions and generic actions as well. I have tested it on demo https://github.com/symfony2admingenerator/symfony2-admingenerator-demo-edition

$(this.options.containerSelector).on('click', this.options.buttonSelector, this.clickHandler.bind(this));
$(this.options.containerSelector)
.find(this.options.buttonSelector)
.on('click',this.clickHandler.bind(this));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please come back to the previous implementation here. The difference is small, but previous version permit to handle AJAX loaded content (while the find version doesn't AFAIK).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will do, thanks for noticing this

@sescandell
Copy link
Member

Hi @calvera

I see you added the confirmModal property on Action objects, but I don't see Action class(es). Could you please double check that point (or remove the confirmModal option, that's your choice, I see what you mean by this parameter).

If you let the confirmModal option, please, update the documentation to recise there is a new option confirmModal in generators for actions, possible values and behavior depending on value.

Thank you,

@calvera
Copy link
Contributor Author

calvera commented Mar 11, 2016

@sescandell
Copy link
Member

Hi @calvera

Everything seems good... I'm just wondering if your proposition about modals with additional fields is the right way to recommend. I agree with you: it works, and is fairly simple. But, with that solution I think you miss something important which is Symfony Form bidning and all validation process. What if the field required a valid unique email but is not valid (because already in the database). With this solution, the user doesn't have an easy way to manage that situation.

I already pushed a solution to that following an issue if I'm not wrong, based on Ajax, real form and managing validation constraints (actually based on Get / Post requests and form submitted or not). Could you please so complete your documentation based on that?

@ioleo
Copy link
Member

ioleo commented Mar 13, 2016

I agree with @sescandell. The idea is good, but this should be improved to handle the form via AJAX and display server-side validation messages.

@calvera
Copy link
Contributor Author

calvera commented Mar 13, 2016

@sescandell i'm not sure what you mean by 'I already pushed a solution to that following an issue...'. What you pushed and where? I have an example of full Symfony form in my symfony2-admingenerator-demo-edition/src/Admingenerator/DoctrineOrmDemoBundle/Resources/views/PostActions/index.html.twig

but this is not ideal... i'm not sure if we could somehow make all action twig templates to be ajax compatible...

@sescandell
Copy link
Member

Hi @calvera

We discussed about that there is some times now here and following comment.

I took a look to your fork of the demo. In that code, you create a new modal with a form not binded to any Symfony2 Form (here. My proposition is to manage that more globally with dynamic forms (as discussed here a long time ago).

Actually, if I clearly understand your fork, this is really near to how you handle simpleedit action (but loaders and form handlers are maybe missing).

If you prefer, I can propose you to split this PR in 2 parts: first one is moving to bootstrap modals (what you already made and is pretty good IMO) ; then, secondly, AJAX and dynamic form loading in modals (with documentation and/or helpers).

@calvera
Copy link
Contributor Author

calvera commented Mar 14, 2016

@sescandell - the ajax/form part is now in cookbook only. I think someone could use the 'no-form' approach for simple task. it is his/her decision. let's make it clear in cookbook.

but I agree we could leave the full ajax/form for another PR.

thanks for comments and proposals...

p.s. after i read that discussion about ajaxification, i'll think about it.

@calvera
Copy link
Contributor Author

calvera commented Mar 26, 2016

Where are we now? Am I supposed to do something more? :)

@sescandell
Copy link
Member

Looks good to me.

Ping @bobvandevijver and @loostro. If everybody is ok, I'll merge it 👍

Many thanks @calvera

@sescandell sescandell added this to the v2.2 milestone Mar 29, 2016
@sescandell
Copy link
Member

@calvera could you please rebase the PR (otherwise, I'll do it :))

thanks

@calvera
Copy link
Contributor Author

calvera commented Mar 31, 2016

squashed and rebased

@sescandell sescandell merged commit fab86a7 into symfony2admingenerator:master Mar 31, 2016
@sescandell
Copy link
Member

Merged, many thanks @calvera 👍

@calvera calvera deleted the modals branch March 31, 2016 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants