encyclopedia: { "title": true, "encyclopedia": true },
news: { "title": true, "work": true, "date": true },
newsgroup: { "title": true },
"press release" : { "title": true },
interview: { "last": true }, // TODO: Interview requires last *or* subject. Currently, we can't represent that.
episode: { "title": true },
"AV media": { "title": true }
};  
/**
- Return required parameters for this citation type.
- @return {Object} object with required parameters as keys and true as value; empty object for unknown type
- /
this.getRequiredParams = function
{
var curReq = requiredParams[this.type];
if(curReq)
return curReq;
else
return {}; // Return empty object rather than null to avoid dereferencing null.
};  
// These paramaters will be auto-suggested when editing.
var defaultParams =
{
web: [ "url", "title", "author", "accessdate", "work", "publisher", "date", "pages"],
book: [ "title", "author", "authorlink", "year", "isbn", "publisher", "location", "pages", "url" ],
journal: [ "title", "author", "journal", "volume", "issue", "year", "month", "pages", "url", "doi" ],
conference: [ "conference", "title", "booktitle", "author", "editor", "year", "month", "url", "id", "accessdate", "location", "pages", "publisher" ],
encyclopedia: [ "title", "encyclopedia", "author", "editor", "accessdate", "edition", "year",
"publisher", "volume", "location", "pages" ],
news: [ "title", "author", "url", "work", "date", "accessdate", "pages", "location", "agency" ],
newsgroup: [ "title", "author", "date", "newsgroup", "id", "url", "accessdate" ],
"press release" : [ "title", "url", "publisher", "date", "accessdate" ],
interview: ["last", "first", "subjectlink", "interviewer", "title", "callsign", "city", "date", "program", "accessdate"],
episode: ["title", "series", "credits", "airdate", "city", "network", "season"],
"AV media": ["people", "date", "url", "title", "medium", "location", "publisher"]
};  
/**
- Returns default parameters (to be suggested when editing) for current reference
- @return {Array} array of default parameter names; empty array if unknown
- /
this.getDefaultParams = function
{
var curDefault = defaultParams[this.type];
if(curDefault)
return curDefault;
else
return []; // Return empty array rather than null to avoid dereferencing null.
};  
this.isValid = function
{
if(this.type == '')
{
return false;
}
var req = this.getRequiredParams;
var i = 0;
var allFound = true;
for(var reqParam in req)
{
/* Ignore parameters in req object that are null, undefined, or false.
They are not required. */
if(!req[reqParam])
continue;
allFound &= (reqParam in this.params);
if(!allFound)
break;
}
return allFound;
};  
var iconMapping =
{
web: "page_white_world.png",
book: "book.png",
journal: "page_white_text.png",
news: "newspaper.png",
newsgroup: "comments.png",
"press release": "transmit_blue.png",
interview: "telephone.png",
episode: "television.png",
"AV media": "film.png"
};  
var superGetIcon = this.getIcon;
this.getIcon = function
{
var icon = iconMapping[this.type];
if(icon)
{
return proveit.STATIC_BASE + icon;
}
return superGetIcon.call(this);
};
},  
/**
- A function for citation style refs.
- @class CitationReference
- @for proveit
- @constructor
- @extends AbstractReference
- @param {Object} argObj argument object with keys for each option
- /  
CitationReference: function(argObj) {
proveit.AbstractReference.call(this, argObj);  
// None currently required;
var requiredParams = {};  
// These paramaters will be auto-suggested when editing.
var defaultParams =
{
web: [ "url", "author", "title", "date", "accessdate"],
news: [ "author", "title", "newspaper", "url", "publication-place", "volume", "issue", "date", "pages"],
encyclopedia: ["author", "editor", "contribution", "title", "publisher", "place", "year", "volume", "pages"],
book: ["author", "title", "publisher", "place", "year"],
journal: ["author", "title", "journal", "volume", "issue", "year", "pages"],
patent: ["inventor", "title", "issue-date", "patent-number", "country-code"]
};  
/**
- Returns the sort index for a given parameter
- @param {String} param parameter name
- @return {Number} sort index if found, otherwise -1
- /
this.getSortIndex = function(param)
{
// This is the order fields will be displayed or outputted.
return $.inArray(param, [
"last",
"first",
"url",
"author",
"editor",
"contribution",
"author-link",
"last2",
"first2",
"author2-link",
"publication-date",
"inventor",
"title",
"issue-date",
"patent-number",
"country-code",
"journal",
"volume",
"newspaper",
"issue",
"date",
"publisher",
"place",
"year",
"edition",
"publication-place",
"series",
"version",
"pages",
"page",
"id",
"isbn",
"doi",
"oclc",
"accessdate"
]);
};  
/**
- Returns this reference as a string.
- @return {String} reference as string
- /
this.toString = function
{
return this.toStringInternal("Citation", false);
};  
/**
- Return required parameters for this citation type.
- @return {Object} object with required parameters as keys and true as value; empty object for unknown type
- /
this.getRequiredParams = function
{
return requiredParams;
};  
/**
- Returns default parameters (to be suggested when editing) for current reference
- @return {Array} array of default parameter names; empty array if unknown
- /
this.getDefaultParams = function
{
if(this.type)
{
return defaultParams[this.type];
}
else
{
return ["url", "title", "author", "date", "publisher"]; // Can't determine more specific defaults when editing a pre-existing Citation.
}
};
},  
/**
- Constructor for RawReference type.
- @class RawReference
- @for proveit
- @constructor
- @extends AbstractReference
- @param {Object} argObj the argument object, with keys for each option
- /
RawReference: function(argObj)
{
proveit.AbstractReference.call(this, argObj);
this.type = 'raw';  
/**
- Returns this reference as a string.
- @return {String} reference as string
- /
this.toString = function
{
return this.orig;
};
this.params['title'] = this.orig;  
this.getIcon = function
{
return proveit.STATIC_BASE + 'raw.png';
};  
this.getTypeForDisplay = function
{
return proveit.getDescriptions['raw'];
};
},  
// TODO: This should be unified with changeRefFromEditPane
/**
- Convert the current contents of the add citation panel to a reference (i.e CiteReference, CitationReference)
- @for proveit
- @param {Node} box typepane root of add GUI (pane for specific type, e.g. journal)
- @return {AbstractReference} ref or null if no panel exists yet.
- /
getRefFromAddPane: function(box)
{
var $box = $(box);
var type = $box.data('proveitRefType');  
// get <ref> name
var refName = $('#addrefname').val;  
var citeFunc = this.togglestyle ? this.CiteReference : this.CitationReference;
var ref = new citeFunc({"name": refName, "type": type});  
var paramName, paramVal;  
var paramList = $(".paramlist", box)[0];
var paramRows = $('div', paramList);
for (var i = 0; i < paramRows.length; i++)
{
var paramRow = paramRows[i];
var valueTextbox = $(".paramvalue", paramRow)[0];  
if($(paramRow).hasClass("addedrow")) // Added with "Add another field"
{
paramName = $.trim($(".paramdesc", paramRow)[0].value);
}
else
{
paramName = valueTextbox.id.substring(this.NEW_PARAM_PREFIX.length);
}  
paramVal = $.trim(valueTextbox.value);
if(paramName != "" && paramVal != "")
{ // Non-blank
ref.params[paramName] = paramVal;
}
}
ref.update;
return ref;
},  
/**
- Called from the add citation panel, this is the function used to
- add the actual citation.
-
- @param {AbstractReference} ref reference being added
- /
addReference: function(ref) {
// get this working, lots of typing here.  
this.addNewElement(ref);  
ref.orig = ref.toString;
/*
- Cycle through the boxes and grab the id's versus the values, watch
- for the final box and make sure to grab the type as well
- /  
this.insertRefIntoMWEditBox(ref, true); // true means insert full text here, regardless of global toggle.
ref.save = true;
ref.inMWEditBox = true;
},  
/**
- Clear all rows of passed in add citation panes.