-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from datacite/feature_dates_field
Feature dates field
- Loading branch information
Showing
26 changed files
with
427 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Component from '@ember/component'; | ||
|
||
const dateTypesCompleteList = [ | ||
'Accepted', | ||
'Available', | ||
'Copyrighted', | ||
'Collected', | ||
'Created', | ||
'Issued', | ||
'Submitted', | ||
'Updated', | ||
'Valid', | ||
'Withdrawn', | ||
'Other', | ||
]; | ||
|
||
|
||
export default Component.extend({ | ||
dateTypesCompleteList, | ||
dateTypesList: dateTypesCompleteList, | ||
dateTypes: [], | ||
|
||
actions: { | ||
updateDate(value) { | ||
this.fragment.set('date', value); | ||
}, | ||
selectDateType(value) { | ||
this.fragment.set('dateType', value); | ||
this.set('dateType', this.dateTypesCompleteList); | ||
}, | ||
updateDateInformation(value) { | ||
this.fragment.set('dateInformation', value); | ||
}, | ||
deleteDate() { | ||
this.model.get('dates').removeObject(this.fragment); | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import Component from '@ember/component'; | ||
|
||
export default Component.extend({ | ||
validationClass: null, | ||
|
||
didReceiveAttrs() { | ||
this._super(...arguments); | ||
|
||
if (!this.model.get('dates')) { | ||
this.model.set('dates', []); | ||
} | ||
if (this.model.get('dates').length == 0) { | ||
this.model.get('dates').createFragment(); | ||
} | ||
}, | ||
actions: { | ||
addDate() { | ||
console.log(this.model.get('dates')); | ||
console.log(this.model); | ||
this.model.get('dates').createFragment(); | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
|
||
import DS from 'ember-data'; | ||
import MF from 'ember-data-model-fragments'; | ||
import { validator, buildValidations } from 'ember-cp-validations'; | ||
import { computed } from '@ember/object'; | ||
|
||
const Validations = buildValidations({ | ||
dateType: [ | ||
validator('presence', { | ||
presence: true, | ||
message: 'Date type must be included when adding a Date', | ||
isWarning: computed('model.state', function() { | ||
return this.model.get('state') === 'draft'; | ||
}), | ||
disabled: computed('model.date', function() { | ||
return this.model.get('date') == null; | ||
}), | ||
}), | ||
], | ||
date: [ | ||
validator('date-format', { | ||
allowBlank: true, | ||
isWarning: computed('model.state', function() { | ||
return this.model.get('state') === 'draft'; | ||
}), | ||
}), | ||
], | ||
}); | ||
|
||
export default MF.Fragment.extend(Validations, { | ||
date: DS.attr('string'), | ||
dateType: DS.attr('string'), | ||
dateInformation: DS.attr('string'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
{{#if (gt index 0)}} | ||
<div class="power-select-label"> | ||
<label for="dateType" class="subtitle">Date Type</label> | ||
</div> | ||
{{/if}} | ||
|
||
<div class="power-select-fragment"> | ||
{{#form.element | ||
controlType="power-select" | ||
helpText="Type of date. " | ||
value=fragment.dateType | ||
options=dateTypesList | ||
destination=fragment.dateType | ||
disabled=disabled as |el|}} | ||
{{el.control onChange=(action "selectDateType") placeholder="Select Date Type" allowClear=false}} | ||
{{/form.element}} | ||
</div> | ||
|
||
<div class="power-select-label"> | ||
<label for="dateInformation" class="subtitle">Date (optional)</label> | ||
</div> | ||
|
||
{{#if (gt index 0)}} | ||
<div class="input-group"> | ||
<input class="form-control date-field" value={{fragment.date}} onblur={{action "updateDate" value="target.value"}} placeholder="Date" | ||
data-test-date /> | ||
<span class="input-group-addon"> | ||
<BsButton @outline={{true}} @onClick={{action "deleteDate" index}}>{{fa-icon "trash" pull="left" style="margin:0;"}} | ||
</BsButton> | ||
</span> | ||
</div> | ||
{{else}} | ||
<input class="form-control date-field" value={{fragment.date}} onblur={{action "updateDate" value="target.value"}} placeholder="Date" | ||
data-test-date /> | ||
<div class="help-block help-block-fragment">Different dates relevant to the work. </div> | ||
{{/if}} | ||
|
||
|
||
<div class="power-select-label"> | ||
<label for="dateInformation" class="subtitle">Date Information (optional)</label> | ||
</div> | ||
|
||
<input class="form-control date-information-field" value={{fragment.dateInformation}} | ||
placeholder="Date Information" | ||
oninput={{action "updateDateInformation" value="target.value"}} data-test-date /> | ||
<div class="help-block help-block-fragment">Specific information about the date, if appropriate.</div> | ||
|
||
|
||
<hr /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<div class="form-group {{validationClass}}"> | ||
<label class="control-label col-md-3">Date(s) (optional)</label> | ||
<div class="col-md-9"> | ||
{{#each model.dates as |date index|}} | ||
<DoiDate @model={{model}} @fragment={{date}} @form={{form}} @index={{index}} /> | ||
{{/each}} | ||
|
||
{{#if (or (not model.dates) (lte model.dates.length 4))}} | ||
<BsButton @class="btn-sm" @id="add-date" @outline={{true}} @onClick={{action "addDate"}}>{{fa-icon "plus"}} Add {{if (gt model.dates.length 0) "another "}}date</BsButton> | ||
{{/if}} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.