class AjaxCatList constructor: -> $('#new-translation-modal').hide() $('#new-experiment-modal').hide() $('#new-translation').on('click',@new_translation) $('#create-new-translation').on('click',@create_new_translation) @show_translations() $(".example").click( (event) => text = $(event.currentTarget).data("text") $('#new-translation-text').val(text) return false ) $("#new-experiment-translation").click( => @new_experiment_translation() ) $("#create-new-experiment").click( => @create_experiment_translation() ) create_experiment_translation: => email = $("#new-experiment-email").val() pair = $("#new-experiment-pair").val() filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/ unless filter.test(email) alert "Write your email, please." return $.ajax "/admin/get_experiment" data: email: email pair: pair success: (data) => data = JSON.parse(data) id = @add_translation(data.sentence, "EXPERIMENT ##{data.task_id}, #{data.email}", data.pair, data.task_id, data.email) window.location = "/translation.html##{id}" error: => alert "Could not find experiment for you." new_experiment_translation: => $("#new-experiment-pair").html("") $.ajax "/api/info" success: (data) => data = JSON.parse(data) for p in data.pairs $("#new-experiment-pair").append("") $('#new-experiment-modal').modal('show') new_translation: => $("#new-translation-pair").html("") $.ajax "/api/info" success: (data) => data = JSON.parse(data) for p in data.pairs $("#new-translation-pair").append("") $('#new-translation-name').val('Name') $('#new-translation-text').val('') $('#new-translation-modal').modal('show') $('#new-translation-text').focus() show_translations: => $("#translation-list").html('') return unless localStorage['ac-data'] ids = JSON.parse(localStorage['ac-data']) for i in ids doc = JSON.parse(localStorage[i]) $("#translation-list").append("