click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r925582 - in /click/trunk/click/examples: src/org/apache/click/examples/control/ src/org/apache/click/examples/page/control/ webapp/WEB-INF/ webapp/control/
Date Sat, 20 Mar 2010 11:29:26 GMT
Author: sabob
Date: Sat Mar 20 11:29:26 2010
New Revision: 925582

URL: http://svn.apache.org/viewvc?rev=925582&view=rev
Log:
added disabled demo

Added:
    click/trunk/click/examples/src/org/apache/click/examples/page/control/DisabledDemo.java
    click/trunk/click/examples/webapp/control/disabled-demo.htm
    click/trunk/click/examples/webapp/control/disabled-demo.js
Modified:
    click/trunk/click/examples/src/org/apache/click/examples/control/InvestmentSelect.java
    click/trunk/click/examples/webapp/WEB-INF/menu.xml

Modified: click/trunk/click/examples/src/org/apache/click/examples/control/InvestmentSelect.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/control/InvestmentSelect.java?rev=925582&r1=925581&r2=925582&view=diff
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/control/InvestmentSelect.java
(original)
+++ click/trunk/click/examples/src/org/apache/click/examples/control/InvestmentSelect.java
Sat Mar 20 11:29:26 2010
@@ -59,6 +59,18 @@ public class InvestmentSelect extends Se
     }
 
     /**
+     * Create the Investment option Select control with the given field name
+     * and required status.
+     *
+     * @param name the Selection option field name
+     * @param required the field required status
+     */
+    public InvestmentSelect(String name, boolean required) {
+        super(name, required);
+        setOptionList(INVESTMENT_OPTIONS);
+    }
+
+    /**
      * Create the Investment option Select control with the given field name.
      *
      * @param name the Selection option field name

Added: click/trunk/click/examples/src/org/apache/click/examples/page/control/DisabledDemo.java
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/src/org/apache/click/examples/page/control/DisabledDemo.java?rev=925582&view=auto
==============================================================================
--- click/trunk/click/examples/src/org/apache/click/examples/page/control/DisabledDemo.java
(added)
+++ click/trunk/click/examples/src/org/apache/click/examples/page/control/DisabledDemo.java
Sat Mar 20 11:29:26 2010
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.click.examples.page.control;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Resource;
+import org.apache.cayenne.access.DataContext;
+import org.apache.click.ActionListener;
+import org.apache.click.Control;
+import org.apache.click.control.Checkbox;
+import org.apache.click.control.Form;
+import org.apache.click.control.Radio;
+import org.apache.click.control.RadioGroup;
+import org.apache.click.control.Submit;
+import org.apache.click.control.TextField;
+import org.apache.click.element.JsImport;
+import org.apache.click.element.JsScript;
+import org.apache.click.examples.control.InvestmentSelect;
+import org.apache.click.examples.domain.Customer;
+import org.apache.click.examples.page.BorderPage;
+import org.apache.click.examples.service.CustomerService;
+import org.springframework.stereotype.Component;
+
+/**
+ * Demonstrates disabled field behavior.
+ *
+ * Note the following:
+ *
+ * - disabled fields are not processed and validated
+ * - disabled field values are not copied to domain objects
+ * - disabled fields that are enabled through JavaScript, will be enabled
+ */
+@Component
+public class DisabledDemo extends BorderPage {
+
+    private static final long serialVersionUID = 1L;
+
+    private Form form = new Form("form");
+
+    private TextField nameField = new TextField("name", true);
+
+    private InvestmentSelect investmentSelect = new InvestmentSelect("investments", true);
+
+    // This checkbox will enable/disable the form fields
+    private Checkbox toggle = new Checkbox("toggle", "Enable Fields");
+
+    private Submit submit = new Submit("save");
+
+    @Resource(name="customerService")
+    private CustomerService customerService;
+
+    @Override
+    public void onInit() {
+        super.onInit();
+
+        final Customer customer = loadCustomer();
+
+        // Disable fields
+        nameField.setDisabled(true);
+        form.add(nameField);
+
+        investmentSelect.setDisabled(true);
+        form.add(investmentSelect);
+
+        form.add(toggle);
+
+        form.add(submit);
+        submit.setActionListener(new ActionListener() {
+
+            public boolean onAction(Control source) {
+
+                if (form.isValid()) {
+                    // Copy field values to customer
+                    form.copyTo(customer);
+                    DataContext.getThreadObjectContext().commitChanges();
+                }
+                return true;
+            }
+        });
+
+        addControl(form);
+
+        // Populate field values from customer
+        form.copyFrom(customer);
+
+        addModel("customer", customer);
+    }
+
+    public Customer loadCustomer() {
+        boolean ascending = true;
+        return customerService.getCustomersSortedBy(Customer.DATE_JOINED_PROPERTY,
+            ascending).get(0);
+    }
+
+    @Override
+    public List getHeadElements() {
+        if (headElements == null) {
+            headElements = super.getHeadElements();
+            headElements.add(new JsImport("/assets/js/jquery-1.3.2.js"));
+
+            Map jsModel = new HashMap();
+            headElements.add(new JsScript("/control/disabled-demo.js", jsModel));
+        }
+        return headElements;
+    }
+}

