Exemplo n.º 1
0
  public PersonFormPage() throws IOException {

    setPageTitle(ResourceUtils.getModel("pageTitle.addPerson"));
    add(new Label("title", ResourceUtils.getModel("pageTitle.addPerson")));

    add(new ButtonPageMenu("leftMenu", PersonPageLeftMenu.values()));
    Person person = new Person();
    person.setDateOfBirth(new Timestamp(new Date().getTime()));

    add(new PersonForm("form", new Model<Person>(person), educationFacade, facade, getFeedback()));
  }
Exemplo n.º 2
0
    public PersonForm(
        String id,
        IModel<Person> model,
        final EducationLevelFacade educationFacade,
        final PersonFacade personFacade,
        final FeedbackPanel feedback)
        throws IOException {
      super(id, new CompoundPropertyModel<Person>(model));

      EmailTextField email = new EmailTextField("username");
      email.setLabel(ResourceUtils.getModel("label.email"));
      email.setRequired(true);
      FormComponentLabel emailLabel = new FormComponentLabel("emailLb", email);
      add(email, emailLabel);

      final PersonFormPanel<Person> panelPerson =
          new PersonFormPanel<Person>("panelPerson", model, educationFacade);
      add(panelPerson);

      AjaxButton submit =
          new AjaxButton("submit", ResourceUtils.getModel("button.save"), this) {

            private static final long serialVersionUID = 1L;

            @Override
            protected void onError(AjaxRequestTarget target, Form<?> form) {
              target.add(feedback);
            }

            @Override
            protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
              Person user = panelPerson.getModelObject();
              user.setUsername(PersonForm.this.getModelObject().getUsername());
              user.setEmail(user.getUsername().toLowerCase());
              boolean isEdit = user.getPersonId() > 0;

              if (validation(user, personFacade, isEdit)) {
                if (isEdit) {
                  personFacade.update(user);
                } else {
                  user.setAuthority(Util.ROLE_READER);
                  personFacade.create(user);
                }
                setResponsePage(ListPersonPage.class);
              }
              target.add(feedback);
            }
          };
      add(submit);
    }
Exemplo n.º 3
0
  public PersonFormPage(PageParameters parameters) throws IOException {

    StringValue paramId = parameters.get(DEFAULT_PARAM_ID);

    if (paramId.isNull() || paramId.isEmpty())
      throw new RestartResponseAtInterceptPageException(ListPersonPage.class);

    setPageTitle(ResourceUtils.getModel("pageTitle.editPerson"));
    add(new Label("title", ResourceUtils.getModel("pageTitle.editPerson")));

    add(new ButtonPageMenu("leftMenu", PersonPageLeftMenu.values()));

    Person person = facade.getPersonForDetail(paramId.toInt());

    if (!securityFacade.userCanEditPerson(person.getPersonId()))
      throw new RestartResponseAtInterceptPageException(
          PersonDetailPage.class,
          PageParametersUtils.getDefaultPageParameters(person.getPersonId()));

    add(new PersonForm("form", new Model<Person>(person), educationFacade, facade, getFeedback()));
  }
Exemplo n.º 4
0
  public MetadataFormPage(final PageParameters parameters) {

    setPageTitle(ResourceUtils.getModel("pageTitle.metadata.new"));
    add(new ButtonPageMenu("leftMenu", ExperimentsPageLeftMenu.values()));

    StringValue value = parameters.get(DEFAULT_PARAM_ID);
    if (value.isEmpty() || value.isNull()) {
      throw new RestartResponseAtInterceptPageException(ListTemplatePage.class);
    }

    int experimentId = value.toInt();
    Experiment exp = expFacade.getExperimentForDetail(experimentId);
    add(
        new MetadataForm(
            "metadata-form",
            new Model<Section>(exp.getElasticExperiment().getMetadata()),
            experimentId));
    getFeedback().setFilter(new ComponentFeedbackMessageFilter(this));
  }
