@@ -486,6 +486,84 @@ var PolicyFormView = Backbone.View.extend({
486
486
} ) ;
487
487
} ) ;
488
488
489
+ } ,
490
+
491
+ addAdvancedClaim :function ( e ) {
492
+ e . preventDefault ( ) ;
493
+
494
+ var name = $ ( '#name' , this . el ) . val ( ) ;
495
+ var friendly = $ ( '#friendly-name' , this . el ) . val ( ) ;
496
+ var rawValue = $ ( '#value' , this . el ) . val ( ) ;
497
+ var valueType = $ ( '#value-type' , this . el ) . val ( ) ;
498
+ var value = null ;
499
+ if ( valueType == 'number' ) {
500
+ value = Number ( rawValue ) ;
501
+ } else if ( valueType == 'boolean' ) {
502
+ value = ( rawValue . toLowerCase ( ) == 'true' ) ;
503
+ } else if ( valueType == 'json' ) {
504
+ value = JSON . parse ( rawValue ) ;
505
+ } else {
506
+ // treat it as a string, the default
507
+ value = rawValue ;
508
+ }
509
+
510
+ var issuers = this . issuerCollection . pluck ( 'item' ) ;
511
+
512
+ console . log ( name , friendly , rawValue , valueType , value , issuers ) ;
513
+
514
+ if ( ! _ . isEmpty ( issuers )
515
+ && name
516
+ && value ) {
517
+ // we've got a valid claim, add it to our set
518
+ // grab the current state of the scopes checkboxes just in case
519
+ var scopes = $ ( '#scopes input[type="checkbox"]:checked' ) . map ( function ( idx , elem ) { return $ ( elem ) . val ( ) ; } ) . get ( ) ;
520
+
521
+ var claimsRequired = this . model . get ( 'claimsRequired' ) ;
522
+ if ( ! claimsRequired ) {
523
+ claimsRequired = [ ] ;
524
+ }
525
+ console . log ( claimsRequired ) ;
526
+ claimsRequired . push ( {
527
+ name : name ,
528
+ friendlyName : friendly ,
529
+ value : value ,
530
+ issuer : issuers
531
+ } ) ;
532
+ console . log ( claimsRequired ) ;
533
+
534
+ this . model . set ( {
535
+ scopes : scopes ,
536
+ claimsRequired : claimsRequired
537
+ } , { trigger : false } ) ;
538
+
539
+ $ ( '#name' , this . el ) . val ( '' ) ;
540
+ $ ( '#friendly-name' , this . el ) . val ( '' ) ;
541
+ $ ( '#value' , this . el ) . val ( '' ) ;
542
+ $ ( '#value-type' , this . el ) . val ( 'text' ) ;
543
+
544
+ this . render ( ) ;
545
+
546
+ // re-select the advanced tab
547
+ $ ( 'a[data-target="#policy-advanced-tab"]' , this . el ) . tab ( 'show' )
548
+
549
+ } else {
550
+ // something is missing
551
+ $ ( '#loadingbox' ) . sheet ( 'hide' ) ;
552
+
553
+ //Display an alert with an error message
554
+ $ ( '#modalAlert div.modal-header' ) . html ( $ . t ( 'policy.advanced-error' ) ) ;
555
+ $ ( '#modalAlert div.modal-body' ) . html ( $ . t ( 'policy.advanced-error-description' ) ) ;
556
+
557
+ $ ( "#modalAlert" ) . modal ( { // wire up the actual modal functionality and show the dialog
558
+ "backdrop" : "static" ,
559
+ "keyboard" : true ,
560
+ "show" : true // ensure the modal is shown immediately
561
+ } ) ;
562
+ }
563
+
564
+
565
+
566
+
489
567
} ,
490
568
491
569
savePolicy :function ( e ) {
0 commit comments