--- a/server/src/remie/templates/remie/iframe_tester.html Mon Jul 20 17:37:14 2015 +0200
+++ b/server/src/remie/templates/remie/iframe_tester.html Mon Jul 20 18:43:52 2015 +0200
@@ -7,22 +7,78 @@
$(document).ready(function(){
$("#iframe_update_button").click(function(){
var default_url = "{% url 'remie_segment' %}";
- var project_id = $("#project_id").val();
+ var project_id = $("#project_id_iframe").val();
var group_mode = $("#group_mode").is(":checked");
var final_url = default_url+"?project_id="+project_id+"&group_mode="+group_mode;
$("#remie_workunit_iframe").attr("src", final_url);
});
+
+ function getCookie(name) {
+ var cookieValue = null;
+ if (document.cookie && document.cookie != '') {
+ var cookies = document.cookie.split(';');
+ for (var i = 0; i < cookies.length; i++) {
+ var cookie = jQuery.trim(cookies[i]);
+ // Does this cookie string begin with the name we want?
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
+ break;
+ }
+ }
+ }
+ return cookieValue;
+ }
+
+ $("#copy_button").click(function(){
+ var project_id = $("#project_id_copy").val();
+ var copy_title = $("#title_copy").val();
+ console.log(project_id)
+ var csrftoken = getCookie('csrftoken');
+
+ function csrfSafeMethod(method) {
+ // these HTTP methods do not require CSRF protection
+ return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
+ }
+ $.ajaxSetup({
+ beforeSend: function(xhr, settings) {
+ if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
+ xhr.setRequestHeader("X-CSRFToken", csrftoken);
+ }
+ $("#success_copy").css("color", "orange");
+ $("#success_copy").html("Copie en cours ... ");
+ }
+ });
+ $.ajax({
+ method: "POST",
+ url: '{% url "api_dispatch_list" resource_name="projects" api_name="1.0" %}?format=json',
+ contentType: 'application/json',
+ data: '{"source": "'+project_id+'", "title": "'+copy_title+'", "publish": "true"}',
+ success: function(_data) {
+ $("#success_copy").css("color", "green");
+ $("#success_copy").html("Copie réussie: l'id de la copie du projet est "+_data.ldt_id);
+ },
+ error: function(_xhr, _error, _thrown) {
+ $("#success_copy").css("color", "red");
+ $("#success_copy").html("Une erreur est survenue: "+_thrown);
+ }
+ });
+ });
});
</script>
</head>
<body>
-<div style="float:left; width:1191px; height:200px;">
-<label>Id projet: </label><br><input id="project_id" type="text"></input><br><br>
-<label>Mode groupe: </label><input id="group_mode" type="checkbox"></input><br><br>
-<input id="iframe_update_button" type="button" value="Générer"></input>
-<input id="copy_button" type="button" value="Copier"></input>
+<div style="float:left; width:500px; height: 200px; margin-left: 10px;">
+ <label>Id projet (génération d'iframe): </label><input id="project_id_iframe" type="text"></input>
+ <br><label>Mode groupe: </label><input id="group_mode" type="checkbox"></input>
+ <br><input id="iframe_update_button" type="button" value="Générer"></input>
+</div>
+<div style="display: inline-block; width: 500px; height: 200px">
+ <label>Id projet (copie via l'API): </label><input id="project_id_copy" type="text"></input>
+ <br><label>Titre de la copie: </label><input id="title_copy" type="text"></input>
+ <br><input id="copy_button" type="button" value="Copier"></input>
+ <div id="success_copy"></div>
</div>
<div style="width:1191px; height:625px; outline: 1px;" id="remie_iframe_container">
<iframe id="remie_workunit_iframe" width="1191" height="625" src=""></iframe>