1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.exoplatform.ecm.permission.info;
18
19 import org.exoplatform.ecm.webui.form.UIFormInputSetWithAction;
20 import org.exoplatform.services.jcr.access.PermissionType;
21 import org.exoplatform.webui.config.annotation.ComponentConfig;
22 import org.exoplatform.webui.event.Event;
23 import org.exoplatform.webui.event.EventListener;
24 import org.exoplatform.webui.form.UIForm;
25 import org.exoplatform.webui.form.UIFormStringInput;
26 import org.exoplatform.webui.form.input.UICheckBoxInput;
27
28
29
30
31
32
33
34 @ComponentConfig(template = "classpath:groovy/ecm/webui/form/UIPermissionInputSet.gtmpl")
35 public class UIPermissionInputSet extends UIFormInputSetWithAction {
36
37 final static public String FIELD_USERORGROUP = "userOrGroup";
38 private String[] buttonActions_ = {"Save", "Reset"};
39 private String primaryBtn_ = "Save";
40
41 public UIPermissionInputSet(String name) throws Exception {
42 super(name);
43 initComponent(true);
44 }
45 private void initComponent(boolean hasPermissionCheckbox) throws Exception{
46 setComponentConfig(getClass(), null);
47 UIFormStringInput userGroup = new UIFormStringInput(FIELD_USERORGROUP, FIELD_USERORGROUP, null);
48 userGroup.setReadOnly(true);
49 addUIFormInput(userGroup);
50 if (hasPermissionCheckbox) {
51 for (String perm : new String[] { PermissionType.READ, PermissionType.ADD_NODE, PermissionType.REMOVE }) {
52 UICheckBoxInput checkBoxInput = new UICheckBoxInput(perm, perm, false);
53 addUIFormInput(checkBoxInput);
54 checkBoxInput.setOnChange("OnChange");
55 }
56 }
57 setActionInfo(FIELD_USERORGROUP, new String[] {"SelectUser", "SelectMember", "AddAny"});
58 }
59 public UIPermissionInputSet(String name, boolean hasPermissionCheckbox) throws Exception {
60 super(name);
61 initComponent(hasPermissionCheckbox);
62 }
63 public String[] getButtonActions() {
64 return buttonActions_;
65 }
66
67 public void setButtonActions(String[] actions) {
68 buttonActions_ = actions;
69 }
70
71 public String getPrimaryButtonAction() {
72 return primaryBtn_;
73 }
74
75 public void setPrimaryButtonAction(String primaryBtn) {
76 primaryBtn_ = primaryBtn;
77 }
78
79 static public class OnChangeActionListener extends EventListener<UIForm> {
80 public void execute(Event<UIForm> event) throws Exception {
81 UIForm permissionForm = event.getSource();
82 UICheckBoxInput readCheckBox = permissionForm.getUICheckBoxInput(PermissionType.READ);
83 boolean isAddNodeCheckBoxChecked = permissionForm.getUICheckBoxInput(PermissionType.ADD_NODE).isChecked();
84 boolean isRemoveCheckBoxChecked = permissionForm.getUICheckBoxInput(PermissionType.REMOVE).isChecked();
85 if (isAddNodeCheckBoxChecked || isRemoveCheckBoxChecked) {
86 readCheckBox.setChecked(true);
87 }
88 event.getRequestContext().addUIComponentToUpdateByAjax(permissionForm);
89 }
90 }
91 }