@@ -14,6 +14,10 @@ import RegistrationModel from 'ember-osf-web/models/registration';
14
14
import captureException , { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception' ;
15
15
16
16
import 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' ;
17
21
import template from './template' ;
18
22
19
23
export interface FinalizeRegistrationModalManager {
@@ -25,16 +29,44 @@ export interface FinalizeRegistrationModalManager {
25
29
draftManager : DraftRegistrationManager ;
26
30
}
27
31
32
+ interface ManualDoiAndGuidForm {
33
+ manualDoi : string ;
34
+ manualGuid : string ;
35
+ }
36
+
28
37
@layout ( template )
29
38
@tagName ( '' )
30
39
export default class FinalizeRegistrationModalManagerComponent extends Component
31
40
implements FinalizeRegistrationModalManager {
32
41
@service intl ! : Intl ;
33
42
@service toast ! : Toast ;
34
43
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
+ } ;
35
66
// Required arguments
36
67
registration ! : RegistrationModel ;
37
68
draftManager ! : DraftRegistrationManager ;
69
+ guidAndDoiFormChangeset ! : any ;
38
70
39
71
// Optional arguments
40
72
onSubmitRegistration ?: ( registrationId : string ) => void ;
@@ -67,6 +99,14 @@ export default class FinalizeRegistrationModalManagerComponent extends Component
67
99
68
100
didReceiveAttrs ( ) {
69
101
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 ( ) ;
70
110
}
71
111
72
112
@action
0 commit comments