package hu.user.lis.ui.view;
-import com.google.common.collect.ImmutableMap;
import hu.user.lis.db.*;
import hu.user.lis.db.repository.filter.DateType;
import hu.user.lis.db.repository.filter.InvoiceFilter;
import hu.user.lis.ui.data.InvoiceDataModel;
import hu.user.lis.ui.data.InvoicesDataModel;
import hu.user.lis.ui.data.common.CachedSpringDataModel;
+import hu.user.lis.ui.data.common.ColDef;
import hu.user.lis.ui.editor.common.Editors;
import hu.user.lis.ui.editor.selector.EntitySelectorRouter;
import hu.user.lis.ui.event.EventBus;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;
import org.springframework.transaction.annotation.Transactional;
+import org.zkoss.bind.BindContext;
import org.zkoss.bind.BindUtils;
import org.zkoss.bind.PropertyChangeEvent;
import org.zkoss.bind.annotation.*;
import org.zkoss.zk.ui.Component;
+import org.zkoss.zk.ui.event.DropEvent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.select.annotation.WireVariable;
+import org.zkoss.zul.Listheader;
+import org.zkoss.zul.event.ColSizeEvent;
-import static hu.user.lis.ui.data.common.CachedDataModel.ASCENDING;
-import static hu.user.lis.ui.data.common.CachedDataModel.NATURAL;
+import java.util.Arrays;
@Log4j2
public class InvoicesViewModel extends EntityViewModel<Invoice> implements EventListener<Event> {
.build();
eventBus.register(this);
eventBus.registerForBinding(this);
- addColumns(ImmutableMap.of(
- "planned", NATURAL,
- "humanId", NATURAL,
- "partner.name", NATURAL,
- "project.humanId", NATURAL,
- "project.name", NATURAL,
- "paymentDeadline", ASCENDING,
- "grossAmount", NATURAL,
- "currency", NATURAL,
- "incoming", NATURAL
+
+ addColumns(Arrays.asList(
+ "planned,Terv,ascending,left,true",
+ "humanId,Sorszám,natural,left,true",
+ "partner.name,Partner név,natural,left,true",
+ "project.humanId,Projekt azonosító,natural,left,true",
+ "project.name,Projekt név,natural,left,true",
+ "paymentDeadline,Fizetési határidő,ascending,right,true",
+ "grossAmount,Bruttó összeg,natural,right,true",
+ "currency,Pénznem,natural,left,true",
+ "incoming,Költség/Bevétel,natural,left,true"
));
+
refresh();
}
public void onInvoicePayment() {
eventBus.showInvoicePayment(getSelectedEntity().getId());
}
+
+ public void onHeaderMenuClicked(@BindingParam("node") ColDef node) {
+ invoicesDataModel.onHeaderMenuClicked(node);
+ }
+
+ @Command
+ public void onHeaderSizeChanged(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx, @BindingParam("node") ColDef node) {
+ ColSizeEvent evt = (ColSizeEvent) ctx.getTriggerEvent();
+ invoicesDataModel.onHeaderSizeChanged(evt.getColIndex(), evt.getWidth());
+ }
+
+ @Command
+ public void onHeaderReorder(@ContextParam(ContextType.BIND_CONTEXT) BindContext ctx) {
+ DropEvent ev = (DropEvent) ctx.getTriggerEvent();
+ Listheader dragged = (Listheader) ev.getDragged();
+ Listheader dropped = (Listheader) ev.getTarget();
+ invoicesDataModel.onHeaderReorder(dragged, dropped);
+ }
+
}
Listheader dragged = (Listheader) ev.getDragged();
Listheader dropped = (Listheader) ev.getTarget();
partnersDataModel.onHeaderReorder(dragged, dropped);
-// int from = lHead.getChildren().indexOf(dragged);
-// int to = lHead.getChildren().indexOf(droppedOn);
-//
-// // swap the positions
-// lHead.insertBefore(dragged, droppedOn);
-//
-// // swap related Listcell in all Listitem instances
-// for (Listitem item : lbox.getItems()) {
-// item.insertBefore(item.getChildren().get(from), item.getChildren().get(to));
-// }
-
}
@Override
public void render(Listitem item, final Object data, final int index) throws Exception {
- log.info("Rendering item index {}, index {}", item.getIndex(), index);
final Listbox listbox = (Listbox) item.getParent();
final int size = listbox.getModel().getSize();
String subtype = item instanceof Listgroup ? "group" : (item instanceof Listgroupfoot ? "groupfoot" : null);
List<org.zkoss.zk.ui.Component> children = new ArrayList<>(nli.getChildren());
nli.getChildren().clear();
-// nli.appendChild(children.get(3));
-// nli.appendChild(children.get(2));
-// nli.appendChild(children.get(1));
-// nli.appendChild(children.get(0));
for (int i = 0; i < columnSettings.length; i++) {
int mappedIndex = columnSettings[i].getIndex();
</toolbar>
</vlayout>
</north>
- <center border="none" hflex="true" vflex="true">
- <listbox id="invoicesList" vflex="true" model="@load(vm.invoicesDataModel)"
- autopaging="true" mold="paging" pagingPosition="top" multiple="false"
- onSelect="@command('onListSelection')">
- <listhead sizable="true">
- <listheader width="30px" label="Terv" sort="auto(planned)" align="left"
- sortDirection="@load(vm.cols['planned'].sortDirection)"/>
- <listheader label="Sorszám" sort="auto(humanId)" align="left"
- sortDirection="@load(vm.cols['humanId'].sortDirection)"/>
- <listheader label="Partner név" sort="auto(partner.name)" align="left"
- sortDirection="@load(vm.cols['partner.name'].sortDirection)"/>
- <listheader label="Projekt azonosító" sort="auto(project.humanId)" align="left"
- sortDirection="@load(vm.cols['project.humanId'].sortDirection)"/>
- <listheader label="Projekt név" sort="auto(project.name)" align="left"
- sortDirection="@load(vm.cols['project.name'].sortDirection)"/>
- <listheader label="Fizetési határidő" sort="auto(paymentDeadline)" align="left"
- sortDirection="@load(vm.cols['paymentDeadline'].sortDirection)"/>
- <listheader label="Bruttó összeg" sort="auto(grossAmount)" align="right"
- style="text-align: center"
- sortDirection="@load(vm.cols['grossAmount'].sortDirection)"/>
- <listheader label="Pénznem" sort="auto(currency)" align="left"
- sortDirection="@load(vm.cols['currency'].sortDirection)"/>
- <listheader label="Költség/Bevétel" sort="auto(incoming)" align="left"
- sortDirection="@load(vm.cols['incoming'].sortDirection)"/>
- </listhead>
- <template name="model">
- <listitem onDoubleClick="@command('onEdit')">
- <listcell>
- <a iconSclass="z-icon-map-marker" visible="@load(each.planned)"
- style="@load(each.planned ? 'color: gray' : 'color: black')"/>
- </listcell>
- <listcell label="@load(each.humanId)"
- style="@load(each.planned ? 'color: gray' : 'color: black')"/>
- <listcell label="@load(each.partner.name)"
- style="@load(each.planned ? 'color: gray' : 'color: black')"/>
- <listcell label="@load(each.project.humanId)"
- style="@load(each.planned ? 'color: gray' : 'color: black')"/>
- <listcell label="@load(each.project.name)"
- style="@load(each.planned ? 'color: gray' : 'color: black')"/>
- <listcell
- label="@load(each.paymentDeadline) @converter('hu.user.lis.ui.converter.DateToStringConverter')"
- style="@load(each.planned ? 'color: gray' : 'color: black')"/>
- <listcell
- label="@load(each.grossAmount) @converter('hu.user.lis.ui.converter.DoubleToStringConverter')"
- style="@load(each.planned ? 'color: gray' : 'color: black')"/>
- <listcell label="@load(each.currency)"
- style="@load(each.planned ? 'color: gray' : 'color: black')"/>
- <listcell>
- <a iconSclass="z-icon-external-link" visible="@load(each.incoming)"
- style="@load(each.planned ? 'color: gray' : 'color: black')"/>
- <a iconSclass="z-icon-sign-in" visible="@load(!each.incoming)"
- style="@load(each.planned ? 'color: gray' : 'color: black')"/>
- </listcell>
- </listitem>
- </template>
- </listbox>
+ <center border="none">
+ <vlayout vflex="true" hflex="true">
+ <menupopup id="editPopup"
+ children="@bind(vm.invoicesDataModel.renderer.columnSettings) @template('menu-item')">
+ <template name="menu-item" var="node">
+ <menuitem label="@load(node.label)" checked="@load(node.visible)"
+ onClick="@command('onHeaderMenuClicked', node=node)"/>
+ </template>
+ </menupopup>
+ <listbox id="invoicesList" vflex="true" model="@load(vm.invoicesDataModel)" multiple="false"
+ itemRenderer="@load(vm.invoicesDataModel.renderer)" onSelect="@command('onListSelection')">
+ <listhead sizable="true" menupopup="editPopup"
+ onColSize="@command('onHeaderSizeChanged', node=node)"
+ children="@bind(vm.invoicesDataModel.renderer.columnSettings) @template('head-item')">
+ <template name="head-item" var="node">
+ <listheader label="@load(node.label)" sort="@load(node.sort)" align="@load(node.align)"
+ visible="@load(node.visible)" width="@load(node.width)" draggable="head"
+ droppable="head" sortDirection="@load(node.sortDirection)"
+ onDrop="@command('onHeaderReorder')"/>
+ </template>
+ </listhead>
+ <template name="model">
+ <listitem onDoubleClick="@command('onEdit')">
+ <listcell>
+ <a iconSclass="z-icon-map-marker" visible="@load(each.planned)"
+ style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+ </listcell>
+ <listcell label="@load(each.humanId)"
+ style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+ <listcell label="@load(each.partner.name)"
+ style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+ <listcell label="@load(each.project.humanId)"
+ style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+ <listcell label="@load(each.project.name)"
+ style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+ <listcell
+ label="@load(each.paymentDeadline) @converter('hu.user.lis.ui.converter.DateToStringConverter')"
+ style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+ <listcell
+ label="@load(each.grossAmount) @converter('hu.user.lis.ui.converter.DoubleToStringConverter')"
+ style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+ <listcell label="@load(each.currency)"
+ style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+ <listcell>
+ <a iconSclass="z-icon-external-link" visible="@load(each.incoming)"
+ style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+ <a iconSclass="z-icon-sign-in" visible="@load(!each.incoming)"
+ style="@load(each.planned ? 'color: gray' : 'color: black')"/>
+ </listcell>
+ </listitem>
+ </template>
+ </listbox>
+ </vlayout>
</center>
</borderlayout>
</window>
</toolbar>
</north>
- <center border="none" flex="true">
- <vlayout>
+ <center border="none">
+ <vlayout vflex="true" hflex="true">
<menupopup id="editPopup"
children="@bind(vm.partnersDataModel.renderer.columnSettings) @template('menu-item')">
<template name="menu-item" var="node">
onClick="@command('onHeaderMenuClicked', node=node)"/>
</template>
</menupopup>
- <listbox vflex="true" model="@load(vm.partnersDataModel)"
- itemRenderer="@load(vm.partnersDataModel.renderer)"
- autopaging="true" multiple="false"
- onSelect="@command('onListSelection')">
+ <listbox vflex="true" model="@load(vm.partnersDataModel)" multiple="false"
+ itemRenderer="@load(vm.partnersDataModel.renderer)" onSelect="@command('onListSelection')">
<listhead sizable="true" menupopup="editPopup"
onColSize="@command('onHeaderSizeChanged', node=node)"
children="@bind(vm.partnersDataModel.renderer.columnSettings) @template('head-item')">