mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-12-09 13:46:21 +08:00
Fix checklist issues [SCI-6960] (#4222)
This commit is contained in:
parent
33e3d0f3f0
commit
c89968453e
5 changed files with 24 additions and 12 deletions
|
|
@ -30,7 +30,9 @@ module StepElements
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@checklist_item.assign_attributes(checklist_item_params)
|
@checklist_item.assign_attributes(
|
||||||
|
checklist_item_params.merge(last_modified_by: current_user)
|
||||||
|
)
|
||||||
|
|
||||||
if @checklist_item.save!
|
if @checklist_item.save!
|
||||||
if @checklist_item.saved_change_to_attribute?(:checked)
|
if @checklist_item.saved_change_to_attribute?(:checked)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
<div class="step-element-header">
|
<div class="step-element-header">
|
||||||
<div class="step-controls">
|
<div class="step-controls">
|
||||||
<div v-if="reorderStepUrl" class="step-element-grip" @click="$emit('reorder')">
|
<div v-if="reorderStepUrl" class="step-element-grip" @click="$emit('reorder')">
|
||||||
<i class="fas fa-grip-vertical"></i>
|
<i class="fas fas-rotated-90 fa-exchange-alt"></i>
|
||||||
</div>
|
</div>
|
||||||
<a class="step-collapse-link"
|
<a class="step-collapse-link"
|
||||||
:href="'#stepBody' + step.id"
|
:href="'#stepBody' + step.id"
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,10 @@
|
||||||
},
|
},
|
||||||
reorderElementUrl: {
|
reorderElementUrl: {
|
||||||
type: String
|
type: String
|
||||||
|
},
|
||||||
|
isNew: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|
@ -109,6 +113,10 @@
|
||||||
this.checklistItems = this.element.attributes.orderable.checklist_items.map((item, index) => {
|
this.checklistItems = this.element.attributes.orderable.checklist_items.map((item, index) => {
|
||||||
return { attributes: {...item, position: index } }
|
return { attributes: {...item, position: index } }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.isNew) {
|
||||||
|
this.addItem();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
orderedChecklistItems() {
|
orderedChecklistItems() {
|
||||||
|
|
@ -177,7 +185,8 @@
|
||||||
attributes: {
|
attributes: {
|
||||||
text: '',
|
text: '',
|
||||||
checked: false,
|
checked: false,
|
||||||
position: this.checklistItems.length
|
position: this.checklistItems.length,
|
||||||
|
isNew: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
@ -212,7 +221,7 @@
|
||||||
},
|
},
|
||||||
handleMultilinePaste(data) {
|
handleMultilinePaste(data) {
|
||||||
this.linesToPaste = data.length;
|
this.linesToPaste = data.length;
|
||||||
let nextPosition = this.checklistItems.length;
|
let nextPosition = this.checklistItems.length - 1;
|
||||||
|
|
||||||
// we need to post items to API in the right order, to avoid positions breaking
|
// we need to post items to API in the right order, to avoid positions breaking
|
||||||
let synchronousPost = (index) => {
|
let synchronousPost = (index) => {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
<input ref="checkbox"
|
<input ref="checkbox"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="sci-checkbox"
|
class="sci-checkbox"
|
||||||
|
:disabled="checklistItem.attributes.isNew"
|
||||||
:checked="checklistItem.attributes.checked" @change="toggleChecked($event)" />
|
:checked="checklistItem.attributes.checked" @change="toggleChecked($event)" />
|
||||||
<span class="sci-checkbox-label" >
|
<span class="sci-checkbox-label" >
|
||||||
</span>
|
</span>
|
||||||
|
|
@ -24,7 +25,7 @@
|
||||||
:autofocus="editingText"
|
:autofocus="editingText"
|
||||||
:attributeName="`${i18n.t('ChecklistItem')} ${i18n.t('name')}`"
|
:attributeName="`${i18n.t('ChecklistItem')} ${i18n.t('name')}`"
|
||||||
:multilinePaste="true"
|
:multilinePaste="true"
|
||||||
:editOnload="newItem()"
|
:editOnload="checklistItem.attributes.isNew"
|
||||||
:smartAnnotation="true"
|
:smartAnnotation="true"
|
||||||
@editingEnabled="enableTextEdit"
|
@editingEnabled="enableTextEdit"
|
||||||
@editingDisabled="disableTextEdit"
|
@editingDisabled="disableTextEdit"
|
||||||
|
|
@ -41,23 +42,21 @@
|
||||||
<button v-if="!checklistItem.attributes.urls || updateUrl" class="btn icon-btn btn-light" @click="enableTextEdit" tabindex="-1">
|
<button v-if="!checklistItem.attributes.urls || updateUrl" class="btn icon-btn btn-light" @click="enableTextEdit" tabindex="-1">
|
||||||
<i class="fas fa-pen"></i>
|
<i class="fas fa-pen"></i>
|
||||||
</button>
|
</button>
|
||||||
<button v-if="!checklistItem.attributes.urls || deleteUrl" class="btn icon-btn btn-light" @click="showDeleteModal" tabindex="-1">
|
<button v-if="!checklistItem.attributes.urls || deleteUrl" class="btn icon-btn btn-light" @click="deleteElement" tabindex="-1">
|
||||||
<i class="fas fa-trash"></i>
|
<i class="fas fa-trash"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<deleteElementModal v-if="confirmingDelete" @confirm="deleteElement" @cancel="closeDeleteModal"/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import DeleteMixin from 'vue/protocol/mixins/components/delete.js'
|
import DeleteMixin from 'vue/protocol/mixins/components/delete.js'
|
||||||
import deleteElementModal from 'vue/protocol/modals/delete_element.vue'
|
|
||||||
import InlineEdit from 'vue/shared/inline_edit.vue'
|
import InlineEdit from 'vue/shared/inline_edit.vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ChecklistItem',
|
name: 'ChecklistItem',
|
||||||
components: { deleteElementModal, InlineEdit },
|
components: { InlineEdit },
|
||||||
mixins: [DeleteMixin],
|
mixins: [DeleteMixin],
|
||||||
props: {
|
props: {
|
||||||
checklistItem: {
|
checklistItem: {
|
||||||
|
|
@ -107,6 +106,10 @@
|
||||||
this.$emit('editStart');
|
this.$emit('editStart');
|
||||||
},
|
},
|
||||||
disableTextEdit() {
|
disableTextEdit() {
|
||||||
|
if (this.checklistItem.attributes.isNew) {
|
||||||
|
this.removeItem();
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.editingText = false;
|
this.editingText = false;
|
||||||
this.$emit('editEnd');
|
this.$emit('editEnd');
|
||||||
},
|
},
|
||||||
|
|
@ -131,9 +134,6 @@
|
||||||
this.$emit('removeItem', this.checklistItem.attributes.position);
|
this.$emit('removeItem', this.checklistItem.attributes.position);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
newItem(){
|
|
||||||
return this.checklistItem.attributes.text === ''
|
|
||||||
},
|
|
||||||
update() {
|
update() {
|
||||||
this.$emit('update', this.checklistItem);
|
this.$emit('update', this.checklistItem);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
@keydown="handleKeypress"
|
@keydown="handleKeypress"
|
||||||
@paste="handlePaste"
|
@paste="handlePaste"
|
||||||
@blur="handleBlur"
|
@blur="handleBlur"
|
||||||
|
@keyup.escape="cancelEdit"
|
||||||
></textarea>
|
></textarea>
|
||||||
<div v-else @click="enableEdit($event)" class="sci-inline-edit__view" v-html="sa_value || value || placeholder" :class="{ 'blank': isBlank }"></div>
|
<div v-else @click="enableEdit($event)" class="sci-inline-edit__view" v-html="sa_value || value || placeholder" :class="{ 'blank': isBlank }"></div>
|
||||||
<div v-if="editing && error" class="sci-inline-edit__error">
|
<div v-if="editing && error" class="sci-inline-edit__error">
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue