8 This component can print cvterm properties
16 hashref of cvtermprops . keys = prop name (cvterm.name) values = list of prop values
21 Naama Menda <nm249@cornell.edu>
35 $cv_name => 'trait_property'
41 my $subset_json = JSON::Any->objToJson($subset);
43 $div_name ||= join("_", @$subset);
44 $div_name =~ s/ +/\_/g;
46 my $prop_select = prop_select($editable, $div_name);
53 my $html = "<select id=\"$div_name"."_select"."\">";
54 foreach my $item (@$editable) {
55 $html .= qq{ <option>$item</option> };
57 $html .= qq{ </select> };
64 <div id="<% $div_name %>_content">
67 <div id="<% $div_name %>_add_dialog" >
68 Add <% $prop_select %>
69 <input id="<% $div_name %>_prop" />
72 <script defer="defer" >
74 jQuery(document).ready(function() {
76 jQuery('#<% $div_name %>_add_dialog').dialog( {
77 title: 'Add property',
78 buttons: { 'Cancel': function() { jQuery('#<% $div_name %>_add_dialog').dialog("close"); }, 'Add': {text: 'Add', id: '<% $div_name %>_addProp_submit', click: function() { <% $div_name %>_addProp() } } },
83 <% $div_name %>_getProps();
87 // note: the $div_name prefix is needed when several instances are created on a page
89 function <% $div_name %>_getProps() {
92 url: '/cvterm/prop/get',
93 data: { cvterm_id: <% $cvterm_id %> },
94 success: function(response) { <% $div_name %>_renderProps(response); },
95 error: function(response) { alert('an error occurred'); }
100 function <% $div_name %>_renderProps(props) {
101 var subset = eval(<% $subset_json %>);
103 // eliminate types without values
104 var filteredSet = {};
105 for (var n=0; n<subset.length; n++) {
106 for (var i=0; i<props.length; i++) {
107 if (subset[n] == props[i]['type_name']) {
108 filteredSet[subset[n]]=1;
116 var edit_privs = <% $edit_privs %>;
117 for (var n in filteredSet) {
118 var lines = new Array();
119 for(var i=0; i<props.length; i++) {
120 if (n === props[i]['type_name']) {
121 var lineStr = props[i]['value'];
122 if (jQuery.cookie("sgn_session_id") && edit_privs === 1) {
123 lineStr = lineStr + '[<a href="javascript:<% $div_name %>_deleteProp(\''+props[i]['value']+'\', '+props[i]['cvtermprop_id']+')">X</a>]';
129 html = html + '<b>'+n+'</b> ';
130 //html = html + lineStr;
131 html = html + lines.join(", ");
132 html = html + '<br />\n';
135 jQuery('#<% $div_name %>_content').html(html);
139 function <% $div_name %>_addPropDialog(prop, typeId) {
140 jQuery('#<% $div_name %>_add_dialog').dialog("open");
146 function <% $div_name %>_addProp() {
147 var prop_type = jQuery('#<% $div_name %>_select').val();
148 var prop = jQuery('#<% $div_name %>_prop').val();
150 if (prop === '') { alert("Please fill in the field."); return; }
154 url: '/cvterm/prop/add',
155 beforeSend: function(){
156 jQuery('#working_modal').modal('show');
158 data: { 'cvterm_id' : <% $cvterm_id %>, 'prop' : prop, 'prop_type': prop_type, 'cv_name' : "<% $cv_name %>" },
159 success: function(response) {
160 jQuery('#working_modal').modal('hide');
161 if ("error" in response) { alert ('ERROR '+response.error); }
162 if ("message" in response) { alert('Successfully added property: ' + prop + '. ('+response.message+')'); }
164 error: function(response) {
165 jQuery('#working_modal').modal('hide');
166 alert('an error occurred while storing the prop ' + response.error);
170 <% $div_name %>_getProps();
171 jQuery('#<% $div_name %>_add_dialog').dialog("close");
175 function <% $div_name %>_deleteProp(cvtermprop_value, cvtermprop_id) {
176 if (confirm('Delete cvtermprop '+cvtermprop_value+'?')) {
179 url: '/cvterm/prop/delete',
180 data: { 'cvtermprop_id' : cvtermprop_id },
181 success: function(response) {
182 if ('message' in response) { alert(response.message); }
183 if ('error' in response) { alert(response.error); }
185 error: function(response) {
186 alert('An error occurred. Please try again later.');
191 <% $div_name %>_getProps();