package org.orienteer.core.widget.command;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.Model;
import org.orienteer.core.component.command.AjaxCommand;
import org.orienteer.core.widget.AbstractWidget;

/**
 * Command to make widget fullscreen and back 
 * @param <T> the type of an entity to which this command can be applied
 */
public class FullScreenCommand<T> extends AjaxCommand<T> {
	
	private boolean expanded = false;
	public FullScreenCommand(String commandId) {
		super(commandId, Model.of());
		setAutoNotify(false);
	}
	
	@Override
	protected void onConfigure() {
		super.onConfigure();
		getLink().get("label").setDefaultModelObject(getLocalizer().getString(expanded?"command.fullscreen.min":"command.fullscreen.max", null));
	}

	@Override
	public void onClick(AjaxRequestTarget target) {
		expanded=!expanded;
		configure();
		target.add(this);
		AbstractWidget<?> widget = findParent(AbstractWidget.class);
		target.appendJavaScript("$('body').toggleClass('noscroll'); $('#"+widget.getMarkupId()+"').toggleClass('fullscreen');");
	}

}

@@ -1079,10 +1079,98 @@
 %22);%0A%09%7D%0A%0A
+%09@Override%0A%09protected void onDetach() %7B%0A%09%09this.expanded = false;%0A%09%09super.onDetach();%0A%09%7D%0A
 %7D%0A

Set field expanded to false on detach