diff --git a/resources/assets/js/components/ColumnEditor.vue b/resources/assets/js/components/ColumnEditor.vue index 60f5ad6..b923c4f 100644 --- a/resources/assets/js/components/ColumnEditor.vue +++ b/resources/assets/js/components/ColumnEditor.vue @@ -19,6 +19,7 @@ Complex animated column editor for the table edit page Name Type Title + + + + + @@ -210,7 +222,7 @@ export default { data () { return { newColNum: 0, - orderChanged: this.orderChanged, + //orderChanged: this.orderChanged, columns: this.xColumns, colTypes: ['string', 'int', 'float', 'bool'], debouncedSortUpdate: _.debounce(() => this.submitColOrder(), 350) @@ -393,6 +405,11 @@ export default { if (!editing) { this.submitColChange(col) } else { + let origvals = {}; + _.each(col, (v, k) => { + if (k[0] != '_') origvals[k] = v + }) + this.$set(this.columns[n], '_loadvals', origvals) this.$set(this.columns[n], '_editing', true) } }, @@ -424,6 +441,22 @@ export default { this.columns = resp.data this.orderChanged = false }) + }, + + colNeedsSave(col) { + if (!col._loadvals) return false; + for (const [key, value] of Object.entries(col._loadvals)) { + // changed if differs from orig value and also from previous value from revision + if (col[key] != value) return true + } + return false + }, + + discardEdit(col) { + col._editing = false; + for (const [key, value] of Object.entries(col._loadvals)) { + col[key] = value + } } } } diff --git a/resources/assets/js/components/DraftNotePage.js b/resources/assets/js/components/DraftNotePage.js index 2470efe..274d8d3 100644 --- a/resources/assets/js/components/DraftNotePage.js +++ b/resources/assets/js/components/DraftNotePage.js @@ -1,21 +1,38 @@ import { query } from './table-editor-utils' -export default function (dataRoute) { +export default function (opts) { let $note = $('#field-note') - let lastText = $note.val() + let $submit = $('#submit-button') + let $emptyPrompt = $('#empty-note-prompt') + let lastText = $note.val().trim() let handler = _.debounce(function () { - query(dataRoute, { + query(opts.route, { action: 'note.set', text: lastText }) }, 350) $note.on('input', () => { - let text = $note.val() + let text = $note.val().trim() if (text !== lastText) { lastText = text handler() + + let empty = text.length === 0 + if (opts.anyChanges) { + $submit.toggleClass('disabled', empty) + } + + // Hide prompt text if anything is written + $emptyPrompt.toggleClass('hidden', !empty) + } + }) + + // prevent submit with empty note + $submit.on('click', (e) => { + if ($note.val().trim().length === 0) { + e.preventDefault() } }) } diff --git a/resources/views/table/propose/review.blade.php b/resources/views/table/propose/review.blade.php index bb31bac..92155ab 100644 --- a/resources/views/table/propose/review.blade.php +++ b/resources/views/table/propose/review.blade.php @@ -16,7 +16,7 @@ $anyColChanges = $numChangedColumns || $numNewColumns || $numRemovedColumns || $colsReordered; - $anyChanges = $anyRowChanges || $anyColChanges; + $anyChanges = ($anyRowChanges || $anyColChanges) && strlen(trim($changeset->note)) > 0; @endphp @extends('table.propose.layout') @@ -123,14 +123,20 @@
@if(user()->ownsTable($table)) - + @icon(fa-save fa-pr)Save & Apply @else - + @icon(fa-paper-plane-o fa-pr)Submit for review @endif + + @if($anyRowChanges || $anyColChanges) + Write a summary to submit your changes. + @else + No changes to submit. + @endif
@@ -141,7 +147,10 @@ @push('scripts') @endpush