Search in sources :

Example 1 with EscapedClientId

use of com.liferay.faces.alloy.render.internal.EscapedClientId in project liferay-faces-alloy by liferay.

the class DataTableRenderer method encodeJavaScriptCustom.

@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    DataTable dataTable = (DataTable) uiComponent;
    String selectionMode = dataTable.getSelectionMode();
    if ("checkbox".equals(selectionMode) || "radio".equals(selectionMode)) {
        String dataTableClientId = dataTable.getClientId(facesContext);
        EscapedClientId escapedDataTableClientId = new EscapedClientId(dataTableClientId);
        String hiddenFieldClientId = dataTableClientId.concat("_selectedRowIndexes");
        EscapedClientId escapedHiddenFieldClientId = new EscapedClientId(hiddenFieldClientId);
        ResponseWriter responseWriter = facesContext.getResponseWriter();
        // rowSelect
        JavaScriptFragment rowSelectClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowSelectEvent.ROW_SELECT, "rowIndex");
        // rowSelectRange
        JavaScriptFragment rowSelectRangeClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowSelectRangeEvent.ROW_SELECT_RANGE, "rowIndexRange");
        // rowDeselect
        JavaScriptFragment rowDeselectClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowDeselectEvent.ROW_DESELECT, "rowIndex");
        // rowDeSelectRange
        JavaScriptFragment rowDeselectRangeClientBehaviorScript = getRowEventClientBehaviorScript(facesContext, dataTable, dataTableClientId, RowDeselectRangeEvent.ROW_DESELECT_RANGE, "rowIndexRange");
        if ("checkbox".equals(selectionMode)) {
            // Register the onclick event callback for the "Select All" checkbox.
            String selectAllCheckboxClientId = dataTableClientId.concat("_selectAll");
            EscapedClientId escapedSelectAllCheckboxClientId = new EscapedClientId(selectAllCheckboxClientId);
            encodeFunctionCall(responseWriter, "LFAI.initDataTableSelectAllCheckbox", 'A', escapedDataTableClientId, escapedSelectAllCheckboxClientId, rowSelectRangeClientBehaviorScript, rowDeselectRangeClientBehaviorScript);
            // Register the onclick event callback for each row-level checkbox.
            encodeFunctionCall(responseWriter, "LFAI.initDataTableCheckboxSelection", 'A', escapedDataTableClientId, escapedHiddenFieldClientId, rowSelectClientBehaviorScript, rowDeselectClientBehaviorScript);
        } else if ("radio".equals(selectionMode)) {
            // Register the onclick event callback for each row-level radio button.
            encodeFunctionCall(responseWriter, "LFAI.initDataTableRadioSelection", 'A', escapedDataTableClientId, escapedHiddenFieldClientId, rowSelectClientBehaviorScript, rowDeselectClientBehaviorScript);
        }
    }
}
Also used : DataTable(com.liferay.faces.alloy.component.datatable.DataTable) ResponseWriter(javax.faces.context.ResponseWriter) JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) EscapedClientId(com.liferay.faces.alloy.render.internal.EscapedClientId)

Example 2 with EscapedClientId

use of com.liferay.faces.alloy.render.internal.EscapedClientId in project liferay-faces-alloy by liferay.

the class InputDateRenderer method encodeCalendar.

