You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ve...@apache.org on 2015/03/31 18:56:09 UTC
incubator-ranger git commit: RANGER-283 : Allow navigation on dirty
forms
Repository: incubator-ranger
Updated Branches:
refs/heads/master 3487811ec -> ded323b77
RANGER-283 : Allow navigation on dirty forms
Signed-off-by: Velmurugan Periasamy <ve...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-ranger/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ranger/commit/ded323b7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ranger/tree/ded323b7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ranger/diff/ded323b7
Branch: refs/heads/master
Commit: ded323b776e6b5bf92c0c643c3e50e5377a8fd93
Parents: 3487811
Author: Gautam Borad <gb...@gmail.com>
Authored: Tue Mar 31 17:51:25 2015 +0530
Committer: Velmurugan Periasamy <ve...@apache.org>
Committed: Tue Mar 31 12:55:22 2015 -0400
----------------------------------------------------------------------
security-admin/src/main/webapp/scripts/App.js | 1 +
security-admin/src/main/webapp/scripts/Main.js | 3 +-
.../main/webapp/scripts/modules/XAOverrides.js | 14 +++++++
.../scripts/modules/globalize/message/en.js | 2 +
.../src/main/webapp/scripts/routers/Router.js | 44 +++++++++++++++++++-
.../src/main/webapp/scripts/utils/XAUtils.js | 34 ++++++++++-----
6 files changed, 84 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ded323b7/security-admin/src/main/webapp/scripts/App.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/App.js b/security-admin/src/main/webapp/scripts/App.js
index 2a57d73..937ee27 100644
--- a/security-admin/src/main/webapp/scripts/App.js
+++ b/security-admin/src/main/webapp/scripts/App.js
@@ -44,6 +44,7 @@ define(function(require) {
/* Add initializers here */
App.addInitializer( function () {
// Communicator.mediator.trigger("Application:Start");
+ window._preventNavigation = false;
Backbone.history.start();
});
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ded323b7/security-admin/src/main/webapp/scripts/Main.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/Main.js b/security-admin/src/main/webapp/scripts/Main.js
index cefaa31..460c91a 100644
--- a/security-admin/src/main/webapp/scripts/Main.js
+++ b/security-admin/src/main/webapp/scripts/Main.js
@@ -37,7 +37,8 @@ function ( Backbone, App, RegionManager, AppRouter, AppController, XAOverrides,
controller: controller
});
App.appRouter.on('beforeroute', function(event) {
- $(App.rContent.$el).html(loadingHTML);
+ if(!window._preventNavigation)
+ $(App.rContent.$el).html(loadingHTML);
});
// Start Marionette Application in desktop mode (default)
Backbone.fetchCache._cache = {};
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ded323b7/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/modules/XAOverrides.js b/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
index a60383e..f312065 100644
--- a/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
+++ b/security-admin/src/main/webapp/scripts/modules/XAOverrides.js
@@ -25,6 +25,20 @@
require('backgrid');
require('jquery-toggles');
+
+ window.onbeforeunload = function(e) {
+ if (window._preventNavigation) {
+ var message = 'Are you sure you want to refresh the page? Unsaved changes will be lost.';
+ if (typeof e == 'undefined') {
+ e = window.event;
+ }
+ if (e) {
+ e.returnValue = message;
+ }
+ return message;
+ }
+ };
+
/**
HtmlCell renders any html code
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ded323b7/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js b/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js
index 9645216..2231037 100644
--- a/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js
+++ b/security-admin/src/main/webapp/scripts/modules/globalize/message/en.js
@@ -217,6 +217,8 @@ define(function(require) {
save : 'Save',
cancel : 'Cancel',
addMore : 'Add More..',
+ stayOnPage : 'Stay on this page',
+ leavePage : 'Leave this page',
setVisibility : 'Set Visibility'
},
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ded323b7/security-admin/src/main/webapp/scripts/routers/Router.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/routers/Router.js b/security-admin/src/main/webapp/scripts/routers/Router.js
index 095e56e..d4b047c 100644
--- a/security-admin/src/main/webapp/scripts/routers/Router.js
+++ b/security-admin/src/main/webapp/scripts/routers/Router.js
@@ -19,9 +19,12 @@
define([
'backbone',
- 'backbone.marionette'
+ 'backbone.marionette',
+ 'utils/XALangSupport',
+ 'models/VAppState',
+ 'utils/XAUtils'
],
-function(Backbone){
+function(Backbone, Marionette, localization, MAppState, XAUtil){
'use strict';
return Backbone.Marionette.AppRouter.extend({
@@ -58,6 +61,43 @@ function(Backbone){
/*************** ERROR PAGE ****************************************/
"*actions" : "pageNotFoundAction"
+ },
+ route: function(route, name, callback) {
+ var router = this,
+ callbackArgs;
+ if (!callback) callback = this[name];
+ var proceedWithCallback = function() {
+ var currentFragment = Backbone.history.getFragment();
+ router.trigger('beforeroute', name);
+ callback.apply(router, callbackArgs);
+ MAppState.set('previousFragment', currentFragment);
+ };
+
+ var overrideCallback = function() {
+ callbackArgs = arguments;
+ if (window._preventNavigation) {
+ bootbox.dialog(window._preventNavigationMsg, [{
+ "label": "Stay on this page!",
+ "class": "btn-success btn-small",
+ "callback": function() {
+ router.navigate(MAppState.get('previousFragment'), {
+ trigger: false
+ });
+ }
+ }, {
+ "label": "Leave this page",
+ "class": "btn-danger btn-small",
+ "callback": function() {
+ XAUtil.allowNavigation();
+ proceedWithCallback();
+ }
+ }]);
+
+ } else {
+ proceedWithCallback();
+ }
+ };
+ return Backbone.Router.prototype.route.call(this, route, name, overrideCallback);
}
});
});
http://git-wip-us.apache.org/repos/asf/incubator-ranger/blob/ded323b7/security-admin/src/main/webapp/scripts/utils/XAUtils.js
----------------------------------------------------------------------
diff --git a/security-admin/src/main/webapp/scripts/utils/XAUtils.js b/security-admin/src/main/webapp/scripts/utils/XAUtils.js
index 114fc88..1bcb4b3 100644
--- a/security-admin/src/main/webapp/scripts/utils/XAUtils.js
+++ b/security-admin/src/main/webapp/scripts/utils/XAUtils.js
@@ -260,9 +260,11 @@ define(function(require) {
* @param {String} msg - The msg to show
* @param {function} callback - The callback to call
*/
- XAUtils.preventNavigation = function(msg, $form, callback) {
- $("body a, i[class^='icon-'],allowNav").on("click.blockNavigation", function(e) {
- XAUtils.preventNavigationHandler(e, msg, $form, callback);
+ XAUtils.preventNavigation = function(msg, $form) {
+ window._preventNavigation = true;
+ window._preventNavigationMsg = msg;
+ $("body a, i[class^='icon-']").on("click.blockNavigation", function(e) {
+ XAUtils.preventNavigationHandler.call(this, e, msg, $form);
});
};
@@ -270,22 +272,32 @@ define(function(require) {
* remove the block of preventNavigation
*/
XAUtils.allowNavigation = function() {
+ window._preventNavigation = false;
+ window._preventNavigationMsg = undefined;
$("body a, i[class^='icon-']").off('click.blockNavigation');
};
- XAUtils.preventNavigationHandler = function(e, msg,$form,callback) {
+ XAUtils.preventNavigationHandler = function(e, msg, $form) {
var formChanged = false;
- if(!_.isUndefined($form))
+ var target = this;
+ if (!_.isUndefined($form))
formChanged = $form.find('.dirtyField').length > 0 ? true : false;
if (!$(e.currentTarget).hasClass("_allowNav") && formChanged) {
-
+
e.preventDefault();
e.stopImmediatePropagation();
- XAUtils.alertPopup({
- msg : msg,
- title : "Warning",
- callback : callback
- });
+ bootbox.dialog(msg, [{
+ "label": localization.tt('btn.stayOnPage'),
+ "class": "btn-success btn-small",
+ "callback": function() {}
+ }, {
+ "label": localization.tt('btn.leavePage'),
+ "class": "btn-danger btn-small",
+ "callback": function() {
+ XAUtils.allowNavigation();
+ target.click();
+ }
+ }]);
return false;
}
};