Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Kishor Ghule
Date type in Structure
January 13, 2011 1:05 AM
Answer

Kishor Ghule

Rank: New Member

Posts: 13

Join Date: June 18, 2010

Recent Posts

I want to add Date type in the input field of Structure. By default there is no such provision by Liferay. I have following questions for this:
1) How can i achieve this?
2) Where can i do development for this?
3)Which file is responsible for the input field types that we see when we click Add Row while creating a Structure
Piotr Filipowicz
RE: Date type in Structure
January 13, 2011 3:04 AM
Answer

Piotr Filipowicz

Rank: Junior Member

Posts: 52

Join Date: November 18, 2010

Recent Posts

Hi Kishor!
This post is only suggest where you find pieces of code which are responsible for render and edit structure's field.

- html/portlet/journal/js/main.js file. In this file we register new field's model: registerFieldModel(namespace, type, variableName, optionsEditable) and add this one to model's map in function _fieldInstanceFactory() : <type> : Journal.FieldModel.<namespace>

- html/portlet/journal/edit_article_content_xsd_el.jsp file. We display and serve our new type inside <div> tag (journal-article-component-container).

- html/portlet/journal/edit_structure_xsd_el.jsp file. We shoud add our new type to select list: <select id="<portlet:namespace />structure_el<%= count.getValue() %>_type" tabindex="<%= tabIndex.getValue() %>">

