Skip to content

Commit

Permalink
[FIXED JENKINS-19835]
Browse files Browse the repository at this point in the history
Merged pull request #962.
  • Loading branch information
kohsuke committed Oct 27, 2013
2 parents a84d1bc + a6b7f4b commit d3bce1e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog.html
Expand Up @@ -55,6 +55,9 @@
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=rfe>
Ask for confirmation if an user tries to leave an edited configuration page.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-19835">issue 19835</a>)
<li class=rfe>
Test failure summary appearance is improved.
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-19884">issue 19884</a>)
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/hudson/model/Job/configure.jelly
Expand Up @@ -63,11 +63,12 @@ THE SOFTWARE.
<j:if test="${h.hasPermission(it,it.CONFIGURE)}">
<f:bottomButtonBar>
<!--<input type="button" name="StructureTest" value="Test" onclick="buildFormTree(this.form)" />-->
<f:submit value="${%Save}" />
<f:submit value="${%Save}"/>
<f:apply />
</f:bottomButtonBar>
</j:if>
</f:form>
<st:adjunct includes="lib.form.confirm" />
</l:main-panel>
</l:layout>
</j:jelly>
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/form/apply.jelly
Expand Up @@ -35,5 +35,5 @@ THE SOFTWARE.
</s:documentation>
<st:adjunct includes="lib.form.apply.apply"/>
<input type="hidden" name="core:apply" value="" />
<input type="button" value="${%Apply}" class="apply-button applyButton" /><!-- applyButton is legacy -->
<input type="button" value="${%Apply}" class="apply-button applyButton" name="Apply"/><!-- applyButton is legacy -->
</j:jelly>
56 changes: 56 additions & 0 deletions core/src/main/resources/lib/form/confirm.js
@@ -0,0 +1,56 @@
(function() {
var errorMessage = "You have modified configuration";
var needToConfirm = false;

function confirm() {
needToConfirm = true;
}

function confirmExit() {
if (needToConfirm) {
return errorMessage;
}
}

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" || name == "Apply") {
$(buttons[i]).on('click', function() {
needToConfirm = false;
});
} else {
$(buttons[i]).on('click', confirm);
}
}

var inputs = configForm.getElementsByTagName("input");
for ( var i = 0; i < inputs.length; i++) {
$(inputs[i]).on('change', confirm);
if (inputs[i].type == 'checkbox' || inputs[i].type == 'radio') {
$(inputs[i]).on('click', confirm);
} else {
$(inputs[i]).on('keydown', confirm);
}
}

inputs = configForm.getElementsByTagName("select");
for ( var i = 0; i < inputs.length; i++) {
$(inputs[i]).on('keydown', confirm);
$(inputs[i]).on('click', confirm);
}

inputs = configForm.getElementsByTagName("textarea");
for ( var i = 0; i < inputs.length; i++) {
$(inputs[i]).on('keydown', confirm);
}
}

window.onbeforeunload = confirmExit;
Event.on(window,'load', initConfirm);

})();

0 comments on commit d3bce1e

Please sign in to comment.