Archive for January, 2013

AUI script tab

Sample Code


<h2>From markup</h2>

<div id="markupTabs">
<ul id="test">
<li><a href="javascript:;">Hello A</a></li>
<li><a href="javascript:;">Hello B</a></li>
<li><a href="javascript:;">Hello C</a></li>
</ul>

<div id="testContent">
<div>
<h3>1. New tab content</h3><br />
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div>
<h3>2. New tab content</h3><br />
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
<div>
<h3>3. New tab content</h3><br />
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</div>
</div>

 


<script type="text/javascript" charset="utf-8">

AUI().ready(
'aui-tabs', 'substitute',
function(A) {
var tabs1 = new A.TabView(
{
boundingBox: '#markupTabs',
listNode: '#test',
contentNode: '#testContent'
}
);
tabs1.render();
}
);

</script>

 

Check Point:

AUI-Tab

How to get List journalarticle filter by Tags ? Asset Publisher

Liferay version : 6.1.20EE

To get List of journal Article filter by Tags use the below code.



public void doView(RenderRequest renderRequest,
RenderResponse renderResponse) throws IOException, PortletException {

ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest
.getAttribute(WebKeys.THEME_DISPLAY);
try {
List<JournalArticle> journalArticles = getArticleByTags(themeDisplay.getScopeGroupId(), "help");
renderRequest.setAttribute("journalArticles", journalArticles);
} catch (SystemException e) {
e.getMessage();
} catch (PortalException e) {
e.getMessage();
}

public List<JournalArticle> getArticleByTags(long groupId, String tagName)
throws PortalException, SystemException {

AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

long[] anyTagIds = AssetTagLocalServiceUtil.getTagIds(groupId, new String[] { "alllocation", tagName });
assetEntryQuery.setAnyTagIds(anyTagIds);

List<AssetEntry> assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
List<JournalArticle> journalArticleList = new ArrayList<JournalArticle>();

for (AssetEntry ae : assetEntryList) {
JournalArticleResource journalArticleResourceObj = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(ae.getClassPK());
JournalArticle journalArticleObj = JournalArticleLocalServiceUtil.getArticle(groupId, journalArticleResourceObj.getArticleId());
journalArticleList.add(journalArticleObj);
}

return journalArticleList;
}


In jsp file add this below code


<%
List journalArticles =(List) renderRequest.getAttribute("journalArticles");
for(JournalArticle journalArticle : journalArticles){
%>
<%=journalArticle.getTitle("en_US") %>
<%
}
%>

Youtube Feed Callback

To display uploaded You tube video, title views count, description Published date …

<script type="text/javascript">
function youtubeFeedCallback(data) {
var s = '';
s += ' <span>'+ Math.floor(data.entry.media$group.yt$duration.seconds / 60) + ':' + (data.entry.media$group.yt$duration.seconds % 60)+'</span><br/>';
s += '<h1>' + data.entry.title.$t + '</h1>';
s += '<p>' + data.entry.yt$statistics.viewCount + ' view(s)</p>';

s += '<p>by ' + data.entry.author[0].name.$t + ' On ' + new Date(data.entry.published.$t).toLocaleDateString() + '</p>';
s += '<p>'+data.entry.media$group.media$description.$t.replace(/\n/g,'<br/>' ) +'</p><hr/>';

s += '<p><strong><a href="$videoViewMoreLink.getData()" target="_blank">View All Videos</a></strong></p></div>';
document.write(s);

}
</script>
<script type="text/javascript" src="http://gdata.youtube.com/feeds/api/videos/vR_r06JVpj8?v=2&alt=json-in-script&callback=youtubeFeedCallback"></script>

Check point:

http://www.youtube.com/watch?v=vR_r06JVpj8

youtube

for more information check the below reference link

https://developers.google.com/youtube/2.0/developers_guide_json

https://developers.google.com/youtube/js_api_reference

Creating table view in mysql and oracle database server

Oracle SQL to create  table view

To fetch distinct row based on the max version of the article from liferay database.

CREATE VIEW LATEST_JOURNALARTICLE
AS
(SELECT JA.GROUPID,
JA.ARTICLEID,
JA.VERSION AS MAX_VERSION,
JA.TITLE,
JA.DISPLAYDATE,
JA.EXPIRATIONDATE
FROM JOURNALARTICLE JA,
(  SELECT GROUPID, ARTICLEID, MAX (VERSION) AS MAX_VERSION
FROM JOURNALARTICLE J
GROUP BY GROUPID, ARTICLEID) JD
WHERE     JA.GROUPID = JD.GROUPID
AND JA.ARTICLEID = JD.ARTICLEID
AND JA.VERSION = JD.MAX_VERSION);

MySQL Query and Rules

A view definition is subject to the following restrictions:

The SELECT statement cannot contain a subquery in the FROM clause.

The SELECT statement cannot refer to system or user variables.

The SELECT statement cannot refer to prepared statement parameters .

CREATE VIEW MAX_VERSION_JOURNALARTICLE
AS
(SELECT GROUPID, ARTICLEID, MAX(VERSION) AS MAX_VERSION
FROM JOURNALARTICLE J
GROUP BY GROUPID, ARTICLEID);
CREATE VIEW LATEST_JOURNALARTICLE
AS
(SELECT JA.GROUPID,
JA.ARTICLEID,
JA.VERSION AS MAX_VERSION,
JA.TITLE,
JA.DISPLAYDATE,
JA.EXPIRATIONDATE
FROM JOURNALARTICLE JA, MAX_VERSION_JOURNALARTICLE JD
WHERE JA.GROUPID = JD.GROUPID AND
JA.ARTICLEID = JD.ARTICLEID AND
JA.VERSION = JD.MAX_VERSION);

AUI form Validation using AUI Validation tag library

Sample example


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>

<aui:form name="fm2" action="" method="post">
<table>
<tr>
<td>
<aui:input name="phoneNumber" value='${phoneNumber}' label="Enter number#" inlineLabel="left">
           <!-- Pre defined validation -->
        <aui:validator name="required"  errorMessage="Phone number format as (xxx) xxx-xxxx"  />
        <aui:validator name="minLength" errorMessage="Phone number format as (xxx) xxx-xxxx" >14</aui:validator>
        <aui:validator name="maxLength" errorMessage="Phone number format as (xxx) xxx-xxxx" >14</aui:validator>
</aui:input>
</td>
<td>
<aui:input name="phoneNumber" value='${phoneNumber}' label="Enter number#" inlineLabel="left">
           <!-- Custom validation -->
 <aui:validator name="required"  errorMessage="Phone number format as (xxx) xxx-xxxx"  />
 <aui:validator name="custom" errorMessage="Please check term of use">
function (val, fieldNode, ruleValue) {
var result = false;

if (val == "true") {
result = true;
}
return result;
}
</aui:validator>
</aui:input>
</td>
<td>
<aui:button type="submit" name="numberSearch" value="Number Search" />
</td>
</tr>
</table>
</aui:form>

Validator file path : %LIFERAY_HOME%\webapps\ROOT\html\js\liferay\form.js

DEFAULTS FORM VALIDATOR STRINGS:

DEFAULT: Liferay.Language.get(‘please-fix-this-field’),
acceptFiles: Liferay.Language.get(‘please-enter-a-file-with-a-valid-extension-x’),
alpha: Liferay.Language.get(‘please-enter-only-alpha-characters’),
alphanum: Liferay.Language.get(‘please-enter-only-alphanumeric-characters’),
date: Liferay.Language.get(‘please-enter-a-valid-date’),
digits: Liferay.Language.get(‘please-enter-only-digits’),
email: Liferay.Language.get(‘please-enter-a-valid-email-address’),
equalTo: Liferay.Language.get(‘please-enter-the-same-value-again’),
max: Liferay.Language.get(‘please-enter-a-value-less-than-or-equal-to-x’),
maxLength: Liferay.Language.get(‘please-enter-no-more-than-x-characters’),
min: Liferay.Language.get(‘please-enter-a-value-greater-than-or-equal-to-x’),
minLength: Liferay.Language.get(‘please-enter-at-list-x-characters’),
number: Liferay.Language.get(‘please-enter-a-valid-number’),
range: Liferay.Language.get(‘please-enter-a-value-between-x-and-x’),
rangeLength: Liferay.Language.get(‘please-enter-a-value-between-x-and-x-characters-long’),
required: Liferay.Language.get(‘this-field-is-required’),
url: Liferay.Language.get(‘please-enter-a-valid-url’)

Follow

Get every new post delivered to your Inbox.