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

Commit

Permalink
WIP: project settings - role restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Feb 17, 2014
1 parent e1dba82 commit ebf3af7
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 71 deletions.
28 changes: 15 additions & 13 deletions zanata-war/src/main/java/org/zanata/action/ProjectHome.java
Expand Up @@ -188,7 +188,7 @@ public void onSelectItemAction() {
HLocale locale =
localeServiceImpl.getByLocaleId(getSelectedItem());

if(!getInstance().isOverrideLocales()) {
if (!getInstance().isOverrideLocales()) {
getInstance().setOverrideLocales(true);
getInstance().getCustomizedLocales().clear();
}
Expand All @@ -205,7 +205,7 @@ public void onSelectItemAction() {
};

public void setSelectedProjectType(String selectedProjectType) {
if (!StringUtils.isEmpty(selectedProjectType)) {
if (!StringUtils.isEmpty(selectedProjectType) && !selectedProjectType.equals("null")) {
ProjectType projectType = ProjectType.valueOf(selectedProjectType);
getInstance().setDefaultProjectType(projectType);
} else {
Expand Down Expand Up @@ -475,7 +475,7 @@ public int compare(HAccountRole o1, HAccountRole o2) {
/**
* Use FlashScopeBean to store message in page. Multiple ajax requests for
* re-rendering statistics after updating will clear FacesMessages.
*
*
* @param severity
* @param message
*/
Expand Down Expand Up @@ -600,27 +600,29 @@ private Map<ValidationId, ValidationAction> getValidations() {

@Restrict("#{s:hasPermission(projectHome.instance, 'update')}")
public void updateValidationOption(String name, String state) {
ValidationId validatationId = ValidationId.valueOf(name);

for (Map.Entry<String, String> entry : getInstance()
.getCustomizedValidations().entrySet()) {
if (entry.getKey().equals(name)) {
entry.setValue(state);
getValidations().get(ValidationId.valueOf(name)).setState(
for (Map.Entry<ValidationId, ValidationAction> entry : getValidations()
.entrySet()) {
if (entry.getKey().name().equals(name)) {
getValidations().get(validatationId).setState(
ValidationAction.State.valueOf(state));
ensureMutualExclusivity(getValidations().get(validatationId));
break;
}
getInstance().getCustomizedValidations().put(entry.getKey().name(),
entry.getValue().getState().name());
}
ensureMutualExclusivity(getValidations()
.get(ValidationId.valueOf(name)));

update();
addMessage(StatusMessage.Severity.INFO, zanataMessages.getMessage(
"jsf.project.validation.updated", name, state));
"jsf.project.validation.updated",
validatationId.getDisplayName(), state));
}

public List<ValidationAction> getValidationList() {
List<ValidationAction> sortedList =
new ArrayList<ValidationAction>(getValidations().values());
Lists.newArrayList(getValidations().values());
Collections.sort(sortedList,
ValidationFactory.ValidationActionComparator);
return sortedList;
Expand All @@ -629,7 +631,7 @@ public List<ValidationAction> getValidationList() {
/**
* If this action is enabled(Warning or Error), then it's exclusive
* validation will be turn off
*
*
* @param selectedValidationAction
*/
private void ensureMutualExclusivity(
Expand Down
Expand Up @@ -32,9 +32,9 @@
import com.google.gwt.regexp.shared.RegExp;

/**
*
*
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a>
*
*
**/
public class XmlEntityValidation extends AbstractValidationAction {
// &amp;, &quot;
Expand Down Expand Up @@ -85,7 +85,7 @@ private List<String> validateIncompleteEntity(String target) {

/**
* Replace matched string with empty string
*
*
* @param regex
* @param text
* @return
Expand All @@ -103,11 +103,11 @@ private List<String> validateIncompleteEntity(String target) {

@Override
public String getSourceExample() {
return "Pepper &amp; salt";
return "Pepper &amp;amp; salt";
}

@Override
public String getTargetExample() {
return "Pepper &amp<span class='js-example__target txt--warning'>missing ;</span> salt";
return "Pepper amp<span class='js-example__target txt--warning'> incomplete entity, missing '& and ;'</span> salt";
}
}
71 changes: 43 additions & 28 deletions zanata-war/src/main/webapp/WEB-INF/layout/project/edit_form.xhtml
Expand Up @@ -7,6 +7,14 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://richfaces.org/rich">

<script>
function onProjectTypeChanged(radioForm) {
var id = jQuery(radioForm).children(".form__radio__input").attr("id");
var selectedProjectType = id.substring('project-type-'.length, id.length);
bindProjectTypeValue(selectedProjectType);
}

</script>
<a4j:jsFunction name="bindProjectTypeValue" limitRender="true">
<a4j:param name="val" assignTo="#{projectHome.selectedProjectType}"/>
</a4j:jsFunction>
Expand Down Expand Up @@ -45,7 +53,7 @@
</div>

<div class="form__item l--push-bottom-1">
<h:outputLabel for="id">#{messages['jsf.ProjectDescription']}
<h:outputLabel for="descriptionField">#{messages['jsf.ProjectDescription']}
<span class="txt--meta">#{messages['jsf.field.optional']}</span>
</h:outputLabel>
<s:decorate id="descriptionField" template="../field.xhtml">
Expand All @@ -66,40 +74,47 @@
<i class="i i--help"></i>
</a>
</p>

<ul class="list--slat l--push-bottom-1">
<li>
<s:fragment rendered="#{projectHome.instance.defaultProjectType eq null}">
<input type="radio" name="project-type" id="project-type-null"
checked="true" class="form__radio__input" onchange="bindProjectTypeValue('')"/>
</s:fragment>
<s:fragment rendered="#{projectHome.instance.defaultProjectType ne null}">
<input type="radio" name="project-type" id="project-type-null"
class="form__radio__input" onchange="bindProjectTypeValue('')"/>
</s:fragment>
<label for="project-type-null"
class="form__radio__label">#{messages['jsf.projectType.NoSelection']}
</label>
</li>

<ui:repeat value="#{projectHome.projectTypeList}" var="projectType">
<li class="form__radio">
<div class="form__radio js-form__radio"
onclick="onProjectTypeChanged(this)">
<s:fragment
rendered="#{projectHome.instance.defaultProjectType.name() eq projectType.name()}">
<input type="radio" name="project-type" class="form__radio__input"
id="project-type-#{projectType.name()}" checked="true"
onchange="bindProjectTypeValue(this.id.substring('project-type-'.length, this.id.length))"/>
rendered="#{projectHome.instance.defaultProjectType eq null}">
<input type="radio" name="project-type" id="project-type-null"
checked="true" class="form__radio__input js-form__radio__input"/>
</s:fragment>
<s:fragment
rendered="#{projectHome.instance.defaultProjectType.name() ne projectType.name()}">
<input type="radio" name="project-type" class="form__radio__input"
id="project-type-#{projectType.name()}"
onchange="bindProjectTypeValue(this.id.substring('project-type-'.length, this.id.length))"/>
rendered="#{projectHome.instance.defaultProjectType ne null}">
<input type="radio" name="project-type" id="project-type-null"
class="form__radio__input js-form__radio__input"/>
</s:fragment>
<label for="project-type-#{projectType.name()}"
class="form__radio__label">#{projectType.name()} <span
class="txt--meta">#{messages['jsf.projectType.detail.'.concat(projectType)]}</span>
<label for="project-type-null"
class="form__radio__label">#{messages['jsf.projectType.NoSelection']}
</label>
</div>
</li>

<ui:repeat value="#{projectHome.projectTypeList}" var="projectType">
<li>
<div class="form__radio js-form__radio"
onclick="onProjectTypeChanged(this)">
<s:fragment
rendered="#{projectHome.instance.defaultProjectType.name() eq projectType.name()}">
<input type="radio" name="project-type"
class="form__radio__input js-form__radio__input"
id="project-type-#{projectType.name()}" checked="true"/>
</s:fragment>
<s:fragment
rendered="#{projectHome.instance.defaultProjectType.name() ne projectType.name()}">
<input type="radio" name="project-type"
class="form__radio__input js-form__radio__input"
id="project-type-#{projectType.name()}"/>
</s:fragment>
<label for="project-type-#{projectType.name()}"
class="form__radio__label">#{projectType.name()} <span
class="txt--meta">#{messages['jsf.projectType.detail.'.concat(projectType)]}</span>
</label>
</div>
</li>
</ui:repeat>
</ul>
Expand Down
Expand Up @@ -18,6 +18,12 @@
var value = validationId.split('-');
bindValidationValue(value[0], value[1]);
}

jQuery(document).ready(function () {
jQuery('.js-form__checkbox.restricted-by-role-form').click(function () {
bindRestrictedByRoleValue(!jQuery(this).children(".js-form__checkbox__input").is(':checked'))
});
});
</script>

<a4j:jsFunction name="bindValidationValue"
Expand All @@ -34,6 +40,12 @@
<a4j:param name="val2" assignTo="#{value}"/>
</a4j:jsFunction>

<a4j:jsFunction name="bindRestrictedByRoleValue" limitRender="true"
render="user-roles">
<a4j:param name="val"
assignTo="#{projectHome.instance.restrictedByRoles}"/>
</a4j:jsFunction>

<h1>#{messages['jsf.Settings']}</h1>

<div class="tabs--vertical js-tabs">
Expand Down Expand Up @@ -200,8 +212,7 @@
<s:div id="validation-list">
<ul class="list--slat">
<ui:repeat
value="#{projectHome.validationList}"
var="validationAction">
value="#{projectHome.validationList}" var="validationAction">
<li class="js-example js-reveal">
<div class="g--tight">
<div class="g__item w--7-12">
Expand Down Expand Up @@ -340,30 +351,37 @@
<hr/>

<div class="l--push-bottom-half">
<div class="form__checkbox">
<h:selectBooleanCheckbox styleClass="form__checkbox__input"
id="restrict-access"
value="#{projectHome.instance.restrictedByRoles}">
<a4j:ajax event="change" render="user-roles"/>
</h:selectBooleanCheckbox>
<label for="#{rich:clientId('restrict-access')}"
class="form__checkbox__label l--push-bottom-0"
<div class="form__checkbox js-form__checkbox restricted-by-role-form">
<s:fragment rendered="#{projectHome.instance.restrictedByRoles}">
<input type="checkbox" id="restrict-access"
class="form__checkbox__input js-form__checkbox__input"
checked="true"/>
</s:fragment>
<s:fragment rendered="#{!projectHome.instance.restrictedByRoles}">
<input type="checkbox" id="restrict-access"
class="form__checkbox__input js-form__checkbox__input"/>
</s:fragment>
<label for="restrict-access"
class="form__checkbox__label js-form__checkbox__label js-reveal__toggle l--push-bottom-0"
data-target="#user-roles">#{messages['jsf.RestrictRoleAccessMessage']}</label>
</div>
<s:div
styleClass="#{projectHome.instance.restrictedByRoles?'is-active': 'is-hidden'} bg--high l--pad-top-quarter l--pad-h-quarter"
id="user-roles">
<ul class="g--tighter">
<ui:repeat value="#{projectHome.availableRoles}" var="role">
<li class="form__checkbox g__item w--1-3 w--1-2-s">
<h:selectBooleanCheckbox id="role"
styleClass="form__checkbox__input"
value="#{projectHome.roleRestrictions[role.name]}">
<a4j:ajax event="click" render="pageMessages"
listener="#{projectHome.updateRoles()}"/>
</h:selectBooleanCheckbox>
<label for="#{rich:clientId('role')}"
class="form__checkbox__label">#{role.name}</label>
<li class="g__item w--1-3 w--1-2-s">
<div class="form__checkbox js-form__checkbox">
<h:selectBooleanCheckbox id="role"
styleClass="form__checkbox__input js-form__checkbox__input"
value="#{projectHome.roleRestrictions[role.name]}">
<a4j:ajax event="change" render="pageMessages"
listener="#{projectHome.updateRoles()}"/>
</h:selectBooleanCheckbox>

<label for="#{role.name}"
class="form__checkbox__label js-form__checkbox__label">#{role.name}</label>
</div>
</li>
</ui:repeat>
</ul>
Expand Down
Expand Up @@ -3,7 +3,8 @@
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:zanata="http://java.sun.com/jsf/composite/zanata"
xmlns:f="http://java.sun.com/jsf/core">
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j">

<div class="panel">
<div class="panel__header">
Expand Down Expand Up @@ -146,7 +147,11 @@
value="#{projectHomeAction.getStatisticForVersion(versionItem.version.slug)}"
rendered="#{projectHomeAction.pageRendered}"/>

<zanata:loader rendered="#{!projectHomeAction.pageRendered}"/>
<a4j:status name="statistic-loader">
<f:facet name="start">
<zanata:loader/>
</f:facet>
</a4j:status>
</s:link>
</li>
</ui:repeat>
Expand Down
8 changes: 4 additions & 4 deletions zanata-war/src/main/webapp/project/project.xhtml
Expand Up @@ -20,11 +20,11 @@
});
</script>
<h:form>
<a4j:jsFunction name="refreshStatistics" render="versions_form"
action="#{projectHomeAction.resetPageData}"/>
<a4j:jsFunction name="refreshStatistics" status="statistic-loader"
render="versions_form" action="#{projectHomeAction.resetPageData}"/>

<a4j:jsFunction name="renderStatistics" render="versions_form"
action="#{projectHomeAction.setPageRendered(true)}"/>
<a4j:jsFunction name="renderStatistics" status="statistic-loader"
render="versions_form" action="#{projectHomeAction.setPageRendered(true)}"/>
</h:form>

<div class="g">
Expand Down

0 comments on commit ebf3af7

Please sign in to comment.