1 // ==========================================================================
  2 // Papercube.AuthorPaperController
  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   Controls the sliders used for the author papers.
 13 
 14   @extends NodeGraph.NodeGraphDelegate
 15   @author Peter Bergstrom
 16   @version 1.0
 17   @copyright 2008-2009 Peter Bergström.
 18   @static
 19 */
 20 Papercube.authorPaperController = NodeGraph.NodeGraphDelegate.create(
 21 /** @scope Papercube.authorPaperController.prototype */ {
 22 
 23   /**
 24     The increment value for the refThreshold slider. 
 25     
 26     @property {Integer}
 27     @default 1
 28   */
 29   refThresholdStep: 1,
 30 
 31   /**
 32     The max value for the refThreshold slider. 
 33     
 34     @property {Integer}
 35     @default 30
 36   */
 37   refThresholdValueMax: 30,
 38 
 39   /**
 40     The min value for the refThreshold slider. 
 41 
 42     @property {Integer}
 43     @default 0
 44   */
 45   refThresholdValueMin: 0,
 46 
 47   /**
 48     The value for the refThreshold slider. 
 49     
 50     @property {Integer}
 51     @default 30
 52   */
 53   refThreshold: 0,
 54 
 55   /**
 56     The default refThreshold value. 
 57     
 58     @property {Integer}
 59     @default 0
 60   */
 61   defaultRefThreshold: 0,
 62 
 63 
 64   /**
 65     The increment value for the citeThreshold slider. 
 66     
 67     @property {Integer}
 68     @default 1
 69   */
 70   citeThresholdStep: 1,
 71 
 72   /**
 73     The max value for the citeThreshold slider. 
 74     
 75     @property {Integer}
 76     @default 1
 77   */
 78   citeThresholdValueMax: 30,
 79 
 80   /**
 81     The min value for the citeThreshold slider. 
 82     
 83     @property {Integer}
 84     @default 0
 85   */
 86   citeThresholdValueMin: 0,
 87 
 88   /**
 89     The value for the citeThreshold slider. 
 90     
 91     @property {Integer}
 92     @default 0
 93   */
 94   citeThreshold: 0,
 95 
 96   /**
 97     The default citeThreshold value. 
 98     
 99     @property {Integer}
100     @default 0
101   */
102   defaultCiteThreshold: 0,
103 
104   /**
105     The increment value for the startYearThreshold slider. 
106 
107     @property {Integer}
108     @default 1
109   */
110   startYearThresholdStep: 1,
111 
112   /**
113     The max value for the startYearThreshold slider. 
114 
115     @property {Integer}
116     @default new Date().getFullYear()
117   */
118   startYearThresholdValueMax: (new Date().getFullYear()-1960),
119 
120   /**
121     The min value for the startYearThreshold slider. 
122 
123     @property {Integer}
124     @default 0
125   */
126   startYearThresholdValueMin: 0,
127 
128   /**
129     The value for the startYearThreshold slider. 
130 
131     @property {Integer}
132     @default 1960
133   */
134   startYearThreshold: 1960,
135 
136   /**
137     The value for the startYearThreshold slider. 
138 
139     @property {Integer}
140     @default 0
141   */
142   startYearThresholdValue: 0,
143 
144   /**
145     The default startYearThreshold value. 
146 
147     @property {Integer}
148     @default 0
149   */
150   defaultStartYearThreshold: 0,
151 
152   /**
153     The increment value for the endYearThreshold slider. 
154 
155     @property {Integer}
156     @default 1
157   */
158   endYearThresholdStep: 1,
159 
160   /**
161     The max value for the endYearThreshold slider. 
162 
163     @property {Integer}
164     @default 100
165   */
166   endYearThresholdValueMax: (new Date().getFullYear()-1960),
167 
168   /**
169     The min value for the endYearThreshold slider. 
170 
171     @property {Integer}
172     @default 0
173   */
174   endYearThresholdValueMin: 0,
175 
176   /**
177     The value for the endYearThreshold slider. 
178 
179     @property {Integer}
180     @default 100
181   */
182   endYearThresholdValue: (new Date().getFullYear()-1960),
183 
184   /**
185     The value for the endYearThreshold slider. 
186 
187     @property {Integer}
188     @default new Date().getFullYear()
189   */
190   endYearThreshold: new Date().getFullYear(),
191 
192   /**
193     The default endYearThreshold value. 
194 
195     @property {Integer}
196     @default 0
197   */
198   defaultEndYearThreshold: (new Date().getFullYear()-1960),
199   
200   /**
201     Called by the NodeGraph instance when a mouseDown is triggered.
202     
203     @param {DOM Event} evt The mouseDown event.
204     @param {NodeGraph.NodeGraphView} The NodeGraph view.
205     @param guid {String} The guid of the node.
206   */
207   nodeGraphDidMouseDown: function(evt, view, guid) {
208     var type = evt.target.getAttribute('type');
209     if(guid && type)
210     {
211       Papercube.canvasController.showFan(Event.pointerX(evt), 
212                                          Event.pointerY(evt), 
213                                          view.viewName, (type+"Fan"));
214       return YES;
215     }
216     return NO;
217   },
218 
219   /**
220     Allow for additional customized setup of the NodeGraph view.
221     
222     @param {NodeGraph.NodeGraphView} nodeGraph The NodeGraph instance.
223   */
224   finishInitForGraph: function(nodeGraph) {
225     Papercube.canvasController.fanForNodeGraph(nodeGraph);
226   },
227   
228   /**
229     Route to the appropriate max strength action.
230   
231     @param opt {boolean} If YES, ref, ff NO, cite.
232   */
233   maxStrength: function(opt)
234   {
235     if(opt===YES)
236     {
237       this.maxRefStrength();
238     }
239     else if(opt === 2)
240     {
241       this.maxEndYearStrength();
242     }
243     else if(opt === 3)
244     {
245       this.maxStartYearStrength();
246     } else {
247       this.maxCiteStrength();
248     }
249   },
250 
251   /**
252     Route to the appropriate min strength action.
253   
254     @param opt {boolean} If YES, ref, if NO, cite.
255   */
256   minStrength: function(opt)  
257   {
258     if(opt === YES)
259     {
260       this.minRefStrength();
261     }
262     else if(opt === 2)
263     {
264       this.minEndYearStrength();
265     }
266     else if(opt === 3)
267     {
268       this.minStartYearStrength();
269     } else {
270       this.minCiteStrength();
271     }
272   },
273   
274   /**
275     Increment the ref strength towards the maximum.
276   */
277   maxRefStrength: function()
278   {
279     if(this.get('refThreshold') < this.get('refThresholdValueMax'))
280       this.set('refThreshold', this.get('refThreshold')+1);
281   },
282 
283   /**
284     Increment the ref strength towards the minimum.
285   */
286   minRefStrength: function()
287   {
288     if(this.get('refThreshold') > this.get('refThresholdValueMin'))
289       this.set('refThreshold', this.get('refThreshold')-1);
290   },
291 
292   /**
293     Increment cite ref strength towards the maximum.
294   */
295   maxCiteStrength: function()
296   {
297     if(this.get('citeThreshold') < this.get('citeThresholdValueMax'))
298       this.set('citeThreshold', this.get('citeThreshold')+1);
299   },
300 
301   /**
302     Increment cite ref strength towards the miniumum.
303   */
304   minCiteStrength: function()
305   {
306     if(this.get('citeThreshold') > this.get('citeThresholdValueMin'))
307       this.set('citeThreshold', this.get('citeThreshold')-1);
308   },
309 
310 
311   /**
312     Increment the startYear strength towards the maximum.
313   */
314   maxStartYearStrength: function()
315   {
316     if(this.get('startYearThresholdValue') < this.get('startYearThresholdValueMax'))
317       this.set('startYearThresholdValue', this.get('startYearThresholdValue')+1);
318   },
319 
320   /**
321     Increment the startYear strength towards the minimum.
322   */
323   minStartYearStrength: function()
324   {
325     if(this.get('startYearThresholdValue') > this.get('startYearThresholdValueMin'))
326       this.set('startYearThresholdValue', this.get('startYearThresholdValue')-1);
327   },
328 
329   /**
330     Increment the endYear strength towards the maximum.
331   */
332   maxEndYearStrength: function()
333   {
334     if(this.get('endYearThresholdValue') < this.get('endYearThresholdValueMax'))
335       this.set('endYearThresholdValue', this.get('endYearThresholdValue')+1);
336   },
337 
338   /**
339     Increment the endYear strength towards the minimum.
340   */
341   minEndYearStrength: function()
342   {
343     if(this.get('endYearThresholdValue') > this.get('endYearThresholdValueMin'))
344       this.set('endYearThresholdValue', this.get('endYearThresholdValue')-1);
345   },
346 
347   /**
348     Set the default values for the controller.
349   */
350   setDefaults: function()
351   {
352     this.set('refThreshold', this.get('defaultRefThreshold'));
353     this.set('citeThreshold', this.get('defaultCiteThreshold'));
354     this.set('startYearThresholdValue', this.get('defaultStartYearThreshold'));
355     this.set('endYearThresholdValue', this.get('defaultEndYearThreshold'));
356   },
357   
358   /**
359     Set the startYearThreshold
360   
361     @observes startYearThresholdValue
362   */
363   startYearThresholdValueDidChange: function() {
364     this.set('startYearThreshold', 
365       1960+this.get('startYearThresholdValue'));
366   }.observes('startYearThresholdValue'),
367 
368   /**
369     Set the endYearThreshold
370   
371     @observes endYearThresholdValue
372   */
373   endYearThresholdValueDidChange: function() {
374     this.set('endYearThreshold', 
375       1960+this.get('endYearThresholdValue'));
376   }.observes('endYearThresholdValue')
377   
378   
379 
380 }) ;
381