BrightSide Workbench Full Report + Source Code
TaskViewVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.dossier.task;
20 
21 import java.util.Collection;
22 import java.util.Collections;
23 import org.turro.attach.zul.control.AttachmentControl;
24 import org.turro.command.Context;
25 import org.turro.dossier.entity.Dossier;
26 import org.turro.dossier.entity.Issue;
27 import org.turro.dossier.util.DossiersInfo;
28 import org.turro.dossier.zul.menu.DossierMenu;
29 import org.turro.elephant.context.Application;
30 import org.turro.i18n.I_;
31 import org.turro.zkoss.dialog.SelectionDialog;
32 import org.turro.zul.frame.Framework;
33 import org.zkoss.bind.BindUtils;
34 import org.zkoss.bind.annotation.BindingParam;
35 import org.zkoss.bind.annotation.Command;
36 import org.zkoss.bind.annotation.NotifyChange;
37 import org.zkoss.zk.ui.Component;
38 
43 public class TaskViewVM {
44 
45  private final boolean show, all, addNew;
46  private Dossier dossier;
47  private boolean onlyOpen = false;
48 
49  public TaskViewVM() {
51  show = app.isInRole("issue:show");
52  all = app.isInRole("issue:all");
53  addNew = app.isInRole("issue:new");
54  }
55 
56  @Command
57  public void showInfo(@BindingParam("taskItem") TaskItem taskItem,
58  @BindingParam("component") Component component, @BindingParam("position") String position) {
59  if(show && (all || taskItem.getIssue().getFullParticipants().isParticipant())) {
60  DossiersInfo.popup(taskItem.getIssue());
61  }
62  }
63 
64  @Command
65  public void showIssue(@BindingParam("issue") Issue issue) {
66  DossierMenu.showIssue(issue.getId());
67  }
68 
69  @NotifyChange("model")
70  @Command("update")
71  public void update() {}
72 
73  @NotifyChange("model")
74  @Command
75  public void selectDossier(@BindingParam("dossier") Dossier dossier) {
76  setDossier(dossier);
77  }
78 
79  @NotifyChange("model")
80  @Command
81  public void onlyOpen(@BindingParam("onlyOpen") Boolean onlyOpen) {
82  this.onlyOpen = onlyOpen;
83  }
84 
85  @Command
86  public void showAttachments(@BindingParam("issue") Issue issue) {
87  if(show && (all || issue.getFullParticipants().isParticipant())) {
89  ac.setEntity(issue);
90  SelectionDialog.showComponent(Framework.getCurrent().getPage(), I_.get("Attachments"),
91  ac, "80%", "80%", null);
92  }
93  }
94 
95  @Command
96  public void addInformation(@BindingParam("issue") Issue issue) {
97  if(show && (all || issue.getFullParticipants().isParticipant())) {
98  DossierMenu.addInformation(issue, (Context context) -> {
99  BindUtils.postNotifyChange(null, null, TaskViewVM.this, "model");
100  return null;
101  });
102  }
103  }
104 
105  @Command
106  public void addIssue() {
107  if(all || addNew) {
108  DossierMenu.addDossierInformation(dossier, (Context context) -> {
109  BindUtils.postNotifyChange(null, null, TaskViewVM.this, "model");
110  return null;
111  });
112  }
113  }
114 
115  public Dossier getDossier() {
116  return dossier;
117  }
118 
119  public void setDossier(Dossier dossier) {
120  this.dossier = dossier;
121  }
122 
123  public Collection<TaskItem> getModel() {
124  if(dossier != null) {
125  return Tasks.from(dossier, onlyOpen, true).getFilledFlat();
126  } else {
127  return Collections.EMPTY_LIST;
128  }
129  }
130 
131 }
ParticipantSet getFullParticipants()
Definition: Issue.java:461
void showIssue(@BindingParam("issue") Issue issue)
Definition: TaskViewVM.java:65
void onlyOpen(@BindingParam("onlyOpen") Boolean onlyOpen)
Definition: TaskViewVM.java:81
void selectDossier(@BindingParam("dossier") Dossier dossier)
Definition: TaskViewVM.java:75
void showAttachments(@BindingParam("issue") Issue issue)
Definition: TaskViewVM.java:86
Collection< TaskItem > getModel()
void showInfo(@BindingParam("taskItem") TaskItem taskItem, @BindingParam("component") Component component, @BindingParam("position") String position)
Definition: TaskViewVM.java:57
void addInformation(@BindingParam("issue") Issue issue)
Definition: TaskViewVM.java:96
void setDossier(Dossier dossier)
static Tasks from(Dossier dossier, boolean onlyOpen, boolean sameDossier)
static void popup(Issue issue)
static void addDossierInformation(Dossier dossier, Command command)
static void addInformation(Issue issue, final Command command)
static String get(String msg)
Definition: I_.java:41
static void showComponent(Page page, String title, Component component, String width, String height, final Command command)
static Framework getCurrent()
Definition: Framework.java:203