2013-04-11 12:42:56 +02:00
package org.gcube.portlets.user.gcubeloggedin.client.ui ;
2016-09-30 15:30:07 +02:00
import org.gcube.portlets.user.gcubeloggedin.client.LoggedinService ;
2013-04-11 12:42:56 +02:00
import org.gcube.portlets.user.gcubeloggedin.client.LoggedinServiceAsync ;
import org.gcube.portlets.user.gcubeloggedin.shared.VObject ;
2016-09-30 15:30:07 +02:00
import org.gcube.portlets.user.gcubewidgets.client.elements.Span ;
2013-04-11 12:42:56 +02:00
2016-09-30 15:30:07 +02:00
import com.github.gwtbootstrap.client.ui.AlertBlock ;
2015-05-06 17:38:27 +02:00
import com.github.gwtbootstrap.client.ui.Button ;
2016-03-23 16:23:47 +01:00
import com.github.gwtbootstrap.client.ui.Hero ;
import com.github.gwtbootstrap.client.ui.Image ;
2016-09-30 15:30:07 +02:00
import com.github.gwtbootstrap.client.ui.constants.AlertType ;
import com.github.gwtbootstrap.client.ui.constants.ButtonType ;
2013-04-11 12:42:56 +02:00
import com.google.gwt.core.client.GWT ;
import com.google.gwt.event.dom.client.ClickEvent ;
2016-09-30 15:30:07 +02:00
import com.google.gwt.event.dom.client.ClickHandler ;
2013-04-11 12:42:56 +02:00
import com.google.gwt.uibinder.client.UiBinder ;
import com.google.gwt.uibinder.client.UiField ;
import com.google.gwt.uibinder.client.UiHandler ;
2016-09-30 15:30:07 +02:00
import com.google.gwt.user.client.Window ;
import com.google.gwt.user.client.Window.Location ;
import com.google.gwt.user.client.rpc.AsyncCallback ;
2013-04-11 12:42:56 +02:00
import com.google.gwt.user.client.ui.Composite ;
import com.google.gwt.user.client.ui.HTML ;
2016-09-30 15:30:07 +02:00
import com.google.gwt.user.client.ui.HasAlignment ;
import com.google.gwt.user.client.ui.InlineHTML ;
import com.google.gwt.user.client.ui.VerticalPanel ;
2013-04-11 12:42:56 +02:00
import com.google.gwt.user.client.ui.Widget ;
public class AboutView extends Composite {
2016-03-23 16:23:47 +01:00
private static int MAX_CHAR_DESC = 400 ;
private static String SEE_LESS = " See less " ;
private static String SEE_MORE = " See more " ;
2016-09-30 15:30:07 +02:00
private Button leaveVreButton = new Button ( " Leave Group " ) ;
private AlertBlock alertBlockOnLeave = new AlertBlock ( ) ;
2019-10-16 16:58:44 +02:00
private AlertBlock infoBlock = new AlertBlock ( ) ;
2016-09-30 15:30:07 +02:00
// more options label to show the other ones (if present)
final Button showMoreOptions = new Button ( " Other options ... " ) ;
private static final String leaveAlertMessage = " Are you sure you want to leave this group? "
2019-10-16 16:48:21 +02:00
+ " By leaving this group you will no longer receive updates and lose the workspace folder related to the group. This operation may take a minute or so. " ;
2016-03-23 16:23:47 +01:00
2016-09-30 15:30:07 +02:00
// panel for leave group option
private VerticalPanel leaveVREOption = new VerticalPanel ( ) ;
private final LoggedinServiceAsync service = GWT . create ( LoggedinService . class ) ;
2013-04-11 12:42:56 +02:00
private static AboutViewUiBinder uiBinder = GWT
. create ( AboutViewUiBinder . class ) ;
interface AboutViewUiBinder extends UiBinder < Widget , AboutView > {
}
public AboutView ( ) {
initWidget ( uiBinder . createAndBindUi ( this ) ) ;
}
2015-05-06 17:38:27 +02:00
private String vreDescription ;
2016-03-23 16:23:47 +01:00
@UiField Image vreImage ;
2014-09-15 16:45:05 +02:00
@UiField HTML description ;
2015-05-06 17:38:27 +02:00
@UiField Button seeMore ;
2016-05-13 15:12:38 +02:00
@UiField Button editButton ;
2016-03-23 16:23:47 +01:00
@UiField Hero mainPanel ;
2016-05-13 15:12:38 +02:00
private EditDescriptionModal mod ;
2013-04-11 12:42:56 +02:00
public AboutView ( VObject vobj , LoggedinServiceAsync loggedinService ) {
initWidget ( uiBinder . createAndBindUi ( this ) ) ;
2016-03-23 16:23:47 +01:00
this . vreDescription = vobj . getDescription ( ) ;
vreImage . setUrl ( vobj . getImageURL ( ) ) ;
2015-05-06 17:38:27 +02:00
String desc = vreDescription = vobj . getDescription ( ) ;
if ( desc . length ( ) > MAX_CHAR_DESC ) {
desc = desc . substring ( 0 , MAX_CHAR_DESC ) + " ... " ;
2016-03-23 16:23:47 +01:00
//description.getElement().setInnerHTML(desc);
description . setHTML ( desc ) ;
2015-05-06 17:38:27 +02:00
seeMore . setVisible ( true ) ;
2016-03-23 16:23:47 +01:00
seeMore . setText ( SEE_MORE ) ;
2016-05-13 15:46:28 +02:00
} else
description . setHTML ( desc ) ;
description . addStyleName ( " vre-description " ) ;
if ( vobj . isManager ( ) ) {
editButton . setVisible ( true ) ;
2015-05-06 17:38:27 +02:00
}
2016-05-13 15:12:38 +02:00
mod = new EditDescriptionModal ( vobj . getName ( ) , vobj . getDescription ( ) ) ;
2016-09-30 15:30:07 +02:00
service . isLeaveButtonAvailable ( Location . getHref ( ) , new AsyncCallback < Boolean > ( ) {
@Override
public void onSuccess ( Boolean result ) {
leaveVREOption . clear ( ) ;
leaveVREOption . setHorizontalAlignment ( HasAlignment . ALIGN_LEFT ) ;
if ( result )
addLeaveVREButton ( ) ;
showMoreOptions . setVisible ( result ) ;
}
@Override
public void onFailure ( Throwable caught ) {
leaveVREOption . clear ( ) ;
}
} ) ;
showMoreOptions . setType ( ButtonType . LINK ) ;
// handler
showMoreOptions . addClickHandler ( new ClickHandler ( ) {
@Override
public void onClick ( ClickEvent event ) {
// hide the button itself
showMoreOptions . setVisible ( false ) ;
// show other options
leaveVREOption . setVisible ( true ) ;
}
} ) ;
mainPanel . add ( showMoreOptions ) ;
mainPanel . add ( leaveVREOption ) ;
// hide options but askManagersOption
leaveVREOption . setVisible ( false ) ;
2016-03-23 16:23:47 +01:00
}
boolean open = false ;
2015-05-06 17:38:27 +02:00
@UiHandler ( " seeMore " )
2016-03-23 16:23:47 +01:00
void onSeemore ( ClickEvent e ) {
GWT . log ( seeMore . getText ( ) ) ;
if ( ! open ) {
description . setHTML ( vreDescription ) ;
seeMore . setText ( SEE_LESS ) ;
open = true ;
} else {
description . setHTML ( vreDescription . substring ( 0 , MAX_CHAR_DESC ) + " ... " ) ;
seeMore . setText ( SEE_MORE ) ;
open = false ;
}
2013-04-11 12:42:56 +02:00
}
2016-05-13 15:12:38 +02:00
@UiHandler ( " editButton " )
void onEditButton ( ClickEvent e ) {
mod . show ( ) ;
}
2016-09-30 15:30:07 +02:00
private void addLeaveVREButton ( ) {
// add leave VRE button
leaveVreButton . addClickHandler ( new ClickHandler ( ) {
@Override
public void onClick ( ClickEvent event ) {
// show alert block
alertBlockOnLeave . setVisible ( true ) ;
2016-10-14 14:58:32 +02:00
leaveVreButton . setVisible ( false ) ;
2016-09-30 15:30:07 +02:00
}
} ) ;
// Add Cancel and Confirm Leave buttons
Span cancel = new Span ( " Cancel " ) ;
Span confirmLeave = new Span ( " Confirm Leave " ) ;
cancel . setStyleName ( " cancel-leave-button " ) ;
confirmLeave . setStyleName ( " cancel-leave-button " ) ;
// add to main panel
alertBlockOnLeave . setHTML ( leaveAlertMessage + " <br><br> " ) ;
alertBlockOnLeave . add ( cancel ) ;
alertBlockOnLeave . add ( new InlineHTML ( " or " ) ) ;
alertBlockOnLeave . add ( confirmLeave ) ;
alertBlockOnLeave . setType ( AlertType . WARNING ) ;
alertBlockOnLeave . setHeading ( " WARNING! " ) ;
alertBlockOnLeave . setClose ( false ) ;
alertBlockOnLeave . setVisible ( false ) ;
leaveVREOption . add ( alertBlockOnLeave ) ;
leaveVREOption . add ( leaveVreButton ) ;
// add handlers
cancel . addClickHandler ( new ClickHandler ( ) {
@Override
public void onClick ( ClickEvent event ) {
// just hide alertBlock
alertBlockOnLeave . setVisible ( false ) ;
2016-10-14 14:58:32 +02:00
leaveVreButton . setVisible ( true ) ;
2016-09-30 15:30:07 +02:00
}
} ) ;
confirmLeave . addClickHandler ( new ClickHandler ( ) {
@Override
public void onClick ( ClickEvent event ) {
2019-10-16 16:58:44 +02:00
infoBlock . setType ( AlertType . INFO ) ;
infoBlock . setHeading ( " Operation in progress! " ) ;
infoBlock . setHTML ( " please wait ... " ) ;
leaveVREOption . remove ( alertBlockOnLeave ) ;
leaveVREOption . add ( infoBlock ) ;
2019-10-16 16:48:21 +02:00
2016-09-30 15:30:07 +02:00
service . removeUserFromVRE ( new AsyncCallback < String > ( ) {
@Override
public void onSuccess ( String result ) {
if ( result ! = null )
Location . assign ( result ) ;
2016-11-14 18:04:27 +01:00
2016-09-30 15:30:07 +02:00
}
@Override
public void onFailure ( Throwable caught ) {
Window . alert ( " We're sorry we couldn't reach the server, try again later ... " + caught . getMessage ( ) ) ;
}
} ) ;
}
} ) ;
}
2016-05-13 15:12:38 +02:00
2014-09-15 16:45:05 +02:00
/ * *
*
* @return
* /
2015-05-06 17:38:27 +02:00
public static Widget getLoadingHTML ( ) {
return new LoadingText ( ) ;
2014-09-15 16:45:05 +02:00
}
2013-04-11 12:42:56 +02:00
}