Thursday, 21 May 2015

Garbage collection in cq 5.6

Schedule and Reschedule the garbage collection in cq5, also overriding the gc call time :


1. Go to the web console in crx (Adobe Experience Manager Web Console Configuration)
     [  http://localhost:4592/system/console/configMgr  ].

2.  Search ( ctrl + f ) for "Repository Garbage Collection Scheduler" , double click on it.
     You will see a popup window like this


3. There is a field "Schedule" , you can schedule it by using regular expression like this



here "0 58 19 ? * MON-FRI"  means monday to friday (each day) at 19:58:00 (24 hr format) garbage collector will be called.

** This is not the same in AEM 6.

4.  All the details when gc is called can be seen with time stamp  in "error.log".


Now overriding the Schedular, no need to go to the web console :

1. Create a node, name it as "com.day.crx.sling.server.impl.jmx.GarbageCollectionConfig" with jcr:primaryType as "sling:OsgiConfig".


2. Now add these properties, it will use the time as you enter in the field schedule.



Wednesday, 20 May 2015

This component will show and hide the tabs a/c to the selection from dropdown box

Dynamic tabs using listeners in cq5




"afterrender" in listener :

function(box, dialog)
{
box.findParentByType('tabpanel').hideTabStripItem(1);
box.findParentByType('tabpanel').hideTabStripItem(2);
}


"selectionchange" in listeners :

function(box,value){
if(value == 'work')
{
box.findParentByType('tabpanel').unhideTabStripItem(1);
box.findParentByType('tabpanel').hideTabStripItem(2);
}
else if(value == 'contact')
{
box.findParentByType('tabpanel').hideTabStripItem(1);
box.findParentByType('tabpanel').unhideTabStripItem(2);
}
else
{
box.findParentByType('tabpanel').hideTabStripItem(1);
box.findParentByType('tabpanel').hideTabStripItem(2);
}
}



Doing same thing using json file, without creating options node

 1. create a json file with data in it, as Key Value pair.

 2. create a node and add a property sling:resourceSuperType and keep the json file address in value field.



 3. In the node having xtype selection, make a property as options and keep the json file's address in the value field.

4. Delete the options nodes within the select node, if you have already created it.

** Listeners code will be same as the above.




JSON FILE : 

[
    {"text":"--Select--", "value":"company"},
    {"text":"Work", "value":"work"},
    {"text":"Contact us", "value":"contact"}
]






This component will show alert box when past time along with date is selected








Javascript code to be written in listeners:

 function(dialog){
var datefieldArray = dialog.findByType("datefield");
var data = datefieldArray[0].getValue();
if(data != "")
{
var date = data.toString(); 
var currentDate = new Date();
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
year = year % 100;

var str = date.substring(4, 7);

var mnth;
switch(str)
{
case "Jan":
mnth = 1;
break;
case "Feb":
mnth = 2;
break;
case "Mar":
mnth = 3;
break;
case "Apr":
mnth = 4;
break;
case "May":
mnth = 5;
break;
case "Jun":
mnth = 6;
break;
case "Jul":
mnth = 7;
break;
case "Aug":
mnth = 8;
break;
case "Sep":
mnth = 9;
break;
case "Oct":
mnth = 10;
break;
case "Nov":
mnth = 11;
break;
case "Dec":
mnth = 12;
break;

var check = 0;
if(year > ((parseInt(date.charAt(13)) * 10) +  parseInt(date.charAt(14))))
{
check = 1;
}
else if(year == ((parseInt(date.charAt(13)) * 10) +  parseInt(date.charAt(14))))
{
if(month > mnth)
{
check = 1;
}
else if(month == mnth)
{
if(day > ((parseInt(date.charAt(8)) * 10) +  parseInt(date.charAt(9))))
{
check = 1;
}
else if(day == ((parseInt(date.charAt(8)) * 10) +  parseInt(date.charAt(9))))
{
check = 2;
}
}
}

if(check == 1)
{
alert("You selected a PAST DATE, plz select a VALID DATE");
alertDialog.show();
}

if(check == 2)
{
var timefieldArray = dialog.findByType("timefield");
var input = timefieldArray[0].getValue();
if(input != "")
{
var time = input.toString(); 
var l = time.length;

var hr = currentDate.getHours();
var min = currentDate.getMinutes();

var hours;
var mins;

if(l == 8)
{
hours = (parseInt(time.charAt(0)) * 10) +  parseInt(time.charAt(1));
mins = (parseInt(time.charAt(3)) * 10) +  parseInt(time.charAt(4));
if((time.substring(6,8) == "PM") && (hours < 12))
{
hours = hours + 12;
}
else if((time.substring(6,8) == "AM") && (hours == 12))
{
hours = 0;
}
}
else
{
hours = parseInt(time.charAt(0));
mins = (parseInt(time.charAt(2)) * 10) +  parseInt(time.charAt(3));
if((time.substring(5,7) == "PM") && (hours < 12))
{
hours = hours + 12;
}
else if((time.substring(5,7) == "AM") && (hours == 12))
{
hours = 0;
}
}
var chk = 0;
if(hours < hr)
{
chk = 1;
}
else if(hours == hr)
{
if(mins < min)
{
chk = 1;
}
else if(mins = min)
{
chk = 2;
}
}
if(chk == 1)
{
alert("You have selected the PAST TIME, plz select a FUTURE TIME");
alertDialog.show();
}
if(chk == 2)
{
alert("You have select the CURRENT TIME");
}
}
}
 }
}