|
22 | 22 |
|
23 | 23 | <div class="flex flex-wrap items-center gap-2"> |
24 | 24 | <BaseButton |
| 25 | + v-if="!isLearningPathContext" |
25 | 26 | :label="t('Back to survey list')" |
26 | 27 | :route="buildListRoute()" |
27 | 28 | icon="back" |
|
362 | 363 | class="flex flex-col-reverse gap-3 rounded-2xl border border-gray-20 bg-white p-6 shadow-sm md:flex-row md:items-center md:justify-end" |
363 | 364 | > |
364 | 365 | <BaseButton |
| 366 | + v-if="isLearningPathContext" |
| 367 | + :label="t('Cancel')" |
| 368 | + icon="close" |
| 369 | + type="black" |
| 370 | + @click="goToLearningPathAddItem" |
| 371 | + /> |
| 372 | + <BaseButton |
| 373 | + v-else |
365 | 374 | :label="t('Cancel')" |
366 | 375 | :route="buildListRoute()" |
367 | 376 | icon="close" |
@@ -467,14 +476,89 @@ function createEmptyForm() { |
467 | 476 | } |
468 | 477 | } |
469 | 478 |
|
470 | | -function getContextParams() { |
| 479 | +function getContextParams(extra = {}) { |
| 480 | + return cleanQueryParams({ |
| 481 | + cid: getQueryValue(route.query.cid), |
| 482 | + sid: getQueryValue(route.query.sid), |
| 483 | + gid: getQueryValue(route.query.gid), |
| 484 | + origin: getQueryValue(route.query.origin), |
| 485 | + lp_id: getQueryValue(route.query.lp_id), |
| 486 | + lpItemId: getQueryValue(route.query.lpItemId || route.query.lp_item_id), |
| 487 | + type: getQueryValue(route.query.type), |
| 488 | + returnToLp: getQueryValue(route.query.returnToLp), |
| 489 | + isStudentView: getQueryValue(route.query.isStudentView), |
| 490 | + ...extra, |
| 491 | + }) |
| 492 | +} |
| 493 | +
|
| 494 | +function getQueryValue(value) { |
| 495 | + if (Array.isArray(value)) { |
| 496 | + return value[0] || "" |
| 497 | + } |
| 498 | +
|
| 499 | + return value || "" |
| 500 | +} |
| 501 | +
|
| 502 | +function cleanQueryParams(params = {}) { |
| 503 | + const cleanParams = {} |
| 504 | +
|
| 505 | + for (const [key, value] of Object.entries(params)) { |
| 506 | + if (value !== undefined && value !== null && String(value) !== "") { |
| 507 | + cleanParams[key] = value |
| 508 | + } |
| 509 | + } |
| 510 | +
|
| 511 | + return cleanParams |
| 512 | +} |
| 513 | +
|
| 514 | +const learningPathId = computed(() => Number(getQueryValue(route.query.lp_id) || 0)) |
| 515 | +
|
| 516 | +const isLearningPathContext = computed(() => { |
| 517 | + return getQueryValue(route.query.origin) === "learnpath" && learningPathId.value > 0 |
| 518 | +}) |
| 519 | +
|
| 520 | +function buildLearningPathQuery(extra = {}) { |
| 521 | + const query = new URLSearchParams() |
| 522 | +
|
| 523 | + query.set("action", extra.action || "add_item") |
| 524 | + query.set("type", extra.type || "step") |
| 525 | + query.set("lp_id", String(learningPathId.value)) |
| 526 | +
|
| 527 | + for (const key of ["cid", "sid", "gid"]) { |
| 528 | + const value = getQueryValue(route.query[key]) |
| 529 | +
|
| 530 | + if (String(value) !== "") { |
| 531 | + query.set(key, String(value)) |
| 532 | + } |
| 533 | + } |
| 534 | +
|
| 535 | + query.set("isStudentView", "false") |
| 536 | +
|
| 537 | + if (extra.surveyId) { |
| 538 | + query.set("survey_id", String(extra.surveyId)) |
| 539 | + } |
| 540 | +
|
| 541 | + return query.toString() |
| 542 | +} |
| 543 | +
|
| 544 | +function buildLearningPathAddItemUrl() { |
| 545 | + return `/main/lp/lp_controller.php?${buildLearningPathQuery()}` |
| 546 | +} |
| 547 | +
|
| 548 | +function buildLearningPathQuestionsRoute(surveyId) { |
471 | 549 | return { |
472 | | - cid: route.query.cid, |
473 | | - sid: route.query.sid, |
474 | | - gid: route.query.gid, |
| 550 | + name: "SurveyQuestions", |
| 551 | + params: { |
| 552 | + node: route.params.node, |
| 553 | + surveyId, |
| 554 | + }, |
| 555 | + query: getContextParams({ lpItemId: undefined }), |
475 | 556 | } |
476 | 557 | } |
477 | 558 |
|
| 559 | +function goToLearningPathAddItem() { |
| 560 | + window.location.href = buildLearningPathAddItemUrl() |
| 561 | +} |
478 | 562 |
|
479 | 563 | function buildQuestionsRoute() { |
480 | 564 | return { |
@@ -654,6 +738,12 @@ async function submitForm() { |
654 | 738 | csrfToken.value = saved.csrfToken || csrfToken.value |
655 | 739 |
|
656 | 740 | if (!isEditMode.value && saved.surveyId) { |
| 741 | + if (isLearningPathContext.value) { |
| 742 | + await router.push(buildLearningPathQuestionsRoute(saved.surveyId)) |
| 743 | +
|
| 744 | + return |
| 745 | + } |
| 746 | +
|
657 | 747 | await router.push({ |
658 | 748 | name: "SurveyQuestions", |
659 | 749 | params: { |
|
0 commit comments