Permalink
Browse files

Updated to scala 2.7.7 and Lift 1.1-M7. Also add String and Local fie…

…lds to deal with missing functionality
  • Loading branch information...
1 parent f9cfcfa commit 499945fc13f09774310a924d8d6917f84202012c Tim committed Nov 4, 2009
View
@@ -1,8 +1,8 @@
-#Project properties
-#Mon Jul 27 17:50:24 CDT 2009
-project.organization=com.eltimn.scamongo
+#Project Properties
+#Tue Nov 03 08:35:36 CST 2009
project.name=scamongo
-sbt.version=0.5.4
+project.organization=com.eltimn.scamongo
+sbt.version=0.5.6
+scala.version=2.7.7
project.version=0.1
-scala.version=2.7.6
project.initialize=false
@@ -18,12 +18,13 @@ package com.eltimn.scamongo
import scala.xml.{Node, NodeSeq, Text}
+import net.liftweb.common.{Box, Empty, Failure, Full}
import net.liftweb.http.{S}
import net.liftweb.http.js.JE.Str
import net.liftweb.json.JsonAST.JObject
import net.liftweb.json.JsonParser
import net.liftweb.record.{Field, Record}
-import net.liftweb.util.{Box, Empty, Failure, FieldError, Full, Log}
+import net.liftweb.util.{FieldError, Log}
import com.mongodb._
import com.mongodb.util.{JSON, JSONParseException}
@@ -22,11 +22,11 @@ import java.util.regex.Pattern
import scala.collection.jcl.Conversions._
import scala.collection.mutable.ListBuffer
+import net.liftweb.common.{Box, Empty, Full}
import net.liftweb.json.Formats
import net.liftweb.json.JsonAST.JObject
import net.liftweb.record.{MetaRecord, Record}
import net.liftweb.record.field._
-import net.liftweb.util.{Box, Empty, Full}
import com.mongodb._
import com.mongodb.util.JSON
@@ -16,7 +16,7 @@ package com.eltimn.scamongo
* and limitations under the License.
*/
-import net.liftweb.util.{Box, Full}
+import net.liftweb.common.{Box, Full}
import net.liftweb.record.{MetaRecord, Record}
import net.liftweb.record.field.StringField
@@ -16,9 +16,9 @@ package com.eltimn.scamongo.field
* and limitations under the License.
*/
+import net.liftweb.common.{Box, Empty, Failure, Full}
import net.liftweb.http.js.JE.Str
import net.liftweb.record.{Field, Record}
-import net.liftweb.util.{Box, Empty, Failure, Full}
import com.mongodb.{BasicDBObject, BasicDBObjectBuilder, DBObject, DBRef, ObjectId}
import com.mongodb.util.JSON
@@ -16,11 +16,11 @@ package com.eltimn.scamongo.field
* and limitations under the License.
*/
+import net.liftweb.common.{Box, Empty, Failure, Full}
import net.liftweb.http.js.JE.Str
import net.liftweb.json.JsonAST.JObject
import net.liftweb.json.JsonParser
import net.liftweb.record.{Field, Record}
-import net.liftweb.util.{Box, Empty, Failure, Full}
class JObjectField[OwnerType <: Record[OwnerType]](rec: OwnerType) extends Field[JObject, OwnerType] {
@@ -0,0 +1,65 @@
+package com.eltimn.scamongo.field
+
+/*
+ * Copyright 2009 Tim Nelson
+ *
+ * Licensed 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.
+ */
+
+import _root_.scala.xml._
+import _root_.net.liftweb.util._
+import _root_.net.liftweb.common._
+import _root_.net.liftweb.http.{S, SHtml}
+import _root_.java.util.{Locale}
+import S._
+import Helpers._
+
+import net.liftweb.record.{Field, Record}
+
+object LocaleField {
+ lazy val localeList = Locale.getAvailableLocales.toList.
+ sort(_.getDisplayName < _.getDisplayName).
+ map(lo => (lo.toString, lo.getDisplayName))
+}
+
+class LocaleField[OwnerType <: Record[OwnerType]](rec: OwnerType) extends StringField(rec, 16) {
+
+ override def defaultValue = Locale.getDefault.toString
+
+ def isAsLocale: Locale = Locale.getAvailableLocales.filter(_.toString == value).toList match {
+ case Nil => Locale.getDefault
+ case x :: xs => x
+ }
+
+ private def elem = SHtml.select(LocaleField.localeList,
+ Full(value), set) % ("tabindex" -> tabIndex.toString)
+
+ override def toForm = {
+ var el = elem
+
+ uniqueFieldId match {
+ case Full(id) =>
+ <div id={id+"_holder"}><div><label for={id+"_field"}>{displayName}</label></div>{el % ("id" -> (id+"_field"))}<lift:msg id={id}/></div>
+ case _ => <div>{el}</div>
+ }
+ }
+
+ override def asXHtml: NodeSeq = {
+ var el = elem
+
+ uniqueFieldId match {
+ case Full(id) => el % ("id" -> (id+"_field"))
+ case _ => el
+ }
+ }
+}
@@ -20,10 +20,10 @@ import java.util.Date
import scala.collection.jcl.Conversions._
+import net.liftweb.common.{Box, Empty, Failure, Full}
import net.liftweb.json.JsonAST.JObject
import net.liftweb.http.js.JE.Str
import net.liftweb.record.{Field, Record}
-import net.liftweb.util.{Box, Empty, Failure, Full}
import com.mongodb._
import com.mongodb.util.JSON
@@ -16,9 +16,9 @@ package com.eltimn.scamongo.field
* and limitations under the License.
*/
+import net.liftweb.common.{Box, Empty, Failure, Full}
import net.liftweb.http.js.JE.Str
import net.liftweb.record.{Field, Record}
-import net.liftweb.util.{Box, Empty, Failure, Full}
import com.mongodb.{ObjectId, DBRef}
@@ -0,0 +1,136 @@
+package com.eltimn.scamongo.field
+
+/*
+ * Copyright 2009 Tim Nelson
+ *
+ * Licensed 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.
+ */
+
+import scala.xml._
+import net.liftweb.util._
+import net.liftweb.common._
+import net.liftweb.http.{S}
+import net.liftweb.http.js._
+import _root_.java.util.regex._
+import S._
+import Helpers._
+import JE._
+
+import net.liftweb.record.{Field, Record}
+
+/**
+ * A Field containing String content.
+ */
+class StringField[OwnerType <: Record[OwnerType]](rec: OwnerType, maxLength: Int) extends Field[String, OwnerType] {
+
+ def this(rec: OwnerType, maxLength: Int, value: String) = {
+ this(rec, maxLength)
+ set(value)
+ }
+
+ def this(rec: OwnerType, value: String) = {
+ this(rec, 100)
+ set(value)
+ }
+
+ def owner = rec
+
+ def setFromAny(in: Any): Box[String] = {
+ in match {
+ case seq: Seq[_] if !seq.isEmpty => seq.map(setFromAny)(0)
+ case (s: String) :: _ => Full(set(s))
+ case null => Full(set(null))
+ case s: String => Full(set(s))
+ case Some(s: String) => Full(set(s))
+ case Full(s: String) => Full(set(s))
+ case None | Empty | Failure(_, _, _) => Full(set(null))
+ case o => Full(this.set(o.toString))
+ }
+ }
+
+ def setFromString(s: String): Box[String] = Full(set(s))
+
+ private def elem = S.fmapFunc(SFuncHolder(this.setFromAny(_))) {
+ funcName =>
+ <input type="text" maxlength={maxLength.toString}
+ name={funcName}
+ value={value match {case null => "" case s => s.toString}}
+ tabindex={tabIndex toString}/>
+ }
+
+ def toForm = {
+ uniqueFieldId match {
+ case Full(id) =>
+ <div id={id+"_holder"}><div><label for={id+"_field"}>{displayName}</label></div>{elem % ("id" -> (id+"_field"))}<lift:msg id={id}/></div>
+ case _ => <div>{elem}</div>
+ }
+
+ }
+
+ def asXHtml: NodeSeq = {
+ var el = elem
+
+ uniqueFieldId match {
+ case Full(id) => el % ("id" -> (id+"_field"))
+ case _ => el
+ }
+ }
+
+
+ def defaultValue = ""
+
+ /**
+ * A validation helper. Make sure the string is at least a particular
+ * length and generate a validation issue if not
+ */
+ def valMinLen(len: Int, msg: => String)(value: String): Box[Node] =
+ if ((value eq null) || value.length < len) Full(Text(msg))
+ else Empty
+
+ /**
+ * A validation helper. Make sure the string is no more than a particular
+ * length and generate a validation issue if not
+ */
+ def valMaxLen(len: Int, msg: => String)(value: String): Box[Node] =
+ if ((value ne null) && value.length > len) Full(Text(msg))
+ else Empty
+
+ // use maxLength
+ def valMaxLen(msg: => String)(value: String): Box[Node] = valMaxLen(maxLength, msg)(value)
+
+ /**
+ * Make sure the field matches a regular expression
+ */
+ def valRegex(pat: Pattern, msg: => String)(value: String): Box[Node] = pat.matcher(value).matches match {
+ case true => Empty
+ case false => Full(Text(msg))
+ }
+
+ final def toUpper(in: String): String = in match {
+ case null => null
+ case s => s.toUpperCase
+ }
+
+ final def trim(in: String): String = in match {
+ case null => null
+ case s => s.trim
+ }
+
+ final def notNull(in: String): String = in match {
+ case null => ""
+ case s => s
+ }
+
+ def asJs = Str(value)
+
+}
@@ -21,11 +21,11 @@ import java.util.regex.Pattern
import scala.collection.mutable.ListBuffer
+import net.liftweb.common.{Box, Full}
import net.liftweb.json.DefaultFormats
import net.liftweb.json.JsonDSL._
import net.liftweb.json.JsonAST.JObject
-import net.liftweb.record.field._
-import net.liftweb.util.{Box, Full}
+import net.liftweb.record.field.{StringField => LStringField, LocaleField => LLocaleField, _}
import org.specs.Specification
import org.specs.runner.{Runner, JUnit}

0 comments on commit 499945f

Please sign in to comment.