@@ -9,6 +9,7 @@ foam.CLASS({
99 name : 'RowPropertyView' ,
1010 extends : 'foam.u2.PropertyBorder' ,
1111 mixins : [ 'foam.u2.layout.ContainerWidth' ] ,
12+ requires : [ 'foam.u2.ControllerMode' ] ,
1213
1314 documentation : `
1415 View a property's columnLabel and value in a single row. The table cell formatter
@@ -50,40 +51,48 @@ foam.CLASS({
5051 const self = this ;
5152 const sup = this . SUPER ;
5253 this . initContainer ( ) ;
54+ if ( this . __context__ . controllerMode$ )
55+ this . controllerMode$ . follow ( this . __context__ . controllerMode$ ) ;
5356 this . isRow_$ = this . inlineSize$ . map ( v => v > foam . u2 . layout . DisplayWidth . XS . minWidth ) ;
5457 // dynamic is implemented manually and not through add() here as the sup.call() will always add to "this" element and
5558 // not to the dynamic node. Hence removal has to be performed on this element.
5659 // Hijack prop label and view and replace them with the table-esque variant
5760 let label = self . prop . columnLabel ;
58- self . prop . view = function ( ) {
59- const el = self . E ( ) ;
60- const prop = this ;
61- prop . tableCellFormatter . format (
62- el ,
63- prop . f ? prop . f ( self . objData || self . data ) : null ,
64- self . objData || self . data ,
65- prop
66- ) ;
67- return el ;
68- } ;
69- this . dynamic ( function ( isRow_ ) {
61+ this . config = { label : label } ;
62+ this . dynamic ( function ( isRow_ , mode ) {
7063 this . removeAllChildren ( ) ;
71- this . enableClass ( self . myClass ( 'row' ) , isRow_ ) ;
72- if ( ! isRow_ ) {
73- this . config = { label : label } ;
74- sup . call ( self ) ;
75- } else {
76- this
77- . start ( )
78- . add ( label ) . show ( label )
79- . addClass ( self . myClass ( 'label' ) )
80- . end ( )
81- . add ( this . slot ( function ( data , objData ) {
82- let el = self . prop . view ( ) ;
83- return el . addClass ( self . myClass ( 'body' ) ) ;
84- } ) ) ;
64+ switch ( mode ) {
65+ case self . ControllerMode . CREATE :
66+ case self . ControllerMode . EDIT :
67+ sup . call ( self ) ;
68+ break ;
69+ case self . ControllerMode . VIEW :
70+ this . enableClass ( self . myClass ( 'row' ) , isRow_ ) ;
71+ if ( ! isRow_ ) {
72+ sup . call ( self ) ;
73+ } else {
74+ this
75+ . start ( )
76+ . add ( label ) . show ( label )
77+ . addClass ( self . myClass ( 'label' ) )
78+ . end ( )
79+ . add ( self . slot ( function ( data , objData ) {
80+ const el = self . E ( ) ;
81+ const prop = self . prop ;
82+ prop . tableCellFormatter . format (
83+ el ,
84+ prop . f ? prop . f ( self . objData || self . data ) : null ,
85+ self . objData || self . data ,
86+ prop
87+ ) ;
88+ return el . addClass ( self . myClass ( 'body' ) )
89+ } ) ) ;
90+ }
91+ break ;
92+ default :
93+ console . warn ( 'Unrecognized mode: ' + mode ) ;
8594 }
86- } ) ;
95+ } , this . isRow_$ , this . controllerMode$ ) ;
8796 }
8897 ]
8998} ) ;
0 commit comments