/*
* Create the store
*/
Store store = new Store(className, ns);
/*
* Set the model name
*/
if (name != null) store.modelName(name);
/*
* If our store doesn't have a class drop out
*/
Class<?> clazz = store.getConfig().getClazz();
if (clazz == null) {
write ("<!-- Error creating store: Could not find entity for " + className + " -->\n");
return;
}
/*
* Various store options
*/
if (pageSize != null) store.pageSize(Integer.valueOf(pageSize));
if (include != null) store.include(include);
if (exclude != null) store.exclude(exclude);
if (clearOnPageLoad != null && clearOnPageLoad.equals("true")) store.clearOnPageLoad();
if (clearRemovedOnLoad != null && clearRemovedOnLoad.equals("true")) store.clearRemovedOnLoad();
if (autoSync != null && autoSync.equals("true")) store.autoSync();
if (autoLoad != null && autoLoad.equals("true")) store.autoLoad();
if (buffered != null && !buffered.equals("false")) store.buffered();
if (remoteGroup != null && remoteGroup.equals("true")) store.remoteGroup();
if (remoteSort != null && remoteSort.equals("true")) store.remoteSort();
if (remoteFilter != null && remoteFilter.equals("true")) store.remoteFilter(true);
if (sortOnFilter != null && sortOnFilter.equals("true")) store.sortOnFilter(true);
/*
* Filtering
*/
if (filter != null) {
for (String filterItem : filter.split(",")) {
String[] parts = filterItem.split("=");
String property = parts[0];
String value = parts.length > 1 ? parts[1] : null;
store.filter(property, value);
}
}
/*
* Grouping
*/
if (group != null) {
for (String groupItem : group.split(",")) {
String[] parts = groupItem.split(":");
String property = parts[0];
String direction = parts.length > 1 ? parts[1] : null;
String root = parts.length > 2 ? parts[2] : null;
store.group(property, direction, root);
}
}
/*
* Sorting
*/
if (sort != null) {
for (String sortItem : sort.split(",")) {
String[] parts = sortItem.split(":");
String property = parts[0];
String direction = parts.length > 1 ? parts[1] : "ASC";
String root = parts.length > 2 ? parts[2] : null;
store.sort(property, direction, root);
}
}
/*
* Buffering
*/
if (buffered != null) {
store.buffered();
if (!buffered.equals("true")) {
String[] parts = buffered.split(":");
store.trailingBufferZone(Integer.valueOf(parts[0]));
if (parts.length > 1) store.leadingBufferZone(Integer.valueOf(parts[1]));
if (parts.length > 1) store.purgePageCount(Integer.valueOf(parts[2]));
}
}
/*
* Add associations
*/
if (associations != null) store.associations(associations);
/*
* Load inline data?
*/
if (inline != null && inline.equals("true")) {
store.inline();
if (where != null) store.where(where);
if (param != null) {
for (String p : param.split(",")) {
String[] parts = p.split(":");
store.param(parts[0],parts[1]);
}
}
if (start != null) store.start(Integer.valueOf(start));
}
/*
* The proxy needs additinoal information from the store. We shouldn't create
* the proxy until the store has been fully configured
*/
if (rest != null) {
String restPath = getRequest().getContextPath() + "/rest/";
store.proxy(restPath + (rest.equals("true") ? clazz.getSimpleName().toLowerCase() : rest));
}
StoreDefinition storeDefinition = store.getStoreDefinition();
ModelDefinition baseModelDefinition = store.getModelDefinition();
/*
* Write the javascript for this store/model.
*
* During development using Ext.Loader, we need to syncRequire Ext.data.Model.
* If we asynchronously load all of our model's dependencies, they will not be
* available at the time we define our store. If they are not available, our
* model definition will not yet be instantiated and Ext.Loader will attempt (and fail)
* to load it dynamically.
*/
String storeModelName = store.getConfig().getModelName();
String storeName = ns + ".store." + StringUtilities.pluralize(storeModelName);
String modelName = ns + ".model." + storeModelName;
String output =
"Ext.syncRequire('Ext.data.Model');\n" +
"Ext.define(\"" + modelName + "\"," + StringUtilities.json(baseModelDefinition) + ");\n" +