import * as ko from "knockout" ; import * as Survey from "survey-knockout" ; import { SurveyPropertyEditorBase , ISurveyObjectEditorOptions , } from "./propertyEditorBase" ; import { SurveyQuestionEditor } from "../questionEditors/questionEditor" ; import { editorLocalization } from "../editorLocalization" ; import { SurveyNestedPropertyEditor , SurveyNestedPropertyEditorItem , } from "./propertyNestedPropertyEditor" ; import { SurveyPropertyEditorFactory } from "./propertyEditorFactory" ; import { SurveyHelper } from "../surveyHelper" ; import { EditableObject } from "./editableObject" ; export class SurveyPropertyPagesEditor extends SurveyNestedPropertyEditor { constructor ( property ) { super ( property ) ; } public get editorType ( ) : string { return "surveypages" ; } public get editorTypeTemplate ( ) : string { return "nested-items" ; } protected getEditorName ( ) { if ( ! this . koEditItem ( ) ) return "" ; return editorLocalization . getString ( "pe.columnEdit" ) [ "format" ] ( this . koEditItem ( ) . obj . name ) ; } protected getItemClassName ( item ) { return "page" ; } protected createNewItem ( ) { var newName = SurveyHelper . getNewPageName ( this . originalValue ) ; return new Survey . Page ( newName ) ; } protected getColumnsProperties ( ) { var propertyNames = [ "name" , "title" ] ; if ( ! ! this . object ) { propertyNames = this . getPropertiesNames ( "page@" + this . object . getType ( ) , [ "name" , "title" , ] ) ; } return this . getPropertiesByNames ( "page" , propertyNames ) ; } protected createEditorItem ( item ) { var res = super . createEditorItem ( item ) ; res . koHasDetails ( false ) ; return res ; } protected canDeleteItem ( item ) { var survey = EditableObject . getSurvey ( this . object ) ; if ( ! survey ) return true ; return ( ! this . options || this . options . onCanDeleteItemCallback ( this . object , item , survey . currentPage !== item ) ) ; } protected createEditorOptions ( ) { return { allowAddRemoveItems : true , allowRemoveAllItems : false } ; } protected startDragItem ( ) { var survey = EditableObject . getSurvey ( this . object ) ; if ( ! ! survey ) { survey [ "onContainsPageCallback" ] = function ( ) { return true ; } ; } } protected endDragItem ( ) { var survey = EditableObject . getSurvey ( this . object ) ; if ( ! ! survey ) { survey [ "onContainsPageCallback" ] = null ; } } } SurveyPropertyEditorFactory . registerEditor ( "surveypages" , function ( property ) : SurveyPropertyEditorBase { return new SurveyPropertyPagesEditor ( property ) ; } ) ;