package com.flexicious.example.model.classic
{
import com.flexicious.grids.filters.CollectionManipulator;
import com.flexicious.grids.filters.Filter;
import com.flexicious.grids.filters.FilterSort;
import mx.collections.ArrayCollection;
/**
* This is the equivalent of a server API that provides
* methods to retrieve data.
*/
public class EmployeeGenerator
{
public function getAllDepartments():ArrayCollection{
return new ArrayCollection(Employee.allDepartments.source);
}
/**
* This is the equivalent of the Server Side implementation
* of data retrieval. Please note, we're passing the entire
* filter object, because its assumed that the ActionScript
* MyFilter Object is mapped to a corresponding MyFilter class
* on the server via the RemoteClass mechanism.
*/
public function getEmployees(filter:Filter):Filter
{
var allEmployees:ArrayCollection = new ArrayCollection(Employee.employees.source);
var collectionManipulator:CollectionManipulator=new CollectionManipulator();
if(filter.arguments && filter.arguments.length>0)
collectionManipulator.filterArrayCollection(allEmployees,filter.arguments,null);
var totalRecords:int = allEmployees.length;
if (filter.sorts.length > 0)
collectionManipulator.sortArrayCollection(allEmployees, filter.sorts);
if(filter.pageIndex>-1)
collectionManipulator.pageArrayCollection(allEmployees,filter.pageIndex,filter.pageSize);
allEmployees.refresh();
var result:ArrayCollection = new ArrayCollection();
for each(var o:Object in allEmployees)
result.addItem(o);
filter.recordCount = totalRecords;
filter.records = result;
return filter;
}
}
}