1 // ==========================================================================
  2 // Papercube.CiteRefView
  3 //
  4 // License:  PaperCube is open source software released under 
  5 //           the MIT License (see license.js)
  6 // ==========================================================================
  7 
  8 require('core');
  9 require('controllers/cite_ref');
 10 require('controllers/canvas');
 11 
 12 /** @class
 13 
 14   This is the author cite/ref view. It will show all the authors who reference or
 15   are cited by the author. Strong relationships will be shown with thicker and 
 16   darker lines. This view uses SVG.
 17 
 18   @extends NodeGraph.NodeGraphView
 19   @author Peter Bergstrom
 20   @version 1.0
 21   @copyright 2008-2009 Peter Bergström.
 22 */
 23 
 24 Papercube.CiteRefView = NodeGraph.NodeGraphView.extend(
 25 /** @scope Papercube.CiteRefView.prototype */ {
 26 
 27   /**
 28     The delegate is the citeRefController
 29   */
 30   delegate: Papercube.citeRefController,
 31 
 32   /**
 33     Bind the display properties from the canvasController.
 34 
 35     @property {Array}
 36     @binding "Papercube.canvasController.displayProperties"
 37   */
 38   displayPropertiesBinding: "Papercube.canvasController.displayProperties",
 39 
 40   /**
 41     The value for the depth slider.
 42 
 43     @property {Integer}
 44     @default 1
 45   */
 46   depth: 1,
 47   
 48   /**
 49     Bind the link threshold binding. Don't show items with less links. 
 50 
 51     @property {Integer}
 52     @binding "Papercube.citeRefController.linkThreshold"
 53   */
 54   linkThresholdBinding: "Papercube.citeRefController.linkThreshold",
 55 
 56   /**
 57     Bind the view direction from the viewController.
 58 
 59     @property {String}
 60     @binding "Papercube.viewController.viewDirection"
 61   */
 62   viewDirectionBinding: "Papercube.viewController.viewDirection",
 63   
 64   /**
 65     The name of the view. 
 66     
 67     Overridden value is 'citeref'
 68 
 69     @property {String}
 70     @config
 71     @default 'citeref'
 72   */
 73   viewName: 'citeref',
 74   
 75   /**
 76     The type of content being displayed.
 77     
 78     Overridden value is 'Author'
 79 
 80     @property {String}
 81     @config
 82     @default 'Author'
 83   */
 84   contentTypeViewing: 'Author',
 85   
 86   /** 
 87     The key for the default title display.
 88 
 89     Overridden value is 'name'
 90 
 91     @property {String}
 92     @config
 93     @default 'name'
 94   */
 95   defaultTitleKey: 'name',
 96   
 97   /**
 98     Meta data box small height. 
 99     
100     Overridden value is 100px.
101     
102     @property {Integer}
103     @config
104     @default 100px
105   */  
106   metaDataBoxHeightSmall: 100,
107 
108   /**
109     Meta data box small width. 
110     
111     Overridden value is  200px. 
112     
113     @property {Integer}
114     @config
115     @default 100px
116   */  
117   metaDataBoxWidthSmall: 200,
118 
119   /** 
120     Class name for meta data DIV.
121     
122     Overridden value is 'author'
123     
124     @property {String}
125     @config
126     @default 'author'
127   */
128   metaDataClassName: 'author',
129 
130   /** 
131     Get the details of a given item.
132     
133     @param guids {Array} The array of guids.
134     @param callBack {Function} The callBack function is called when the request is successful.
135   */
136   performCustomRequest: function(guids, callBack)
137   {
138     Papercube.adaptor.getAuthorDetails(guids, callBack);
139   },
140     
141   /** 
142     Generate custom metadata for item.
143     
144     @param guid {string} The guid for content object to be shown in the meta data view.
145 
146     @returns {Boolean} Returns NO if there is an error.
147   */
148   generateCustomMetaData: function(guid)
149   {
150     // Get the author content.
151     var content = Papercube.Author.find(guid);
152 
153     if(!content) return;
154 
155     // Set the title
156     this.metaDataView.childNodes[0].innerHTML = content.get("name");
157     this.metaDataView.childNodes[1].innerHTML = "<strong>Papers Published:</strong> " +Papercube.pluralizeString(" paper", content.get('paperCount'));
158     this.metaDataView.childNodes[2].innerHTML = "<strong>Number of Collaborators:</strong> " +Papercube.pluralizeString(" author",content.get('collaborators').length);
159     this.metaDataView.childNodes[3].innerHTML = "<strong>Author references:</strong> " +Papercube.pluralizeString(" other author",content.get('refAuthors').length);
160     this.metaDataView.childNodes[4].innerHTML = "<strong>Author is cited by:</strong> " +Papercube.pluralizeString(" other author",content.get('citeAuthors').length);
161   },
162   
163   /** 
164     Generate custom metadata for item.
165     
166     @param guid {string} The guid for content object that is found in the SC Store.
167 
168     @returns {array|SC.Record} Returns the found content object.
169   */
170   findCustomObject: function(guid)
171   {
172     return Papercube.Author.find(guid);
173   },
174 
175   /** 
176     Find Custom Object Relation Attribute.
177 
178     @param object {Record} The content object.
179 
180     @returns {Array} Returns the found relation attribute array.
181   */
182   findCustomObjectAttr: function(object)
183   {
184     if(object) 
185     {
186       if(this._displayRefs)
187         return object._attributes.refAuthors;
188       return object._attributes.citeAuthors;
189     }
190   },
191 
192   /**
193     Given relation object, return guid for it.
194 
195     @param rel {Object} The relation object or array.
196 
197     @returns {String} Returns the guid for the relation object.
198   */
199   getGuidForRelation: function(rel)
200   {
201     if(rel) return rel[0];
202   },
203   
204   /**
205     Given relation object, return weight for it.
206 
207     @param rel {Object} The relation object or array.
208 
209     @returns {Integer} Returns the calculated weight for the relation object.
210   */
211   calcRelationWeight: function(rel)
212   {
213     return rel[1];
214   },
215 
216   /**
217     Given an object, return its label.
218 
219     @param object {Object} The content object.
220 
221     @returns {String} Returns a title string for display.
222   */
223   findCustomObjectLabel: function(object)
224   {
225     var name = '';
226     if(object)
227     {
228       var n = object._attributes.name.split(' ');
229       var authLen = n.length;
230       for(var i=0; i<authLen; i++)
231       {
232         if(i<authLen-1)
233         {
234           name += n[i].substr(0,1).toUpperCase() + ' ';
235         }
236         else
237         {
238           name += n[i].substr(0,6);
239         }
240       }          
241     }
242     return name;
243   },
244     
245   /**
246     Revert bindings to default.
247   */
248   setBindingDefaults: function()
249   {
250     Papercube.citeRefController.setDefaults();
251   },
252 
253   /**
254     Redraw if viewDirection changes.
255 
256     @observes viewDirection
257   */
258   viewDirectionDidChange: function()
259   {
260     var content = this.get('content');
261     // If there is no content or if you're not visible, bail.
262 
263     Papercube.citeRefController.setPrompt();
264 
265     if(!this.get("isVisible") || !content) return;
266     
267     var direction = this.get('viewDirection');
268     
269     // Render if needed.
270     if(direction != this._cached_viewDirection)
271     {
272       this._hideExistingLines();
273       this._cached_viewDirection = direction;
274       this._displayRefs = (direction == "References");
275       
276       this._render();
277     }
278   }.observes('viewDirection')
279 }) ;
280