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

Fix #3279 warning closing form #3303

Merged
merged 8 commits into from Apr 9, 2020
Merged

Fix #3279 warning closing form #3303

merged 8 commits into from Apr 9, 2020

Conversation

stu01509
Copy link
Member

@stu01509 stu01509 commented Apr 1, 2020

Fixes #3279

Short description of what this resolves:

Added warning dialog to show when the user closes the tabs.

image

@stu01509
Copy link
Member Author

stu01509 commented Apr 1, 2020

Hello @bradymiller @stephenwaite @sjpadgett @tywrenn

Please review this PR, and give me feedback or suggestion about this dialog style.
Thanks :)

@sjpadgett
Copy link
Sponsor Member

Hi Cliff, while the workflow is correct for the alert, we don't want user having to do this for every tab closure. You think providers are stressed now, wait til we give them this:)

These type alerts should happen in forms where if content changed to trigger alert occurs.

@stu01509
Copy link
Member Author

stu01509 commented Apr 1, 2020

Hi @sjpadgett

Thanks for your reply, If have any request changed Please let me know.

@sjpadgett
Copy link
Sponsor Member

Well if I understand @stephenwaite original issue, he was concern that a modified SOAP could be canceled w/o a second chance for user to reconsider. This is common in UX and should somehow extend to all our encounter forms.

I see two places to trigger the alert.

  • x-ed out from tab while form is being edited.
  • canceled in form while editing.

My first thought is a javascript function, maybe even one placed in our JS utility.js that monitors for content changes and sets a flag that is exposed globally to parent tabs or form(perhaps a session variable) that can be checked by alert before popping up. Set the context for the changes also.

@stu01509
Copy link
Member Author

stu01509 commented Apr 2, 2020

Hi @sjpadgett @stephenwaite and @bradymiller

I try to in interface/forms/soap/templates/general_new.html write a javascript addEventListener to record text change counter, But it will happen open SOAP page HTTP 500 error.

Also, I've tried in utility.js writer a counter to record, But It will happen redeclaration of let, Any suggestion or advise?

@stephenwaite
Copy link
Sponsor Member

hi @stu01509 , not really sure, would you like to push you're best effort so can take a look at the code?

@stu01509
Copy link
Member Author

stu01509 commented Apr 3, 2020

Hi @sjpadgett @stephenwaite and @bradymiller

Finally, I used local storage to record isSoapEdit variables when SOAP textarea trigger onkeyup event. Now the modal only shows when the textarea has modified.

Please review it again, Thanks.

@stu01509 stu01509 changed the title Fix #3279 warning closing form [WIP]Fix #3279 warning closing form Apr 4, 2020
@stephenwaite
Copy link
Sponsor Member

nice @stu01509 , that fixes when you click to close the tab but not the cancel button, thank you

@sjpadgett
Copy link
Sponsor Member

In form cancel will require you to create a doCancel() function to replace the window.location redirect in the cancel button. The check you onchange flag and act accordingly. Just saying:)

@stu01509
Copy link
Member Author

stu01509 commented Apr 5, 2020

Thanks for @stephenwaite and @sjpadgett review and suggestion,
I will try to improve this solution and push a new commit asap.

const panelId = self.parent().attr("href").substring(1);
top.restoreSession();
twCloseTab(tabsid, panelId);
localStorage.removeItem('isSoapEdit');
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

shouldn't need to use localStorage. would be more straightforward to just store it in top.* . See here for example of things that are stored there:
https://github.com/openemr/openemr/blob/master/interface/main/tabs/main.php#L157-L164

Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, Thanks for your instruction, It's very useful to me,
I will try it! 😁

@stu01509
Copy link
Member Author

stu01509 commented Apr 5, 2020

I've tried in general _new.html onkeyup event to trigger console.log(jsGlobals) variables, But it seems can't access this variable.

image

@stu01509
Copy link
Member Author

stu01509 commented Apr 5, 2020

Now, I still use localstorage to record the isSoapEdit variable, Because of the general _new.html page can't access jsGlobals variable.

Any suggestions or feedback to improve it?

@stu01509 stu01509 changed the title [WIP]Fix #3279 warning closing form Fix #3279 warning closing form Apr 5, 2020
@bradymiller
Copy link
Sponsor Member

hi @stu01509 , To store the variable in top, you would end up doing something like:

top.isSoapEdit = true;

@stu01509
Copy link
Member Author

stu01509 commented Apr 6, 2020

Oh my! It's working.
Please review it again 😁

@stephenwaite
Copy link
Sponsor Member

hi @stu01509 , the alert works great when you try to close the tab but there's still no alert for clicking the Cancel button. Not seeing anything new in the onclick attr of that button. Thank you

