git-svn-id: svn://svn.dsv.su.se/scipro/scipro/trunk@332 73ecded7-942e-4092-bab0-0e58ef0ee984
This commit is contained in:
parent
e8d6a10592
commit
fabe99c8e9
src/main/java/se/su/dsv/scipro/util
@ -0,0 +1,33 @@
|
||||
package se.su.dsv.scipro.util;
|
||||
|
||||
import org.apache.wicket.behavior.AttributeAppender;
|
||||
import org.apache.wicket.model.Model;
|
||||
|
||||
/**
|
||||
* Add this to your component if you want to display a javascript-confirmation dialog before
|
||||
* performing some action.
|
||||
*
|
||||
* Note: add as the last thing you add to your component.
|
||||
*
|
||||
* @author Dan Kjellman <dan-kjel@dsv.su.se>
|
||||
*
|
||||
*/
|
||||
public class JavascriptEventConfirmation extends AttributeAppender {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public JavascriptEventConfirmation(String event, String msg){
|
||||
super(event, true, new Model<String>(msg), " ");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String newValue(final String currentValue, final String replacementValue) {
|
||||
String prefix = "var conf = confirm('" + replacementValue + "'); " +
|
||||
"if (!conf) return false; ";
|
||||
String result = prefix;
|
||||
if (currentValue != null) {
|
||||
result = prefix + currentValue;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
27
src/main/java/se/su/dsv/scipro/util/SelectOption.java
Normal file
27
src/main/java/se/su/dsv/scipro/util/SelectOption.java
Normal file
@ -0,0 +1,27 @@
|
||||
package se.su.dsv.scipro.util;
|
||||
|
||||
import org.apache.wicket.IClusterable;
|
||||
|
||||
/**
|
||||
* Use this for an option in a dropdownchoice.
|
||||
*
|
||||
* @author Dan Kjellman <dan-kjel@dsv.su.se>
|
||||
*
|
||||
* @param <T> - Type of the value-object
|
||||
*/
|
||||
public class SelectOption<T> implements IClusterable {
|
||||
|
||||
private static final long serialVersionUID = -8100206655504746602L;
|
||||
|
||||
public String text;
|
||||
public T value;
|
||||
|
||||
public SelectOption(String text, T value){
|
||||
this.text = text;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return text;
|
||||
}
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package se.su.dsv.scipro.util;
|
||||
|
||||
import org.apache.wicket.Component;
|
||||
import org.apache.wicket.behavior.AttributeAppender;
|
||||
import org.apache.wicket.model.Model;
|
||||
import org.odlabs.wiquery.core.commons.WiQueryResourceManager;
|
||||
import org.odlabs.wiquery.core.effects.Effect;
|
||||
import org.odlabs.wiquery.core.effects.EffectBehavior;
|
||||
import org.odlabs.wiquery.core.effects.EffectSpeed;
|
||||
import org.odlabs.wiquery.core.effects.fading.FadeIn;
|
||||
import org.odlabs.wiquery.core.effects.fading.FadeOut;
|
||||
import org.odlabs.wiquery.core.effects.sliding.SlideDown;
|
||||
import org.odlabs.wiquery.core.effects.sliding.SlideUp;
|
||||
import org.odlabs.wiquery.core.javascript.JsStatement;
|
||||
import org.odlabs.wiquery.ui.effects.CoreEffectJavaScriptResourceReference;
|
||||
|
||||
/**
|
||||
* Helper for adding wiquery core effects to a component.
|
||||
*
|
||||
* Usage for an ajax reqeust (remember to set outputmarkupid to true on the component) :
|
||||
* target.addComponent(WiQueryCoreEffectsHelper.fadeIn( THE COMPONENT , EffectSpeed.FAST/SLOW));
|
||||
* @author Dan Kjellman <dan-kjel@dsv.su.se>
|
||||
*
|
||||
*/
|
||||
|
||||
public class WiQueryCoreEffectsHelper {
|
||||
|
||||
/**
|
||||
* Make the component fade in
|
||||
*
|
||||
* @param comp the component
|
||||
* @param speed effectspeed
|
||||
* @return the component
|
||||
*/
|
||||
public static Component fadeIn(Component comp, EffectSpeed speed){
|
||||
FadeIn fi = new FadeIn(speed);
|
||||
WiQueryCoreEffectsHelper.putCssClass(comp);
|
||||
comp.add(WiQueryCoreEffectsHelper.getEffectBehavior(fi));
|
||||
return comp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the component fade out (the component will when effect is over have display none)
|
||||
*
|
||||
* @param comp the component
|
||||
* @param speed effectspeed
|
||||
* @return the component
|
||||
*/
|
||||
public static Component fadeOut(Component comp, EffectSpeed speed){
|
||||
FadeOut fi = new FadeOut(speed);
|
||||
comp.add(WiQueryCoreEffectsHelper.getEffectBehavior(fi));
|
||||
return comp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the component slide down
|
||||
*
|
||||
* @param comp the component
|
||||
* @param speed effectspeed
|
||||
* @return the component
|
||||
*/
|
||||
public static Component slideDown(Component comp, EffectSpeed speed){
|
||||
SlideDown sd = new SlideDown(speed);
|
||||
WiQueryCoreEffectsHelper.putCssClass(comp);
|
||||
comp.add(WiQueryCoreEffectsHelper.getEffectBehavior(sd));
|
||||
return comp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the component slide up (the component will when effect is over have display none)
|
||||
*
|
||||
* @param comp the component
|
||||
* @param speed effectspeed
|
||||
* @return the component
|
||||
*/
|
||||
public static Component slideUp(Component comp, EffectSpeed speed){
|
||||
Effect e = new SlideUp(speed);
|
||||
comp.add(WiQueryCoreEffectsHelper.getEffectBehavior(e));
|
||||
return comp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Effect that hides a component by sliding it up. Returns the javascript to append to the ajaxrequesttarget
|
||||
* target.appendJavascript(WiQueryCoreEffectsHelper.slideUpJs(THE COMPONENT, effectspeed));
|
||||
* @param comp
|
||||
* @param speed
|
||||
* @return
|
||||
*/
|
||||
public static String slideUpJs(Component comp, EffectSpeed speed){
|
||||
return new StringBuffer(new JsStatement().$(comp).chain(new SlideUp(speed)).render(true)).toString();
|
||||
}
|
||||
|
||||
private static EffectBehavior getEffectBehavior(Effect e){
|
||||
return new EffectBehavior(e){
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public void contribute(WiQueryResourceManager wiQueryResourceManager){
|
||||
wiQueryResourceManager.addJavaScriptResource(CoreEffectJavaScriptResourceReference.get());
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
private static Component putCssClass(Component c){
|
||||
c.add(new AttributeAppender("style", new Model<String>("display:none;"), " "));
|
||||
return c;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user