use of org.broadleafcommerce.openadmin.web.form.component.ListGridAction in project BroadleafCommerce by BroadleafCommerce.
the class AdminProductController method viewEntityForm.
@Override
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public String viewEntityForm(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id) throws Exception {
String view = super.viewEntityForm(request, response, model, pathVars, id);
// Skus have a specific toolbar action to generate Skus based on permutations
EntityForm form = (EntityForm) model.asMap().get("entityForm");
ListGridAction generateSkusAction = new ListGridAction(ListGridAction.GEN_SKUS).withDisplayText("Generate_Skus").withIconClass("icon-fighter-jet").withButtonClass("generate-skus").withUrlPostfix("/generate-skus").withActionUrlOverride("/product/" + id + "/additionalSkus/generate-skus");
ListGrid skusGrid = form.findListGrid("additionalSkus");
if (skusGrid != null) {
skusGrid.setCanFilterAndSort(false);
}
ListGrid productOptionsGrid = form.findListGrid("productOptions");
if (productOptionsGrid != null) {
productOptionsGrid.addToolbarAction(generateSkusAction);
}
// list grids. Remove them from the form.
if (ProductBundle.class.isAssignableFrom(Class.forName(form.getEntityType()))) {
form.removeListGrid("additionalSkus");
form.removeListGrid("productOptions");
form.removeField("canSellWithoutOptions");
}
form.removeListGrid("defaultSku.skuAttributes");
return view;
}
use of org.broadleafcommerce.openadmin.web.form.component.ListGridAction in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method populateEntityForm.
@Override
public void populateEntityForm(ClassMetadata cmd, Entity entity, Map<String, DynamicResultSet> collectionRecords, EntityForm ef, List<SectionCrumb> sectionCrumbs) throws ServiceException {
// Get the form with values for this entity
populateEntityForm(cmd, entity, ef, sectionCrumbs);
// Attach the sub-collection list grids and specialty UI support
for (Property p : cmd.getProperties()) {
if (p.getMetadata() instanceof BasicFieldMetadata) {
continue;
}
if (!ArrayUtils.contains(p.getMetadata().getAvailableToTypes(), entity.getType()[0])) {
continue;
}
if (collectionRecords != null) {
DynamicResultSet subCollectionEntities = collectionRecords.get(p.getName());
String containingEntityId = entity.getPMap().get(ef.getIdProperty()).getValue();
ListGrid listGrid = buildCollectionListGrid(containingEntityId, subCollectionEntities, p, ef.getSectionKey(), sectionCrumbs);
CollectionMetadata md = ((CollectionMetadata) p.getMetadata());
if (md instanceof BasicCollectionMetadata) {
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
ClassMetadata collectionCmd = adminEntityService.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
if (collectionCmd.getPolymorphicEntities().getChildren().length != 0) {
List<ClassTree> entityTypes = collectionCmd.getPolymorphicEntities().getCollapsedClassTrees();
ListGridActionGroup actionGroup = new ListGridActionGroup().withName("Add");
for (ClassTree entityType : entityTypes) {
ListGridAction ADD = new ListGridAction(ListGridAction.ADD).withButtonClass(AddMethodType.PERSIST_EMPTY == ((BasicCollectionMetadata) md).getAddMethodType() ? "sub-list-grid-add-empty" : "sub-list-grid-add").withActionTargetEntity(entityType.getFullyQualifiedClassname()).withUrlPostfix("/add").withIconClass("fa fa-plus").withDisplayText(BLCMessageUtils.getMessage(entityType.getFriendlyName()));
actionGroup.getListGridActions().add(0, ADD);
}
listGrid.addToolbarActionGroup(actionGroup);
} else {
listGrid.getToolbarActions().add(0, AddMethodType.PERSIST_EMPTY == ((BasicCollectionMetadata) md).getAddMethodType() ? DefaultListGridActions.ADD_EMPTY : DefaultListGridActions.ADD);
}
} else {
listGrid.getToolbarActions().add(0, DefaultListGridActions.ADD);
}
if (subCollectionEntities.getUnselectedTabMetadata().get(md.getTab()) != null) {
ef.addListGrid(cmd, listGrid, md.getTab(), md.getTabOrder(), md.getGroup(), true);
} else {
ef.addListGrid(cmd, listGrid, md.getTab(), md.getTabOrder(), md.getGroup(), false);
}
}
}
if (CollectionUtils.isEmpty(ef.getActions())) {
ef.addAction(DefaultEntityFormActions.SAVE);
}
addDeleteActionIfAllowed(ef, cmd, entity);
setReadOnlyState(ef, cmd, entity);
// check for fields that should be hidden based on annotations
setVisibilityBasedOnShowIfFieldEquals(cmd, entity, ef);
extensionManager.getProxy().modifyDetailEntityForm(ef);
}
use of org.broadleafcommerce.openadmin.web.form.component.ListGridAction in project BroadleafCommerce by BroadleafCommerce.
the class TranslationFormBuilderServiceImpl method buildListGrid.
@Override
public ListGrid buildListGrid(List<Translation> translations, boolean isRte) {
// Set up the two header fields we're interested in for the translations list grid
List<Field> headerFields = new ArrayList<Field>();
headerFields.add(new Field().withName("localeCode").withFriendlyName("Translation_localeCode").withOrder(0));
headerFields.add(new Field().withName("translatedValue").withFriendlyName("Translation_translatedValue").withOrder(10));
// Create the list grid and set its basic properties
ListGrid listGrid = new ListGrid();
listGrid.getHeaderFields().addAll(headerFields);
listGrid.setListGridType(ListGrid.Type.TRANSLATION);
listGrid.setSelectType(ListGrid.SelectType.SINGLE_SELECT);
listGrid.setCanFilterAndSort(false);
// Allow add/update/remove actions, but provisioned especially for translation. Because of this, we will clone
// the default actions so that we may change the class
ListGridAction addAction = DefaultListGridActions.ADD.clone();
ListGridAction removeAction = DefaultListGridActions.REMOVE.clone();
ListGridAction updateAction = DefaultListGridActions.UPDATE.clone();
addAction.setButtonClass("translation-grid-add");
removeAction.setButtonClass("translation-grid-remove");
updateAction.setButtonClass("translation-grid-update");
listGrid.addToolbarAction(addAction);
listGrid.addRowAction(updateAction);
listGrid.addRowAction(removeAction);
// TODO rework code elsewhere so these don't have to be added
listGrid.setSectionKey(Translation.class.getCanonicalName());
listGrid.setSubCollectionFieldName("translation");
// Create records for each of the entries in the translations list
for (Translation t : translations) {
ListGridRecord record = new ListGridRecord();
record.setListGrid(listGrid);
record.setId(String.valueOf(t.getId()));
Locale locale = localeService.findLocaleByCode(t.getLocaleCode());
record.getFields().add(new Field().withName("localeCode").withFriendlyName("Translation_localeCode").withOrder(0).withValue(locale.getLocaleCode()).withDisplayValue(locale.getFriendlyName()));
record.getFields().add(new Field().withName("translatedValue").withFriendlyName("Translation_translatedValue").withOrder(10).withValue(t.getTranslatedValue()).withDisplayValue(isRte ? getLocalizedEditToViewMessage() : t.getTranslatedValue()));
listGrid.getRecords().add(record);
}
listGrid.setTotalRecords(listGrid.getRecords().size());
return listGrid;
}
Aggregations