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:
parent
f994352ab9
commit
cc1517da90
|
@ -830,6 +830,11 @@ var ZoteroItemPane = new function()
|
||||||
if (valueText){
|
if (valueText){
|
||||||
var date = Zotero.Date.sqlToDate(valueText, true);
|
var date = Zotero.Date.sqlToDate(valueText, true);
|
||||||
valueText = date ? date.toLocaleString() : '';
|
valueText = date ? date.toLocaleString() : '';
|
||||||
|
|
||||||
|
// Don't show time for access date if none
|
||||||
|
if (fieldName == 'accessDate') {
|
||||||
|
valueText = valueText.replace('00:00:00 ', '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1241,12 +1246,22 @@ var ZoteroItemPane = new function()
|
||||||
// Fields
|
// Fields
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Access date needs to be converted to UTC
|
// Access date needs to be parsed and converted to UTC
|
||||||
if (fieldName=='accessDate' && value!='')
|
if (fieldName=='accessDate' && value!='')
|
||||||
{
|
{
|
||||||
|
if (Zotero.Date.isSQLDate(value) || Zotero.Date.isSQLDateTime(value)) {
|
||||||
var localDate = Zotero.Date.sqlToDate(value);
|
var localDate = Zotero.Date.sqlToDate(value);
|
||||||
value = Zotero.Date.dateToSQL(localDate, true);
|
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)
|
if(saveChanges)
|
||||||
modifyField(fieldName,value);
|
modifyField(fieldName,value);
|
||||||
|
|
|
@ -509,6 +509,15 @@ Zotero.Item.prototype.setField = function(field, value, loadIn){
|
||||||
!Zotero.Date.isMultipart(value)){
|
!Zotero.Date.isMultipart(value)){
|
||||||
value = Zotero.Date.strToMultipart(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
|
// If existing value, make sure it's actually changing
|
||||||
|
|
|
@ -771,8 +771,11 @@ Zotero.Schema = new function(){
|
||||||
// Firefox 2.0, so we just throw the triggers at the DB on every
|
// Firefox 2.0, so we just throw the triggers at the DB on every
|
||||||
// userdata update and catch errors individually
|
// 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"
|
+ " BEGIN\n"
|
||||||
+ " SELECT CASE\n"
|
+ " SELECT CASE\n"
|
||||||
+ " CAST(SUBSTR(NEW.value, 1, 4) AS INT) BETWEEN 0 AND 9999 AND\n"
|
+ " CAST(SUBSTR(NEW.value, 1, 4) AS INT) BETWEEN 0 AND 9999 AND\n"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
-- 17
|
-- 18
|
||||||
|
|
||||||
-- This file creates tables containing user-specific data -- any changes
|
-- This file creates tables containing user-specific data -- any changes
|
||||||
-- to existing tables made here must be mirrored in transition steps in
|
-- to existing tables made here must be mirrored in transition steps in
|
||||||
|
|
Loading…
Reference in New Issue
Block a user