import { IQuestion , ItemValue , QuestionImagePickerModel } from 'survey-core' ; import { SurveyPDF } from '../survey' ; import { FlatQuestion } from './flat_question' ; import { FlatRepository } from './flat_repository' ; import { IPoint , IRect , DocController } from '../doc_controller' ; import { IPdfBrick } from '../pdf_render/pdf_brick' ; import { TextBrick } from '../pdf_render/pdf_text' ; import { FlatRadiogroup } from './flat_radiogroup' ; import { CheckItemBrick } from '../pdf_render/pdf_checkitem' ; import { CompositeBrick } from '../pdf_render/pdf_composite' ; import { SurveyHelper } from '../helper_survey' ; export class FlatImagePicker extends FlatQuestion { protected question : QuestionImagePickerModel ; protected radio : FlatRadiogroup ; public constructor ( protected survey , question , controller ) { super ( survey , question , controller ) ; this . question = < QuestionImagePickerModel > question ; } private async generateFlatItem ( point , item , index ) { const pageAvailableWidth = SurveyHelper . getPageAvailableWidth ( this . controller ) ; const imageFlat = SurveyHelper . createImageFlat ( point , this . question , this . controller , ( < any > item ) . imageLink , pageAvailableWidth , pageAvailableWidth / SurveyHelper . IMAGEPICKER_RATIO ) ; const compositeFlat = new CompositeBrick ( imageFlat ) ; let buttonPoint = SurveyHelper . createPoint ( compositeFlat ) ; if ( this . question . showLabel ) { let labelFlat = await SurveyHelper . createTextFlat ( buttonPoint , this . question , this . controller , item . text || item . value , TextBrick ) ; compositeFlat . addBrick ( labelFlat ) ; buttonPoint = SurveyHelper . createPoint ( labelFlat ) ; } const height = this . controller . unitHeight ; const buttonRect = SurveyHelper . createRect ( buttonPoint , pageAvailableWidth , height ) ; if ( this . question . multiSelect ) { compositeFlat . addBrick ( new CheckItemBrick ( this . question , this . controller , buttonRect , this . question . id + 'index' + index , this . question . isReadOnly || ! item . isEnabled , this . question . value . indexOf ( item . value ) !== - 1 ) ) ; } else { compositeFlat . addBrick ( this . radio . generateFlatItem ( buttonRect , item , index ) ) ; } return compositeFlat ; } public async generateFlatsContent ( point ) { this . radio = this . question . multiSelect ? null : new FlatRadiogroup ( this . survey , this . question , this . controller ) ; const rowsFlats = [ new CompositeBrick ( ) ] ; const colWidth = SurveyHelper . getImagePickerAvailableWidth ( this . controller ) / SurveyHelper . IMAGEPICKER_COUNT ; let cols = ~ ~ ( SurveyHelper . getPageAvailableWidth ( this . controller ) / colWidth ) || 1 ; const count = this . question . visibleChoices . length ; cols = cols <= count ? cols : count ; const rows = ~ ~ ( Math . ceil ( count / cols ) ) ; const currPoint = SurveyHelper . clone ( point ) ; for ( let i = 0 ; i < rows ; i ++ ) { let yBot = currPoint . yTop ; this . controller . pushMargins ( ) ; let currMarginLeft = this . controller . margins . left ; for ( let j = 0 ; j < cols ; j ++ ) { const index = i * cols + j ; if ( index == count ) break ; this . controller . margins . left = currMarginLeft ; this . controller . margins . right = this . controller . paperWidth - currMarginLeft - colWidth ; currMarginLeft = this . controller . paperWidth - this . controller . margins . right + this . controller . unitWidth ; currPoint . xLeft = this . controller . margins . left ; const itemFlat = await this . generateFlatItem ( currPoint , this . question . visibleChoices [ index ] , index ) ; rowsFlats [ rowsFlats . length - 1 ] . addBrick ( itemFlat ) ; yBot = Math . max ( yBot , itemFlat . yBot ) ; } this . controller . popMargins ( ) ; currPoint . xLeft = point . xLeft ; currPoint . yTop = yBot ; if ( i !== rows - 1 ) { rowsFlats [ rowsFlats . length - 1 ] . addBrick ( SurveyHelper . createRowlineFlat ( currPoint , this . controller ) ) ; currPoint . yTop += SurveyHelper . EPSILON ; rowsFlats . push ( new CompositeBrick ( ) ) ; } } return rowsFlats ; } } FlatRepository . getInstance ( ) . register ( 'imagepicker' , FlatImagePicker ) ;