Skip to content

Commit

Permalink
Closes #10462 (#10468)
Browse files Browse the repository at this point in the history
Signed-off-by: Dr M H B Ariyaratne <[email protected]>

Co-authored-by: imexh <[email protected]>
  • Loading branch information
buddhika75 and imexh authored Feb 10, 2025
1 parent afe157d commit 1c5dd56
Show file tree
Hide file tree
Showing 10 changed files with 431 additions and 149 deletions.
75 changes: 63 additions & 12 deletions src/main/java/com/divudi/bean/common/RelationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,33 @@ public class RelationController implements Serializable {
SessionController sessionController;

private List<Relation> items = null;
private Relation selected;
private Relation current;

public RelationController() {
}

public Relation getSelected() {
return selected;
public void prepareAdd() {
current = new Relation();
fillItems();
}

public void setSelected(Relation selected) {
this.selected = selected;
public void fillItems() {
String j;
j = "select s "
+ " from Relation s "
+ " where s.retired=:ret "
+ " order by s.name";
Map m = new HashMap();
m.put("ret", false);
items = getFacade().findByJpql(j, m);
}

public Relation getCurrent() {
return current;
}

public void setCurrent(Relation current) {
this.current = current;
}

protected void setEmbeddableKeys() {
Expand All @@ -58,9 +74,9 @@ private RelationFacade getFacade() {
}

public Relation prepareCreate() {
selected = new Relation();
current = new Relation();
initializeEmbeddableKey();
return selected;
return current;
}

public void create() {
Expand All @@ -77,7 +93,7 @@ public void update() {
public void destroy() {
persist(PersistAction.DELETE, "Deleted");
if (JsfUtil.isValidationPassed()) {
selected = null; // Remove selection
current = null; // Remove selection
items = null; // Invalidate list of items to trigger re-query.
}
}
Expand All @@ -94,7 +110,7 @@ public Relation fetchRelationByName(String relationName) {
String j = "select r from Relation r where r.name=:relationName";
Map m = new HashMap();
m.put("relationName", relationName);
Relation relation = getFacade().findFirstByJpql(j,m);
Relation relation = getFacade().findFirstByJpql(j, m);
if (relation == null) {
relation = new Relation();
relation.setName(relationName);
Expand All @@ -107,14 +123,49 @@ public Relation fetchRelationByName(String relationName) {
return relation;
}

public void delete() {
if (current != null) {
current.setRetired(true);
current.setRetiredAt(new Date());
current.setRetirer(sessionController.getLoggedUser());
getFacade().edit(current);
JsfUtil.addSuccessMessage("Deleted Successfully");
} else {
JsfUtil.addSuccessMessage("Nothing to Delete");
}
recreateModel();
fillItems();
current = null;
getCurrent();
}

private void recreateModel() {
items = null;
}

public void saveSelected() {
if (getCurrent().getId() != null && getCurrent().getId() > 0) {
getFacade().edit(current);
JsfUtil.addSuccessMessage("Updated Successfully.");
} else {
current.setCreatedAt(new Date());
current.setCreater(sessionController.getLoggedUser());
getFacade().create(current);
JsfUtil.addSuccessMessage("Saved Successfully");
}
recreateModel();
fillItems();
}


private void persist(PersistAction persistAction, String successMessage) {
if (selected != null) {
if (current != null) {
setEmbeddableKeys();
try {
if (persistAction != PersistAction.DELETE) {
getFacade().edit(selected);
getFacade().edit(current);
} else {
getFacade().remove(selected);
getFacade().remove(current);
}
JsfUtil.addSuccessMessage(successMessage);
} catch (EJBException ex) {
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/com/divudi/bean/membership/MembershipController.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,21 @@ public int getMembershipAdminIndex() {
public void setMembershipAdminIndex(int membershipAdminIndex) {
this.membershipAdminIndex = membershipAdminIndex;
}
public String navigateToMembershipAnalyticsIndex(){

public String navigateToMembershipAnalyticsIndex() {
return "/membership/analytics/index?faces-redirect=true";
}

public String navigateToMembershipAdministrationIndex() {
return "/membership/admin/index?faces-redirect=true;";
}

public String navigateToManageMembershipScheme() {
return "/membership/admin/membership_scheme?faces-redirect=true;";
}

public String navigateToManageRelationships() {
return "/membership/admin/relationships?faces-redirect=true;";
}

}
121 changes: 3 additions & 118 deletions src/main/webapp/admin/pricing/membership/membership_scheme.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,124 +5,9 @@
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui">


xmlns:p="http://primefaces.org/ui"
xmlns:me="http://xmlns.jcp.org/jsf/composite/ezcomp/pages/membership">
<ui:define name="subcontent">

<h:panelGroup >
<h:form >
<p:growl />
<p:focus id="selectFocus" for="lstSelect" />
<p:focus id="detailFocus" for="txtName" />



<p:panel id ="gpVeda" class="w-100" >
<f:facet name="header" >
<h:outputText value="Manage Membership Schemes" ></h:outputText>
</f:facet>
<div class="d-flex gap-2 mb-2">
<p:commandButton
id="btnAdd"
value="Add"
action="#{membershipSchemeController.prepareAdd()}"
process="btnAdd"
icon="pi pi-plus"
class="ui-button-Warning "
update="lstSelect gpDetailText detailFocus">
<p:ajax
event="click"
update="gpDetailText detailFocus"
process="@this" >
</p:ajax>
</p:commandButton>
<p:commandButton
id="btnDelete"
icon="pi pi-trash"
class="ui-button-danger "
onclick="if (!confirm('Are you sure you want to delete this record?'))
return false;" action="#{membershipSchemeController.delete()}" value="Delete" ajax="false" >
</p:commandButton>

<p:commandButton
value="Reload"
action="#{membershipSchemeController.fillItems()}"
class="ui-button-info"
icon="pi pi-refresh"
>
<f:ajax event="click" render="btnAdd btnDelete btnSave lstSelect :#{p:resolveFirstComponentWithId('gpDetailText',view).clientId} detailFocus" execute="@this" >
</f:ajax>
</p:commandButton>
</div>

<div class="row" >
<div class="col-5" >
<p:selectOneListbox
id="lstSelect"
class="w-100"
scrollHeight="500"
value="#{membershipSchemeController.current}"
filter="true">
<f:selectItems value="#{membershipSchemeController.items}" var="myItem" itemValue="#{myItem}" itemLabel="#{myItem.name}" ></f:selectItems>
<!-- <f:ajax render="gpDetailText" execute="lstSelect" >
</f:ajax>-->
<p:ajax process="lstSelect" update="gpDetailText"/>
</p:selectOneListbox>


</div>
<div class="col-7" >
<p:panel >
<f:facet name="header">
<h:outputText value="Details of the Membership Scheme" class="mt-2"></h:outputText>
<p:commandButton
id="btnSave"
value="Save"
icon="pi pi-save"
style="float: right;"
class="ui-button-success"
action="#{membershipSchemeController.saveSelected()}"
process="btnSave gpDetailText "
update="lstSelect selectFocus msg"
>
</p:commandButton>
</f:facet>
<p:panelGrid id="gpDetailText" columns="2" class="w-100">
<p:outputLabel for="txtName" id="lblName" value="Name" class="w-100"></p:outputLabel>
<p:inputText autocomplete="off" required="true" class="mb-1 w-100" id="txtName" value="#{membershipSchemeController.current.name}" ></p:inputText>

<p:outputLabel for="txtCode" id="lblCode" value="Code" ></p:outputLabel>
<p:inputText autocomplete="off" id="txtCode" class="mb-1 w-100" value="#{membershipSchemeController.current.code}" ></p:inputText>

<p:outputLabel for="txtPoints" id="lblPoints" value="Pointes for 1000" ></p:outputLabel>
<p:inputText autocomplete="off" id="txtPoints" class="mb-1 w-100" value="#{membershipSchemeController.current.pointesForThousand}" ></p:inputText>


<p:outputLabel for="lstDiscountScheme" id="lblDs" value="Discount Scheme" ></p:outputLabel>
<p:selectOneMenu
filter="true"
filterMatchMode="contains"
id="lstDiscountScheme"
class="w-100 mb-1"
value="#{membershipSchemeController.current.paymentScheme}" >
<f:selectItem itemLabel="Select" ></f:selectItem>
<f:selectItems value="#{paymentSchemeController.items}" var="myItem" itemValue="#{myItem}" itemLabel="#{myItem.name}" ></f:selectItems>
<f:ajax render="gpDetail" execute="lstSelect" >
</f:ajax>
</p:selectOneMenu>
</p:panelGrid>
</p:panel>

<p:messages id="msg" />
<p:defaultCommand target="btnSave"/>
</div>
</div>

</p:panel>
</h:form>
</h:panelGroup>

<me:membership/>
</ui:define>

</ui:composition>
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
xmlns:p="http://primefaces.org/ui"
xmlns:na="http://xmlns.jcp.org/jsf/composite/template"
xmlns:h="http://xmlns.jcp.org/jsf/html">



<h:head>

</h:head>

<h:body>
Expand All @@ -21,31 +17,37 @@
</h:panelGroup>

<p:panel
rendered="#{webUserController.hasPrivilege('MembershipAdministration')}"
rendered="#{webUserController.hasPrivilege('MembershipAdministration')}"
header="Membership Administration" >

<div class="row">
<div class="col-md-3">
<h:form>
<p:accordionPanel activeIndex="#{membershipController.membershipAdminIndex}">
<p:tab title="Manage Membersip Data" >
<div class="d-grid gap-2">
<p:commandButton class="w-100" ajax="false" value="Change Membership"
action="#{patientController.toChangeMembershipOfSelectedPersons()}"></p:commandButton>
</div>
</p:tab>

<p:tab title="Manage Metadata" >
<div class="d-grid gap-2">
<p:commandButton ajax="false" value="Relationship"
action="/membership/relation/List"></p:commandButton>
<p:commandButton
ajax="false"
value="Memberships"
action="#{membershipController.navigateToManageMembershipScheme}"></p:commandButton>
<p:commandButton
ajax="false"
value="Relationship"
action="#{membershipController.navigateToManageRelationships}"></p:commandButton>

</div>
</p:tab>


<p:commandButton ajax="false" value="Memberships"
action="/membership/membership_scheme"></p:commandButton>
<p:tab title="Manage Membersip Data" >
<div class="d-grid gap-2">
<p:commandButton class="w-100" ajax="false" value="Change Membership"
action="#{patientController.toChangeMembershipOfSelectedPersons()}"></p:commandButton>
</div>
</p:tab>


<p:tab title="Manage Discounts" >

<div class="d-grid gap-2">
Expand Down
13 changes: 13 additions & 0 deletions src/main/webapp/membership/admin/membership_scheme.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
template="/membership/admin/index.xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:me="http://xmlns.jcp.org/jsf/composite/ezcomp/pages/membership">
<ui:define name="subcontent">
<me:membership/>
</ui:define>
</ui:composition>
Loading

0 comments on commit 1c5dd56

Please sign in to comment.