@@ -246,17 +246,19 @@ function readFile(file) {
246246} 
247247
248248async  function  renderFiles ( input )  { 
249-     let  template_id  =  input . getAttribute ( 'template_id' ) 
250-     if  ( template_id )  { 
251-         let  template  =  document . querySelector ( `[template="${ template_id }  ) 
252-         template . setAttribute ( 'file_id' ,  '{{id}}' ) 
249+     let  selector  =  input . getAttribute ( 'render-selector' ) 
250+     if  ( ! selector )  return 
251+     let  templates  =  document . querySelectorAll ( selector ) 
252+     for  ( let  i  =  0 ;  i  <  templates . length ;  i ++ )  { 
253+         templates [ i ] . setAttribute ( 'file_id' ,  '{{id}}' ) 
253254        const  data  =  await  getFiles ( input ,  false ) 
254255        if  ( ! data . length )  return 
255256        render . data ( { 
256-             selector :  `[template=' ${ template_id } ']` , 
257+             selector, 
257258            data
258259        } ) ; 
259260    } 
261+ 
260262} 
261263
262264async  function  fileFormAction ( data )  { 
@@ -292,21 +294,18 @@ async function fileFormAction(data) {
292294async  function  fileRenderAction ( data )  { 
293295    const  action  =  data . name 
294296    const  element  =  data . element 
297+ 
298+     let  input  =  element . fileInput 
295299    let  file_id  =  element . getAttribute ( 'file_id' ) ; 
296300    if  ( ! file_id )  { 
297301        const  closestElement  =  element . closest ( '[file_id]' ) ; 
298302        if  ( closestElement )  { 
303+             input  =  closestElement . renderedData . input 
299304            file_id  =  closestElement . getAttribute ( 'file_id' ) ; 
300305        } 
301306    } 
302-     if  ( ! file_id )  return 
303- 
304-     let  templateid  =  element . closest ( '[templateid]' ) 
305-     if  ( templateid ) 
306-         templateid  =  templateid . getAttribute ( 'templateid' ) 
307307
308-     const  input  =  document . querySelector ( `[type="file"][template_id="${ templateid }  ) 
309-     if  ( ! input )  return 
308+     if  ( ! file_id  ||  ! input )  return 
310309
311310    let  file  =  inputs . get ( input ) . get ( file_id ) 
312311    if  ( ! file )  return 
@@ -427,7 +426,7 @@ async function Import(input) {
427426
428427async  function  Export ( btn ,  inputs )  { 
429428    let  data  =  crud . getAttributes ( btn ) ; 
430-     const  template_id  =  btn . getAttribute ( 'template_id ' ) ; 
429+     const  renderSelector  =  btn . getAttribute ( 'render-selector ' ) ; 
431430
432431    if  ( data . storage  ||  data . database  ||  data . collection )  { 
433432        let  name  =  data . name 
@@ -442,7 +441,7 @@ async function Export(btn, inputs) {
442441            data  =  data . document [ 0 ] [ name ] 
443442        } 
444443
445-     }  else  if  ( template_id )  { 
444+     }  else  if  ( renderSelector )  { 
446445        console . log ( 'export json data used to render templates' ) 
447446    }  else  { 
448447        data  =  getFiles ( inputs ) 
@@ -572,12 +571,12 @@ observer.init({
572571observer . init ( { 
573572    name : 'fileRender' , 
574573    observe : [ 'attributes' ] , 
575-     attributeName : [ 'template_id ' ] , 
574+     attributeName : [ 'render-selector ' ] , 
576575    target : 'input[type="file"]' , 
577576    callback : mutation  =>  renderFiles ( mutation . target ) 
578577} ) ; 
579578
580- actions . init ( 
579+ actions . init ( [ 
581580    { 
582581        name : [ "upload" ,  "download" ,  "saveLocally" ,  "import" ,  "export" ] , 
583582        callback : ( action )  =>  { 
@@ -590,7 +589,7 @@ actions.init(
590589            fileRenderAction ( action ) 
591590        } 
592591    } 
593- ) 
592+ ] ) 
594593
595594init ( ) 
596595
0 commit comments