1 // ========================================================================== 2 // Papercube.SearchResultsItemView 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 search result item. 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.SearchResultsItemView = SC.View.extend( 21 /** @scope Papercube.SearchResultsItemView.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 /** 50 Observe the content and render the item's contents. 51 52 @observes content 53 */ 54 contentDidChange: function() 55 { 56 57 var content = this.get('content'); 58 59 // Bail if there is no content. 60 if(!content) return; 61 62 // innerHTML is an array that will be joined at the end of the function. 63 var innerHTML = []; 64 65 // Set up the HTML for Authors. 66 if(Papercube.viewController.get('viewingMode') == 'Authors') 67 { 68 var statsstring = Papercube.pluralizeString(" paper", content.get("paperCount")) + ", " + 69 Papercube.pluralizeString(" collab", content.get("collaborators").length) + ", references " + 70 content.get("refAuthors").length + ", cited by " + content.get("citeAuthors").length ; 71 72 innerHTML = [ 73 '<div class="title">', 74 content.get('name'), 75 '</div>', 76 '<div class="num">', 77 content.get('affiliation'), 78 '</div>', 79 '<div class="subtitle">', 80 statsstring, 81 '</div>' 82 ]; 83 84 } 85 86 // Set up the HTML for Papers. 87 else 88 { 89 // Get the author list. 90 var authorstring = content.get('authorNames').join(', '); 91 if(authorstring.length > 50) 92 { 93 authorstring = authorstring.substr(0, 50) + "…"; 94 } 95 96 var title = titleStr = (content.get('title')) ? content.get('title') : 'Untitled'; 97 if(title.length > 35) 98 { 99 title = title.substr(0,33) + "&hellip"; 100 } 101 innerHTML = [ 102 '<div class="title" title="'+titleStr+'">', 103 title, 104 '</div>', 105 '<div class="num">', 106 Papercube.pluralizeString(" ref", content.get('refCount')) + ", " + Papercube.pluralizeString(" cite", content.get('citeCount')), 107 '</div>', 108 '<div class="subtitle">', 109 authorstring, 110 '</div>' 111 ]; 112 } 113 114 // Set the innerHTML of the view of the HTML that was just generated. 115 this.set('innerHTML', innerHTML.join('')); 116 117 }.observes('content') 118 }) ; 119