BrightSide Workbench Full Report + Source Code
ImpersonateControl.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2018 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.elephant.signin;
20 
21 import java.io.IOException;
22 import org.turro.auth.Authentication;
23 import org.turro.command.Command;
24 import org.turro.command.Context;
25 import org.turro.elephant.TemplateControl;
26 import org.turro.elephant.context.Application;
27 import org.turro.entities.EntityCombobox;
28 import org.turro.i18n.I_;
29 import org.turro.zkoss.dialog.InputDialog;
30 import org.turro.zkoss.dialog.InputField;
31 import org.zkoss.zk.ui.HtmlBasedComponent;
32 import org.zkoss.zk.ui.event.Event;
33 import org.zkoss.zk.ui.select.annotation.Listen;
34 import org.zkoss.zk.ui.select.annotation.Wire;
35 import org.zkoss.zul.A;
36 import org.zkoss.zul.Div;
37 
42 public class ImpersonateControl extends TemplateControl {
43 
44  @Wire("#impersonateform")
45  private Div impersonateform;
46 
47  @Wire("#impersonate")
48  private A impersonate;
49 
50  @Wire("#backtoself")
51  private A backtoself;
52 
53  @Listen("onClick = #impersonate")
54  public void onImpersonate(Event event) throws IOException {
56  getPage(),
57  I_.get("Impersonate"),
58  new InputField[] {
59  new InputField("Contact", null, null, 0) {
60  @Override
61  protected HtmlBasedComponent createEditor() {
62  EntityCombobox ec = new EntityCombobox();
63  ec.setRoot("contact");
64  return ec;
65  }
66  @Override
67  protected Object getEditorValue() {
68  return ((EntityCombobox) editor).getObjectValue();
69  }
70  }
71  }, new Command() {
72  @Override
73  public Object execute(Context context) {
74  InputField[] fields = (InputField[]) context.get("fields");
75  if(fields.length > 0) {
76  for(InputField f : fields) {
77  if("Contact".equals(f.getLabel())) {
78  Authentication.impersonateContact(f.getValue());
80  break;
81  }
82  }
83  }
84  return null;
85  }
86  });
87  }
88 
89  @Listen("onClick = #backtoself")
90  public void onBackToSelf() {
93  }
94 
95  @Override
96  public void doFinally() {
97  impersonate.setVisible(Authentication.canImpersonate());
98  backtoself.setVisible(Authentication.isBehaving());
99  impersonateform.setVisible(impersonate.isVisible() || backtoself.isVisible());
100  }
101 
102 }
103 
static void impersonateIContact(IContact contact)
static void impersonateContact(Object contact)
abstract void sendRedirect(String uri)
static String get(String msg)
Definition: I_.java:41
static void getInput(Page page, String title, String label, Object value, String format, int scale, final Command onOk)