Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[JENKINS-19835] added page-leave confirmation on the configuration page
- Loading branch information
Showing
3 changed files
with
66 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,63 @@ | ||
var errorMessage = "Leave without saving?"; | ||
var needToConfirm = false; | ||
|
||
window.onbeforeunload = confirmExit; | ||
Event.observe(window, 'load', initConfirm); | ||
|
||
function initConfirm() { | ||
var configForm = document.getElementsByName("config")[0]; | ||
|
||
var buttons = configForm.getElementsByTagName("button"); | ||
var name; | ||
for ( var i = 0; i < buttons.length; i++) { | ||
name = buttons[i].parentNode.parentNode.getAttribute('name'); | ||
if (name == "Submit") { | ||
addEventToElement(buttons[i], 'click', function() { | ||
needToConfirm = false; | ||
}); | ||
} else if (name == "Apply") { | ||
} else { | ||
addEventToElement(buttons[i], 'click', confirm); | ||
} | ||
} | ||
|
||
var inputs = configForm.getElementsByTagName("input"); | ||
for ( var i = 0; i < inputs.length; i++) { | ||
addEventToElement(inputs[i], 'change', confirm); | ||
if (inputs[i].type == 'checkbox' || inputs[i].type == 'radio') { | ||
addEventToElement(inputs[i], 'click', confirm); | ||
} else { | ||
addEventToElement(inputs[i], 'keydown', confirm); | ||
} | ||
} | ||
|
||
inputs = configForm.getElementsByTagName("select"); | ||
for ( var i = 0; i < inputs.length; i++) { | ||
addEventToElement(inputs[i], 'keydown', confirm); | ||
addEventToElement(inputs[i], 'click', confirm); | ||
} | ||
|
||
inputs = configForm.getElementsByTagName("textarea"); | ||
for ( var i = 0; i < inputs.length; i++) { | ||
addEventToElement(inputs[i], 'keydown', confirm); | ||
} | ||
} | ||
|
||
function confirm() { | ||
needToConfirm = true; | ||
} | ||
|
||
function addEventToElement(obj, evType, fn) { | ||
if (obj.addEventListener) { | ||
obj.addEventListener(evType, fn, false); | ||
return true; | ||
} else if (obj.attachEvent) { | ||
return obj.attachEvent("on" + evType, fn); | ||
} | ||
} | ||
|
||
function confirmExit() { | ||
if (needToConfirm) { | ||
return errorMessage; | ||
} | ||
} |