3 if (!CXGN) CXGN = function () { };
5 CXGN.Dataset = function () {
10 CXGN.Dataset.prototype = {
12 // return info on all available datasets
13 getDatasets: function() {
16 'url' : '/ajax/dataset/by_user',
18 'success': function(response) {
20 //alert(response.error);
25 'error': function(response) {
26 alert('An error occurred. Please try again.');
32 getDataset: function(id) {
35 'url' : '/ajax/dataset/get/'+id,
37 'success': function(response) {
39 alert(response.error);
42 dataset = response.dataset;
45 'error': function(response) {
46 alert('An error occurred. The specified dataset may not exist. Please try again.'+JSON.stringify(response));
53 deleteDataset: function(id) {
56 'url' : '/ajax/dataset/delete/'+id,
58 'success': function(response) {
60 alert('An error occurred during dataset deletion. '+response.error);
63 alert('The dataset has been deleted.');
66 'error': function(response) {
67 alert('An error occurred. The specified dataset may not exist. Please try again.'+JSON.stringify(response));
73 datasetSelect: function(div_name, empty_element, refresh) {
75 var datasets = new Array();
76 datasets = this.getDatasets();
77 var html = '<select class="form-control input-sm" id="'+div_name+'_dataset_select" name="'+div_name+'_dataset_select" >';
79 html += '<option value="">'+empty_element+'</option>\n';
81 for (var n=0; n<datasets.length; n++) {
82 html += '<option value='+datasets[n][0]+'>'+datasets[n][1]+'</option>';
85 html = '<div class="input-group">'+html+'</select><span class="input-group-btn"><button class="btn btn-default" type="button" id="'+div_name+'_dataset_refresh" title="Refresh datasets" onclick="refreshDatasetSelect(\''+div_name+'_dataset_select\',\'Options refreshed.\')"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span></button></span></div>';
89 html = html + '</select>';
94 renderDatasets: function(div) {
95 var datasets = this.getDatasets();
98 if (!datasets || datasets.length===0) {
100 jQuery('#'+div+'_div').html(html);
104 html += '<table class="table table-hover table-condensed">';
105 html += '<thead><tr><th>Dataset Name</th><th>Description</th><th colspan="4">Actions</th></tr></thead><tbody><tr>';
106 for (var i = 0; i < datasets.length; i++) {
107 html += '<td><b>'+datasets[i][1]+'</b></td>';
108 html += '<td>'+datasets[i][2]+'</td>';
109 html += '<td><a title="View" id="view_dataset_'+datasets[i][1]+'" href="javascript:showDatasetItems(\'dataset_item_dialog\','+datasets[i][0]+')"><span class="glyphicon glyphicon-th-list"></span></a></td>';
110 html += '<td><a title="Delete" id="delete_dataset_'+datasets[i][1]+'" href="javascript:deleteDataset('+datasets[i][0]+')"><span class="glyphicon glyphicon-remove"></span></a></td></tr>';
112 html = html + '</tbody></table>';
113 html += '<div id="list_group_select_action"></div>';
115 jQuery('#'+div+'_div').html(html);
118 renderItems: function(div, dataset_id) {
119 var dataset = this.getDataset(dataset_id);
121 var html = "This dataset contains the following:<br />";
124 for(var key in dataset.categories) {
125 if (dataset.categories.hasOwnProperty(key)) {
126 if (dataset.categories[key]===null || dataset.categories[key].length===0) {
130 html += dataset.categories[key].length+" elements of type <b>"+key+"</b><br />";
135 if (zero_count === Object.keys(dataset.categories).length) {
136 jQuery('#'+div).html("This dataset does not contain any selections.");
139 jQuery('#'+div).html(html);
144 function refreshDatasetSelect(div_name, empty_element) {
145 var l = new CXGN.Dataset();
146 var datasets = l.getDatasets();
149 html += '<option value="">'+empty_element+'</option>\n';
151 for (var n=0; n<datasets.length; n++) {
152 html += '<option value='+datasets[n][0]+'>'+datasets[n][1]+'</option>';
154 jQuery('#'+div_name).html(html);
157 function setUpDatasets() {
158 // jQuery("button[name='datasets_link']").click(
159 // function() { show_datasets(); }
163 function show_datasets() {
164 jQuery('#dataset_dialog').modal("show");
165 var l = new CXGN.Dataset();
166 l.renderDatasets('dataset_dialog');
169 function deleteDataset(dataset_id) {
170 var reply = confirm("Are you sure you want to delete the dataset with id "+dataset_id+"? Please note that deletion cannot be undone.");
174 'url' : '/ajax/dataset/delete/'+dataset_id,
175 'success': function(response) {
176 if (response.error) {
177 alert(response.error);
180 alert('Successfully deleted dataset with id '+dataset_id);
183 'error': function(response) {
184 alert('A processing error occurred.');
191 function showDatasetItems(div, dataset_id) {
193 working_modal_show();
195 var d = new CXGN.Dataset();
197 jQuery('#'+div).html('hello!');
199 d.renderItems(div, dataset_id);
201 jQuery('#'+div).modal("show");
203 working_modal_hide();