public void onCreate$detalleUsuarioWindow(Event event) throws Exception {
    doOnCreateCommon(this.detalleUsuarioWindow, event);
    MensajeMultilinea.doSetTemplate();
    if (this.args.containsKey("usuarioSelected")) {
      usuarioSelected = ((Usuarios) this.args.get("usuarioSelected"));
      setUsuarioSelected(usuarioSelected);
      if (!workspace.isAllowed("mostrar_password_user")) {
        txtClaveUsuario.setType("password");
        txtClaveUsuario2.setType("password");
      }
    } else {
      txtClaveUsuario.setType("password");
      txtClaveUsuario2.setType("password");
    }
    if (this.args.containsKey("token")) {
      this.token = ((Integer) this.args.get("token"));
      setToken(this.token);
    } else {
      setToken(Integer.valueOf(0));
    }
    if (this.args.containsKey("listaUsuariosCtrl")) {
      listaUsuarioCtrl = ((ListaUsuariosCtrl) this.args.get("listaUsuariosCtrl"));
    }

    checkPermisos();
    showDetalleCliente();
  }
Пример #2
0
  public ProfileComponent() {
    super();
    final PlayerProfileData player = getPlayerFacade().getCurrentPlayer();

    final Grid profileGrid = new Grid();
    profileGrid.setSclass("profileGrid");

    final Rows profileRows = new Rows();
    profileGrid.appendChild(profileRows);

    final Row idRow = new Row();
    idRow.setSclass("profileRow");
    idRow.appendChild(new Label(Labels.getLabel("profile.id")));
    idRow.appendChild(new Label(player.getId()));
    profileRows.appendChild(idRow);

    final Row nameRow = new Row();
    nameRow.setSclass("profileRow");
    nameRow.appendChild(new Label(Labels.getLabel("profile.name")));
    final Textbox nameBox = new Textbox(player.getName());
    nameBox.setConstraint(
        new SimpleConstraint(SimpleConstraint.NO_EMPTY, Labels.getLabel("register.error.noname")));
    nameRow.appendChild(nameBox);
    profileRows.appendChild(nameRow);

    final Row mailRow = new Row();
    mailRow.setSclass("profileRow");
    mailRow.appendChild(new Label(Labels.getLabel("profile.email")));
    final Textbox mailBox = new Textbox(player.getEMail());
    mailBox.setConstraint("/.+@.+\\.[a-z]+/: " + Labels.getLabel("register.error.noemail"));
    mailRow.appendChild(mailBox);
    profileRows.appendChild(mailRow);

    final Row pwdRow = new Row();
    pwdRow.setSclass("profileRow");
    pwdRow.appendChild(new Label(Labels.getLabel("profile.password")));
    final Textbox pwdBox = new Textbox(player.getPassword());
    // pwdBox.setConstraint(new SimpleConstraint(SimpleConstraint.NO_EMPTY,
    // Labels.getLabel("register.error.nopassword")));
    pwdBox.setType("password");
    pwdRow.appendChild(pwdBox);
    profileRows.appendChild(pwdRow);

    final Row pwd2Row = new Row();
    pwd2Row.setSclass("profileRow");
    pwd2Row.appendChild(new Label(Labels.getLabel("profile.passwordagain")));
    final Textbox pwd2Box = new Textbox(player.getPassword());
    pwd2Box.setConstraint(
        new Constraint() {
          @Override
          public void validate(final Component comp, final Object value)
              throws WrongValueException {
            if (!(pwdBox.getValue().equals(value))) {
              throw new WrongValueException(
                  comp, Labels.getLabel("register.error.unequalpassword"));
            }
          }
        });
    pwd2Box.setType("password");
    pwd2Row.appendChild(pwd2Box);
    profileRows.appendChild(pwd2Row);

    final Row countryRow = new Row();
    countryRow.setSclass("profileRow");
    countryRow.appendChild(new Label(Labels.getLabel("profile.country")));
    final Combobox countryBox = new Combobox();
    countryBox.setConstraint(
        new SimpleConstraint(
            SimpleConstraint.NO_EMPTY, Labels.getLabel("register.error.nocountry")));
    countryBox.setAutodrop(true);
    countryBox.setReadonly(true);
    fillCombo(countryBox, player.getLocale());
    countryRow.appendChild(countryBox);
    profileRows.appendChild(countryRow);

    final Row avCompetitionsRow = new Row();
    avCompetitionsRow.setSclass("competitionsRow");
    avCompetitionsRow.appendChild(new Label(Labels.getLabel("profile.availableCompetitions")));
    final Listbox listbox = new Listbox();
    listbox.setSclass("competitionsListbox");
    avCompetitionsRow.appendChild(listbox);
    listbox.setCheckmark(true);
    listbox.setMultiple(true);

    final List<CompetitionData> comps = getPlayerFacade().getAllCompetitions();
    for (final CompetitionData cmpData : comps) {
      final Listitem listItem = new Listitem(cmpData.getName());
      listItem.setValue(cmpData);
      listItem.setSelected(cmpData.isActive());
      listItem.setDisabled(
          !cmpData.isDeactivatable() || (cmpData.isCurrentCompetition() && comps.size() != 1));
      listbox.appendChild(listItem);
    }

    profileRows.appendChild(avCompetitionsRow);

    final Row buttonRow = new Row();
    buttonRow.setSclass("profileRow");
    final Button button = new Button(Labels.getLabel("profile.submit"));
    button.addEventListener(
        Events.ON_CLICK,
        new EventListener() {
          @Override
          public void onEvent(final Event event) {
            player.setEMail(mailBox.getValue());
            player.setName(nameBox.getValue());

            if (StringUtils.isNotBlank(pwdBox.getValue())
                && pwdBox.getValue().equals(pwd2Box.getValue())) {
              player.setPassword(pwdBox.getValue());
            }
            player.setLocale((Locale) countryBox.getSelectedItem().getValue());

            final List<CompetitionData> cmps = new ArrayList<CompetitionData>();
            for (final Object listItem : listbox.getSelectedItems()) {
              if (listItem instanceof Listitem) {
                final Object value = ((Listitem) listItem).getValue();
                if (value instanceof CompetitionData) {
                  cmps.add((CompetitionData) value);
                }
              }
            }

            getPlayerFacade().setActiveCompetitions(cmps);

            getPlayerFacade().updatePlayer(player);

            try {
              Messagebox.show(Labels.getLabel("profile.update.success"));
              // TODO proper update mechanism
              Executions.sendRedirect("/");
            } catch (final InterruptedException e) {
              LOG.warn("Error while showing messagebox: ", e);
            }
          }
        });
    buttonRow.appendChild(button);
    profileRows.appendChild(buttonRow);

    this.appendChild(profileGrid);

    final Div detailsDiv = new Div();
    detailsDiv.setSclass("rankingUserDetails");

    final Img img = new Img();
    final Div imgCnt = new Div();
    imgCnt.appendChild(img);
    imgCnt.setSclass("rankingUserDetailsImg");
    img.setDynamicProperty("src", player.getPictureUrl());
    detailsDiv.appendChild(imgCnt);

    final Button uploadButton = new Button(Labels.getLabel("profile.upload"));
    uploadButton.setSclass("btngreen profileUserDetailsUpload");
    detailsDiv.appendChild(uploadButton);

    uploadButton.addEventListener(
        Events.ON_CLICK,
        new EventListener() {

          @Override
          public void onEvent(final Event event) throws InterruptedException {
            final Object media = Fileupload.get();
            if (media instanceof Image) {
              final Image image = (Image) media;
              player.setPictureUrl(
                  getPlayerFacade().uploadProfilePicture(image.getByteData(), image.getName()));
              img.setDynamicProperty("src", player.getPictureUrl());
            } else if (media != null) {
              Messagebox.show("Not an image: " + media, "Error", Messagebox.OK, Messagebox.ERROR);
            }
          }
        });
    this.appendChild(detailsDiv);
  }