001// Licensed under the Apache License, Version 2.0 (the "License"); 002// you may not use this file except in compliance with the License. 003// You may obtain a copy of the License at 004// 005// http://www.apache.org/licenses/LICENSE-2.0 006// 007// Unless required by applicable law or agreed to in writing, software 008// distributed under the License is distributed on an "AS IS" BASIS, 009// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 010// See the License for the specific language governing permissions and 011// limitations under the License. 012 013package org.apache.tapestry5.corelib.mixins; 014 015import org.apache.tapestry5.BindingConstants; 016import org.apache.tapestry5.MarkupWriter; 017import org.apache.tapestry5.annotations.Environmental; 018import org.apache.tapestry5.annotations.MixinAfter; 019import org.apache.tapestry5.annotations.Parameter; 020import org.apache.tapestry5.services.javascript.JavaScriptSupport; 021 022/** 023 * A mixin that can be placed on a clickable component, such as {@link org.apache.tapestry5.corelib.components.LinkSubmit}, 024 * and will raise a confirmation dialog when the element is clicked. 025 * 026 * Due to conflicts between jQuery (as used by Bootstrap's JavaScript library) and Prototype, this mixin does not operate 027 * when the {@linkplain org.apache.tapestry5.SymbolConstants#JAVASCRIPT_INFRASTRUCTURE_PROVIDER JavaScript infrastructure provider} 028 * is "prototype". 029 * 030 * @tapestrydoc 031 * @since 5.4 032 */ 033@MixinAfter 034public class Confirm 035{ 036 /** 037 * The message to present to the user in the body of the modal dialog. 038 */ 039 @Parameter(value = "message:private-default-confirm-message", defaultPrefix = BindingConstants.LITERAL) 040 private String message; 041 042 /** 043 * The title for the modal dialog. 044 */ 045 @Parameter(value = "message:private-default-confirm-title", defaultPrefix = BindingConstants.LITERAL) 046 private String title; 047 048 /** 049 * If true, then the mixin does nothing (no attributes added, no module imported). 050 */ 051 @Parameter("false") 052 private boolean disabled; 053 054 @Environmental 055 private JavaScriptSupport javaScriptSupport; 056 057 /** 058 * The label for the ok button. 059 */ 060 @Parameter(value = "message:private-default-confirm-ok", defaultPrefix = BindingConstants.LITERAL) 061 private String ok; 062 063 /** 064 * The label for the ok button. 065 */ 066 @Parameter(value = "message:private-default-confirm-cancel", defaultPrefix = BindingConstants.LITERAL) 067 private String cancel; 068 069 void beginRender(MarkupWriter writer) 070 { 071 if (!disabled) 072 { 073 javaScriptSupport.require("t5/core/confirm-click"); 074 075 writer.attributes("data-confirm-title", title, 076 "data-confirm-message", message, 077 "data-confirm-label-ok", ok, 078 "data-confirm-label-cancel", cancel); 079 } 080 } 081}