user-credential-page.js 962 B

123456789101112131415161718192021222324252627282930313233
  1. this.UserCredentialPage = class UserCredentialPage {
  2. constructor() {
  3. const editor = ace.edit("ace-credential-value");
  4. editor.getSession().setTabSize(2);
  5. editor.getSession().setUseSoftTabs(true);
  6. editor.getSession().setUseWrapMode(false);
  7. const setMode = function () {
  8. const mode = $("#user_credential_mode").val();
  9. if (mode === "java_script") {
  10. return editor.getSession().setMode("ace/mode/javascript");
  11. } else {
  12. return editor.getSession().setMode("ace/mode/text");
  13. }
  14. };
  15. setMode();
  16. $("#user_credential_mode").on("change", setMode);
  17. const $textarea = $("#user_credential_credential_value").hide();
  18. editor.getSession().setValue($textarea.val());
  19. $textarea
  20. .closest("form")
  21. .on("submit", () => $textarea.val(editor.getSession().getValue()));
  22. }
  23. };
  24. $(() =>
  25. Utils.registerPage(UserCredentialPage, {
  26. forPathsMatching: /^user_credentials\/(\d+|new)/,
  27. })
  28. );