parent
467a8d8b64
commit
2ead72c552
6 changed files with 54 additions and 17 deletions
|
@ -1,7 +1,11 @@
|
||||||
|
import { getProperties, set } from '@ember/object';
|
||||||
import Component from '@ember/component';
|
import Component from '@ember/component';
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
|
import { debounce } from '@ember/runloop';
|
||||||
|
import RSVP from 'rsvp';
|
||||||
import Changeset from 'ember-changeset';
|
import Changeset from 'ember-changeset';
|
||||||
import lookupValidator from 'ember-changeset-validations';
|
import lookupValidator from 'ember-changeset-validations';
|
||||||
|
import config from 'ccdb-web/config/environment';
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
store: service(),
|
store: service(),
|
||||||
|
@ -33,6 +37,7 @@ export default Component.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
this.set('changesets', changesets);
|
this.set('changesets', changesets);
|
||||||
|
this.set('newStudyLocationAdmin', `${config.APP.API_HOST}/admin/locations/studylocation/add/`);
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -55,8 +60,34 @@ export default Component.extend({
|
||||||
changesets['hasMany'][relatedName].removeObject(changesetRecord);
|
changesets['hasMany'][relatedName].removeObject(changesetRecord);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Gross, this side-effects by saving immediately. Someday I should clean
|
||||||
|
// this up, but for now, you have been warned.
|
||||||
|
addOption(relatedModelName, optionName, collectionAttrName, relatedAttrName, term) {
|
||||||
|
const props = getProperties(this, 'store', 'options', 'changesets');
|
||||||
|
const { store, options, changesets: { model } } = props;
|
||||||
|
let payload = {};
|
||||||
|
payload[relatedAttrName] = term;
|
||||||
|
const record = store.createRecord(relatedModelName, payload)
|
||||||
|
record.save().then((record) => {
|
||||||
|
set(options, optionName, store.peekAll(relatedModelName));
|
||||||
|
set(model, collectionAttrName, record);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
updateDatasheet(changeset, event) {
|
updateDatasheet(changeset, event) {
|
||||||
changeset.set('datasheet', event.target.files[0]);
|
changeset.set('datasheet', event.target.files[0]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
searchStudyLocation(term) {
|
||||||
|
return new RSVP.Promise((resolve, reject) => {
|
||||||
|
debounce(this, this._performSearch, 'study-location', { page_size: 500, code: term }, resolve, reject, 400);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
_performSearch(model, payload, resolve, reject) {
|
||||||
|
this.get('store').query(model, payload).then((results) => {
|
||||||
|
resolve(results);
|
||||||
|
}, reject);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default Route.extend({
|
||||||
return RSVP.hash({
|
return RSVP.hash({
|
||||||
model: store.createRecord('collection'),
|
model: store.createRecord('collection'),
|
||||||
projectOptions: store.findAll('project'),
|
projectOptions: store.findAll('project'),
|
||||||
studyLocationOptions: store.findAll('study-location'),
|
studyLocationOptions: store.query('study-location', { page_size: 500 }),
|
||||||
collectionTypeOptions: store.findAll('collection-type'),
|
collectionTypeOptions: store.findAll('collection-type'),
|
||||||
collectionMethodOptions: store.findAll('collection-method'),
|
collectionMethodOptions: store.findAll('collection-method'),
|
||||||
speciesOptions: store.query('species', { page_size: 500 }),
|
speciesOptions: store.query('species', { page_size: 500 }),
|
||||||
|
|
|
@ -8,7 +8,7 @@ export default Route.extend({
|
||||||
return RSVP.hash({
|
return RSVP.hash({
|
||||||
model: model,
|
model: model,
|
||||||
projectOptions: store.findAll('project'),
|
projectOptions: store.findAll('project'),
|
||||||
studyLocationOptions: store.findAll('study-location'),
|
studyLocationOptions: store.query('study-location', { page_size: 500 }),
|
||||||
collectionTypeOptions: store.findAll('collection-type'),
|
collectionTypeOptions: store.findAll('collection-type'),
|
||||||
collectionMethodOptions: store.findAll('collection-method'),
|
collectionMethodOptions: store.findAll('collection-method'),
|
||||||
speciesOptions: store.query('species', { page_size: 500 }),
|
speciesOptions: store.query('species', { page_size: 500 }),
|
||||||
|
|
|
@ -29,7 +29,7 @@ export default Route.extend({
|
||||||
projectOptions: store.findAll('project'),
|
projectOptions: store.findAll('project'),
|
||||||
regionOptions: store.findAll('region'),
|
regionOptions: store.findAll('region'),
|
||||||
siteOptions: store.findAll('site'),
|
siteOptions: store.findAll('site'),
|
||||||
studyLocationOptions: store.findAll('study-location'),
|
studyLocationOptions: store.query('study-location', { page_size: 500 }),
|
||||||
collectionMethodOptions: store.findAll('collection-method'),
|
collectionMethodOptions: store.findAll('collection-method'),
|
||||||
adfgPermitOptions: store.findAll('adfg-permit'),
|
adfgPermitOptions: store.findAll('adfg-permit'),
|
||||||
speciesOptions: store.query('species', { page_size: 500 }),
|
speciesOptions: store.query('species', { page_size: 500 }),
|
||||||
|
|
|
@ -21,27 +21,33 @@
|
||||||
{{/validated-field}}
|
{{/validated-field}}
|
||||||
|
|
||||||
{{#validated-field property='adfgPermit' label='ADFG Permit' changeset=changeset}}
|
{{#validated-field property='adfgPermit' label='ADFG Permit' changeset=changeset}}
|
||||||
{{#power-select
|
{{#power-select-with-create
|
||||||
options=options.adfgPermits
|
options=options.adfgPermits
|
||||||
selected=changeset.adfgPermit
|
selected=changeset.adfgPermit
|
||||||
onchange=(action (mut changeset.adfgPermit))
|
onchange=(action (mut changeset.adfgPermit))
|
||||||
|
oncreate=(action 'addOption' 'adfg-permit' 'adfgPermits' 'adfgPermit' 'name')
|
||||||
searchField='name'
|
searchField='name'
|
||||||
as |adfgPermit|
|
as |adfgPermit term|
|
||||||
}}
|
}}
|
||||||
{{adfgPermit.name}}
|
{{adfgPermit.name}}
|
||||||
{{/power-select}}
|
{{/power-select-with-create}}
|
||||||
{{/validated-field}}
|
{{/validated-field}}
|
||||||
|
|
||||||
{{#validated-field property='studyLocation' label='Study location' changeset=changeset}}
|
{{#validated-field property='studyLocation' changeset=changeset}}
|
||||||
{{#power-select
|
<label class="control-label">
|
||||||
options=options.studyLocations
|
Study location
|
||||||
selected=changeset.studyLocation
|
<a href="{{newStudyLocationAdmin}}" target="_blank">+</a>
|
||||||
onchange=(action (mut changeset.studyLocation))
|
</label>
|
||||||
searchField='name'
|
{{#power-select
|
||||||
as |studyLocation|
|
search=(action 'searchStudyLocation')
|
||||||
}}
|
options=options.studyLocations
|
||||||
{{studyLocation.name}}
|
selected=changeset.studyLocation
|
||||||
{{/power-select}}
|
onchange=(action (mut changeset.studyLocation))
|
||||||
|
searchField='code'
|
||||||
|
as |studyLocation|
|
||||||
|
}}
|
||||||
|
{{studyLocation.code}}
|
||||||
|
{{/power-select}}
|
||||||
{{/validated-field}}
|
{{/validated-field}}
|
||||||
|
|
||||||
{{#validated-field property='collectionType' label='Collection type' changeset=changeset}}
|
{{#validated-field property='collectionType' label='Collection type' changeset=changeset}}
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
"ember-moment": "7.3.1",
|
"ember-moment": "7.3.1",
|
||||||
"ember-pikaday": "^2.2.3",
|
"ember-pikaday": "^2.2.3",
|
||||||
"ember-power-select": "^1.8.5",
|
"ember-power-select": "^1.8.5",
|
||||||
"ember-power-select-with-create": "0.4.3",
|
"ember-power-select-with-create": "^0.4.3",
|
||||||
"ember-resolver": "^4.0.0",
|
"ember-resolver": "^4.0.0",
|
||||||
"ember-responsive": "^2.0.4",
|
"ember-responsive": "^2.0.4",
|
||||||
"ember-simple-auth": "1.4.0",
|
"ember-simple-auth": "1.4.0",
|
||||||
|
|
Loading…
Add table
Reference in a new issue