All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.broadleafcommerce.admin.client.presenter.promotion.OfferPresenterInitializer Maven / Gradle / Ivy

/*
 * Copyright 2008-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.broadleafcommerce.admin.client.presenter.promotion;

import com.google.gwt.core.client.GWT;
import com.smartgwt.client.data.AdvancedCriteria;
import com.smartgwt.client.data.Criteria;
import com.smartgwt.client.data.DSCallback;
import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DSResponse;
import com.smartgwt.client.data.Record;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import org.broadleafcommerce.admin.client.view.promotion.OfferDisplay;
import org.broadleafcommerce.openadmin.client.BLCMain;
import org.broadleafcommerce.openadmin.client.datasource.dynamic.DynamicEntityDataSource;
import org.broadleafcommerce.openadmin.client.translation.IncompatibleMVELTranslationException;
import org.broadleafcommerce.openadmin.client.translation.MVELToAdvancedCriteriaTranslator;
import org.broadleafcommerce.openadmin.client.view.dynamic.ItemBuilderDisplay;

import java.util.LinkedHashMap;

/**
 * 
 * @author jfischer
 *
 */
public class OfferPresenterInitializer {

	private static final MVELToAdvancedCriteriaTranslator TRANSLATOR = new MVELToAdvancedCriteriaTranslator();
	
	protected OfferPresenter presenter;
	protected boolean customerRuleIncompatible = false;
	protected boolean orderRuleIncompatible = false;
	protected boolean fgRuleIncompatible = false;
	protected DynamicEntityDataSource offerItemCriteriaDataSource;
	protected DynamicEntityDataSource orderItemDataSource;
	
	public OfferPresenterInitializer(OfferPresenter presenter, DynamicEntityDataSource offerItemCriteriaDataSource, DynamicEntityDataSource orderItemDataSource) {
		this.presenter = presenter;
		this.offerItemCriteriaDataSource = offerItemCriteriaDataSource;
		this.orderItemDataSource = orderItemDataSource;
	}
	
	protected OfferDisplay getDisplay() {
		return presenter.getDisplay();
	}
	
	public void initSectionBasedOnType(String sectionType, Record selectedRecord) {
        getDisplay().getCustomerLayout().setVisible(true);
        getDisplay().getOrderSectionLayout().setVisible(true);
        getDisplay().getCustomerSection().setVisible(true);
        getDisplay().getOrderSection().setVisible(true);
		getDisplay().getItemQualificationSectionView().setVisible(true);
		if (sectionType.equals("FULFILLMENT_GROUP")) {
			getDisplay().getFgSectionView().setVisible(true);
		} else {
			getDisplay().getFgSectionView().setVisible(false);
		}
		if (sectionType.equals("ORDER_ITEM")) {
			getDisplay().getBogoQuestionLayout().setVisible(true);
			getDisplay().getItemTargetSectionView().setVisible(true);
			getDisplay().getOrderItemLayout().setVisible(false);
			getDisplay().getRequiredItemsLayout().setVisible(false);
			getDisplay().getOrderItemCombineForm().setVisible(true);
			getDisplay().getOrderItemCombineLabel().setVisible(true);
		} else {
			getDisplay().getBogoQuestionLayout().setVisible(false);
			getDisplay().getItemTargetSectionView().setVisible(false);
			getDisplay().getRequiredItemsLayout().setVisible(true);
			getDisplay().getOrderItemLayout().setVisible(true);
			getDisplay().getOrderItemCombineForm().setVisible(false);
			getDisplay().getOrderItemCombineLabel().setVisible(false);
		}
		if (sectionType.equals("ORDER")) {
			getDisplay().getOrderCombineForm().setVisible(true);
			getDisplay().getOrderCombineLabel().setVisible(true);
			
			//Order promotions cannot have a discount type of "FIX_PRICE", since it would not be correct to set the order total to a fixed amount
			LinkedHashMap valueMap = new LinkedHashMap();
			String[][] enumerationValues = (String[][]) getDisplay().getDynamicFormDisplay().getFormOnlyDisplay().getForm().getDataSource().getField("discountType").getAttributeAsObject("enumerationValues");
			for (int j=0; j




© 2015 - 2025 Weber Informatics LLC | Privacy Policy