コード例 #1
0
ファイル: Defects.java プロジェクト: manuelbernhardt/tm
  @Restrict(UnitRole.DEFECTVIEW)
  public static void getComments(Long defectId) {
    List<DefectComment> defectComments = DefectComment.find("defect.id=?", defectId).fetch();
    TMUser tmUser = TMUser.find("id=?", getConnectedUserId()).first();
    JsonArray jsonArray = new JsonArray();
    JsonObject result = new JsonObject();
    for (DefectComment defectComment : defectComments) {
      JsonObject comment = new JsonObject();
      comment.addProperty("id", defectComment.id);
      comment.addProperty("comment", JavaExtensions.nl2br(defectComment.comment).toString());
      comment.addProperty("submittedBy", defectComment.submittedBy.getFullName());
      SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
      comment.addProperty("submittedOn", sdf.format(defectComment.created));

      comment.addProperty("commentText", defectComment.comment);
      comment.addProperty("mainCommentId", "mainCommentId" + defectComment.id);
      comment.addProperty("hiddenDivId", "hiddenDiv" + defectComment.id);
      comment.addProperty("visibleDivId", "visibleDiv" + defectComment.id);
      comment.addProperty("visibleActionsId", "visibleActions" + defectComment.id);
      comment.addProperty("hiddenActionsId", "hiddenActions" + defectComment.id);
      comment.addProperty("commentEditInputId", "commentEditInputId" + defectComment.id);
      comment.addProperty("canEdit", defectComment.submittedBy.equals(tmUser));

      jsonArray.add(comment);
    }
    result.add("comments", jsonArray);
    renderJSON(result.toString());
  }
コード例 #2
0
 public Question(
     String name, String answer, String slug, Long userID, Long containerID, Long versionID) {
   this.question = name;
   this.answer = answer;
   this.slug_anchor = play.templates.JavaExtensions.slugify(slug);
   this.containerID = containerID;
   this.userID = userID;
   this.versionID = versionID;
 }
コード例 #3
0
ファイル: Tags.java プロジェクト: aryanugroho/play-cms
  public static void _display(
      Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine)
      throws Throwable {

    String pageName = (String) args.get("arg");
    CMSPage page = CMSPage.findById(pageName);
    if (page == null) {
      page = new CMSPage();
      page.name = pageName;
      page.title = "Fragment on " + template.template.name;
      page.body = JavaExtensions.toString(body);
      page.active = false;
      page.save();
      out.print(JavaExtensions.toString(body));
    } else if (!page.active) {
      out.print(JavaExtensions.toString(body));
    } else {
      out.print(page.body);
    }
    edit(out, page.name);
  }
コード例 #4
0
ファイル: PlayHandler.java プロジェクト: robfig/play
  void saveExceededSizeError(HttpRequest nettyRequest, Request request, Response response) {

    String warning = nettyRequest.getHeader(HttpHeaders.Names.WARNING);
    String length = nettyRequest.getHeader(HttpHeaders.Names.CONTENT_LENGTH);
    if (warning != null) {
      Logger.trace("saveExceededSizeError: begin");
      try {
        StringBuilder error = new StringBuilder();
        error.append("\u0000");
        // Cannot put warning which is play.netty.content.length.exceeded
        // as Key as it will result error when printing error
        error.append("play.netty.maxContentLength");
        error.append(":");
        String size = null;
        try {
          size = JavaExtensions.formatSize(Long.parseLong(length));
        } catch (Exception e) {
          size = length + " bytes";
        }
        error.append(Messages.get(warning, size));
        error.append("\u0001");
        error.append(size);
        error.append("\u0000");
        if (request.cookies.get(Scope.COOKIE_PREFIX + "_ERRORS") != null
            && request.cookies.get(Scope.COOKIE_PREFIX + "_ERRORS").value != null) {
          error.append(request.cookies.get(Scope.COOKIE_PREFIX + "_ERRORS").value);
        }
        String errorData = URLEncoder.encode(error.toString(), "utf-8");
        Http.Cookie c = new Http.Cookie();
        c.value = errorData;
        c.name = Scope.COOKIE_PREFIX + "_ERRORS";
        request.cookies.put(Scope.COOKIE_PREFIX + "_ERRORS", c);
        Logger.trace("saveExceededSizeError: end");
      } catch (Exception e) {
        throw new UnexpectedException("Error serialization problem", e);
      }
    }
  }
