Esempio n. 1
0
  public void deleteMenuItem(String groupName, FBMenuItem item) {
    RequestBuilder request =
        new RequestBuilder(
            RequestBuilder.DELETE, GWT.getModuleBaseURL() + this.contextPath + "/menuItems/");
    request.setCallback(
        new RequestCallback() {
          public void onResponseReceived(Request request, Response response) {
            int code = response.getStatusCode();
            if (code != Response.SC_ACCEPTED
                && code != Response.SC_NO_CONTENT
                && code != Response.SC_OK) {
              bus.fireEvent(
                  new NotificationEvent(
                      Level.WARN, "Error deleting menu item on server (code = " + code + ")"));
            } else {
              bus.fireEvent(new NotificationEvent(Level.INFO, "menu item deleted successfully"));
            }
          }

          public void onError(Request request, Throwable exception) {
            bus.fireEvent(
                new NotificationEvent(
                    Level.ERROR, "Error deleting menu item on server", exception));
          }
        });
    try {
      request.setRequestData(helper.asXml(groupName, item));
      request.send();
    } catch (RequestException e) {
      bus.fireEvent(new NotificationEvent(Level.ERROR, "Error deleting menu item on server", e));
    }
  }
Esempio n. 2
0
  public void generateForm(FormRepresentation form, String language, Map<String, Object> inputs) {
    RequestBuilder request =
        new RequestBuilder(
            RequestBuilder.POST,
            GWT.getModuleBaseURL() + this.contextPath + "/formPreview/lang/" + language);
    request.setCallback(
        new RequestCallback() {
          public void onResponseReceived(Request request, Response response) {
            String html = response.getText();
            bus.fireEvent(new PreviewFormResponseEvent(html));
          }

          public void onError(Request request, Throwable exception) {
            bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't preview form", exception));
          }
        });
    try {
      request.setRequestData(helper.asXml(form, inputs));
      request.send();
    } catch (RequestException e) {
      bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't send form to server", e));
    } catch (FormEncodingException e) {
      bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't decode form", e));
    }
  }
Esempio n. 3
0
  public void loadFormTemplate(final FormRepresentation form, final String language) {
    RequestBuilder request =
        new RequestBuilder(
            RequestBuilder.POST,
            GWT.getModuleBaseURL() + this.contextPath + "/formTemplate/lang/" + language);
    request.setCallback(
        new RequestCallback() {
          public void onResponseReceived(Request request, Response response) {
            String fileName = helper.getFileName(response.getText());
            FormPanel auxiliarForm = new FormPanel();
            auxiliarForm.setMethod("get");
            auxiliarForm.setAction(
                GWT.getModuleBaseURL() + contextPath + "/formTemplate/lang/" + language);
            Hidden hidden1 = new Hidden("fileName");
            hidden1.setValue(fileName);
            Hidden hidden2 = new Hidden("formName");
            hidden2.setValue(
                form.getName() == null || "".equals(form.getName()) ? "template" : form.getName());
            VerticalPanel vPanel = new VerticalPanel();
            vPanel.add(hidden1);
            vPanel.add(hidden2);
            auxiliarForm.add(vPanel);
            RootPanel.get().add(auxiliarForm);
            auxiliarForm.submit();
          }

          public void onError(Request request, Throwable exception) {
            bus.fireEvent(
                new NotificationEvent(Level.ERROR, "Couldn't export template", exception));
          }
        });
    try {
      request.setRequestData(helper.asXml(form, null));
      request.send();
    } catch (RequestException e) {
      bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't send form to server", e));
    } catch (FormEncodingException e) {
      bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't decode form", e));
    }
  }
Esempio n. 4
0
  public void saveFormItem(final FormItemRepresentation formItem, String formItemName) {
    RequestBuilder request =
        new RequestBuilder(
            RequestBuilder.POST,
            GWT.getModuleBaseURL() + this.contextPath + "/formItems/package/defaultPackage/");
    request.setCallback(
        new RequestCallback() {
          public void onResponseReceived(Request request, Response response) {
            if (response.getStatusCode() == Response.SC_CONFLICT) {
              bus.fireEvent(
                  new NotificationEvent(
                      Level.WARN, "formItem already updated in server. Try refreshing your view"));
            } else if (response.getStatusCode() != Response.SC_CREATED) {
              bus.fireEvent(
                  new NotificationEvent(
                      Level.WARN,
                      "Unkown status for saveFormItem: HTTP " + response.getStatusCode()));
            } else {
              String name = helper.getFormItemId(response.getText());
              bus.fireEvent(
                  new NotificationEvent(Level.INFO, "Form item " + name + " saved successfully"));
            }
          }

          public void onError(Request request, Throwable exception) {
            bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't save form item", exception));
          }
        });
    try {
      request.setRequestData(helper.asXml(formItemName, formItem));
      request.send();
    } catch (RequestException e) {
      bus.fireEvent(
          new NotificationEvent(
              Level.ERROR, "Couldn't send form item " + formItemName + " to server", e));
    } catch (FormEncodingException e) {
      bus.fireEvent(
          new NotificationEvent(Level.ERROR, "Couldn't decode form item " + formItemName, e));
    }
  }
Esempio n. 5
0
  public void saveMenuItem(final String groupName, final FBMenuItem item) {
    RequestBuilder request =
        new RequestBuilder(
            RequestBuilder.POST,
            GWT.getModuleBaseURL()
                + this.contextPath
                + "/defaultPackage/menuItems/"
                + groupName
                + "/");
    request.setCallback(
        new RequestCallback() {
          public void onResponseReceived(Request request, Response response) {
            int code = response.getStatusCode();
            NotificationEvent event;
            if (code == Response.SC_CREATED) {
              event =
                  new NotificationEvent(
                      Level.INFO, "Menu item " + item.getItemId() + " saved successfully.");
            } else {
              event =
                  new NotificationEvent(
                      Level.WARN, "Invalid status for saveMenuItem: HTTP " + code);
            }
            bus.fireEvent(event);
          }

          public void onError(Request request, Throwable exception) {
            bus.fireEvent(
                new NotificationEvent(Level.ERROR, "Couldn't generate menu item", exception));
          }
        });
    try {
      request.setRequestData(helper.asXml(groupName, item));
      request.send();
    } catch (RequestException e) {
      bus.fireEvent(new NotificationEvent(Level.ERROR, "Couldn't save menu item", e));
    }
  }