class ListComponent { constructor(parent, df) { this.parent = parent; this.df = df || {}; this.make(); } make() { this.wrapper = $(`
`).appendTo(this.parent); this.iterate_list( this.wrapper, this.df.data, this.df.template, this.df.onclick, ); } iterate_list(parent, data, template) { for (var i = 0; i < data.length; i++) { let cursor_style = this.df.onclick ? 'cursor: pointer;' : ''; let list_row = $( `
`, ).appendTo(parent); data[i].last = i == data.length - 1; list_row.append(template(data[i])); if (this.df.onclick) { $(list_row).on('click', () => { this.df.onclick(list_row[0].id); // TODO pass index }); } } } } // list component templates function title_with_message_and_tag_template(data) { let title = data.title || ''; let message = data.message || ''; let tag = data.tag || ''; let tag_type = data.tag_type || ''; return `
${title || ''}

${message || ''}

${tag || ''}

${data.last ? `` : `
`} `; } function title_with_sub_text_tag_and_button_template(data) { return `

${data.title || ''}

${data.last ? `` : `
`} `; } function title_with_text_area_template(data) { return `
${data.title || ''}
${data.message || ''}
`; }