preview.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/#/dw/survey");
  10. $("#designSurvey").attr("href","/dw/static/diaowen/design.html?surveyId="+surveyId);
  11. $("#dwPhone").hide();
  12. $("#dwPad").hide();
  13. var tag = $("#tag").val();
  14. $("#PcSurvey").attr("src","/dw/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","/dw/static/diaowen/answer-m.html?surveyId="+surveyId+"&sid="+sid+"&tag="+tag);
  33. }else if(thHref==="#dwPhone"){
  34. $("#PhoneSurvey").attr("src","/dw/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/#/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="/dw/#/login";
  60. window.location.href="/dw/#/401";
  61. }else if(xmlHttpRequest.status===403){
  62. alert("没有发布权限");
  63. // window.location.href="/dw/#/exception/403";
  64. }
  65. }
  66. });
  67. });
  68. }
  69. function loadSurveyData(callback){
  70. var ctx=$("#ctx").val();
  71. var surveyId = $("#id").val();
  72. var url = ctx+"/survey/info.do";
  73. var data = "id="+surveyId;
  74. $.ajax({
  75. url:url,
  76. data:data,
  77. type:"get",
  78. success:function(httpResult){
  79. if(httpResult.resultCode==401){
  80. // window.location.href="/dw/#/login";
  81. window.location.href="/dw/#/401";
  82. }
  83. //surveyName
  84. if(httpResult.resultCode==200){
  85. $("#surveyName").val(httpResult.data.surveyName);
  86. }
  87. if(callback!=null){
  88. callback();
  89. }
  90. }
  91. });
  92. }