Skip to content

Commit

Permalink
Merge pull request #1175 from daniel-beck/JENKINS-21720-2
Browse files Browse the repository at this point in the history
[FIXED JENKINS-20597 JENKINS-21720] Improved config confirmation.
  • Loading branch information
olivergondza committed Apr 18, 2014
2 parents 803f91d + ee64eb9 commit fc47115
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 10 deletions.
Expand Up @@ -71,6 +71,7 @@ THE SOFTWARE.
<f:submit value="${%Save}" />
</f:block>
</f:form>
<st:adjunct includes="lib.form.confirm" />
</l:main-panel>
</l:layout>
</j:jelly>
Expand Up @@ -46,6 +46,7 @@ THE SOFTWARE.
<f:submit value="${%Save}"/>
</f:bottomButtonBar>
</f:form>
<st:adjunct includes="lib.form.confirm" />
</l:main-panel>
</l:layout>
</j:jelly>
3 changes: 2 additions & 1 deletion core/src/main/resources/hudson/model/ComputerSet/_new.jelly
Expand Up @@ -31,7 +31,7 @@ THE SOFTWARE.
<l:layout norefresh="true" permission="${it.CREATE}">
<st:include page="sidepanel.jelly"/>
<l:main-panel>
<f:form method="post" action="doCreateItem">
<f:form method="post" action="doCreateItem" name="config">
<f:entry title="${%Name}" help="/help/system-config/master-slave/name.html">
<f:textbox name="name" value="${request.getParameter('name')}" clazz="required" checkMessage="${%Name is mandatory}"/>
</f:entry>
Expand All @@ -46,6 +46,7 @@ THE SOFTWARE.
<f:submit value="${%Save}"/>
</f:block>
</f:form>
<st:adjunct includes="lib.form.confirm" />
</l:main-panel>
</l:layout>
</j:jelly>
Expand Up @@ -44,6 +44,7 @@ THE SOFTWARE.
<f:apply />
</f:bottomButtonBar>
</f:form>
<st:adjunct includes="lib.form.confirm" />
</l:main-panel>
</l:layout>
</j:jelly>
4 changes: 3 additions & 1 deletion core/src/main/resources/hudson/model/Job/configure.jelly
Expand Up @@ -68,7 +68,9 @@ THE SOFTWARE.
</f:bottomButtonBar>
</j:if>
</f:form>
<st:adjunct includes="lib.form.confirm" />
<j:if test="${h.hasPermission(it,it.CONFIGURE)}">
<st:adjunct includes="lib.form.confirm" />
</j:if>
</l:main-panel>
</l:layout>
</j:jelly>
3 changes: 3 additions & 0 deletions core/src/main/resources/hudson/model/Run/configure.jelly
Expand Up @@ -43,6 +43,9 @@ THE SOFTWARE.
</f:bottomButtonBar>
</j:if>
</f:form>
<j:if test="${h.hasPermission(it,it.UPDATE)}">
<st:adjunct includes="lib.form.confirm" />
</j:if>
</l:main-panel>
</l:layout>
</j:jelly>
1 change: 1 addition & 0 deletions core/src/main/resources/hudson/model/User/configure.jelly
Expand Up @@ -59,6 +59,7 @@ THE SOFTWARE.
<f:apply />
</f:bottomButtonBar>
</f:form>
<st:adjunct includes="lib.form.confirm" />
</l:main-panel>
</l:layout>
</j:jelly>
1 change: 1 addition & 0 deletions core/src/main/resources/hudson/model/View/configure.jelly
Expand Up @@ -59,6 +59,7 @@ THE SOFTWARE.
<f:apply />
</f:bottomButtonBar>
</f:form>
<st:adjunct includes="lib.form.confirm" />
</l:main-panel>
</l:layout>
</j:jelly>
Expand Up @@ -43,6 +43,7 @@ THE SOFTWARE.
<f:submit value="${%Save}"/>
</f:block>
</f:form>
<st:adjunct includes="lib.form.confirm" />
</l:main-panel>
</l:layout>
</j:jelly>
Expand Up @@ -56,6 +56,8 @@ l.layout(norefresh:true, permission:app.ADMINISTER, title:my.displayName) {
f.apply()
}
}

st.adjunct(includes: "lib.form.confirm")
}
}

Expand Up @@ -65,6 +65,7 @@ THE SOFTWARE.
<f:apply />
</f:bottomButtonBar>
</f:form>
<st:adjunct includes="lib.form.confirm" />
</l:main-panel>
</l:layout>
</j:jelly>
47 changes: 39 additions & 8 deletions core/src/main/resources/lib/form/confirm.js
Expand Up @@ -6,48 +6,79 @@
needToConfirm = true;
}

function clearConfirm() {
needToConfirm = false;
}

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

function isModifyingButton(btn) {
// TODO don't consider hetero list 'add' buttons
// needs to handle the yui menus instead
// if (btn.classList.contains("hetero-list-add")) {
// return false;
// }

if (btn.parentNode.parentNode.classList.contains("advanced-button")) {
// don't consider 'advanced' buttons
return false;
}

// default to true
return true;
}

function initConfirm() {
var configForm = document.getElementsByName("config")[0];
// Timeout is needed since some events get sent on page load for some reason.
// Shouldn't hurt anything for this to only start monitoring events after a few millis;.
setTimeout(function() {
var configForm = document.getElementsByName("config");
if (configForm.length > 0) {
configForm = configForm[0]
} else {
configForm = document.getElementsByName("viewConfig")[0];
}

YAHOO.util.Event.on($(configForm), "submit", clearConfirm, this);

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

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

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

window.onbeforeunload = confirmExit;
Expand Down

0 comments on commit fc47115

Please sign in to comment.