import { EmployeeViewModel } from "./../../view-models/employee-model" ; import { RadDataForm , EntityProperty , DataFormEventData , DataFormEditorType } from "nativescript-ui-dataform" ; import * as utilsModule from "tns-core-modules/utils/utils" ; import { ios } from "tns-core-modules/application" ; import { Color } from "tns-core-modules/color" ; const editorPaddingHorizontal = 10 ; const editorPaddingVertical = 5 ; const coreEditorPaddingHorizontal = 7 ; const coreEditorPaddingVertical = 3 ; const strokeWidth = 1 ; const cornerRadius = 4 ; const strokeColor = new Color ( "DarkGray" ) ; const fillColor = new Color ( "#00000000" ) ; export function onPageNavigatingTo ( args ) { let viewModel = new EmployeeViewModel ( ) ; const page = args . object ; page . bindingContext = viewModel ; } export function dfEditorUpdate ( args ) { const dataForm = < RadDataForm > args . object ; const entityProperty = < EntityProperty > dataForm . getPropertyByName ( args . propertyName ) ; const editor = args . editor ; const editorType = entityProperty . editor . type ; if ( ! editorNeedsUpdate ( editorType ) ) { return ; } if ( ios ) { const editorOffsets = new UIEdgeInsets ( { top : editorPaddingVertical , left : editorPaddingHorizontal , bottom : editorPaddingVertical , right : editorPaddingHorizontal } ) ; editor . style . insets = editorOffsets ; const textOffsets = new UIEdgeInsets ( { top : coreEditorPaddingVertical , left : coreEditorPaddingHorizontal , bottom : coreEditorPaddingVertical , right : coreEditorPaddingHorizontal } ) ; if ( editorHasValueLabel ( editorType ) ) { editor . showAccessoryImage = false ; } editor . editorCore . insets = textOffsets ; const layer = editor . editorCore . layer ; layer . borderColor = strokeColor . ios . CGColor ; layer . borderWidth = strokeWidth ; layer . cornerRadius = cornerRadius ; } else { const editorOffsetH = utilsModule . layout . toDevicePixels ( coreEditorPaddingHorizontal ) ; const editorOffsetV = utilsModule . layout . toDevicePixels ( coreEditorPaddingVertical ) ; editor . rootLayout ( ) . setPadding ( editorOffsetH , editorOffsetV , editorOffsetH , editorOffsetV ) ; const coreEditorView = editor . getEditorView ( ) ; const textOffsetH = utilsModule . layout . toDevicePixels ( coreEditorPaddingHorizontal ) ; const textOffsetV = utilsModule . layout . toDevicePixels ( coreEditorPaddingVertical ) ; coreEditorView . setPadding ( textOffsetH , textOffsetV , textOffsetH , textOffsetV ) ; const drawable = new android . graphics . drawable . GradientDrawable ( ) ; drawable . setCornerRadius ( utilsModule . layout . toDevicePixels ( cornerRadius ) ) ; drawable . setStroke ( utilsModule . layout . toDevicePixels ( strokeWidth ) , strokeColor . android ) ; drawable . setColor ( fillColor . android ) ; coreEditorView . setBackgroundDrawable ( drawable ) ; } } export function editorNeedsUpdate ( type ) { return editorHasValueLabel ( type ) || editorIsTextField ( type ) ; } export function editorHasValueLabel ( type ) { return type === DataFormEditorType . DatePicker || type === DataFormEditorType . TimePicker || type === DataFormEditorType . Picker ; } export function editorIsTextField ( type ) { return type === DataFormEditorType . Text || type === DataFormEditorType . Email || type === DataFormEditorType . Password || type === DataFormEditorType . Phone || type === DataFormEditorType . Number || type === DataFormEditorType . Decimal ; }