From 6ab7fd1e18e5024e92be84deb419f8892ab66ec2 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sun, 30 Jul 2006 21:01:23 +0000 Subject: [PATCH] Closes #119, When Item.isNote(), Item.getField('title') should return first line of note Returns the first 80 characters of the note content as the title Also changed setField() to use the loadIn parameter for primary fields so it can be used instead of this._data without affected _changedItems --- .../content/scholar/xpcom/data_access.js | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js index ed8e4df762..555aa3849e 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/data_access.js +++ b/chrome/chromeFiles/content/scholar/xpcom/data_access.js @@ -91,6 +91,11 @@ Scholar.Item.prototype.loadFromRow = function(row){ for (col in row){ // Only accept primary field data through loadFromRow() if (this.isPrimaryField(col)){ + // Return first line of content for note items + if (col=='title' && this.isNote()){ + row[col] = this._noteToTitle(); + } + this._data[col] = row[col]; } else { @@ -329,7 +334,9 @@ Scholar.Item.prototype.setField = function(field, value, loadIn){ return false; } this._data[field] = value; - this._changed.set(field); + if (!loadIn){ + this._changed.set(field); + } return true; } // Type-specific field @@ -828,6 +835,8 @@ Scholar.Item.prototype.updateNote = function(text){ if (updated){ this.updateDateModified(); Scholar.DB.commitTransaction(); + // Update title field + this.setField('title', this._noteToTitle(text), true); Scholar.Notifier.trigger('modify', 'item', this.getID()); } else { @@ -1570,6 +1579,22 @@ Scholar.Item.prototype._loadItemData = function(){ } +Scholar.Item.prototype._noteToTitle = function(note){ + var MAX_LENGTH = 80; + + if (typeof note == 'undefined'){ + note = this.getNote(); + } + + var t = note.substring(0, MAX_LENGTH); + var ln = t.indexOf("\n"); + if (ln>-1 && ln