function create_info(){ $(document).ready(function() { $.ajax({ type: "GET", url: "https://cpee.org/~demo/zt/information.json", success: (res) => { var info = res; let ids = $('div.task').find('*').map(function() { if (this.id){ return this.id; } }).get(); ids.forEach((e) => { if (info[e]){ let myinfo = $('#my-info')[0].content.cloneNode(true); $('span.tooltiptext',myinfo).text(info[e]); $("label[for='"+e+"']").append($(myinfo)); } }); } }); }); } function create_table(params){ let table = $('#my-simple-table')[0].content.cloneNode(true); Object.keys(params).forEach(val => { let line = $('#myentry',table)[0].content.cloneNode(true); $('td.name',line).text(val.replace(/_/,' ')); $('td.value',line).text(params[val]); $('tbody',table).append(line); }); $("p.container").append(table); $("p.container").append($('
')); } function create_section_table(params,name){ let table = $('#mytable')[0].content.cloneNode(true); let section = $('#mysection',table)[0].content.cloneNode(true); $('th.section',section).text(name.replaceAll(/_/g,' ')); $('tbody',table).append(section); Object.keys(params).forEach(val => { let line = $('#myentry',table)[0].content.cloneNode(true); $('td.name',line).text(val.replace(/_/,' ')); if (params[val].match(/https:/)) { params[val] = params[val].replace(/(https:[^\s]*)/g,'$1') } $('td.value',line).append(params[val]); $('tbody',table).append(line); }); $("p.container").append(table); $("p.container").append($('
')); } function display_all(data){ Object.keys(data).forEach(val => { if (val != "roles" && val != "resources_allocation" && val != "resources_estimation"){ var params = data[val]; create_section_table(params,val); } }); } function add_selection_options(list,id){ let selection = $('#myselection')[0].content.cloneNode(true); $('select.myselect',selection).attr('name', id); $('select.myselect',selection).attr('id', id); $('select.myselect',selection).attr('multiple',''); list.forEach(role => { let option = $('#my-new-option',selection)[0].content.cloneNode(true); $('option.newoption',option).text(role); $('option.newoption',option).attr('value',role); $('option.newoption',option).attr('title',role); $('select',selection).append(option); }); return selection; } function create_estimation(list){ let table = $('#myresources')[0].content.cloneNode(true); let line = $('#myentry',table)[0].content.cloneNode(true); let selection = add_selection(list,"resourcetypes"); $('td.rolelist',line).append(selection); $('tbody',table).append(line); $("p.container").append(table); } function add_selection(list,id){ let selection = $('#myselection')[0].content.cloneNode(true); $('select.myselect',selection).attr('name', id); $('select.myselect',selection).attr('id', id); list.forEach(role => { let option = $('#my-new-option',selection)[0].content.cloneNode(true); $('option.newoption',option).text(role); $('option.newoption',option).attr('value',role); $('select',selection).append(option); }); return selection; } function all_roles(data,teams){ let allocation = $('#myallocation')[0].content.cloneNode(true); for (let i = 0; i < data.length; i=i+2) { let entry = data[i]; let usage_entry = data[i+1]; let line = $('#myentry',allocation)[0].content.cloneNode(true); $('td.usage',line).text(usage_entry["value"]); Object.keys(entry).forEach(key => { if ( key != "name" ) { $('td.role',line).text(entry["value"]); let selection = add_selection_options(teams[entry[key]],entry[key]); $('td.teamlist',line).append(selection); } }); $('tbody',allocation).append(line); }; $("p.container").append(allocation); } function selected_roles(data){ let allocation = $('#my-simple-allocation')[0].content.cloneNode(true); for (let i = 0; i < data.length; i=i+2) { let entry = data[i]; let usage_entry = data[i+1]; let line = $('#myentry',allocation)[0].content.cloneNode(true); $('td.usage',line).text(usage_entry["value"]); Object.keys(entry).forEach(key => { if ( key != "name" ) { $('td.role',line).text(entry["value"]); } }); $('tbody',allocation).append(line); }; $("p.container").append(allocation); $("p.container").append($('
')); } function list_resources(resources){ let table = $('#my-simple-table')[0].content.cloneNode(true); resources.forEach(resource => { let line = $('#myentry',table)[0].content.cloneNode(true); $('td.name',line).text(resource["name"]); $('td.value',line).text(resource["value"]); $('tbody',table).append(line); } ); $("p.container").append(table); $("p.container").append($('
')); } function add_filename(name){ console.log('rrrr'); let fileform = $('#file_upload')[0].content.cloneNode(true); $('input.field',fileform).attr('name',name ); $("#" + name).append(fileform); } function add_rating(ratings){ console.log(ratings); let table = $('#rating')[0].content.cloneNode(true); Object.keys(ratings).forEach(val => { let line = $('#userrating',table)[0].content.cloneNode(true); console.log(val,ratings[val]); $('td.user',line).append(val); let rating = ratings[val]; Object.keys(rating).forEach(v => { console.log(v,rating[v]); $('td.'+v,line).append(rating[v]); }); $('tbody',table).append(line); }); $("p.container").append(table); $("p.container").append($('
')); } function add_general_rating(rating,levels){ console.log(rating); console.log(levels); let table = $('#general-rating')[0].content.cloneNode(true); let line = $('#rating',table)[0].content.cloneNode(true); Object.keys(rating).forEach(val => { console.log(val,rating[val]); $('td.'+val,line).append(rating[val]); $('td.'+val+"_note",line).append(levels[val]); }); $('tbody',table).append(line); $("p.container").append(table); } $('select[multiple] option').mousedown(function(e) { e.preventDefault(); var originalScrollTop = $(this).parent().scrollTop(); $(this).prop('selected', $(this).prop('selected') ? false : true); var self = this; $(this).parent().focus(); setTimeout(function() { $(self).parent().scrollTop(originalScrollTop); }, 0); return false; });