Skip to content
Permalink
Browse files
Merge pull request #1175 from daniel-beck/JENKINS-21720-2
[FIXED JENKINS-20597 JENKINS-21720] Improved config confirmation.
  • Loading branch information
olivergondza committed Apr 18, 2014
2 parents 803f91d + ee64eb9 commit fc471153db957be8d06d2fea63306e8b2f060462
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -56,6 +56,8 @@ l.layout(norefresh:true, permission:app.ADMINISTER, title:my.displayName) {
f.apply()
}
}

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

@@ -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>
@@ -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;

0 comments on commit fc47115

Please sign in to comment.