001package com.hfg.javascript.ext;
002
003
004
005import com.hfg.javascript.JsObjMap;
006import com.hfg.util.StringUtil;
007
008//------------------------------------------------------------------------------
009/**
010 Definition for a field from an ExtJs model.
011 <div>
012 @author J. Alex Taylor, hairyfatguy.com
013 </div>
014 */
015//------------------------------------------------------------------------------
016// com.hfg Library
017//
018// This library is free software; you can redistribute it and/or
019// modify it under the terms of the GNU Lesser General Public
020// License as published by the Free Software Foundation; either
021// version 2.1 of the License, or (at your option) any later version.
022//
023// This library is distributed in the hope that it will be useful,
024// but WITHOUT ANY WARRANTY; without even the implied warranty of
025// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
026// Lesser General Public License for more details.
027//
028// You should have received a copy of the GNU Lesser General Public
029// License along with this library; if not, write to the Free Software
030// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
031//
032// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
033// jataylor@hairyfatguy.com
034//------------------------------------------------------------------------------
035
036public class ExtModelField
037{
038   private String mName;
039   private ExtFieldType mType;
040   private String mSortType;
041   private Boolean mAllowBlank;
042   private Boolean mAllowNull;
043   private String mDateFormat;
044
045   //--------------------------------------------------------------------------
046   public ExtModelField(String inName)
047   {
048      mName = inName;
049   }
050   
051   //--------------------------------------------------------------------------
052   public JsObjMap toJsObjMap()
053   {
054      JsObjMap js = new JsObjMap();
055
056      js.put("name", name());
057
058      if (getType() != null)
059      {
060         js.put("type", getType());
061      }
062
063      if (StringUtil.isSet(getSortType()))
064      {
065         js.put("sortType", getSortType());
066      }
067
068      if (mAllowBlank != null)
069      {
070         js.put("allowBlank", mAllowBlank);
071      }
072
073      if (mAllowNull != null)
074      {
075         js.put("allowNull", mAllowNull);
076      }
077
078      if (mDateFormat != null)
079      {
080         js.put("dateFormat", mDateFormat);
081      }
082
083      return js;
084   }
085   
086   //--------------------------------------------------------------------------
087   public String toJavascript()
088   {
089      return toJsObjMap().toJavascript();
090   }
091
092   //--------------------------------------------------------------------------
093   @Override
094   public String toString()
095   {
096      return toJavascript();
097   }
098
099   //--------------------------------------------------------------------------
100   public String name()
101   {
102      return mName;
103   }
104
105   
106   //--------------------------------------------------------------------------
107   public ExtModelField setType(ExtFieldType inValue)
108   {
109      mType = inValue;
110      return this;
111   }
112
113   //--------------------------------------------------------------------------
114   public ExtFieldType getType()
115   {
116      return mType;
117   }
118
119   
120   //--------------------------------------------------------------------------
121   public ExtModelField setSortType(String inValue)
122   {
123      mSortType = inValue;
124      return this;
125   }
126
127   //--------------------------------------------------------------------------
128   public String getSortType()
129   {
130      return mSortType;
131   }
132
133   
134   //--------------------------------------------------------------------------
135   public ExtModelField setDateFormat(String inValue)
136   {
137      mDateFormat = inValue;
138      return this;
139   }
140
141   //--------------------------------------------------------------------------
142   public String getDateFormat()
143   {
144      return mDateFormat;
145   }
146
147   
148   //--------------------------------------------------------------------------
149   public ExtModelField setAllowBlank(Boolean inValue)
150   {
151      mAllowBlank = inValue;
152      return this;
153   }
154
155   //--------------------------------------------------------------------------
156   public Boolean getAllowBlank()
157   {
158      return mAllowBlank;
159   }
160
161   
162   //--------------------------------------------------------------------------
163   public ExtModelField setAllowNull(Boolean inValue)
164   {
165      mAllowNull = inValue;
166      return this;
167   }
168
169   //--------------------------------------------------------------------------
170   public Boolean getAllowNull()
171   {
172      return mAllowNull;
173   }
174}