Commit b0defd2f authored by Bas Lijnse's avatar Bas Lijnse

Cleaned up some of the leftover hardcoded editors

parent e1a25869
......@@ -90,10 +90,6 @@ instance toString Note
instance html Note
instance == Note
//* Source code
:: CleanCode = CleanCode !String
instance toString CleanCode
//* Money (ISO4217 currency codes are used)
:: EUR = EUR !Int //Euros (amount in cents)
:: USD = USD !Int //Dollars (amount in cents)
......@@ -147,13 +143,13 @@ paddedDateTimeString :: DateTime -> String
instance toString Document
instance == Document
derive JSONEncode EmailAddress, PhoneNumber, URL, Note, CleanCode, EUR, USD, Date, Time, DateTime, Document
derive JSONDecode EmailAddress, PhoneNumber, URL, Note, CleanCode, EUR, USD, Date, Time, DateTime, Document
derive gDefault EmailAddress, PhoneNumber, URL, Note, CleanCode, EUR, USD, Date, Time, DateTime, Document
derive gEq EmailAddress, PhoneNumber, URL, Note, CleanCode, EUR, USD, Date, Time, DateTime, Document
derive JSONEncode EmailAddress, PhoneNumber, URL, Note, EUR, USD, Date, Time, DateTime, Document
derive JSONDecode EmailAddress, PhoneNumber, URL, Note, EUR, USD, Date, Time, DateTime, Document
derive gDefault EmailAddress, PhoneNumber, URL, Note, EUR, USD, Date, Time, DateTime, Document
derive gEq EmailAddress, PhoneNumber, URL, Note, EUR, USD, Date, Time, DateTime, Document
derive gText EmailAddress, PhoneNumber, URL, Note, CleanCode, EUR, USD, Date, Time, DateTime, Document
derive gEditor EmailAddress, PhoneNumber, URL, Note, CleanCode, EUR, USD, Date, Time, DateTime, Document
derive gText EmailAddress, PhoneNumber, URL, Note, EUR, USD, Date, Time, DateTime, Document
derive gEditor EmailAddress, PhoneNumber, URL, Note, EUR, USD, Date, Time, DateTime, Document
//* Common exceptions used by API tasks
......
......@@ -162,24 +162,8 @@ instance == Note
where
(==) (Note x) (Note y) = x == y
//* Source code
JSONEncode{|CleanCode|} _ (CleanCode txt) = [JSONString txt]
JSONDecode{|CleanCode|} _ [JSONString txt:c] = (Just (CleanCode txt),c)
JSONDecode{|CleanCode|} _ c = (Nothing,c)
gText{|CleanCode|} _ val = [maybe "" toString val]
derive gEditor CleanCode
derive gDefault CleanCode
derive gEq CleanCode
instance toString CleanCode
where
toString (CleanCode s) = s
//* Money (ISO4217 currency codes are used)
gText{|EUR|} _ val = [maybe "" toString val]
gEditor{|EUR|} = whenDisabled
......@@ -466,7 +450,10 @@ gText{|Document|} _ (Just val)
| otherwise = [val.Document.name]
gText{|Document|} _ Nothing = [""]
gEditor {|Document|} = documentField 'DM'.newMap
gEditor {|Document|} = liftEditor toView fromView (documentField 'DM'.newMap)
where
toView {Document|documentId,contentUrl,name,mime,size} = (documentId,contentUrl,name,mime,size)
fromView (documentId,contentUrl,name,mime,size) = {Document|documentId=documentId,contentUrl=contentUrl,name=name,mime=mime,size=size}
derive JSONEncode Document
derive JSONDecode Document
......@@ -531,24 +518,15 @@ gDefault{|Scale|} = {Scale|min=1,cur=3,max=5}
//* Progress bars
gText{|Progress|} _ val = [maybe "" (\{Progress|description} -> description) val]
gEditor{|Progress|} = {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
gEditor{|Progress|} = liftEditor toView fromView (progressBar 'DM'.newMap)
where
genUI dp val vst=:{VSt|taskId}
# attr = 'DM'.unions [textAttr (text val),valueAttr (toJSON (value val))]
= (Ok (uia UIProgressBar attr,newFieldMask), vst)
toView {Progress|progress,description} = (value,Just description)
where
text {Progress|description} = description
value {Progress|progress=ProgressRatio ratio}
| ratio < 0.0 = ProgressRatio 0.0
| ratio > 1.0 = ProgressRatio 1.0
= ProgressRatio ratio
value {Progress|progress} = progress
onEdit dp e val mask ust = (Ok (NoChange,mask),val,ust)
value = case progress of
ProgressUndetermined = Nothing
(ProgressRatio r) = Just (entier (100.0 * r))
onRefresh dp new old mask vst
= (Ok (if (old === new) NoChange (ChangeUI [SetAttribute "value" (encodeUI (value new))] []),mask),new,vst)
fromView _ = defaultValue
derive gDefault Progress
......@@ -563,16 +541,10 @@ derive gEditor ProgressAmount
gText{|HtmlInclude|} _ (Just (HtmlInclude location)) = ["<External html: " + location + ">"]
gText{|HtmlInclude|} _ _ = [""]
gEditor{|HtmlInclude|} = {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
gEditor{|HtmlInclude|} = liftEditor toView fromView (htmlView 'DM'.newMap)
where
genUI dp (HtmlInclude path) vst
# attr = 'DM'.fromList [("value",JSONString (toString (IframeTag [SrcAttr path] [])))]
= (Ok (uia UIHtmlView attr,newFieldMask),vst)
onEdit dp e val mask ust = (Ok (NoChange,mask),val,ust)
onRefresh dp val=:(HtmlInclude new) (HtmlInclude old) mask vst
= (Ok (if (old === new) NoChange (ChangeUI [SetAttribute "value" (encodeUI new)] []),mask),val,vst)
toView (HtmlInclude src) = IframeTag [SrcAttr src] []
fromView _ = defaultValue
derive gDefault HtmlInclude
......@@ -903,12 +875,10 @@ derive gDefault Icon
derive gEq Icon
derive gText Icon
gEditor{|Icon|} = {Editor|genUI=genUI,onEdit=onEdit,onRefresh=onRefresh}
gEditor{|Icon|} = liftEditor toView fromView (icon 'DM'.newMap)
where
genUI _ (Icon icon) vst = (Ok (uia UIIcon (iconClsAttr ("icon-"+++icon)),newFieldMask), vst)
onEdit dp e val mask ust = (Ok (NoChange,mask),val,ust)
onRefresh _ (Icon new) (Icon old) mask vst
= (Ok (if (old === new) NoChange (ChangeUI [SetAttribute "iconCls" (encodeUI ("icon-"+++new))] []),mask),Icon new, vst)
toView (Icon name) = ("icon-"+++name,Nothing)
fromView _ = defaultValue
// Generic instances for common library types
derive JSONEncode Either, MaybeError, HtmlTag, HtmlAttr
......
......@@ -3,11 +3,12 @@ definition module iTasks.UI.Editor.Builtin
* This module provides a set of editors that are standard available
* in the client-side UI framework.
*/
import iTasks.UI.Editor
from iTasks.UI.Editor import :: Editor
from iTasks.UI.Definition import :: UIAttributes
from Data.Maybe import :: Maybe
from Data.Map import :: Map
from Text.HTML import :: HtmlTag
from iTasks.API.Core.Types import :: Document
from iTasks.UI.Definition import :: UIAttributes
from Text.JSON import :: JSONNode
// ## Form components ##
// UITextField, UITextArea, UIPasswordField, UIIntegerField, UIDecimalField, UIDocumentField
......@@ -18,12 +19,12 @@ textArea :: UIAttributes -> Editor String
passwordField :: UIAttributes -> Editor String
integerField :: UIAttributes -> Editor Int
decimalField :: UIAttributes -> Editor Real
documentField :: UIAttributes -> Editor Document
documentField :: UIAttributes -> Editor (!String,!String,!String,!String,!Int)
checkBox :: UIAttributes -> Editor Bool
slider :: UIAttributes -> Editor Int
button :: UIAttributes -> Editor Bool
label :: UIAttributes -> Editor String
icon :: UIAttributes -> Editor (String,Maybe String)
icon :: UIAttributes -> Editor (!String,!Maybe String)
// ## Display components ##
// UITextView, UIHtmlView, UIProgressBar
......@@ -39,6 +40,7 @@ choiceList :: UIAttributes -> Editor ([String], [Int])
grid :: UIAttributes -> Editor (ChoiceGrid, [Int])
tree :: UIAttributes -> Editor ([ChoiceNode], [Int])
//Convenient types for describing the values of grids and trees
:: ChoiceGrid =
{ header :: [String]
, rows :: [[HtmlTag]]
......
......@@ -20,7 +20,7 @@ integerField attr = fieldComponent attr toJSON UIIntegerField
decimalField :: UIAttributes -> Editor Real
decimalField attr = fieldComponent attr toJSON UIDecimalField
documentField :: UIAttributes -> Editor Document
documentField :: UIAttributes -> Editor (!String,!String,!String,!String,!Int)
documentField attr = fieldComponent attr toJSON UIDocumentField
checkBox :: UIAttributes -> Editor Bool
......@@ -35,7 +35,7 @@ button attr = fieldComponent attr toJSON UIButton
label :: UIAttributes -> Editor String
label attr = viewComponent (\text -> 'DM'.union attr (textAttr text)) UILabel
icon :: UIAttributes -> Editor (String,Maybe String)
icon :: UIAttributes -> Editor (!String,!Maybe String)
icon attr = viewComponent (\(iconCls,tooltip) -> 'DM'.unions [iconClsAttr iconCls,maybe 'DM'.newMap tooltipAttr tooltip,attr]) UIIcon
textView :: UIAttributes -> Editor String
......
......@@ -43,7 +43,7 @@ where
testDocumentField = itest "Document field" "Check if the decimal field is ok" "You should be able to edit" tut
where
tut :: Task Document
tut :: Task (!String,!String,!String,!String,!Int)
tut = testEditor (documentField 'DM'.newMap) defaultValue Enter
testCheckbox = itest "Checkbox" "Check if the checkbox is ok" "You should be able to edit" tut
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment