Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
refactor(admin: confirm): migrate js confirm to modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Jul 28, 2016
1 parent ff84435 commit 9cae8f5
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 101 deletions.
Expand Up @@ -54,6 +54,7 @@ public class TranslationMemoryPage extends BasePage {
private By listDeleteButton = By.linkText("Delete");
private By deleteConfirmation = By.id("deleteTMModal");
private By clearConfirmation = By.id("clearTMModal");
private By uploadNotification = By.id("uploadTMNotification");
private By okConfirmation = By.id("confirm-ok-button");
private By cancelConfirmation = By.id("confirm-cancel-button");

Expand Down Expand Up @@ -91,7 +92,8 @@ public TranslationMemoryPage enterImportFileName(String importFileName) {
public TranslationMemoryPage clickUploadButtonAndAcknowledge() {
log.info("Click and accept Upload button");
clickElement(uploadButton);
switchToAlert().accept();
clickElement(
readyElement(uploadNotification).findElement(okConfirmation));
return new TranslationMemoryPage(getDriver());
}

Expand Down
Expand Up @@ -95,8 +95,12 @@ public List<HRoleAssignmentRule> getAllRules() {
return roleAssignmentRuleDAO.findAll();
}

public void remove(HRoleAssignmentRule rule) {
roleAssignmentRuleDAO.makeTransient(rule);
public void remove(String id) {
HRoleAssignmentRule rule = roleAssignmentRuleDAO.findById(new Long(id));
if (rule != null) {
roleAssignmentRuleDAO.makeTransient(rule);
roleAssignmentRuleDAO.flush();
}
}

public void setRoleToAssign(String roleName) {
Expand Down
6 changes: 5 additions & 1 deletion zanata-war/src/main/resources/messages.properties
Expand Up @@ -1080,6 +1080,7 @@ jsf.config.userEmail.description=If enabled, user email will be visible
jsf.CreateNewUser=Create new user
jsf.MemberOf=Member of
jsf.Enabled=Enabled
jsf.user.delete.title=Delete user
jsf.AreYouSureYouWishToDeleteThisUserThisActionCannotBeUndone=Are you sure you wish to delete this user? This action cannot be undone.
jsf.UserManager.delete.constraintViolation.error=This user cannot be removed from the system. You can deactivate the user instead.
jsf.AccountEnabled=Account enabled
Expand All @@ -1093,6 +1094,7 @@ jsf.account.notActivated=Account is not activated.
#------ [home] > Administration > Manage Roles > Role Details ------
jsf.CreateRole=Create Role
jsf.AreYouSureYouWishToDeleteThisRoleThisActionCannotBeUndone=Are you sure you wish to delete this role? This action cannot be undone.
jsf.role.delete.title=Delete role
jsf.Role=Role
jsf.RoleDetails=Role Details

Expand Down Expand Up @@ -1185,6 +1187,7 @@ jsf.rolerules.CreateRule=New Rule
jsf.rolerules.title=Rules
jsf.rolerules.CreateRoleAssignmentRule=Create Role Assignment Rule
jsf.rolerules.EditRoleAssignmentRule=Edit Role Assignment Rule
jsf.rolerules.delele.title=Delete rule
jsf.rolerules.ConfirmDelete=Are you sure you want to remove this rule?
jsf.rolerules.Description=<b>Role Assignment Rules</b> assist with the automatic assignment of user roles to certain users when they sign in. If the user's identity (e.g. user name) matches a certain pattern and they are authenticated in a certain way (e.g. via Open Id where available), Zanata will be able to automatically add the user to a specified user Role.
jsf.rolerules.PolicyName=Policy Name
Expand Down Expand Up @@ -1213,7 +1216,7 @@ jsf.processmanager.progress={0} of {1} complete
#------ [home] > Translation Memory ------
jsf.transmemory.Id=Id
jsf.transmemory.Title=Translation Memory
jsf.transmemory.Clear.Title=Clear the contents of a Translation Memory
jsf.transmemory.Clear.Title=Clear Translation Memory
jsf.transmemory.Clearing.Message=Clearing
jsf.transmemory.CreateNew = Create New
jsf.transmemory.ConfirmClearTM=Are you sure you want to remove all content from this Translation Memory?
Expand All @@ -1233,6 +1236,7 @@ jsf.transmemory.TransMemoryIdExample=Cannot include spaces and must be unique. E
jsf.transmemory.title.New = New Translation Memory
jsf.transmemory.TransMemoryNotFound = Translation Memory not found.
jsf.transmemory.createdOn=Created on
jsf.transmemory.upload.notification=Upload status


#------ [home] > Projects > [project-id] > [version-id] > [group-id] > Request To Join Group ------
Expand Down
36 changes: 26 additions & 10 deletions zanata-war/src/main/webapp/admin/rolemanager.xhtml
Expand Up @@ -4,8 +4,8 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
>
xmlns:zanata="http://java.sun.com/jsf/composite/zanata"
xmlns:a4j="http://richfaces.org/a4j">

<ui:composition template="../WEB-INF/template/template.xhtml">
<f:metadata>
Expand All @@ -16,10 +16,27 @@
<ui:define name="page_title">#{msgs['jsf.ManageRoles']}</ui:define>

<ui:define name="center_content">
<zanata:confirm-modal id="deleteRoleModal"
title="#{msgs['jsf.role.delete.title']}"
message="#{msgs['jsf.AreYouSureYouWishToDeleteThisRoleThisActionCannotBeUndone']}"
onresponse="onDeleteRoleResponse" />

<a4j:jsFunction name="deleteRole" action="#{identityManager.deleteRole(selectedRoleId)}" render="roles-form">
<a4j:param name="val1" assignTo="#{selectedRoleId}"/>
</a4j:jsFunction>

<script type="text/javascript">
function confirmDelete() {
return confirm("#{msgs['jsf.AreYouSureYouWishToDeleteThisRoleThisActionCannotBeUndone']}");
var selectedRoleId;
function setSelectedRole(id) {
selectedRoleId = id;
}
function onDeleteRoleResponse(del) {
if (del) {
deleteRole(selectedRoleId);
} else {
selectedRoleId = null;
}
zanata.modal.hide('#deleteRoleModal');
}
</script>
<div class="g--centered">
Expand Down Expand Up @@ -56,7 +73,7 @@
</div>
<h2 class="panel__heading">#{msgs['jsf.admin.managerole.header']}</h2>
</div>
<h:form styleClass="l--push-bottom-0">
<h:form styleClass="l--push-bottom-0" id="roles-form">
<ul class="list--stats">
<ui:repeat value="#{zanataRoleSearch.roles}" var="role">
<li class="list__item--actionable">
Expand All @@ -71,12 +88,11 @@
<ui:fragment
rendered="#{identity.hasPermission('seam.role', 'delete') and accountRoleDAO.findByName(role).roleType.toString() ne 'AUTO'}">
<li>
<h:commandLink
action="#{identityManager.deleteRole(role)}"
onclick="return confirmDelete()"
styleClass="i__item--right txt--danger">#{msgs['jsf.Delete']}
<a href="#" class="i__item--right txt--danger" onclick="setSelectedRole('#{role.id}')"
data-toggle="modal" data-target="#deleteRoleModal">
#{msgs['jsf.Delete']}
<i class="i i--remove i__item__icon"></i>
</h:commandLink>
</a>
</li>
</ui:fragment>
</ul>
Expand Down
135 changes: 77 additions & 58 deletions zanata-war/src/main/webapp/admin/rolerules.xhtml
Expand Up @@ -5,7 +5,8 @@
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich"
>
xmlns:zanata="http://java.sun.com/jsf/composite/zanata"
xmlns:a4j="http://richfaces.org/a4j">

<ui:composition template="../WEB-INF/template/template.xhtml">
<f:metadata>
Expand All @@ -16,9 +17,27 @@
name="page_title">#{msgs['jsf.RoleAssignmentRules']}</ui:define>

<ui:define name="center_content">
<zanata:confirm-modal id="deleteRuleModal"
title="#{msgs['jsf.rolerules.delele.title']}"
message="#{msgs['jsf.rolerules.ConfirmDelete']}"
onresponse="onDeleteRuleResponse" />

<a4j:jsFunction name="deleteRule" action="#{roleAssignmentRuleAction.remove(rule)}" render="rules-content">
<a4j:param name="val1" assignTo="#{rule}"/>
</a4j:jsFunction>

<script type="text/javascript">
function confirmDelete() {
return confirm("#{msgs['jsf.rolerules.ConfirmDelete']}");
var selectedRule;
function setSelectedRule(rule) {
selectedRule = rule;
}
function onDeleteRuleResponse(del) {
if (del) {
deleteRule(selectedRule);
} else {
selectedRule = null;
}
zanata.modal.hide('#deleteRuleModal');
}
</script>

Expand Down Expand Up @@ -56,66 +75,66 @@
<h2 class="panel__heading">#{msgs['jsf.rolerules.title']}</h2>
</div>

<h:panelGroup layout="block" styleClass="l--pad-all-half"
rendered="#{empty roleAssignmentRuleAction.allRules}">
<p class="txt--meta">#{msgs['jsf.rolerules.norules']}</p>
<p>
<h:link value="#{msgs['jsf.rolerules.CreateRule']}"
outcome="/admin/roleruledetails.xhtml" styleClass="button button--primary">
<i class="i i--plus i__item__icon"></i>
</h:link>
</p>
</h:panelGroup>

<h:panelGroup layout="block" id="rules-content">
<h:panelGroup layout="block" styleClass="l--pad-all-half"
rendered="#{empty roleAssignmentRuleAction.allRules}">
<p class="txt--meta">#{msgs['jsf.rolerules.norules']}</p>
<p>
<h:link value="#{msgs['jsf.rolerules.CreateRule']}"
outcome="/admin/roleruledetails.xhtml" styleClass="button button--primary">
<i class="i i--plus i__item__icon"></i>
</h:link>
</p>
</h:panelGroup>

<h:form styleClass="l--push-bottom-0" id="roleRules"
rendered="#{not empty roleAssignmentRuleAction.allRules}">
<ul class="list--stats">
<ui:repeat value="#{roleAssignmentRuleAction.allRules}" var="rule">
<li class="list__item--actionable">
<div class="list__item__action">
<div
class="dropdown dropdown--small dropdown--inline dropdown--single list__item__dropdown js-dropdown">
<a href="#" title="Options"
class="dropdown__toggle js-dropdown__toggle txt--meta">
<span class="is-invisible">Options</span>
</a>
<ul class="dropdown__content js-dropdown__content">
<li>
<h:commandLink value="#{msgs['jsf.Delete']}"
action="#{roleAssignmentRuleAction.remove(rule)}"
onclick="return confirmDelete()"
styleClass="i__item--right txt--danger">
<i class="i i--remove i__item__icon"></i>
</h:commandLink>
</li>
</ul>
<h:form styleClass="l--push-bottom-0" id="roleRules"
rendered="#{not empty roleAssignmentRuleAction.allRules}">
<ul class="list--stats">
<ui:repeat value="#{roleAssignmentRuleAction.allRules}" var="rule">
<li class="list__item--actionable">
<div class="list__item__action">
<div
class="dropdown dropdown--small dropdown--inline dropdown--single list__item__dropdown js-dropdown">
<a href="#" title="Options"
class="dropdown__toggle js-dropdown__toggle txt--meta">
<span class="is-invisible">Options</span>
</a>
<ul class="dropdown__content js-dropdown__content">
<li>
<a href="#" class="i__item--right txt--danger" onclick="setSelectedRule('#{rule.id}')"
data-toggle="modal" data-target="#deleteRuleModal">
#{msgs['jsf.Delete']}
<i class="i i--remove i__item__icon"></i>
</a>
</li>
</ul>
</div>
</div>
</div>
<h:link outcome="/admin/roleruledetails.xhtml">
<f:param name="id" value="#{rule.id}" />
<div class="list__item__content">
<div class="list__item__info">
<h3 class="list__title">
#{rule.policyName}
<span class="txt--meta l--push-left-quarter l--push-right-half">
<h:outputFormat value="#{msgs['jsf.rolerules.Role']}">
<f:param value="#{rule.roleToAssign.name}" />
<h:link outcome="/admin/roleruledetails.xhtml">
<f:param name="id" value="#{rule.id}" />
<div class="list__item__content">
<div class="list__item__info">
<h3 class="list__title">
#{rule.policyName}
<span class="txt--meta l--push-left-quarter l--push-right-half">
<h:outputFormat value="#{msgs['jsf.rolerules.Role']}">
<f:param value="#{rule.roleToAssign.name}" />
</h:outputFormat>
</span>
</h3>
<span class="list__item__meta">
<h:outputFormat value="#{msgs['jsf.rolerules.Pattern']}">
<f:param value="#{rule.identityRegExp}" />
</h:outputFormat>
</span>
</h3>
<span class="list__item__meta">
<h:outputFormat value="#{msgs['jsf.rolerules.Pattern']}">
<f:param value="#{rule.identityRegExp}" />
</h:outputFormat>
</span>
</div>
</div>
</div>
</h:link>
</li>
</ui:repeat>
</ul>
</h:form>
</h:link>
</li>
</ui:repeat>
</ul>
</h:form>
</h:panelGroup>
</div>
</div>
</div>
Expand Down
46 changes: 29 additions & 17 deletions zanata-war/src/main/webapp/admin/usermanager.xhtml
Expand Up @@ -18,8 +18,33 @@

<ui:define name="page_title">#{msgs['jsf.ManageUsers']}</ui:define>
<ui:define name="center_content">


<zanata:confirm-modal id="deleteUserModal"
title="#{msgs['jsf.user.delete.title']}"
message="#{msgs['jsf.AreYouSureYouWishToDeleteThisUserThisActionCannotBeUndone']}"
onresponse="onDeleteUserResponse" />

<h:form>
<a4j:jsFunction name="deleteUser"
action="#{userAction.deleteUser(username)}" render="usermanagerForm,
userSearch-pager, userSearch-page-info, userSearchBottom-pager, userSearchBottom-page-info">
<a4j:param name="val1" assignTo="#{username}"/>
</a4j:jsFunction>
</h:form>

<script type="text/javascript">
var selectedUser;
function setSelectedUser(user) {
selectedUser = user;
}
function onDeleteUserResponse(del) {
if (del) {
deleteUser(selectedUser);
} else {
selectedUser = null;
}
zanata.modal.hide('#deleteUserModal');
}
</script>

<div class="g--centered">
<div class="g__item w--2-3 l--push-bottom-half">
Expand Down Expand Up @@ -51,19 +76,6 @@
</a4j:status>

<h:form id="usermanagerForm" styleClass="l--push-bottom-0">

<a4j:jsFunction name="deleteUser"
action="#{userAction.deleteUser(username)}" render="usermanagerForm,
userSearch-pager, userSearch-page-info, userSearchBottom-pager, userSearchBottom-page-info">
<a4j:param name="val1" assignTo="#{username}"/>
</a4j:jsFunction>

<script type="text/javascript">
function confirmDelete() {
return confirm("#{msgs['jsf.AreYouSureYouWishToDeleteThisUserThisActionCannotBeUndone']}");
}
</script>

<ul class="list--stats">
<ui:repeat value="#{userAction.userFilter.currentPage}"
var="user">
Expand All @@ -79,8 +91,8 @@
<ui:fragment
rendered="#{identity.hasPermission('seam.user', 'delete')}">
<li>
<a onclick="if(confirmDelete()){deleteUser('#{user}')};return false;"
class="i__item--right txt--danger">
<a href="#" class="i__item--right txt--danger" onclick="setSelectedUser('#{user}')"
data-toggle="modal" data-target="#deleteUserModal">
#{msgs['jsf.Delete']}
<i class="i i--remove i__item__icon"></i>
</a>
Expand Down

0 comments on commit 9cae8f5

Please sign in to comment.