1 // ==========================================================================
  2 // Papercube.SavedItemsItemView
  3 //
  4 // License:  PaperCube is open source software released under 
  5 //           the MIT License (see license.js)
  6 // ==========================================================================
  7 
  8 require('core');
  9 
 10 /** @class
 11 
 12   This view is the saved items. It is rendered not using SC views in
 13   order to make things faster.
 14 
 15   @extends SC.View
 16   @author Peter Bergstrom
 17   @version 1.0
 18   @copyright 2008-2009 Peter Bergström.
 19 */
 20 Papercube.SavedItemsItemView = SC.View.extend(
 21 /** @scope Papercube.SavedItemsItemView.prototype */ {
 22 
 23   /**
 24     Empty element is an empty DIV.
 25 
 26     @property {String}
 27     @default "<div></div>"
 28   */
 29   emptyElement: '<div></div>',
 30 
 31   /**
 32     By default, it is not selected.
 33     
 34     @property {Boolean}
 35     @default NO
 36   */
 37   isSelected: NO,
 38 
 39   /**
 40     Add a selected class if it is selected.
 41     
 42     @observes isSelected
 43   */
 44   isSelectedDidChange: function() 
 45   {
 46     this.setClassName('sel',this.get('isSelected')) ;
 47   }.observes('isSelected'),
 48   
 49   _contentIsPaper: NO,
 50 
 51   /**
 52     Observe the content and render the item's contents.
 53     
 54     @observes content
 55   */
 56   contentDidChange: function()
 57   {
 58    
 59    var content = this.get('content');
 60    
 61    // Bail if there is no content.
 62    if(!content) return;
 63    
 64    // innerHTML is an array that will be joined at the end of the function.
 65    var innerHTML = [];
 66 
 67    // Set up the HTML for Authors.
 68    if(content._type == "Papercube.Author")
 69    {
 70      this._contentIsPaper = NO;
 71      var statsstring = Papercube.pluralizeString(" paper", content.get("paperCount")) + " published, " +
 72      Papercube.pluralizeString(" collaboration", content.get("collaborators").length) + " with others, references " +
 73      Papercube.pluralizeString(" author", content.get("refAuthors").length) + ", cited by " +
 74      Papercube.pluralizeString(" author", content.get("citeAuthors").length) ;
 75      
 76      
 77     innerHTML = [
 78       '<div class="title">',
 79           content.get('name'),
 80       '</div>',
 81       '<div class="num">', 
 82         content.get('affiliation'), 
 83       '</div>',
 84       '<div class="subtitle">', 
 85         statsstring,
 86       '</div>'
 87       ];
 88 
 89   }
 90   
 91   // Set up the HTML for Papers.
 92   else
 93   {
 94     this._contentIsPaper = YES;
 95     // Get the author list.
 96     var authorstring = content.get('authorNames').join(', ');
 97     if(authorstring.length > 100)
 98     {
 99       authorstring = authorstring.substr(0, 99) + "…";
100     }
101     var title = titleStr = content.get('title');
102     if(title.length > 70)
103     {
104       title = title.substr(0,69) + "&hellip";
105     }
106     innerHTML = [
107      '<div class="title" title="'+titleStr+'">',
108       title,
109      '</div>',
110      '<div class="num">', 
111        Papercube.pluralizeString(" ref", content.get('refCount')) + ", " + Papercube.pluralizeString(" cite", content.get('citeCount')), 
112      '</div>',
113      '<div class="subtitle">', 
114         authorstring,
115      '</div>'
116      ];
117    }
118    
119    // Set the innerHTML of the view of the HTML that was just generated.
120    this.set('innerHTML', innerHTML.join(''));
121     
122  }.observes('content'),
123  
124  /** 
125    Show the paper or author in the last view.
126    
127    @param {DOM Event} evt The mouseDown event.
128  */
129  mouseDown: function(evt)
130  {
131    var content = this.get('content');
132    Papercube.viewController.set('savedPanelShowing', NO);
133    if(!this._contentIsPaper && content)
134    {
135      Papercube.viewController.viewAuthor(content.get('guid'));
136    }
137    if(this._contentIsPaper && content)
138    {
139      Papercube.viewController.viewPaper(content.get('guid'));
140    }
141  }
142 
143 }) ;
144