/**
 * Copyright (C) 2010 Asterios Raptis
 *
 * 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 de.alpharogroup.wicket.components.examples.toastr;

import org.apache.wicket.Application;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.extensions.ajax.markup.html.IndicatingAjaxButton;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import de.alpharogroup.locale.ResourceBundleKey;
import de.alpharogroup.wicket.base.util.resource.ResourceModelFactory;
import de.alpharogroup.wicket.behaviors.pnotify.PnotifyJsGenerator;
import de.alpharogroup.wicket.behaviors.pnotify.PnotifyJsReference;
import de.alpharogroup.wicket.behaviors.pnotify.PnotifySettings;
import de.alpharogroup.wicket.behaviors.toastr.Position;
import de.alpharogroup.wicket.behaviors.toastr.ToastJsGenerator;
import de.alpharogroup.wicket.behaviors.toastr.ToastrSettings;
import de.alpharogroup.wicket.components.buttons.ButtonPanel;

public class NotificationExamplesPanel extends Panel
{

	/**
	 * The serialVersionUID
	 */
	private static final long serialVersionUID = 1L;

	public NotificationExamplesPanel(String id, IModel<?> model)
	{
		super(id, model);
		IModel<String> labelModel = ResourceModelFactory
			.newResourceModel(
				ResourceBundleKey.builder().key("button.toastr.label")
					.defaultValue("Show toastr notice.").build(), this);
		Form<Object> form = new Form<Object>("form");
		add(form);
		form.add(new ButtonPanel("toastrButtonPanel", labelModel, form)
		{

			/**
			 * The serialVersionUID
			 */
			private static final long serialVersionUID = 1L;

			@Override
			protected Button newButton(String id)
			{
				IndicatingAjaxButton indicatingAjaxButton = new IndicatingAjaxButton(id, getForm())
				{
					/**
					 * The serialVersionUID.
					 */
					private static final long serialVersionUID = 1L;

					@Override
					protected void onSubmit(final AjaxRequestTarget target, final Form<?> form)
					{
						target.add(form);
						ToastJsGenerator jsGenerator = new ToastJsGenerator();

						ToastrSettings settings = new ToastrSettings();
						settings.getPositionClass().setValue(Position.TOP_RIGHT);
						settings.getNotificationContent().setValue("This is a notification");
						String js = jsGenerator.generateToastrJs(settings);
						target.prependJavaScript(js);
					}

					@Override
					protected void onError(AjaxRequestTarget target, Form<?> form)
					{
					}
				};
				indicatingAjaxButton.add(new AttributeAppender("class", Model
					.of(" btn btn-primary")));
				return indicatingAjaxButton;
			}
		});
		IModel<String> pnotifyLabelModel = ResourceModelFactory.newResourceModel(ResourceBundleKey
			.builder().key("button.label").defaultValue("Show pnotify notice.").build(), this);
		form.add(new ButtonPanel("pnotifyButtonPanel", pnotifyLabelModel, form)
		{

			/**
			 * The serialVersionUID
			 */
			private static final long serialVersionUID = 1L;

			@Override
			protected Button newButton(String id)
			{
				IndicatingAjaxButton indicatingAjaxButton = new IndicatingAjaxButton(id, getForm())
				{
					/**
					 * The serialVersionUID.
					 */
					private static final long serialVersionUID = 1L;

					@Override
					protected void onSubmit(final AjaxRequestTarget target, final Form<?> form)
					{
						target.add(form);
						PnotifySettings pnotifySettings = new PnotifySettings();
						pnotifySettings.getTitle().setValue("Test title");
						pnotifySettings.getText().setValue("a text");
						PnotifyJsGenerator pnotifyJsGenerator = new PnotifyJsGenerator(
							pnotifySettings);
						String js = pnotifyJsGenerator.generateJs(pnotifySettings);
						target.prependJavaScript(js);
					}

					@Override
					protected void onError(AjaxRequestTarget target, Form<?> form)
					{
					}
				};
				indicatingAjaxButton.add(new AttributeAppender("class", Model
					.of(" btn btn-primary")));
				return indicatingAjaxButton;
			}
		});
	}

	@Override
	public void renderHead(IHeaderResponse response)
	{
		super.renderHead(response);
		response.render(JavaScriptHeaderItem.forReference(Application.get()
			.getJavaScriptLibrarySettings().getJQueryReference()));
		response
			.render(JavaScriptHeaderItem.forReference(ToastJsGenerator.TOASTR_PLUGIN_REFERENCE));
		response.render(JavaScriptHeaderItem.forReference(PnotifyJsReference.INSTANCE));
	}

}

@@ -1650,32 +1650,104 @@
 astJsGenerator;%0A
+import de.alpharogroup.wicket.behaviors.toastr.ToastrResourceReference;%0A
 import de.alphar
@@ -1785,32 +1785,32 @@
 ToastrSettings;%0A
-
 import de.alphar
@@ -2980,18 +2980,23 @@
 s = 
-new Toastr
+jsGenerator.get
 Sett
@@ -3185,25 +3185,11 @@
 rate
-ToastrJs(settings
+Js(
 );%0A%09
@@ -4528,31 +4528,16 @@
 erateJs(
-pnotifySettings
 );%0A%09%09%09%09%09
@@ -5113,40 +5113,32 @@
 oast
-JsGenerator.TOASTR_PLUGIN_REFERE
+rResourceReference.INSTA
 NCE)

update to new settings.