@@ -548,6 +548,8 @@ OrganisationPageViewModel = function (props, options) {
548
548
}
549
549
}
550
550
} ;
551
+ var organisationService = new OrganisationService ( options ) ;
552
+ self . periods = organisationService . getBudgetHeaders ( ) ;
551
553
552
554
self . initialise = function ( ) {
553
555
$ . fn . dataTable . moment ( 'dd-MM-yyyy' ) ;
@@ -634,6 +636,32 @@ OrganisationPageViewModel = function (props, options) {
634
636
self . reportingEnabled = ko . observable ( ) ;
635
637
self . selectedOrganisationReportCategories = ko . observableArray ( ) ;
636
638
639
+ // List of service / target measure
640
+ self . allTargetMeasures = [ ] ;
641
+ var services = options . services || [ ] ;
642
+ for ( var i = 0 ; i < services . length ; i ++ ) {
643
+ if ( services [ i ] . scores ) {
644
+ for ( var j = 0 ; j < services [ i ] . scores . length ; j ++ ) {
645
+ self . allTargetMeasures . push ( {
646
+ label :services [ i ] . name + ' - ' + services [ i ] . scores [ j ] . label ,
647
+ serviceId :services [ i ] . id ,
648
+ scoreId :services [ i ] . scores [ j ] . scoreId ,
649
+ service :services [ i ] ,
650
+ score :services [ i ] . scores [ j ] ,
651
+ value :services [ i ] . scores [ j ] . scoreId
652
+ } ) ;
653
+ }
654
+ }
655
+ }
656
+
657
+ self . allTargetMeasures = _ . sortBy ( self . allTargetMeasures , 'label' ) ;
658
+ var propDetails = props && props . custom && props . custom . details || { } ;
659
+ self . selectedTargetMeasures = ko . observableArray ( ) ;
660
+ var details = new DetailsViewModel ( propDetails , props , self . periods , self . allTargetMeasures , options ) ;
661
+ updatedTargetMeasures ( details ) ;
662
+ self . reportingTargets = ko . observable ( details ) ;
663
+ self . isProjectDetailsLocked = ko . observable ( false ) ;
664
+
637
665
var setStartAndEndDateDefaults = function ( ) {
638
666
var currentConfig = parsedConfig ( ) ;
639
667
if ( ! currentConfig || ! currentConfig . organisationReports || currentConfig . organisationReports . length == 0 ) {
@@ -692,6 +720,26 @@ OrganisationPageViewModel = function (props, options) {
692
720
reportService . regenerateReports ( data , options . regenerateOrganisationReportsUrl ) ;
693
721
} ;
694
722
723
+ function updatedTargetMeasures ( details ) {
724
+ var reportingTargets = details ,
725
+ selectedServices = reportingTargets . services . services ( ) ,
726
+ allServices = self . allTargetMeasures ;
727
+
728
+ _ . each ( allServices , function ( service ) {
729
+ var found = _ . find ( selectedServices , function ( selectedService ) {
730
+ return selectedService . scoreId ( ) === service . scoreId ;
731
+ } ) ;
732
+
733
+ if ( ! found ) {
734
+ reportingTargets . services . addServiceTarget ( service ) ;
735
+ }
736
+ } )
737
+ }
738
+
739
+ self . attachValidation = function ( ) {
740
+ $ ( "#organisation-targets" ) . validationEngine ( 'attach' , { validationAttribute : "data-validation-engine" } ) ;
741
+ } ;
742
+
695
743
self . saveOrganisationConfiguration = function ( ) {
696
744
var currentConfig = parsedConfig ( ) ;
697
745
if ( ! currentConfig ) {
@@ -713,6 +761,13 @@ OrganisationPageViewModel = function (props, options) {
713
761
return saveOrganisation ( json ) ;
714
762
} ;
715
763
764
+ self . saveCustomFields = function ( ) {
765
+ if ( $ ( "#organisation-targets form" ) . validationEngine ( 'validate' ) ) {
766
+ var json = JSON . parse ( self . reportingTargets ( ) . modelAsJSON ( ) ) ;
767
+ return saveOrganisation ( json ) ;
768
+ }
769
+ } ;
770
+
716
771
717
772
var saveOrganisation = function ( json ) {
718
773
return $ . ajax ( {
0 commit comments