Esempio n. 1
0
  public void dataReceived(List<JSOModel> models) {
    HTML promptHTML;
    TreeItem prompt;
    String pName;
    Prompt p;

    // don't re-populate
    if (promptMap.size() == 0) {
      for (JSOModel model : models) {
        p = new Prompt(model);
        pName = p.getName() != null ? p.getName() : "Prompt " + p.getOrder();
        promptHTML = imageItemHTML(images.responses(), pName);
        prompt = new TreeItem(promptHTML);
        promptMap.put(promptHTML, p);
        leaves.put(promptHTML, prompt);
        // root.addItem(prompt);
        root.insertItem(0, prompt);
      }
    }

    selectFirst();
  }
Esempio n. 2
0
  public SurveyWidget(Survey s, Images images, Composite parent) {
    this.survey = s;
    this.images = images;
    this.parent = parent;

    tree = new Tree(images);
    String title = s.getName() + " ";
    SurveyStatus status = survey.getStatus();
    switch (status) {
      case ACTIVE:
        title += "<span style='color:green'>(Active)</span>";
        break;
      case CANCELLED:
        title += "<span style='color:red'>(Cancelled)</span>";
        break;
      case EXPIRED:
        title += "(Expired)";
    }
    rootHTML = imageItemHTML(images.inbox(), title);
    root = new TreeItem(rootHTML);
    tree.addItem(root);

    tree.addSelectionHandler(
        new SelectionHandler<TreeItem>() {

          public void onSelection(SelectionEvent<TreeItem> event) {
            TreeItem item = event.getSelectedItem();

            if (promptMap.containsKey(item)) {
              Prompt p = promptMap.get(item);
              Messages.get().displaySurveyInput(p, 0);
            }
          }
        });

    detailsHTML = imageItemHTML(images.drafts(), "Details");
    detailsHTML.addClickHandler(
        new ClickHandler() {

          public void onClick(ClickEvent event) {
            if (detailsModel == null) {
              JSONRequest request = new JSONRequest();
              request.doFetchURL(
                  AoAPI.SURVEY_DETAILS + survey.getId() + "/", new SurveyDetailsRequester());
            } else {
              DetailsDialog details = new DetailsDialog(detailsModel);
              details.show();
              details.center();
            }
          }
        });

    TreeItem details = new TreeItem(detailsHTML);
    root.addItem(details);

    if (status == SurveyStatus.ACTIVE) {
      cancelHTML = imageItemHTML(images.reject_sm(), "Cancel");
      cancelHTML.addClickHandler(
          new ClickHandler() {
            public void onClick(ClickEvent event) {
              confirm =
                  new AreYouSureDialog(
                      "Are you sure you want to cancel all future calls for this broadcast?");
              confirm.show();
              confirm.center();

              confirm.addCloseHandler(
                  new CloseHandler<PopupPanel>() {
                    public void onClose(CloseEvent<PopupPanel> event) {
                      if (confirm.isConfirmed()) {
                        JSONRequest request = new JSONRequest();
                        request.doFetchURL(
                            AoAPI.CANCEL_SURVEY + survey.getId() + "/",
                            new CancelSurveyRequester());
                      }
                    }
                  });
            }
          });

      TreeItem cancel = new TreeItem(cancelHTML);
      root.addItem(cancel);
    }
  }