476 lines
15 KiB
Vue
476 lines
15 KiB
Vue
<template>
|
|
<div v-if="value != null" class="mt-8">
|
|
<v-row>
|
|
<v-col cols="12">
|
|
<v-menu offset-y>
|
|
<template v-slot:activator="{ on, attrs }">
|
|
<div class="text-h6">
|
|
<v-icon large :color="hasData ? 'primary' : null" class="mr-2"
|
|
>$ayiFan</v-icon
|
|
>
|
|
{{ $ay.t("WorkOrderItemUnitList") }}
|
|
<v-btn v-if="!parentDeleted" large icon v-bind="attrs" v-on="on">
|
|
<v-icon small color="primary">$ayiEllipsisV</v-icon>
|
|
</v-btn>
|
|
</div>
|
|
</template>
|
|
<v-list>
|
|
<v-list-item v-if="canAdd" @click="newItem">
|
|
<v-list-item-icon>
|
|
<v-icon>$ayiPlus</v-icon>
|
|
</v-list-item-icon>
|
|
<v-list-item-title>{{ $ay.t("New") }}</v-list-item-title>
|
|
</v-list-item>
|
|
<v-list-item v-if="canDelete && isDeleted" @click="unDeleteItem">
|
|
<v-list-item-icon>
|
|
<v-icon>$ayiTrashRestoreAlt</v-icon>
|
|
</v-list-item-icon>
|
|
<v-list-item-title>{{ $ay.t("Undelete") }}</v-list-item-title>
|
|
</v-list-item>
|
|
<v-list-item v-if="canDelete && !isDeleted" @click="deleteItem">
|
|
<v-list-item-icon>
|
|
<v-icon>$ayiTrashAlt</v-icon>
|
|
</v-list-item-icon>
|
|
<v-list-item-title>{{ $ay.t("SoftDelete") }}</v-list-item-title>
|
|
</v-list-item>
|
|
<v-list-item v-if="canDeleteAll" @click="deleteAllItem">
|
|
<v-list-item-icon>
|
|
<v-icon>$ayiTrashAlt</v-icon>
|
|
</v-list-item-icon>
|
|
<v-list-item-title>{{
|
|
$ay.t("SoftDeleteAll")
|
|
}}</v-list-item-title>
|
|
</v-list-item>
|
|
</v-list>
|
|
</v-menu>
|
|
</v-col>
|
|
|
|
<template v-if="hasData">
|
|
<!-- ############################################################### -->
|
|
<v-col cols="12" class="mb-10">
|
|
<v-data-table
|
|
:headers="headerList"
|
|
:items="itemList"
|
|
item-key="index"
|
|
v-model="selectedRow"
|
|
class="elevation-1"
|
|
disable-pagination
|
|
disable-filtering
|
|
disable-sort
|
|
hide-default-footer
|
|
data-cy="unitsTable"
|
|
dense
|
|
:item-class="itemRowClasses"
|
|
@click:row="handleRowClick"
|
|
:show-select="$vuetify.breakpoint.xs"
|
|
single-select
|
|
>
|
|
</v-data-table>
|
|
</v-col>
|
|
</template>
|
|
<template v-if="hasData && hasSelection">
|
|
<div ref="unittopform"></div>
|
|
<v-btn
|
|
v-if="canDelete && isDeleted"
|
|
large
|
|
@click="unDeleteItem"
|
|
color="primary"
|
|
>{{ $ay.t("Undelete")
|
|
}}<v-icon right large>$ayiTrashRestoreAlt</v-icon></v-btn
|
|
>
|
|
<v-col
|
|
v-if="form().showMe(this, 'WorkOrderItemUnit')"
|
|
cols="12"
|
|
sm="6"
|
|
lg="4"
|
|
xl="3"
|
|
>
|
|
<gz-pick-list
|
|
:aya-type="$ay.ayt().Unit"
|
|
:show-edit-icon="true"
|
|
v-model="
|
|
value.items[activeWoItemIndex].units[activeItemIndex].unitId
|
|
"
|
|
:readonly="formState.readOnly || isDeleted"
|
|
:disabled="isDeleted"
|
|
:label="$ay.t('Unit')"
|
|
:ref="
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].unitId`
|
|
"
|
|
data-cy="units.unitId"
|
|
:rules="[
|
|
form().required(
|
|
this,
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].unitId`
|
|
)
|
|
]"
|
|
:error-messages="
|
|
form().serverErrors(
|
|
this,
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].unitId`
|
|
)
|
|
"
|
|
@input="
|
|
fieldValueChanged(
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].unitId`
|
|
)
|
|
"
|
|
@update:name="unitChange"
|
|
></gz-pick-list>
|
|
</v-col>
|
|
|
|
<v-col v-if="form().showMe(this, 'WorkOrderItemUnitNotes')" cols="12">
|
|
<v-textarea
|
|
v-model="
|
|
value.items[activeWoItemIndex].units[activeItemIndex].notes
|
|
"
|
|
:readonly="formState.readOnly"
|
|
:disabled="isDeleted"
|
|
:label="$ay.t('WorkOrderItemUnitNotes')"
|
|
:error-messages="
|
|
form().serverErrors(
|
|
this,
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].notes`
|
|
)
|
|
"
|
|
:ref="`Items[${activeWoItemIndex}].units[${activeItemIndex}].notes`"
|
|
data-cy="unitUnitNotes"
|
|
@input="
|
|
fieldValueChanged(
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].notes`
|
|
)
|
|
"
|
|
auto-grow
|
|
></v-textarea>
|
|
</v-col>
|
|
|
|
<v-col v-if="form().showMe(this, 'WorkOrderItemUnitTags')" cols="12">
|
|
<gz-tag-picker
|
|
v-model="value.items[activeWoItemIndex].units[activeItemIndex].tags"
|
|
:readonly="formState.readOnly"
|
|
data-cy="unitTags"
|
|
:error-messages="
|
|
form().serverErrors(
|
|
this,
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].tags`
|
|
)
|
|
"
|
|
:ref="`Items[${activeWoItemIndex}].units[${activeItemIndex}].tags`"
|
|
@input="
|
|
fieldValueChanged(
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].tags`
|
|
)
|
|
"
|
|
></gz-tag-picker>
|
|
</v-col>
|
|
|
|
<v-col cols="12">
|
|
<gz-custom-fields
|
|
v-model="
|
|
value.items[activeWoItemIndex].units[activeItemIndex].customFields
|
|
"
|
|
:form-key="formCustomTemplateKey"
|
|
:readonly="formState.readOnly"
|
|
:parent-v-m="this"
|
|
key-start-with="WorkOrderItemUnitCustom"
|
|
:ref="
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].customFields`
|
|
"
|
|
data-cy="unitCustomFields"
|
|
:error-messages="
|
|
form().serverErrors(
|
|
this,
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].customFields`
|
|
)
|
|
"
|
|
@input="
|
|
fieldValueChanged(
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].customFields`
|
|
)
|
|
"
|
|
></gz-custom-fields>
|
|
</v-col>
|
|
|
|
<v-col v-if="form().showMe(this, 'WorkOrderItemUnitWiki')" cols="12">
|
|
<gz-wiki
|
|
:aya-type="$ay.ayt().WorkOrderItem"
|
|
:aya-id="value.id"
|
|
:ref="`Items[${activeWoItemIndex}].units[${activeItemIndex}].wiki`"
|
|
v-model="value.items[activeWoItemIndex].units[activeItemIndex].wiki"
|
|
:readonly="formState.readOnly"
|
|
@input="
|
|
fieldValueChanged(
|
|
`Items[${activeWoItemIndex}].units[${activeItemIndex}].wiki`
|
|
)
|
|
"
|
|
></gz-wiki
|
|
></v-col>
|
|
|
|
<v-col
|
|
v-if="form().showMe(this, 'WorkOrderItemUnitAttachments') && value.id"
|
|
cols="12"
|
|
>
|
|
<gz-attachments
|
|
:readonly="formState.readOnly"
|
|
:aya-type="$ay.ayt().WorkOrderItemUnit"
|
|
:aya-id="value.items[activeWoItemIndex].units[activeItemIndex].id"
|
|
></gz-attachments
|
|
></v-col>
|
|
</template>
|
|
</v-row>
|
|
</div>
|
|
</template>
|
|
<script>
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/* XXXeslint-disable */
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
export default {
|
|
created() {
|
|
this.setDefaultView();
|
|
},
|
|
data() {
|
|
return {
|
|
activeItemIndex: null,
|
|
selectedRow: []
|
|
};
|
|
},
|
|
props: {
|
|
value: {
|
|
default: null,
|
|
type: Object
|
|
},
|
|
pvm: {
|
|
default: null,
|
|
type: Object
|
|
},
|
|
activeWoItemIndex: {
|
|
default: null,
|
|
type: Number
|
|
},
|
|
gotoIndex: {
|
|
default: null,
|
|
type: Number
|
|
},
|
|
addNew: {
|
|
default: null,
|
|
type: Number
|
|
}
|
|
},
|
|
watch: {
|
|
activeWoItemIndex(val, oldVal) {
|
|
if (val != oldVal) {
|
|
this.setDefaultView();
|
|
}
|
|
},
|
|
gotoIndex(val, oldVal) {
|
|
if (val != oldVal) {
|
|
let gotoIndex = val;
|
|
if (val < 0) {
|
|
//it's a create request
|
|
gotoIndex = this.newItem();
|
|
}
|
|
this.selectedRow = [{ index: gotoIndex }];
|
|
this.activeItemIndex = gotoIndex;
|
|
this.$nextTick(() => {
|
|
const el = this.$refs.unittopform;
|
|
if (el) {
|
|
el.scrollIntoView({ behavior: "smooth" });
|
|
}
|
|
});
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
unitChange(newName) {
|
|
this.value.items[this.activeWoItemIndex].units[
|
|
this.activeItemIndex
|
|
].unitViz = newName;
|
|
},
|
|
newItem() {
|
|
let newIndex = this.value.items[this.activeWoItemIndex].units.length;
|
|
|
|
this.value.items[this.activeWoItemIndex].units.push({
|
|
id: 0,
|
|
concurrency: 0,
|
|
wiki: null,
|
|
customFields: "{}",
|
|
tags: [],
|
|
userId: null,
|
|
unitId: 0, //zero to break rule on new
|
|
estimatedQuantity: 0,
|
|
startDate: null,
|
|
stopDate: null,
|
|
serviceRateId: null,
|
|
isDirty: true,
|
|
workOrderItemId: this.value.items[this.activeWoItemIndex].id,
|
|
uid: Date.now(),
|
|
unitViz: null
|
|
});
|
|
this.$emit("change");
|
|
this.selectedRow = [{ index: newIndex }];
|
|
this.activeItemIndex = newIndex;
|
|
//trigger rule breaking / validation
|
|
this.$nextTick(() => {
|
|
this.value.items[this.activeWoItemIndex].units[
|
|
this.activeItemIndex
|
|
].unitId = null;
|
|
this.fieldValueChanged(
|
|
`Items[${this.activeWoItemIndex}].units[${this.activeItemIndex}].unitId`
|
|
);
|
|
});
|
|
|
|
return newIndex; //for create new on goto
|
|
},
|
|
unDeleteItem() {
|
|
this.value.items[this.activeWoItemIndex].units[
|
|
this.activeItemIndex
|
|
].deleted = false;
|
|
this.setDefaultView();
|
|
},
|
|
deleteItem() {
|
|
this.value.items[this.activeWoItemIndex].units[
|
|
this.activeItemIndex
|
|
].deleted = true;
|
|
this.setDefaultView();
|
|
this.$emit("change");
|
|
},
|
|
deleteAllItem() {
|
|
this.value.items[this.activeWoItemIndex].units.forEach(
|
|
z => (z.deleted = true)
|
|
);
|
|
this.setDefaultView();
|
|
this.$emit("change");
|
|
},
|
|
setDefaultView: function() {
|
|
//if only one record left then display it otherwise just let the datatable show what the user can click on
|
|
if (this.value.items[this.activeWoItemIndex].units.length == 1) {
|
|
this.selectedRow = [{ index: 0 }];
|
|
this.activeItemIndex = 0;
|
|
} else {
|
|
this.selectedRow = [];
|
|
this.activeItemIndex = null; //select nothing in essence resetting a child selects and this one too clearing form
|
|
}
|
|
},
|
|
handleRowClick: function(item) {
|
|
this.activeItemIndex = item.index;
|
|
this.selectedRow = [{ index: item.index }];
|
|
},
|
|
form() {
|
|
return window.$gz.form;
|
|
},
|
|
fieldValueChanged(ref) {
|
|
if (!this.formState.loading && !this.formState.readonly) {
|
|
//flag this record dirty so it gets picked up by save
|
|
this.value.items[this.activeWoItemIndex].units[
|
|
this.activeItemIndex
|
|
].isDirty = true;
|
|
window.$gz.form.fieldValueChanged(this.pvm, ref);
|
|
|
|
// //set viz if applicable
|
|
// if(ref==""){
|
|
// let selectedPartWarehouse = vm.$refs.partWarehouseId.getFullSelectionValue();
|
|
// }
|
|
}
|
|
},
|
|
itemRowClasses: function(item) {
|
|
let ret = "";
|
|
const isDeleted =
|
|
this.value.items[this.activeWoItemIndex].units[item.index].deleted ===
|
|
true;
|
|
|
|
const hasError = this.form().childRowHasError(
|
|
this,
|
|
`Items[${this.activeWoItemIndex}].Units[${item.index}].`
|
|
);
|
|
|
|
if (isDeleted) {
|
|
ret += this.form().tableRowDeletedClass();
|
|
}
|
|
if (hasError) {
|
|
ret += this.form().tableRowErrorClass();
|
|
}
|
|
return ret;
|
|
}
|
|
},
|
|
computed: {
|
|
isDeleted: function() {
|
|
if (
|
|
this.value.items[this.activeWoItemIndex].units[this.activeItemIndex] ==
|
|
null
|
|
) {
|
|
this.setDefaultView();
|
|
return true;
|
|
}
|
|
return (
|
|
this.value.items[this.activeWoItemIndex].units[this.activeItemIndex]
|
|
.deleted === true
|
|
);
|
|
},
|
|
parentDeleted: function() {
|
|
return this.value.items[this.activeWoItemIndex].deleted === true;
|
|
},
|
|
|
|
headerList: function() {
|
|
/*
|
|
If the column is a text, left-align it
|
|
If the column is a number or number + unit, (or date) right-align it (like excel)
|
|
*/
|
|
let headers = [];
|
|
|
|
if (this.form().showMe(this, "WorkOrderItemUnit")) {
|
|
headers.push({
|
|
text: this.$ay.t("Unit"),
|
|
align: "left",
|
|
value: "unitViz"
|
|
});
|
|
}
|
|
|
|
if (this.form().showMe(this, "WorkOrderItemUnitNotes")) {
|
|
headers.push({
|
|
text: this.$ay.t("WorkOrderItemUnitNotes"),
|
|
align: "left",
|
|
value: "notes"
|
|
});
|
|
}
|
|
|
|
return headers;
|
|
},
|
|
itemList: function() {
|
|
return this.value.items[this.activeWoItemIndex].units.map((x, i) => {
|
|
return {
|
|
index: i,
|
|
id: x.id,
|
|
unitViz: x.unitViz,
|
|
notes: window.$gz.util.truncateString(
|
|
x.notes,
|
|
this.pvm.maxTableNotesLength
|
|
)
|
|
};
|
|
});
|
|
},
|
|
formState: function() {
|
|
return this.pvm.formState;
|
|
},
|
|
formCustomTemplateKey: function() {
|
|
return this.pvm.formCustomTemplateKey;
|
|
},
|
|
hasData: function() {
|
|
return this.value.items[this.activeWoItemIndex].units.length > 0;
|
|
},
|
|
hasSelection: function() {
|
|
return this.activeItemIndex != null;
|
|
},
|
|
canAdd: function() {
|
|
return this.pvm.rights.change && this.pvm.subRights.units.create;
|
|
},
|
|
canDelete: function() {
|
|
return this.activeItemIndex != null && this.canDeleteAll;
|
|
},
|
|
canDeleteAll: function() {
|
|
return this.pvm.rights.change && this.pvm.subRights.units.delete;
|
|
}
|
|
}
|
|
};
|
|
</script>
|