var filters = new Array();
var completedFilters = new Array();
var Filter = Class.create();
Filter.prototype =
{
initialize: function()
{
this.index = null;
this.id = '';
},
generateHTML: function()
{
},
remove: function()
{
var div = $('divFilterSelection_' + this.index);
if (div)
div.remove();
div = $('filter_' + this.index)
if (div)
div.remove();
},
removeButtonHTML: function()
{
var output = '';
output = '';
return output;
},
setup: function()
{
},
serialize: function(data)
{
return JSON.stringify(data);
},
ajaxData: function()
{
return '';
}
};
var FilterActivityDate =
{
id: 'activityDate',
generateHTML: function()
{
var output = '';
output += '
';
output += 'A data de chegada na atividade atual é ';
output += ' ';
output += '';
output += ' ' + this.removeButtonHTML();
output += '
';
return output;
},
setup: function()
{
Calendar.setup({"inputField":this.id + '_' + this.index + '_date',"button":this.id + '_' + this.index + '_date-trigger',"singleClick":true,"name":this.id + '_' + this.index + '_date',"default":true});
},
ajaxData: function()
{
var data =
{
id: this.id,
operator: $F(this.id + '_' + this.index + '_operator'),
date: $F(this.id + '_' + this.index + '_date')
};
return this.serialize(data);
}
};
var FilterInstanceName =
{
id: 'instanceName',
generateHTML: function()
{
var output = '';
output += '';
output += 'O identificador da instância contém: ';
output += ' ' + this.removeButtonHTML();
output += '
';
return output;
},
ajaxData: function()
{
var data =
{
id: this.id,
name: $F(this.id + '_' + this.index + '_name')
};
return this.serialize(data);
}
};
var FilterInstanceID =
{
id: 'instanceID',
generateHTML: function()
{
var output = '';
output += '';
output += 'O ID da instância é ';
output += ' ';
output += ' ' + this.removeButtonHTML();
output += '
';
return output;
},
ajaxData: function()
{
var data =
{
id: this.id,
operator: $F(this.id + '_' + this.index + '_operator'),
number: $F(this.id + '_' + this.index + '_number')
};
return this.serialize(data);
}
};
var FilterInstancePriority =
{
id: 'instancePriority',
generateHTML: function()
{
var output = '';
output += '';
output += 'A prioridade da instância é ';
output += ' ';
output += ' ' + this.removeButtonHTML();
output += '
';
return output;
},
ajaxData: function()
{
var data =
{
id: this.id,
operator: $F(this.id + '_' + this.index + '_operator'),
priority: $F(this.id + '_' + this.index + '_priority')
};
return this.serialize(data);
}
};
var FilterInstanceDate =
{
id: 'instanceDate',
generateHTML: function()
{
var output = '';
output += '';
output += 'A data de criação da instância é ';
output += ' ';
output += '';
output += ' ' + this.removeButtonHTML();
output += '
';
return output;
},
setup: function()
{
Calendar.setup({"inputField":this.id + '_' + this.index + '_date',"button":this.id + '_' + this.index + '_date-trigger',"singleClick":true,"name":this.id + '_' + this.index + '_date',"default":true});
},
ajaxData: function()
{
var data =
{
id: this.id,
operator: $F(this.id + '_' + this.index + '_operator'),
date: $F(this.id + '_' + this.index + '_date')
};
return this.serialize(data);
}
};
var FilterInstanceEndDate =
{
id: 'instanceEndDate',
generateHTML: function()
{
var output = '';
output += '';
output += 'A data de finalização da instância é ';
output += ' ';
output += '';
output += ' ' + this.removeButtonHTML();
output += '
';
return output;
},
setup: function()
{
Calendar.setup({"inputField":this.id + '_' + this.index + '_date',"button":this.id + '_' + this.index + '_date-trigger',"singleClick":true,"name":this.id + '_' + this.index + '_date',"default":true});
},
ajaxData: function()
{
var data =
{
id: this.id,
operator: $F(this.id + '_' + this.index + '_operator'),
date: $F(this.id + '_' + this.index + '_date')
};
return this.serialize(data);
}
};
var FilterInstanceStatus =
{
id: 'instanceStatus',
generateHTML: function()
{
var output = '';
output += '';
output += 'O status da instância é: ';
output += ' ';
output += ' ' + this.removeButtonHTML();
output += '
';
return output;
},
ajaxData: function()
{
var data =
{
id: this.id,
status: $F(this.id + '_' + this.index + '_status')
};
return this.serialize(data);
}
};
var FilterInstanceActivity =
{
id: 'instanceActivity',
generateHTML: function()
{
var output = '';
output += '';
output += 'A instância encontra-se na atividade: ';
output += '';
output += ' ' + this.removeButtonHTML();
output += '
';
return output;
},
setup: function()
{
var filterIndex = this.index;
var filterID = this.id;
function resultInstanceActivitySetup(data)
{
var content = '';
content += ' ';
new Insertion.Before($('dummy_' + filterIndex), content);
$('dummy_' + filterIndex).remove();
}
cExecute('$this.bo_monitors.listActivities', resultInstanceActivitySetup, 'pid=' + workflowMonitorInstancesParams['pid']);
},
ajaxData: function()
{
var data =
{
id: this.id,
activity: $F(this.id + '_' + this.index + '_activity')
};
return this.serialize(data);
}
};
var FilterInstanceUser =
{
id: 'instanceUser',
generateHTML: function()
{
var output = '';
output += '';
output += 'A instância encontra-se com o usuário: ';
output += '';
output += ' ' + this.removeButtonHTML();
output += '
';
return output;
},
setup: function()
{
var filterIndex = this.index;
var filterID = this.id;
function resultInstanceUserSetup(data)
{
var content = '';
content += ' ';
new Insertion.Before($('dummy_' + filterIndex), content);
$('dummy_' + filterIndex).remove();
}
cExecute("$this.bo_monitors.getUsersInInstances", resultInstanceUserSetup, 'pid=' + workflowMonitorInstancesParams['pid']);
},
ajaxData: function()
{
var data =
{
id: this.id,
user: $F(this.id + '_' + this.index + '_user')
};
return this.serialize(data);
}
};
var FilterInstanceOwner =
{
id: 'instanceOwner',
generateHTML: function()
{
var output = '';
output += '';
output += 'O proprietário da instância é: ';
output += '';
output += ' ' + this.removeButtonHTML();
output += '
';
return output;
},
setup: function()
{
var filterIndex = this.index;
var filterID = this.id;
function resultInstanceOwnerSetup(data)
{
var content = '';
content += ' ';
new Insertion.Before($('dummy_' + filterIndex), content);
$('dummy_' + filterIndex).remove();
}
cExecute("$this.bo_monitors.getInstancesOwners", resultInstanceOwnerSetup, 'pid=' + workflowMonitorInstancesParams['pid'] + '¤tList=' + workflowMonitorCurrentList);
},
ajaxData: function()
{
var data =
{
id: this.id,
owner: $F(this.id + '_' + this.index + '_owners')
};
return this.serialize(data);
}
};
function addFilterSelection(onlyCompletedInstances)
{
var content = '';
var index = filters.length;
var objFilter = new Filter();
objFilter.index = index;
filters[index] = objFilter;
content += '';
content += '
';
content += '
';
content += ' ' + objFilter.removeButtonHTML();
content += '
';
new Insertion.Before($('filterMenu'), content)
}
function addFilter(index)
{
var div = $('divFilterSelection_' + index);
var selectBox = $('filterSelect_' + index);
var selected = $F(selectBox);
var content = '';
switch (selected)
{
case 'activityDate':
Object.extend(filters[index], FilterActivityDate);
break;
case 'instanceName':
Object.extend(filters[index], FilterInstanceName);
break;
case 'instanceID':
Object.extend(filters[index], FilterInstanceID);
break;
case 'instancePriority':
Object.extend(filters[index], FilterInstancePriority);
break;
case 'instanceDate':
Object.extend(filters[index], FilterInstanceDate);
break;
case 'instanceEndDate':
Object.extend(filters[index], FilterInstanceEndDate);
break;
case 'instanceStatus':
Object.extend(filters[index], FilterInstanceStatus);
break;
case 'instanceActivity':
Object.extend(filters[index], FilterInstanceActivity);
break;
case 'instanceUser':
Object.extend(filters[index], FilterInstanceUser);
break;
case 'instanceOwner':
Object.extend(filters[index], FilterInstanceOwner);
break;
}
content += filters[index].generateHTML();
new Insertion.Before(div, content);
filters[index].setup();
div.remove();
}
function removeFilter(index)
{
filters[index].remove();
filters[index] = null;
}
function filterInstances(completedInstances)
{
var ajaxData = new Array();
var currentData = '';
for (var i = 0; i < filters.length; i++)
{
/* ignora se o filtro foi removido */
if (filters[i] == null)
continue;
/* verifica se os critérios foram satisfeitos */
currentData = filters[i].ajaxData();
if (currentData == '')
continue;
/* filtro com JSON */
ajaxData[ajaxData.length] = filters[i].ajaxData();
}
if (completedInstances)
{
if (ajaxData.length > 0)
callCompletedInstanceList(workflowMonitorInstancesParams['pid'], workflowMonitorInstancesParams['str'], 0, JSON.stringify(ajaxData));
else
callCompletedInstanceList(workflowMonitorInstancesParams['pid'], workflowMonitorInstancesParams['str'], 0);
}
else
{
if (ajaxData.length > 0)
callInstanceList(workflowMonitorInstancesParams['pid'], workflowMonitorInstancesParams['str'], 0, JSON.stringify(ajaxData));
else
callInstanceList(workflowMonitorInstancesParams['pid'], workflowMonitorInstancesParams['str'], 0);
}
}