Hi, I just made some experiments with the new custom columns features, by merging created and modified dates, choosing the most recent of both, and then using to group items. the problem is that I want to order the groups in other way (right now it seems that is ordered alphabetically) Can somebody help me?
// The OnInit function is called by Directory Opus to initialize the script add-in
function OnInit(initData) {
// Provide basic information about the script by initializing the properties of the ScriptInitData object
initData.name = "ByDate";
initData.default_enable = false;
// Create a new ScriptColumn object and initialize it to add the column to Opus
var cmd = initData.AddColumn();
cmd.name = "ByDate";
cmd.method = "ByDate";
cmd.label = "Fecha";
cmd.autogroup = false; // we provide our own grouping information
cmd.autorefresh = true; // auto-refresh column when file changes
cmd.keyscroll = true;
}
// Implement the IsModified column (this entry point is an OnScriptColumn event).
// The name of this function must correspond to the value specified for the method property when the column was added in OnInit
function OnByDate(scriptColData) {
// we don't provide a value for folders since their timestamps don't mean much
// we set the sort key to 3 so they come last (in case the user is mixing files and folders)
scriptColData.value = scriptColData.item.create + "|" + scriptColData.item.modify;
var today = new Date();
var item_time = new Date(Math.max(scriptColData.item.create, scriptColData.item.modify));
if (today.getTime() < item_time.getTime())
{
scriptColData.group = "Del Futuro!";
scriptColData.sort = 1;
}
// Si son del mismo año
else if (today.getFullYear() == item_time.getFullYear()) {
var group = "Este año";
var sort = 5;
//Si son del mismo mes
if (today.getMonth() == item_time.getMonth())
{
sort = 4;
group = "Este mes";
//Si son de la misma semana
if (today.getDate() - today.getDay() == item_time.getDate() - item_time.getDay())
{
sort = 3;
group = "Esta semana";
//Si son del mismo dia
if (today.getDay() == item_time.getDay())
{
sort = 2;
group = "Hoy";
}
}
}
scriptColData.group = group;
scriptColData.sort = sort;
}
//Si es del año pasado
else if (today.getFullYear() - 1 == item_time.getFullYear()) {
scriptColData.group = "El año pasado";
scriptColData.sort = 6;
}
// Es de hace mucho tiempo
else {
scriptColData.group = "Hace tiempo";
scriptColData.sort = 7;
}
}
PD: Also I know that the code is very inneficient, anyone who can improve it, I'll be very appreciate.
Thanks