|
1 | | -import "./main"; |
2 | | -import $ from "jquery"; |
3 | | -import "./compat/json"; |
| 1 | +import { htmlEntities } from "@ctfdio/ctfd-js/utils/html"; |
4 | 2 | import "bootstrap/js/dist/tab"; |
| 3 | +import $ from "jquery"; |
| 4 | +import Vue from "vue"; |
5 | 5 | import CTFd from "./compat/CTFd"; |
6 | | -import { htmlEntities } from "@ctfdio/ctfd-js/utils/html"; |
7 | | -import { ezQuery, ezAlert, ezToast } from "./compat/ezq"; |
| 6 | +import { ezAlert, ezQuery, ezToast } from "./compat/ezq"; |
8 | 7 | import { default as helpers } from "./compat/helpers"; |
9 | | -import { bindMarkdownEditors } from "./styles"; |
10 | | -import Vue from "vue"; |
| 8 | +import "./compat/json"; |
11 | 9 | import CommentBox from "./components/comments/CommentBox.vue"; |
12 | | -import FlagList from "./components/flags/FlagList.vue"; |
13 | | -import Requirements from "./components/requirements/Requirements.vue"; |
14 | | -import TopicsList from "./components/topics/TopicsList.vue"; |
15 | | -import TagsList from "./components/tags/TagsList.vue"; |
16 | 10 | import ChallengeFilesList from "./components/files/ChallengeFilesList.vue"; |
| 11 | +import FlagList from "./components/flags/FlagList.vue"; |
17 | 12 | import HintsList from "./components/hints/HintsList.vue"; |
18 | 13 | import NextChallenge from "./components/next/NextChallenge.vue"; |
| 14 | +import Requirements from "./components/requirements/Requirements.vue"; |
| 15 | +import TagsList from "./components/tags/TagsList.vue"; |
| 16 | +import TopicsList from "./components/topics/TopicsList.vue"; |
| 17 | +import "./main"; |
| 18 | +import { bindMarkdownEditors } from "./styles"; |
19 | 19 |
|
20 | 20 | function loadChalTemplate(challenge) { |
21 | 21 | CTFd._internal.challenge = {}; |
@@ -251,6 +251,94 @@ $(() => { |
251 | 251 | }); |
252 | 252 |
|
253 | 253 | $("#challenge-create-options form").submit(handleChallengeOptions); |
| 254 | + |
| 255 | + $(".chal-function") |
| 256 | + .change(function () { |
| 257 | + const selectedFunction = $(this).val(); |
| 258 | + const initialFormGroup = $(".chal-initial").closest(".form-group"); |
| 259 | + const decayFormGroup = $(".chal-decay").closest(".form-group"); |
| 260 | + const minimumFormGroup = $(".chal-minimum").closest(".form-group"); |
| 261 | + const initialInput = $(".chal-initial"); |
| 262 | + const decayInput = $(".chal-decay"); |
| 263 | + const minimumInput = $(".chal-minimum"); |
| 264 | + const valueInput = $(".chal-value"); |
| 265 | + |
| 266 | + if (selectedFunction === "static") { |
| 267 | + // Save current values to data attributes before clearing them |
| 268 | + if (initialInput.val()) { |
| 269 | + initialInput.data("saved-value", initialInput.val()); |
| 270 | + } |
| 271 | + if (decayInput.val()) { |
| 272 | + decayInput.data("saved-value", decayInput.val()); |
| 273 | + } |
| 274 | + if (minimumInput.val()) { |
| 275 | + minimumInput.data("saved-value", minimumInput.val()); |
| 276 | + } |
| 277 | + |
| 278 | + // Clear the input values to prevent validation errors on hidden fields |
| 279 | + initialInput.val(""); |
| 280 | + decayInput.val(""); |
| 281 | + minimumInput.val(""); |
| 282 | + |
| 283 | + // Hide initial, decay, and minimum form groups for static function |
| 284 | + initialFormGroup.hide(); |
| 285 | + decayFormGroup.hide(); |
| 286 | + minimumFormGroup.hide(); |
| 287 | + |
| 288 | + // Remove name attributes so they won't be included in serializeJSON |
| 289 | + initialInput.removeAttr("name").data("original-name", "initial"); |
| 290 | + decayInput.removeAttr("name").data("original-name", "decay"); |
| 291 | + minimumInput.removeAttr("name").data("original-name", "minimum"); |
| 292 | + |
| 293 | + // Remove required attribute for static function |
| 294 | + initialInput.removeAttr("required"); |
| 295 | + decayInput.removeAttr("required"); |
| 296 | + minimumInput.removeAttr("required"); |
| 297 | + |
| 298 | + // Make value input enabled and required for static function |
| 299 | + valueInput.prop("disabled", false).prop("required", true); |
| 300 | + } else if ( |
| 301 | + selectedFunction === "linear" || |
| 302 | + selectedFunction === "logarithmic" |
| 303 | + ) { |
| 304 | + // Show initial, decay, and minimum form groups for linear and logarithmic functions |
| 305 | + initialFormGroup.show(); |
| 306 | + decayFormGroup.show(); |
| 307 | + minimumFormGroup.show(); |
| 308 | + |
| 309 | + // Restore name attributes so they will be included in serializeJSON |
| 310 | + initialInput.attr( |
| 311 | + "name", |
| 312 | + initialInput.data("original-name") || "initial", |
| 313 | + ); |
| 314 | + decayInput.attr("name", decayInput.data("original-name") || "decay"); |
| 315 | + minimumInput.attr( |
| 316 | + "name", |
| 317 | + minimumInput.data("original-name") || "minimum", |
| 318 | + ); |
| 319 | + |
| 320 | + // Restore saved values from data attributes |
| 321 | + if (initialInput.data("saved-value")) { |
| 322 | + initialInput.val(initialInput.data("saved-value")); |
| 323 | + } |
| 324 | + if (decayInput.data("saved-value")) { |
| 325 | + decayInput.val(decayInput.data("saved-value")); |
| 326 | + } |
| 327 | + if (minimumInput.data("saved-value")) { |
| 328 | + minimumInput.val(minimumInput.data("saved-value")); |
| 329 | + } |
| 330 | + |
| 331 | + // Add required attribute for dynamic functions |
| 332 | + initialInput.prop("required", true); |
| 333 | + decayInput.prop("required", true); |
| 334 | + minimumInput.prop("required", true); |
| 335 | + |
| 336 | + // Make value input disabled and not required for dynamic functions |
| 337 | + valueInput.prop("disabled", true).prop("required", false); |
| 338 | + } |
| 339 | + }) |
| 340 | + .trigger("change"); // Trigger change event on page load to set initial state |
| 341 | + |
254 | 342 |
|
255 | 343 | // Load FlagList component |
256 | 344 | if (document.querySelector("#challenge-flags")) { |
|
0 commit comments