- html/portlet/journal/edit_article_structure extra.jspf file. We add our type to select list: (add our type to select fieldType inside journalArticleEditField's field). We also define look out field inside journalFieldModelContainer's div (create div with attribute dataType="<type>").

- In file html/portlet/journal/edit_article_extra.jsp we must add and register our new component.


Hints:
You must look and handle your new component in this files:
- html/portlet/journal/js/main.js
- html/portlet/journal/edit_article_content_xsd_el.jsp
- portal-impl/src/com/liferay/portlet/journal/action/EditArticleAction.java
Piotr Filipowicz
RE: Date type in Structure
January 15, 2011 9:19 AM
Answer

Piotr Filipowicz

Rank: Junior Member

Posts: 52

Join Date: November 18, 2010

Recent Posts

Hi!
I wrote tutorial about creating new structure's fields. This tutorial shows how to add date type in structure. Please, visit liferaycms.wordpress.com.
Kishor Ghule
RE: Date type in Structure
January 27, 2011 9:12 PM
Answer

Kishor Ghule

Rank: New Member

Posts: 13

Join Date: June 18, 2010

Recent Posts

Hi Piotr,

Thanks! I'll go through the tutorial.
David García González
RE: Date type in Structure
November 3, 2011 9:57 AM
Answer

David García González

Rank: Regular Member

Posts: 127

Join Date: July 14, 2009

Recent Posts

I wanted to configure a new element of type list (combo box select) but I dont know how to configure the values of this combo.

1<dynamic-element name='Peso' type='list' index-type='' repeatable='false'></dynamic-element>


Where is it explained? Is there a dtd?

Thanks!
David García González
RE: Date type in Structure
November 3, 2011 10:02 AM
Answer

David García González

Rank: Regular Member

Posts: 127

Join Date: July 14, 2009

Recent Posts

I found it in another forum:

1  <dynamic-element name='Peso' type='list' index-type='' repeatable='false'>
2    <dynamic-element name='extinct' type='Extinct' index-type='' repeatable='false'>  </dynamic-element>
3    <dynamic-element name='extinctWild' type='Extinct%20in%20the%20wild' index-type='' repeatable='false'>  </dynamic-element>
4    <dynamic-element name='criticEndanger' type='Critically%20Endangered' index-type='' repeatable='false'>  </dynamic-element>
5    <dynamic-element name='endanger' type='Endangered' index-type='' repeatable='false'>  </dynamic-element>
6    <dynamic-element name='vulnerable' type='Vulnerable' index-type='' repeatable='false'></dynamic-element>
7  </dynamic-element>


Forum
Simon Marcini
RE: Date type in Structure
September 26, 2012 3:41 PM
Answer

Simon Marcini

Rank: New Member

Posts: 18

Join Date: February 13, 2012

Recent Posts

Piotr Filipowicz:
Hi!
I wrote tutorial about creating new structure's fields. This tutorial shows how to add date type in structure. Please, visit liferaycms.wordpress.com.



Hey Piotr!

I've followed your tutorial, it's really good. Thanks. However, I'm trying to add empty field to dropdownlist. I actually want the user to be able to choose empty value from the calender: empty day, month and year, but I'm having some troubles figuring it out. Could you help me with that please?
Javi GC
RE: Date type in Structure
December 12, 2012 12:44 PM
Answer

Javi GC

Rank: New Member

Posts: 4

Join Date: August 16, 2012

Recent Posts

Hi Piotr,

Is it a solution available for the calendar? Selection on it doesn't change any value (year, month or day).

I'm using CE 6.1.1 CE GA2.

Thanks in advance
Asier Hernández
RE: Date type in Structure
November 11, 2013 10:38 AM
Answer

Asier Hernández

Rank: New Member

Posts: 21

Join Date: February 1, 2011

Recent Posts

I am looking for this hook too. The hook presented in http://liferaycms.wordpress.com/2011/01/15/add-new-structure-field/ is not working for Liferay 6.1.

¿Some ideas?

Thanks a lot!
Beatriz Sánchez Pérez
RE: Date type in Structure
April 17, 2014 7:35 AM
Answer

Beatriz Sánchez Pérez

Rank: New Member

Posts: 18

Join Date: April 28, 2011

Recent Posts

This is the code for liferay 6.1.1 GA2

1.- in main.js add

var model = {
'boolean': Journal.FieldModel.Boolean,
'document_library': Journal.FieldModel.DocumentLibrary,
'image': Journal.FieldModel.Image,
'link_to_layout': Journal.FieldModel.LinkToPage,
'list': Journal.FieldModel.List,
'multi-list': Journal.FieldModel.MultiList,
'selection_break': Journal.FieldModel.SelectionBreak,
'text': Journal.FieldModel.Text,
'text_area': Journal.FieldModel.TextArea,
'text_box': Journal.FieldModel.TextBox,
'date': Journal.FieldModel.Date,

2.- edit_article_content_xsd_el.jsp

<c:if test='<%= elType.equals("date") %>'>
<%@ include file="/html/portlet/journal/edit_article_content_xsd_date_el.jspf" %>
</c:if>

3.- edit_article_extra.jspf

<div dataType="date">
<liferay-ui:message key="date" />
</div>

4.- edit_article_structure_extra.jspf

<aui:select disabled="<%= true %>" name="fieldType">
<aui:option label="text-field" value="text" />
<aui:option label="text-box" value="text_box" />
<aui:option label="text-area" value="text_area" />
<aui:option label="checkbox" value="boolean" />
<aui:option label="options" />
<aui:option label="select-box" value="list" />
<aui:option label="multi-selection-list" value="multi-list" />
<aui:option label="image-uploader" value="image" />
<aui:option label="document-library" value="document_library" />
<aui:option label="link-to-page" value="link_to_layout" />
<aui:option label="selection-break" value="selection_break" />
<aui:option label="date" value="date" />

5.- edit_structure_xsd_el.jsp

<option <%= elType.equals("date") ? "selected" : "" %> value="date"><liferay-ui:message key="date" /></option>
Sergio Romero Zayas
RE: Date type in Structure
May 9, 2014 5:20 AM
Answer

Sergio Romero Zayas

Rank: Regular Member

Posts: 115

Join Date: April 14, 2008

Recent Posts

Missing some important steps:
add to main.js:
1registerFieldModel('Date', 'date', 'DateField', true);


code of edit_article_content_xsd_date_el.jspf.

 1
 2<aui:fieldset>
 3<%
 4Calendar cal = CalendarFactoryUtil.getCalendar(timeZone, locale);
 5if (elContent != null && !elContent.equals("")) {
 6  DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd H:m");
 7  Date date = (Date)formatter.parse(elContent);
 8  cal.setTime(date);
 9}
10
11%>
12
13<aui:field-wrapper>
14  <div>
15    <liferay-ui:input-date
16      dayParam="dateDay"
17      dayValue="<%= cal.get(Calendar.DATE) %>"
18      disabled="<%= false %>"
19      firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>"
20      monthParam="dateMonth"
21      monthValue="<%= cal.get(Calendar.MONTH) %>"
22      yearParam="dateYear"
23      yearValue="<%= cal.get(Calendar.YEAR) %>"
24      yearRangeStart="<%= cal.get(Calendar.YEAR) %>"
25      yearRangeEnd="<%= cal.get(Calendar.YEAR) + 5 %>"
26    />
27
28    &nbsp;
29
30    <liferay-ui:input-time
31      amPmParam="dateAmPm"
32      amPmValue="<%= cal.get(Calendar.AM_PM) %>"
33      hourParam="dateHour"
34      hourValue="<%= cal.get(Calendar.HOUR) %>"
35      minuteParam="dateMinute"
36      minuteValue="<%= cal.get(Calendar.MINUTE) %>"
37      minuteInterval="<%= 1 %>"
38    />
39  </div>
40</aui:field-wrapper>
41</aui:fieldset>


add to if in main.js

 1
 2if (type == 'date') {
 3    var dateContents = componentContainer.all('select');
 4    var date = [Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN, Number.NaN];
 5
 6    if (dateContents) {
 7        dateContents.each(
 8            function(select, selectIndex, selects) {
 9                var options = select.all('option');
10                if (options) {
11                    options.each(
12                        function(option, optionIndex, options) {
13                            if (option.get('selected')) {
14                                //name selecta, zawierajacego wybrany item
15                                var selectName = select.get('name');
16                                var selectedValue = option.val();
17
18                                if (selectName.match(/dateDay$/)) {
19                                    date[0] = selectedValue;
20                                } else if (selectName.match(/dateMonth$/)) {
21                                    date[1] = selectedValue;
22                                } else if (selectName.match(/dateYear$/)) {
23                                    date[2] = selectedValue;
24                                } else if (selectName.match(/dateHour$/)) {
25                                    date[3] = selectedValue;
26                                } else if (selectName.match(/dateMinute$/)) {
27                                    date[4] = selectedValue;
28                                } else if (selectName.match(/dateAmPm$/)) {
29                                    date[6] = selectedValue;
30                                }
31                            }
32                        },
33                        select
34                    );
35                }
36            }
37        );
38
39    }
40    content = instance.getDateAsString(date);
41
42}


Also we must define the "getDateAsString” function

 1
 2getDateAsString: function(stringDateArray) {
 3        if (stringDateArray.length != 7) {
 4            return '';
 5        }
 6        var intDateArray = new Array(stringDateArray.length);
 7        var notNaNExist = false;
 8        for (var i = 0; i < stringDateArray.length; i++) {
 9            intDateArray[i] = parseInt(stringDateArray[i], 10);
10            if (intDateArray[i] != NaN) {
11                notNaNExist = true;
12            }
13        }
14
15        if (!notNaNExist) {
16            return '';
17        }
18
19        var day = intDateArray[0];
20        var month = intDateArray[1];
21        var year = intDateArray[2];
22        var hour = intDateArray[3];
23        var minute = intDateArray[4];
24        var second = 0;
25        var ampm = intDateArray[6];
26
27        if (!isNaN(month)) {
28            month = month + 1;
29        }
30
31        if (ampm == 1 && !isNaN(hour)) {
32            hour = hour + 12;
33        }
34
35        if (month < 10) {
36            month = '0' + month;
37        }
38        if (day < 10) {
39            day = '0' + day;
40        }
41        if (hour < 10) {
42            hour = '0' + hour;
43        }
44        if (minute < 10) {
45            minute = '0' + minute;
46        }
47        if (second < 10) {
48            second = '0' + second;
49        }
50
51        return year + '-' + month + '-' + day + ' ' + hour + ':' + minute;
52    }



Everything said in this blog perfectly : http://liferaycms.wordpress.com/2011/01/15/add-new-structure-field/
Thanks to its creator.


Happy Friday and happy weekend.
emoticon
Haythem Benizid
RE: Date type in Structure
October 13, 2014 4:32 AM
Answer

Haythem Benizid

Rank: New Member

Posts: 6

Join Date: August 3, 2014

Recent Posts

Hello,
I work with Liferay 6.2 CE.
I added a new structure, in which I added a date field. when adding content I can not specify the time.
how I can configure the field the way it gives me the possibilty to enter the date and time ?
should i add a new field?
PLZ help emoticon