package com.jcommerce.gwt.client.panels.promote;
import java.util.ArrayList;
import java.util.List;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.event.ButtonEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Label;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.grid.CheckBoxSelectionModel;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.TextBox;
import com.jcommerce.gwt.client.ContentWidget;
import com.jcommerce.gwt.client.ModelNames;
import com.jcommerce.gwt.client.PageState;
import com.jcommerce.gwt.client.form.BeanObject;
import com.jcommerce.gwt.client.model.IGroupBuy;
import com.jcommerce.gwt.client.panels.order.OrderListPanel;
import com.jcommerce.gwt.client.resources.Resources;
import com.jcommerce.gwt.client.service.Criteria;
import com.jcommerce.gwt.client.service.PagingListService;
import com.jcommerce.gwt.client.widgets.ActionCellRenderer;
import com.jcommerce.gwt.client.widgets.ColumnPanel;
public class GroupBuyListPanel extends ContentWidget {
private PagingToolBar toolBar;
private ListStore<BeanObject> store;
private Grid<BeanObject> grid;
Criteria criteria = new Criteria();
ColumnPanel contentPanel = new ColumnPanel();
TextBox txtUserName = new TextBox();
Button btnSearch = new Button("搜索");
public static class State extends PageState {
public String getPageClassName() {
return GroupBuyListPanel.class.getName();
}
public String getMenuDisplayName() {
return "团购活动列表 ";
}
}
public State getCurState() {
if (curState == null ) {
curState = new State();
}
return (State)curState;
}
public String getDescription() {
return "cwBasicTextDescription";
}
public String getName() {
return "团购活动列表 ";
}
public String getButtonText() {
return "添加团购活动";
}
protected void buttonClicked() {
NewGroupBuyPanel.State state = new NewGroupBuyPanel.State();
state.execute();
}
public GroupBuyListPanel() {
initJS(this);
}
private native void initJS(GroupBuyListPanel me) /*-{
$wnd.searchOrder = function (id) {
me.@com.jcommerce.gwt.client.panels.promote.GroupBuyListPanel::searchGroupBuyAndRefrsh(Ljava/lang/String;)(id);
};
$wnd.editGroupBuy = function (id) {
me.@com.jcommerce.gwt.client.panels.promote.GroupBuyListPanel::editGroupBuyAndRefrsh(Ljava/lang/String;)(id);
};
$wnd.deleteGroupBuy = function (id) {
me.@com.jcommerce.gwt.client.panels.promote.GroupBuyListPanel::deleteGroupBuyAndRefrsh(Ljava/lang/String;)(id);
};
}-*/;
private void searchGroupBuyAndRefrsh(final String id) {
OrderListPanel.State state = new OrderListPanel.State();
state.execute();
}
private void editGroupBuyAndRefrsh(final String id) {
}
private void deleteGroupBuyAndRefrsh(final String id) {
}
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
HorizontalPanel header = new HorizontalPanel();
header.add(Resources.images.icon_search().createImage());
header.add(new Label("活动名称"));
header.add(txtUserName);
header.add(btnSearch);
add(header);
BasePagingLoader loader = new PagingListService().getLoader(ModelNames.GROUPBUY, criteria);
loader.load(0, 10);
store = new ListStore<BeanObject>(loader);
toolBar = new PagingToolBar(10);
toolBar.bind(loader);
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
final CheckBoxSelectionModel<BeanObject> smRowSelection = new CheckBoxSelectionModel<BeanObject>();
columns.add(smRowSelection.getColumn());
columns.add(new ColumnConfig("number", "编号", 50));
columns.add(new ColumnConfig(IGroupBuy.GOOD_NAME, "商品名称", 150));
columns.add(new ColumnConfig(IGroupBuy.ACTIVITY_STATE, "状态", 150));
columns.add(new ColumnConfig(IGroupBuy.END_TIME, "结束时间", 150));
columns.add(new ColumnConfig(IGroupBuy.SEC_PRICE, "保证金", 50));
columns.add(new ColumnConfig(IGroupBuy.LIMIT_NUM, "限购", 50));
columns.add(new ColumnConfig(IGroupBuy.GOOD_NAME, "订购商品", 50));
columns.add(new ColumnConfig(IGroupBuy.SEC_PRICE, "订单", 50));
columns.add(new ColumnConfig(IGroupBuy.GOOD_NAME, "当前价格", 100));
ColumnConfig action = new ColumnConfig("", "操作", 100);
columns.add(action);
ColumnModel cm = new ColumnModel(columns);
grid = new Grid<BeanObject>(store, cm);
grid.setLoadMask(true);
grid.setBorders(true);
grid.setSelectionModel(smRowSelection);
grid.addPlugin(smRowSelection);
grid.setHeight(350);
ActionCellRenderer render = new ActionCellRenderer(grid);
ActionCellRenderer.ActionInfo act = new ActionCellRenderer.ActionInfo();
act.setText("查看");
act.setTooltip("查看订单");
act.setAction("searchOrder($id)");
render.addAction(act);
act = new ActionCellRenderer.ActionInfo();
act.setAction("editGroupBuy($id)");
act.setText("编辑");
act.setTooltip("编辑");
render.addAction(act);
act = new ActionCellRenderer.ActionInfo();
act.setAction("deleteGroupBuy($id)");
act.setText("删除");
act.setTooltip("删除");
render.addAction(act);
action.setRenderer(render);
ContentPanel panel = new ContentPanel();
panel.setFrame(true);
panel.setCollapsible(true);
panel.setAnimCollapse(false);
panel.setButtonAlign(HorizontalAlignment.CENTER);
panel.setIconStyle("icon-table");
panel.setLayout(new FitLayout());
panel.add(grid);
panel.setBottomComponent(toolBar);
btnSearch.addSelectionListener(new SelectionListener<ButtonEvent>(){
public void componentSelected(ButtonEvent ce) {
List<BeanObject> newBeans = new ArrayList<BeanObject>();
for(BeanObject bean : store.getModels()) {
if(bean.getString(IGroupBuy.GOOD_NAME).equals(txtUserName.getText())) {
newBeans.add(bean);
}
}
if(newBeans.size() > 0) {
store.removeAll();
store.add(newBeans);
store.commitChanges();
}
}});
contentPanel.add(panel);
add(contentPanel);
}
public void refresh() {
toolBar.refresh();
}
}