Skip to content

Commit

Permalink
Merge pull request CESNET#133 from zlamalp/registration
Browse files Browse the repository at this point in the history
REGISTRAR: Allow editing submitted form to users
  • Loading branch information
zlamalp authored Dec 2, 2020
2 parents 77a68f7 + c74fa27 commit 266e760
Show file tree
Hide file tree
Showing 28 changed files with 460 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,23 @@ public static Request checkForSimilarUsers(List<ApplicationFormItemData> formIte

}

/**
* Update form items data of existing submitted application.
* This might trigger verification and approval of application!
*
* @param applicationId ID of application
* @param formItems Form items to be updated
* @param events Events done on callback
*
* @return Request unique request
*/
public static Request updateFormItemsData(int applicationId, List<ApplicationFormItemData> formItems, JsonEvents events) {

JsonClient client = new JsonClient(true, events);
if (applicationId > 0) client.put("appId", applicationId);
if (formItems != null) client.put("data", formItems);
return client.call(REGISTRAR_MANAGER + "updateFormItemsData");

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public final native void setApplicationTypes(JsArrayString applicationTypes) /*-
}-*/;

private final native void setApplicationTypes(JavaScriptObject object)/*-{
this.applicationTypes = applicationTypes;
this.applicationTypes = object;
}-*/;

// TODO - item texts
Expand All @@ -332,6 +332,10 @@ public final native void setItemTexts(String locale, ApplicationFormItemTexts it
this.i18n[locale] = itemTexts;
}-*/;

public final native String[] getItemTextLocales() /*-{
return Object.keys(this.i18n);
}-*/;

/**
* Return TRUE if item was marked for deletion. FALSE otherwise.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void resolve() {
}

setInfo(trans.alreadySubmitted(getBeanName()),
text + trans.visitSubmitted(Window.Location.getHref().split("#")[0], trans.submittedTitle()));
text + trans.visitSubmitted(Window.Location.getHref().split("#")[0], application.getId(), trans.submittedTitle()));

} else if ("MissingRequiredDataException".equalsIgnoreCase(exception.getName())) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public interface PerunRegistrarTranslation extends PerunTranslation {
@DefaultMessage("Please wait until your application has been approved. You will be notified by email.")
public String waitForAcceptation();

@DefaultMessage("<p><p>You can <b>see or edit your application <a href=\"{0}#appdetail;id={1}\">here</b></a>.")
public String seeOrEditApplicationHere(String url, int id);

@DefaultMessage("Please wait until your application for membership extension has been approved. You will be notified by email.")
public String waitForExtAcceptation();

Expand Down Expand Up @@ -239,8 +242,22 @@ public interface PerunRegistrarTranslation extends PerunTranslation {
@DefaultMessage("Membership extension in {0}")
public String extensionDetail(String registerTo);

@DefaultMessage("Form content")
public String formDataTitle();
// -------------- APP DETAIL PAGE - EDIT ------------------------ //

@DefaultMessage("Edit")
public String edit();

@DefaultMessage("Save")
public String save();

@DefaultMessage("Cancel")
public String cancel();

@DefaultMessage("There are no changes to be saved!")
public String noChange();

@DefaultMessage("All changes to the form will be discarded. Do you wish to continue?")
public String cancelAsk();

// --------------- EXCEPTIONS -------------------------------- //

Expand All @@ -256,8 +273,8 @@ public interface PerunRegistrarTranslation extends PerunTranslation {
@DefaultMessage("You have already submitted extension application to {0}")
public String alreadySubmittedExtension(String voName);

@DefaultMessage("<p>You can check details of your application in <a href=\"{0}#submitted\">{1}</a>.")
public String visitSubmitted(String url, String title);
@DefaultMessage("<p>You can <b>see or edit your application <a href=\"{0}#appdetail;id={1}\">here</b></a>. You can see all your applications in section <a href=\"{0}#submitted\">{2}</a>.")
public String visitSubmitted(String url, int appId, String title);

@DefaultMessage("You are already registered")
public String cantExtendMembership();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.gwtplatform.mvp.client.Presenter;
import com.gwtplatform.mvp.client.View;
import com.gwtplatform.mvp.client.annotations.NameToken;
import com.gwtplatform.mvp.client.annotations.ProxyCodeSplit;
import com.gwtplatform.mvp.client.annotations.ProxyStandard;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.ProxyPlace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.ViewImpl;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import cz.metacentrum.perun.wui.client.resources.PerunSession;
import cz.metacentrum.perun.wui.client.utils.JsUtils;
import cz.metacentrum.perun.wui.json.ErrorTranslator;
import cz.metacentrum.perun.wui.json.Events;
import cz.metacentrum.perun.wui.json.JsonEvents;
import cz.metacentrum.perun.wui.json.managers.RegistrarManager;
import cz.metacentrum.perun.wui.model.PerunException;
Expand All @@ -33,10 +35,8 @@
import org.gwtbootstrap3.client.ui.html.Text;
import org.gwtbootstrap3.extras.notify.client.constants.NotifyType;
import org.gwtbootstrap3.extras.notify.client.ui.Notify;
import org.gwtbootstrap3.extras.notify.client.ui.NotifySettings;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

Expand Down Expand Up @@ -95,9 +95,6 @@ interface AppDetailViewUiBinder extends UiBinder<Widget, AppDetailView> {
@UiField
Form formWrapper;

@UiField
Heading formTitle;

@UiField
DescriptionTitle subTitle;

Expand All @@ -113,6 +110,10 @@ interface AppDetailViewUiBinder extends UiBinder<Widget, AppDetailView> {
@UiField
Alert state;

@UiField PerunButton editButton;
@UiField PerunButton saveButton;
@UiField PerunButton cancelButton;

@UiField
PerunLoader loader;

Expand All @@ -135,19 +136,86 @@ interface AppDetailViewUiBinder extends UiBinder<Widget, AppDetailView> {
@Inject
public AppDetailView(AppDetailViewUiBinder binder) {
initWidget(binder.createAndBindUi(this));
form.setOnlyPreview(true);
editButton.setText(translation.edit());
saveButton.setText(translation.save());
cancelButton.setText(translation.cancel());
form.setFormState(PerunForm.FormState.PREVIEW);
}

@UiHandler(value = "backButton")
public void back(ClickEvent event) {
placeManager.navigateBack();
if (PerunForm.FormState.EDIT.equals(form.getFormState())) {
//
boolean ok = Window.confirm(translation.cancelAsk());
if (ok) {
updateState(false);
placeManager.navigateBack();
}
} else {
placeManager.navigateBack();
}
}

@UiHandler(value = "editButton")
public void edit(ClickEvent event) {
updateState(true);
}

@UiHandler(value = "cancelButton")
public void cancel(ClickEvent event) {
updateState(false);
}

@UiHandler(value = "saveButton")
public void save(ClickEvent event) {
form.submitEditedForm(app, new Events<Boolean>() {
@Override
public void onFinished(Boolean result) {
alertErrorReporter.setVisible(false);
saveButton.setProcessing(false);
cancelButton.setEnabled(true);
updateState(false);
// reload whole application state/form from API
placeManager.revealCurrentPlace();
}

@Override
public void onError(PerunException error) {
cancelButton.setEnabled(true);
saveButton.setProcessing(false);
if (error != null) {
alertErrorReporter.setVisible(true);
alertErrorReporter.setHTML(ErrorTranslator.getTranslatedMessage(error));
alertErrorReporter.setReportInfo(error);
} else {
Window.alert(translation.noChange());
}
}

@Override
public void onLoadingStart() {
cancelButton.setEnabled(false);
saveButton.setProcessing(true);
alertErrorReporter.setVisible(false);
}
});
}

private void updateState(boolean edit) {
form.setFormState(edit ? PerunForm.FormState.EDIT : PerunForm.FormState.PREVIEW);
form.setFormItems(form.getSourceFormItems());
editButton.setVisible(!edit);
saveButton.setVisible(edit);
cancelButton.setVisible(edit);
}


public void draw() {

form.setSeeHiddenItems(canSeeHiddenFields());

formTitle.setText(translation.formDataTitle());
// hide notice until loaded
mailVerificationAlert.setVisible(false);

if (Application.ApplicationType.INITIAL.equals(app.getType())) {
text.setText(translation.initialDetail(app.getVo().getName()));
Expand Down Expand Up @@ -179,13 +247,17 @@ public void draw() {
stateTitle.setText(app.getTranslatedState());
stateText.setText(app.getModifiedAt().split("\\.")[0]);

// only new and verified application are editable
editButton.setVisible(Application.ApplicationState.NEW.equals(app.getState()) ||
Application.ApplicationState.VERIFIED.equals(app.getState()));

}

private boolean canSeeHiddenFields() {
// TODO - authorization shouldnt be in gui.
// TODO - authorization shouldn't be in gui.
// admins can see hidden fields - users not
PerunSession sess = PerunSession.getInstance();
return (sess.isVoAdmin(app.getVo().getId()) || sess.isVoObserver(app.getVo().getId()) || (app.getGroup() != null && sess.isGroupAdmin(app.getGroup().getId())));
return (sess.isPerunAdmin() || sess.isVoAdmin(app.getVo().getId()) || sess.isVoObserver(app.getVo().getId()) || (app.getGroup() != null && sess.isGroupAdmin(app.getGroup().getId())));

}

Expand Down Expand Up @@ -269,6 +341,11 @@ public void onLoadingStart() {
}

form.setFormItems(list);

if (form.hasNoVisibleItems() || form.hasNoUpdatableItems()) {
editButton.setVisible(false);
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@

<b:Form type="HORIZONTAL" ui:field="formWrapper">

<b:Heading size="H3" text="Form data" ui:field="formTitle"/>
<p:PerunToolbar>
<p:PerunButton ui:field="editButton" text="Edit" icon="EDIT" />
<p:PerunButton ui:field="saveButton" text="Save" icon="SAVE" visible="false" />
<p:PerunButton ui:field="cancelButton" text="Cancel" visible="false" />
</p:PerunToolbar>
<b.html:Hr/>

<p.registrar:PerunForm ui:field="form">
Expand All @@ -58,4 +62,4 @@
</b:Row>
</b:Container>

</ui:UiBinder>
</ui:UiBinder>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ public AppsPresenter(final EventBus eventBus, final MyView view, final MyProxy p
super(eventBus, view, proxy, PerunPresenter.SLOT_MAIN_CONTENT);
}

/* @Override
@Override
protected void onReset() {
super.onReset();
((AppsView)getView()).draw();
}

/* @Override
protected void onReset() {
super.onReset();
// resize when any of presenters is attached/detached
Expand All @@ -39,4 +45,4 @@ protected void onReset() {
}
}*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;
import com.gwtplatform.mvp.client.ViewImpl;
Expand All @@ -16,6 +17,7 @@
import cz.metacentrum.perun.wui.model.beans.Application;
import cz.metacentrum.perun.wui.registrar.client.resources.PerunRegistrarTranslation;
import cz.metacentrum.perun.wui.registrar.model.ApplicationColumnProvider;
import cz.metacentrum.perun.wui.widgets.PerunButton;
import cz.metacentrum.perun.wui.widgets.PerunDataGrid;
import org.gwtbootstrap3.client.ui.html.Text;

Expand All @@ -35,18 +37,25 @@ interface AppsViewUiBinder extends UiBinder<Widget, AppsView> {
@UiField
Text text;

@UiField
PerunButton refresh;

private PerunRegistrarTranslation translation = GWT.create(PerunRegistrarTranslation.class);

@Inject
public AppsView(AppsViewUiBinder binder) {

initWidget(binder.createAndBindUi(this));
text.setText(translation.submittedTitle());
refresh.setTooltipText(translation.refresh());
grid.setHeight("100%");
draw();

}

@UiHandler(value = "refresh")
public void refresh(ClickEvent event) {
draw();
}

public void draw() {

Expand Down Expand Up @@ -79,4 +88,4 @@ public void onLoadingStart() {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<b:Icon ui:field="icon" type="ARCHIVE" fixedWidth="true" />
<b.html:Text text="My registrations" ui:field="text"/>
<b.html:Small text=""/>
<p:PerunButton tooltipText="Refresh" icon="REFRESH" ui:field="refresh" marginLeft="20" />
</b:Heading>

<g:ResizeLayoutPanel addStyleNames="{res.gss.grid}">
Expand All @@ -26,4 +27,4 @@

</b.html:Div>

</ui:UiBinder>
</ui:UiBinder>
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public void draw() {
return;
}

// hide previous state
hideMailVerificationAlert();
hideNotice();
form.clear();

final PerunLoader loader = new PerunLoader();
form.add(loader);
Expand Down
Loading

0 comments on commit 266e760

Please sign in to comment.