Sunday 19 March 2017

Learning - Enterprise portal

View.jsp

<%@page import="com.liferay.portal.security.permission.PermissionThreadLocal"%>
<%@page import="com.liferay.portal.security.permission.PermissionChecker"%>
<%@page import="com.liferay.portal.theme.ThemeDisplay"%>
<%@include file="/html/new/init.jsp"%>


<portlet:defineObjects />
<%
PortletURL complaintBoxURL = renderResponse.createActionURL();
complaintBoxURL.setParameter(ActionRequest.ACTION_NAME, "complaintBox");

PortletURL complaintURL = renderResponse.createRenderURL();
complaintURL.setParameter("jspPage", "/html/new/complaintsView.jsp");


ThemeDisplay themedisplay = (ThemeDisplay)request.getAttribute(WebKeys.THEME_DISPLAY);
PermissionChecker permissionChecker = PermissionThreadLocal.getPermissionChecker();
permissionChecker.isOmniadmin();
%>

<div class="row-fluid">
    <div class="span10">
        <h5>Hi&nbsp;<%=themedisplay.getUser().getFirstName() %>, admin only can view your suggestion. So honestly submit your complaints.</h5>
    </div>
    <div class="span2">
        <%if(permissionChecker.isOmniadmin()){ %>
        <a href="<%=complaintURL.toString()%>"><button class="btn-warning">Complaint Box</button></a>
        <%}%>
    </div>
</div>
<hr>




<aui:form name="fm" method="POST" action="<%= complaintBoxURL.toString() %>">

<aui:input type="text" name="name" label="First Name" value="<%=themedisplay.getUser().getFullName() %>" inlineLabel="true" placeholder="Enter your name">
</aui:input>

<aui:input type="text" name="EmployeeId" label="Employee Id" inlineLabel="true" placeholder="Enter your Employee Id">
</aui:input>

<aui:select name="network" label="How is our office network?" inlineLabel="true">
        <aui:option>Select your </aui:option>
        <aui:option value="Excellent">Excellent</aui:option>
        <aui:option value="Verygood">Very good</aui:option>
        <aui:option value="Good">Good</aui:option>
        <aui:option value="Notbad">Not bad</aui:option>
        <aui:option value="waste">waste</aui:option>
</aui:select>

<aui:input type="textarea" name="pantryService" label="How is our pantry?" inlineLabel="true" placeholder="Your suggestion">
</aui:input>

<aui:input type="textarea" name="infrastructure" label="How to improve our infrastructure ?" inlineLabel="true" placeholder="Your suggestion">
</aui:input>

<aui:input type="textarea" name="manager" label="Type about your manager?" inlineLabel="true" placeholder="Please provide a brief summary of your manager">
</aui:input>


<div align="center">
<aui:button type="submit" cssClass="btn-info" value="Save"/>
<aui:button type="reset" cssClass="btn-primary" value="Reset"/>
</div>
</aui:form>



Complaints view

<%@page import="com.service.service.ComplaintBoxLocalServiceUtil"%>
<%@page import="com.service.model.ComplaintBox"%>
<%@include file="/html/library/init.jsp"%>
<%@page import="com.constants.NewConstants"%>


<h3>Complaint list</h3>
<hr>
<%

PortletURL iteratorURL = renderResponse.createRenderURL();
/* iteratorURL.setParameter("jspPage", NewConstants.page_list); */
PortletURL deleteBookURL = renderResponse.createActionURL();
deleteBookURL.setParameter(ActionRequest.ACTION_NAME,NewConstants.Delete_complaint);
/* deleteBookURL.setParameter("redirectURL", iteratorURL.toString()); */




List<ComplaintBox> cb = ComplaintBoxLocalServiceUtil.getComplaintBoxs(-1, -1);
%>


<%if(cb.isEmpty()){%>
<h3>There is no complaints. your company is going correct way.</h3>
<%}else{ %>


<%for(ComplaintBox complaint : cb){%>

<div>
<% deleteBookURL.setParameter("NId", Long.toString(complaint.getNId()));%>
    <span style="font-weight: bold">User Name :</span><span class="name"><%=complaint.getName()%></span><br>
    <span style="font-weight: bold">EmployeeId :</span><span class="name"><%=complaint.getEmployeeId() %></span><br>
    <span style="font-weight: bold">Office Network :</span><span class="name"><%=complaint.getNetwork() %></span><br>
    <span style="font-weight: bold">How is yor manager :</span><span class="name"><%=complaint.getManager()%></span><br>
    <span style="font-weight: bold">How is our infrastructure  :</span><span class="name"><%=complaint.getInfrastructure() %></span><br>
    <span style="font-weight: bold">How is our pantry :</span><span class="name"><%=complaint.getPantryService() %></span><br>

    <a href="<%= deleteBookURL.toString() %>">Delete</a>
</div>
<hr>
<%}%>

<%} %>

init

<%@taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<%@taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
<%@page import="javax.portlet.PortletURL"%>
<%@page import="javax.portlet.ActionRequest"%>
<%@taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@page import="com.liferay.portal.kernel.util.WebKeys"%>
<%@page import="com.liferay.portal.kernel.dao.search.ResultRow"%>

controller

package com.test;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import javax.servlet.http.HttpServletRequest;
import javax.swing.Box;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import com.service.model.ComplaintBox;
import com.service.model.EmployeeDetails;
import com.service.model.impl.ComplaintBoxImpl;
import com.service.model.impl.EmployeeDetailsImpl;
import com.service.service.ComplaintBoxLocalServiceUtil;

/**
 * Portlet implementation class NewPortlet
 */
public class NewPortlet extends MVCPortlet {

    private static final HttpServletRequest Request = null;
   
    public void complaintBox(ActionRequest actionRequest,ActionResponse actionResponse)throws IOException, PortletException {
       
        String pantryService = ParamUtil.getString(actionRequest, "pantryService");
        String infrastructure = ParamUtil.getString(actionRequest, "infrastructure");
        String manager = ParamUtil.getString(actionRequest, "manager");
        String name = ParamUtil.getString(actionRequest, "name");
        String EmployeeId = ParamUtil.getString(actionRequest, "EmployeeId");
        String network = ParamUtil.getString(actionRequest, "network");
       
        ComplaintBox Box = new ComplaintBoxImpl();
       
        Box.setPantryService(pantryService);
        Box.setInfrastructure(infrastructure);
        Box.setManager(manager);
        Box.setName(name);
        Box.setEmployeeId(EmployeeId);
        Box.setNetwork(network);
       
        try {
            ComplaintBoxLocalServiceUtil.addComplaintBox(Box);
        } catch (SystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
       
   
       
        Box.getManager();
        Box.getNId();
        Box.getPantryService();
        Box.getInfrastructure();
        Box.getName();
        Box.getEmployeeId();
        Box.getNetwork();
       
       
        }
    public void deleteBook(ActionRequest actionRequest,ActionResponse actionResponse)throws IOException, PortletException, SystemException {
       
        System.out.println("##########################inside delete#####################################");
        long ndId = ParamUtil.getLong(actionRequest, "NId");
       
        try {
            ComplaintBox cmp = ComplaintBoxLocalServiceUtil.fetchComplaintBox(ndId);
            ComplaintBoxLocalServiceUtil.deleteComplaintBox(cmp);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
   
   

}


constants

package com.constants;

public class NewConstants{
    public static final String page_list = "/html/library/complaintsView.jsp";
    public static final String Delete_complaint = "deleteBook";
   
}