user_credentials.js.coffee 843 B

1234567891011121314151617181920212223242526272829
  1. #= require ace/ace
  2. #= require ace/mode-javascript.js
  3. #= require ace/mode-markdown.js
  4. #= require_self
  5. # This is not included in the core application.js bundle.
  6. $ ->
  7. editor = ace.edit("ace-credential-value")
  8. editor.getSession().setTabSize(2)
  9. editor.getSession().setUseSoftTabs(true)
  10. editor.getSession().setUseWrapMode(false)
  11. editor.setTheme("ace/theme/chrome")
  12. setMode = ->
  13. mode = $("#user_credential_mode").val()
  14. if mode == 'java_script'
  15. editor.getSession().setMode("ace/mode/javascript")
  16. else
  17. editor.getSession().setMode("ace/mode/text")
  18. setMode()
  19. $("#user_credential_mode").on 'change', setMode
  20. $textarea = $('#user_credential_credential_value').hide()
  21. editor.getSession().setValue($textarea.val())
  22. $textarea.closest('form').on 'submit', ->
  23. $textarea.val(editor.getSession().getValue())