1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | "use strict" ;
|
28 |
|
29 |
|
30 |
|
31 | const Element = require( './Element.js' ) ;
|
32 | const BaseMenu = require( './BaseMenu.js' ) ;
|
33 | const ColumnMenuMulti = require( './ColumnMenuMulti.js' ) ;
|
34 | const Button = require( './Button.js' ) ;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | function SelectListMulti( options ) {
|
41 |
|
42 | options = ! options ? {} : options.internal ? options : Object.create( options ) ;
|
43 | options.internal = true ;
|
44 |
|
45 | if ( ! options.master || typeof options.master !== 'object' ) {
|
46 | options.master = Object.assign( {} , this.defaultOptions.master ) ;
|
47 | }
|
48 | else {
|
49 | options.master = Object.assign( {} , this.defaultOptions.master , options.master ) ;
|
50 | }
|
51 |
|
52 | if ( options.content ) {
|
53 | options.master.content = options.content ;
|
54 | }
|
55 |
|
56 | if ( ! options.separator || typeof options.separator !== 'object' ) {
|
57 | options.separator = Object.assign( {} , this.defaultOptions.separator ) ;
|
58 | }
|
59 | else {
|
60 | options.separator = Object.assign( {} , this.defaultOptions.separator , options.separator ) ;
|
61 | }
|
62 |
|
63 | ColumnMenuMulti.call( this , options ) ;
|
64 |
|
65 | this.show = false ;
|
66 | this.zIndexRef = this.zIndex ;
|
67 |
|
68 | this.initPage() ;
|
69 | this.toggle( this.show , options.noDraw ) ;
|
70 |
|
71 | this.onClickOut = this.onClickOut.bind( this ) ;
|
72 |
|
73 | this.on( 'clickOut' , this.onClickOut ) ;
|
74 |
|
75 |
|
76 | if ( this.elementType === 'SelectListMulti' && ! options.noDraw ) { this.draw() ; }
|
77 | }
|
78 |
|
79 | module.exports = SelectListMulti ;
|
80 |
|
81 | SelectListMulti.prototype = Object.create( ColumnMenuMulti.prototype ) ;
|
82 | SelectListMulti.prototype.constructor = SelectListMulti ;
|
83 | SelectListMulti.prototype.elementType = 'SelectListMulti' ;
|
84 |
|
85 |
|
86 |
|
87 | SelectListMulti.prototype.defaultOptions = {
|
88 | buttonBlurAttr: { bgColor: 'gray' , color: 'white' , bold: true } ,
|
89 | buttonFocusAttr: { bgColor: 'white' , color: 'black' , bold: true } ,
|
90 | buttonDisabledAttr: {
|
91 | bgColor: 'gray' , color: 'white' , bold: true , dim: true
|
92 | } ,
|
93 | buttonSubmittedAttr: { bgColor: 'gray' , color: 'brightWhite' , bold: true } ,
|
94 | turnedOnBlurAttr: { bgColor: 'cyan' } ,
|
95 | turnedOnFocusAttr: { bgColor: 'brightCyan' , bold: true } ,
|
96 | turnedOffBlurAttr: { bgColor: 'gray' , dim: true } ,
|
97 | turnedOffFocusAttr: { bgColor: 'white' , color: 'black' , bold: true } ,
|
98 |
|
99 | master: {
|
100 | content: 'select-list-multi' ,
|
101 | symbol: '▼' ,
|
102 | internalRole: 'toggle'
|
103 | } ,
|
104 | separator: {
|
105 | content: '-' ,
|
106 | contentRepeat: true ,
|
107 | internalRole: 'separator'
|
108 | }
|
109 | } ;
|
110 |
|
111 |
|
112 |
|
113 | SelectListMulti.prototype.destroy = function( isSubDestroy ) {
|
114 | this.off( 'clickOut' , this.onClickOut ) ;
|
115 |
|
116 | ColumnMenuMulti.prototype.destroy.call( this , isSubDestroy ) ;
|
117 | } ;
|
118 |
|
119 |
|
120 |
|
121 | SelectListMulti.prototype.toggle = function( show = null , noDraw = false ) {
|
122 | var i , iMax ;
|
123 |
|
124 | if ( show === null ) { this.show = ! this.show ; }
|
125 | else { this.show = !! show ; }
|
126 |
|
127 | for ( i = 1 , iMax = this.buttons.length ; i < iMax ; i ++ ) {
|
128 | this.buttons[ i ].hidden = ! this.show ;
|
129 | }
|
130 |
|
131 |
|
132 | this.outputHeight = this.show ? this.pageHeight : 1 ;
|
133 |
|
134 | if ( this.show ) { this.topZ() ; }
|
135 | else { this.restoreZ() ; }
|
136 |
|
137 |
|
138 | if ( noDraw ) { return ; }
|
139 |
|
140 | this.document.giveFocusTo( this.buttons[ 0 ] ) ;
|
141 |
|
142 | this.redraw() ;
|
143 | } ;
|
144 |
|
145 |
|
146 |
|
147 | SelectListMulti.prototype.onButtonSubmit = function( buttonValue , action , button ) {
|
148 | switch ( button.internalRole ) {
|
149 | case 'previousPage' :
|
150 | this.previousPage() ;
|
151 | break ;
|
152 | case 'nextPage' :
|
153 | this.nextPage() ;
|
154 | break ;
|
155 | case 'toggle' :
|
156 | this.toggle() ;
|
157 |
|
158 |
|
159 | if ( ! this.show ) {
|
160 | this.emit( 'submit' , this.value , action , this ) ;
|
161 | }
|
162 | break ;
|
163 | default :
|
164 | this.emit( 'submit' , this.value , action , this ) ;
|
165 | }
|
166 | } ;
|
167 |
|
168 |
|
169 |
|
170 | SelectListMulti.prototype.onClickOut = function() {
|
171 | if ( this.show ) {
|
172 | this.toggle( false ) ;
|
173 |
|
174 | this.emit( 'submit' , this.value , undefined , this ) ;
|
175 | }
|
176 | } ;
|
177 |
|
178 | SelectListMulti.prototype.getValue = function() { return this.value ; } ;
|
179 |
|