Skip to content

Commit 0d6cf57

Browse files
committed
Bug 1459834 - Don't stop navigation when a user has blocked confirm dialogs
1 parent f70768f commit 0d6cf57

File tree

4 files changed

+64
-17
lines changed

4 files changed

+64
-17
lines changed

app/scripts/constants.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ angular.extend(window.OPENSHIFT_CONSTANTS, {
7878
// removes the option from the route creation form.
7979
DISABLE_WILDCARD_ROUTES: true,
8080

81+
// true indicates that the web console should not show confirmation prompts
82+
// when users navigate away from a page without saving.
83+
DISABLE_CONFIRM_ON_EXIT: false,
84+
8185
// This blacklist hides certain kinds from the "Other Resources" page because they are unpersisted, disallowed for most end users, or not supported by openshift but exist in kubernetes
8286
AVAILABLE_KINDS_BLACKLIST: [],
8387

app/scripts/directives/confirmOnExit.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ angular.module("openshiftConsole")
99
message: '='
1010
},
1111
link: function($scope) {
12+
// If the feature is disabled or the user has asked the browser to
13+
// block dialogs, don't try to prompt.
14+
if (_.get(window, 'OPENSHIFT_CONSTANTS.DISABLE_CONFIRM_ON_EXIT') ||
15+
_.get(window, 'OPENSHIFT_CONSTANTS.CONFIRM_DIALOG_BLOCKED')) {
16+
return;
17+
}
18+
1219
var getMessage = function() {
1320
return $scope.message || "You have unsaved changes. Leave this page anyway?";
1421
};
@@ -27,7 +34,27 @@ angular.module("openshiftConsole")
2734
return;
2835
}
2936

30-
if(!confirm(getMessage())) {
37+
var start = new Date().getTime();
38+
39+
// Use a native confirm dialog to block code execution since we're in
40+
// the local change handler.
41+
var okToExit = confirm(getMessage());
42+
if (okToExit) {
43+
return;
44+
}
45+
46+
// Workaround "Prevent this page from creating additional dialogs"
47+
//
48+
// If the response took less than 50ms, assume the confirm dialog was
49+
// blocked by the browser. There's no API to detect that the user
50+
// has told Chrome to block these dialogs, and the user can't
51+
// navigate away otherwise.
52+
var end = new Date().getTime();
53+
console.log('confirm time', end - start);
54+
if ((end - start) < 50) {
55+
// Remember that the user is blocking dialogs. This is a per session settings.
56+
_.set(window, 'OPENSHIFT_CONSTANTS.CONFIRM_DIALOG_BLOCKED', true);
57+
} else {
3158
event.preventDefault();
3259
}
3360
});

