function drawTable(fields, rows) { var head = ''; for(let field in fields) { var fieldName = fields[field]; fieldName = (typeof fieldSettings[field] !== 'undefined' && fieldSettings[field].name ? fieldSettings[field].name : fieldName); var width = getTextWidth(fieldName) + 40; head += '' + fieldName + '' + ''; } head += ''; var html = '' + head + ''; var body = ''; for(let row of rows) { body += ''; for(let index in row) body += '' + row[index] + ''; body += ''; } html += '' + body + ''; $('table.result').html(html); } function getTextWidth(text) { var font = "bold 12pt arial" var canvas = document.createElement("canvas"); var context = canvas.getContext("2d"); context.font = font; var measure = context.measureText(text); return measure.width; } function configHeader(obj) { modal = new $.zui.ModalTrigger({title: lang.fieldSettings, custom: function(el) { var html = '
'; html += ''; html += ''; for(let index in fields) { var field = fields[index]; var typeOptions = genTypeOptions(index); var name = typeof fieldSettings[field] == 'undefined' ? '' : fieldSettings[field].name; html += ''; } html += ''; html += ''; html += '
' + lang.field + '' + lang.fieldName + '' + lang.fieldType + '
' + field + '' + typeOptions + '
'; html += '
'; return html; }}); modal.show({onShow: function() { setTimeout(function() { $('.chosen').chosen(); $('select[name^="object"]').change(function(e) { var object = $(this).val(); var objectid = $(this).attr('id'); var $that = $(this); if(!object) { return false; } $.get(createLink('dataset', 'ajaxGetTypeOptions', 'object=' + object), function(res) { var index = objectid.substring(6); var id = 'type' + index; var res = JSON.parse(res); var options = ''; for(let key in res.options) { options += ''; } allTypeOptions[object] = res.options; var html = ''; $that.closest('.td-row').find('.typebox').html(html); $('.types').chosen(); }); }); }, 20) return false; }}) modal.show(); }