@@ -14,6 +14,10 @@ import RegistrationModel from 'ember-osf-web/models/registration';
1414import captureException , { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception' ;
1515
1616import DraftRegistrationManager from 'registries/drafts/draft/draft-registration-manager' ;
17+ import buildChangeset from 'ember-osf-web/utils/build-changeset' ;
18+ import { ValidationObject } from 'ember-changeset-validations' ;
19+ import { validateFormat , validateLength } from 'ember-changeset-validations/validators' ;
20+ import { DOIRegex } from 'ember-osf-web/utils/doi' ;
1721import template from './template' ;
1822
1923export interface FinalizeRegistrationModalManager {
@@ -25,16 +29,44 @@ export interface FinalizeRegistrationModalManager {
2529 draftManager : DraftRegistrationManager ;
2630}
2731
32+ interface ManualDoiAndGuidForm {
33+ manualDoi : string ;
34+ manualGuid : string ;
35+ }
36+
2837@layout ( template )
2938@tagName ( '' )
3039export default class FinalizeRegistrationModalManagerComponent extends Component
3140 implements FinalizeRegistrationModalManager {
3241 @service intl ! : Intl ;
3342 @service toast ! : Toast ;
3443
44+ // validationFunction() {
45+ // debugger;
46+ // }
47+ manualDoiAndGuidFormChangesetValidation : ValidationObject < ManualDoiAndGuidForm > = {
48+ manualDoi : validateFormat ( {
49+ allowBlank : true ,
50+ allowNone : true ,
51+ ignoreBlank : true ,
52+ regex : DOIRegex ,
53+ type : 'invalid_doi' ,
54+ } ) ,
55+ // manualDoi: this.validationFunction,
56+ manualGuid : validateLength ( {
57+ allowBlank : true ,
58+ min :5 ,
59+ type : 'greaterThanOrEqualTo' ,
60+ translationArgs : {
61+ description : this . intl . t ( 'preprints.submit.step-title.guid' ) ,
62+ gte : '5 characters' ,
63+ } ,
64+ } ) ,
65+ } ;
3566 // Required arguments
3667 registration ! : RegistrationModel ;
3768 draftManager ! : DraftRegistrationManager ;
69+ guidAndDoiFormChangeset ! : any ;
3870
3971 // Optional arguments
4072 onSubmitRegistration ?: ( registrationId : string ) => void ;
@@ -67,6 +99,14 @@ export default class FinalizeRegistrationModalManagerComponent extends Component
6799
68100 didReceiveAttrs ( ) {
69101 assert ( 'finalize-registration-modal::manager must have a registration' , Boolean ( this . registration ) ) ;
102+ this . guidAndDoiFormChangeset = buildChangeset ( this . registration , this . manualDoiAndGuidFormChangesetValidation ) ;
103+ }
104+
105+ @action
106+ validateManualDoiAndGuid ( ) {
107+ // debugger;
108+ this . guidAndDoiFormChangeset . validate ( ) ;
109+ this . guidAndDoiFormChangeset . execute ( ) ;
70110 }
71111
72112 @action
0 commit comments