Author: erwan
Date: Mon Mar 14 11:15:24 2011
New Revision: 1081333

URL: http://svn.apache.org/viewvc?rev=1081333&view=rev
Log:
Adding a masked input capability to the date fields, use mask=Y and the field 
type will be taken for it. jQuery pPlugin is from 
http://digitalbush.com/projects/masked-input-plugin/ and under a MIT license

Added:
    
ofbiz/trunk/framework/images/webapp/images/jquery/plugins/jquery.maskedinput-1.2.2.min.js
   (with props)
Modified:
    ofbiz/trunk/framework/common/widget/CommonScreens.xml
    ofbiz/trunk/framework/example/widget/example/FormWidgetExampleForms.xml
    ofbiz/trunk/framework/widget/dtd/widget-form.xsd
    
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
    ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
    ofbiz/trunk/framework/widget/templates/csvFormMacroLibrary.ftl
    ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl
    ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl

Modified: ofbiz/trunk/framework/common/widget/CommonScreens.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/widget/CommonScreens.xml?rev=1081333&r1=1081332&r2=1081333&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/widget/CommonScreens.xml (original)
+++ ofbiz/trunk/framework/common/widget/CommonScreens.xml Mon Mar 14 11:15:24 
2011
@@ -109,6 +109,7 @@ under the License.
                     <!-- jQuery part -->
                 <set field="layoutSettings.javaScripts[+0]" 
value="/images/jquery/plugins/asmselect/jquery.asmselect-1.0.4a-beta.js" 
global="true"/>
                 <set field="layoutSettings.javaScripts[+0]" 
value="/images/jquery/plugins/datetimepicker/jquery-ui-timepicker-addon-0.9.3.min.js"
 global="true"/>
+                <set field="layoutSettings.javaScripts[+0]" 
value="/images/jquery/plugins/jquery.maskedinput-1.2.2.min.js" global="true"/>
                 <set field="layoutSettings.javaScripts[+0]" 
value="/images/jquery/ui/js/jquery-ui-1.8.6.custom.min.js" global="true"/>
                 <set field="layoutSettings.javaScripts[+0]" 
value="/images/jquery/plugins/jeditable/jquery.jeditable.js" global="true"/>
                 <set field="layoutSettings.javaScripts[+0]" 
value="/images/jquery/plugins/validate/jquery.validate.min.js" global="true"/>

Modified: 
ofbiz/trunk/framework/example/widget/example/FormWidgetExampleForms.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/example/widget/example/FormWidgetExampleForms.xml?rev=1081333&r1=1081332&r2=1081333&view=diff
==============================================================================
--- ofbiz/trunk/framework/example/widget/example/FormWidgetExampleForms.xml 
(original)
+++ ofbiz/trunk/framework/example/widget/example/FormWidgetExampleForms.xml Mon 
Mar 14 11:15:24 2011
@@ -31,7 +31,7 @@ under the License.
         <field name="field1"
                title="${uiLabelMap.ExampleDateField1Title}"
                tooltip="${uiLabelMap.ExampleToDo}">
-            <date-time/>
+            <date-time mask="Y"/>
         </field>
         <!-- ***************** -->
         <!-- ***   field9  *** -->

Added: 
ofbiz/trunk/framework/images/webapp/images/jquery/plugins/jquery.maskedinput-1.2.2.min.js
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/images/webapp/images/jquery/plugins/jquery.maskedinput-1.2.2.min.js?rev=1081333&view=auto
==============================================================================
--- 
ofbiz/trunk/framework/images/webapp/images/jquery/plugins/jquery.maskedinput-1.2.2.min.js
 (added)
+++ 
ofbiz/trunk/framework/images/webapp/images/jquery/plugins/jquery.maskedinput-1.2.2.min.js
 Mon Mar 14 11:15:24 2011