Modified: click/trunk/click/examples/webapp/WEB-INF/menu.xml
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/WEB-INF/menu.xml?rev=925582&r1=925581&r2=925582&view=diff
==============================================================================
--- click/trunk/click/examples/webapp/WEB-INF/menu.xml (original)
+++ click/trunk/click/examples/webapp/WEB-INF/menu.xml Sat Mar 20 11:29:26 2010
@@ -86,6 +86,8 @@
     <menu label="PickList" path="control/pick-list-demo.htm"/>
     <menu label="RegexField" path="control/regex-demo.htm"/>
     <menu label="RichTextArea" path="control/email-form.htm"/>
+    <menu separator="true"/>
+    <menu label="Disabled behavior" path="control/disabled-demo.htm"/>
   </menu>
   
   <menu label=" Forms" path="#" imageSrc="/assets/images/form.png">

Added: click/trunk/click/examples/webapp/control/disabled-demo.htm
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/control/disabled-demo.htm?rev=925582&view=auto
==============================================================================
--- click/trunk/click/examples/webapp/control/disabled-demo.htm (added)
+++ click/trunk/click/examples/webapp/control/disabled-demo.htm Sat Mar 20 11:29:26 2010
@@ -0,0 +1,30 @@
+<style type="text/css">
+    td.fields {
+        width: 8em;
+    }
+</style>
+
+This example demonstrates the following features:
+<ul>
+    <li>
+        Disabled fields are not processed or validated
+    </li>
+    <li>
+        Disabled field values are not copied to domain objects
+    </li>
+    <li>
+        Disabled fields are automatically enabled if the field has an
+        incoming request parameter, indicating that the field was enabled
+        on the client using JavaScript.
+    </li>
+</ul>
+
+$form
+
+<div style="border: 1px solid black; padding: 10px;width: 300px">
+    <b><u>Customer details</u></b>
+    <p/>
+    <b>Name:</b> $customer.name
+    <br/>
+    <b>Investments: </b> $customer.investments
+</div>
\ No newline at end of file

Added: click/trunk/click/examples/webapp/control/disabled-demo.js
URL: http://svn.apache.org/viewvc/click/trunk/click/examples/webapp/control/disabled-demo.js?rev=925582&view=auto
==============================================================================
--- click/trunk/click/examples/webapp/control/disabled-demo.js (added)
+++ click/trunk/click/examples/webapp/control/disabled-demo.js Sat Mar 20 11:29:26 2010
@@ -0,0 +1,26 @@
+$(document).ready(function() {
+    $('#form_toggle').click(function() {
+        if($(this).is(':checked')) {
+            toggle(false);
+            $("label[for='form_toggle']").text('Disable Fields');
+        } else {
+            toggle(true);
+            $("label[for='form_toggle']").text('Enable Fields');
+        }
+    });
+
+    function toggle(disable) {
+        var nameFld = $('#form_name');
+        var investmentSelect = $('#form_investments');
+
+        if (disable) {
+            // set the disabled attribute and 'disabled' CSS class
+            nameFld.attr('disabled', 'disabled').attr('class', 'disabled');
+            investmentSelect.attr('disabled', 'disabled').attr('class', 'disabled');
+        } else {
+            // remove the disabled attribute and 'disabled' CSS class
+            nameFld.removeAttr('disabled').removeAttr('class');
+            investmentSelect.removeAttr('disabled').removeAttr('class');
+        }
+    }
+})



Mime
View raw message