示例#1
0
  private void doSave() {
    if (validateFields()) {
      group.setName(Utils.safeString(nameTextBox.getValue()));
      group.removeUsers();
      for (UserData userData : toUserStore.getModels()) {
        group.addUser((User) userData.get(Constants.USER));
      }

      final AsyncCallback<Boolean> callbackCheck =
          new AsyncCallback<Boolean>() {
            @Override
            public void onFailure(Throwable caught) {
              WebPasswordSafe.handleServerFailure(caught);
            }

            @Override
            public void onSuccess(Boolean result) {
              // true => group name already taken, else go ahead and save
              if (result) {
                MessageBox.alert(textMessages.error(), textMessages.groupNameAlreadyExists(), null);
              } else {
                AsyncCallback<Void> callback =
                    new AsyncCallback<Void>() {
                      @Override
                      public void onFailure(Throwable caught) {
                        WebPasswordSafe.handleServerFailure(caught);
                      }

                      @Override
                      public void onSuccess(Void result) {
                        Info.display(textMessages.status(), textMessages.groupSaved());
                        hide();
                      }
                    };
                if (group.getId() == 0) {
                  UserService.Util.getInstance().addGroup(group, callback);
                } else {
                  UserService.Util.getInstance().updateGroup(group, callback);
                }
              }
            }
          };
      UserService.Util.getInstance().isGroupTaken(group.getName(), group.getId(), callbackCheck);
    }
  }
示例#2
0
 public GroupData(Group group) {
   set(Constants.ID, group.getId());
   set(Constants.NAME, Format.htmlEncode(group.getName()));
   set(Constants.GROUP, group);
 }