diff --git a/app/blueprints/admin.py b/app/blueprints/admin.py index dfceb16..3a638cf 100644 --- a/app/blueprints/admin.py +++ b/app/blueprints/admin.py @@ -570,13 +570,14 @@ def get_all_options(collection): 'options': [x.to_dict() for x in ac.named_area] } - # phase 1 site = get_current_site(request) if phase := site.data.get('phase'): if phase == 1: - data['_phase1'] = site.data['admin'] - data['_phase1']['fields'] = site.data.get('fields', []) + data['_phase1'] = { + 'form': site.data['admin']['form'][str(collection.id)], + 'fields': site.data.get('fields', []), + } return data diff --git a/app/helpers.py b/app/helpers.py index e61a326..99561ad 100644 --- a/app/helpers.py +++ b/app/helpers.py @@ -370,6 +370,19 @@ def save_record(record, payload, collection, uid): if len(changes): relate_changes['units'] = changes + + if phase1_raw := payload.get('_phase1'): + #record.source_data.update(phase1_raw) + raw = {} + for k, v in phase1_raw.items(): + if k in record.source_data: + if record.source_data[k] != v: + raw[k] = v + elif v != '': + raw[k] = v + #record.source_data.update(raw) + modify['source_data'] = raw + #changes['_phase1'] if len(modify): record.update(modify) #print(modify, flush=True) @@ -379,7 +392,7 @@ def save_record(record, payload, collection, uid): print('modify:', modify, flush=True) print('record:', changes, flush=True) - if len(changes) or \ + if (len(modify) and len(changes)) or \ relate_changes.get('assertions') or \ relate_changes.get('identifications') or \ relate_changes.get('named_areas') or \ diff --git a/app/models/collection.py b/app/models/collection.py index d68c896..03a1a5c 100644 --- a/app/models/collection.py +++ b/app/models/collection.py @@ -108,7 +108,7 @@ class Collection(Base, TimestampMixin): people = relationship('Person', secondary=collection_person_map, back_populates='collections') area_classes = relationship('AreaClass') organization = relationship('Organization', back_populates='collections') - site = relationship('Site') + site = relationship('Site', back_populates='collections') def get_options(self, key): if key == 'assertion_types': diff --git a/app/templates/admin/inc_record-form2.tpl.js b/app/templates/admin/inc_record-form2.tpl.js index e4d5300..f27d620 100644 --- a/app/templates/admin/inc_record-form2.tpl.js +++ b/app/templates/admin/inc_record-form2.tpl.js @@ -185,6 +185,16 @@ $( document ).ready(function() { }; const preparePayload = (options) => { + + if (options._phase1) { + const rawElem = document.querySelectorAll('.ndb-phase1-raw'); + let payload = {_phase1: {}}; + rawElem.forEach( x => { + payload._phase1[x.id.replace('raw-', '').replace('-id', '')] = x.value || ''; + }); + return payload; + } + let payload = { assertions: {}, identifications: [], @@ -890,18 +900,28 @@ $( document ).ready(function() { const label = document.createElement('label'); label.classList.add('uk-form-label'); label.setAttribute('for', `raw-${z}-id`); - const fieldInfo = findItem(z, allOptions._phase1.fields, true); - label.textContent = fieldInfo[1]; + //const fieldInfo = findItem(z, allOptions._phase1.fields, true); + label.textContent = (allOptions._phase1.fields[z]) ? allOptions._phase1.fields[z][0] : ''; const control = document.createElement('div'); control.classList.add('uk-form-controls'); - // TODO determine type - const input = document.createElement('input'); - input.classList.add('uk-input', 'uk-form-small'); - input.id = `raw-${z}-id`; - input.value = values.raw_data[z] || ''; - input.setAttribute('name', `raw_${z}`); - control.appendChild(input); - // -- + + if (allOptions._phase1.fields[z] && allOptions._phase1.fields[z].length === 1 ) { + const input = document.createElement('input'); + input.classList.add('uk-input', 'uk-form-small', 'ndb-phase1-raw'); + input.id = `raw-${z}-id`; + let val = values.raw_data[z] || ''; + input.value = val; + input.setAttribute('name', `raw_${z}`); + input.oninput = (e) => { + if ( val === e.target.value) { + e.target.classList.remove('uk-form-success'); + } else { + e.target.classList.add('uk-form-success'); + } + }; + control.appendChild(input); + } else { + } margin.appendChild(label); margin.appendChild(control); widget.appendChild(margin); diff --git a/app/templates/sites/taibol/specimen-detail.html b/app/templates/sites/taibol/specimen-detail.html index 0b654e7..d949ba5 100644 --- a/app/templates/sites/taibol/specimen-detail.html +++ b/app/templates/sites/taibol/specimen-detail.html @@ -34,7 +34,6 @@

{% if entity.collection.name == "sample_material" %}遺傳物質{% elif enti {% endif %}
-
{% if entity.collection.name == "sample_material" %}
遺傳物質標本號