| 1 |  |   | 
  | 2 |  |  package net.wotonomy.web; | 
  | 3 |  |   | 
  | 4 |  |  import net.wotonomy.foundation.NSArray; | 
  | 5 |  |  import net.wotonomy.foundation.NSDictionary; | 
  | 6 |  |  import net.wotonomy.foundation.NSMutableArray; | 
  | 7 |  |   | 
  | 8 |  |  public class WOCheckBox extends WOInput { | 
  | 9 |  |   | 
  | 10 | 0 |      protected boolean checked = false; | 
  | 11 |  |   | 
  | 12 |  |      public WOCheckBox() { | 
  | 13 | 0 |          super(); | 
  | 14 | 0 |      } | 
  | 15 |  |   | 
  | 16 |  |      public WOCheckBox(String aName, NSDictionary assocs, WOElement template) { | 
  | 17 | 0 |          super(aName, assocs, template); | 
  | 18 | 0 |      } | 
  | 19 |  |   | 
  | 20 |  |      protected String inputType() { | 
  | 21 | 0 |          return "CHECKBOX"; | 
  | 22 |  |      } | 
  | 23 |  |   | 
  | 24 |  |      protected Object value(WOContext c) { | 
  | 25 | 0 |          Object val = null; | 
  | 26 | 0 |          boolean checked = false; | 
  | 27 | 0 |          if (associations.objectForKey("value") != null) { | 
  | 28 | 0 |              val = valueForProperty("value", c.component()); | 
  | 29 | 0 |              Object sel = valueForProperty("selection", c.component()); | 
  | 30 | 0 |              if (sel != null && val != null && sel.equals(val)) | 
  | 31 | 0 |                  checked = true; | 
  | 32 |  |          } | 
  | 33 | 0 |          if (val == null) { | 
  | 34 | 0 |              val = c.elementID(); | 
  | 35 |  |          } | 
  | 36 | 0 |          return val; | 
  | 37 |  |      } | 
  | 38 |  |   | 
  | 39 |  |      protected void appendExtras(WOResponse r, WOContext c) { | 
  | 40 | 0 |          checked |= booleanForProperty("checked", c.component()); | 
  | 41 | 0 |          if (checked) | 
  | 42 | 0 |              r.appendContentString(" CHECKED"); | 
  | 43 | 0 |      } | 
  | 44 |  |   | 
  | 45 |  |      protected NSMutableArray additionalAttributes() { | 
  | 46 | 0 |          NSMutableArray a = super.additionalAttributes(); | 
  | 47 | 0 |          a.addObject("checked"); | 
  | 48 | 0 |          a.addObject("selection"); | 
  | 49 | 0 |          return a; | 
  | 50 |  |      } | 
  | 51 |  |   | 
  | 52 |  |      public void appendToResponse(WOResponse r, WOContext c) { | 
  | 53 | 0 |          checked = false; | 
  | 54 | 0 |          super.appendToResponse(r, c); | 
  | 55 | 0 |      } | 
  | 56 |  |   | 
  | 57 |  |      public void takeValuesFromRequest(WORequest r, WOContext c) { | 
  | 58 | 0 |          if (disabled(c)) | 
  | 59 | 0 |              return; | 
  | 60 | 0 |          NSArray values = r.formValuesForKey(inputName(c)); | 
  | 61 | 0 |          Object val = valueForProperty("value", c.component()); | 
  | 62 | 0 |          if (val == null) | 
  | 63 | 0 |              val = c.elementID(); | 
  | 64 | 0 |          java.util.Enumeration enumerator = values.objectEnumerator(); | 
  | 65 | 0 |          checked = false; | 
  | 66 | 0 |          while (enumerator.hasMoreElements()) { | 
  | 67 | 0 |              Object nextval = enumerator.nextElement(); | 
  | 68 | 0 |              if (nextval.equals(val)) | 
  | 69 | 0 |                  checked = true; | 
  | 70 | 0 |          } | 
  | 71 | 0 |          if (associations.objectForKey("value") != null && associations.objectForKey("selection") != null) { | 
  | 72 | 0 |              if (checked) | 
  | 73 | 0 |                  setValueForProperty("selection", val, c.component()); | 
  | 74 | 0 |              else if (valueForProperty("selection", c.component()) != null) | 
  | 75 | 0 |                  setValueForProperty("selection", null, c.component()); | 
  | 76 |  |          } | 
  | 77 | 0 |          if (associations.objectForKey("checked") != null) | 
  | 78 | 0 |              setValueForProperty("checked", checked ? Boolean.TRUE : Boolean.FALSE, c.component()); | 
  | 79 | 0 |      } | 
  | 80 |  |   | 
  | 81 |  |  } |