Update SelfServeTasks question handling with enhanced filtering and default option
- Made `question` selection mandatory during task creation. - Enhanced dynamic filtering by including `department_id` and `product_id`. - Added a default "Altid" option for question selection. - Improved `showEditObjectFieldForm` by supporting extra `options` parameters for contextual edits.
This commit is contained in:
@@ -143,7 +143,7 @@ const onDrop = async (event, newIndex) => {
|
||||
:object="object"
|
||||
:loadList="loadList"
|
||||
column="question"
|
||||
:edit-function="SessionUser.objects.self_serve_tasks.showEditObjectFieldForm"
|
||||
:edit-function="(id, column, value, onAfterSubmit) => SessionUser.objects.self_serve_tasks.showEditObjectFieldForm(id, column, value, onAfterSubmit, { department: object.department, product: object.product })"
|
||||
:parse-function="(questionId) => questionId ? SessionUser.objects.self_serve_questions.functions.getQuestionText(questionId) : 'Altid'"
|
||||
:permission-check-function="SessionUser.canAccessAdmin"
|
||||
/>
|
||||
|
||||
@@ -633,7 +633,7 @@ export const ObjectsGlobal = {
|
||||
for (let i = 0; i < response.length; i++) {
|
||||
var tmp = response[i];
|
||||
console.log(tmp);
|
||||
html += `<option value="${tmp.id}">${tmp.name ? tmp.name : tmp.id}</option>`;
|
||||
html += `<option value="${tmp.id}" ${(value == tmp.id || (value === null && tmp.id === 0)) ? 'selected' : ''}>${tmp.name ? tmp.name : tmp.id}</option>`;
|
||||
}
|
||||
});
|
||||
html += `</select>
|
||||
|
||||
@@ -61,14 +61,31 @@ export const SelfServeTasks = {
|
||||
type: "select",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: false
|
||||
required: true
|
||||
},
|
||||
options: async (lockedValues = {}) => {
|
||||
const questions = await SessionUser.objects.self_serve_questions.get.all();
|
||||
if (lockedValues && lockedValues.department) {
|
||||
return questions.filter(q => parseInt(q.department) === parseInt(lockedValues.department));
|
||||
let questions = await SessionUser.objects.self_serve_questions.get.all();
|
||||
const departmentId = lockedValues.department || lockedValues.department_id;
|
||||
const productId = lockedValues.product || lockedValues.vehicle_type || lockedValues.product_id;
|
||||
|
||||
if (departmentId) {
|
||||
questions = questions.filter(q => parseInt(q.department) === parseInt(departmentId));
|
||||
}
|
||||
return questions;
|
||||
if (productId) {
|
||||
questions = questions.filter(q => parseInt(q.product) === parseInt(productId));
|
||||
}
|
||||
|
||||
let options = questions.map(q => ({
|
||||
...q,
|
||||
name: q.question
|
||||
}));
|
||||
|
||||
options.unshift({
|
||||
id: 0,
|
||||
name: "Altid"
|
||||
});
|
||||
|
||||
return options;
|
||||
},
|
||||
parse: (id) => {
|
||||
return SessionUser.objects.self_serve_questions.functions.getQuestionText(id);
|
||||
@@ -106,7 +123,7 @@ export const SelfServeTasks = {
|
||||
department: parseInt(department),
|
||||
lane: parseInt(lane),
|
||||
product: parseInt(product),
|
||||
question: question ? parseInt(question) : null,
|
||||
question: (question && parseInt(question) !== 0) ? parseInt(question) : null,
|
||||
task: task,
|
||||
description: description,
|
||||
order_priority: parseInt(order_priority),
|
||||
@@ -143,7 +160,7 @@ export const SelfServeTasks = {
|
||||
SelfServeTasks.meta.endpoint,
|
||||
id,
|
||||
"question",
|
||||
question ? parseInt(question) : null
|
||||
(question && parseInt(question) !== 0) ? parseInt(question) : null
|
||||
)
|
||||
},
|
||||
product: async (id, product) => {
|
||||
@@ -204,13 +221,14 @@ export const SelfServeTasks = {
|
||||
* @param onAfterSubmit
|
||||
* @returns {Promise<SweetAlertResult<Awaited<any>>>}
|
||||
*/
|
||||
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null) => {
|
||||
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null, options = {}) => {
|
||||
return ObjectsGlobal.showEditObjectFieldForm(
|
||||
SelfServeTasks,
|
||||
id,
|
||||
column,
|
||||
value,
|
||||
onAfterSubmit
|
||||
onAfterSubmit,
|
||||
options
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user