1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.social.webui.space;
18
19 import java.util.Iterator;
20 import java.util.ResourceBundle;
21
22 import org.exoplatform.services.organization.Group;
23 import org.exoplatform.services.security.ConversationState;
24 import org.exoplatform.services.security.MembershipEntry;
25 import org.exoplatform.social.core.space.SpaceUtils;
26 import org.exoplatform.social.webui.UISocialGroupSelector;
27 import org.exoplatform.webui.application.WebuiRequestContext;
28 import org.exoplatform.webui.config.annotation.ComponentConfig;
29 import org.exoplatform.webui.config.annotation.ComponentConfigs;
30 import org.exoplatform.webui.config.annotation.EventConfig;
31 import org.exoplatform.webui.core.UIContainer;
32 import org.exoplatform.webui.core.UIPopupWindow;
33 import org.exoplatform.webui.event.Event;
34 import org.exoplatform.webui.event.Event.Phase;
35 import org.exoplatform.webui.event.EventListener;
36 import org.exoplatform.webui.form.UIFormInputInfo;
37 import org.exoplatform.webui.form.input.UICheckBoxInput;
38
39 @ComponentConfigs({
40 @ComponentConfig(
41 template = "war:/groovy/social/webui/space/UISpaceGroupBound.gtmpl",
42 events = {@EventConfig(listeners = UISpaceGroupBound.SelectGroupActionListener.class, phase=Phase.DECODE) }
43 ),
44 @ComponentConfig(
45 type = UIPopupWindow.class,
46 id = "SelectGroup",
47 template = "system:/groovy/webui/core/UIPopupWindow.gtmpl",
48 events = @EventConfig(listeners = UISpaceGroupBound.ClosePopupActionListener.class, name = "ClosePopup")
49 )
50 })
51
52 public class UISpaceGroupBound extends UIContainer {
53 private final String USE_EXISTING_GROUP = "UseExistingGroupCheckBox";
54 private final String POPUP_GROUP_BOUND = "UIPopupGroupBound";
55 private final String SELECTED_GROUP = "groupId";
56 private final String ANY_MEMBERSHIP_TYPE = "*";
57
58
59 private static final String HTML_ATTRIBUTE_TITLE = "title";
60
61
62
63
64
65 public UISpaceGroupBound() throws Exception {
66 WebuiRequestContext requestContext = WebuiRequestContext.getCurrentInstance();
67 ResourceBundle resourceBundle = requestContext.getApplicationResourceBundle();
68 UICheckBoxInput uiUseExisting = new UICheckBoxInput(USE_EXISTING_GROUP, null, false);
69 uiUseExisting.setHTMLAttribute(HTML_ATTRIBUTE_TITLE, resourceBundle.getString("UISpaceGroupBound.label.useExistingGroup"));
70 uiUseExisting.setId(USE_EXISTING_GROUP);
71 uiUseExisting.setOnChange("ToggleUseGroup");
72 addChild(uiUseExisting);
73
74 UIFormInputInfo uiFormInputInfo = new UIFormInputInfo(SELECTED_GROUP, null, null);
75 uiFormInputInfo.setId(SELECTED_GROUP);
76 addChild(uiFormInputInfo);
77 UIPopupWindow uiPopup = createUIComponent(UIPopupWindow.class, "SelectGroup", POPUP_GROUP_BOUND);
78 uiPopup.setWindowSize(550, 0);
79 addChild(uiPopup);
80 }
81
82
83
84
85
86 @SuppressWarnings("unchecked")
87 public String getSelectedGroup() {
88 UICheckBoxInput uiCheckBox = getChild(UICheckBoxInput.class);
89 if(uiCheckBox.isChecked()) {
90 UIFormInputInfo uiInfo = getChild(UIFormInputInfo.class);
91 return uiInfo.getValue();
92 }
93 return null;
94 }
95
96
97
98
99
100
101
102 protected boolean hasGroupWithManagerRole() throws Exception {
103 String adminMSType = SpaceUtils.getUserACL().getAdminMSType();
104
105 Iterator<MembershipEntry> iter = ConversationState.getCurrent().getIdentity().getMemberships().iterator();
106 while (iter.hasNext()) {
107 String msType = iter.next().getMembershipType();
108
109 if (ANY_MEMBERSHIP_TYPE.equals(msType) || adminMSType.equals(msType)) {
110 return true;
111 }
112 }
113
114 return false;
115 }
116
117
118
119
120 static public class SelectGroupActionListener extends EventListener<UISocialGroupSelector> {
121 public void execute(Event<UISocialGroupSelector> event) throws Exception {
122 WebuiRequestContext context = event.getRequestContext();
123 String groupId = context.getRequestParameter(OBJECTID);
124 UISocialGroupSelector uiGroupSelector = event.getSource();
125 UISpaceGroupBound uiGroupBound = uiGroupSelector.getAncestorOfType(UISpaceGroupBound.class);
126 UIFormInputInfo uiFormInputInfo = uiGroupBound.getChild(UIFormInputInfo.class);
127 uiFormInputInfo.setValue(groupId);
128 event.getRequestContext().addUIComponentToUpdateByAjax(uiGroupBound);
129 }
130 }
131
132
133
134
135
136 static public class ClosePopupActionListener extends EventListener<UIPopupWindow> {
137 @SuppressWarnings("unchecked")
138 @Override
139 public void execute(Event<UIPopupWindow> event) throws Exception {
140 UIPopupWindow uiPopup = event.getSource();
141 UISpaceGroupBound uiGroupBound = uiPopup.getAncestorOfType(UISpaceGroupBound.class);
142 UISocialGroupSelector uiGroupSelector = (UISocialGroupSelector)uiPopup.getUIComponent();
143 Group group = uiGroupSelector.getCurrentGroup();
144 if (group == null) {
145 UICheckBoxInput uiUseExisting = uiGroupBound.getChild(UICheckBoxInput.class);
146 uiUseExisting.setChecked(false);
147 } else {
148 UIFormInputInfo uiSelected = uiGroupBound.getChild(UIFormInputInfo.class);
149 uiSelected.setValue(group.getId());
150 }
151 uiPopup.setShow(false);
152 }
153 }
154 }