@@ -7,12 +7,18 @@ var BrowserWindow = remote.require('browser-window');
7
7
var format = require ( 'util' ) . format ;
8
8
var bindings = require ( 'ampersand-dom-bindings' ) ;
9
9
var fileReaderTemplate = require ( './filereader-default.jade' ) ;
10
+ var assert = require ( 'assert' ) ;
10
11
11
12
// var debug = require('debug')('scout:connect:filereader-view');
12
13
13
14
module . exports = InputView . extend ( {
14
15
template : fileReaderTemplate ,
15
16
props : {
17
+ multi : {
18
+ type : 'boolean' ,
19
+ required : true ,
20
+ default : false
21
+ } ,
16
22
inputValue : {
17
23
type : 'array' ,
18
24
required : true ,
@@ -31,10 +37,11 @@ module.exports = InputView.extend({
31
37
deps : [ 'inputValue' ] ,
32
38
fn : function ( ) {
33
39
if ( this . inputValue . length === 0 ) {
34
- return 'Choose certificate (s)' ;
40
+ return this . multi ? 'Choose file (s)' : 'Choose file ';
35
41
} else if ( this . inputValue . length === 1 ) {
36
42
return path . basename ( this . inputValue [ 0 ] ) ;
37
43
}
44
+ assert . equal ( this . multi , true ) ;
38
45
return format ( '%d files selected' , this . inputValue . length ) ;
39
46
}
40
47
} ,
@@ -78,6 +85,9 @@ module.exports = InputView.extend({
78
85
*/
79
86
initialize : function ( spec ) {
80
87
spec = spec || { } ;
88
+ if ( spec . multi ) {
89
+ this . multi = spec . multi ;
90
+ }
81
91
_ . defaults ( spec , { value : [ ] } ) ;
82
92
this . invalidClass = 'has-error' ;
83
93
this . validityClassSelector = '.form-item-file' ;
@@ -173,8 +183,12 @@ module.exports = InputView.extend({
173
183
this . runTests ( ) ;
174
184
} ,
175
185
loadFileButtonClicked : function ( ) {
186
+ var properties = [ 'openFile' ] ;
187
+ if ( this . multi ) {
188
+ properties . push ( 'multiSelections' ) ;
189
+ }
176
190
dialog . showOpenDialog ( BrowserWindow . getFocusedWindow ( ) , {
177
- properties : [ 'openFile' , 'multiSelections' ]
191
+ properties : properties
178
192
} , function ( filenames ) {
179
193
this . inputValue = filenames || [ ] ;
180
194
this . handleChange ( ) ;
0 commit comments