package org.sagebionetworks.web.client.help;

/*
 * #%L
 * GwtBootstrap3
 * %%
 * Copyright (C) 2013 GwtBootstrap3
 * %%
 * 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.
 * #L%
 */

import org.gwtbootstrap3.client.ui.Icon;
import org.gwtbootstrap3.client.ui.Popover;
import org.gwtbootstrap3.client.ui.constants.IconType;
import org.gwtbootstrap3.client.ui.constants.Placement;
import org.gwtbootstrap3.client.ui.constants.Trigger;
import org.gwtbootstrap3.client.ui.html.Div;
import org.gwtbootstrap3.client.ui.html.Text;

import com.google.gwt.user.client.ui.Widget;

/**
 * Context-sensitive help button/modal combination.
 * 
Recipe for Context-Sensitive Help dialog
<b:Modal title="Help" closable="true" fade="true" dataBackdrop="STATIC" dataKeyboard="true" b:id="discussionForum">
  <b:ModalBody>
    <bh:Text><ui:text from='{help.discussionForum}'/></bh:Text>
  </b:ModalBody>
  <b:ModalFooter>
  	<b:Anchor href="https://docs.synapse.org/discussionForum" target="_blank">
  		<button class="btn btn-primary margin-right-10">Learn More...</button>
  	</b:Anchor>
    <b:Button dataDismiss="MODAL">Close</b:Button>
  </b:ModalFooter>
</b:Modal>
<b:Button dataTarget="#discussionForum" dataToggle="MODAL" icon="QUESTION" type="PRIMARY" size="EXTRA_SMALL" />

 */
public class HelpButton extends Div {
	
    private final Icon helpButton = new Icon(IconType.QUESTION_CIRCLE);
    private final Popover popover = new Popover(helpButton);
    
    public HelpButton() {
    	addStyleName("displayInline margin-left-5 margin-right-5");
    	popover.setTrigger(Trigger.CLICK);
    	popover.setIsHtml(true);
    	helpButton.addStyleName("imageButton synapse-blue");
    	add(helpButton);
    }
    
    public void setHref(String href) {
    	popover.setContent("<a href=\""+href+"\" target=\"_blank\"><button class=\"btn btn-primary right\">Learn More</button></a>");
    }
    
    public void setPlacement(Placement placement) {
    	popover.setPlacement(placement);
    }
    
    @Override
    public void add(final Widget w) {
    	// user should specify content
        if (w instanceof Text) {
        	popover.setTitle(((Text)w).getText());
        } else {
            super.add(w);
        }
    }


}

@@ -1135,641 +1135,345 @@
 %0A * 
-%0ARecipe for Context-Sensitive Help dialog%0A%3Cb:Modal title=%22Help%22 closable=%22true%22 fade=%22true%22 dataBackdrop=%22STATIC%22 dataKeyboard=%22true%22 b:id=%22discussionForum%22%3E%0A  %3Cb:ModalBody%3E%0A    %3Cbh:Text%3E%3Cui:text from='%7Bhelp.discussionForum%7D'/%3E%3C/bh:Text%3E%0A  %3C/b:ModalBody%3E%0A  %3Cb:ModalFooter%3E%0A  %09%3Cb:Anchor href=%22https://docs.synapse.org/discussionForum%22 target=%22_blank%22%3E%0A  %09%09%3Cbutton class=%22btn btn-primary margin-right-10%22%3ELearn More...%3C/button%3E%0A  %09%3C/b:Anchor%3E%0A    %3Cb:Button dataDismiss=%22MODAL%22%3EClose%3C/b:Button%3E%0A  %3C/b:ModalFooter%3E%0A%3C/b:Modal%3E%0A%3Cb:Button dataTarget=%22#discussionForum%22 dataToggle=%22MODAL%22 icon=%22QUESTION%22 type=%22PRIMARY%22 size=%22EXTRA_SMALL%22 /%3E
+https://sagebionetworks.jira.com/wiki/pages/createpage.action?spaceKey=SWC&fromPageId=6357131%0A *  %0A%0AImport:%0Axmlns:h=%22urn:import:org.sagebionetworks.web.client.help%22%0A%0AUse:%0A%3Ch:HelpButton href=%22https://docs.synapse.org/discussionForum%22 placement=%22RIGHT%22%3E%0A         %3Cbh:Text%3E%3Cui:text from='%7Bhelp.discussionForum%7D'/%3E%3C/bh:Text%3E%0A%3C/h:HelpButton%3E 
 %0A%0A *

edit comment