Exemplo n.º 5
0
 public BasePage() {
   add(new Label("pageTitle", ResourceUtils.getModel("title.app")));
 }
  private void setupComponents() {

    setPageTitle(ResourceUtils.getModel("pageTitle.weatherDefinitionsList"));

    add(new ButtonPageMenu("leftMenu", ListsLeftPageMenu.values()));

    final WebMarkupContainer container = new WebMarkupContainer("container");
    container.setOutputMarkupPlaceholderTag(true);

    final ListModelWithResearchGroupCriteria<Weather> model =
        new ListModelWithResearchGroupCriteria<Weather>() {

          private static final long serialVersionUID = 1L;

          @Override
          protected List<Weather> loadList(ResearchGroup group) {
            if (group == null || group.getResearchGroupId() == CoreConstants.DEFAULT_ITEM_ID)
              return facade.getDefaultRecords();
            else {
              return facade.getRecordsByGroup(group.getResearchGroupId());
            }
          }
        };

    List<ResearchGroup> groups;
    final boolean isAdmin = security.isAdmin();
    final boolean isExperimenter = security.userIsExperimenter();
    if (isAdmin) {
      ResearchGroup defaultGroup =
          new ResearchGroup(
              CoreConstants.DEFAULT_ITEM_ID,
              EEGDataBaseSession.get().getLoggedUser(),
              ResourceUtils.getString("label.defaultWeather"),
              "-");
      groups = researchGroupFacade.getAllRecords();
      groups.add(0, defaultGroup);
    } else
      groups =
          researchGroupFacade.getResearchGroupsWhereMember(
              EEGDataBaseSession.get().getLoggedUser());

    PropertyListView<Weather> weathers =
        new PropertyListView<Weather>("weathers", model) {

          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(final ListItem<Weather> item) {
            item.add(new Label("weatherId"));
            item.add(new Label("title"));
            item.add(new Label("description"));

            PageParameters parameters =
                PageParametersUtils.getDefaultPageParameters(item.getModelObject().getWeatherId())
                    .add(
                        PageParametersUtils.GROUP_PARAM,
                        (model.getCriteriaModel().getObject() == null)
                            ? CoreConstants.DEFAULT_ITEM_ID
                            : model.getCriteriaModel().getObject().getResearchGroupId());

            item.add(new BookmarkablePageLink<Void>("edit", WeatherFormPage.class, parameters));
            item.add(
                new AjaxLink<Void>("delete") {

                  private static final long serialVersionUID = 1L;

                  @Override
                  public void onClick(AjaxRequestTarget target) {

                    int id = item.getModelObject().getWeatherId();
                    ResearchGroup group = model.getCriteriaModel().getObject();

                    if (facade.canDelete(id)) {
                      if (group != null) {
                        int groupId = group.getResearchGroupId();

                        if (groupId
                            == CoreConstants
                                .DEFAULT_ITEM_ID) { // delete default weather if it's from default
                          // group
                          if (!facade.hasGroupRel(
                              id)) { // delete only if it doesn't have group relationship
                            facade.delete(item.getModelObject());
                            setResponsePage(ListWeatherDefinitiosPage.class);
                          } else {
                            getFeedback().error(ResourceUtils.getString("text.itemInUse"));
                          }
                        } else {
                          WeatherGroupRel h = facade.getGroupRel(id, groupId);
                          if (!facade.isDefault(id)) { // delete only non default weather
                            facade.delete(item.getModelObject());
                          }
                          facade.deleteGroupRel(h);
                          setResponsePage(ListWeatherDefinitiosPage.class);
                        }
                      }

                    } else {
                      getFeedback().error(ResourceUtils.getString("text.itemInUse"));
                    }

                    target.add(container);
                    target.add(getFeedback());
                  }

                  @Override
                  protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
                    super.updateAjaxAttributes(attributes);

                    AjaxCallListener ajaxCallListener = new AjaxCallListener();
                    ajaxCallListener.onPrecondition(
                        "return confirm('Are you sure you want to delete item?');");
                    attributes.getAjaxCallListeners().add(ajaxCallListener);
                  }
                }.setVisibilityAllowed(isAdmin || isExperimenter));
          }
        };
    container.add(weathers);

    AjaxLink<Void> link =
        new AjaxLink<Void>("addWeatherLink") {

          private static final long serialVersionUID = 1L;

          @Override
          public void onClick(AjaxRequestTarget target) {
            int researchGroupId =
                (model.getCriteriaModel().getObject() == null)
                    ? CoreConstants.DEFAULT_ITEM_ID
                    : model.getCriteriaModel().getObject().getResearchGroupId();
            setResponsePage(
                WeatherFormPage.class,
                PageParametersUtils.getPageParameters(
                    PageParametersUtils.GROUP_PARAM, researchGroupId));
          }
        };
    link.setVisibilityAllowed(isAdmin || isExperimenter);

    add(
        new ResearchGroupSelectForm(
            "form",
            model.getCriteriaModel(),
            new ListModel<ResearchGroup>(groups),
            container,
            isAdmin));
    add(link, container);
  }