1 // ========================================================================== 2 // Papercube.ViewSelectView 3 // 4 // License: PaperCube is open source software released under 5 // the MIT License (see license.js) 6 // ========================================================================== 7 8 require('core'); 9 require('views/dropdown'); 10 11 /** @class 12 13 This is the view drop down... it's a bit more complicated than most drop downs. 14 15 @extends Papercube.DropDownView 16 @author Peter Bergstrom 17 @version 1.0 18 @copyright 2008-2009 Peter Bergström. 19 */ 20 Papercube.ViewSelectView = Papercube.DropDownView.extend( 21 /** @scope Papercube.ViewSelectView.prototype */ { 22 23 /** 24 Specifies what the views pulls its data from. Either viewingMode or viewChoice. 25 26 @property {Boolean} 27 @default NO 28 */ 29 isViewingModeSelector: NO, 30 31 /** 32 Observe viewingMode and set the innerHTML of the button to the viewingMode name if it is that drop down. 33 34 @observes viewingMode 35 */ 36 viewingModeDidChange: function() 37 { 38 if(this.isViewingModeSelector) 39 { 40 this.button.innerHTML = this.get("viewingMode"); 41 } 42 }.observes('viewingMode'), 43 44 /** 45 Observe viewChoice and set the innerHTML of the button to the viewChoice name if it is that drop down. 46 47 @observes viewChoice 48 */ 49 viewChoiceDidChange: function() 50 { 51 if(!this.isViewingModeSelector) 52 { 53 this.button.innerHTML = this.get("viewChoice"); 54 } 55 }.observes('viewChoice'), 56 57 /** 58 If the button has been clicked before show the list, if it is clicked again 59 but it has the active class, hide the list. 60 61 @param {DOM Event} evt The mouseDown event. 62 */ 63 mouseDown: function(evt) 64 { 65 if(evt.target.hasClassName('button') && !this.button.hasClassName('active')) 66 { 67 this.button.addClassName('active'); 68 this.showList(); 69 } 70 else if(evt.target.hasClassName('button') && this.button.hasClassName('active')) 71 { 72 this.mouseExited(evt); 73 } 74 }, 75 76 /** 77 Depending on the viewing mode, set a viewingChoice or a viewChoice, then hide the list. 78 79 @param str {string} The selected item's string. 80 */ 81 selectItem: function(str) 82 { 83 if(this.isViewingModeSelector) 84 { 85 Papercube.viewController.setViewingMode(str); 86 } 87 else 88 { 89 Papercube.viewController.setViewChoice(str); 90 } 91 92 // Call super. 93 sc_super(); 94 }, 95 96 /** 97 Show the list. 98 99 Construct the HTML based on the type of list. 100 */ 101 showList: function() 102 { 103 this.list.innerHTML = ''; 104 if(this.isViewingModeSelector) 105 { 106 var items = Papercube.viewController.get('viewingModes'); 107 } 108 else 109 { 110 var items = Papercube.viewController.get('viewChoices')[Papercube.viewController.get('viewingMode')]; 111 } 112 this.set('choices', items); 113 114 // Call super. 115 sc_super(); 116 117 } 118 119 }) ; 120