post = (path, params, method) -> method = method or 'post' # Set method to post by default if not specified. # The rest of this code assumes you are not using a library. # It can be made less wordy if you use one. form = document.createElement('form') form.setAttribute 'method', method form.setAttribute 'action', path for key of params if params.hasOwnProperty(key) hiddenField = document.createElement('input') hiddenField.setAttribute 'type', 'hidden' hiddenField.setAttribute 'name', key hiddenField.setAttribute 'value', params[key] form.appendChild hiddenField authenticity_token = $("#authenticity_token").text().replace(/\s/g, '') authenticityField = document.createElement('input') authenticityField.setAttribute 'type', 'hidden' authenticityField.setAttribute 'name', 'authenticity_token' authenticityField.setAttribute 'value', authenticity_token form.appendChild authenticityField document.body.appendChild form form.submit() $ -> $('#files-to-upload').jstree( plugins: ["checkbox","contextmenu"] core: data: url: window.files_url dataType: 'json' data: (node) -> { id: node.id , li_attr: node.li_attr} error: -> $('.tree').hide() $('.no-files').show() checkbox: three_state: false ) $('.serials_selection').on 'change', -> serial_id = $('.serials_selection option:selected').val() if serial_id url = window.seasons_js_url + "&category_id=#{serial_id}" $.getScript url $('.convert-button').on 'click', (event) -> event.preventDefault() tree = $('#files-to-upload').jstree(true) nodes = $('#files-to-upload').jstree('get_selected') data = $.map(nodes, (n,i) => node = tree.get_node(n) { li_attr: node.li_attr, name: node.text } ) season_id = $('.seasons_selection option:selected').val() postData = { 'nodes': JSON.stringify(data), 'season_id': season_id } post window.upload_url, postData