This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Project version group - implemented add group by admin
- Loading branch information
Alex Eng
committed
Apr 12, 2012
1 parent
f2ad51b
commit d097eaf
Showing
10 changed files
with
250 additions
and
62 deletions.
There are no files selected for viewing
55 changes: 0 additions & 55 deletions
55
server/zanata-war/src/main/java/org/zanata/action/VersionGroupAction.java
This file was deleted.
Oops, something went wrong.
149 changes: 149 additions & 0 deletions
149
server/zanata-war/src/main/java/org/zanata/action/VersionGroupHome.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
* Copyright 2012, Red Hat, Inc. and individual contributors as indicated by the | ||
* @author tags. See the copyright.txt file in the distribution for a full | ||
* listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it under the | ||
* terms of the GNU Lesser General Public License as published by the Free | ||
* Software Foundation; either version 2.1 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
* details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this software; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF | ||
* site: http://www.fsf.org. | ||
*/ | ||
package org.zanata.action; | ||
|
||
import java.util.List; | ||
|
||
import javax.faces.event.ValueChangeEvent; | ||
import javax.persistence.NoResultException; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.criterion.NaturalIdentifier; | ||
import org.hibernate.criterion.Restrictions; | ||
import org.jboss.seam.annotations.In; | ||
import org.jboss.seam.annotations.Name; | ||
import org.jboss.seam.annotations.datamodel.DataModel; | ||
import org.jboss.seam.faces.FacesMessages; | ||
import org.zanata.common.EntityStatus; | ||
import org.zanata.model.HIterationGroup; | ||
import org.zanata.service.VersionGroupService; | ||
|
||
/** | ||
* @author Alex Eng <a href="mailto:aeng@redhat.com">aeng@redhat.com</a> | ||
*/ | ||
|
||
@Name("versionGroupHome") | ||
public class VersionGroupHome extends SlugHome<HIterationGroup> | ||
{ | ||
private String slug; | ||
|
||
private EntityStatus status = EntityStatus.ACTIVE; | ||
|
||
@In | ||
private VersionGroupService versionGroupServiceImpl; | ||
|
||
@DataModel | ||
List<HIterationGroup> allVersionGroups; | ||
|
||
@Override | ||
protected HIterationGroup loadInstance() | ||
{ | ||
Session session = (Session) getEntityManager().getDelegate(); | ||
return (HIterationGroup) session.createCriteria(getEntityClass()).add(Restrictions.naturalId().set("slug", getSlug())).setCacheable(true).uniqueResult(); | ||
} | ||
|
||
public void loadAllActiveGroups() | ||
{ | ||
allVersionGroups = versionGroupServiceImpl.getAllActiveVersionGroups(); | ||
} | ||
|
||
@Override | ||
public NaturalIdentifier getNaturalId() | ||
{ | ||
return Restrictions.naturalId().set("slug", slug); | ||
} | ||
|
||
@Override | ||
public boolean isIdDefined() | ||
{ | ||
return slug != null; | ||
} | ||
|
||
@Override | ||
public Object getId() | ||
{ | ||
return slug; | ||
} | ||
|
||
public String getSlug() | ||
{ | ||
return slug; | ||
} | ||
|
||
public void setSlug(String slug) | ||
{ | ||
this.slug = slug; | ||
} | ||
|
||
public void validateSuppliedId() | ||
{ | ||
getInstance(); // this will raise an EntityNotFound exception | ||
// when id is invalid and conversation will not | ||
// start | ||
} | ||
|
||
public void verifySlugAvailable(ValueChangeEvent e) | ||
{ | ||
String slug = (String) e.getNewValue(); | ||
validateSlug(slug, e.getComponent().getId()); | ||
} | ||
|
||
public boolean validateSlug(String slug, String componentId) | ||
{ | ||
if (!isSlugAvailable(slug)) | ||
{ | ||
FacesMessages.instance().addToControl(componentId, "This slug is not available"); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public boolean isSlugAvailable(String slug) | ||
{ | ||
try | ||
{ | ||
getEntityManager().createQuery("from HIterationGroup g where g.slug = :slug").setParameter("slug", slug).getSingleResult(); | ||
return false; | ||
} | ||
catch (NoResultException e) | ||
{ | ||
// pass | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public String persist() | ||
{ | ||
if (!validateSlug(getInstance().getSlug(), "slug")) | ||
return null; | ||
getInstance().setStatus(status); | ||
|
||
return super.persist(); | ||
} | ||
|
||
@Override | ||
public String update() | ||
{ | ||
String state = super.update(); | ||
return state; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
server/zanata-war/src/main/webapp/WEB-INF/layout/version_group_details_form.xhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<a4j:form id="projectForm" | ||
xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:s="http://jboss.com/products/seam/taglib" | ||
xmlns:ui="http://java.sun.com/jsf/facelets" | ||
xmlns:f="http://java.sun.com/jsf/core" | ||
xmlns:h="http://java.sun.com/jsf/html" | ||
xmlns:rich="http://richfaces.org/rich" | ||
xmlns:a4j="http://richfaces.org/a4j" | ||
> | ||
|
||
<s:token allowMultiplePosts="true" /> | ||
<rich:panel> | ||
<s:decorate id="slugField" template="edit.xhtml"> | ||
<ui:define name="label">#{messages['jsf.VersionGroupId']}</ui:define> | ||
<h:outputText rendered="#{versionGroupHome.managed}" value="#{versionGroupHome.instance.slug}" /> | ||
<h:inputText rendered="#{not versionGroupHome.managed}" | ||
id="slug" required="true" | ||
value="#{versionGroupHome.instance.slug}" | ||
valueChangeListener="#{versionGroupHome.verifySlugAvailable}"> | ||
<a4j:support event="onblur" reRender="slugField" ajaxSingle="true"/> | ||
</h:inputText> | ||
<h:graphicImage id="slugHelp" value="/public-img/msginfo.png" styleClass="input_help"> | ||
<rich:toolTip> | ||
<em><code>#{messages['jsf.VersionGroupIdExample']}</code></em> | ||
</rich:toolTip> | ||
</h:graphicImage> | ||
</s:decorate> | ||
|
||
<s:decorate id="nameField" template="edit.xhtml"> | ||
<ui:define name="label">#{messages['jsf.Name']}</ui:define> | ||
<h:inputText id="name" required="true" | ||
value="#{versionGroupHome.instance.name}"/> | ||
</s:decorate> | ||
|
||
<s:decorate id="descriptionField" template="edit.xhtml"> | ||
<ui:define name="label">#{messages['jsf.Description']}</ui:define> | ||
<h:inputText id="description" required="false" | ||
value="#{versionGroupHome.instance.description}" style="width:400px;"/> | ||
</s:decorate> | ||
|
||
<div style="clear:both"></div> | ||
|
||
</rich:panel> | ||
|
||
<div class="actionButtons"><h:commandButton | ||
value="#{messages['jsf.Save']}" | ||
action="#{versionGroupHome.persist}" /> <s:button | ||
view="/admin/versiongroupmanager.xhtml" | ||
value="#{messages['jsf.Cancel']}" propagation="end" /> | ||
</div> | ||
|
||
</a4j:form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
server/zanata-war/src/main/webapp/admin/versiongroupdetails.xhtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
<ui:composition xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:s="http://jboss.com/products/seam/taglib" | ||
xmlns:ui="http://java.sun.com/jsf/facelets" | ||
xmlns:f="http://java.sun.com/jsf/core" | ||
xmlns:h="http://java.sun.com/jsf/html" | ||
xmlns:rich="http://richfaces.org/rich" | ||
xmlns:a4j="http://richfaces.org/a4j" | ||
template="../WEB-INF/layout/template.xhtml"> | ||
|
||
<ui:define name="page_title">Version Group Details</ui:define> | ||
<ui:define name="center_content"> | ||
<rich:jQuery selector="#tab_admin" query="addClass('ui-tabs-selected')" /> | ||
<h1>#{messages['jsf.CreateNewVersionGroup']}</h1> | ||
|
||
<ui:include src="../WEB-INF/layout/version_group_details_form.xhtml" /> | ||
|
||
</ui:define> | ||
|
||
</ui:composition> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters