import { inject , View , MemberAPI } from '../../../' ; import { createTemptask } from '../CreateTaskView' ; import { IMemberData } from 'teambition' ; @ inject ( [ 'MemberAPI' ] ) export class CreatetaskInvolveView extends View { public task : typeof createTemptask ; public members : { [ index ] : IMemberData ; } ; private MemberAPI : MemberAPI ; private projectId : string ; public onInit ( ) { this . task = createTemptask ; this . projectId = this . $state . params . _id ; return this . MemberAPI . fetch ( this . projectId ) . then ( ( members ) => { this . members = members ; } ) ; } public onAllChangesDone ( ) { angular . forEach ( this . members , ( val ) => { if ( this . task . involveMembers . indexOf ( val . _id ) !== - 1 ) { val . isSelected = true ; } else { val . isSelected = false ; } } ) ; } public selectInvolveMember ( _id ) { this . members [ _id ] . isSelected = ! this . members [ _id ] . isSelected ; } public getMemberSelectedLength ( ) { let length = 0 ; if ( this . members ) { angular . forEach ( this . members , ( member ) => { if ( member . isSelected ) { length ++ ; } } ) ; } return length ; } public selectInvolve ( ) { angular . forEach ( this . members , ( member ) => { if ( member . isSelected && this . task . involveMembers . indexOf ( member . _id ) === - 1 ) { this . task . involveMembers . push ( member . _id ) ; } } ) ; this . task . visiable = this . task . isVisiable ? 'involves' : 'members' ; window . history . back ( ) ; } } angular . module ( 'teambition' ) . controller ( 'CreatetaskInvolveView' , CreatetaskInvolveView ) ;