BrightSide Workbench Full Report + Source Code
SubtaskViewVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 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.Issue;
26 import org.turro.dossier.util.DossiersInfo;
27 import org.turro.dossier.zul.menu.DossierMenu;
28 import org.turro.elephant.context.Application;
29 import org.turro.i18n.I_;
30 import org.turro.zkoss.dialog.SelectionDialog;
31 import org.turro.zul.frame.Framework;
32 import org.zkoss.bind.BindUtils;
33 import org.zkoss.bind.annotation.BindingParam;
34 import org.zkoss.bind.annotation.Command;
35 import org.zkoss.bind.annotation.ExecutionArgParam;
36 import org.zkoss.bind.annotation.Init;
37 import org.zkoss.bind.annotation.NotifyChange;
38 import org.zkoss.zk.ui.Component;
39 
44 public class SubtaskViewVM {
45 
46  private final boolean show, all, addNew;
47  private Issue issue;
48 
49  public SubtaskViewVM() {
51  show = app.isInRole("issue:show");
52  all = app.isInRole("issue:all");
53  addNew = app.isInRole("issue:new");
54  }
55 
56  @Init
57  public void init(@ExecutionArgParam("issue") Issue issue) {
58  this.issue = issue;
59  }
60 
61  @Command
62  public void showInfo(@BindingParam("taskItem") TaskItem taskItem,
63  @BindingParam("component") Component component, @BindingParam("position") String position) {
64  if(show && (all || taskItem.getIssue().getFullParticipants().isParticipant())) {
65  DossiersInfo.popup(taskItem.getIssue());
66  }
67  }
68 
69  @Command
70  public void showIssue(@BindingParam("issue") Issue issue) {
71  DossierMenu.showIssue(issue.getId());
72  }
73 
74  @NotifyChange("model")
75  @Command("update")
76  public void update() {}
77 
78  @Command
79  public void showAttachments(@BindingParam("issue") Issue issue) {
80  if(show && (all || issue.getFullParticipants().isParticipant())) {
82  ac.setEntity(issue);
83  SelectionDialog.showComponent(Framework.getCurrent().getPage(), I_.get("Attachments"),
84  ac, "80%", "80%", null);
85  }
86  }
87 
88  @Command
89  public void addInformation(@BindingParam("issue") Issue issue) {
90  if(show && (all || issue.getFullParticipants().isParticipant())) {
91  DossierMenu.addInformation(issue, (Context context) -> {
92  BindUtils.postNotifyChange(null, null, SubtaskViewVM.this, "model");
93  return null;
94  });
95  }
96  }
97 
98  @Command
99  public void addSubtask(@BindingParam("issue") Issue issue) {
100  if(all || addNew) {
101  DossierMenu.addSubtask(issue, (Context context) -> {
102  BindUtils.postNotifyChange(null, null, SubtaskViewVM.this, "model");
103  return null;
104  });
105  }
106  }
107 
108  public Collection<TaskItem> getModel() {
109  if(issue != null) {
110  return Tasks.from(issue, false, false).getFilledFlat();
111  } else {
112  return Collections.EMPTY_LIST;
113  }
114  }
115 
116 }
ParticipantSet getFullParticipants()
Definition: Issue.java:461
void init(@ExecutionArgParam("issue") Issue issue)
void showIssue(@BindingParam("issue") Issue issue)
void showInfo(@BindingParam("taskItem") TaskItem taskItem, @BindingParam("component") Component component, @BindingParam("position") String position)
Collection< TaskItem > getModel()
void addSubtask(@BindingParam("issue") Issue issue)
void addInformation(@BindingParam("issue") Issue issue)
void showAttachments(@BindingParam("issue") Issue issue)
static Tasks from(Dossier dossier, boolean onlyOpen, boolean sameDossier)
static void popup(Issue issue)
static void addSubtask(Issue issue, final 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