@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); }
/** * Displays the form part corresponding to the video input. The form input is a way to change or * to remove the video file if this one exists. * * @param attachmentId the identifier of the attached file containing the video to display. * @param template the template of the field to which is mapped the video. * @param pagesContext the context of the displaying page. */ private void displayVideoFormInput( final String attachmentId, final FieldTemplate template, final ElementContainer xhtmlContainer, final PagesContext pagesContext) { String fieldName = template.getFieldName(); String language = pagesContext.getLanguage(); String deletionIcon = Util.getIcon("delete"); String deletionLab = Util.getString("removeFile", language); String videoURL = computeVideoURL(attachmentId, pagesContext); Operation defaultOperation = Operation.ADD; if (!videoURL.isEmpty()) { defaultOperation = Operation.UPDATE; Map<String, String> parameters = template.getParameters(pagesContext.getLanguage()); parameters.remove(PARAMETER_WIDTH); parameters.remove(PARAMETER_HEIGHT); // a link to the video Element videoLink = createVideoLink(videoURL, parameters); // a link to the deletion operation img deletionImage = new img(); deletionImage .setAlt(deletionLab) .setSrc(deletionIcon) .setWidth(15) .setHeight(15) .setAlt(deletionLab) .setTitle(deletionLab); a removeLink = new a(); removeLink .setHref("#") .addElement(deletionImage) .setOnClick( "javascript: document.getElementById('" + fieldName + "Video').style.display='none'; document." + pagesContext.getFormName() + "." + fieldName + OPERATION_KEY + ".value='" + Operation.DELETION.name() + "';"); div videoDiv = new div(); videoDiv.setID(fieldName + "Video"); videoDiv.setClass("video"); videoDiv.addElement(videoLink); videoDiv.addElement(" "); videoDiv.addElement(removeLink); xhtmlContainer.addElement(videoDiv); } // the input from which a video file can be selected input fileInput = new input(); fileInput.setID(fieldName); fileInput.setType("file"); fileInput.setSize(50); fileInput.setName(fieldName); input attachmentInput = new input(); attachmentInput .setType("hidden") .setName(fieldName + Field.FILE_PARAM_NAME_SUFFIX) .setValue(attachmentId) .setID(fieldName + Field.FILE_PARAM_NAME_SUFFIX); input operationInput = new input(); operationInput .setType("hidden") .setName(fieldName + OPERATION_KEY) .setValue(defaultOperation.name()) .setID(fieldName + OPERATION_KEY); div selectionDiv = new div(); selectionDiv.setID(fieldName + "Selection"); selectionDiv.addElement(fileInput); selectionDiv.addElement(attachmentInput); selectionDiv.addElement(operationInput); if (template.isMandatory() && pagesContext.useMandatory()) { selectionDiv.addElement(Util.getMandatorySnippet()); } xhtmlContainer.addElement(selectionDiv); Element player = createVideoPlayer(videoURL, template.getParameters(pagesContext.getLanguage())); xhtmlContainer.addElement(player); }