/* Scholar Copyright (C) 2006 Center for History and New Media, George Mason University, Fairfax, VA http://chnm.gmu.edu/ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ ScholarItemPane = new function() { var _dynamicFields; var _creatorTypeMenu; var _beforeRow; var _notesList; var _linksBox; var _notesLabel; var _creatorCount; var _loaded; var _itemBeingEdited; this.onLoad = onLoad; this.viewItem = viewItem; this.loadPane = loadPane; this.changeTypeTo = changeTypeTo; this.onOpenURLClick = onOpenURLClick; this.addCreatorRow = addCreatorRow; this.removeCreator = removeCreator; this.showEditor = showEditor; this.hideEditor = hideEditor; this.modifyField = modifyField; this.getCreatorFields = getCreatorFields; this.modifyCreator = modifyCreator; this.removeNote = removeNote; this.addNote = addNote; this.removeAttachment = removeAttachment; this.addAttachmentFromDialog = addAttachmentFromDialog; this.addAttachmentFromPage = addAttachmentFromPage; function onLoad() { _tabs = document.getElementById('scholar-view-tabs'); _dynamicFields = document.getElementById('editpane-dynamic-fields'); _itemTypeMenu = document.getElementById('editpane-type-menu'); _creatorTypeMenu = document.getElementById('creatorTypeMenu'); _notesList = document.getElementById('editpane-dynamic-notes'); _notesLabel = document.getElementById('editpane-notes-label'); _attachmentsList = document.getElementById('editpane-dynamic-attachments'); _attachmentsLabel = document.getElementById('editpane-attachments-label'); _tagsBox = document.getElementById('editpane-tags'); _relatedBox = document.getElementById('editpane-related'); var creatorTypes = Scholar.CreatorTypes.getTypes(); for(var i = 0; i < creatorTypes.length; i++) { var menuitem = document.createElement("menuitem"); menuitem.setAttribute("label",Scholar.getString('creatorTypes.'+creatorTypes[i]['name'])); menuitem.setAttribute("typeid",creatorTypes[i]['id']); if(creatorTypes[i]['id'] == 0) menuitem.setAttribute("selected",true); _creatorTypeMenu.appendChild(menuitem); } var itemTypes = Scholar.ItemTypes.getTypes(); for(var i = 0; i 0) { for(var i = 0, len=_itemBeingEdited.numCreators(); i 29 ) || firstSpace > 29) { valueElement.setAttribute('crop', 'end'); valueElement.setAttribute('value',valueText); } else valueElement.appendChild(document.createTextNode(valueText)); return valueElement; } function removeCreator(index, labelToDelete) { // If unsaved row, just remove element if (!_itemBeingEdited.hasCreatorAt(index)){ labelToDelete.parentNode.removeChild(labelToDelete); _creatorCount--; return; } _itemBeingEdited.removeCreator(index); _itemBeingEdited.save(); loadPane(0); } function showEditor(elem) { //Scholar.debug('Showing editor'); var fieldName = elem.getAttribute('fieldname'); var value = ''; var creatorFields = fieldName.split('-'); if(creatorFields[0] == 'creator') { var c = _itemBeingEdited.getCreator(creatorFields[1]); if(c) value = c[creatorFields[2]]; } else { value = _itemBeingEdited.getField(fieldName); } var t = document.createElement("textbox"); t.setAttribute('value',value); t.setAttribute('fieldname',fieldName); t.setAttribute('flex','1'); t.className = 'fieldeditor'; var box = elem.parentNode; box.replaceChild(t,elem); t.select(); t.setAttribute('onblur',"ScholarItemPane.hideEditor(this, true);"); t.setAttribute('onkeypress','if(event.keyCode == event.DOM_VK_RETURN) document.commandDispatcher.focusedElement.blur(); else if(event.keyCode == event.DOM_VK_ESCAPE) ScholarItemPane.hideEditor(document.commandDispatcher.focusedElement, false);'); //for some reason I can't just say this.blur(); } function hideEditor(t, saveChanges) { //Scholar.debug('Hiding editor'); var textbox = t.parentNode.parentNode; var fieldName = textbox.getAttribute('fieldname'); var value = t.value; var elem; var creatorFields = fieldName.split('-'); if(creatorFields[0] == 'creator') { if (saveChanges){ var otherFields = this.getCreatorFields(textbox.parentNode.parentNode.parentNode); modifyCreator(creatorFields[1], creatorFields[2], value, otherFields); } var val = _itemBeingEdited.getCreator(creatorFields[1])[creatorFields[2]]; if (!val){ // Reset to '(first)' or '(last)' if (creatorFields[2]=='lastName'){ val = "(" + Scholar.getString('pane.item.defaultLastName') + ")"; } else if (creatorFields[2]=='firstName'){ val = "(" + Scholar.getString('pane.item.defaultFirstName') + ")"; } } // Add trailing comma if (creatorFields[2]=='lastName'){ val += ','; } elem = createValueElement(val, fieldName); } else { if(saveChanges) modifyField(fieldName,value); elem = createValueElement(_itemBeingEdited.getField(fieldName),fieldName); } var box = textbox.parentNode; box.replaceChild(elem,textbox); } function modifyField(field, value) { _itemBeingEdited.setField(field,value); _itemBeingEdited.save(); } function getCreatorFields(row){ var type = row.getElementsByTagName('label')[0].getAttribute('value'); var label1 = row.getElementsByTagName('hbox')[0].firstChild.firstChild; var label2 = label1.nextSibling; // doesn't currently return creator type, since we don't need it anywhere return { lastName: label1.firstChild ? label1.firstChild.nodeValue // Strip trailing comma .substr(0, label1.firstChild.nodeValue.length-1): label1.value, firstName: label2.firstChild ? label2.firstChild.nodeValue : label2.value, typeID: Scholar.CreatorTypes.getID(type.substr(0, type.length-1).toLowerCase()), isInstitution: null // placeholder } } function modifyCreator(index, field, value, otherFields) { if (otherFields){ var firstName = otherFields.firstName; var lastName = otherFields.lastName; var typeID = otherFields.typeID; // var isInstitution = otherFields.isInstitution; // Ignore '(first)' and '(last)' if (firstName == "(" + Scholar.getString('pane.item.defaultFirstName') + ")"){ firstName = ''; } if (lastName == "(" + Scholar.getString('pane.item.defaultLastName') + ")"){ lastName = ''; } } else { var creator = _itemBeingEdited.getCreator(index); var firstName = creator['firstName']; var lastName = creator['lastName']; var typeID = creator['creatorTypeID']; // var isInstitution = creator['isInstitution']; } if (!_itemBeingEdited.hasCreatorAt(index) && !firstName && !lastName){ return; } switch (field){ case 'firstName': firstName = value; break; case 'lastName': lastName = value; break; case 'typeID': typeID = value; break; } _itemBeingEdited.setCreator(index, firstName, lastName, typeID); _itemBeingEdited.save(); } function removeNote(id) { var note = Scholar.Items.get(id); if(note) if(confirm(Scholar.getString('pane.item.notes.delete.confirm'))) note.erase(); } function addNote() { ScholarPane.openNoteWindow(_itemBeingEdited.getID()); } function _noteToTitle(text) { var MAX_LENGTH = 100; var t = text.substring(0, MAX_LENGTH); var ln = t.indexOf("\n"); if (ln>-1 && ln