11/*eslint indent: ["warn", 2, { "VariableDeclarator": 2 }]*/
22var h = require ( 'attodom/el' ) ,
3- list = require ( 'attodom/list' ) ,
4- t = require ( 'attodom/text' )
3+ list = require ( 'attodom/list' )
54
6- var TITLE = 'attodom v0.9.0 '
5+ var TITLE = 'attodom v0.11.3 '
76
87module . exports = function ( store ) {
98 function clickHandlerMenu ( e ) {
109 var key = e . target . id
1110 if ( key ) {
1211 e . preventDefault ( )
1312 store [ key === 'runlots' ? 'runLots' : key === 'swaprows' ? 'swapRows' : key ] ( )
14- rows . update ( store . data )
13+ rowList . update ( store . data )
1514 }
1615 }
16+
1717 function updateRow ( v ) {
1818 this . $label . data = v . label
1919 this . className = ( this . id === store . selected ) ? 'danger' : ''
2020 }
21- function clickHandlerSelect ( e ) {
22- e . preventDefault ( )
23- store . select ( this . parentNode . id )
24- rows . update ( store . data )
25- }
26- function clickHandlerDelete ( e ) {
27- e . preventDefault ( )
28- store . delete ( + this . parentNode . id )
29- rows . update ( store . data )
30- }
3121
32- var rows = list ( 'id' , function ( rec ) {
33- var attr = { id : rec . id , update : updateRow , $label : t ( rec . label ) }
22+ function makeRow ( rec ) {
23+ var attr = { id : rec . id , update : updateRow }
3424 return h ( 'tr' , attr ,
3525 h ( 'td' , { class : 'col-md-1' } , rec . id ) ,
36- h ( 'td' , { class : 'col-md-4' , onclick : clickHandlerSelect } ,
37- h ( 'a' , { class : 'lbl' } , attr . $label )
26+ h ( 'td' , { class : 'col-md-4' , onClick : clickHandlerSelect } ,
27+ h ( 'a' , { class : 'lbl' } , attr . $label = document . createTextNode ( rec . label ) )
3828 ) ,
39- h ( 'td' , { class : 'col-md-1' , onclick : clickHandlerDelete } ,
29+ h ( 'td' , { class : 'col-md-1' , onClick : clickHandlerDelete } ,
4030 h ( 'a' , { class : 'remove' } ,
4131 h ( 'span' , { class : 'glyphicon glyphicon-remove remove' , 'aria-hidden' : '' } )
4232 )
4333 ) ,
4434 h ( 'td' , { class : 'col-md-6' } )
4535 )
46- } )
36+ }
37+
38+ function clickHandlerSelect ( e ) {
39+ e . preventDefault ( )
40+ store . select ( this . parentNode . id )
41+ rowList . update ( store . data )
42+ }
4743
48- return h ( 'div' , { id : 'main' , update : function ( ) { rows . update ( store . data ) } } ,
44+ function clickHandlerDelete ( e ) {
45+ e . preventDefault ( )
46+ store . delete ( + this . parentNode . id )
47+ rowList . update ( store . data )
48+ }
49+
50+ var rowList = list ( h ( 'tbody' , { id : 'tbody' } ) , makeRow , { key : 'id' } )
51+
52+ return h ( 'div' , { id : 'main' , update : function ( ) { rowList . update ( store . data ) } } ,
4953 h ( 'div' , { class : 'container' } ,
5054 h ( 'div' , { class : 'jumbotron' } ,
5155 h ( 'div' , { class : 'row' } ,
@@ -64,9 +68,7 @@ module.exports = function(store) {
6468 )
6569 )
6670 ) ,
67- h ( 'table' , { class : 'table table-hover table-striped test-data' } ,
68- h ( 'tbody' , { id : 'tbody' } , rows )
69- ) ,
71+ h ( 'table' , { class : 'table table-hover table-striped test-data' } , rowList . parent ) ,
7072 h ( 'span' , { class : 'preloadicon glyphicon glyphicon-remove' , 'aria-hidden' : '' } )
7173 )
7274 )
0 commit comments