Exemplo n.º 1
0
  public static void printSuggestionsScripts(
      PagesContext pageContext, String fieldName, List<String> suggestions, PrintWriter out) {
    out.println("<script type=\"text/javascript\">\n");
    out.println("listArray" + fieldName + " = [\n");

    Iterator<String> itRes = suggestions.iterator();
    String val;
    while (itRes.hasNext()) {
      val = itRes.next();

      out.println("\"" + EncodeHelper.javaStringToJsString(val) + "\"");

      if (itRes.hasNext()) out.println(",");
    }

    out.println("];\n");
    out.println("</script>\n");

    out.println("<script type=\"text/javascript\">\n");
    out.println(
        " this.oACDS"
            + fieldName
            + " = new YAHOO.util.LocalDataSource(listArray"
            + fieldName
            + ");\n");
    out.println(
        "	this.oAutoComp"
            + fieldName
            + " = new YAHOO.widget.AutoComplete('"
            + fieldName
            + "','container"
            + fieldName
            + "', this.oACDS"
            + fieldName
            + ");\n");
    out.println(
        "	this.oAutoComp" + fieldName + ".prehighlightClassName = \"yui-ac-prehighlight\";\n");
    out.println("	this.oAutoComp" + fieldName + ".typeAhead = true;\n");
    out.println("	this.oAutoComp" + fieldName + ".useShadow = true;\n");
    out.println("	this.oAutoComp" + fieldName + ".minQueryLength = 0;\n");

    out.println("	this.oAutoComp" + fieldName + ".textboxFocusEvent.subscribe(function(){\n");
    out.println("		var sInputValue = YAHOO.util.Dom.get('" + fieldName + "').value;\n");
    out.println("		if(sInputValue.length == 0) {\n");
    out.println("			var oSelf = this;\n");
    out.println("			setTimeout(function(){oSelf.sendQuery(sInputValue);},0);\n");
    out.println("		}\n");
    out.println("	});\n");
    out.println("</script>\n");
  }
  @Override
  public void displayScripts(
      final PrintWriter out, final FieldTemplate template, final PagesContext pageContext)
      throws IOException {
    checkFieldType(template.getTypeName(), "VideoFieldDisplayer.displayScripts");
    String language = pageContext.getLanguage();
    String fieldName = template.getFieldName();
    if (template.isMandatory() && pageContext.useMandatory()) {
      out.append("	if (isWhitespace(stripInitialWhitespace(field.value))) {\n")
          .append("		var ")
          .append(fieldName)
          .append("Value = document.getElementById('")
          .append(fieldName)
          .append(Field.FILE_PARAM_NAME_SUFFIX)
          .append("').value;\n")
          .append("   var ")
          .append(fieldName)
          .append("Operation = document.")
          .append(pageContext.getFormName())
          .append(".")
          .append(fieldName)
          .append(OPERATION_KEY)
          .append(".value;\n")
          .append("		if (")
          .append(fieldName)
          .append("Value=='' || ")
          .append(fieldName)
          .append("Operation=='")
          .append(Operation.DELETION.name())
          .append("') {\n")
          .append("			errorMsg+=\"  - '")
          .append(EncodeHelper.javaStringToJsString(template.getLabel(language)))
          .append("' ")
          .append(Util.getString("GML.MustBeFilled", language))
          .append("\\n \";\n")
          .append("			errorNb++;\n")
          .append("		}\n")
          .append("	}\n");
    }

    Util.includeFileNameLengthChecker(template, pageContext, out);
    Util.getJavascriptChecker(template.getFieldName(), pageContext, out);
  }