'; html += '\n\t\t'; html += '\n\t\tTourCMS - enquiry form'; html += '\n\t\t'; html += '\n\t\t'; html += '\n'; html += '\n'; html += '\n\t'+document.getElementById("code").value; html += '\n'; html += '\n'; element.setAttribute('href', 'data:text/html;charset=utf-8,' + encodeURIComponent(html)); element.setAttribute('download', 'tourcms-enquiry-form.html'); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); }else{ if($("#sortable li").length == 0) { $(".error").html("Please add at least one field using the Add a field button above."); $(".error").fadeIn(); return; }else{ $(".error").html("Please generate the code to be able download it."); $(".error").fadeIn(); return; } } }); /*$("legend").each( function( intIndex ){ var temp = $(this).text(); $(this).html("" + temp + ""); } );*/ $("#dragTip").hide(); $("#code").fadeOut(); $(".notice").fadeOut(); $(".error").fadeOut(); $( "#sortable" ).sortable(); $( "#sortable" ).disableSelection(); $( "#css" ).change( function() { if($(this).is(':checked')) $( "#layout" ).removeAttr("disabled"); else $( "#layout" ).attr("disabled", "disabled"); }); // Lightbox $("a[rel*='lightbox']").colorbox(); $("a[class*='iframe']").click(function(event) { var idDiv = $(this).attr( "id" ); console.log("idDiv: "+ idDiv); var url; url = idDiv == "add" ? "add_edit_element.php" : "select_example_form.php"; $.colorbox.settings.data = null; event.preventDefault(); $.colorbox({ iframe:true, maxHeight:"90%", innerHeight:"600px", innerWidth:"960px", onOpen:function() { $(document.body).css('overflow','hidden'); }, onClosed:function() { $(document.body).css('overflow',''); }, href:url }); }); // Add an event listener onto the "Get the code for this form" button $("#generate").click(function(event) { event.preventDefault(); // Check for errors // Check at least one field has been added if($("#sortable li").length == 0){ $(".error").html("Please add at least one field using the Add a field button above."); $(".error").fadeIn(); return; } // Check for warnings var warnings = []; if($("#tourcms_account_id").val()=="") warnings.push("TourCMS Account ID"); /*if($("#tourcms_channel_id").val()=="") warnings.push("TourCMS Channel ID");*/ if($("#tourcms_enquiry_key").val()=="") warnings.push("Enquiry Key"); if($("#enquiry_type").val()=="") warnings.push("Enquiry Type"); if($("#tourcms_return_url").val()=="") warnings.push("Return URL"); /*if($("#tourcms_problem_url").val()=="") warnings.push("Problem URL");*/ // Output warnings if(warnings.length > 0) { var warningStr = ""; if(warnings.length == 4) { warningStr += "" + warnings[0] + ", " + warnings[1] + ", " + warnings[2] + " or " + warnings[3] + ""; } else if(warnings.length == 3) { warningStr += "" + warnings[0] + ", " + warnings[1] + " or " + warnings[2] + ""; } else if(warnings.length == 2) { warningStr += "" + warnings[0] + " or " + warnings[1] + ""; } else { warningStr += "" + warnings[0] + ""; } if(warnings.length > 1) $(".notice").html("You have not entered your " + warningStr + ". You will need to add them to the code before the form will work, alternatively just enter them in the correct boxes above and click the button again"); else $(".notice").html("You have not entered your " + warningStr + ". You will need to add that to the code before the form will work, alternatively just enter it in the correct box above and click the button again"); $(".notice").fadeIn(); } else { $(".notice").fadeOut(); } // Start generating HTML $("#generating").html("Generating code..."); // Boilerplate var titleForm = $("#form_title").val() ? $("#form_title").val(): ""; var code = '\n\n
'; code += '\n\t

' + titleForm + '

'; code += '\n\t
'; code += '\n\n\t\t'; code += '\n\t\t'; code += '\n\t\t'; code += '\n\t\t'; code += '\n\t\t'; code += '\n\t\t'; code += '\n\n\t\t'; code += '\n\t\t