@@ -0,0 +1,7 @@
+/*
+       Masked Input plugin for jQuery
+       Copyright (c) 2007-2009 Josh Bush (digitalbush.com)
+       Licensed under the MIT license 
(http://digitalbush.com/projects/masked-input-plugin/#license) 
+       Version: 1.2.2 (03/09/2009 22:39:06)
+*/
+(function(a){var c=(a.browser.msie?"paste":"input")+".mask";var 
b=(window.orientation!=undefined);a.mask={definitions:{"9":"[0-9]",a:"[A-Za-z]","*":"[A-Za-z0-9]"}};a.fn.extend({caret:function(e,f){if(this.length==0){return}if(typeof
 e=="number"){f=(typeof f=="number")?f:e;return 
this.each(function(){if(this.setSelectionRange){this.focus();this.setSelectionRange(e,f)}else{if(this.createTextRange){var
 
g=this.createTextRange();g.collapse(true);g.moveEnd("character",f);g.moveStart("character",e);g.select()}}})}else{if(this[0].setSelectionRange){e=this[0].selectionStart;f=this[0].selectionEnd}else{if(document.selection&&document.selection.createRange){var
 
d=document.selection.createRange();e=0-d.duplicate().moveStart("character",-100000);f=e+d.text.length}}return{begin:e,end:f}}},unmask:function(){return
 this.trigger("unmask")},mask:function(j,d){if(!j&&this.length>0){var 
f=a(this[0]);var g=f.data("tests");return 
a.map(f.data("buffer"),function(l,m){return g[m]?l:null}).join("")}
 d=a.extend({placeholder:"_",completed:null},d);var k=a.mask.definitions;var 
g=[];var e=j.length;var i=null;var 
h=j.length;a.each(j.split(""),function(m,l){if(l=="?"){h--;e=m}else{if(k[l]){g.push(new
 RegExp(k[l]));if(i==null){i=g.length-1}}else{g.push(null)}}});return 
this.each(function(){var r=a(this);var 
m=a.map(j.split(""),function(x,y){if(x!="?"){return k[x]?d.placeholder:x}});var 
n=false;var q=r.val();r.data("buffer",m).data("tests",g);function 
v(x){while(++x<=h&&!g[x]){}return x}function t(x){while(!g[x]&&--x>=0){}for(var 
y=x;y<h;y++){if(g[y]){m[y]=d.placeholder;var 
z=v(y);if(z<h&&g[y].test(m[z])){m[y]=m[z]}else{break}}}s();r.caret(Math.max(i,x))}function
 u(y){for(var A=y,z=d.placeholder;A<h;A++){if(g[A]){var B=v(A);var 
x=m[A];m[A]=z;if(B<h&&g[B].test(x)){z=x}else{break}}}}function l(y){var 
x=a(this).caret();var 
z=y.keyCode;n=(z<16||(z>16&&z<32)||(z>32&&z<41));if((x.begin-x.end)!=0&&(!n||z==8||z==46)){w(x.begin,x.end)}if(z==8||z==46||(b&&z==127)){t(x.begin+(z==46?0:-1))
 ;return false}else{if(z==27){r.val(q);r.caret(0,p());return false}}}function 
o(B){if(n){n=false;return(B.keyCode==8)?false:null}B=B||window.event;var 
C=B.charCode||B.keyCode||B.which;var 
z=a(this).caret();if(B.ctrlKey||B.altKey||B.metaKey){return 
true}else{if((C>=32&&C<=125)||C>186){var x=v(z.begin-1);if(x<h){var 
A=String.fromCharCode(C);if(g[x].test(A)){u(x);m[x]=A;s();var 
y=v(x);a(this).caret(y);if(d.completed&&y==h){d.completed.call(r)}}}}}return 
false}function w(x,y){for(var 
z=x;z<y&&z<h;z++){if(g[z]){m[z]=d.placeholder}}}function s(){return 
r.val(m.join("")).val()}function p(y){var z=r.val();var C=-1;for(var 
B=0,x=0;B<h;B++){if(g[B]){m[B]=d.placeholder;while(x++<z.length){var 
A=z.charAt(x-1);if(g[B].test(A)){m[B]=A;C=B;break}}if(x>z.length){break}}else{if(m[B]==z[x]&&B!=e){x++;C=B}}}if(!y&&C+1<e){r.val("");w(0,h)}else{if(y||C+1>=e){s();if(!y){r.val(r.val().substring(0,C+1))}}}return(e?B:i)}if(!r.attr("readonly")){r.one("unmask",function(){r.unbind(".mask").removeData("b
 uffer").removeData("tests")}).bind("focus.mask",function(){q=r.val();var 
x=p();s();setTimeout(function(){if(x==j.length){r.caret(0,x)}else{r.caret(x)}},0)}).bind("blur.mask",function(){p();if(r.val()!=q){r.change()}}).bind("keydown.mask",l).bind("keypress.mask",o).bind(c,function(){setTimeout(function(){r.caret(p(true))},0)})}p()})}})})(jQuery);
\ No newline at end of file

Propchange: 
ofbiz/trunk/framework/images/webapp/images/jquery/plugins/jquery.maskedinput-1.2.2.min.js
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ofbiz/trunk/framework/images/webapp/images/jquery/plugins/jquery.maskedinput-1.2.2.min.js
------------------------------------------------------------------------------
    svn:keywords = "Date Rev Author URL Id"

Propchange: 
ofbiz/trunk/framework/images/webapp/images/jquery/plugins/jquery.maskedinput-1.2.2.min.js
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: ofbiz/trunk/framework/widget/dtd/widget-form.xsd
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/dtd/widget-form.xsd?rev=1081333&r1=1081332&r2=1081333&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/dtd/widget-form.xsd (original)
+++ ofbiz/trunk/framework/widget/dtd/widget-form.xsd Mon Mar 14 11:15:24 2011
@@ -656,6 +656,15 @@ under the License.
                 </xs:restriction>
             </xs:simpleType>
         </xs:attribute>
+        <xs:attribute name="mask" default="N">
+            <xs:annotation><xs:documentation>Will use the type value if set to 
yes, add a masked input</xs:documentation></xs:annotation>
+            <xs:simpleType>
+                <xs:restriction base="xs:token">
+                    <xs:enumeration value="Y"/>
+                    <xs:enumeration value="N"/>
+                </xs:restriction>
+            </xs:simpleType>
+        </xs:attribute>
     </xs:attributeGroup>
     <xs:element name="display" substitutionGroup="AllFields">
         <xs:complexType>

Modified: 
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java?rev=1081333&r1=1081332&r2=1081333&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java 
(original)
+++ 
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/MacroFormRenderer.java 
Mon Mar 14 11:15:24 2011
@@ -474,6 +474,7 @@ public class MacroFormRenderer implement
         String className = "";
         String alert = "false";
         String name = "";
+        String formattedMask = "";
         String event = modelFormField.getEvent();
         String action = modelFormField.getAction(context);
         if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) {
@@ -610,6 +611,16 @@ public class MacroFormRenderer implement
                 ampmName = UtilHttp.makeCompositeParam(paramName, "ampm");
             }
         }
