Skip to content

Commit

Permalink
Improve Subform UX
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Dec 9, 2024
1 parent 8aea58c commit 186a5d1
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 84 deletions.
72 changes: 36 additions & 36 deletions assets/vendor/manager/dist/index.js

Large diffs are not rendered by default.

File renamed without changes.
33 changes: 15 additions & 18 deletions assets/vendor/manager/index.html

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions assets/vendor/manager/index.manage.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/vendor/manager/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ onBeforeMount(()=>{
if (colorMode) {
theme.value = colorMode;
} else if (getCookie('osColorScheme')) {
theme.value = getCookie('osColorScheme');
theme.value = getCookie('osColorScheme');
}
})
Expand Down
5 changes: 3 additions & 2 deletions assets/vendor/manager/src/components/helpers/Fields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import SubLayouts from './SubLayouts.vue';
const emit = defineEmits(['update:contentlayout', 'update:loadPreset', 'update:getPreset', 'update:subFormState']);
const props = defineProps({
field: { type: Object, default: null },
scope: { type: Object, default: null }
scope: { type: Object, default: null },
actSave: {type: Boolean, default: false}
});
const constant = inject('constant', {});
Expand Down Expand Up @@ -170,7 +171,7 @@ function updateSubLayouts() {
<Presets :field="props.field" @update:loadPreset="(value) => {emit('update:loadPreset', value)}" @update:getPreset="(value) => {emit('update:getPreset', value)}" />
</div>
<div v-else-if="props.field.input.type === `astroidsubform`" class="astroid-subform">
<SubForm v-model="props.scope[props.field.name]" :field="props.field" @update:subFormState="(value) => {emit('update:subFormState', value)}" />
<SubForm v-model="props.scope[props.field.name]" :field="props.field" :actSave="props.actSave" @update:subFormState="(value) => {emit('update:subFormState', value)}" />
</div>
<div v-else-if="props.field.input.type === `astroidicons`" class="astroid-icons">
<Icons v-model="props.scope[props.field.name]" :field="props.field" />
Expand Down
46 changes: 24 additions & 22 deletions assets/vendor/manager/src/components/helpers/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,31 @@ function checkShowGroup(fields) {
}
return hasField;
}
function saveModal(){
let allowSave = true;
const actSave = ref(false);
function storeParams() {
const tmp = Object.keys(params.value).map(key => ({
name: key,
value: typeof params.value[key] === 'object' && !Array.isArray(params.value[key]) && params.value[key] !== null
? JSON.parse(JSON.stringify(params.value[key]))
: params.value[key]
}));
emit('update:saveElement', tmp);
emit('update:closeElement');
}
function saveModal() {
if (subFormOpen.value.value) {
if (!confirm(subFormOpen.value.name + ' has not been saved. Are you sure to skip the subform?')) {
allowSave = false;
const message = `${subFormOpen.value.name} has not been saved. Are you sure to save the subform?`;
if (confirm(message)) {
actSave.value = true;
setTimeout(() => {
storeParams();
actSave.value = false;
}, 1000);
} else {
storeParams();
}
}
if (allowSave) {
let tmp = [];
Object.keys(params.value).forEach(key => {
if (typeof params.value[key] === 'object' && !Array.isArray(params.value[key]) && params.value[key] !== null) {
tmp.push({
'name': key,
'value': JSON.parse(JSON.stringify(params.value[key]))
});
} else {
tmp.push({
'name': key,
'value': params.value[key]
});
}
});
emit('update:saveElement', tmp);
emit('update:closeElement')
} else {
storeParams();
}
}
function updateSubForm(value) {
Expand Down Expand Up @@ -102,6 +103,7 @@ const pro_badge = '<span class="badge text-bg-danger ms-2">PRO</span>';
<Fields
:field="field"
:scope="params"
:actSave="actSave"
@update:subFormState="updateSubForm"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ onMounted(()=> {
} else {
title.value = 'Select a sub-layout';
}
getSublayouts();
if (props.source === 'root') {
getSublayouts();
}
})
function getSublayouts() {
Expand Down
12 changes: 9 additions & 3 deletions assets/vendor/manager/src/components/helpers/SubForm.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup>
import { onBeforeMount, ref } from "vue";
import { onBeforeMount, ref, onUpdated } from "vue";
import draggable from "vuedraggable";
import Fields from './Fields.vue';
const emit = defineEmits(['update:modelValue', 'update:subFormState']);
const props = defineProps(['modelValue', 'field']);
const props = defineProps(['modelValue', 'field', 'actSave']);
const items = ref([]);
const edit = ref(false);
const params = ref(new Object());
Expand All @@ -17,6 +17,12 @@ onBeforeMount(()=>{
itemLabel.value = props.field.input.form.index !== '' ? props.field.input.form.index : 'title';
})
onUpdated(() => {
if (props.actSave && edit.value) {
saveItem();
}
})
function listUpdated() {
emit('update:subFormState', {name: props.field.label, value: false});
emit('update:modelValue', JSON.stringify(items.value));
Expand Down Expand Up @@ -132,7 +138,7 @@ function deleteItem(index) {
<div v-for="(fieldset, idx) in props.field.input.form.content" :key="fieldset.name" class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<div>Add Item</div>
<button class="btn btn-sm btn-primary btn-as-primary" @click.prevent="saveItem">Apply</button>
<button class="as-subform-apply btn btn-sm btn-primary btn-as-primary" @click.prevent="saveItem">Apply</button>
</div>
<div v-for="(group, gid) in fieldset.childs" :key="gid" :class="`group-`+gid" class="card-body">
<div v-if="group.title || group.description" class="heading-group mb-4">
Expand Down
2 changes: 1 addition & 1 deletion framework/fields/astroidlayoutmodule.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function getInput() {
&& $app->input->get('layout', '') == 'edit') {
$id = $app->input->get('id');
$layout = Layout::loadModuleLayout($id);
$constant = Helper\Constants::manager_configs('article_data');
$constant = Helper\Constants::manager_configs('joomla_module');
$json = [
'id' => $this->id,
'name' => $this->name,
Expand Down

0 comments on commit 186a5d1

Please sign in to comment.