Fixes #333, Access date needs special handling in item pane for webpage item type
- Currently requires user to enter dates in SQL format if they want to change the access date, but at least it doesn't mangle the dates anymore - Uses new function ScholardammitZotero.Date.dateToSQL(Date date [, Boolean toUTC]) - Utilities.lpad() now forces _string_ to a string so that .length exists - Unrelated: Item.save() now returns false if the item didn't change
This commit is contained in:
parent
92620afa52
commit
7cee5b3b60
4 changed files with 75 additions and 12 deletions
|
@ -207,13 +207,6 @@ var ZoteroItemPane = new function()
|
|||
|
||||
var val = _itemBeingEdited.getField(fieldNames[i]);
|
||||
|
||||
// Convert dates from UTC
|
||||
if (fieldNames[i]=='dateAdded' || fieldNames[i]=='dateModified'
|
||||
|| fieldNames[i]=='accessDate'){
|
||||
var date = Zotero.Date.sqlToDate(val, true);
|
||||
val = date ? date.toLocaleString() : '';
|
||||
}
|
||||
|
||||
// Start tabindex at 1000 after creators
|
||||
var tabindex = editable ? (i>0 ? _tabIndexMinFields + i : 1) : 0;
|
||||
|
||||
|
@ -652,9 +645,19 @@ var ZoteroItemPane = new function()
|
|||
valueElement.setAttribute('onclick', 'ZoteroItemPane.showEditor(this)');
|
||||
valueElement.className = 'clicky';
|
||||
|
||||
if (fieldName=='tag')
|
||||
switch (fieldName)
|
||||
{
|
||||
_tabIndexMaxTagsFields = Math.max(_tabIndexMaxTagsFields, tabindex);
|
||||
case 'tag':
|
||||
_tabIndexMaxTagsFields = Math.max(_tabIndexMaxTagsFields, tabindex);
|
||||
break;
|
||||
|
||||
// Convert dates from UTC
|
||||
case 'dateAdded':
|
||||
case 'dateModified':
|
||||
case 'accessDate':
|
||||
var date = Zotero.Date.sqlToDate(valueText, true);
|
||||
valueText = date ? date.toLocaleString() : '';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -730,6 +733,13 @@ var ZoteroItemPane = new function()
|
|||
{
|
||||
var value = _itemBeingEdited.getField(fieldName);
|
||||
var itemID = _itemBeingEdited.getID();
|
||||
|
||||
// Access date needs to be converted from UTC
|
||||
if (fieldName=='accessDate')
|
||||
{
|
||||
var localDate = Zotero.Date.sqlToDate(value, true);
|
||||
var value = Zotero.Date.dateToSQL(localDate);
|
||||
}
|
||||
}
|
||||
|
||||
var t = document.createElement("textbox");
|
||||
|
@ -988,9 +998,16 @@ var ZoteroItemPane = new function()
|
|||
// Fields
|
||||
else
|
||||
{
|
||||
// Access date needs to be converted to UTC
|
||||
if (fieldName=='accessDate')
|
||||
{
|
||||
var localDate = Zotero.Date.sqlToDate(value);
|
||||
var value = Zotero.Date.dateToSQL(localDate, true);
|
||||
}
|
||||
|
||||
if(saveChanges)
|
||||
modifyField(fieldName,value);
|
||||
|
||||
|
||||
elem = createValueElement(_itemBeingEdited.getField(fieldName), fieldName, tabindex);
|
||||
}
|
||||
|
||||
|
@ -1011,7 +1028,7 @@ var ZoteroItemPane = new function()
|
|||
function modifyField(field, value)
|
||||
{
|
||||
_itemBeingEdited.setField(field,value);
|
||||
_itemBeingEdited.save();
|
||||
return _itemBeingEdited.save();
|
||||
}
|
||||
|
||||
function _getFieldValue(field)
|
||||
|
|
|
@ -421,7 +421,7 @@ Zotero.Item.prototype.setField = function(field, value, loadIn){
|
|||
Zotero.Item.prototype.save = function(){
|
||||
if (!this.hasChanged()){
|
||||
Zotero.debug('Item ' + this.getID() + ' has not changed', 4);
|
||||
return !!this.getID();
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -134,6 +134,7 @@ Zotero.Utilities.prototype.inArray = Zotero.inArray;
|
|||
* pads a number or other string with a given string on the left
|
||||
*/
|
||||
Zotero.Utilities.prototype.lpad = function(string, pad, length) {
|
||||
string = string + '';
|
||||
while(string.length < length) {
|
||||
string = pad + string;
|
||||
}
|
||||
|
|
|
@ -632,6 +632,7 @@ Zotero.Hash.prototype.has = function(in_key){
|
|||
|
||||
Zotero.Date = new function(){
|
||||
this.sqlToDate = sqlToDate;
|
||||
this.dateToSQL = dateToSQL;
|
||||
this.strToDate = strToDate;
|
||||
this.formatDate = formatDate;
|
||||
this.getFileDateString = getFileDateString;
|
||||
|
@ -672,6 +673,50 @@ Zotero.Date = new function(){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert a JS Date object to an SQL date in the form '2006-06-13 11:03:05'
|
||||
*
|
||||
* If _toUTC_ is true, creates a UTC date
|
||||
**/
|
||||
function dateToSQL(date, toUTC)
|
||||
{
|
||||
try {
|
||||
if (toUTC){
|
||||
var year = date.getUTCFullYear();
|
||||
var month = date.getUTCMonth();
|
||||
var day = date.getUTCDate();
|
||||
var hours = date.getUTCHours();
|
||||
var minutes = date.getUTCMinutes();
|
||||
var seconds = date.getUTCSeconds();
|
||||
}
|
||||
else {
|
||||
var year = date.getFullYear();
|
||||
var month = date.getMonth();
|
||||
var day = date.getDate();
|
||||
var hours = date.getHours();
|
||||
var minutes = date.getMinutes();
|
||||
var seconds = date.getSeconds();
|
||||
}
|
||||
|
||||
var utils = new Zotero.Utilities();
|
||||
year = utils.lpad(year, '0', 4);
|
||||
month = utils.lpad(month + 1, '0', 2);
|
||||
day = utils.lpad(day, '0', 2);
|
||||
hours = utils.lpad(hours, '0', 2);
|
||||
minutes = utils.lpad(minutes, '0', 2);
|
||||
seconds = utils.lpad(seconds, '0', 2);
|
||||
|
||||
return year + '-' + month + '-' + day + ' '
|
||||
+ hours + ':' + minutes + ':' + seconds;
|
||||
}
|
||||
catch (e){
|
||||
Zotero.debug(date + ' is not a valid JS date', 2);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* converts a string to an object containing:
|
||||
* day: integer form of the day
|
||||
|
|
Loading…
Add table
Reference in a new issue