Ejemplo n.º 1
0
  private void buildJSImagesList() {
    String str = "var tinyMCEImageList = new Array(\n";
    Path dir = Paths.get(System.getProperty("user.home"), ".saas", "app", "ui", "img", "www");
    boolean isFirst = true;
    for (File f : dir.toFile().listFiles()) {
      if (f.isDirectory()) {
        continue;
      }

      String s = "[\"" + f.getName() + "\", \"img/www/" + f.getName() + "\"]";
      if (isFirst) {
        str += s;
        isFirst = false;
      } else {
        str += ",\n" + s;
      }
    }

    str += "\n);";

    Path f =
        Paths.get(System.getProperty("user.home"), ".saas", "app", "ui", "js", "image_list.js");
    try {
      Files.write(f, str.getBytes());
    } catch (IOException ex) {
      Logger.getGlobal().log(Level.WARNING, str, ex);
      JSMediator.alert(getSession(), ex.toString());
    }
  }
Ejemplo n.º 2
0
  private void savePage(String page) {
    PopupPanel popupPanel = new PopupPanel(getSession());
    popupPanel.setTitle("Сообщение");
    popupPanel.setPanel("Сохранено");

    if (core.isPageExist(selectedPage)) {
      Result r = core.modifyWWWPage(selectedPage, page);
      if (r.isError()) {
        JSMediator.alert(getSession(), r.getReason());
      } else {
        popupPanel.showPanel();
      }

    } else {
      Result r = core.addWWWPage(selectedPage, page);
      if (r.isError()) {
        JSMediator.alert(getSession(), r.getReason());
      } else {
        popupPanel.showPanel();
      }
    }
  }
Ejemplo n.º 3
0
  @Override
  public void fireEvent(String json) {
    if (json == null) {
      return;
    }
    if (json.equals("")) {
      return;
    }
    if (json.equals("{}")) {
      return;
    }
    try {
      JSONObject jsonObject = new JSONObject(json);

      setSession(jsonObject.getString("session"));

      if (jsonObject.getString("eventType").equals("click")) {
        MainFrame.getInstance().setSelectedOperationButton(getSession(), "WWW редактор");
        JSMediator.showEditor(getSession(), getModel());
        JSMediator.hideNavigationPanel(getSession());
      }

      if (jsonObject.getString("eventType").equals("save")) {
        savePage(jsonObject.getString("value"));
      }

      if (jsonObject.getString("eventType").equals("fileUploaded")) {
        JSONObject jsObj = new JSONObject(jsonObject.getString("response"));
        if (jsObj.getString("status").equals("success")) {
          try {
            Path src = Paths.get(jsObj.getString("file"));
            Path dst =
                Paths.get(
                    System.getProperty("user.home"),
                    ".saas",
                    "app",
                    "ui",
                    "img",
                    "www",
                    src.getName(src.getNameCount() - 1).toString());
            Files.move(src, dst);
            buildJSImagesList();
            JSMediator.setImageBrowser(getSession(), getImageBrowser());

          } catch (IOException ex) {
            Logger.getLogger(EditorPanel.class.getName()).log(Level.SEVERE, null, ex);
          }
        }
      }

      if (jsonObject.getString("eventType").equals("selectImage")) {
        selectedFileImage =
            Paths.get(
                System.getProperty("user.home"),
                ".saas",
                "app",
                "ui",
                "img",
                "www",
                jsonObject.getString("image"));
      }

    } catch (JSONException ex) {
      Logger.getGlobal().log(Level.WARNING, json, ex);
    }
  }