(task, fieldsToSkip)
| 533 | } |
| 534 | |
| 535 | function restoreTaskToUI(task, fieldsToSkip) { |
| 536 | fieldsToSkip = fieldsToSkip || [] |
| 537 | |
| 538 | if ("numOutputsTotal" in task) { |
| 539 | numOutputsTotalField.value = task.numOutputsTotal |
| 540 | } |
| 541 | if ("seed" in task) { |
| 542 | randomSeedField.checked = false |
| 543 | seedField.value = task.seed |
| 544 | } |
| 545 | if (!("reqBody" in task)) { |
| 546 | return |
| 547 | } |
| 548 | for (const key in TASK_MAPPING) { |
| 549 | if (key in task.reqBody && !fieldsToSkip.includes(key)) { |
| 550 | TASK_MAPPING[key].setUI(task.reqBody[key]) |
| 551 | } |
| 552 | } |
| 553 | |
| 554 | // properly reset fields not present in the task |
| 555 | if (!("use_hypernetwork_model" in task.reqBody)) { |
| 556 | hypernetworkModelField.value = "" |
| 557 | hypernetworkModelField.dispatchEvent(new Event("change")) |
| 558 | } |
| 559 | |
| 560 | if (!("use_lora_model" in task.reqBody)) { |
| 561 | loraModelField.modelNames = [] |
| 562 | loraModelField.modelWeights = [] |
| 563 | } |
| 564 | |
| 565 | // restore the original prompt if provided (e.g. use settings), fallback to prompt as needed (e.g. copy/paste or d&d) |
| 566 | promptField.value = task.reqBody.original_prompt |
| 567 | if (!("original_prompt" in task.reqBody)) { |
| 568 | promptField.value = task.reqBody.prompt |
| 569 | } |
| 570 | promptField.dispatchEvent(new Event("input")) |
| 571 | |
| 572 | // properly reset checkboxes |
| 573 | if (!("use_face_correction" in task.reqBody)) { |
| 574 | useFaceCorrectionField.checked = false |
| 575 | gfpganModelField.disabled = true |
| 576 | } |
| 577 | if (!("use_upscale" in task.reqBody)) { |
| 578 | useUpscalingField.checked = false |
| 579 | } |
| 580 | if (!("mask" in task.reqBody) && maskSetting.checked) { |
| 581 | maskSetting.checked = false |
| 582 | maskSetting.dispatchEvent(new Event("click")) |
| 583 | } |
| 584 | upscaleModelField.disabled = !useUpscalingField.checked |
| 585 | upscaleAmountField.disabled = !useUpscalingField.checked |
| 586 | |
| 587 | // hide/show source picture as needed |
| 588 | if (IMAGE_REGEX.test(initImagePreview.src) && task.reqBody.init_image == undefined) { |
| 589 | // hide source image |
| 590 | initImageClearBtn.dispatchEvent(new Event("click")) |
| 591 | } else if (task.reqBody.init_image !== undefined) { |
| 592 | // listen for inpainter loading event, which happens AFTER the main image loads (which reloads the inpainter) |
no test coverage detected