view vendor/plugins/redmine_bibliography/assets/javascripts/authors.js @ 710:7db874627e11 feature_36_js_refactoring

Refactoring author/authorship related JS.
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Wed, 21 Sep 2011 15:47:56 +0100
parents b6f9f005c0b6
children 3c1257f96b79
line wrap: on
line source
function remove_fields(link) {
    $(link).previous("input[type=hidden]").value = "1";
    $(link).up(".fields").hide();
}


function add_author_fields(link, association, content, action) {
	var new_id = new Date().getTime();
  var regexp = new RegExp("new_" + association, "g");
  $(link).insert({
		before: content.replace(regexp, new_id)
  });

	if(action != "new"){
		toggle_save_author(new_id, $(link));
	};
}



function identify_author_status(status, object_id) {
    $('publication_authorships_attributes_' + object_id + '_edit_author_info').select('input').each(function(s) {
	if(status == "no"){
	    s.value = "";
	    s.readOnly = false;
	};
	
	if(status == "correct"){s.readOnly = false;};
	if(status == "yes"){s.readOnly = true;};
    });
}

function toggle_div(div_id){	
    Effect.toggle(div_id, "appear", {duration:0.3});
}

function toggle_input_field(field){	
    if (field.classNames().inspect().include("readonly") == false){
			field.readOnly = true;	
			field.addClassName('readonly');
    } else {
			field.readOnly = false;
			field.removeClassName('readonly');
    };	
}

function toggle_edit_save_button(object_id){
    $button = $('publication_authorships_attributes_' + object_id + '_edit_save_button');
    if ($button.value == "Edit author"){
	$button.value = "Save author";
    } else {
	$button.value = "Edit author";
    };
}

function toggle_save_author(form_object_id, $this){
    $('publication_authorships_attributes_' + form_object_id + '_edit_author_info').select('input').each(function(s) {
	toggle_input_field(s, $this);
    });
    $('publication_authorships_attributes_' + form_object_id + '_edit_author_info').select('p.description').each(function(s) {
	s.toggle();
    });
    toggle_edit_save_button(form_object_id);
    toggle_div("publication_authorships_attributes_" + form_object_id +"_search_author");
}

function hide_all_bibtex_required_fields(){$$('p.bibtex').each(function(s){s.hide()})}

// entrytype_fields is a jsno array with the fields requires by the selected bibtex entry 
function show_required_bibtex_fields(entrytype_fields) {
	$$('p.bibtex').each(function(s){
		if(entrytype_fields.indexOf(s.down('input').id.split('_').last()) != -1){
			s.show();
			}
		else {
			s.hide();
			}
	})
}


// 
// 
// 
Event.observe(window, 'load', function() {

	// All page's functions
	var Publication = {
		init: function(){
			var self = this;
			var authorshipButton = $('add_another_author');						
			
			authorshipButton.observe('click', function(event){
				self.addAuthorship();
			});
		},
		
		addAuthorship: function(){
			Publication.Authorships.add()
		}
		
		// $(this).previous('div').down('.edit-save-button').observe('click', function(event){
		    //	  alert(Event.element(event).innerHTML);
		//		alert($(this).id);
		//	 })
	
	
	// ~ Pulication.Authorships					
	};


	Publication.Authorships = {
		init: function(){
			var self = this;
									
		},
		
		add: function(){
			alert("Button Pressed");
		},
		
		
		state: 'edit'	
	// ~ Pulication.Authorships	
	};


	// main
	Publication.init();


// ~ Event.observe	
});