Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Inform server that user wants to close the dialog. #52

Merged
merged 5 commits into from
Apr 9, 2018

Conversation

manolo
Copy link
Member

@manolo manolo commented Mar 23, 2018

Client-side can close the dialog synchronously when the user presses escape or
clicking outside. This makes server side unable to prevent closing if there
are unsave changes etc. With this change, server side can listen to an event
and decide whether to close the dialog.

Fixes #37


This change is Reviewable

manolo added a commit to vaadin/bakery-app-starter-flow-spring that referenced this pull request Mar 23, 2018
This needs to be removed when this PR is merged:
vaadin/vaadin-dialog-flow#52
@manolo manolo force-pushed the fix/37-send-close-event branch 2 times, most recently from e609d6f to fae44e4 Compare March 30, 2018 06:16
Client-side can close the dialog synchronously when the user presses escape or
clicking outside. This makes server side unable to prevent closing if there
are unsave changes etc. With this change, server side can listen to an event
and decide whether to close the dialog.

Fixes vaadin#37
@caalador
Copy link
Contributor

caalador commented Apr 6, 2018

Review status: 0 of 1 files reviewed at latest revision, all discussions resolved, some commit checks failed.


src/main/java/com/vaadin/flow/component/dialog/Dialog.java, line 78 at r1 (raw file):

              + "};"
              + "$0.$.overlay.addEventListener('vaadin-overlay-outside-click', f);"
              + "$0.$.overlay.addEventListener('vaadin-overlay-escape-press', f);", getElement());

For the latter part $0.$.overlay... i think you might need to postpone the execution if the polymer element hasn't yet initialised as now it would seem that it is run too early.
So I guess something like:

if(PolymerUtils:isPolymerElemnet(*)($0)) { 
  // Add event listeners
} else if (PolymerUtils::mayBePolymerElement(*)($0)){
  Window.customElements.whenDefined($0.localName).then(function () {
    // Add event listeners
  });
}

Or if there is another hook in 'vaadin-dialog' element to catch initialization complete then use that.


Comments from Reviewable

This fixes when dialog is created in pure java instead of in templates
@manolo
Copy link
Member Author

manolo commented Apr 7, 2018

Review status: 0 of 1 files reviewed at latest revision, 1 unresolved discussion, some commit checks failed.


src/main/java/com/vaadin/flow/component/dialog/Dialog.java, line 78 at r1 (raw file):

Previously, caalador wrote…

For the latter part $0.$.overlay... i think you might need to postpone the execution if the polymer element hasn't yet initialised as now it would seem that it is run too early.
So I guess something like:

if(PolymerUtils:isPolymerElemnet(*)($0)) { 
  // Add event listeners
} else if (PolymerUtils::mayBePolymerElement(*)($0)){
  Window.customElements.whenDefined($0.localName).then(function () {
    // Add event listeners
  });
}

Or if there is another hook in 'vaadin-dialog' element to catch initialization complete then use that.

This was working because in bakery dialog is created in a template, hence failing when creating it in pure java.

I have moved the code to the block where the dialog is attached in java. This guarantees that the client-side element is actually enhanced and avoids adding more code to client side.


Comments from Reviewable

@caalador
Copy link
Contributor

caalador commented Apr 9, 2018

Reviewed 3 of 3 files at r2.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@ZheSun88 ZheSun88 merged commit 59d5fe2 into vaadin:master Apr 9, 2018
@ZheSun88 ZheSun88 deleted the fix/37-send-close-event branch April 9, 2018 07:31
@pekam pekam added this to the 1.0.0.beta4 milestone Apr 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add close listener support where it's possible to cancel the closing of a Dialog
4 participants