dist/scripts/scripts.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ DEFAULT_HPA_CPU_TARGET_PERCENT:80,
687687
DISABLE_OVERVIEW_METRICS:!1,
688688
DISABLE_CUSTOM_METRICS:!1,
689689
DISABLE_WILDCARD_ROUTES:!0,
690+
DISABLE_CONFIRM_ON_EXIT:!1,
690691
AVAILABLE_KINDS_BLACKLIST:[],
691692
ENABLE_TECH_PREVIEW_FEATURE:{
692693
service_catalog_landing_page:!1,
@@ -13306,19 +13307,27 @@ dirty:"=",
1330613307
message:"="
1330713308
},
1330813309
link:function(a) {
13310+
if (!_.get(window, "OPENSHIFT_CONSTANTS.DISABLE_CONFIRM_ON_EXIT") && !_.get(window, "OPENSHIFT_CONSTANTS.CONFIRM_DIALOG_BLOCKED")) {
1330913311
var b = function() {
1331013312
return a.message || "You have unsaved changes. Leave this page anyway?";
1331113313
}, c = function() {
1331213314
if (a.dirty) return b();
1331313315
};
1331413316
$(window).on("beforeunload", c);
1331513317
var d = a.$on("$locationChangeStart", function(c) {
13316-
a.dirty && (confirm(b()) || c.preventDefault());
13318+
if (a.dirty) {
13319+
var d = new Date().getTime(), e = confirm(b());
13320+
if (!e) {
13321+
var f = new Date().getTime();
13322+
console.log("confirm time", f - d), f - d < 50 ? _.set(window, "OPENSHIFT_CONSTANTS.CONFIRM_DIALOG_BLOCKED", !0) :c.preventDefault();
13323+
}
13324+
}
1331713325
});
1331813326
a.$on("$destroy", function() {
1331913327
$(window).off("beforeunload", c), d && d();
1332013328
});
1332113329
}
13330+
}
1332213331
};
1332313332
}), angular.module("openshiftConsole").filter("duration", function() {
1332413333
return function(a, b, c, d) {

dist/scripts/vendor.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60542,9 +60542,8 @@ return a;
6054260542
var e = {
6054360543
group:"servicecatalog.k8s.io",
6054460544
resource:"bindings"
60545-
}, f = function(b) {
60546-
var c = a("generateName");
60547-
return {
60545+
}, f = function(b, c) {
60546+
var e = a("generateName"), f = e(_.trunc(b, d.maxlength - 6) + "-"), g = {
6054860547
kind:"Binding",
6054960548
apiVersion:"servicecatalog.k8s.io/v1alpha1",
6055060549
metadata:{
@@ -60554,14 +60553,20 @@ spec:{
6055460553
instanceRef:{
6055560554
name:b
6055660555
},
60557-
secretName:c(_.trunc(b, d.maxlength - 6) + "-")
60556+
secretName:f
6055860557
}
60559-
};
60558+
}, h = _.get(c, "spec.selector");
60559+
return h && (h.matchLabels || h.matchExpressions || (h = {
60560+
matchLabels:h
60561+
}), g.spec.alphaPodPresetTemplate = {
60562+
name:f,
60563+
selector:h
60564+
}), g;
6056060565
};
6056160566
return {
6056260567
bindingResource:e,
6056360568
bindService:function(a, b, d) {
60564-
var g = f(b);
60569+
var g = f(b, d);
6056560570
return c.create(e, null, g, a);
6056660571
},
6056760572
isServiceBindable:function(a, b) {
@@ -64564,7 +64569,9 @@ repository:a.ctrl.repository,
6456464569
namespace:a.ctrl.selectedProject.metadata.name,
6456564570
imageStreamTag:b
6456664571
});
64567-
a.createAPIObjects(c), a.ctrl.serviceToBind && a.bindService();
64572+
a.createAPIObjects(c), a.ctrl.serviceToBind && a.bindService(e.find(c, {
64573+
kind:"DeploymentConfig"
64574+
}));
6456864575
}, function(b) {
6456964576
a.ctrl.error = b;
6457064577
});
@@ -64592,18 +64599,18 @@ a.failure.length ? b.ctrl.error = a :b.ctrl.success = !0;
6459264599
}, function(a) {
6459364600
b.ctrl.error = a;
6459464601
});
64595-
}, a.prototype.bindService = function() {
64596-
var a = this;
64602+
}, a.prototype.bindService = function(a) {
64603+
var b = this;
6459764604
this.ctrl.bindInProgress = !0, this.ctrl.bindError = !1;
64598-
var b = {
64605+
var c = {
6459964606
namespace:e.get(this.ctrl.selectedProject, "metadata.name")
6460064607
};
64601-
this.BindingService.bindService(b, this.ctrl.serviceToBind, this.ctrl.name).then(function(c) {
64602-
a.ctrl.binding = c, a.ctrl.bindInProgress = !1, a.ctrl.bindComplete = !0, a.ctrl.bindError = null, a.DataService.watchObject(a.BindingService.bindingResource, e.get(a.ctrl.binding, "metadata.name"), b, function(b) {
64603-
a.ctrl.binding = b;
64608+
this.BindingService.bindService(c, this.ctrl.serviceToBind, a).then(function(a) {
64609+
b.ctrl.binding = a, b.ctrl.bindInProgress = !1, b.ctrl.bindComplete = !0, b.ctrl.bindError = null, b.DataService.watchObject(b.BindingService.bindingResource, e.get(b.ctrl.binding, "metadata.name"), c, function(a) {
64610+
b.ctrl.binding = a;
6460464611
});
64605-
}, function(b) {
64606-
a.ctrl.bindInProgress = !1, a.ctrl.bindComplete = !0, a.ctrl.bindError = b;
64612+
}, function(a) {
64613+
b.ctrl.bindInProgress = !1, b.ctrl.bindComplete = !0, b.ctrl.bindError = a;
6460764614
});
6460864615
}, a.prototype.getServiceClasses = function() {
6460964616
var a = this, b = {

0 commit comments

Comments
 (0)