You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by co...@apache.org on 2004/01/29 17:36:17 UTC

cvs commit: cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel AbstractContainerWidget.java ContainerWidget.java

coliver     2004/01/29 08:36:17

  Modified:    src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2
                        Form.js ScriptableWidget.java
               src/blocks/woody/java/org/apache/cocoon/woody/formmodel
                        AbstractContainerWidget.java ContainerWidget.java
  Log:
  Added support to access widget properties in view and modified showForm() to use the form widget itself as the flow context
  
  Revision  Changes    Path
  1.2       +2 -5      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2/Form.js
  
  Index: Form.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2/Form.js,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Form.js	28 Jan 2004 18:31:59 -0000	1.1
  +++ Form.js	29 Jan 2004 16:36:17 -0000	1.2
  @@ -73,8 +73,6 @@
           this.binding = null;
           this.eventHandler = null;
           this.formWidget = new Widget(this.form);
  -        this.context = {};
  -        this.context.widget = this.formWidget;
           this.local = cocoon.createPageLocal();
       } finally {
           cocoon.releaseComponent(formMgr);
  @@ -111,11 +109,10 @@
   Form.prototype.showForm = function(uri, fun) {
       var FormContext = Packages.org.apache.cocoon.woody.FormContext;
       this.local.webContinuation = cocoon.createWebContinuation();
  -    this.context.form = this.formWidget;
       // this is needed by the WoodyTemplateTransformer:
  -    this.context["woody-form"] = this.formWidget.unwrap();
  +    this.formWidget["woody-form"] = this.formWidget.unwrap();
       cocoon.request.setAttribute("woody-form", this.form);
  -    var wk = cocoon.sendPageAndWait(uri, this.context, fun);
  +    var wk = cocoon.sendPageAndWait(uri, this.formWidget, fun);
       var formContext = 
           new FormContext(cocoon.request, this.form.getLocale());
       this.isValid = this.form.process(formContext);
  
  
  
  1.2       +39 -7     cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2/ScriptableWidget.java
  
  Index: ScriptableWidget.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/flow/javascript/v2/ScriptableWidget.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ScriptableWidget.java	28 Jan 2004 18:31:59 -0000	1.1
  +++ ScriptableWidget.java	29 Jan 2004 16:36:17 -0000	1.2
  @@ -53,6 +53,7 @@
   import org.apache.cocoon.woody.formmodel.BooleanField;
   import org.apache.cocoon.woody.formmodel.Field;
   import org.apache.cocoon.woody.formmodel.Form;
  +import org.apache.cocoon.woody.formmodel.ContainerWidget;
   import org.apache.cocoon.woody.formmodel.MultiValueField;
   import org.apache.cocoon.woody.formmodel.Output;
   import org.apache.cocoon.woody.formmodel.Repeater;
  @@ -74,6 +75,9 @@
   import org.mozilla.javascript.Undefined;
   import org.mozilla.javascript.Wrapper;
   import java.math.BigDecimal;
  +import java.util.List;
  +import java.util.LinkedList;
  +import java.util.Iterator;
   import java.util.Map;
   import java.util.HashMap;
   
  @@ -119,6 +123,13 @@
           return obj;
       }
   
  +    private void deleteWrapper(Widget w) {
  +        if (delegate instanceof Form) {
  +            Map widgetMap = (Map)super.get("__widgets__", this);
  +            widgetMap.remove(w);
  +        }
  +    }
  +
       private ScriptableWidget wrap(Widget w) {
           if (w == null) return null;
           if (delegate instanceof Form) {
  @@ -191,8 +202,30 @@
           return super.get(index, start);
       }
   
  -    public void delete(String id) {
  -        super.delete(id);
  +    public Object[] getAllIds() {
  +        Object[] result = super.getAllIds();
  +        return addWidgetIds(result);
  +    }
  +
  +    public Object[] getIds() {
  +        Object[] result = super.getIds();
  +        return addWidgetIds(result);
  +    }
  +
  +    private Object[] addWidgetIds(Object[] result) {
  +        if (delegate instanceof ContainerWidget) {
  +            Iterator iter = ((ContainerWidget)delegate).getChildren();
  +            List list = new LinkedList();
  +            for (int i = 0; i < result.length; i++) {
  +                list.add(result[i]);
  +            }
  +            while (iter.hasNext()) {
  +                Widget widget = (Widget)iter.next();
  +                list.add(widget.getId());
  +            }
  +            result = list.toArray();
  +        }
  +        return result;
       }
   
       public void delete(int index) {
  @@ -255,7 +288,6 @@
               Repeater repeater = (Repeater)delegate;
               return repeater.getSize();
           }
  -        return 0;
       }
   
       public void jsSet_value(Object value) throws JavaScriptException {
  @@ -491,12 +523,16 @@
                   }    
                   for (int i = len-1; i >= 0; --i) {
                       if (index[i]) {
  +                        Widget row = repeater.getRow(i);
  +                        formWidget.deleteWrapper(row);
                           repeater.removeRow(i);
                       }
                   }
               } else if (obj instanceof Number) {
                   int index = (int)Context.toNumber(obj);
                   if (index > 0 && index < repeater.getSize()) {
  +                    Widget row = repeater.getRow(index);
  +                    formWidget.deleteWrapper(row);
                       repeater.removeRow(index);
                   }
               } else {
  @@ -589,10 +625,6 @@
   
       public String jsFunction_toString() {
           return "[object Widget (" + jsFunction_getWidgetClass() + ")]";
  -    }
  -
  -    public static void install(Scriptable scope) throws Exception {
  -        defineClass(scope, ScriptableWidget.class);
       }
   
   }
  
  
  
  1.3       +6 -2      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AbstractContainerWidget.java
  
  Index: AbstractContainerWidget.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/AbstractContainerWidget.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractContainerWidget.java	29 Dec 2003 17:52:12 -0000	1.2
  +++ AbstractContainerWidget.java	29 Jan 2004 16:36:17 -0000	1.3
  @@ -51,7 +51,7 @@
   package org.apache.cocoon.woody.formmodel;
   
   import java.util.Locale;
  -
  +import java.util.Iterator;
   import org.apache.cocoon.woody.Constants;
   import org.apache.cocoon.woody.FormContext;
   import org.apache.cocoon.xml.AttributesImpl;
  @@ -84,6 +84,10 @@
   
       public Widget getWidget(String id) {
       	return widgets.getWidget(id);
  +    }
  +
  +    public Iterator getChildren() {
  +        return widgets.iterator();
       }
   
       public void readFromRequest(FormContext formContext) {
  
  
  
  1.5       +8 -2      cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/ContainerWidget.java
  
  Index: ContainerWidget.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/woody/java/org/apache/cocoon/woody/formmodel/ContainerWidget.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ContainerWidget.java	29 Dec 2003 17:52:12 -0000	1.4
  +++ ContainerWidget.java	29 Jan 2004 16:36:17 -0000	1.5
  @@ -49,7 +49,7 @@
   
   */
   package org.apache.cocoon.woody.formmodel;
  -
  +import java.util.Iterator;
   
   /**
    * Interface to be implemented by Widgets which contain other widgets.
  @@ -74,4 +74,10 @@
        * Returns null if there is no child with the given id.
        */
       public Widget getWidget(String id);
  +
  +    /**
  +     * Returns an iterator over the widgets this object contains
  +     */
  +    public Iterator getChildren();
  +
   }