+        String mask = dateTimeField.getMask();
+        if ("Y".equals(mask)) {
+            if ("date".equals(dateTimeField.getType())) {
+                formattedMask = "9999-99-99";
+            } else if ("time".equals(dateTimeField.getType())) {
+                formattedMask = "99:99:99";
+            } else if ("timestamp".equals(dateTimeField.getType())) {
+                formattedMask = "9999-99-99 99:99:99.999";
+            }
+        }
         StringWriter sr = new StringWriter();
         sr.append("<@renderDateTimeField ");
         sr.append("name=\"");
@@ -676,6 +687,8 @@ public class MacroFormRenderer implement
         sr.append(compositeType);
         sr.append("\" formName=\"");
         sr.append(formName);
+        sr.append("\" mask=\"");
+        sr.append(formattedMask);
         sr.append("\" />");
         executeMacro(writer, sr.toString());
         this.addAsterisks(writer, context, modelFormField);

Modified: 
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java?rev=1081333&r1=1081332&r2=1081333&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java 
(original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelFormField.java 
Mon Mar 14 11:15:24 2011
@@ -3074,6 +3074,7 @@ public class ModelFormField {
         protected String inputMethod;
         protected String clock;
         protected String step;
+        protected String mask;
 
         protected DateTimeField() {
             super();
@@ -3093,6 +3094,7 @@ public class ModelFormField {
             type = element.getAttribute("type");
             inputMethod = element.getAttribute("input-method");
             clock = element.getAttribute("clock");
+            mask = element.getAttribute("mask");
             if (UtilValidate.isNotEmpty(element.getAttribute("step"))) {
                 this.setStep(element.getAttribute("step"));
             }
@@ -3126,6 +3128,10 @@ public class ModelFormField {
             return this.clock;
         }
 
+        public String getMask() {
+            return this.mask;
+        }
+
         public String getStep() {
             return this.step;
         }

Modified: ofbiz/trunk/framework/widget/templates/csvFormMacroLibrary.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/csvFormMacroLibrary.ftl?rev=1081333&r1=1081332&r2=1081333&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/templates/csvFormMacroLibrary.ftl (original)
+++ ofbiz/trunk/framework/widget/templates/csvFormMacroLibrary.ftl Mon Mar 14 
11:15:24 2011
@@ -28,7 +28,7 @@ under the License.
 
 <#macro renderTextareaField name className alert cols rows id readonly value 
visualEditorEnable language buttons><@renderField value /></#macro>
 
-<#macro renderDateTimeField name className alert title value size maxlength 
step timeValues id dateType shortDateInput timeDropdownParamName 
defaultDateTimeString localizedIconTitle timeDropdown timeHourName classString 
hour1 hour2 timeMinutesName minutes isTwelveHour ampmName amSelected pmSelected 
compositeType formName><@renderField value /></#macro>
+<#macro renderDateTimeField name className alert title value size maxlength 
step timeValues id dateType shortDateInput timeDropdownParamName 
defaultDateTimeString localizedIconTitle timeDropdown timeHourName classString 
hour1 hour2 timeMinutesName minutes isTwelveHour ampmName amSelected pmSelected 
compositeType formName mask><@renderField value /></#macro>
 
 <#macro renderDropDownField name className alert id multiple formName 
otherFieldName event action size firstInList currentValue explicitDescription 
allowEmpty options fieldName otherFieldName otherValue otherFieldSize 
dDFCurrent ajaxEnabled noCurrentSelectedKey ajaxOptions frequency minChars 
choices autoSelect partialSearch partialChars ignoreCase fullSearch>
 <#if currentValue?has_content && firstInList?has_content>

Modified: ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl?rev=1081333&r1=1081332&r2=1081333&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl (original)
+++ ofbiz/trunk/framework/widget/templates/foFormMacroLibrary.ftl Mon Mar 14 
11:15:24 2011
@@ -52,7 +52,7 @@ under the License.
 
 <#macro renderTextareaField name className alert cols rows id readonly value 
visualEditorEnable language buttons><@makeBlock className value /></#macro>
 
-<#macro renderDateTimeField name className alert title value size maxlength 
step timeValues id event action dateType shortDateInput timeDropdownParamName 
defaultDateTimeString localizedIconTitle timeDropdown timeHourName classString 
hour1 hour2 timeMinutesName minutes isTwelveHour ampmName amSelected pmSelected 
compositeType formName><@makeBlock className value /></#macro>
+<#macro renderDateTimeField name className alert title value size maxlength 
step timeValues id event action dateType shortDateInput timeDropdownParamName 
defaultDateTimeString localizedIconTitle timeDropdown timeHourName classString 
hour1 hour2 timeMinutesName minutes isTwelveHour ampmName amSelected pmSelected 
compositeType formName mask><@makeBlock className value /></#macro>
 
 <#macro renderDropDownField name className alert id multiple formName 
otherFieldName event action size firstInList currentValue explicitDescription 
allowEmpty options fieldName otherFieldName otherValue otherFieldSize 
dDFCurrent ajaxEnabled noCurrentSelectedKey ajaxOptions frequency minChars 
choices autoSelect partialSearch partialChars ignoreCase fullSearch>
 <#if currentValue?has_content && firstInList?has_content>

Modified: ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl?rev=1081333&r1=1081332&r2=1081333&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl (original)
+++ ofbiz/trunk/framework/widget/templates/htmlFormMacroLibrary.ftl Mon Mar 14 
11:15:24 2011
@@ -95,8 +95,13 @@ under the License.
     </#if>
 </#macro>
 
-<#macro renderDateTimeField name className alert title value size maxlength id 
dateType shortDateInput timeDropdownParamName defaultDateTimeString 
localizedIconTitle timeDropdown timeHourName classString hour1 hour2 
timeMinutesName minutes isTwelveHour ampmName amSelected pmSelected 
compositeType formName event="" action="" step="" timeValues="">
+<#macro renderDateTimeField name className alert title value size maxlength id 
dateType shortDateInput timeDropdownParamName defaultDateTimeString 
localizedIconTitle timeDropdown timeHourName classString hour1 hour2 
timeMinutesName minutes isTwelveHour ampmName amSelected pmSelected 
compositeType formName mask="" event="" action="" step="" timeValues="">
   <span class="view-calendar">
+      <#if mask?has_content>
+          <script type="text/javascript">
+            jQuery(function($){jQuery("#${id}").mask("${mask}");});
+          </script>
+      </#if>
       <input type="text" name="${name}" <#if event?has_content && 
action?has_content> ${event}="${action}"</#if> <@renderClass className alert 
/><#rt/>
         <#if title?has_content> title="${title}"</#if>
         <#if value?has_content> value="${value}"</#if>


Reply via email to