create-page.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. $(document).ready(function(event) {
  2. $("#asset-store-link").addClass("active");
  3. $(".checkbox").checkbox();
  4. $(".softwareType").checkbox("setting", "onChange", function() {
  5. toggleRepostoryOptionsVisibility(this);
  6. });
  7. });
  8. function toggleRepostoryOptionsVisibility(elem) {
  9. let attrVal = $(elem).attr("value");
  10. let visible = attrVal == "opensource" || attrVal == "sponsored";
  11. if (visible) {
  12. $("#git-repository-data").css("display", "initial");
  13. } else {
  14. $("#git-repository-data").css("display", "none");
  15. }
  16. }
  17. $("#submitAssetButton").click(function() {
  18. let formElement = $("#newAssetForm").get(0);
  19. let formData = new FormData(formElement);
  20. $.ajax({
  21. url: "/api/page/draft/",
  22. method: "POST",
  23. data: formData,
  24. cache: false,
  25. contentType: false,
  26. processData: false,
  27. success: function(data) {
  28. let assetId = data.id;
  29. window.location.href = "/edit/draft/" + assetId;
  30. },
  31. error: function(xhr, status, error) {
  32. let message = "<p>" + xhr.responseJSON.message + "</p>";
  33. message += toast.arrayToHtmlList(xhr.responseJSON.details);
  34. toast.error(null, message, true);
  35. }
  36. });
  37. });
  38. $("#forkedCheckBox").checkbox();
  39. $("#forkedCheckBox").click(function() {
  40. // this is the opposite value because it evaluates before the checkbox has changed.
  41. let checked = !$("#forkedCheckBox").checkbox("is checked");
  42. if (checked) {
  43. // console.log("checked");
  44. $("#parentRepoInput").removeClass("hidden");
  45. } else {
  46. // console.log("unchecked");
  47. $("#parentRepoInput").addClass("hidden");
  48. }
  49. });