collect.js 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /**
  2. *
  3. * DWSurvey 3.0
  4. *
  5. * @desc: 收集问卷设置
  6. * @author: keyuan(@keyuan, keyuan258@gmail.com)
  7. * @github: https://github.com/wkeyuan/DWSurvey
  8. *
  9. * Copyright 2012, 2017 调问问卷(DWSurvey,http://dwsurvey.net)
  10. *
  11. */
  12. $(document).ready(function(){
  13. var ctx=$("input[name='ctx']").val();
  14. //检查问卷状态---如果是设计状态,则提醒先发布,再收集
  15. var surveyState=$("#surveyState").val();
  16. if(surveyState==="0"){
  17. $("body").append("<div id=\"myDialogRoot\"><div class='dialogMessage'>您问卷当前是设计状态,需要先发布才能收集答卷。<br/>是否确认发布问卷!</div></div>");
  18. var myDialog=$( "#myDialogRoot" ).dialog({
  19. width:500,
  20. height:230,
  21. autoOpen: true,
  22. modal:true,
  23. position:["center","center"],
  24. title:"提示",
  25. resizable:false,
  26. draggable:false,
  27. closeOnEscape:false,
  28. show: {effect:"blind",direction:"up",duration: 500},
  29. hide: {effect:"blind",direction:"left",duration: 200},
  30. buttons: {
  31. "OK":{
  32. text: "确认发布",
  33. addClass:'dialogMessageButton',
  34. click: function() {
  35. //执行发布
  36. var surveyId=$("#id").val();
  37. window.location.href=ctx+"/design/my-survey-design!devSurvey.action?surveyId="+surveyId;
  38. }
  39. },
  40. "llll":{
  41. text: "继续设计",
  42. addClass:'dialogMessageButton',
  43. click: function() {
  44. //$( this ).dialog( "close" );
  45. var surveyId=$("#id").val();
  46. window.location.href=ctx+"/design/my-survey-design.action?surveyId="+surveyId;
  47. }
  48. },
  49. "CENCEL":{
  50. text: "退出",
  51. click: function() {
  52. //$( this ).dialog( "close" );
  53. window.location.href=ctx+"/design/my-survey.action";
  54. }
  55. }
  56. },
  57. open:function(event,ui){
  58. $(".ui-dialog-titlebar-close").hide();
  59. },
  60. close:function(event,ui){
  61. $("#myDialogRoot").remove();
  62. }
  63. });
  64. }
  65. //设置收集规则
  66. $(".sur_collectSet").unbind();
  67. $(".sur_collectSet").click(function(){
  68. var url=ctx+"/js/dw/html/collectset.html";
  69. $.ajax({
  70. url:url,
  71. type:"get",
  72. dataType:"html",
  73. success:function(data){
  74. //$("body").append("<div id=\"myDialogRoot\"><div class='dialogMessage'></div></div>");
  75. $("body").append("<div id=\"myDialogRoot\">"+data+"</div>");
  76. $("#myDialogRoot .mailOnlyItem").hide();
  77. url=ctx+"/design/my-survey!attrs.action";
  78. var data="id="+$("#id").val();
  79. $.ajax({
  80. url:url,
  81. data:data,
  82. type:'post',
  83. success:function(msg){
  84. // console.debug(msg);
  85. var survey=eval("("+msg+")");
  86. $("#myDialogRoot input[name='effective'][value='"+survey.surveyDetail.effective+"']").attr("checked",true);
  87. $("#myDialogRoot input[name='effectiveIp'][value='"+survey.surveyDetail.effectiveIp+"']").attr("checked",true);
  88. $("#myDialogRoot input[name='rule'][value='"+survey.surveyDetail.rule+"']").attr("checked",true);
  89. $("#myDialogRoot input[name='ruleCode']").val(survey.surveyDetail.ruleCode);
  90. $("#myDialogRoot input[name='refresh'][value='"+survey.surveyDetail.refresh+"']").attr("checked",true);
  91. $("#myDialogRoot input[name='mailOnly'][value='"+survey.surveyDetail.mailOnly+"']").attr("checked",true);
  92. $("#myDialogRoot input[name='ynEndNum'][value='"+survey.surveyDetail.ynEndNum+"']").attr("checked",true);
  93. $("#myDialogRoot input[name='endNum']").val(survey.surveyDetail.endNum);
  94. $("#myDialogRoot input[name='ynEndTime'][value='"+survey.surveyDetail.ynEndTime+"']").attr("checked",true);
  95. $("#myDialogRoot input[name='endTime']").val(survey.surveyDetail.endTime);
  96. $("#myDialogRoot input[name='showShareSurvey'][value='"+survey.surveyDetail.showShareSurvey+"']").attr("checked",true);
  97. $("#myDialogRoot input[name='showAnswerDa'][value='"+survey.surveyDetail.showAnswerDa+"']").attr("checked",true);
  98. }
  99. });
  100. var myDialog=$( "#myDialogRoot" ).dialog({
  101. width:550,
  102. height:490,
  103. autoOpen: true,
  104. modal:true,
  105. position:["center","center"],
  106. title:"提示",
  107. resizable:false,
  108. draggable:false,
  109. closeOnEscape:false,
  110. show: {effect:"blind",direction:"up",duration: 500},
  111. //hide: {effect:"blind",direction:"left",duration: 200},
  112. buttons: {
  113. "OK":{
  114. text: "保存",
  115. addClass:'dialogMessageButton',
  116. click: function() {
  117. //异步保存结果
  118. saveAttrs();
  119. $( this ).dialog( "close" );
  120. }
  121. },
  122. "CENCEL":{
  123. text: "取消",
  124. click: function() {
  125. $( this ).dialog( "close" );
  126. //window.location.href=ctx+"/design/my-survey.action";
  127. }
  128. }
  129. },
  130. open:function(event,ui){
  131. laydate.render({
  132. elem: '#surveyEndTime' //指定元素
  133. ,type: 'datetime'
  134. });
  135. $(".ui-dialog-titlebar-close").hide();
  136. },
  137. close:function(event,ui){
  138. $("#myDialogRoot").remove();
  139. }
  140. });
  141. }
  142. });
  143. });
  144. function saveAttrs(){
  145. var url=ctx+"/design/my-survey-design!ajaxSave.action";
  146. var surveyId=$("#id").val();
  147. var data="surveyId="+surveyId;
  148. //收集规则
  149. var effective=$("#myDialogRoot input[name='effective']:checked")[0]?"4":"0";
  150. var effectiveIp=$("#myDialogRoot input[name='effectiveIp']:checked")[0]?"1":"0";
  151. var rule=$("#myDialogRoot input[name='rule']:checked")[0]?"3":"0";
  152. var ruleCode=$("#myDialogRoot input[name='ruleCode']").val();
  153. var refresh=$("#myDialogRoot input[name='refresh']:checked")[0]?"1":"0";
  154. var mailOnly=$("#myDialogRoot input[name='mailOnly']:checked")[0]?"1":"0";
  155. var ynEndNum=$("#myDialogRoot input[name='ynEndNum']:checked")[0]?"1":"0";
  156. var ynEndTime=$("#myDialogRoot input[name='ynEndTime']:checked")[0]?"1":"0";
  157. var endTime=$("#myDialogRoot input[name='endTime']").val();
  158. var endNum=$("#myDialogRoot input[name='endNum']").val();
  159. var showShareSurvey=$("#myDialogRoot input[name='showShareSurvey']:checked")[0]?"1":"0";
  160. var showAnswerDa=$("#myDialogRoot input[name='showAnswerDa']:checked")[0]?"1":"0";
  161. data+="&effective="+effective+"&effectiveIp="+effectiveIp+"&rule="+rule+"&refresh="+refresh+"&ruleCode="+ruleCode+"&mailOnly="+mailOnly;
  162. data+="&ynEndNum="+ynEndNum+"&ynEndTime="+ynEndTime+"&endTime="+endTime+"&endNum="+endNum;
  163. data+="&showShareSurvey="+showShareSurvey+"&showAnswerDa="+showAnswerDa;
  164. $.ajax({
  165. url : url,
  166. data : data,
  167. type : "post",
  168. success : function(msg){
  169. //alert(msg);
  170. notify("修改保存成功!",5000);
  171. }
  172. });
  173. return false;
  174. }
  175. //
  176. $(".sur_edit").unbind();
  177. $(".sur_edit").click(function(){
  178. //${ctx }/design/my-survey-design.action?surveyId=${surveyId}
  179. $("body").append("<div id=\"myDialogRoot\"><div class='dialogMessage'>您问卷已经发布,确认要重新编辑使问卷回到设计状态。<br/>是否确认返回设计状态!</div></div>");
  180. var myDialog=$( "#myDialogRoot" ).dialog({
  181. width:500,
  182. height:230,
  183. autoOpen: true,
  184. modal:true,
  185. position:["center","center"],
  186. title:"提示",
  187. resizable:false,
  188. draggable:false,
  189. closeOnEscape:false,
  190. //show: {effect:"blind",direction:"up",duration: 500},
  191. //hide: {effect:"blind",direction:"left",duration: 200},
  192. buttons: {
  193. "OK":{
  194. text: "确认编辑",
  195. addClass:'dialogMessageButton',
  196. click: function() {
  197. //执行发布
  198. var surveyId=$("#id").val();
  199. window.location.href=ctx+"/design/my-survey-design.action?surveyId="+surveyId;
  200. }
  201. },
  202. "CENCEL":{
  203. text: "取消",
  204. click: function() {
  205. $( this ).dialog( "close" );
  206. }
  207. }
  208. },
  209. open:function(event,ui){
  210. $(".ui-dialog-titlebar-close").hide();
  211. },
  212. close:function(event,ui){
  213. $("#myDialogRoot").remove();
  214. }
  215. });
  216. return false;
  217. });
  218. $(".surveyStateBtn").unbind();
  219. $(".surveyStateBtn").click(function(){
  220. //var thVal=$("#surveyState").val();
  221. var thBtn=$(this);
  222. var thText=thBtn.text();
  223. var surveyState="";
  224. if(thText==="开始收集"){
  225. surveyState=1;
  226. }else if(thText==="停止收集"){
  227. //alert("结束意味着");
  228. surveyState=2;
  229. }else if(thText==="重新打开收集"){
  230. surveyState=1;
  231. }
  232. var ctx=$("#ctx").val();
  233. var url=ctx+"/design/my-survey!surveyState.action";
  234. var surveyId=$("#id").val();
  235. var data="id="+surveyId+"&surveyState="+surveyState;
  236. $.ajax({
  237. url:url,
  238. data:data,
  239. type:"post",
  240. success:function(msg){
  241. if(msg==="true"){
  242. if(thText==="开始收集"){
  243. thBtn.text("停止收集");
  244. $(".surveyStateText").text("收集中");
  245. }else if(thText==="停止收集"){
  246. thBtn.text("重新打开收集");
  247. $(".surveyStateText").text("收集完成");
  248. }else if(thText==="重新打开收集"){
  249. thBtn.text("停止收集");
  250. $(".surveyStateText").text("收集中");
  251. }
  252. }
  253. }
  254. });
  255. return false;
  256. });
  257. });
  258. function notify(msg,delayHid) {
  259. //var msg = "保存成功";
  260. //alert(msg);
  261. $(".notification").remove();
  262. if(delayHid==null){
  263. delayHid=5000;
  264. }
  265. $( "<div>" )
  266. .appendTo( document.body )
  267. .text( msg )
  268. .addClass( "notification ui-state-default ui-corner-bottom" )
  269. .position({
  270. my: "center top",
  271. at: "center top",
  272. of: window
  273. })
  274. .show({
  275. effect: "blind"
  276. })
  277. .delay( delayHid )
  278. .hide({
  279. effect: "blind",
  280. duration: "slow"
  281. }, function() {
  282. $( this ).remove();
  283. });
  284. }