summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.web/src/main/java/net/wotonomy/web/WOImageButton.java
blob: ebb9ae14ca6cfae19b1a1b2c5e16e78c1c142bbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

package net.wotonomy.web;

import net.wotonomy.foundation.NSArray;
import net.wotonomy.foundation.NSDictionary;

/**
 * WOImageButton renders a dynamically generated IMG tag or an INPUT tag,
 * depending on whether the element is inside a WOForm (in which case an INPUT
 * of type IMAGE is generated) or not (in which case the equivalent of a
 * WOActiveImage)
 *
 * Bindings are:
 * <UL>
 * <LI>src: A static URL for the image source.</li>
 * <li>data: A NSData object with the image content. Must be used with
 * mimeType.</li>
 * <li>mimeType: The MIME type for the image data. Can be used with filename or
 * data bindings.</li>
 * <li>filename: The path to a file containing an image.</li>
 * <li>framework: The framework where the image should be retrieved from (used
 * in conjunction with filename).</li>
 *
 * @author ezamudio@nasoft.com
 * @author $Author: cgruber $
 * @version $Revision: 905 $
 */
public class WOImageButton extends WOImage {

	protected WOImageButton() {
		super();
	}

	public WOImageButton(String aName, NSDictionary aMap, WOElement template) {
		super(aName, aMap, template);
	}

	public String buttonName(WOContext c) {
		String x = (String) valueForProperty("name", c.component());
		if (x != null)
			return x;
		return c.elementID();
	}

	public void appendToResponse(WOResponse r, WOContext c) {
		if (c.isInForm()) {
			// generate an INPUT
			r.appendContentString("<INPUT TYPE=IMAGE NAME=\"");
			r.appendContentString(buttonName(c));
			r.appendContentString("\" SRC=\"");
			r.appendContentString(sourceURL(c));
			r.appendContentString("\"");
			r.appendContentString(additionalHTMLProperties(c.component(), new NSArray(
					new Object[] { "name", "action", "src", "filename", "framework", "data", "mimeType" })));
			r.appendContentString(">");
		} else {
			// generate a WOActiveImage
			new WOActiveImage(name, associations, rootElement).appendToResponse(r, c);
		}
	}

}