Skip to content

Commit

Permalink
show form errors for doi. #280
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 5, 2020
1 parent 632d64d commit 7569d70
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 109 deletions.
30 changes: 0 additions & 30 deletions app/components/model-validation-errors.js

This file was deleted.

24 changes: 24 additions & 0 deletions app/helpers/doi-form-errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { helper } from '@ember/component/helper';

export function doiFormErrors([ model ]) {
if (model.state === 'draft') {
return [];
}

let errorAttributes = model.validations.errors.mapBy('attribute');

// check validation errors for embed data model fragments
if (model.titles) {
model.titles.forEach((title) => {
errorAttributes = errorAttributes.concat(title.validations.errors.mapBy('attribute'));
});
}
if (model.creators) {
model.creators.forEach((creator) => {
errorAttributes = errorAttributes.concat(creator.validations.errors.mapBy('attribute'));
});
}
return errorAttributes.join(', ');
}

export default helper(doiFormErrors);
40 changes: 0 additions & 40 deletions app/helpers/form-has-errors.js

This file was deleted.

8 changes: 4 additions & 4 deletions app/templates/components/doi-upload.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</span>
</FileUpload>
</div>

<Textarea @property="xml" @rows={{15}} @showValidationOn="focusOut" @id="metadata-field" @helpText="Metadata that describe the resource. Upload a file with metadata in DataCite XML format, or one of the other supported formats. The DOI in the metadata will be replaced with the DOI in the DOI field if different." @required={{false}} as |el|>
<el.control @class="form-control metadata" />
</Textarea>
</div>

{{#form.element controlType="textarea" property="xml" rows=15 showValidationOn="focusOut" id="metadata" helpText='Metadata that describe the resource. Upload a file with metadata in DataCite XML format, or one of the other supported formats. The DOI in the metadata will be replaced with the DOI in the DOI field if different.' required=false as |el|}}
{{el.control class="form-control metadata"}}
{{/form.element}}
13 changes: 10 additions & 3 deletions app/templates/dois/show/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,17 @@
<DoiTypes @model={{model}} @form={{form}} />
<DoiDescriptions @model={{model}} @form={{form}} />

<ModelValidationErrors @model={{model}} @form={{form}} />

<div class="col-md-9 col-md-offset-3">
<button type="submit" id="doi-update" class="btn btn-sm btn-fill" disabled={{form-has-errors model}}>Update DOI</button>
{{#if (is-empty (doi-form-errors model))}}
<button type="submit" id="doi-update" class="btn btn-sm btn-fill" disabled={{false}}>Update DOI</button>
{{else}}
<BsAlert @dismissible={{false}} @type="warning">
To save this DOI, first resolve the errors with these fields: {{doi-form-errors model}}.
</BsAlert>

<button type="submit" id="doi-update" class="btn btn-sm btn-fill" disabled={{true}}>Update DOI</button>
{{/if}}

<button {{action "cancel"}} class="btn btn-sm">Cancel</button>
</div>
</BsForm>
Expand Down
13 changes: 10 additions & 3 deletions app/templates/dois/show/modify.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@
<form.element @id="url" @controlType="text" @label="URL" @property="url" @helpText="The location of the landing page with more information about the resource." @required={{false}} />
<DoiUpload @model={{model}} @form={{form}} />

<ModelValidationErrors @model={{model}} @form={{form}} />

<div class="col-md-9 col-md-offset-3">
<button type="submit" id="doi-modify" class="btn btn-sm btn-fill" disabled={{form-has-errors model}}>Update DOI</button>
{{#if (is-empty (doi-form-errors model))}}
<button type="submit" id="doi-modify" class="btn btn-sm btn-fill" disabled={{false}}>Update DOI</button>
{{else}}
<BsAlert @dismissible={{false}} @type="warning">
To save this DOI, first resolve the errors with these fields: {{doi-form-errors model}}.
</BsAlert>

<button type="submit" id="doi-modify" class="btn btn-sm btn-fill" disabled={{true}}>Update DOI</button>
{{/if}}

<button {{action "cancel"}} class="btn btn-sm">Cancel</button>
</div>
</BsForm>
Expand Down
13 changes: 10 additions & 3 deletions app/templates/repositories/show/dois/new.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@
<DoiTypes @model={{model.doi}} @form={{form}} />
<DoiDescriptions @model={{model.doi}} @form={{form}} />

<ModelValidationErrors @model={{model.doi}} @form={{form}} />

<div class="col-md-9 col-md-offset-3">
<button type="submit" id="doi-create" class="btn btn-sm btn-fill" disabled={{form-has-errors model.doi}}>Create DOI</button>
{{#if (is-empty (doi-form-errors model.doi))}}
<button type="submit" id="doi-create" class="btn btn-sm btn-fill" disabled={{false}}>Create DOI</button>
{{else}}
<BsAlert @dismissible={{false}} @type="warning">
To save this DOI, first resolve the errors with these fields: {{doi-form-errors model.doi}}.
</BsAlert>

<button type="submit" id="doi-create" class="btn btn-sm btn-fill" disabled={{true}}>Create DOI</button>
{{/if}}

<button {{action "cancel"}} class="btn btn-sm">Cancel</button>
</div>
</BsForm>
Expand Down
13 changes: 10 additions & 3 deletions app/templates/repositories/show/dois/upload.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@

<DoiUpload @model={{model.doi}} @form={{form}} />

<ModelValidationErrors @model={{model.doi}} @form={{form}} />

<div class="col-md-9 col-md-offset-3">
<button type="submit" id="doi-create" class="btn btn-sm btn-fill" disabled={{form-has-errors model.doi}}>Create DOI</button>
{{#if (is-empty (doi-form-errors model.doi))}}
<button type="submit" id="doi-create" class="btn btn-sm btn-fill" disabled={{false}}>Create DOI</button>
{{else}}
<BsAlert @dismissible={{false}} @type="warning">
To save this DOI, first resolve the errors with these fields: {{doi-form-errors model.doi}}.
</BsAlert>

<button type="submit" id="doi-create" class="btn btn-sm btn-fill" disabled={{true}}>Create DOI</button>
{{/if}}

<button {{action "cancel"}} class="btn btn-sm">Cancel</button>
</div>
</BsForm>
Expand Down
23 changes: 0 additions & 23 deletions tests/integration/components/model-validation-errors-test.js

This file was deleted.

0 comments on commit 7569d70

Please sign in to comment.