1 //require <jquery.packed.js>
  2 //require <jquery-ui.min.js>
  3 //require-css <jquery-ui/jquery-ui.css>
  4 (function(){
  5 	
  6 	var $ = jQuery;
  7 	
  8 	
  9 	$(document).ready(function(){
 10 		var form = document.getElementById('copy_replace_form');
 11 		var fields= form.elements['-copy_replace:fields'];
 12 		var fieldSelector = $('#xf-copy-replace-fields-select');
 13 		
 14 		
 15 		var helpButton = $('#df-copy-replace-help-button');
 16 		
 17 		helpButton.click(function(){
 18 		
 19 			var dlg = document.createElement('div');
 20 			$(dlg).load(DATAFACE_URL+'/help/update_records.html', function(){
 21 				$('body').append(dlg);
 22 				$(dlg).dialog({
 23 					title: 'Update Form Help',
 24 					width: $(window).width()-10,
 25 					height: $(window).height()-10
 26 				});
 27 			});
 28 			return false;
 29 		});
 30 		
 31 			
 32 			
 33 		$('tr.xf-copy-replace-field-row').each(function(){
 34 			var removeFieldBtn = $('button.xf-remove-field', this);
 35 			var fld = $(this).attr('data-xf-update-field');
 36 			var label = $('option[value="'+fld+'"]', fieldSelector).text();
 37 			var input = $('[data-xf-field]', this);
 38 
 39 			var tr = this;
 40 			$(removeFieldBtn).click(function(){
 41 
 42 				$(tr).hide();
 43 				fieldSelector.append($('<option/>').attr('value',fld).text(label));
 44 				
 45 				var vals = fields.value.split('-');
 46 				var newvals = [];
 47 				$.each(vals, function(){
 48 					if ( this != fld ) newvals.push(this);
 49 				});
 50 				fields.value = newvals.join('-');
 51 				return false;
 52 				
 53 			});
 54 			
 55 			
 56 			
 57 			
 58 		});
 59 			
 60 		$('tr.xf-update-default').each(function(){
 61 		
 62 			
 63 			
 64 			$(this)
 65 				.css('display','');
 66 				
 67 			
 68 			var fld = $(this).attr('data-xf-update-field');
 69 			var label = $('option[value="'+fld+'"]', fieldSelector).text();
 70 			
 71 			if ( fields.value ) fields.value += '-'+fld;
 72 			else fields.value = fld;
 73 			
 74 			$('option[value="'+fld+'"]', fieldSelector).remove();
 75 			
 76 			
 77 			
 78 			
 79 			
 80 			
 81 
 82 			
 83 		});
 84 		
 85 		
 86 		
 87 		
 88 		
 89 	});
 90 	
 91 })();