1 // ========================================================================== 2 // Papercube.Paper 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 Paper model 13 14 @extends SC.Record 15 @author Peter Bergstrom 16 @version 1.0 17 @copyright 2008-2009 Peter Bergström. 18 */ 19 Papercube.Paper = SC.Record.extend( 20 /** @scope Papercube.Paper.prototype */ { 21 22 /** 23 The max level explored for refs. 24 25 @property {Integer} 26 @default 0 27 */ 28 maxRefLevel: 0, 29 30 /** 31 The max level explored for citations. 32 33 @property {Integer} 34 @default 0 35 */ 36 maxCiteLevel: 0, 37 38 /** 39 Flag that shows that all data has been retrieved from the server. 40 41 @property {Boolean} 42 @default NO 43 */ 44 // allDataRetrieved: NO, 45 46 47 /** 48 Cached citation count. 49 50 @property {Integer} 51 */ 52 _cached_citeCount: null, 53 54 /** 55 Computed property returning citation count. 56 57 @property {Integer} 58 @isReadOnly 59 */ 60 citeCount: function() 61 { 62 if(!this._cached_citeCount) 63 { 64 var cites = this.get('citations'); 65 if(cites && cites.length) 66 { 67 this._cached_citeCount = cites.length; 68 } 69 else 70 { 71 this._cached_citeCount = 0; 72 } 73 } 74 return this._cached_citeCount; 75 }.property(), 76 77 /** 78 Cached reference count. 79 80 @property {Integer} 81 */ 82 _cached_refCount: null, 83 84 /** 85 Computed property returning reference count. 86 87 @property {Integer} 88 @isReadOnly 89 */ 90 refCount: function() 91 { 92 if(!this._cached_refCount) 93 { 94 var refs = this.get('references'); 95 if(refs && refs.length) 96 { 97 this._cached_refCount = refs.length; 98 } 99 else 100 { 101 this._cached_refCount = 0; 102 } 103 } 104 return this._cached_refCount; 105 }.property(), 106 107 /** 108 Cached author count. 109 110 @property {Integer} 111 */ 112 _cached_authorCount: null, 113 114 /** 115 Computed property returning author count. 116 117 @property {Integer} 118 @isReadOnly 119 */ 120 authorCount: function() 121 { 122 if(!this._cached_authorCount) 123 { 124 var a = this.get('authors'); 125 if(a && a.length) 126 { 127 this._cached_authorCount = a.length; 128 } 129 else 130 { 131 this._cached_authorCount = 0; 132 } 133 } 134 return this._cached_authorCount; 135 }.property(), 136 137 /** 138 Cached formatted reference count string. 139 140 @property {String} 141 */ 142 _cached_formattedReferenceCount: null, 143 144 /** 145 Computed property returning formatted reference count string. 146 147 @property {String} 148 @isReadOnly 149 */ 150 formattedReferenceCount: function() 151 { 152 if(!this._cached_formattedReferenceCount) 153 { 154 this._cached_formattedReferenceCount = "[" + Papercube.pluralizeString(" ref", this.get('refCount'))+"]"; 155 } 156 return this._cached_formattedReferenceCount; 157 }.property(), 158 159 /** 160 Cached formatted citation count string. 161 162 @property {String} 163 */ 164 _cached_formattedCitationCount: null, 165 166 /** 167 Computed property returning formatted citation count string. 168 169 @property {String} 170 @isReadOnly 171 */ 172 formattedCitationCount: function() 173 { 174 if(!this._cached_formattedCitationCount) 175 { 176 this._cached_formattedCitationCount = "[" + Papercube.pluralizeString(" cite", this.get('citeCount'))+"]"; 177 } 178 return this._cached_formattedCitationCount; 179 }.property(), 180 181 /** 182 Cached author names array. 183 184 @property {Array} 185 */ 186 _cached_authorNames: null, 187 188 /** 189 Computed property returning a paper's authors names in an array. 190 191 @property {String} 192 @isReadOnly 193 */ 194 authorNames: function() 195 { 196 if(!this._cached_authorNames) 197 { 198 var authors = []; 199 var auths = this.get("authors"); 200 201 for(var i=0; i<auths.length; i++) 202 { 203 authors.push(auths[i].name); 204 } 205 if(authors.length == 0) 206 { 207 authors = ["unknown"]; 208 } 209 this._cached_authorNames = authors; 210 } 211 return this._cached_authorNames; 212 }.property(), 213 214 /** 215 Computed property returning a paper's title as different property, 'label' 216 217 @property {String} 218 @isReadOnly 219 */ 220 label: function() 221 { 222 return this.get('title'); 223 }.property(), 224 225 /** 226 Computed property generating the CiteSeer URL. 227 228 @property {String} 229 @isReadOnly 230 */ 231 url: function() 232 { 233 return 'http://citeseer.ist.psu.edu/'+this.get('guid').split('-')[1]+'.html'; 234 }.property() 235 236 }) ; 237