Skip to content

Commit

Permalink
feat: delete version group
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Apr 24, 2018
1 parent 85e2568 commit 9b12ee6
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 33 deletions.
Expand Up @@ -40,6 +40,7 @@
import javax.inject.Named;
import org.zanata.common.EntityStatus;
import org.zanata.dao.ProjectIterationDAO;
import org.zanata.dao.VersionGroupDAO;
import org.zanata.i18n.Messages;
import org.zanata.model.HAccount;
import org.zanata.model.HIterationGroup;
Expand Down Expand Up @@ -97,6 +98,8 @@ public class VersionGroupHome extends SlugHome<HIterationGroup>
private GroupLocaleAutocomplete localeAutocomplete;
@Inject
private UrlUtil urlUtil;
@Inject
private VersionGroupDAO versionGroupDAO;
private AbstractListFilter<HPerson> maintainerFilter =
new InMemoryListFilter<HPerson>() {

Expand Down Expand Up @@ -201,8 +204,14 @@ private String update(
}

@Transactional
public void setStatus(char initial) {
getInstance().setStatus(EntityStatus.valueOf(initial));
public void deleteSelf() {
identity.checkPermission(getInstance(), "update");
String slug = getInstance().getSlug();
versionGroupDAO.makeTransient(getInstance());
versionGroupDAO.flush();
facesMessages.addGlobal(FacesMessage.SEVERITY_INFO,
msgs.format("jsf.group.notification.deleted", slug));
urlUtil.redirectToInternal(urlUtil.dashboardUrl());
}

@Transactional
Expand Down
7 changes: 3 additions & 4 deletions server/services/src/main/resources/messages.properties
Expand Up @@ -608,6 +608,7 @@ jsf.group.FindGroup=Find Group
jsf.GroupName=Group Name
jsf.GroupDescription=Group Description
jsf.GroupStatus=Group Status
jsf.group.notification.deleted=Group "{0}" deleted.
jsf.UpdateGeneralSettings=Update general settings
jsf.SelectGroup=Select group
jsf.Select=Select
Expand Down Expand Up @@ -760,8 +761,7 @@ jsf.VersionAddedToGroup=Version "{0}" of Project "{1}" has been added to group.
jsf.LanguageAlreadyInGroup=Language "{0}" is already added to group.
jsf.InvalidProjectVersion=Invalid project version
jsf.VersionAlreadyInGroup=Version "{0}" is already added to group.
jsf.ArchiveThisGroup=Archive this Group
jsf.UnArchiveThisGroup=Unarchive this Group
jsf.DeleteThisGroup=Delete this Group
jsf.MaintainerRemoveFromGroup=Maintainer "{0}" has been removed from group.
jsf.MaintainerAddedToGroup=Maintainer "{0}" has been added to group.
jsf.InvalidUsername=Invalid username.
Expand All @@ -770,8 +770,7 @@ jsf.ProjectMissingLanguage={0} project missing for this language
jsf.ProjectsMissingLanguage={0} projects missing for this language
jsf.LanguageMissingProject={0} language missing for this project
jsf.LanguagesMissingProject={0} languages missing for this project
jsf.ArchiveGroupMessage=This will set the group's status to archived and remove it from the public groups list, you will still be able to access it and unarchive it later.
jsf.ActivateGroupMessage=This will set the group's status to active and make it visible in the public groups list.
jsf.DeleteGroupMessage=This will delete this group and remove it from the public groups list. You will not be able to access it any more.
jsf.Missing=missing
jsf.project.search.placeholder=Search project names
jsf.ClearSearch=Clear search
Expand Down
@@ -0,0 +1,89 @@
<!--
~ Copyright 2018, 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.
-->

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:h="http://java.sun.com/jsf/html">



<div class="modal" id="delete-group-confirmation-modal" tabindex="-1"
role="dialog" >
<div class="modal__dialog l--constrain-medium">
<header class="modal__header">
<h2 class="modal__title">#{msgs.format('jsf.DeleteConfirmation', 'group', entityName)}</h2>
<button class="modal__close button--link" data-dismiss="modal"><i
class="i i--huge i--cancel"></i></button>
</header>


<h:outputScript>
function toggleDeleteButton(textField) {
var enabled = textField.value === '#{entityName}';
var deleteButton = document.getElementById('#{deleteButton.clientId}');
deleteButton.disabled = !enabled;
if (enabled) {
deleteButton.disabled = false;
deleteButton.onclick = function() {
runDelete();
zanata.modal.hide('#delete-group-confirmation-modal')
}
}
}
</h:outputScript>
<div class="modal__content">
<div class="l--pad-all-1">
<div class="message--danger">
<h:outputText value="#{msgs['jsf.DeleteConfirmation.Message.prefix']}" />
<strong>#{msgs['jsf.DeleteConfirmation.Message.word.permanently']}</strong>
<h:outputText value="#{msgs['jsf.DeleteConfirmation.Message.suffix']}" />
</div>
<div class="l--pad-all-1">
<h:outputLabel value="#{msgs.format('jsf.DeleteConfirmation.Prompt', entityName)}" />
<h:inputText id="confirmDeleteInput" onkeyup="toggleDeleteButton(this);return true;" />
</div>
</div>
</div>



<footer class="modal__footer l--pad-h-1 l--pad-v-half bg--highest">
<div class="g--tight">
<h:panelGroup layout="block" styleClass="g__item txt--align-right"
id="delete-confirmation-buttons">
<div class="bx--inline-block">
<button id="cancelDelete" onclick="zanata.modal.hide('#delete-group-confirmation-modal');return false;"
class="cancel button--link l--push-right-half" data-dismiss="modal">
#{msgs['jsf.Cancel']}
</button>
</div>
<div class="bx--inline-block">
<button id="deleteButton" styleClass="button--danger" jsfc="a4j:commandButton" binding="#{deleteButton}" disabled="true"
value="#{msgs['jsf.Delete']}"></button>
</div>
</h:panelGroup>
</div>
</footer>
</div>
</div>

</ui:composition>
Expand Up @@ -6,6 +6,9 @@
xmlns:f="http://java.sun.com/jsf/core"
xmlns:zanata="http://java.sun.com/jsf/composite/zanata">

<h:form>
<a4j:jsFunction name="runDelete" action="#{versionGroupHome.deleteSelf()}" />
</h:form>
<h1>#{msgs['jsf.Settings']}</h1>

<div class="tabs--vertical js-tabs">
Expand Down Expand Up @@ -63,33 +66,15 @@
</div>
<hr/>
<h:panelGroup id="status">
<ui:fragment
rendered="#{versionGroupHome.instance.status == 'ACTIVE'}">
<p>
<a4j:commandLink styleClass="button--danger"
action="#{versionGroupHome.setStatus('O')}" render="status">
#{msgs['jsf.ArchiveThisGroup']}
</a4j:commandLink>
</p>

<p class="txt--meta">#{msgs['jsf.ArchiveGroupMessage']}</p>
</ui:fragment>

<ui:fragment
rendered="#{versionGroupHome.instance.status != 'ACTIVE'}">
<p>
<a4j:commandLink styleClass="button--success"
action="#{versionGroupHome.setStatus('A')}" render="status">
<i
class="i--left i--archive"></i> #{msgs['jsf.UnArchiveThisGroup']}
</a4j:commandLink>
</p>

<p class="txt--meta">
<i
class="i--left i--archive"></i> #{msgs['jsf.ActivateGroupMessage']}
</p>
</ui:fragment>
<p>
<a href="javascript:void(0)" id="button-delete-group"
class="button--danger l--push-bottom-half"
data-toggle="modal"
data-target="#delete-group-confirmation-modal">
#{msgs['jsf.DeleteThisGroup']} <i class="i--left i--trash"></i>
</a>
</p>
<p class="txt--meta">#{msgs['jsf.DeleteGroupMessage']}</p>
</h:panelGroup>
</div>
</h:form>
Expand Down Expand Up @@ -274,4 +259,7 @@
</li>
</ul>
</div>
<ui:include src="/WEB-INF/layout/version-group/delete_group_confirmation_modal.xhtml">
<ui:param name="entityName" value="#{versionGroupHome.instance.name}" />
</ui:include>
</ui:composition>

0 comments on commit 9b12ee6

Please sign in to comment.