@@ -180,11 +180,14 @@ function ProjectViewModel(project) {
180
180
self . geographicInfo = {
181
181
nationwide : ko . observable ( project . geographicInfo . nationwide || false ) ,
182
182
statewide : ko . observable ( project . geographicInfo . statewide || false ) ,
183
- isDefault : ko . observable ( project . geographicInfo . isDefault || false ) ,
183
+ overridePrimaryElectorate : ko . observable ( project . geographicInfo . overridePrimaryElectorate || false ) ,
184
+ overridePrimaryState : ko . observable ( project . geographicInfo . overridePrimaryState || false ) ,
184
185
primaryState : ko . observable ( project . geographicInfo . primaryState ) ,
185
186
primaryElectorate : ko . observable ( project . geographicInfo . primaryElectorate ) ,
186
187
otherStates : ko . observableArray ( project . geographicInfo . otherStates || [ ] ) ,
187
- otherElectorates : ko . observableArray ( project . geographicInfo . otherElectorates || [ ] )
188
+ otherExcludedStates : ko . observableArray ( project . geographicInfo . otherExcludedStates || [ ] ) ,
189
+ otherElectorates : ko . observableArray ( project . geographicInfo . otherElectorates || [ ] ) ,
190
+ otherExcludedElectorates : ko . observableArray ( project . geographicInfo . otherExcludedElectorates || [ ] )
188
191
} ;
189
192
self . geographicInfo . nationwide . subscribe ( function ( newValue ) {
190
193
if ( newValue ) {
@@ -193,6 +196,8 @@ function ProjectViewModel(project) {
193
196
self . geographicInfo . primaryElectorate ( "" ) ;
194
197
self . geographicInfo . otherStates ( [ ] ) ;
195
198
self . geographicInfo . otherElectorates ( [ ] ) ;
199
+ self . geographicInfo . otherExcludedStates ( [ ] ) ;
200
+ self . geographicInfo . otherExcludedElectorates ( [ ] ) ;
196
201
}
197
202
} ) ;
198
203
@@ -202,6 +207,8 @@ function ProjectViewModel(project) {
202
207
self . geographicInfo . primaryElectorate ( "" ) ;
203
208
self . geographicInfo . otherStates ( [ ] ) ;
204
209
self . geographicInfo . otherElectorates ( [ ] ) ;
210
+ self . geographicInfo . otherExcludedStates ( [ ] ) ;
211
+ self . geographicInfo . otherExcludedElectorates ( [ ] ) ;
205
212
}
206
213
} ) ;
207
214
@@ -462,30 +469,66 @@ function ProjectViewModel(project) {
462
469
} ) ;
463
470
self . associatedProgram ( project . associatedProgram ) ; // to trigger the computation of sub-programs
464
471
} ;
465
-
466
- self . transients . states = ko . observableArray ( [ ] ) ;
467
- self . transients . states . filteredStates = ko . computed ( function ( ) {
468
- var primaryState = self . geographicInfo . primaryState ( ) , states = self . transients . states ( ) . concat ( [ ] ) ;
469
- if ( primaryState ) {
470
- var index = states . indexOf ( primaryState ) ;
472
+ self . transients . removeAll = function ( source , toRemove ) {
473
+ for ( var i = 0 ; i < toRemove . length ; i ++ ) {
474
+ var index = source . indexOf ( toRemove [ i ] ) ;
471
475
if ( index > - 1 ) {
472
- states . splice ( index , 1 ) ;
476
+ source . splice ( index , 1 ) ;
473
477
}
474
478
}
475
479
476
- return states ;
480
+ return source
481
+ }
482
+
483
+ self . transients . states = ko . observableArray ( [ ] ) ;
484
+ self . transients . statesUnavailableForSelection = function ( included ) {
485
+ var result = [ ] ,
486
+ primaryState = self . geographicInfo . primaryState ( ) ,
487
+ otherStates = self . geographicInfo . otherStates ( ) || [ ] ,
488
+ excludedStates = self . geographicInfo . otherExcludedStates ( ) || [ ] ;
489
+
490
+ if ( primaryState )
491
+ result . push ( primaryState )
492
+ if ( ! included )
493
+ result . push . apply ( result , otherStates )
494
+ else
495
+ result . push . apply ( result , excludedStates )
496
+ return result
497
+ }
498
+ self . transients . states . statesToIncludeOrExclude = function ( include ) {
499
+ var toRemove = self . transients . statesUnavailableForSelection ( include ) , states = self . transients . states ( ) . concat ( [ ] ) ;
500
+ return self . transients . removeAll ( states , toRemove ) ;
501
+ } ;
502
+ self . transients . states . statesToInclude = ko . computed ( function ( ) {
503
+ return self . transients . states . statesToIncludeOrExclude ( true ) ;
504
+ } ) ;
505
+ self . transients . states . statesToExclude = ko . computed ( function ( ) {
506
+ return self . transients . states . statesToIncludeOrExclude ( false ) ;
477
507
} ) ;
478
508
self . transients . electorates = ko . observableArray ( [ ] ) ;
479
- self . transients . electorates . filteredElectorates = ko . computed ( function ( ) {
480
- var primaryElectorate = self . geographicInfo . primaryElectorate ( ) , electorates = self . transients . electorates ( ) . concat ( [ ] ) ;
481
- if ( primaryElectorate ) {
482
- var index = electorates . indexOf ( primaryElectorate ) ;
483
- if ( index > - 1 ) {
484
- electorates . splice ( index , 1 ) ;
485
- }
486
- }
487
-
488
- return electorates ;
509
+ self . transients . electoratesUnavailableForSelection = function ( included ) {
510
+ var result = [ ] ,
511
+ primaryElectorate = self . geographicInfo . primaryElectorate ( ) ,
512
+ otherElectorates = self . geographicInfo . otherElectorates ( ) || [ ] ,
513
+ excludedElectorates = self . geographicInfo . otherExcludedElectorates ( ) || [ ] ;
514
+
515
+ if ( primaryElectorate )
516
+ result . push ( primaryElectorate )
517
+ if ( ! included )
518
+ result . push . apply ( result , otherElectorates )
519
+ else
520
+ result . push . apply ( result , excludedElectorates )
521
+ return result
522
+ }
523
+ self . transients . electorates . electoratesToIncludeOrExclude = function ( include ) {
524
+ var toRemove = self . transients . electoratesUnavailableForSelection ( include ) , source = self . transients . electorates ( ) . concat ( [ ] ) ;
525
+ return self . transients . removeAll ( source , toRemove ) ;
526
+ } ;
527
+ self . transients . electorates . electoratesToInclude = ko . computed ( function ( ) {
528
+ return self . transients . electorates . electoratesToIncludeOrExclude ( true ) ;
529
+ } ) ;
530
+ self . transients . electorates . electoratesToExclude = ko . computed ( function ( ) {
531
+ return self . transients . electorates . electoratesToIncludeOrExclude ( false ) ;
489
532
} ) ;
490
533
491
534
self . loadStatesAndElectorates = function ( ) {
@@ -514,11 +557,14 @@ function ProjectViewModel(project) {
514
557
self . loadGeographicInfo = function ( ) {
515
558
self . geographicInfo . nationwide ( project . geographicInfo . nationwide ) ;
516
559
self . geographicInfo . statewide ( project . geographicInfo . statewide ) ;
517
- self . geographicInfo . isDefault ( project . geographicInfo . isDefault ) ;
560
+ self . geographicInfo . overridePrimaryElectorate ( project . geographicInfo . overridePrimaryElectorate ) ;
561
+ self . geographicInfo . overridePrimaryElectorate ( project . geographicInfo . overridePrimaryElectorate ) ;
518
562
self . geographicInfo . primaryState ( project . geographicInfo . primaryState ) ;
519
563
self . geographicInfo . primaryElectorate ( project . geographicInfo . primaryElectorate ) ;
520
564
self . geographicInfo . otherStates ( project . geographicInfo . otherStates ) ;
521
565
self . geographicInfo . otherElectorates ( project . geographicInfo . otherElectorates ) ;
566
+ self . geographicInfo . otherExcludedStates ( project . geographicInfo . otherExcludedStates ) ;
567
+ self . geographicInfo . otherExcludedElectorates ( project . geographicInfo . otherExcludedElectorates ) ;
522
568
}
523
569
524
570
self . toJS = function ( ) {
0 commit comments