[Bug #1090] Added JavaScript removed in one of the previous patches.

FEA: ItEr74S04BugFixing
This commit is contained in:
Manuel Rego Casasnovas 2011-06-16 18:15:28 +02:00
parent 18c91cbbe4
commit 6d28f88394
4 changed files with 64 additions and 0 deletions

View file

@ -27,6 +27,7 @@ import org.navalplanner.business.common.exceptions.ValidationException;
import org.navalplanner.business.users.entities.Profile;
import org.navalplanner.business.users.entities.User;
import org.navalplanner.business.users.entities.UserRole;
import org.navalplanner.web.users.bootstrap.MandatoryUser;
/**
* Model for UI operations related to {@link User}
@ -122,4 +123,6 @@ public interface IUserModel {
String getClearNewPassword();
boolean hasChangedDefaultPasswordOrDisabled(MandatoryUser admin);
}

View file

@ -38,8 +38,10 @@ import org.navalplanner.web.common.Util;
import org.navalplanner.web.common.components.Autocomplete;
import org.navalplanner.web.common.entrypoints.EntryPointsHandler;
import org.navalplanner.web.common.entrypoints.IURLHandlerRegistry;
import org.navalplanner.web.users.bootstrap.MandatoryUser;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Combobox;
import org.zkoss.zul.Comboitem;
@ -170,6 +172,7 @@ public class UserCRUDController extends GenericForwardComposer implements
userModel.confirmSave();
messagesForUser.showMessage(Level.INFO,
_("User saved"));
showOrHideDefaultPasswordWarnings();
return true;
} catch (ValidationException e) {
messagesForUser.showInvalidValues(e);
@ -177,6 +180,26 @@ public class UserCRUDController extends GenericForwardComposer implements
return false;
}
/**
* It calls a JavaScript method to show or hide the default password
* warnings if the user has changed the password or has been disabled
*/
private void showOrHideDefaultPasswordWarnings() {
boolean adminNotDefaultPassword = userModel
.hasChangedDefaultPasswordOrDisabled(MandatoryUser.ADMIN);
boolean userNotDefaultPassword = userModel
.hasChangedDefaultPasswordOrDisabled(MandatoryUser.USER);
boolean wsreaderNotDefaultPassword = userModel
.hasChangedDefaultPasswordOrDisabled(MandatoryUser.WSREADER);
boolean wswriterNotDefaultPassword = userModel
.hasChangedDefaultPasswordOrDisabled(MandatoryUser.WSWRITER);
Clients.evalJavaScript("showOrHideDefaultPasswordWarnings("
+ adminNotDefaultPassword + ", " + userNotDefaultPassword
+ ", " + wsreaderNotDefaultPassword + ", "
+ wswriterNotDefaultPassword + ");");
}
public User getUser() {
return userModel.getUser();
}

View file

@ -248,4 +248,11 @@ public class UserModel implements IUserModel {
public String getClearNewPassword() {
return clearNewPassword;
}
@Override
@Transactional(readOnly = true)
public boolean hasChangedDefaultPasswordOrDisabled(MandatoryUser user) {
return user.hasChangedDefaultPasswordOrDisabled();
}
}

View file

@ -29,6 +29,37 @@
<?component name="list" inline="true" macroURI="_listUsers.zul"?>
<?component name="edition" inline="true" macroURI="_editUser.zul"?>
<zk>
<script type="text/javascript">
<![CDATA[
function showOrHideDefaultPasswordWarnings(adminNotDefaultPassword,
userNotDefaultPassword, wsreaderNotDefaultPassword,
wswriterNotDefaultPassword) {
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdadmin"),
adminNotDefaultPassword);
var otherDefaultPassword = adminNotDefaultPassword &&
(!userNotDefaultPassword || !wsreaderNotDefaultPassword || !wswriterNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdOthers"),
!otherDefaultPassword);
if (otherDefaultPassword) {
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswduser"),
userNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdwsreader"),
wsreaderNotDefaultPassword);
setDisplayNoneOrInline(document.getElementById("warningDefaultPasswdwswriter"),
wswriterNotDefaultPassword);
}
}
function setDisplayNoneOrInline(component, boolean) {
component.style["display"] = boolean ? "none" : "inline";
}
]]>
</script>
<window self="@{define(content)}"
apply="org.navalplanner.web.users.UserCRUDController">
<vbox id="messagesContainer"></vbox>