// Copyright 2013 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package org.apache.tapestry5.corelib.mixins;

import org.apache.tapestry5.BindingConstants;
import org.apache.tapestry5.MarkupWriter;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.MixinAfter;
import org.apache.tapestry5.annotations.Parameter;

/**
 * A mixin that can be placed on a clickable component, such as {@link org.apache.tapestry5.corelib.components.LinkSubmit},
 * and will raise a confirmation dialog when the element is clicked.
 * <p/>
 * Due to conflicts between jQuery (as used by Bootstrap's JavaScript library) and Prototype, this mixin does not operate
 * when the {@linkplain org.apache.tapestry5.SymbolConstants#JAVASCRIPT_INFRASTRUCTURE_PROVIDER JavaScript infrastructure provider}
 * is "prototype".
 *
 * @tapestrydoc
 * @since 5.4
 */
@MixinAfter
@Import(module = "t5/core/confirm-click")
public class Confirm
{
    /**
     * The message to present to the user in the body of the modal dialog.
     */
    @Parameter(value = "message:private-default-confirm-message", defaultPrefix = BindingConstants.LITERAL)
    private String message;

    /**
     * The title for the modal dialog.
     */
    @Parameter(value = "message:private-default-confirm-title", defaultPrefix = BindingConstants.LITERAL)
    private String title;

    void beginRender(MarkupWriter writer)
    {
        writer.attributes("data-confirm-title", title,
                "data-confirm-message", message);
    }
}

@@ -1,56 +1,4 @@
-// Copyright 2013 The Apache Software Foundation%0A//%0A
 // L
@@ -723,22 +723,29 @@
 tations.
-Import
+Environmental
 ;%0Aimport
@@ -840,16 +840,83 @@
 rameter;
+%0Aimport org.apache.tapestry5.services.javascript.JavaScriptSupport;
 %0A%0A/**%0A *
@@ -1440,50 +1440,8 @@
 ter%0A
-@Import(module = %22t5/core/confirm-click%22)%0A
 publ
@@ -1883,52 +1883,381 @@
     
-void beginRender(MarkupWriter writer)%0A    %7B%0A
+/**%0A     * If true, then the mixin does nothing (no attributes added, no module imported).%0A     */%0A    @Parameter(%22false%22)%0A    private boolean disabled;%0A%0A    @Environmental%0A    private JavaScriptSupport javaScriptSupport;%0A%0A    void beginRender(MarkupWriter writer)%0A    %7B%0A        if (!disabled)%0A        %7B%0A            javaScriptSupport.require(%22t5/core/confirm-click%22);%0A%0A    
     
@@ -2323,16 +2323,20 @@
         
+    
 %22data-co
@@ -2361,16 +2361,26 @@
 ssage);%0A
+        %7D%0A
     %7D%0A%7D%0A

Add a disabled parameter to the Confirm mixin