6 CXGN.List - a javascript library to implement the lists on the SGN platform
10 There are two important list functions in this library, listed below. All other functions should be considered private and/or deprecated.
13 * addToListMenu(listMenuDiv, dataDiv)
15 this function will generate a select of all available lists and allow the content to be added to a list (from a search, etc). The first parameter is the id of the div tag where the menu should be drawn. The second parameter is the div that contains the data to be added. This can be a textfield, a div or span tag, or a multiple select tag.
17 * pasteListMenu(divName, menuDiv, buttonName)
19 this will generate an html select box of all the lists, and a "paste" button, to paste into a textarea (typically). The divName is the id of the textarea, the menuDiv is the id where the paste menu should be placed.
22 Public List object functions
24 * listSelect(divName, types)
26 will create an html select with id and name 'divName'. Optionally, a list of types can be specified that will limit the menu to the respective types.
29 You have to instantiate the list object first:
31 var lo = new CXGN.List(); var s = lo.listSelect('myseldiv', [ 'trials' ]);
34 * validate(list_id, type, non_interactive)
36 * transform(list_id, new_type)
41 Lukas Mueller <lam87@cornell.edu>
47 //JSAN.use('jqueryui');
49 if (!CXGN) CXGN = function () { };
51 CXGN.List = function () {
56 CXGN.List.prototype = {
58 // Return the data as a straight list
60 getList: function(list_id) {
64 url: '/list/contents/'+list_id,
66 success: function(response) {
68 //document.write(response.error);
74 error: function(response) {
75 alert("An error occurred.");
83 // this function also returns some metadata about
84 // list, namely its type.
86 getListData: function(list_id) {
92 data: { 'list_id': list_id },
93 success: function(response) {
95 alert(response.error);
106 getListType: function(list_id) {
110 url: '/list/type/'+list_id,
112 success: function(response) {
113 if (response.error) {
114 alert(response.error);
117 type = response.list_type;
122 alert('An error occurred. Cannot determine type. ');
129 setListType: function(list_id, type) {
132 url: '/list/type/'+list_id+'/'+type,
134 success: function(response) {
135 if (response.error) {
136 alert(response.error);
139 //alert('Type of list '+list_id+' set to '+type);
146 allListTypes: function() {
149 url: '/list/alltypes',
151 success: function(response) {
152 if (response.error) {
153 alert(response.error);
164 typesHtmlSelect: function(list_id, html_select_id, selected) {
165 var types = this.allListTypes();
166 var html = '<select class="form-control" id="'+html_select_id+'" onchange="javascript:changeListType(\''+html_select_id+'\', '+list_id+');" >';
167 html += '<option name="null">(none)</option>';
168 for (var i=0; i<types.length; i++) {
169 var selected_html = '';
170 if (types[i][1] == selected) {
171 selected_html = ' selected="selected" ';
173 html += '<option name="'+types[i][1]+'"'+selected_html+'>'+types[i][1]+'</option>';
179 newList: function(name) {
180 var oldListId = this.existsList(name);
184 alert('Please provide a name for the new list.');
188 if (oldListId === null) {
192 data: { 'name': name },
193 success: function(response) {
194 if (response.error) {
195 alert(response.error);
198 newListId=response.list_id;
205 alert('A list with name "'+ name + '" already exists. Please choose another list name.');
208 alert("An error occurred. Cannot create new list right now.");
212 availableLists: function(list_type) {
215 url: '/list/available',
216 data: { 'type': list_type },
218 success: function(response) {
219 if (response.error) {
220 //alert(response.error); //do not alert here
224 error: function(response) {
225 alert("An error occurred");
231 publicLists: function(list_type) {
234 url: '/list/available_public',
235 data: { 'type': list_type },
237 success: function(response) {
238 if (response.error) {
239 alert(response.error);
243 error: function(response) {
244 alert("An error occurred");
250 //return the newly created list_item_id or 0 if nothing was added
251 //(due to duplicates)
252 addItem: function(list_id, item) {
253 var exists_item_id = this.existsItem(list_id,item);
254 if (exists_item_id ===0 ) {
257 url: '/list/item/add',
258 data: { 'list_id': list_id, 'element': item },
259 success: function(response) {
260 if (response.error) {
261 alert(response.error);
266 var new_list_item_id = this.existsItem(list_id,item);
267 return new_list_item_id;
272 addBulk: function(list_id, items) {
274 var elements = items.join("\t");
280 url: '/list/add/bulk',
281 data: { 'list_id': list_id, 'elements': elements },
282 success: function(response) {
283 if (response.error) {
284 alert(response.error);
287 if (response.duplicates) {
288 alert("The following items are already in the list and were not added: "+response.duplicates.join(", "));
290 count = response.success;
297 removeItem: function(list_id, item_id) {
300 url: '/list/item/remove',
301 data: { 'list_id': list_id, 'item_id': item_id }
305 deleteList: function(list_id) {
309 data: { 'list_id': list_id }
313 renderLists: function(div) {
314 var lists = this.availableLists();
316 html = html + '<div class="input-group"><input id="add_list_input" type="text" class="form-control" placeholder="Create New List" /><span class="input-group-btn"><button class="btn btn-primary" type="button" id="add_list_button" value="new list">New List</button></span></div><br/>';
318 if (lists.length===0) {
319 html = html + "None";
320 jQuery('#'+div+'_div').html(html);
323 html += '<table class="table table-hover table-condensed">';
324 html += '<thead><tr><th> </th><th>List Name</th><th>Count</th><th>Type</th><th colspan="4">Actions</th></tr></thead><tbody>';
325 for (var i = 0; i < lists.length; i++) {
326 html += '<tr><td><input type="checkbox" name="list_select_checkbox" value="'+lists[i][0]+'"/></td>';
327 html += '<td><b>'+lists[i][1]+'</b></td>';
328 html += '<td>'+lists[i][3]+'</td>';
329 html += '<td>'+lists[i][5]+'</td>';
330 html += '<td><a title="View" id="view_list_'+lists[i][1]+'" href="javascript:showListItems(\'list_item_dialog\','+lists[i][0]+')"><span class="glyphicon glyphicon-th-list"></span></a></td>';
331 html += '<td><a title="Delete" id="delete_list_'+lists[i][1]+'" href="javascript:deleteList('+lists[i][0]+')"><span class="glyphicon glyphicon-remove"></span></a></td>';
332 html += '<td><a target="_blank" title="Download" id="download_list_'+lists[i][1]+'" href="/list/download?list_id='+lists[i][0]+'"><span class="glyphicon glyphicon-arrow-down"></span></a></td>';
333 if (lists[i][6] == 0){
334 html += '<td><a title="Make Public" id="share_list_'+lists[i][1]+'" href="javascript:togglePublicList('+lists[i][0]+')"><span class="glyphicon glyphicon-share-alt"></span></a></td></tr>';
335 } else if (lists[i][6] == 1){
336 html += '<td><a title="Make Private" id="share_list_'+lists[i][1]+'" href="javascript:togglePublicList('+lists[i][0]+')"><span class="glyphicon glyphicon-ban-circle"></span></a></td></tr>';
339 html = html + '</tbody></table>';
340 html += '<div id="list_group_select_action"></div>';
342 jQuery('#'+div+'_div').html(html);
344 jQuery('#add_list_button').click(function() {
345 var lo = new CXGN.List();
347 var name = jQuery('#add_list_input').val();
353 jQuery('#view_public_lists_button').click(function() {
354 jQuery('#public_list_dialog').modal('show');
355 var lo = new CXGN.List();
356 lo.renderPublicLists('public_list_dialog_div');
359 jQuery("input[name='list_select_checkbox']").click(function() {
360 var total=jQuery("input[name='list_select_checkbox']:checked").length;
361 var list_group_select_action_html='';
363 list_group_select_action_html += '';
366 $("input:checkbox:checked").each(function() {
367 selected.push($(this).attr('value'));
370 list_group_select_action_html = '<hr><div class="row well well-sm"><div class="col-sm-4">For Selected Lists:</div><div class="col-sm-8">';
372 list_group_select_action_html += '<a class="btn btn-default btn-sm" style="color:white" href="javascript:deleteSelectedListGroup(['+selected+'])">Delete</a><a class="btn btn-default btn-sm" style="color:white" href="javascript:makePublicSelectedListGroup(['+selected+'])">Make Public</a><a class="btn btn-default btn-sm" style="color:white" href="javascript:makePrivateSelectedListGroup(['+selected+'])">Make Private</a>';
373 } else if (total > 1) {
374 list_group_select_action_html += '<a class="btn btn-default btn-sm" style="color:white" href="javascript:deleteSelectedListGroup(['+selected+'])">Delete</a><a class="btn btn-default btn-sm" style="color:white" href="javascript:makePublicSelectedListGroup(['+selected+'])">Make Public</a><a class="btn btn-default btn-sm" style="color:white" href="javascript:makePrivateSelectedListGroup(['+selected+'])">Make Private</a><br/><br/><div class="input-group input-group-sm"><input type="text" class="form-control" id="new_combined_list_name" placeholder="New List Name"><span class="input-group-btn"><a class="btn btn-default btn-sm" style="color:white" href="javascript:combineSelectedListGroup(['+selected+'])">Combine</a></span></div>';
376 list_group_select_action_html += '</div></div>';
378 jQuery("#list_group_select_action").html(list_group_select_action_html);
382 renderPublicLists: function(div) {
383 var lists = this.publicLists();
386 html += '<table id="public_list_data_table" class="table table-hover table-condensed">';
387 html += '<thead><tr><th>List Name</th><th>Count</th><th>Type</th><th>Actions</th><th> </th><th> </th></tr></thead><tbody>';
388 for (var i = 0; i < lists.length; i++) {
389 html += '<tr><td><b>'+lists[i][1]+'</b></td>';
390 html += '<td>'+lists[i][3]+'</td>';
391 html += '<td>'+lists[i][5]+'</td>';
392 html += '<td><a title="View" id="view_public_list_'+lists[i][1]+'" href="javascript:showPublicListItems(\'list_item_dialog\','+lists[i][0]+')"><span class="glyphicon glyphicon-th-list"></span></a></td>';
393 html += '<td><a target="_blank" title="Download" id="download_public_list_'+lists[i][1]+'" href="/list/download?list_id='+lists[i][0]+'"><span class="glyphicon glyphicon-arrow-down"></span></a></td>';
394 html += '<td><a title="Copy to Your Lists" id="copy_public_list_'+lists[i][1]+'" href="javascript:copyPublicList('+lists[i][0]+')"><span class="glyphicon glyphicon-plus"></span></a></td>';
396 html = html + '</tbody></table>';
398 jQuery('#'+div).html(html);
400 jQuery('#public_list_data_table').DataTable({
402 "columnDefs": [ { "orderable": false, "targets": [3,4,5] } ]
406 listNameById: function(list_id) {
407 lists = this.availableLists();
408 for (var n=0; n<lists.length; n++) {
409 if (lists[n][0] == list_id) { return lists[n][1]; }
413 publicListNameById: function(list_id) {
414 lists = this.publicLists();
415 for (var n=0; n<lists.length; n++) {
416 if (lists[n][0] == list_id) { return lists[n][1]; }
420 renderItems: function(div, list_id) {
421 var list_data = this.getListData(list_id);
422 var items = list_data.elements;
423 var list_type = list_data.type_name;
424 var list_name = this.listNameById(list_id);
427 html += '<table class="table"><tr><td>List ID</td><td id="list_id_div">'+list_id+'</td></tr>';
428 html += '<tr><td>List name:<br/><input type="button" class="btn btn-primary btn-xs" id="updateNameButton" value="Update" /></td>';
429 html += '<td><input class="form-control" type="text" id="updateNameField" size="10" value="'+list_name+'" /></td></tr>';
430 html += '<tr><td>Type:<br/><input id="list_item_dialog_validate" type="button" class="btn btn-primary btn-xs" value="Validate" onclick="javascript:validateList('+list_id+',\'type_select\')" /></td><td>'+this.typesHtmlSelect(list_id, 'type_select', list_type)+'</td></tr>';
431 html += '<tr><td>Add New Items:<br/><button class="btn btn-primary btn-xs" type="button" id="dialog_add_list_item_button" value="Add">Add</button></td><td><textarea id="dialog_add_list_item" type="text" class="form-control" placeholder="Add Item To List" /></textarea></td></tr></table>';
433 html += '<table id="list_item_dialog_datatable" class="table table-condensed table-hover table-bordered"><thead style="display: none;"><tr><th><b>List items</b> ('+items.length+')</th><th> </th></tr></thead><tbody>';
435 for(var n=0; n<items.length; n++) {
436 html = html +'<tr><td>'+ items[n][1] + '</td><td><input id="'+items[n][0]+'" type="button" class="btn btn-default btn-xs" value="Remove" /></td></tr>';
438 html += '</tbody></table>';
440 jQuery('#'+div+'_div').html(html);
442 jQuery('#list_item_dialog_datatable').DataTable({
445 scrollCollapse: true,
449 for (var n=0; n<items.length; n++) {
450 var list_item_id = items[n][0];
452 jQuery('#'+items[n][0]).click(
454 var lo = new CXGN.List();
455 var i = lo.availableLists();
457 lo.removeItem(list_id, this.id );
458 lo.renderItems(div, list_id);
459 lo.renderLists('list_dialog');
463 jQuery('#dialog_add_list_item_button').click(
465 jQuery('#working_modal').modal("show");
466 addMultipleItemsToList('dialog_add_list_item', list_id);
467 var lo = new CXGN.List();
468 lo.renderItems(div, list_id);
469 jQuery('#working_modal').modal("hide");
473 jQuery('#updateNameButton').click(
475 var lo = new CXGN.List();
476 var new_name = jQuery('#updateNameField').val();
477 var list_id = jQuery('#list_id_div').html();
478 lo.updateName(list_id, new_name);
479 alert("Changed name to "+new_name+" for list id "+list_id);
484 renderPublicItems: function(div, list_id) {
485 var list_data = this.getListData(list_id);
486 var items = list_data.elements;
487 var list_type = list_data.type_name;
488 var list_name = this.publicListNameById(list_id);
491 html += '<table class="table"><tr><td>List ID</td><td id="list_id_div">'+list_id+'</td></tr>';
492 html += '<tr><td>List name:</td>';
493 html += '<td>'+list_name+'</td></tr>';
494 html += '<tr><td>Type:</td><td>'+list_type+'</td></tr>';
496 html += '<table id="public_list_item_dialog_datatable" class="table table-condensed table-hover table-bordered"><thead style="display: none;"><tr><th><b>List items</b> ('+items.length+')</th></tr></thead><tbody>';
497 for(var n=0; n<items.length; n++) {
498 html = html +'<tr><td>'+ items[n][1] + '</td></tr>';
500 html += '</tbody></table>';
502 jQuery('#'+div+'_div').html(html);
504 jQuery('#public_list_item_dialog_datatable').DataTable({
507 scrollCollapse: true,
512 existsList: function(name) {
517 data: { 'name': name },
518 success: function(response) {
519 list_id = response.list_id;
525 existsItem: function(list_id, name) {
528 url: '/list/exists_item',
530 data: { 'list_id' : list_id, 'name':name },
531 success: function(response) {
532 list_item_id = response.list_item_id;
538 addToList: function(list_id, text) {
542 var list = text.split("\n");
545 var info = this.addBulk(list_id, list);
551 /* listSelect: Creates an html select with lists of requested types.
554 div_name: The div_name where the select should appear
555 types: a list of list types that should be listed in the menu
556 add_empty_element: text. if present, add an empty element with the
557 provided text as description
560 listSelect: function(div_name, types, empty_element) {
561 var lists = new Array();
564 for (var n=0; n<types.length; n++) {
565 var more = this.availableLists(types[n]);
567 for (var i=0; i<more.length; i++) {
574 lists = this.availableLists();
577 var html = '<select class="form-control input-sm" id="'+div_name+'_list_select" name="'+div_name+'_list_select" >';
579 html += '<option value="">'+empty_element+'</option>\n';
581 for (var n=0; n<lists.length; n++) {
582 html += '<option value='+lists[n][0]+'>'+lists[n][1]+'</option>';
584 html = html + '</select>';
588 updateName: function(list_id, new_name) {
590 url: '/list/name/update',
592 data: { 'name' : new_name, 'list_id' : list_id },
593 success: function(response) {
594 if (response.error) {
595 alert(response.error);
599 alert("The name of the list was changed to "+new_name);
602 error: function(response) { alert("An error occurred."); }
604 this.renderLists('list_dialog');
607 validate: function(list_id, type, non_interactive) {
608 var missing = new Array();
611 url: '/list/validate/'+list_id+'/'+type,
613 success: function(response) {
614 if (response.error) {
615 alert(response.error);
618 missing = response.missing;
621 error: function(response) { alert("An error occurred while validating the list "+list_id); error=1; }
624 if (error === 1 ) { return; }
626 if (missing.length==0) {
627 if (!non_interactive) { alert("This list passed validation."); }
631 alert("List validation failed. Elements not found: "+ missing.join(","));
636 transform: function(list_id, transform_name) {
637 var transformed = new CXGN.List();
639 url: '/list/transform/'+list_id+'/'+transform_name,
641 success: function(response) {
642 if (response.error) {
643 alert(response.error);
646 transformed = response.transform;
649 error: function(response) { alert("An error occurred while validating the list "+list_id); }
653 transform2Ids: function(list_id) {
654 var list_type = this.getListType(list_id);
656 if (list_type == 'traits') { new_type = 'trait_ids'; }
657 if (list_type == 'locations') { new_type = 'location_ids'; }
658 if (list_type == 'trials') { new_type = 'project_ids'; }
659 if (list_type == 'projects') { new_type = 'project_ids'; }
660 if (list_type == 'plots') { new_type = 'plot_ids'; }
661 if (list_type == 'accessions') { new_type = 'accession_ids'; }
664 return { 'error' : "cannot convert the list because of unknown type" };
667 var transformed = this.transform(list_id, new_type);
669 return { 'transformed' : transformed };
675 function setUpLists() {
676 jQuery("button[name='lists_link']").click(
677 function() { show_lists(); }
682 function show_lists() {
683 jQuery('#list_dialog').modal("show");
685 var l = new CXGN.List();
686 l.renderLists('list_dialog');
690 function pasteListMenu (div_name, menu_div, button_name) {
691 var lo = new CXGN.List();
695 if (button_name === undefined) {
696 button_name = 'paste';
699 html = lo.listSelect(div_name);
700 html = html + '<button class="btn btn-info btn-sm" type="button" value="'+button_name+'" onclick="javascript:pasteList(\''+div_name+'\')" >'+button_name+'</button>';
702 jQuery('#'+menu_div).html(html);
705 function pasteList(div_name) {
706 var lo = new CXGN.List();
707 var list_name = jQuery('#'+div_name+'_list_select').val();
708 var list_content = lo.getList(list_name);
712 for (var n=0; n<list_content.length; n++) {
713 list_text = list_text + list_content[n][1]+"\r\n";
715 jQuery('#'+div_name).text(list_text);
722 * listMenuDiv - the name of the div where the menu will be displayed
723 * dataDiv - the div from which the data will be copied (can be a div, textarea, or html select
724 * options - optional hash with the following keys:
725 - selectText: if the dataDiv is an html select and selectText is true, the text and not the value will be copied into the list
726 - listType: the type of lists to display in the menu
727 - typesSourceDiv: obtain the type from this source div
732 function addToListMenu(listMenuDiv, dataDiv, options) {
733 var lo = new CXGN.List();
742 if (options.selectText) {
743 selectText = options.selectText;
745 if (options.typeSourceDiv) {
746 var sourcetype = getData(options.typeSourceDiv, selectText);
748 type = sourcetype.replace(/(\n|\r)+$/, '');
751 if (options.listType) {
752 type = options.listType;
755 html = '<div class="row"><div class="col-sm-6" style="margin-right:0px; padding-right:0px;"><input class="form-control input-sm" type="text" id="'+dataDiv+'_new_list_name" placeholder="New list..." />';
756 html += '</div><div class="col-sm-6" style="margin-left:0px; padding-left:0px; margin-right:0px; padding-right:0px;"><input type="hidden" id="'+dataDiv+'_list_type" value="'+type+'" />';
757 html += '<input class="btn btn-primary btn-sm" id="'+dataDiv+'_add_to_new_list" type="button" value="add to new list" /></div></div><br />';
759 html += '<div class="row"><div class="col-sm-6" style="margin-right:0px; padding-right:0px;">'+lo.listSelect(dataDiv, [ type ]);
761 html += '</div><div class="col-sm-6" style="margin-left:0px; padding-left:0px; margin-right:0px; padding-right:0px;"><input class="btn btn-primary btn-sm" id="'+dataDiv+'_button" type="button" value="add to list" /></div></div>';
763 jQuery('#'+listMenuDiv).html(html);
767 jQuery('#'+dataDiv+'_add_to_new_list').click(
769 var lo = new CXGN.List();
770 var new_name = jQuery('#'+dataDiv+'_new_list_name').val();
771 var type = jQuery('#'+dataDiv+'_list_type').val();
773 var data = getData(dataDiv, selectText);
775 list_id = lo.newList(new_name);
777 var elementsAdded = lo.addToList(list_id, data);
778 if (type) { lo.setListType(list_id, type); }
779 alert("Added "+elementsAdded+" list elements to list "+new_name+" and set type to "+type);
784 jQuery('#'+dataDiv+'_button').click(
786 var data = getData(dataDiv, selectText);
787 list_id = jQuery('#'+dataDiv+'_list_select').val();
788 var lo = new CXGN.List();
789 var elementsAdded = lo.addToList(list_id, data);
791 alert("Added "+elementsAdded+" list elements");
800 function getData(id, selectText) {
801 var divType = jQuery("#"+id).get(0).tagName;
804 if (divType == 'DIV' || divType =='SPAN' || divType === undefined) {
805 data = jQuery('#'+id).html();
807 if (divType == 'SELECT' && selectText) {
808 if (jQuery.browser.msie) {
809 // Note: MS IE unfortunately removes all whitespace
810 // in the jQuery().text() call. Program it out...
812 var selectbox = document.getElementById(id);
813 var datalist = new Array();
814 for (var n=0; n<selectbox.length; n++) {
815 if (selectbox.options[n].selected) {
816 var x=selectbox.options[n].text;
820 data = datalist.join("\n");
821 //alert("data:"+data);
825 data = jQuery('#'+id+" option:selected").text();
829 if (divType == 'SELECT' && ! selectText) {
830 var return_data = jQuery('#'+id).val();
832 if (return_data instanceof Array) {
833 data = return_data.join("\n");
839 if (divType == 'TEXTAREA') {
840 data = jQuery('textarea#'+id).val();
847 function addTextToListMenu(div) {
848 var lo = new CXGN.List();
849 var html = lo.listSelect(div);
850 html = html + '<input id="'+div+'_button" type="button" value="add to list" />';
852 document.write(html);
854 jQuery('#'+div+'_button').click(
856 var text = jQuery('textarea#div').val();
857 var list_id = jQuery('#'+div+'_list_select').val();
858 lo.addToList(list_id, text);
859 lo.renderLists('list_dialog');
865 function addSelectToListMenu(div) {
866 var lo = new CXGN.List();
867 var html = lo.listSelect(div);
868 html = html + '<input id="'+div+'_button" type="button" value="add to list" />';
870 document.write(html);
872 jQuery('#'+div+'_button').click(
874 var selected_items = jQuery('#'+div).val();
875 var list_id = jQuery('#'+div+'_list_select').val();
876 addArrayToList(selected_items, list_id);
877 lo.renderLists('list_dialog');
884 // add the text in a div to a list
885 function addDivToList(div_name) {
886 var list_id = jQuery('#'+div_name+'_list_select').val();
887 var lo = new CXGN.List();
888 var list = jQuery('#'+div_name).val();
889 var items = list.split("\n");
891 for(var n=0; n<items.length; n++) {
892 var added = lo.addItem(list_id, items[n]);
898 function addTextToList(div, list_id) {
899 var lo = new CXGN.List();
900 var item = jQuery('#'+div).val();
901 var id = lo.addItem(list_id, item);
903 alert('Item "'+item+'" was not added because it already exists');
905 lo.renderLists('list_dialog');
909 function addMultipleItemsToList(div, list_id) {
910 var lo = new CXGN.List();
911 var content = jQuery('#'+div).val();
913 alert("No items - Please enter items to add to the list.");
916 // var items = content.split("\n");
918 // var duplicates = new Array();
919 var items = content.split("\n");
920 lo.addBulk(list_id, items);
921 // for (var n=0; n<items.length; n++) {
922 // var id = lo.addItem(list_id, items[n]);
924 // duplicates.push(items[n]);
927 //if (duplicates.length >0) {
928 // alert("The following items were not added because they are already in the list: "+ duplicates.join(", "));
930 lo.renderLists('list_dialog');
934 function addArrayToList(items, list_id) {
935 var lo = new CXGN.List();
936 var duplicates = new Array();
937 for (var n=0; n<items.length; n++) {
938 var id = lo.addItem(list_id, items[n]);
940 duplicates.push(items[n]);
943 if (duplicates.length >0) {
944 alert("The following items were not added because they are already in the list: "+ duplicates.join(", "));
948 function deleteList(list_id) {
949 var lo = new CXGN.List();
950 var list_name = lo.listNameById(list_id);
951 if (confirm('Delete list "'+list_name+'"? (ID='+list_id+'). This cannot be undone.')) {
952 lo.deleteList(list_id);
953 lo.renderLists('list_dialog');
954 alert('Deleted list '+list_name);
958 function togglePublicList(list_id) {
960 "url": "/list/public/toggle",
962 "data": {'list_id': list_id},
963 success: function(r) {
964 var lo = new CXGN.List();
967 } else if (r.r == 1) {
968 alert("List set to Private");
969 } else if (r.r == 0) {
970 alert("List set to Public");
972 lo.renderLists('list_dialog');
975 alert("Error Setting List to Public! List May Not Exist.");
978 var lo = new CXGN.List();
979 lo.renderLists('list_dialog');
982 function makePublicList(list_id) {
984 "url": "/list/public/true",
986 "data": {'list_id': list_id},
987 success: function(r) {
988 var lo = new CXGN.List();
994 alert("Error Setting List to Public! List May Not Exist.");
999 function makePrivateList(list_id) {
1001 "url": "/list/public/false",
1003 "data": {'list_id': list_id},
1004 success: function(r) {
1005 var lo = new CXGN.List();
1011 alert("Error Setting List to Private! List May Not Exist.");
1016 function copyPublicList(list_id) {
1018 "url": "/list/public/copy",
1020 "data": {'list_id': list_id},
1021 success: function(r) {
1024 } else if (r.success == 'true') {
1025 alert("Public List Copied to Your Lists.");
1029 alert("Error Copying Public List! List May Not Exist.");
1032 var lo = new CXGN.List();
1033 lo.renderLists('list_dialog');
1036 function deleteItemLink(list_item_id) {
1037 var lo = new CXGN.List();
1038 lo.deleteItem(list_item_id);
1039 lo.renderLists('list_dialog');
1042 function showListItems(div, list_id) {
1043 var l = new CXGN.List();
1044 jQuery('#'+div).modal("show");
1045 l.renderItems(div, list_id);
1048 function showPublicListItems(div, list_id) {
1049 var l = new CXGN.List();
1050 jQuery('#'+div).modal("show");
1051 l.renderPublicItems(div, list_id);
1054 function addNewList(div_id) {
1055 var lo = new CXGN.List();
1056 var name = jQuery('#'+div_id).val();
1059 alert("Please specify a name for the list.");
1063 var list_id = lo.existsList(name);
1065 alert('The list '+name+' already exists. Please choose another name.');
1069 lo.renderLists('list_item_dialog');
1072 function changeListType(html_select_id, list_id) {
1073 var type = jQuery('#'+html_select_id).val();
1074 var l = new CXGN.List();
1075 l.setListType(list_id, type);
1076 l.renderLists('list_dialog');
1080 validateList - check if all the elements in a list are of the correct type
1083 * list_id: the id of the list
1084 * html_select_id: the id of the html select containing the type list
1088 function validateList(list_id, html_select_id) {
1089 var lo = new CXGN.List();
1090 var type = jQuery('#'+html_select_id).val();
1091 lo.validate(list_id, type);
1094 function deleteSelectedListGroup(list_ids) {
1095 var arrayLength = list_ids.length;
1096 if (confirm('Delete the selected lists? This cannot be undone.')) {
1097 for (var i=0; i<arrayLength; i++) {
1098 var lo = new CXGN.List();
1099 lo.deleteList(list_ids[i]);
1101 lo.renderLists('list_dialog');
1105 function makePublicSelectedListGroup(list_ids) {
1106 var arrayLength = list_ids.length;
1107 if (confirm('Make selected lists public?')) {
1108 for (var i=0; i<arrayLength; i++) {
1109 makePublicList(list_ids[i]);
1111 var lo = new CXGN.List();
1112 lo.renderLists('list_dialog');
1116 function makePrivateSelectedListGroup(list_ids) {
1117 var arrayLength = list_ids.length;
1118 if (confirm('Make selected lists private?')) {
1119 for (var i=0; i<arrayLength; i++) {
1120 makePrivateList(list_ids[i]);
1122 var lo = new CXGN.List();
1123 lo.renderLists('list_dialog');
1127 function combineSelectedListGroup(list_ids) {
1128 var arrayLength = list_ids.length;
1129 var list_name = jQuery('#new_combined_list_name').val();
1130 if (confirm('Combine selected lists into a new list called '+list_name+'?')) {
1131 var lo = new CXGN.List();
1132 var new_list_id = lo.newList(list_name);
1133 for (var i=0; i<arrayLength; i++) {
1134 list = lo.getListData(list_ids[i]);
1135 var numElements = list.elements.length;
1136 var arrayItems = [];
1137 for (var j=0; j<numElements; j++) {
1138 arrayItems.push(list.elements[j][1]);
1140 lo.addBulk(new_list_id, arrayItems);
1142 lo.renderLists('list_dialog');