コード例 #5
0
ファイル: PaginationTag.java プロジェクト: Ral008/salas
 public static void _pag(
     Map<?, ?> args, Closure body, PrintWriter out, ExecutableTemplate template, int fromLine)
     throws Exception {
   // Refactorizar
   String titulo = (String) args.get("titulo");
   String cab = (String) args.get("cab");
   List lista = (List) args.get("lista");
   int itemPag = (Integer) args.get("itemPag");
   int cantidadPestana = (Integer) args.get("cantidadPestana");
   int cantidadLista = lista.size();
   int cantidadPag = cantidadLista / itemPag;
   int pag = 1;
   if (args.get("pag") != null) {
     pag = (Integer) args.get("pag");
   }
   if (cantidadLista % itemPag != 0) {
     cantidadPag++;
   }
   String html = "";
   html += "<div id='pagination" + titulo + "'>";
   if (pag == 1) {
     if (cantidadPag == 1 || cantidadPag == 0) {
       html += "<div class='pagination'><ul>";
       html += "<li class='active'><a href='#' class='pagination" + titulo + "'>1</a></li>";
       html += "</ul></div>";
     } else {
       int inicioPag = 0;
       int finPag = 0;
       int inicioRango = (cantidadPestana / 2) + 1;
       int finRango = (cantidadPestana / 2) - 1;
       if (cantidadPag < cantidadPestana) {
         inicioPag = 0;
         finPag = cantidadPag;
       } else {
         if (pag > inicioRango && (pag + finRango) < cantidadPag) {
           inicioPag = pag - inicioRango;
           finPag = pag + finRango;
         } else if ((pag + finRango) >= cantidadPag) {
           inicioPag = cantidadPag - cantidadPestana;
           finPag = cantidadPag;
         } else {
           inicioPag = 0;
           finPag = cantidadPestana;
         }
       }
       html += "<div class='pagination'><ul>";
       html +=
           "<li class='active'><a href='#' class='pagination" + titulo + "' key='1'>Pri.</a></li>";
       html +=
           "<li class='active'><a href='#' class='pagination" + titulo + "' key='1'>Ant.</a></li>";
       for (int i = inicioPag; i < finPag; i++) {
         if (pag == (i + 1)) {
           html +=
               "<li class='active'><a href='#' class='pagination"
                   + titulo
                   + "' key='"
                   + (i + 1)
                   + "'>"
                   + (i + 1)
                   + "</a></li>";
         } else {
           html +=
               "<li><a href='#' class='pagination"
                   + titulo
                   + "' key='"
                   + (i + 1)
                   + "'>"
                   + (i + 1)
                   + "</a></li>";
         }
       }
       html += "<li><a href='#' class='pagination" + titulo + "' key='2'>Sig.</a></li>";
       html +=
           "<li><a href='#' class='pagination"
               + titulo
               + "' key='"
               + cantidadPag
               + "'>Ult.</a></li>";
       html += "</ul></div>";
     }
   } else if (cantidadPag == pag) {
     int inicioPag = 0;
     int finPag = 0;
     int inicioRango = (cantidadPestana / 2) + 1;
     int finRango = (cantidadPestana / 2) - 1;
     if (cantidadPag < cantidadPestana) {
       inicioPag = 0;
       finPag = cantidadPag;
     } else {
       if (pag > inicioRango && (pag + finRango) < cantidadPag) {
         inicioPag = pag - inicioRango;
         finPag = pag + finRango;
       } else if ((pag + finRango) >= cantidadPag) {
         inicioPag = cantidadPag - cantidadPestana;
         finPag = cantidadPag;
       } else {
         inicioPag = 0;
         finPag = cantidadPestana;
       }
     }
     html += "<div class='pagination'><ul>";
     html += "<li><a href='#' class='pagination" + titulo + "' key='1'>Pri.</a></li>";
     html +=
         "<li><a href='#' class='pagination" + titulo + "' key='" + (pag - 1) + "'>Ant.</a></li>";
     for (int i = inicioPag; i < finPag; i++) {
       if (pag == (i + 1)) {
         html +=
             "<li class='active'><a href='#' class='pagination"
                 + titulo
                 + "' key='"
                 + (i + 1)
                 + "'>"
                 + (i + 1)
                 + "</a></li>";
       } else {
         html +=
             "<li><a href='#' class='pagination"
                 + titulo
                 + "' key='"
                 + (i + 1)
                 + "'>"
                 + (i + 1)
                 + "</a></li>";
       }
     }
     html +=
         "<li class='active'><a href='#' class='pagination"
             + titulo
             + "' key='"
             + cantidadPag
             + "'>Sig.</a></li>";
     html +=
         "<li class='active'><a href='#' class='pagination"
             + titulo
             + "' key='"
             + cantidadPag
             + "'>Ult.</a></li>";
     html += "</ul></div>";
   } else {
     int inicioPag = 0;
     int finPag = 0;
     int inicioRango = (cantidadPestana / 2) + 1;
     int finRango = (cantidadPestana / 2) - 1;
     if (cantidadPag < cantidadPestana) {
       inicioPag = 0;
       finPag = cantidadPag;
     } else {
       if (pag > inicioRango && (pag + finRango) < cantidadPag) {
         inicioPag = pag - inicioRango;
         finPag = pag + finRango;
       } else if ((pag + finRango) >= cantidadPag) {
         inicioPag = cantidadPag - cantidadPestana;
         finPag = cantidadPag;
       } else {
         inicioPag = 0;
         finPag = cantidadPestana;
       }
     }
     html += "<div class='pagination'><ul>";
     html += "<li><a href='#' class='pagination" + titulo + "' key='1'>Pri.</a></li>";
     html +=
         "<li><a href='#' class='pagination" + titulo + "' key='" + (pag - 1) + "'>Ant.</a></li>";
     for (int i = inicioPag; i < finPag; i++) {
       if (pag == (i + 1)) {
         html +=
             "<li class='active'><a href='#' class='pagination"
                 + titulo
                 + "' key='"
                 + (i + 1)
                 + "'>"
                 + (i + 1)
                 + "</a></li>";
       } else {
         html +=
             "<li><a href='#' class='pagination"
                 + titulo
                 + "' key='"
                 + (i + 1)
                 + "'>"
                 + (i + 1)
                 + "</a></li>";
       }
     }
     html +=
         "<li><a href='#' class='pagination" + titulo + "' key='" + (pag + 1) + "'>Sig.</a></li>";
     html +=
         "<li><a href='#' class='pagination"
             + titulo
             + "' key='"
             + cantidadPag
             + "'>Ult.</a></li>";
     html += "</ul></div>";
   }
   html += "<table class='table table-striped table-bordered table-condensed'><thead><tr>";
   String[] listCab = cab.split(",");
   for (String c : listCab) {
     html += "<th>" + c + "</th>";
   }
   html += "</tr></thead>";
   html += "<tbody>";
   int inicioLista = ((pag - 1) * itemPag);
   int finLista = (pag * itemPag);
   if (finLista > cantidadLista) {
     finLista = cantidadLista;
   }
   for (int i = inicioLista; i < finLista; i++) {
     Object object = lista.get(i);
     body.setProperty("item", object);
     html += JavaExtensions.toString(body);
   }
   html += "</tbody></table>";
   out.println(html);
   out.println("<script type='text/javascript'>");
   out.println("var Paginacion" + titulo + " = {");
   out.println("init : function(){");
   out.println("$('.pagination" + titulo + "').click(Paginacion" + titulo + ".paginacion);");
   out.println("},");
   out.println("paginacion : function(e){");
   out.println("e.preventDefault();");
   out.println("if(!$(this).parents('li').hasClass('active')){");
   out.println(
       "$('#pagination" + titulo + "').load(rutaPaginacion" + titulo + "+'?azar='+Math.random(),");
   out.println("{pag : $(this).attr('key')});");
   out.println("}}}");
   out.println("$(function(){");
   out.println("Paginacion" + titulo + ".init();");
   out.println("});");
   out.println("</script>");
   out.println("</div>");
 }