View Javadoc
1   /*
2    * Copyright (C) 2003-2007 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
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   * Created by The eXo Platform SARL
30   * Author : Tran The Trong
31   *          trongtt@gmail.com
32   * Jun 28, 2006
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  }