BrightSide Workbench Full Report + Source Code
Elephant/elephant-mail/src/main/java/org/turro/mail/model/CategoriesVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2017 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.mail.model;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 import org.turro.action.queue.ConstraintKeys;
24 import org.turro.action.queue.NotificationCategory;
25 import org.turro.action.queue.Notifications;
26 import org.turro.action.queue.QueuePeriod;
27 import org.turro.auth.Authentication;
28 import org.turro.i18n.I_;
29 import org.turro.mail.queue.QueueManager;
30 import org.turro.plugin.contacts.IContact;
31 import org.zkoss.bind.annotation.BindingParam;
32 import org.zkoss.bind.annotation.Command;
33 import org.zkoss.bind.annotation.ExecutionArgParam;
34 import org.zkoss.bind.annotation.Init;
35 import org.zkoss.bind.annotation.NotifyChange;
36 
41 public class CategoriesVM {
42 
43  private IContact contact = Authentication.getIContact();
44 
45  @Init
46  public void init(@ExecutionArgParam("contact") IContact contact) {
47  if(contact != null) this.contact = contact;
48  }
49 
50  @Command
51  @NotifyChange("*")
52  public void check(@BindingParam("entity") Object entity, @BindingParam("period") Object period) {
53  if((period instanceof QueuePeriod) && (entity instanceof NotificationCategory)) {
54  QueuePeriod qp = (QueuePeriod) period;
56  nc.getNotification().subscribe(nc.getIdCategory(), contact, qp);
57  }
58  }
59 
60  public boolean isChecked(NotificationCategory entity, QueuePeriod period) {
61  QueuePeriod qp = getPeriod(entity);
62  return qp != null ? period.equals(qp) : false;
63  }
64 
65  public List<NotificationCategory> getModel() {
66  ArrayList<NotificationCategory> list = new ArrayList<>();
68  if(nc.isPublishable() && nc.strongBond(ConstraintKeys.from(contact))) {
69  list.add(nc);
70  }
71  }
72  return list;
73  }
74 
75  public String getLabel(String label) {
76  return I_.get(label);
77  }
78 
80  return entity.getNotification().period(entity.getIdCategory(), contact);
81  }
82 
83 }
static ConstraintKeys from(IContact contact)
static Collection< NotificationCategory > getCategories()
static String get(String msg)
Definition: I_.java:41
void check(@BindingParam("entity") Object entity, @BindingParam("period") Object period)
QueuePeriod period(String idCategory, IContact contact)
void subscribe(String idCategory, IContact contact, QueuePeriod period)