Commit 4a56b3ff authored by Bas Lijnse's avatar Bas Lijnse

Started creating a convenient interface to the builtin editors.

parent a7d30163
......@@ -48,6 +48,12 @@ itasks.itwc_edit_string = {
});
},
onAttributeChange: function(name,value) {
var me = this;
if(name == 'value') {
if(me.domEl !== document.activeElement) { //Don't update the focused element...
me.domEl.value = (value === null) ? '' : value;
}
}
}
};
itasks.itwc_edit_note = {
......@@ -140,9 +146,12 @@ itasks.itwc_edit_checkbox = {
me.doEditEvent(me.taskId,me.editorId,value);
});
},
setValue: function(value) {
this.domEl.checked = value;
}
onAttributeChange: function(name,value) {
var me = this;
if(name == 'value') {
me.domEl.checked = value;
}
}
};
itasks.itwc_edit_slider = {
......
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
textField :: Editor String
integerField :: Editor Int
decimalField :: Editor Real
checkBox :: Editor Bool
textView :: Editor String
implementation module iTasks.UI.Editor.Builtin
import iTasks.UI.Definition, iTasks.UI.Editor
import qualified Data.Map as DM
import StdMisc
textField :: Editor String
textField = simpleComponent UIEditString
integerField :: Editor Int
integerField = simpleComponent UIEditInt
decimalField :: Editor Real
decimalField = simpleComponent UIEditDecimal
checkBox :: Editor Bool
checkBox = simpleComponent UIEditCheckbox
textView :: Editor String
textView = simpleComponent UIViewString
//Simple components for which simply knowing the UI type is sufficient
simpleComponent type = {Editor|genUI=genUI,updUI=updUI,onEdit=onEdit}
where
genUI dp val mask vst=:{VSt|taskId,optional}
= (Ok (uia type ( 'DM'.unions [optionalAttr optional,editAttrs taskId (editorId dp) (checkMaskValue mask val)])),vst)
updUI dp ov om nv nm vst=:{VSt|optional,disabled}
| checkMaskValue om ov === checkMaskValue nm nv = (Ok NoChange,vst)
| otherwise = (Ok (ChangeUI [SetAttribute "value" (toJSON nv)] []),vst)
onEdit dp e val mask ust
= case e of
JSONNull = (val,Blanked,ust)
json = case fromJSON e of
Nothing = (val,TouchedUnparsed e,ust)
Just val = (val,Touched,ust)
definition module iTasks.UI.Editor.Combinators
/**
* This module provides combinator functions for combining editors
*/
import iTasks.UI.Editor
/**
* Adds hint attributes to an editor by checking the edit mask
*/
withHintAttributes :: String (Editor a) -> Editor a
/**
* Using an alternative editor when editing is disabled
*/
whenDisabled :: (Editor a) (Editor a) -> Editor a
/**
* Lift an editor to another domain
*/
liftEditor :: (a -> b) (b -> a) (Editor a) -> (Editor b)
implementation module iTasks.UI.Editor.Combinators
import iTasks.UI.Editor, iTasks.UI.Definition
import qualified Data.Map as DM
withHintAttributes :: String (Editor a) -> Editor a
withHintAttributes typeDesc editor = {Editor|genUI=genUI,updUI=updUI,onEdit=onEdit}
where
genUI dp val mask vst=:{VSt|taskId,optional}
= case editor.Editor.genUI dp val mask vst of
(Ok (UI type attr items),vst)
//Add hint attributes
# attr = 'DM'.union (stdAttributes typeDesc optional mask) attr
= (Ok (UI type attr items),vst)
(e,vst) = (e,vst)
updUI dp ov om nv nm vst=:{VSt|optional,disabled}
= case stdAttributeChanges typeDesc optional om nm of
[] = editor.Editor.updUI dp ov om nv nm vst //Nothing to add
hintChanges = case editor.Editor.updUI dp ov om nv nm vst of
(Ok NoChange,vst) = (Ok (ChangeUI hintChanges []),vst)
(Ok (ChangeUI attrChanges itemChanges),vst) = (Ok (ChangeUI (attrChanges ++ hintChanges) itemChanges),vst)
(e,vst) = (e,vst)
onEdit dp e val mask ust = editor.Editor.onEdit dp e val mask ust
whenDisabled :: (Editor a) (Editor a) -> Editor a
whenDisabled disabledEditor enabledEditor = {Editor|genUI=genUI,updUI=updUI,onEdit=onEdit}
where
genUI dp val mask vst=:{VSt|taskId,disabled}
| disabled = disabledEditor.Editor.genUI dp val mask vst
= enabledEditor.Editor.genUI dp val mask vst
updUI dp ov om nv nm vst=:{VSt|optional,disabled}
| disabled = disabledEditor.Editor.updUI dp ov om nv nm vst
= enabledEditor.Editor.updUI dp ov om nv nm vst
onEdit dp e val mask ust
= enabledEditor.Editor.onEdit dp e val mask ust
liftEditor :: (a -> b) (b -> a) (Editor a) -> (Editor b)
liftEditor tof fromf editor = {Editor|genUI=genUI,updUI=updUI,onEdit=onEdit}
where
genUI dp val mask vst = editor.Editor.genUI dp (fromf val) mask vst
updUI dp ov om nv nm vst = editor.Editor.updUI dp (fromf ov) om (fromf nv) nm vst
onEdit dp e val mask ust = case editor.Editor.onEdit dp e (fromf val) mask ust of
(val,mask,ust) = (tof val,mask,ust)
......@@ -3,7 +3,7 @@ implementation module iTasks._Framework.Generic.Interaction
from Data.Map import :: Map
import qualified Data.Map as DM
from StdFunc import const
import StdList, StdBool, StdTuple, StdMisc
import StdList, StdBool, StdTuple, StdMisc, StdArray
import Data.Maybe, Data.Either, Data.Error, Data.Generic, Data.Functor, Data.Tuple
import Text, Text.JSON
import iTasks._Framework.IWorld
......@@ -12,6 +12,7 @@ import iTasks._Framework.Util
import iTasks.API.Core.Types
import iTasks.UI.Layout
import iTasks.UI.Editor, iTasks.UI.Definition
import iTasks.UI.Editor.Builtin, iTasks.UI.Editor.Combinators
generic gEditor a | gText a, gDefault a, JSONEncode a, JSONDecode a :: Editor a
derive bimap Editor,(,,),(,,,)
......@@ -309,17 +310,13 @@ flattenPairDiff s n (ChangeUI _ [(_,ChangeChild l),(_,ChangeChild r)])
where
half = n / 2
gEditor{|Int|} = primitiveTypeEditor (Just "whole number") UIViewString UIEditInt
(\value -> JSONString (toString value))
gEditor{|Real|} = primitiveTypeEditor (Just "decimal number") UIViewString UIEditDecimal
(\value -> JSONString (toString value))
gEditor{|Char|} = primitiveTypeEditor (Just "single character") UIViewString UIEditString
(\value -> JSONString (toString value))
gEditor{|String|} = primitiveTypeEditor (Just "single line of text") UIViewString UIEditString
(\value -> JSONString (toString value))
gEditor{|Bool|} = primitiveTypeEditor Nothing UIViewCheckbox UIEditCheckbox
(\value -> JSONBool value)
gEditor{|Int|} = whenDisabled (liftEditor toInt toString textView) (withHintAttributes "whole number" integerField)
gEditor{|Real|} = whenDisabled (liftEditor toReal toString textView) (withHintAttributes "decimal number" decimalField)
gEditor{|Char|} = liftEditor (\c -> c.[0]) toString (whenDisabled textView (withHintAttributes "single character" textField))
gEditor{|String|} = whenDisabled textView (withHintAttributes "single line of text" textField)
gEditor{|Bool|} = checkBox
/*
primitiveTypeEditor mbTypeDesc viewType editType mkViewValue = {Editor|genUI=genUI,updUI=updUI,onEdit=onEdit}
where
genUI dp val mask vst=:{VSt|taskId,optional,disabled}
......@@ -341,7 +338,7 @@ where
attrChanges = maybe [] (\typeDesc ->stdAttributeChanges typeDesc optional om nm) mbTypeDesc
onEdit dp e val mask ust = basicUpdateSimple dp e val mask ust
*/
gEditor{|EditableList|} ex _ dx _ _
= listEditor ex dx
(\{EditableList|items} -> items)
......
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