protected void encodeCalendar(FacesContext facesContext, ResponseWriter responseWriter, InputDate inputDate, boolean first) throws IOException {
    // The calendar attribute value provides the opportunity to specify dateClick events, minDate, maxDate as
    // key:value pairs via JSON syntax. For example: "calendar: {minDate: new Date(2015,1,1,0,0,0,0)}"
    boolean calendarFirst = true;
    encodeNonEscapedObject(responseWriter, "calendar", "", first);
    responseWriter.write("{");
    Object maxDateObject = inputDate.getMaxDate();
    if (maxDateObject != null) {
        encodeDate(responseWriter, inputDate, "maximumDate", maxDateObject, calendarFirst);
        calendarFirst = false;
    }
    Object minDateObject = inputDate.getMinDate();
    if (minDateObject != null) {
        encodeDate(responseWriter, inputDate, "minimumDate", minDateObject, calendarFirst);
        calendarFirst = false;
    }
    String showOn = inputDate.getShowOn();
    boolean showOnButton = "button".equals(showOn);
    Map<String, List<ClientBehavior>> clientBehaviorMap = inputDate.getClientBehaviors();
    List<ClientBehavior> valueChangeClientBehaviors = clientBehaviorMap.get(VALUE_CHANGE);
    boolean valueChangeClientBehaviorsNotEmpty = (valueChangeClientBehaviors != null) && !valueChangeClientBehaviors.isEmpty();
    if (showOnButton || valueChangeClientBehaviorsNotEmpty) {
        encodeNonEscapedObject(responseWriter, "on", "", calendarFirst);
        responseWriter.write("{");
        encodeNonEscapedObject(responseWriter, "dateClick", "", true);
        responseWriter.write("function(event){");
        String clientId = inputDate.getClientId(facesContext);
        String inputClientId = clientId.concat(INPUT_SUFFIX);
        EscapedClientId escapedInputClientId = new EscapedClientId(inputClientId);
        JavaScriptFragment selectable = new JavaScriptFragment("this._canBeSelected(event.date)");
        JavaScriptFragment date = null;
        if (showOnButton) {
            // Each time a date is clicked, the input must be updated via javascript because the datePicker is not
            // attached to the input.
            String datePattern = inputDate.getPattern();
            String mask = getMaskFromDatePattern(datePattern);
            String escapedMask = RendererUtil.escapeJavaScript(mask);
            date = new JavaScriptFragment("A.Date.format(event.date,{format:'".concat(escapedMask).concat("'})"));
        }
        encodeFunctionCall(responseWriter, "LFAI.inputDateTimePickerSelect", 'A', escapedInputClientId, selectable, date, valueChangeClientBehaviorsNotEmpty);
        responseWriter.append(";}");
        responseWriter.write("}");
        calendarFirst = false;
    }
    responseWriter.write("}");
}
Also used : JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) List(java.util.List) EscapedClientId(com.liferay.faces.alloy.render.internal.EscapedClientId) ClientBehavior(javax.faces.component.behavior.ClientBehavior)

Example 3 with EscapedClientId

use of com.liferay.faces.alloy.render.internal.EscapedClientId in project liferay-faces-alloy by liferay.

the class InputTimeRenderer method encodeAutocomplete.

protected void encodeAutocomplete(FacesContext facesContext, ResponseWriter responseWriter, InputTime inputTime, boolean first) throws IOException {
    encodeNonEscapedObject(responseWriter, "autocomplete", "", first);
    responseWriter.write("{");
    boolean autoCompleteFirst = true;
    boolean activateFirstItem = inputTime.isActivateFirstItem();
    encodeBoolean(responseWriter, ACTIVATE_FIRST_ITEM, activateFirstItem, autoCompleteFirst);
    autoCompleteFirst = false;
    Boolean circular = inputTime.getCircular();
    if (circular != null) {
        encodeBoolean(responseWriter, CIRCULAR, circular, autoCompleteFirst);
        autoCompleteFirst = false;
    }
    String filterType = inputTime.getFilterType();
    if (filterType != null) {
        encodeString(responseWriter, "resultFilters", filterType, autoCompleteFirst);
        autoCompleteFirst = false;
    }
    String height = inputTime.getHeight();
    if (height != null) {
        encodeString(responseWriter, HEIGHT, height, autoCompleteFirst);
        autoCompleteFirst = false;
    }
    String highlighterType = inputTime.getHighlighterType();
    if (highlighterType != null) {
        encodeString(responseWriter, "resultHighlighter", highlighterType, autoCompleteFirst);
        autoCompleteFirst = false;
    }
    Integer maxResults = inputTime.getMaxResults();
    if (maxResults != null) {
        encodeString(responseWriter, MAX_RESULTS, maxResults, autoCompleteFirst);
        autoCompleteFirst = false;
    }
    Integer queryDelay = inputTime.getQueryDelay();
    if (queryDelay != null) {
        encodeString(responseWriter, QUERY_DELAY, queryDelay, autoCompleteFirst);
        autoCompleteFirst = false;
    }
    Boolean scrollIntoView = inputTime.getScrollIntoView();
    if (scrollIntoView != null) {
        encodeBoolean(responseWriter, SCROLL_INTO_VIEW, scrollIntoView, autoCompleteFirst);
        autoCompleteFirst = false;
    }
    String showOn = inputTime.getShowOn();
    boolean showOnButton = "button".equals(showOn);
    Map<String, List<ClientBehavior>> clientBehaviorMap = inputTime.getClientBehaviors();
    List<ClientBehavior> valueChangeClientBehaviors = clientBehaviorMap.get(VALUE_CHANGE);
    boolean valueChangeClientBehaviorsNotEmpty = (valueChangeClientBehaviors != null) && !valueChangeClientBehaviors.isEmpty();
    if (showOnButton || valueChangeClientBehaviorsNotEmpty) {
        encodeNonEscapedObject(responseWriter, "after", "", autoCompleteFirst);
        responseWriter.write("{");
        encodeNonEscapedObject(responseWriter, "select", "", true);
        responseWriter.write("function(event){");
        String clientId = inputTime.getClientId(facesContext);
        String inputClientId = clientId.concat(INPUT_SUFFIX);
        EscapedClientId escapedInputClientId = new EscapedClientId(inputClientId);
        boolean selectable = true;
        JavaScriptFragment time = null;
        if (showOnButton) {
            time = new JavaScriptFragment("event.result.text");
        }
        encodeFunctionCall(responseWriter, "LFAI.inputDateTimePickerSelect", 'A', escapedInputClientId, selectable, time, valueChangeClientBehaviorsNotEmpty);
        responseWriter.append(";}");
        responseWriter.write("}");
        autoCompleteFirst = false;
    }
    responseWriter.write("}");
}
Also used : JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) List(java.util.List) EscapedClientId(com.liferay.faces.alloy.render.internal.EscapedClientId) ClientBehavior(javax.faces.component.behavior.ClientBehavior)

