2015-01-27 15:07:25 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package org.gcube.portlets.widgets.workspacesharingwidget.client;
|
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
import java.util.ArrayList;
|
2015-01-27 15:07:25 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.permissions.MessageBoxAlert;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.permissions.PanelTogglePermission;
|
2015-01-28 18:22:52 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingServiceAsync;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.UserStore;
|
2019-07-26 20:14:13 +02:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user.DialogMultiDragContact;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.user.MultiDragContact;
|
2015-01-27 15:07:25 +01:00
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
|
|
|
|
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
|
|
|
|
|
2015-01-28 17:41:11 +01:00
|
|
|
import com.extjs.gxt.ui.client.Style.Scroll;
|
2015-01-28 11:21:10 +01:00
|
|
|
import com.extjs.gxt.ui.client.event.BaseEvent;
|
|
|
|
import com.extjs.gxt.ui.client.event.Events;
|
|
|
|
import com.extjs.gxt.ui.client.event.Listener;
|
2015-01-27 15:07:25 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.Dialog;
|
|
|
|
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
|
2015-01-28 17:41:11 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.Html;
|
2015-03-06 17:47:06 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.LayoutContainer;
|
2015-01-28 18:22:52 +01:00
|
|
|
import com.extjs.gxt.ui.client.widget.MessageBox;
|
2015-01-28 11:21:10 +01:00
|
|
|
import com.google.gwt.core.shared.GWT;
|
2015-01-27 15:07:25 +01:00
|
|
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* A dialog to drag and edit permissions of a workspace folder
|
|
|
|
*
|
2019-02-22 11:14:22 +01:00
|
|
|
* @author Francesco Mangiacrapa Jan 27, 2015
|
2015-01-27 15:07:25 +01:00
|
|
|
*
|
|
|
|
*/
|
2015-01-28 18:22:52 +01:00
|
|
|
public class MultiDragContactsEditPermissions {
|
2015-01-27 15:07:25 +01:00
|
|
|
|
|
|
|
private PanelTogglePermission permission;
|
|
|
|
private HorizontalPanel hpPermission = new HorizontalPanel();
|
2015-01-28 17:41:11 +01:00
|
|
|
private Html htmlCurrentPermissions = new Html();
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
private UserStore userStore = new UserStore();
|
|
|
|
private ConstantsSharing.LOAD_CONTACTS_AS loadContactAs;
|
2019-07-26 20:14:13 +02:00
|
|
|
private DialogMultiDragContact dialogMultiDragContact;
|
2015-01-28 18:22:52 +01:00
|
|
|
private List<InfoContactModel> sources = new ArrayList<InfoContactModel>();
|
|
|
|
private boolean hiddenMySelf;
|
|
|
|
private String workspaceItemId;
|
|
|
|
private String myLogin;
|
|
|
|
private InfoContactModel myContact;
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
public MultiDragContactsEditPermissions(ConstantsSharing.LOAD_CONTACTS_AS load, final String workspaceItemId,
|
|
|
|
boolean hiddenMySelf) {
|
2019-07-26 20:14:13 +02:00
|
|
|
dialogMultiDragContact= new DialogMultiDragContact(
|
|
|
|
MultiDragConstants.HEADING_DIALOG, MultiDragConstants.ALL_CONTACTS_LEFT_LIST,
|
|
|
|
MultiDragConstants.SHARE_WITH_RIGHT_LIST, false, false,hiddenMySelf);
|
2015-01-28 18:22:52 +01:00
|
|
|
initMultiDrag(load, workspaceItemId, hiddenMySelf);
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
// dialog = super.getDialogMultiDragContact();
|
2015-01-28 18:22:52 +01:00
|
|
|
dialogMultiDragContact.setScrollMode(Scroll.AUTOY);
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
// htmlCurrentPermissions.setReadOnly(true);
|
2015-03-06 17:47:06 +01:00
|
|
|
LayoutContainer lcCurrentPermissions = new LayoutContainer();
|
2015-01-28 17:41:11 +01:00
|
|
|
htmlCurrentPermissions.setWidth(MultiDragContact.WIDTH_CP);
|
2019-02-22 11:14:22 +01:00
|
|
|
htmlCurrentPermissions.setStyleAttribute("padding", MultiDragContact.PADDING + "px");
|
2015-03-06 17:47:06 +01:00
|
|
|
lcCurrentPermissions.setScrollMode(Scroll.AUTOY);
|
|
|
|
lcCurrentPermissions.setHeight(50);
|
|
|
|
lcCurrentPermissions.add(htmlCurrentPermissions);
|
|
|
|
lcCurrentPermissions.add(lcCurrentPermissions);
|
|
|
|
|
|
|
|
dialogMultiDragContact.getLcTop().add(lcCurrentPermissions);
|
2019-02-22 11:14:22 +01:00
|
|
|
// dialog.setHeight(dialog.getHeight()+100);
|
2015-01-28 11:21:10 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
WorkspaceSharingController.rpcWorkspaceSharingService.getACLsDescriptionForSharedFolderId(workspaceItemId,
|
|
|
|
new AsyncCallback<String>() {
|
2015-01-28 17:41:11 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
GWT.log("error getACLsDescriptionForSharedFolderId: " + caught.getMessage());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String result) {
|
|
|
|
String msg = "#<b>Current Permissions:</b> <br/>";
|
|
|
|
msg += result;
|
|
|
|
htmlCurrentPermissions.setHtml(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
2015-01-28 17:41:11 +01:00
|
|
|
|
2015-01-28 11:21:10 +01:00
|
|
|
enableSubmit(false);
|
2019-02-22 11:14:22 +01:00
|
|
|
// hpPermission.setStyleAttribute("margin-top", "20px");
|
2015-01-28 11:21:10 +01:00
|
|
|
hpPermission.setStyleAttribute("margin-left", "165px");
|
2019-02-22 11:14:22 +01:00
|
|
|
// Html html = new Html("With Permission : ");
|
|
|
|
// html.setStyleAttribute("margin-left", "10px");
|
|
|
|
// hpPermission.add(html);
|
|
|
|
|
|
|
|
// TODO GET ACL FOR USER
|
2015-01-27 15:07:25 +01:00
|
|
|
WorkspaceSharingController.rpcWorkspaceSharingService.getACLs(new AsyncCallback<List<WorkspaceACL>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<WorkspaceACL> result) {
|
|
|
|
permission = new PanelTogglePermission(result);
|
|
|
|
hpPermission.add(permission);
|
|
|
|
hpPermission.layout();
|
2019-02-22 11:14:22 +01:00
|
|
|
// selectAclForFolder(workspaceItemId);
|
2015-01-28 11:21:10 +01:00
|
|
|
enableSubmit(true);
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
// dialog.unmask();
|
2015-01-27 15:07:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
2019-02-22 11:14:22 +01:00
|
|
|
new MessageBoxAlert("Alert", "Sorry, an error occurred on recovering ACLs", null);
|
|
|
|
// dialog.unmask();
|
2015-01-27 15:07:25 +01:00
|
|
|
}
|
|
|
|
});
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
dialogMultiDragContact.getLcBottom().add(hpPermission);
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
dialogMultiDragContact.addListener(Events.Render, new Listener<BaseEvent>() {
|
2015-01-28 11:21:10 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void handleEvent(BaseEvent be) {
|
2019-02-22 11:14:22 +01:00
|
|
|
dialogMultiDragContact.setHeight(dialogMultiDragContact.getHeight() + 100);
|
2015-01-28 11:21:10 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-01-28 18:22:52 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
public void enableSubmit(boolean bool) {
|
2015-01-28 18:22:52 +01:00
|
|
|
dialogMultiDragContact.getButtonById(Dialog.OK).setEnabled(bool);
|
2015-01-27 15:07:25 +01:00
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 11:21:10 +01:00
|
|
|
public DialogMultiDragContact getDialog() {
|
2015-01-28 18:22:52 +01:00
|
|
|
return dialogMultiDragContact;
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
|
|
|
|
2015-01-27 15:07:25 +01:00
|
|
|
/**
|
|
|
|
* The HL ID of the selected ACL
|
2019-02-22 11:14:22 +01:00
|
|
|
*
|
|
|
|
* @return ACL ID
|
2015-01-27 15:07:25 +01:00
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
public String getSelectedAclID() {
|
|
|
|
if (permission.getSelectedACL() != null)
|
2015-01-27 15:07:25 +01:00
|
|
|
return permission.getSelectedACL().getId();
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-27 15:07:25 +01:00
|
|
|
return null;
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-27 15:07:25 +01:00
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-27 15:07:25 +01:00
|
|
|
/**
|
|
|
|
* The selected ACL
|
2019-02-22 11:14:22 +01:00
|
|
|
*
|
|
|
|
* @return Workspace ACL
|
2015-01-27 15:07:25 +01:00
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
public WorkspaceACL getSelectedAcl() {
|
|
|
|
if (permission.getSelectedACL() != null)
|
2015-01-27 15:07:25 +01:00
|
|
|
return permission.getSelectedACL();
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-27 15:07:25 +01:00
|
|
|
return null;
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-27 15:07:25 +01:00
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
/**
|
|
|
|
* Load administrators or shared users to workspace item id
|
2019-02-22 11:14:22 +01:00
|
|
|
*
|
|
|
|
* @param load
|
|
|
|
* if LOAD_CONTACTS_AS.SHARED_USER loads source users from Shared
|
|
|
|
* Users if LOAD_CONTACTS_AS.ADMINISTRATOR loads source users
|
|
|
|
* from Administrators
|
2015-01-28 18:22:52 +01:00
|
|
|
*
|
|
|
|
* @param workspaceItemId
|
2019-02-22 11:14:22 +01:00
|
|
|
* @param hiddenMySelf
|
|
|
|
* if true the login read from ASL is hidden (so it's not
|
|
|
|
* removable to target users), the login returned anyway among
|
|
|
|
* the target users
|
2015-01-28 18:22:52 +01:00
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
private void initMultiDrag(ConstantsSharing.LOAD_CONTACTS_AS load, String workspaceItemId,
|
|
|
|
final boolean hiddenMySelf) {
|
2015-01-28 18:22:52 +01:00
|
|
|
this.loadContactAs = load;
|
|
|
|
this.hiddenMySelf = hiddenMySelf;
|
|
|
|
this.workspaceItemId = workspaceItemId;
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
if (hiddenMySelf)
|
2015-01-28 18:22:52 +01:00
|
|
|
loadMyLogin(true);
|
|
|
|
else
|
|
|
|
loadSharedContacts();
|
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
private void loadMyLogin(final boolean loadContacts) {
|
|
|
|
|
|
|
|
WorkspaceSharingServiceAsync.INSTANCE.getMyLogin(new AsyncCallback<String>() {
|
2015-01-28 18:22:52 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
GWT.log("Error on loading my login is empty");
|
|
|
|
myLogin = "";
|
|
|
|
loadSharedContacts();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(String result) {
|
2019-02-22 11:14:22 +01:00
|
|
|
GWT.log("My login is: " + result);
|
|
|
|
myLogin = result;
|
|
|
|
|
|
|
|
if (loadContacts)
|
2015-01-28 18:22:52 +01:00
|
|
|
loadSharedContacts();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
/**
|
|
|
|
* Load the target contacts
|
|
|
|
*/
|
2019-02-22 11:14:22 +01:00
|
|
|
private void loadSharedContacts() {
|
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
switch (loadContactAs) {
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
case ADMINISTRATOR:
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
// LOADING LIST OF ALREADY SHARED USER
|
|
|
|
userStore.getAdministratorsByFolderId(workspaceItemId, new AsyncCallback<List<InfoContactModel>>() {
|
2015-01-28 18:22:52 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
GWT.log("Error on loading admnistrators");
|
|
|
|
MessageBox.alert("Error on loading admnistrators", caught.getMessage(), null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<InfoContactModel> result) {
|
2019-02-22 11:14:22 +01:00
|
|
|
GWT.log("Returned " + result.size() + " admin/s");
|
2015-01-28 18:22:52 +01:00
|
|
|
fillMultiDrag(result);
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
}
|
|
|
|
});
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHARED_USER:
|
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
// LOADING LIST OF ALREADY SHARED USER
|
|
|
|
userStore.getListSharedUserByFolderId(workspaceItemId, new AsyncCallback<List<InfoContactModel>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccess(List<InfoContactModel> result) {
|
|
|
|
GWT.log("Returned " + result.size() + " contact/s");
|
|
|
|
fillMultiDrag(result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailure(Throwable caught) {
|
|
|
|
GWT.log("Error on loading shared contacts");
|
|
|
|
MessageBox.alert("Error on shared contacts", caught.getMessage(), null);
|
|
|
|
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
break;
|
|
|
|
default:
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
public void addTargetContact(List<InfoContactModel> listContacts) {
|
|
|
|
if (listContacts != null) {
|
2015-01-28 18:22:52 +01:00
|
|
|
for (InfoContactModel infoContactModel : listContacts) {
|
|
|
|
dialogMultiDragContact.getMultiDrag().addTargetContact(infoContactModel);
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
private void fillMultiDrag(List<InfoContactModel> result) {
|
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
GWT.log("Filling multi-drag..");
|
2019-02-22 11:14:22 +01:00
|
|
|
GWT.log("Hidden my self: " + hiddenMySelf);
|
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
for (InfoContactModel infoContactModel : result) {
|
2019-02-22 11:14:22 +01:00
|
|
|
if (infoContactModel.getLogin() != null) {
|
|
|
|
if (hiddenMySelf && (infoContactModel.getLogin().compareTo(myLogin) == 0)) {
|
|
|
|
myContact = infoContactModel;
|
|
|
|
GWT.log("Skipping myLogin as: " + myContact);
|
|
|
|
} else {
|
|
|
|
dialogMultiDragContact.getMultiDrag().addSourceContact(infoContactModel);
|
|
|
|
sources.add(infoContactModel);
|
2015-01-28 18:22:52 +01:00
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
2015-01-28 18:22:52 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
public void show() {
|
2015-01-28 18:22:52 +01:00
|
|
|
dialogMultiDragContact.show();
|
|
|
|
}
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-27 15:07:25 +01:00
|
|
|
|
2019-02-22 11:14:22 +01:00
|
|
|
public List<InfoContactModel> getTargetContacts() {
|
|
|
|
return dialogMultiDragContact.getMultiDrag().getTargetListContact();
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<InfoContactModel> getTargetContactsWithMyLogin() {
|
2015-01-28 18:22:52 +01:00
|
|
|
List<InfoContactModel> contacts = getTargetContacts();
|
2019-02-22 11:14:22 +01:00
|
|
|
|
|
|
|
if (myContact == null) {
|
2015-01-28 18:22:52 +01:00
|
|
|
GWT.log("TargetContactsWithMyLogin my Contact is null, skipping!");
|
2019-02-22 11:14:22 +01:00
|
|
|
} else
|
2015-01-28 18:22:52 +01:00
|
|
|
contacts.add(myContact);
|
2019-02-22 11:14:22 +01:00
|
|
|
|
2015-01-28 18:22:52 +01:00
|
|
|
return contacts;
|
2019-02-22 11:14:22 +01:00
|
|
|
}
|
|
|
|
|
2015-01-27 15:07:25 +01:00
|
|
|
}
|