Ejemplo n.º 1
0
  private Canvas buildLocaleSelection() {
    String[] languages = {"English", "Spanish"};
    String[] languageCodes = {"en", "sp"};
    Menu localeMenu = new Menu();
    MenuItem[] menuItems = new MenuItem[languages.length];
    for (int i = 0; i < languages.length; i++) {
      MenuItem tempMenuItem = new MenuItem(languages[i]);
      menuItems[i] = tempMenuItem;
    }
    localeMenu.setData(menuItems);
    localeMenu.setShowIcons(false);

    String currentLanguage = languages[0];

    IMenuButton moduleSelectionButton = new IMenuButton(currentLanguage, localeMenu);
    moduleSelectionButton.setOverflow(Overflow.VISIBLE);
    return moduleSelectionButton;
  }
Ejemplo n.º 2
0
  private Canvas buildUserInfo() {
    HLayout userFields = new HLayout();
    userFields.setAlign(Alignment.RIGHT);
    userFields.addMember(buildUserImage());
    LayoutSpacer sp1 = new LayoutSpacer();
    sp1.setWidth(8);
    userFields.addMember(sp1);

    // Label userLabel = new Label(SecurityManager.USER.getUserName());
    //  userLabel.setBaseStyle("userText");
    //  userLabel.setWidth(1);
    //   userLabel.setOverflow(Overflow.VISIBLE);
    //   userFields.addMember(userLabel);

    //  userFields.addMember(buildLogoutImage());

    Menu menu = new Menu();
    menu.setShowShadow(true);
    menu.setShadowDepth(10);
    menu.setShowIcons(false);

    MenuItem logout = new MenuItem("Logout");
    MenuItem edit = new MenuItem("Edit ...");
    MenuItem changePassword = new MenuItem("Change Password ...");

    menu.setItems(edit, changePassword, logout);

    changePassword.addClickHandler(
        new com.smartgwt.client.widgets.menu.events.ClickHandler() {
          @Override
          public void onClick(MenuItemClickEvent event) {
            redirect(GWT.getHostPageBaseURL() + "blcadmin/changePassword");
          }
        });
    //        changePassword.addClickHandler(new
    // com.smartgwt.client.widgets.menu.events.ClickHandler() {
    //                    @Override
    //                    public void onClick(MenuItemClickEvent event) {
    //                        final DynamicEntityDataSource userDS = new
    // DynamicEntityDataSource(CeilingEntities.ADMIN_USER);
    //                        userDS.buildFields(null, false, new AsyncCallbackAdapter() {
    //                            public void onSetupSuccess(DataSource ds) {
    //                                //strip out password validation
    //                                userDS.getField("password").setValidators();
    //
    //                                AdminUser currentUser = SecurityManager.USER;
    //                                Record userRecord = new Record();
    //                                userRecord.setAttribute("id", currentUser.getId());
    //                                userRecord.setAttribute("login", currentUser.getUserName());
    //                                userRecord.setAttribute("_type", new
    // String[]{EntityImplementations.ADMIN_USER});
    //
    //                                EntityEditDialog ed = new EntityEditDialog();
    //
    //                                ed.editRecord("Change Password", userDS, userRecord, new
    // ItemEditedHandler() {
    //                                    public void onItemEdited(ItemEdited event) {
    //                                        String currentPage =
    // BLCLaunch.getSelectedPage(History.getToken());
    //                                        if ("User Management".equals(currentPage)) {
    //                                            buildHistoryNewItem(currentPage,
    // BLCLaunch.getSelectedModule(History.getToken()), event.getRecord().getAttribute("id"));
    //                                        }
    //                                    }
    //                                }, new String[]{"password"}, new String[]{}, false);
    //                            }
    //                        });
    //
    //                    }
    //                });

    edit.addClickHandler(
        new com.smartgwt.client.widgets.menu.events.ClickHandler() {
          @Override
          public void onClick(MenuItemClickEvent event) {
            final DynamicEntityDataSource userDS =
                new DynamicEntityDataSource(CeilingEntities.ADMIN_USER);
            userDS.buildFields(
                null,
                false,
                new AsyncCallbackAdapter() {
                  public void onSetupSuccess(DataSource ds) {
                    AdminUser currentUser = SecurityManager.USER;
                    Record userRecord = new Record();
                    userRecord.setAttribute("id", currentUser.getId());
                    userRecord.setAttribute("name", currentUser.getName());
                    userRecord.setAttribute("email", currentUser.getEmail());
                    userRecord.setAttribute("phoneNumber", currentUser.getPhoneNumber());
                    userRecord.setAttribute("login", currentUser.getUserName());
                    userRecord.setAttribute(
                        "_type", new String[] {EntityImplementations.ADMIN_USER});

                    EntityEditDialog ed = new EntityEditDialog();

                    ed.editRecord(
                        "Edit User Information",
                        userDS,
                        userRecord,
                        new ItemEditedHandler() {
                          public void onItemEdited(ItemEdited event) {
                            SecurityManager.USER.setPhoneNumber(
                                event.getRecord().getAttribute("phoneNumber"));
                            SecurityManager.USER.setName(event.getRecord().getAttribute("name"));
                            SecurityManager.USER.setEmail(event.getRecord().getAttribute("email"));
                            String currentPage = BLCLaunch.getSelectedPage(History.getToken());
                            // If we are on the user module, reload the page with the specifically
                            // edited item.
                            if ("User Management".equals(currentPage)) {
                              buildHistoryNewItem(
                                  currentPage,
                                  BLCLaunch.getSelectedModule(History.getToken()),
                                  event.getRecord().getAttribute("id"));
                            }
                          }
                        },
                        null,
                        new String[] {"login", "activeStatusFlag", "password"},
                        false);
                  }
                });
          }
        });

    logout.addClickHandler(
        new com.smartgwt.client.widgets.menu.events.ClickHandler() {
          @Override
          public void onClick(MenuItemClickEvent event) {
            UrlBuilder builder = Window.Location.createUrlBuilder();
            builder.setPath(BLCMain.webAppContext + "/adminLogout.htm");
            builder.setHash(null);
            builder.setParameter("time", String.valueOf(System.currentTimeMillis()));
            Window.open(builder.buildString(), "_self", null);
          }
        });

    IMenuButton menuButton = new IMenuButton(SecurityManager.USER.getUserName(), menu);
    menuButton.setPadding(5);
    menuButton.setChildrenSnapResizeToGrid(true);
    menuButton.setOverflow(Overflow.VISIBLE);
    userFields.addMember(menuButton);

    LayoutSpacer sp2 = new LayoutSpacer();
    sp2.setWidth(200);
    userFields.addMember(sp2);

    return userFields;
  }