Closes #220, Add a more friendly way to enter dates in search window and accessDate field

Addresss #352, Make sure data layer doesn't allow bad data via the API

Access date field is now human-friendly. Also enforcing SQL date form for the field in the DB and discarding bad data passed via setField().
This commit is contained in:
Dan Stillman 2007-02-06 11:03:22 +00:00
parent f994352ab9
commit cc1517da90
4 changed files with 33 additions and 6 deletions

View File

@ -830,6 +830,11 @@ var ZoteroItemPane = new function()
if (valueText){
var date = Zotero.Date.sqlToDate(valueText, true);
valueText = date ? date.toLocaleString() : '';
// Don't show time for access date if none
if (fieldName == 'accessDate') {
valueText = valueText.replace('00:00:00 ', '');
}
}
break;
}
@ -1241,11 +1246,21 @@ var ZoteroItemPane = new function()
// Fields
else
{
// Access date needs to be converted to UTC
// Access date needs to be parsed and converted to UTC
if (fieldName=='accessDate' && value!='')
{
var localDate = Zotero.Date.sqlToDate(value);
value = Zotero.Date.dateToSQL(localDate, true);
if (Zotero.Date.isSQLDate(value) || Zotero.Date.isSQLDateTime(value)) {
var localDate = Zotero.Date.sqlToDate(value);
value = Zotero.Date.dateToSQL(localDate, true);
}
else {
var d = Zotero.Date.strToDate(value);
value = null;
if (d.year && d.month != undefined && d.day) {
d = new Date(d.year, d.month, d.day);
value = Zotero.Date.dateToSQL(d, true);
}
}
}
if(saveChanges)

View File

@ -509,6 +509,15 @@ Zotero.Item.prototype.setField = function(field, value, loadIn){
!Zotero.Date.isMultipart(value)){
value = Zotero.Date.strToMultipart(value);
}
if (fieldID == Zotero.ItemFields.getID('accessDate')) {
if (!Zotero.Date.isSQLDate(value) &&
!Zotero.Date.isSQLDateTime(value)) {
Zotero.debug("Discarding invalid accessDate '" + value
+ "' in Item.setField()");
return false;
}
}
}
// If existing value, make sure it's actually changing

View File

@ -771,8 +771,11 @@ Zotero.Schema = new function(){
// Firefox 2.0, so we just throw the triggers at the DB on every
// userdata update and catch errors individually
//
// Add in DROP statements if these need to change
var itemDataTrigger = " FOR EACH ROW WHEN NEW.fieldID=14\n"
try { Zotero.DB.query("DROP TRIGGER insert_date_field"); } catch (e) {}
try { Zotero.DB.query("DROP TRIGGER update_date_field"); } catch (e) {}
var itemDataTrigger = " FOR EACH ROW WHEN NEW.fieldID IN (14, 27)\n"
+ " BEGIN\n"
+ " SELECT CASE\n"
+ " CAST(SUBSTR(NEW.value, 1, 4) AS INT) BETWEEN 0 AND 9999 AND\n"

View File

@ -1,4 +1,4 @@
-- 17
-- 18
-- This file creates tables containing user-specific data -- any changes
-- to existing tables made here must be mirrored in transition steps in