8 This component can print stock properties
16 hashref of stockprops . keys = prop name (cvterm.name) values = list of prop values
21 Naama Menda <nm249@cornell.edu>
31 $subset => [ 'released_variety_name' ]
37 <& /util/import_javascript.mas,
38 classes => ["jquery", "jqueryui", "CXGN.Page.FormattingHelpers", "CXGN.Stock" ],
43 use CXGN::Page::FormattingHelpers qw | simple_selectbox_html simple_checkbox_html |;
45 my $subset_json = JSON::Any->objToJson($subset);
48 $div_name ||= join("_", @$subset);
49 $div_name =~ s/ +/\_/g;
53 my $prop_select = simple_selectbox_html(
54 name => $div_name."_select",
55 id => $div_name."_select",
62 <div id="<% $div_name %>_content">
66 <div class ="modal fade" id="<% $div_name %>_add_dialog" name="<% $div_name %>_add_dialog" tabindex="-1" role="dialog" aria-labelledby="add<% $div_name %>Dialog">
68 <div class="modal-dialog" role="document">
69 <div class="modal-content">
70 <div class="modal-header" style="text-align: center">
71 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
72 <h4 class="modal-title" id="add<% $div_name %>Dialog">Add Property</h4>
74 <div class="modal-body">
75 <div class="container-fluid">
77 <form class="form-horizontal" role="form" method="post" id="add_<% $div_name %>_dialog_form" name="add_<% $div_name %>_dialog_form">
78 <div class="form-group">
79 <label class="col-sm-6 control-label"><% $prop_select %> </label><br />
81 <div class ="form-group">
82 <div class="col-sm-6" >
83 <input name="<% $div_name %>_prop" id="<% $div_name %>_prop" class="form-control" type="text" />
90 <div class="modal-footer">
91 <button id="close_add_<% $div_name %>_stockprop_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
92 <button type="button" class="btn btn-primary" name="<% $div_name %>_addProp_submit" id="<% $div_name %>_addProp_submit" title="submit">Submit</button>
101 <script defer="defer" >
103 jQuery(document).ready(function() {
104 <% $div_name %>_getProps();
107 jQuery('#<% $form_div_id %>').click(function(){
108 jQuery('#<% $div_name %>_add_dialog').modal("show");
111 jQuery('#<% $div_name %>_addProp_submit').click( function () {
112 <% $div_name %>_addProp() },
116 // note: the $div_name prefix is needed when several instances are created on a page
118 function <% $div_name %>_getProps() {
121 url: '/stock/prop/get',
122 data: { stock_id: <% $stock_id %> },
123 success: function(response) { <% $div_name %>_renderProps(response); },
124 error: function(response) { alert('an error occurred'); }
130 function <% $div_name %>_renderProps(props) {
131 var subset = eval(<% $subset_json %>);
133 // eliminate types without values
134 var filteredSet = {};
135 for (var n=0; n<subset.length; n++) {
136 for (var i=0; i<props.length; i++) {
137 if (subset[n] == props[i]['type_name']) {
138 filteredSet[subset[n]]=1;
146 var edit_privs = <% $edit_privs %>;
147 for (var n in filteredSet) {
148 var lines = new Array();
149 for(var i=0; i<props.length; i++) {
150 if (n === props[i]['type_name']) {
151 var lineStr = props[i]['value'];
152 if (jQuery.cookie("sgn_session_id") && edit_privs === 1) {
153 lineStr = lineStr + '[<a href="javascript:<% $div_name %>_deleteProp(\''+props[i]['value']+'\', '+props[i]['stockprop_id']+')">X</a>]';
159 html = html + '<b>'+n+'</b> ';
160 //html = html + lineStr;
161 html = html + lines.join(", ");
162 html = html + '<br />\n';
164 jQuery('#<% $div_name %>_content').html(html);
170 function <% $div_name %>_addProp() {
171 var prop_type = jQuery('#<% $div_name %>_select').val();
172 var prop = jQuery('#<% $div_name %>_prop').val();
174 if (prop === '') { alert("Please fill in the field."); return; }
178 url: '/stock/prop/add',
179 beforeSend: function(){
180 jQuery('#working_modal').modal('show');
182 data: { 'stock_id' : <% $stock_id %>, 'prop' : prop, 'prop_type': prop_type },
183 success: function(response) {
184 jQuery('#working_modal').modal('hide');
185 if ("error" in response) { alert ('ERROR '+response.error); }
186 if ("message" in response) {
187 alert('Successfully added property: ' + prop + '. ('+response.message+')');
190 error: function(response) {
191 jQuery('#working_modal').modal('hide');
192 alert('an error occurred while storing the prop ' + response.error);
194 complete: function() {
195 <% $div_name %>_getProps();
196 jQuery('#<% $div_name %>_add_dialog').modal("hide");
203 function <% $div_name %>_deleteProp(stockprop_value, stockprop_id) {
204 var yes = confirm('Delete stockprop '+stockprop_value+'?');
208 url: '/stock/prop/delete',
209 data: { 'stockprop_id' : stockprop_id },
210 success: function(response) {
211 if ('message' in response) {
212 alert(response.message);
215 if ('error' in response) { alert(response.error); }
217 error: function(response) { alert('An error occurred. Please try again later.');
219 complete: function() {
220 <% $div_name %>_getProps();