if (top.isSoapEdit === true) {
dlgopen('', '', 450, 125, '', '<div class="text-danger">Warning</div>', {
type: 'Alert',
html: '<p>Do you want to close the tabs?</p>',
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

translate (using the above xla construct)

html: '<p>Do you want to close the tabs?</p>',
buttons: [
{text: 'Cancel', close: true, style: 'default btn-sm'},
{text: 'Close', close: true, style: 'danger btn-sm', click: closeSoap},
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

translate above 2 labels (using the above xla construct)

}

if (self[0].id === 'SOAP' && top.isSoapEdit === true) {
dlgopen('', '', 450, 125, '', '<div class="text-danger">Warning</div>', {
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

translate (note this is different than in above smarty context):

dlgopen('', '', 450, 125, '', '<div class="text-danger"><?php echo xla("Warning"); ?></div>', {

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @bradymiller

Here, The title will disappear, I guessing in here it using <<<EOD and EOD

image

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

man, EOD...
your gonna have to look up how to call php functions in EOD (there may be examples of this in OpenEMR codebase, but not sure)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds like a huge project 🤣, I will try to fix it.
Thank you.

if (self[0].id === 'SOAP' && top.isSoapEdit === true) {
dlgopen('', '', 450, 125, '', '<div class="text-danger">Warning</div>', {
type: 'Alert',
html: '<p>Do you want to close the tabs?</p>',
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

translate (using the above xla function)

html: '<p>Do you want to close the tabs?</p>',
buttons: [
{text: 'Cancel', close: true, style: 'default btn-sm'},
{text: 'Close', close: true, style: 'danger btn-sm', click: closeSoap},
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

translate above 2 labels (using the above xla function)

@stu01509
Copy link
Member Author

stu01509 commented Apr 7, 2020

Hi @bradymiller

I try to change 'general_new.html'
to dlgopen('', '', 450, 125, '', '<div class="text-danger">{xla t="Warning"}</div>', {

But it looks like have some problem, I guessing maybe is {literal} tag effect?

image

@stephenwaite
Copy link
Sponsor Member

think so @stu01509 , try the {literal}, https://www.smarty.net/docs/en/language.function.literal.tpl

@stu01509
Copy link
Member Author

stu01509 commented Apr 8, 2020

Hi @stephenwaite
Thanks for your information, Let me fix translate in EOD problems :)

@stu01509
Copy link
Member Author

stu01509 commented Apr 8, 2020

Hi @bradymiller and @stephenwaite

Updated this commit, I used variables to save translate content.
Please review it again, Thanks.

@stephenwaite
Copy link
Sponsor Member

hi @stu01509 , nice work! guess this can be extended to other forms which would build on this and be a larger project? would you like to create the parent project and reference this? thank you

@@ -113,9 +113,13 @@ public static function genJavaScript()
$s = '';
if (!defined('INCLUDED_TW_ONETIME_JS')) {
define('INCLUDED_TW_ONETIME_JS', true);
$modalTitle = xla("Warning");
$modalContent = xla("Do you want to close the tabs");
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

place the punctuation (?) within the constant

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! Please review it again :)

@bradymiller
Copy link
Sponsor Member

hi @stu01509 , What will happen here if a user opens up two SOAP forms at the same time and works on them?

@stu01509
Copy link
Member Author

stu01509 commented Apr 8, 2020

Hello @bradymiller

If a user opens up two SOAP forms, and just edit one of form when it closes the anyone form, just show modal dialog.

@stu01509
Copy link
Member Author

stu01509 commented Apr 8, 2020

Hello @stephenwaite

Sounds good ideas, I would like to build on this project after this PR merged, Can you open a new issue and assign me? Thanks 😁

@sjpadgett
Copy link
Sponsor Member

This is why that global js should be array that includes context. This makes life so much easier.
In top:
var FormAction = [{id:'form id'}, {context:'edit'}, {name:'tab name'}, {status:'changed'}];

then universal function to deal.

Just saying one var should handle all edits and just a suggestion from the busy body that is me:)

@stu01509
Copy link
Member Author

stu01509 commented Apr 8, 2020

Hi @sjpadgett

Thanks for your suggestion 👍, It's a good idea to deal with all the encounter form status, I will plan it in the next feature.

@sjpadgett
Copy link
Sponsor Member

It's a good idea to deal with all the encounter form status

Okay but I collect royalties! $9.99 ought to do it:)

@stu01509
Copy link
Member Author

stu01509 commented Apr 9, 2020

royalties

Okay, Let me use PR to instead of royalties 😁

@bradymiller
Copy link
Sponsor Member

hi @stu01509 , Testing well and bringing into codebase. Great job persevering on this one and agree that a generic mechanism that leverages this (ie. any form can plug into it) would be very nice. Thanks for the improvement! -brady

@bradymiller bradymiller merged commit 0544f5c into openemr:master Apr 9, 2020
@stu01509
Copy link
Member Author

stu01509 commented Apr 9, 2020

Hello @bradymiller

Let me planing a pretty plan for implementation about this feature, and that can easily to use in any form and show the dialog 😃

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.

warning when closing an encounter form
4 participants