diff --git a/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/FieldTotal.vue b/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/FieldTotal.vue
index b69b5770bd..85e028eb55 100644
--- a/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/FieldTotal.vue
+++ b/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/FieldTotal.vue
@@ -3,6 +3,7 @@
{ fieldOccurence.isUnsaved = true }"
/>
diff --git a/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/Identifier/IdentifierForm.vue b/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/Identifier/IdentifierForm.vue
index b3e9ae5fd9..dfaf169b94 100644
--- a/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/Identifier/IdentifierForm.vue
+++ b/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/Identifier/IdentifierForm.vue
@@ -15,7 +15,10 @@
others.
-
+
@@ -27,7 +30,7 @@
existingIdentifier && !isCreatedIdentifierCurrent
}"
type="text"
- @input="checkIdentifier"
+ @input="findExistingIdentifier"
@change="() => (store.identifier.isUnsaved = true)"
v-model="store.identifier.identifier"
/>
@@ -46,7 +49,7 @@
/>
Namespace is needed.
@@ -102,7 +105,7 @@ function findExistingIdentifier() {
if (timeOut) {
clearTimeout(timeOut)
}
- if (store.identifier.identifier) {
+ if (store.identifier.identifier && store.namespace) {
timeOut = setTimeout(() => {
Identifier.where({
type: IDENTIFIER_LOCAL_CATALOG_NUMBER,
@@ -117,9 +120,8 @@ function findExistingIdentifier() {
}
}
-function setNamespace(namespace) {
- store.namespace = namespace
- store.isUnsaved = true
+function namespaceSelected() {
+ store.identifier.isUnsaved = true
findExistingIdentifier()
}
function unsetNamespace() {
diff --git a/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/Identifier/NamespaceForm.vue b/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/Identifier/NamespaceForm.vue
index 7caaaa62fa..0d3a9e4f24 100644
--- a/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/Identifier/NamespaceForm.vue
+++ b/app/javascript/vue/tasks/field_occurrences/new/components/FieldOccurenceForm/Identifier/NamespaceForm.vue
@@ -10,12 +10,12 @@
pin-section="Namespaces"
pin-type="Namespace"
v-model="namespace"
- @selected="(item) => (namespace = item)"
+ @selected="(item) => (updateNamespace(item))"
>
- (namespace = item)" />
+ (updateNamespace(item))" />
@@ -23,7 +23,7 @@
(namespace = undefined)"
+ @click="() => (updateNamespace(undefined))"
/>
@@ -37,10 +37,17 @@ import SmartSelectorItem from '@/components/ui/SmartSelectorItem.vue'
import VLock from '@/components/ui/VLock/index.vue'
import useSettingStore from '../../../store/settings.js'
+const emit = defineEmits(['selected'])
+
const namespace = defineModel({
type: Object,
default: undefined
})
const settings = useSettingStore()
+
+function updateNamespace(newNamespace) {
+ namespace.value = newNamespace
+ emit('selected')
+}
diff --git a/app/javascript/vue/tasks/field_occurrences/new/components/HeaderBar.vue b/app/javascript/vue/tasks/field_occurrences/new/components/HeaderBar.vue
index 1b44e02e83..ccae1ee10b 100644
--- a/app/javascript/vue/tasks/field_occurrences/new/components/HeaderBar.vue
+++ b/app/javascript/vue/tasks/field_occurrences/new/components/HeaderBar.vue
@@ -88,7 +88,6 @@ import useDeterminationStore from '../store/determinations.js'
import useSettingStore from '../store/settings.js'
import useBiocurationStore from '../store/biocurations.js'
import useBiologicalAssociationStore from '../store/biologicalAssociations.js'
-import useIdentifierStore from '../store/identifier.js'
import useDepictionStore from '../store/depictions.js'
import VBtn from '@/components/ui/VBtn/index.vue'
import VRecent from './Recent.vue'
@@ -106,7 +105,6 @@ const determinationStore = useDeterminationStore()
const biologicalAssociationStore = useBiologicalAssociationStore()
const ceStore = useCEStore()
const biocurationStore = useBiocurationStore()
-const identifierStore = useIdentifierStore()
const depictionStore = useDepictionStore()
const fieldOccurrenceId = computed(() => foStore.fieldOccurrence.id)
const isUnsaved = computed(
@@ -115,8 +113,7 @@ const isUnsaved = computed(
determinationStore.hasUnsaved ||
biocurationStore.hasUnsaved ||
foStore.fieldOccurrence.isUnsaved ||
- ceStore.isUnsaved ||
- identifierStore.isUnsaved
+ ceStore.isUnsaved
)
const validateSave = computed(() => {
@@ -144,7 +141,6 @@ async function save() {
citationStore.save(args),
determinationStore.load(args),
biocurationStore.save(args),
- identifierStore.save(args),
biologicalAssociationStore.save(args)
]
@@ -180,7 +176,6 @@ function reset() {
}
depictionStore.$reset()
- identifierStore.reset({ keepNamespace: locked.namespace })
determinationStore.reset({ keepRecords: locked.taxonDeterminations })
citationStore.reset({ keepRecords: locked.citations })
biologicalAssociationStore.reset({
@@ -237,7 +232,6 @@ async function loadForms(id) {
determinationStore.load(args),
biocurationStore.load(args),
citationStore.load(args),
- identifierStore.load(args),
biologicalAssociationStore.load(args),
depictionStore.load(args)
]
diff --git a/app/javascript/vue/tasks/field_occurrences/new/components/Recent.vue b/app/javascript/vue/tasks/field_occurrences/new/components/Recent.vue
index f448343016..d4ba7fd601 100644
--- a/app/javascript/vue/tasks/field_occurrences/new/components/Recent.vue
+++ b/app/javascript/vue/tasks/field_occurrences/new/components/Recent.vue
@@ -20,16 +20,30 @@
Total |
+ |
|
+
+ selectFO(item)"
+ >
+
+
+ |
+
+
@@ -40,6 +54,7 @@
import VModal from '@/components/ui/Modal'
import VSpinner from '@/components/ui/VSpinner.vue'
import VBtn from '@/components/ui/VBtn/index.vue'
+import VIcon from '@/components/ui/VIcon/index.vue'
import { FieldOccurrence } from '@/routes/endpoints'
import { ref, watch } from 'vue'
diff --git a/app/javascript/vue/tasks/field_occurrences/new/store/identifier.js b/app/javascript/vue/tasks/field_occurrences/new/store/identifier.js
index d30bda3475..0161218929 100644
--- a/app/javascript/vue/tasks/field_occurrences/new/store/identifier.js
+++ b/app/javascript/vue/tasks/field_occurrences/new/store/identifier.js
@@ -41,19 +41,25 @@ export default defineStore('identifiers', {
},
reset({ keepNamespace }) {
- this.identifier.id = null
+ const newIdentifierId = this.increment
+ ? incrementIdentifier(this.identifier.identifier)
+ : null
+ this.identifier = {
+ ...makeIdentifier(),
+ identifier: newIdentifierId,
+ }
if (!keepNamespace) {
this.namespace = null
}
-
- this.identifier.identifier = this.increment
- ? incrementIdentifier(this.identifier.identifier)
- : null
},
save({ objectId, objectType }) {
- if (!this.identifier.isUnsaved) return
+ if (!this.identifier.isUnsaved ||
+ !this.identifier.identifier || !this.namespace?.id
+ ) {
+ return
+ }
const payload = {
identifier: {
@@ -74,7 +80,7 @@ export default defineStore('identifiers', {
.then(({ body }) => {
this.identifier = body
})
- .catch({})
+ .catch(() => {})
return request
}
diff --git a/app/models/field_occurrence.rb b/app/models/field_occurrence.rb
index c3943b5393..f2d53a0269 100644
--- a/app/models/field_occurrence.rb
+++ b/app/models/field_occurrence.rb
@@ -63,6 +63,7 @@ class FieldOccurrence < ApplicationRecord
validate :check_that_either_total_or_ranged_lot_category_id_is_present
validate :check_that_both_of_category_and_total_are_not_present
validate :total_zero_when_absent
+ validate :total_positive_when_present
accepts_nested_attributes_for :collecting_event, allow_destroy: true, reject_if: :reject_collecting_event
@@ -76,6 +77,10 @@ def total_zero_when_absent
errors.add(:total, 'Must be zero when absent.') if (total != 0) && is_absent
end
+ def total_positive_when_present
+ errors.add(:total, 'Must be positive when not absent.') if !is_absent && total.present? && total <= 0
+ end
+
def check_that_both_of_category_and_total_are_not_present
errors.add(:ranged_lot_category_id, 'Both ranged_lot_category and total can not be set') if ranged_lot_category_id.present? && total.present?
end
diff --git a/app/models/identifier/local/catalog_number.rb b/app/models/identifier/local/catalog_number.rb
index 933f8f7c2d..dea3a4e8e9 100644
--- a/app/models/identifier/local/catalog_number.rb
+++ b/app/models/identifier/local/catalog_number.rb
@@ -26,9 +26,15 @@ def dwc_occurrences
private
def assigned_to_valid_object
- # TODO: unkludge
- if (identifier_object_type && !(TARGETS.include?(identifier_object_type))) || ( identifier_object && !identifier_object.kind_of?(CollectionObject) && !identifier_object.kind_of?(Container) && !identifier_object.kind_of?(Extract) )
- errors.add(:identifier_object_type, "only assignable to #{TARGETS.join(', ')}")
+ type_issue =
+ identifier_object_type && !TARGETS.include?(identifier_object_type)
+
+ object_issue = identifier_object &&
+ TARGETS.none? { |c| identifier_object.kind_of?(c.constantize) }
+
+ if type_issue || object_issue
+ errors.add(:identifier_object_type, "only assignable to #{TARGETS.join(', ')}
+ ")
end
end