Changeset 976 for trunk/web-app
- Timestamp:
- Oct 21, 2010, 5:28:04 PM (10 years ago)
- Location:
- trunk/web-app
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/web-app/css/wizard.css
r959 r976 385 385 } 386 386 387 .wizard ul.publication_list, .wizard ul.contact_list {387 .wizard ul.publication_list, .wizard ul.contact_list, .wizard ul.user_list { 388 388 list-style-type: none; 389 389 margin: -10px 0 0 255px; … … 391 391 } 392 392 393 .wizard ul.publication_list li, .wizard ul.contact_list li {393 .wizard ul.publication_list li, .wizard ul.contact_list li, .wizard ul.user_list li { 394 394 margin-left: 0px; 395 395 padding: 4px 6px; -
trunk/web-app/js/wizard.js
r959 r976 382 382 } 383 383 384 385 384 /************************************************* 386 385 * … … 674 673 } 675 674 675 /************************************************* 676 * 677 * Functions for adding users (readers or writers) to the study 678 * 679 ************************************************/ 680 681 /** 682 * Adds a user to the study using javascript 683 */ 684 function addUser( element_id ) { 685 /* Find publication ID and add to form */ 686 id = parseInt( $("#" + element_id + "_form select").val() ); 687 688 // Put the ID in the array, but only if it does not yet exist 689 var ids = getUserIds( element_id ); 690 691 if( $.inArray (id, ids ) == -1 ) { 692 ids[ ids.length ] = id; 693 $( '#' + element_id + '_ids' ).val( ids.join( ',' ) ); 694 695 // Show the title and a remove button 696 showUser( element_id, id, $("#" + element_id + "_form select option:selected").text(), ids.length - 1 ); 697 698 // Hide the 'none box' 699 $( '#' + element_id + '_none' ).css( 'display', 'none' ); 700 } 701 702 return false; 703 } 704 705 /** 706 * Removes a user from the study using javascript 707 * N.B. The deletion must be handled in grails when the form is submitted 708 */ 709 function removeUser( element_id, id ) { 710 var ids = getUserIds( element_id ); 711 if( $.inArray(id, ids ) != -1 ) { 712 // Remove the ID 713 ids.splice($.inArray(id, ids ), 1); 714 $( '#' + element_id + '_ids' ).val( ids.join( ',' ) ); 715 716 // Remove the title from the list 717 var li = $( "#" + element_id + '_item_' + id ); 718 if( li ) { 719 li.remove(); 720 } 721 722 // Show the 'none box' if needed 723 if( ids.length == 0 ) { 724 $( '#' + element_id + '_none' ).css( 'display', 'inline' ); 725 } 726 727 } 728 } 729 730 /** 731 * Returns an array of user IDs currently attached to the study 732 * The array contains integers 733 */ 734 function getUserIds( element_id ) { 735 var ids = $( '#' + element_id + '_ids' ).val(); 736 if( ids == "" ) { 737 return new Array(); 738 } else { 739 ids_array = ids.split( ',' ); 740 for( var i = 0; i < ids_array.length; i++ ) { 741 ids_array[ i ] = parseInt( ids_array[ i ] ); 742 } 743 744 return ids_array; 745 } 746 } 747 748 /** 749 * Shows a publication on the screen 750 */ 751 function showUser( element_id, id, username, nr ) { 752 var deletebutton = document.createElement( 'img' ); 753 deletebutton.className = 'famfamfam delete_button'; 754 deletebutton.setAttribute( 'alt', 'remove this user' ); 755 deletebutton.setAttribute( 'src', baseUrl + '/images/icons/famfamfam/delete.png' ); 756 deletebutton.onclick = function() { removeUser( element_id, id ); return false; }; 757 758 var titleDiv = document.createElement( 'div' ); 759 titleDiv.className = 'username' ; 760 titleDiv.appendChild( document.createTextNode( username ) ); 761 762 var li = document.createElement( 'li' ); 763 li.setAttribute( 'id', element_id + '_item_' + id ); 764 li.className = nr % 2 == 0 ? 'even' : 'odd'; 765 li.appendChild( deletebutton ); 766 li.appendChild( titleDiv ); 767 768 $( '#' + element_id + '_list' ).append( li ); 769 } 770 771 /** 772 * Creates the dialog for searching a publication 773 */ 774 function createUserDialog( element_id ) { 775 /* Because of the AJAX loading of this page, the dialog will be created 776 * again, when the page is reloaded. This raises problems when reading the 777 * values of the selected publication. For that reason we check whether the 778 * dialog already exists 779 */ 780 if( $( "." + element_id + "_user_dialog" ).length == 0 ) { 781 $("#" + element_id + "_dialog").dialog({ 782 title : "Add user", 783 autoOpen: false, 784 width : 800, 785 height : 400, 786 modal : true, 787 dialogClass : element_id + "_user_dialog", 788 position: "center", 789 buttons : { 790 Add : function() { addUser( element_id ); $(this).dialog("close"); }, 791 Close : function() { $(this).dialog("close"); } 792 }, 793 close : function() { 794 /* closeFunc(this); */ 795 } 796 }).width(790).height(400); 797 } else { 798 /* If a dialog already exists, remove the new div */ 799 $("#" + element_id + "_dialog").remove(); 800 } 801 } 802 803 /** 804 * Opens the dialog for searching a publication 805 */ 806 function openUserDialog( element_id ) { 807 // Empty input field 808 var field = $( '#' + element_id ); 809 field.val( '' ); 810 811 // Show the dialog 812 $( '#' + element_id + '_dialog' ).dialog( 'open' ); 813 field.focus(); 814 815 // Disable 'Add' button 816 //enableButton( '.' + element_id + '_user_dialog', 'Add', false ); 817 }
Note: See TracChangeset
for help on using the changeset viewer.