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";
   
}

Tuesday, 29 November 2016

Input type only numbers(html5)

<input name="termsAndConditionsArticleId" value="${programDetailsForm.termsAndConditionsArticleId}" type="text"  pattern="^[0-9]*$" placeholder="Enter Digits only" title="Please enter numeric value only"/>


Increment & Decrements Hidden
<style>
input[type=number] {
    -moz-appearance:textfield;
}
</style>

Wednesday, 16 November 2016

Using Liferay Services in VM using ServiceLocator

When developing custom themes, we need to use Liferay services in VM. Its quite easy but tricky. So, putting here a simple example-
Write following in init-custom.vm

#set($organizationLocalService = $serviceLocator.findService("com.liferay.portal.
service.OrganizationLocalServiceUtil" )

Now you can use this service as follows:

#set ($org = $organizationLocalService.getOrganization($myPlace.getClassPK($myPlace.getClassPK()))

   

Getting Youtube Video Thumbnail image

<!--  This is for sample test code  -->

  <script type="text/javascript"> function getScreen( url, size ) {
if(url === null){
return "";
}
size = (size === null) ? "big" : size;
var vid;
var results;

results = url.match("[\\?&]v=([^&#]*)");
vid = ( results === null ) ? url : results[1];
if(size == "small"){
return "http://img.youtube.com/vi/"+vid+"/2.jpg"; }
else {
return "http://img.youtube.com/vi/"+vid+"/0.jpg"; }
}
</script>

 <%
  String url = "http://www.youtube.com/watch?v=E88uMNtPjvw";
 %>
<script type="text/javascript">

var imgUrl_small = getScreen("<%=url%>",'small');

 alert("this is image Url :"+imgUrl_small);

document.write('<img src="' + imgUrl_big + '" />');
document.write('<img src="' + imgUrl_small + '" />');

</script>

I hope its usefully for you..

Vm file image src

Explanation: In this we just have a scenario , that how we can display an image using liferay_portal.vm.In this docroot, under docroot dff folder is there placed any image in image folder.
then open the liferay-portal.vm and put this code


                                          $images_folder                                               

                     <img src="$images_folder/image.png">


here $image_folder means _dff/image
image.png is the image that we have to display.


Friday, 4 November 2016

Liferay, Reset Admin password.

If you forget or lose your Liferay Admin user and have access to your Liferay Schema / Database, you can execute the below query to reset your password.

Note: You will have to restart the server for the changes to take place.
 

UPDATE 
  user_ 
SET 
  password_ = '1234',
  passwordEncrypted = '0',
  passwordReset = '1',
  status = 0 
WHERE 
  emailaddress = 'test@liferay.com';
 
password_ is the new password that you are setting. You can use this to log in with the Admin credentials.
emailaddress should be the email Address of the Admin User.

jQuery Datepicker project


I had created a simple jQuery datepicker plugin couple of months back, just wanted to share it.

The plugin converts any input box to a 3 drop down date picker. It gets the name of the input element and attaches a Day, Month and Year respectively. You can access the original field to retrieve the date which will, by default, be in the format yyyy/mm/dd.

So, for example, if your input fields name was dob, then, to retrieve the value for the day, you would use dobDay. For the month it would be dobMonth and year with dobYear. For all event handlers, you will need to use the new name that will be generated.

Find the example JSFiddle link below.
JSFiddle - jQuery Datepicker

Datepicker Source File
Complete Source, (jquery.datepicker.js)

Below is the minified JS file for the datepicker. Copy this to a JavaScript file and include it in the page.
Minified file, (jquery.datepicker.min.js)

Supported Parameters:

startDate: JavaScript Date object to restrict the user to a specific Start date.
endDate: JavaScript Date object to restrict the user to a specific End date.
dateFormat: a function takes (day, month, year) as parameters and that returns a string that will be used to fill the hidden input box.


Usage:
HTML
 

<body>
    <input type="text" name="dob" id="dob" />
</body>

Javascript Code
 

$(function () {
    $('#dob').datepicker();

    // Example: Create 'onChange' handlers.
    $('#dobMonth').on('change', function () {
        alert($(this).val());
    });

    // Example: Display the String value on changin the date.
    $('#dobDay, #dobMonth, #dobYear').on('change', function () {
        alert($('#dob').val());
    });
});