Search in sources :

Example 1 with SendsApplicationForm

use of cz.metacentrum.perun.webgui.client.applicationresources.SendsApplicationForm in project perun by CESNET.

the class ApplicationFormPage method prepareVoForm.

/**
	 * Prepares a VO form
	 */
protected void prepareVoForm() {
    if (submittedOrError)
        formContent.clear();
    bodyContents.setWidget(formContent);
    formContent.setStyleName("formContentTable");
    submittedOrError = false;
    FlexTable header = new FlexTable();
    header.setWidth("100%");
    header.setCellPadding(5);
    int row = 0;
    // display VO logo if present in attribute
    for (int i = 0; i < vo.getAttributes().length(); i++) {
        if (vo.getAttributes().get(i).getFriendlyName().equalsIgnoreCase("voLogoURL")) {
            header.setWidget(row, 0, new Image(vo.getAttributes().get(i).getValue()));
            row++;
        }
    }
    /*

		String headerString = "";

		// display application header
		if (type.equalsIgnoreCase("INITIAL")) {
			if (group != null) {
				headerString = ApplicationMessages.INSTANCE.applicationFormForGroup(group.getName());
			} else {
				headerString = ApplicationMessages.INSTANCE.applicationFormForVo(vo.getName());
			}
		} else if (type.equalsIgnoreCase("EXTENSION")) {
			if (group != null) {
				headerString = ApplicationMessages.INSTANCE.membershipExtensionForGroup(group.getName());
			} else {
				headerString = ApplicationMessages.INSTANCE.membershipExtensionForVo(vo.getName());
			}
		}

		header.setHTML(row, 0, "<h1>" + headerString + "</h1>");

		*/
    // language button
    prepareToggleLanguageButton();
    FlexTable lang = new FlexTable();
    lang.setWidget(0, 1, languageButton);
    header.setWidget(0, 1, lang);
    header.getFlexCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_RIGHT);
    formContent.add(header);
    final GetFormItemsWithPrefilledValues fitems;
    if (group != null) {
        fitems = new GetFormItemsWithPrefilledValues(PerunEntity.GROUP, group.getId());
    } else {
        fitems = new GetFormItemsWithPrefilledValues(PerunEntity.VIRTUAL_ORGANIZATION, vo.getId());
    }
    fitems.setEvents(new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            // when form is auto-submitting
            ArrayList<ApplicationFormItemWithPrefilledValue> items = JsonUtils.<ApplicationFormItemWithPrefilledValue>jsoAsList(jso);
            for (ApplicationFormItemWithPrefilledValue item : items) {
                if (item.getFormItem().getType().equals("AUTO_SUBMIT_BUTTON")) {
                    if (fitems.getSendButton() != null) {
                        // enforce first click to validate and submit the form
                        fitems.getSendButton().click();
                    }
                }
            }
            // try to get user for VOs initial application (only for authz origin when form is defined)
            if (items != null && !items.isEmpty()) {
                if (session.getUser() == null && !session.getPerunPrincipal().getExtSource().equalsIgnoreCase("LOCAL")) {
                    tryToFindUserByName(null);
                }
            }
            Scheduler.get().scheduleDeferred(new Command() {

                @Override
                public void execute() {
                    positionLinker();
                }
            });
        }
    });
    if (Location.getParameter("type") != null && (Location.getParameter("type").equalsIgnoreCase("INITIAL") || Location.getParameter("type").equalsIgnoreCase("EXTENSION"))) {
        fitems.setType(Location.getParameter("type").toUpperCase());
    } else {
        fitems.setType(type);
    }
    fitems.setHidden(true);
    fitems.setSendFormHandler(new SendsApplicationForm() {

        public void sendApplicationForm(CustomButton button) {
            data = fitems.getValues();
            sendForm(button);
        }
    });
    fitems.retrieveData();
    formContent.add(fitems.getContents());
    formContent.add(new HTML("<br /><br /><br />"));
    JsonCallbackEvents formEvent = new JsonCallbackEvents() {

        @Override
        public void onFinished(JavaScriptObject jso) {
            form = jso.cast();
        }
    };
    GetApplicationForm formRequest;
    if (group != null) {
        formRequest = new GetApplicationForm(PerunEntity.GROUP, group.getId(), formEvent);
    } else {
        formRequest = new GetApplicationForm(PerunEntity.VIRTUAL_ORGANIZATION, vo.getId(), formEvent);
    }
    formRequest.retrieveData();
}
Also used : JsonCallbackEvents(cz.metacentrum.perun.webgui.json.JsonCallbackEvents) ArrayList(java.util.ArrayList) GetFormItemsWithPrefilledValues(cz.metacentrum.perun.webgui.json.registrarManager.GetFormItemsWithPrefilledValues) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) Command(com.google.gwt.user.client.Command) CustomButton(cz.metacentrum.perun.webgui.widgets.CustomButton) GetApplicationForm(cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationForm) SendsApplicationForm(cz.metacentrum.perun.webgui.client.applicationresources.SendsApplicationForm)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 Command (com.google.gwt.user.client.Command)1 SendsApplicationForm (cz.metacentrum.perun.webgui.client.applicationresources.SendsApplicationForm)1 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)1 GetApplicationForm (cz.metacentrum.perun.webgui.json.registrarManager.GetApplicationForm)1 GetFormItemsWithPrefilledValues (cz.metacentrum.perun.webgui.json.registrarManager.GetFormItemsWithPrefilledValues)1 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)1 ArrayList (java.util.ArrayList)1