Example 4 with EscapedClientId

use of com.liferay.faces.alloy.render.internal.EscapedClientId in project liferay-faces-alloy by liferay.

the class InputDateRenderer method encodeJavaScriptCustom.

@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
    InputDate inputDate = (InputDate) uiComponent;
    String showOn = inputDate.getShowOn();
    if (isNative(browserSniffer, inputDate) || "button".equals(showOn)) {
        String clientVarName = getClientVarName(facesContext, inputDate);
        String clientKey = inputDate.getClientKey();
        if (clientKey == null) {
            clientKey = clientVarName;
        }
        JavaScriptFragment liferayComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
        ResponseWriter responseWriter = facesContext.getResponseWriter();
        if (isNative(browserSniffer, inputDate)) {
            String clientId = uiComponent.getClientId(facesContext);
            String inputClientId = clientId.concat(INPUT_SUFFIX);
            Object maxDateObject = inputDate.getMaxDate();
            Object minDateObject = inputDate.getMinDate();
            String maxDateString = null;
            String minDateString = null;
            if ((maxDateObject != null) || (minDateObject != null)) {
                String datePattern = inputDate.getPattern();
                String timeZoneString = inputDate.getTimeZone();
                TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(InputDate.DEFAULT_HTML5_DATE_PATTERN, Locale.ENGLISH);
                if (maxDateObject != null) {
                    Date maxDate = inputDate.getObjectAsDate(maxDateObject, datePattern, timeZone);
                    maxDateString = simpleDateFormat.format(maxDate);
                }
                if (maxDateObject != null) {
                    Date minDate = inputDate.getObjectAsDate(minDateObject, datePattern, timeZone);
                    minDateString = simpleDateFormat.format(minDate);
                }
            }
            encodeFunctionCall(responseWriter, "LFAI.initDateTimePickerMobile", liferayComponent, inputClientId, maxDateString, minDateString);
        } else if ("button".equals(showOn)) {
            String clientId = inputDate.getClientId(facesContext);
            String inputClientId = clientId.concat(INPUT_SUFFIX);
            EscapedClientId escapedInputClientId = new EscapedClientId(inputClientId);
            encodeFunctionCall(responseWriter, "LFAI.initDatePickerShowOnButton", 'A', escapedInputClientId, liferayComponent);
        }
    }
}
Also used : InputDate(com.liferay.faces.alloy.component.inputdate.InputDate) BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer) TimeZone(java.util.TimeZone) ResponseWriter(javax.faces.context.ResponseWriter) InputDateTimeResponseWriter(com.liferay.faces.alloy.component.inputdatetime.internal.InputDateTimeResponseWriter) JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) EscapedClientId(com.liferay.faces.alloy.render.internal.EscapedClientId) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) InputDate(com.liferay.faces.alloy.component.inputdate.InputDate)

Aggregations

EscapedClientId (com.liferay.faces.alloy.render.internal.EscapedClientId)4 JavaScriptFragment (com.liferay.faces.util.render.JavaScriptFragment)4 List (java.util.List)2 ClientBehavior (javax.faces.component.behavior.ClientBehavior)2 ResponseWriter (javax.faces.context.ResponseWriter)2 DataTable (com.liferay.faces.alloy.component.datatable.DataTable)1 InputDate (com.liferay.faces.alloy.component.inputdate.InputDate)1 InputDateTimeResponseWriter (com.liferay.faces.alloy.component.inputdatetime.internal.InputDateTimeResponseWriter)1 BrowserSniffer (com.liferay.faces.util.client.BrowserSniffer)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 TimeZone (java.util.TimeZone)1