public inbox for [email protected]
help / color / mirror / Atom feedPATCH: Added user confirmation on panel close (pgAdmin4)
2+ messages / 2 participants
[nested] [flat]
* PATCH: Added user confirmation on panel close (pgAdmin4)
@ 2016-09-05 14:31 Murtuza Zabuawala <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Murtuza Zabuawala @ 2016-09-05 14:31 UTC (permalink / raw)
To: pgadmin-hackers
Hi,
PFA patch to add user confirmation on panel close whenever user has any
changes to save in grid or in sql text area.
RM#1661
--
Regards,
Murtuza Zabuawala
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers
Attachments:
[text/x-patch] user_confirmation_on_panel_close.patch (2.7K, 3-user_confirmation_on_panel_close.patch)
download | inline diff:
diff --git a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
index c22fdd6..ebc7077 100644
--- a/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
+++ b/web/pgadmin/tools/sqleditor/templates/sqleditor/js/sqleditor.js
@@ -268,6 +268,35 @@ define(
self.render_history_grid();
+ // Listen on the panel closed event and notify user to save modifications.
+ _.each(window.top.pgAdmin.Browser.docker.findPanels('frm_datagrid'), function(p) {
+ if(p.isVisible()) {
+ p.on(wcDocker.EVENT.CLOSING, function() {
+ // Only if we can edit data then perform this check
+ var notify = false, msg;
+ if(self.handler.can_edit) {
+ var data_store = self.handler.data_store;
+ if(_.size(data_store.added) ||
+ _.size(data_store.updated)) {
+ msg = '{{ _('The data has been modified, but not saved. Are you sure you wish to discard the changes?') }}';
+ notify = true;
+ }
+ } else if(self.handler.is_query_tool) {
+ // We will check for modified sql content
+ var sql = self.handler.gridView.query_tool_obj.getValue();
+ sql = sql.replace(/\s+/g, '');
+ // If it is an empty query, do nothing.
+ if (sql.length > 0) {
+ msg = '{{ _('The query has been modified, but not saved. Are you sure you wish to discard the changes?') }}';
+ notify = true;
+ }
+ }
+ if(notify) {return self.user_confirmation(p, msg);}
+ return true;
+ });
+ }
+ });
+
/* We have override/register the hint function of CodeMirror
* to provide our own hint logic.
*/
@@ -370,6 +399,25 @@ define(
});
},
+ /* To prompt user for unsaved changes */
+ user_confirmation: function(panel, msg) {
+ // If there is anything to save then prompt user
+ alertify.confirm('{{ _('Unsaved changes') }}', msg,
+ function() {
+ // Do nothing as user do not want to save, just continue
+ window.onbeforeunload = null;
+ panel.off(wcDocker.EVENT.CLOSING);
+ window.top.pgAdmin.Browser.docker.removePanel(panel);
+ },
+ function() {
+ // Stop, User wants to save
+ // false value will prevent from panel to close
+ return true;
+ }
+ ).set('labels', {ok:'Yes', cancel:'No'});
+ return false;
+ },
+
/* Regarding SlickGrid usage in render_grid function.
SlickGrid Plugins:
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: PATCH: Added user confirmation on panel close (pgAdmin4)
@ 2016-09-05 16:21 Dave Page <[email protected]>
parent: Murtuza Zabuawala <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Dave Page @ 2016-09-05 16:21 UTC (permalink / raw)
To: Murtuza Zabuawala <[email protected]>; +Cc: pgadmin-hackers
Thanks - committed, but we managed to miss a couple of similar cases.
I logged them here: https://redmine.postgresql.org/issues/1666 - can
you take a look please?
On Mon, Sep 5, 2016 at 3:31 PM, Murtuza Zabuawala
<[email protected]> wrote:
> Hi,
>
> PFA patch to add user confirmation on panel close whenever user has any
> changes to save in grid or in sql text area.
> RM#1661
>
> --
> Regards,
> Murtuza Zabuawala
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
>
> --
> Sent via pgadmin-hackers mailing list ([email protected])
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>
--
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake
EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2016-09-05 16:21 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-09-05 14:31 PATCH: Added user confirmation on panel close (pgAdmin4) Murtuza Zabuawala <[email protected]>
2016-09-05 16:21 ` Dave Page <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox