/**
   * Returns the theme specified in cookies
   *
   * @return the name of the theme or default theme.
   */
  private static String getTheme() {
    ServletRequest request = ServletFns.getCurrentRequest();

    if (!(request instanceof HttpServletRequest)) return StandardTheme.DEFAULT_NAME;

    return _themeResolver.getTheme((HttpServletRequest) request);
  }
Exemple #2
0
  private static void append(StringBuffer sb, JavaScript js) {
    sb.append("\n<script type=\"text/javascript\"");
    if (js.getSrc() != null) {
      String url;
      try {
        url = ServletFns.encodeURL(js.getSrc());
      } catch (javax.servlet.ServletException ex) {
        throw new UiException(ex);
      }

      sb.append(" src=\"").append(url).append('"');
      final String charset = js.getCharset();
      if (charset != null) sb.append(" charset=\"").append(charset).append('"');
      sb.append('>');
    } else {
      sb.append(" class=\"z-runonce\">\n")
          // B65-ZK-1836
          .append(js.getContent().replaceAll("</(?i)(?=script>)", "<\\\\/"))
          .append("\n");
    }
    sb.append("</script>");
  }
Exemple #3
0
  private static void append(StringBuffer sb, StyleSheet ss, Execution exec, Page page) {
    String href = ss.getHref();
    String media = ss.getMedia();
    if (href != null) {
      try {
        if (exec != null) href = (String) exec.evaluate(page, href, String.class);

        if (href != null && href.length() > 0) {
          sb.append("\n<link rel=\"stylesheet\" type=\"")
              .append(ss.getType())
              .append("\" href=\"")
              .append(ServletFns.encodeURL(href));
          if (media != null) sb.append("\" media=\"").append(media);
          sb.append("\"/>");
        }
      } catch (javax.servlet.ServletException ex) {
        throw new UiException(ex);
      }
    } else {
      sb.append("\n<style");
      if (ss.getType() != null) sb.append(" type=\"").append(ss.getType()).append('"');
      sb.append(">\n").append(ss.getContent()).append("\n</style>");
    }
  }
public class MainWindowVM {

  private ServletRequest request = ServletFns.getCurrentRequest();

  private boolean mobile;
  private MenuGroupBean[] menuGroups;
  private boolean menuOpen = false;
  private boolean modalShow = false;
  private String orient = "landscape";
  private User user;

  private String css;

  private AuthenticationService authService = new AuthenticationServiceImpl();

  @Wire("borderlayout#contentArea")
  private Borderlayout contentArea;

  public List<PostBean> getPostModel() {
    return FakeData.getPosts();
  }

  @Init
  public void init() {

    mobile = Servlets.getBrowser(request, "mobile") != null;

    if (mobile) {
      css = "css/tablet.css.dsp";
    } else {
      css = "css/desktop.css.dsp";
    }

    menuGroups =
        new MenuGroupBean[] {
          new MenuGroupBean(
              "MAGAZZINO",
              new ListModelArray<MenuItemBean>(
                  new MenuItemBean[] {
                    new MenuItemBean("images/navigation/menu/articoli24.png", "Articoli"),
                    new MenuItemBean("images/navigation/menu/categorie24.png", "Categorie")
                  })),
          new MenuGroupBean(
              "ANAGRAFICHE",
              new ListModelArray<MenuItemBean>(
                  new MenuItemBean[] {
                    new MenuItemBean("images/navigation/menu/fornitori24.png", "Fornitori"),
                    new MenuItemBean("images/navigation/menu/clienti24.png", "Clienti")
                    //							,
                    //							new MenuItemBean(
                    //									"",
                    //									"Agenti")
                  })),
          new MenuGroupBean(
              "SCADENZE e PAGAMENTI",
              new ListModelArray<MenuItemBean>(
                  new MenuItemBean[] {
                    new MenuItemBean("images/navigation/menu/scadenziario24.png", "Scadenziario"),
                    new MenuItemBean("images/navigation/menu/promemoria24.png", "Promemoria")
                  })),
          new MenuGroupBean(
              "DOCUMENTI",
              new ListModelArray<MenuItemBean>(
                  new MenuItemBean[] {
                    new MenuItemBean(
                        "images/navigation/menu/documenti24.png", "Gestione Documenti"),
                    new MenuItemBean("images/navigation/menu/fatture24.png", "Fatture"),
                    new MenuItemBean("images/navigation/menu/ordini24.png", "Ordini"),
                    new MenuItemBean("images/navigation/menu/preventivi24.png", "Preventivi"),
                    new MenuItemBean(
                        "images/navigation/menu/spedizioni24.png", "Vendita al pubblico")
                  }))
        };

    user = new User();
    user.setUsername(authService.getUserCredential().getUsername());
  }

  @AfterCompose
  public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
    Double ie = Servlets.getBrowser(request, "ie");
    if (ie != null && ie < 8.0) {
      Clients.showNotification("This application does not support IE6/7", true);
    }

    Selectors.wireComponents(view, this, false);
  }

  public ListModel<String> getToolbarModel() {
    return new ListModelList<>(new String[] {"Nuovo", "Dettaglio", "Logout"});
  }

  @Command
  @NotifyChange({"menuOpen"})
  public void updateDeviceStatus(@BindingParam("orient") String orient) {

    if (!mobile) menuOpen = true;
  }

  @Command
  @NotifyChange({"menuOpen"})
  public void toggleMenu() {
    menuOpen = !menuOpen;
  }

  @Command
  @NotifyChange("modalShow")
  public void hideModal() {
    modalShow = false;
  }

  @Command
  public void doLogout() {
    authService.logout();
    Executions.sendRedirect("/login.zul");
  }

  public boolean isMenuOpen() {
    return menuOpen;
  }

  public void setMenuOpen(boolean menuOpen) {
    this.menuOpen = menuOpen;
  }

  public boolean isModalShow() {
    return modalShow;
  }

  public void setModalShow(boolean modalShow) {
    this.modalShow = modalShow;
  }

  public MenuGroupBean[] getMenuGroups() {
    return menuGroups;
  }

  public void setMenuGroups(MenuGroupBean[] menuGroups) {
    this.menuGroups = menuGroups;
  }

  @Command
  public void showMessage(
      @ContextParam(ContextType.COMPONENT) Component comp, @BindingParam("pos") String pos) {

    String msg = null;

    if (comp instanceof Listbox) {
      Listitem item = ((Listbox) comp).getSelectedItem();

      if (item instanceof MenuItem) msg = ((MenuItem) item).getTitle();

      ((Listbox) comp).setSelectedItem(null);
      comp = item;
    } else if (comp instanceof Toolbarbutton) {
      msg = ((Toolbarbutton) comp).getLabel();
    } else return;

    System.out.println(contentArea);

    //		Center center = contentArea.getCenter();
    //		center.getChildren().clear();
    //		Executions.createComponents("/WEB-INF/fornitori/fornitori.zul", center, null);

    Clients.showNotification(msg, Clients.NOTIFICATION_TYPE_INFO, comp, pos, 2000);
  }

  public String getCss() {
    return css;
  }

  public void setCss(String css) {
    this.css = css;
  }

  public User getUser() {
    return user;
  }
}