preview.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. $(document).ready(function(){
  2. var ctx=$("#ctx").val();
  3. var sid = $.getUrlParam("sid");
  4. var surveyId = $.getUrlParam("surveyId");
  5. var template = $.getUrlParam("template");
  6. $("#sid").val(sid);
  7. $("#id").val(surveyId);
  8. loadSurveyData(function(){
  9. $("#surveyList").attr("href","/#/dw/survey");
  10. $("#designSurvey").attr("href","/static/diaowen/design.html?surveyId="+surveyId);
  11. $("#dwPhone").hide();
  12. $("#dwPad").hide();
  13. var tag = $("#tag").val();
  14. $("#PcSurvey").attr("src","/static/diaowen/answer-p.html?surveyId="+surveyId+"&sid="+sid+"&tag="+tag);
  15. bindEvent();
  16. if(template!=null && template==="1"){
  17. $("#editorPreview").hide();
  18. $("#templatePreview").show();
  19. }
  20. });
  21. });
  22. function bindEvent(){
  23. $(".centerTabbarBtn").click(function(){
  24. var surveyId = $("#id").val();
  25. var sid = $("#sid").val();
  26. var tag = $("#tag").val();
  27. $(".centerTabbarBtn").removeClass("active");
  28. $(this).addClass("active");
  29. var thHref=$(this).attr("href");
  30. if(thHref==="#dwPc"){
  31. }else if(thHref==="#dwPad"){
  32. $("#PadSurvey").attr("src","/static/diaowen/answer-m.html?surveyId="+surveyId+"&sid="+sid+"&tag="+tag);
  33. }else if(thHref==="#dwPhone"){
  34. $("#PhoneSurvey").attr("src","/static/diaowen/answer-m.html?surveyId="+surveyId+"&sid="+sid+"&tag="+tag);
  35. }
  36. $(".dwPreviewBody").hide();
  37. $(thHref).show();
  38. return false;
  39. });
  40. $("#confirgDevSuvey").click(function(){
  41. var ctx = $("#ctx").val();
  42. var surveyId = $("#id").val();
  43. var url = ctx+"/design/survey-design/devSurvey.do";
  44. var data = "surveyId="+surveyId;
  45. $.ajax({
  46. url: url,
  47. data: data,
  48. type: "post",
  49. success: function (httpResult){
  50. if(httpResult.resultCode===200){
  51. window.location.href="/#/dw/survey/c/url/"+surveyId;
  52. }else{
  53. alert(httpResult.resultMsg);
  54. }
  55. },
  56. error: function(xmlHttpRequest, textStatus, errorThrown){
  57. // alert(xmlHttpRequest);
  58. if(xmlHttpRequest.status===401){
  59. window.location.href="/login";
  60. }else if(xmlHttpRequest.status===403){
  61. alert("没有发布权限");
  62. // window.location.href="/#/exception/403";
  63. }
  64. }
  65. });
  66. });
  67. }
  68. function loadSurveyData(callback){
  69. var ctx=$("#ctx").val();
  70. var surveyId = $("#id").val();
  71. var url = ctx+"/survey/info.do";
  72. var data = "id="+surveyId;
  73. $.ajax({
  74. url:url,
  75. data:data,
  76. type:"get",
  77. success:function(httpResult){
  78. if(httpResult.resultCode==401){
  79. window.location.href="/login";
  80. }
  81. //surveyName
  82. if(httpResult.resultCode==200){
  83. $("#surveyName").val(httpResult.data.surveyName);
  84. }
  85. if(callback!=null){
  86. callback();
  87. }
  88. }
  89. });
  90. }