/* * Unified file for catalogue edition */ /* Functions developed for addbiblio.tt and authorities.tt */ // returns the fieldcode based upon tag div id function getFieldCode(tagDivId){ // format : tag__... return tagDivId.substr(3+1,3); } //returns the field and subfieldcode based upon subfield div id function getFieldAndSubfieldCode(subfieldDivId){ // format : subfield... return subfieldDivId.substr(8,3+1); } //returns the subfieldcode based upon subfieldid writing function getSubfieldCode(tagsubfieldid){ // 3 : tag +3 : tagnumber +4 : number of _ +8 subfield -1 begins at 0 return tagsubfieldid.substr(3+3+4+8-1,1); } // Take the base of tagsubfield information (removing the subfieldcodes and subfieldindexes) // returns the filter function getTagInputnameFilter(tagsubfieldid){ var tagsubfield=tagsubfieldid.substr(0,tagsubfieldid.lastIndexOf("_")); var tagcode=tagsubfield.substr(tagsubfield.lastIndexOf("_")); tagsubfield=tagsubfield.substr(0,tagsubfield.lastIndexOf("_")); tagsubfield=tagsubfield.substr(0,tagsubfield.lastIndexOf("_")); tagsubfield=tagsubfield+"_."+tagcode; return tagsubfield; } // if source is "auth", we are editing an authority otherwise it is a biblio function openAuth(tagsubfieldid,authtype,source) { // let's take the base of tagsubfield information (removing the indexes and the codes var element=document.getElementById(tagsubfieldid); var tagsubfield=getTagInputnameFilter(tagsubfieldid); var elementsubfcode=getSubfieldCode(element.name); var mainmainstring=element.value; var mainstring=""; var inputs = element.parentNode.parentNode.getElementsByTagName("input"); for (var myindex =0; myindex var divs = original.getElementsByTagName('div'); for(var i=0,divslen = divs.length ; i show all subfields divs[i].style.display = 'block'; } else if (divs[i].style.display == 'none') { // show divs[i].style.display = 'block'; } else { // hide divs[i].style.display = 'none'; } } } } /** * To clone a field * @param hideMarc '0' for false, '1' for true * @param advancedMARCEditor '0' for false, '1' for true */ function CloneField(index, hideMarc, advancedMARCEditor) { var original = document.getElementById(index); //original
var clone = original.cloneNode(true); var new_key = CreateKey(); var new_id = original.getAttribute('id')+new_key; clone.setAttribute('id',new_id); // setting a new id for the parent div var divs = clone.getElementsByTagName('div'); // if hide_marc, indicators are hidden fields // setting a new name for the new indicator for(var i=0; i < 2; i++) { var indicator = clone.getElementsByTagName('input')[i]; indicator.setAttribute('name',indicator.getAttribute('name')+new_key); } // settings all subfields for(var i=0,divslen = divs.length ; i var clone = original.cloneNode(true); var new_key = CreateKey(); // set the attribute for the new 'div' subfields var inputs = clone.getElementsByTagName('input'); var selects = clone.getElementsByTagName('select'); var textareas = clone.getElementsByTagName('textarea'); var linkid; // input var id_input = ""; for(var i=0,len=inputs.length; i 1) { canUnclone = true; } } else { // unclone a subfield, check if there will remain one subfield var subfieldCode = getFieldAndSubfieldCode(index); // subfield divs of same field with id begining with original field and subfield field code var cloneSubfields = $(original).parent().children('.subfield_line[id^="subfield'+subfieldCode+'"]'); if (cloneSubfields.length > 1) { canUnclone = true; } } if (canUnclone) { // remove clone original.parentNode.removeChild(original); } else { // clear inputs, but don't delete $(":input.input_marceditor", original).each(function(){ // thanks to http://www.learningjquery.com/2007/08/clearing-form-data for // hint about clearing selects correctly var type = this.type; var tag = this.tagName.toLowerCase(); if (type == 'text' || type == 'password' || tag == 'textarea') { this.value = ""; } else if (type == 'checkbox' || type == 'radio') { this.checked = false; } else if (tag == 'select') { this.selectedIndex = -1; } }); $(":input.indicator", original).val(""); } } /** * This function create a random number */ function CreateKey(){ return parseInt(Math.random() * 100000); } /** * This function allows to move a subfield up by clickink on the 'up' button . */ function upSubfield(index) { try{ var line = document.getElementById(index); // get the line where the user has clicked. } catch(e) { return; // this line doesn't exist... } var tag = line.parentNode; // get the dad of this line. (should be "
") // getting all subfields for this tag var subfields = tag.getElementsByTagName('div'); var subfieldsLength = subfields.length; if(subfieldsLength<=1) return; // nothing to do if there is just one subfield. // among all subfields for(var i=0;i * @param original subfield div to clone */ function CloneItemSubfield(original){ var clone = original.cloneNode(true); var new_key = CreateKey(); // set the attribute for the new 'div' subfields var inputs = clone.getElementsByTagName('input'); var selects = clone.getElementsByTagName('select'); var textareas = clone.getElementsByTagName('textarea'); // input (except hidden type) var id_input = ""; for(var i=0,len=inputs.length; imissing class to those who are empty.
* @param p the parent object of subfields to check * @return the number of empty mandatory subfields */ function CheckMandatorySubfields(p){ var total = 0; $(p).find(".subfield_line input[name='mandatory'][value='1']").each(function(i){ var editor = $(this).siblings("[name='field_value']"); if (!editor.val()) { editor.addClass("missing"); total++; } }); return total; } $(document).ready(function() { $("input.input_marceditor, input.indicator").addClass('noEnterSubmit'); });