66/* global alert */
77
88import { fieldParams } from './forms/fieldParams'
9+ import { field , mostSpecificClassURI , fieldFunction } from './forms/fieldFunction'
910
1011module . exports = { }
1112
1213var forms = { }
1314
14- forms . field = { } // Form field functions by URI of field type.
15+ forms . field = field // Form field functions by URI of field type.
1516
1617var UI = {
1718 icons : require ( '../iconBase' ) ,
@@ -90,20 +91,20 @@ forms.field[ns.ui('Form').uri] = forms.field[
9091 var original = [ ]
9192 for ( var i = 0 ; i < p2 . length ; i ++ ) {
9293 var field = p2 [ i ]
93- var t = forms . mostSpecificClassURI ( field ) // Field type
94+ var t = mostSpecificClassURI ( field ) // Field type
9495 if ( t === ui ( 'Options' ) . uri ) {
9596 var dep = kb . any ( field , ui ( 'dependingOn' ) )
9697 if ( dep && kb . any ( subject , dep ) ) original [ i ] = kb . any ( subject , dep ) . toNT ( )
9798 }
9899
99- var fn = forms . fieldFunction ( dom , field )
100+ var fn = fieldFunction ( dom , field )
100101
101102 var itemChanged = function ( ok , body ) {
102103 if ( ok ) {
103104 for ( var j = 0 ; j < p2 . length ; j ++ ) {
104105 // This is really messy.
105106 var field = p2 [ j ]
106- var t = forms . mostSpecificClassURI ( field ) // Field type
107+ var t = mostSpecificClassURI ( field ) // Field type
107108 if ( t === ui ( 'Options' ) . uri ) {
108109 var dep = kb . any ( field , ui ( 'dependingOn' ) )
109110 var newOne = fn (
@@ -385,7 +386,7 @@ forms.field[ns.ui('Multiple').uri] = function (
385386 // var ins = []
386387 // var del = []
387388
388- var fn = forms . fieldFunction ( dom , element )
389+ var fn = fieldFunction ( dom , element )
389390 var subField = fn ( dom , null , already , object , element , store , itemDone ) // p2 was: body. moving to not passing that
390391 subField . subject = object // Keep a back pointer between the DOM array and the RDF objects
391392
@@ -589,7 +590,7 @@ function basicField (
589590 return box
590591 }
591592 lhs . appendChild ( forms . fieldLabel ( dom , property , form ) )
592- var uri = forms . mostSpecificClassURI ( form )
593+ var uri = mostSpecificClassURI ( form )
593594 var params = forms . fieldParams [ uri ]
594595 if ( params === undefined ) params = { } // non-bottom field types can do this
595596 var style = params . style || UI . style . textInputStyle || 'font-size: 100%; margin: 0.1em; padding: 0.1em;'
@@ -971,7 +972,7 @@ forms.field[ns.ui('Choice').uri] = function (
971972 var object = kb . any ( subject , property )
972973 function addSubForm ( ) {
973974 object = kb . any ( subject , property )
974- forms . fieldFunction ( dom , subForm ) (
975+ fieldFunction ( dom , subForm ) (
975976 dom ,
976977 rhs ,
977978 already ,
@@ -1021,7 +1022,7 @@ forms.field[ns.ui('Comment').uri] = forms.field[
10211022 var contents = kb . any ( form , ui ( 'contents' ) )
10221023 if ( ! contents ) contents = 'Error: No contents in comment field.'
10231024
1024- var uri = forms . mostSpecificClassURI ( form )
1025+ var uri = mostSpecificClassURI ( form )
10251026 var params = forms . fieldParams [ uri ]
10261027 if ( params === undefined ) {
10271028 params = { }
@@ -1041,41 +1042,6 @@ forms.field[ns.ui('Comment').uri] = forms.field[
10411042 return box
10421043}
10431044
1044- /// ////////////// Form-related functions
1045-
1046- /** Which class of field is this?
1047- * @param x a field
1048- * @returns the URI of the most specific class
1049- */
1050-
1051- forms . mostSpecificClassURI = function ( x ) {
1052- const kb = UI . store
1053- var ft = kb . findTypeURIs ( x )
1054- var bot = kb . bottomTypeURIs ( ft ) // most specific
1055- var bots = [ ]
1056- for ( var b in bot ) bots . push ( b )
1057- // if (bots.length > 1) throw "Didn't expect "+x+" to have multiple bottom types: "+bots
1058- return bots [ 0 ]
1059- }
1060-
1061- forms . fieldFunction = function ( dom , field ) {
1062- const uri = forms . mostSpecificClassURI ( field ) // What type
1063- // const uri = field.uri
1064- var fun = forms . field [ uri ]
1065- UI . log . debug (
1066- 'paneUtils: Going to implement field ' + field + ' of type ' + uri
1067- )
1068- if ( ! fun ) {
1069- return function ( ) {
1070- return error . errorMessageBlock (
1071- dom ,
1072- 'No handler for field ' + field + ' of type ' + uri
1073- )
1074- }
1075- }
1076- return fun
1077- }
1078-
10791045// A button for editing a form (in place, at the moment)
10801046//
10811047// When editing forms, make it yellow, when editing thr form form, pink
@@ -1125,7 +1091,7 @@ forms.appendForm = function (
11251091 store ,
11261092 itemDone
11271093) {
1128- return forms . fieldFunction ( dom , form ) (
1094+ return fieldFunction ( dom , form ) (
11291095 dom ,
11301096 container ,
11311097 already ,
@@ -1343,7 +1309,7 @@ forms.promptForNew = function (
13431309 box . setAttribute ( 'style' , `border: 0.05em solid ${ UI . style . formBorderColor } ; color: ${ UI . style . formBorderColor } ` ) // @@color ?
13441310 box . innerHTML = '<h3>New ' + utils . label ( theClass ) + '</h3>'
13451311
1346- var formFunction = forms . fieldFunction ( dom , form )
1312+ var formFunction = fieldFunction ( dom , form )
13471313 var object = forms . newThing ( store )
13481314 var gotButton = false
13491315 var itemDone = function ( ok , body ) {
@@ -1607,7 +1573,7 @@ forms.makeSelectForOptions = function (
16071573 if ( ok ) {
16081574 select . disabled = false // data written back
16091575 if ( newObject ) {
1610- var fn = forms . fieldFunction ( dom , options . subForm )
1576+ var fn = fieldFunction ( dom , options . subForm )
16111577 fn (
16121578 dom ,
16131579 select . parentNode ,
0 commit comments