index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. //<%@ page contentType="text/html;charset=UTF-8" %>
  2. jQuery(function($) {
  3. var fields = [
  4. {
  5. type: 'autocomplete',
  6. label: '自动完成',
  7. required: true,
  8. values: [
  9. {label: 'SQL'},
  10. {label: 'C#'},
  11. {label: 'JavaScript'},
  12. {label: 'Java'},
  13. {label: 'Python'},
  14. {label: 'C++'},
  15. {label: 'PHP'},
  16. {label: 'Swift'},
  17. {label: 'Ruby'}
  18. ]
  19. },
  20. {
  21. label: '评分',
  22. attrs: {
  23. type: 'starRating'
  24. },
  25. icon: '🌟'
  26. }
  27. ,
  28. {
  29. label: '部门选择',
  30. attrs: {
  31. type: 'officeSelect'
  32. },
  33. icon: '👨'
  34. }
  35. ,
  36. {
  37. label: '人员选择',
  38. attrs: {
  39. type: 'userSelect'
  40. },
  41. icon: '👨'
  42. } ,
  43. {
  44. label: '省/市/区',
  45. attrs: {
  46. type: 'cityPicker'
  47. },
  48. icon: '👨'
  49. }
  50. ];
  51. var replaceFields = [
  52. {
  53. type: 'textarea',
  54. subtype: 'tinymce',
  55. label: '富文本',
  56. required: true,
  57. }
  58. ];
  59. var templates = {
  60. starRating: function(fieldData) {
  61. var rate = isNaN(parseFloat(fieldData.value))? 0:parseFloat(fieldData.value);
  62. return {
  63. field: '<div id="'+fieldData.name+'" ></div id="'+fieldData.name+'" ><input type="hidden" name="'+fieldData.name+'" value="'+rate+'"/> <div id="'+fieldData.name+'counter'+'" class="counter">'+rate+'</div>',
  64. onRender: function() {
  65. $(document.getElementById(fieldData.name)).rateYo({rating: rate});
  66. $("#"+fieldData.name).rateYo()
  67. .on("rateyo.change", function (e, data) {
  68. var rating = data.rating;
  69. $("#"+fieldData.name+'counter').text(rating);
  70. });
  71. $("#"+fieldData.name).rateYo()
  72. .on("rateyo.set", function (e, data) {
  73. $("input[name='"+fieldData.name+"'").val(data.rating);
  74. });
  75. }
  76. };
  77. },
  78. officeSelect: function(fieldData) {
  79. var office = fieldData.name;
  80. var required = "";
  81. var value = "";
  82. var labelValue = "" ;
  83. if(fieldData.labelValue){
  84. labelValue = fieldData.labelValue;
  85. }
  86. if(fieldData.values){
  87. value = fieldData.value;
  88. }
  89. if(fieldData.required)
  90. required = "required";
  91. return {
  92. field: '<input id="'+office+'Id" name="'+office+'" class="form-control '+required+' " type="hidden" value="'+value+'" aria-required="true">' +
  93. '<div class="input-group" style="width:100%">' +
  94. '<input id="'+office+'Name" readonly="readonly" type="text" value="'+labelValue+'" data-msg-required="" class="form-control '+required+' " style="" aria-required="true">' +
  95. '<span class="input-group-btn"><button type="button" id="'+office+'Button" class="btn btn-primary "><i class="fa fa-search"></i> </button> ' +
  96. '<button type="button" id="'+office+'DelButton" class="close" data-dismiss="alert" style="position: absolute; top: 5px; right: 53px; z-index: 999; display: block;">×</button></span> </div>' +
  97. '<label id="'+office+'Name-error" class="error" for="'+office+'Name" style="display:none"></label>',
  98. onRender: function() {
  99. $("#"+office+"Button, #"+office+"Name").click(function(){
  100. // 是否限制选择,如果限制,设置为disabled
  101. if ($("#"+office+"Button").hasClass("disabled")){
  102. return true;
  103. }
  104. // 正常打开
  105. top.layer.open({
  106. type: 2,
  107. area: ['300px', '420px'],
  108. title:"选择部门",
  109. ajaxData:{selectIds: $("#"+office+"Id").val()},
  110. content: ctx+ "/tag/treeselect?url="+encodeURIComponent("/sys/office/treeData?type=2")+"&module=&checked=&extId=&isAll=&allowSearch=" ,
  111. btn: ['确定', '关闭']
  112. ,yes: function(index, layero){ //或者使用btn1
  113. var tree = layero.find("iframe")[0].contentWindow.tree;//h.find("iframe").contents();
  114. var ids = [], names = [], nodes = [];
  115. if ("" == "true"){
  116. nodes = tree.get_checked(true);
  117. }else{
  118. nodes = tree.get_selected(true);
  119. }
  120. for(var i=0; i<nodes.length; i++) {//
  121. if (nodes[i].original.isParent){
  122. top.layer.msg("不能选择父节点("+nodes[i].text+")请重新选择。", {icon: 0});
  123. return false;
  124. }//
  125. ids.push(nodes[i].id);
  126. names.push(nodes[i].text);//
  127. break; // 如果为非复选框选择,则返回第一个选择
  128. }
  129. $("#"+office+"Id").val(ids.join(",").replace(/u_/ig,""));
  130. $("#"+office+"Name").val(names.join(","));
  131. $("#"+office+"Name").focus();
  132. top.layer.close(index);
  133. },
  134. cancel: function(index){ //或者使用btn2
  135. //按钮【按钮二】的回调
  136. }
  137. });
  138. });
  139. $("#"+office+"DelButton").click(function(){
  140. // 是否限制选择,如果限制,设置为disabled
  141. if ($("#"+office+"Button").hasClass("disabled")){
  142. return true;
  143. }
  144. // 清除
  145. $("#"+office+"Id").val("");
  146. $("#"+office+"Name").val("");
  147. $("#"+office+"Name").focus();
  148. });
  149. }
  150. };
  151. },
  152. userSelect: function(fieldData) {
  153. var user = fieldData.name;
  154. var value = "";
  155. var labelValue = "" ;
  156. if(fieldData.labelValue){
  157. labelValue = fieldData.labelValue;
  158. }
  159. if(fieldData.values){
  160. value = fieldData.value;
  161. }
  162. var required = "";
  163. if(fieldData.required)
  164. required = "required";
  165. return {
  166. field: ' <input id="'+user+'Id" name="'+user+'" class="form-control '+required+' " type="hidden" value="'+value+'" aria-required="true"><div class="input-group" style="width:100%">' +
  167. '<input id="'+user+'Name" readonly="readonly" type="text" value="'+labelValue+'" data-msg-required="" class="form-control '+required+' " style="" aria-required="true">' +
  168. ' <span class="input-group-btn"><button type="button" id="'+user+'Button" class="btn btn-primary "><i class="fa fa-search"></i> </button><button type="button" id="'+user+'DelButton" class="close" data-dismiss="alert" style="position: absolute; top: 5px; right: 53px; z-index: 999; display: block;">×</button></span> </div><label id="'+user+'Name-error" class="error" for="'+user+'Name" style="display:none"></label>',
  169. onRender: function() {
  170. $("#"+user+"Button, #"+user+"Name").click(function(){
  171. // 是否限制选择,如果限制,设置为disabled
  172. if ($("#"+user+"Button").hasClass("disabled")){
  173. return true;
  174. }
  175. // 正常打开
  176. jp.openUserSelectDialog(false,function(ids, names){
  177. $("#"+user+"Id").val(ids.replace(/u_/ig,""));
  178. $("#"+user+"Name").val(names);
  179. $("#"+user+"Name").focus();
  180. })
  181. });
  182. $("#"+user+"DelButton").click(function(){
  183. // 是否限制选择,如果限制,设置为disabled
  184. if ($("#"+user+"Button").hasClass("disabled")){
  185. return true;
  186. }
  187. // 清除
  188. $("#"+user+"Id").val("");
  189. $("#"+user+"Name").val("");
  190. $("#"+user+"Name").focus();
  191. });
  192. }
  193. };
  194. },
  195. cityPicker: function(fieldData) {
  196. var value = "";
  197. if(fieldData.value){
  198. value = fieldData.value;
  199. }
  200. return {
  201. field: '<input name="'+fieldData.name+'" value="'+value+'" id="'+fieldData.name+'" data-toggle="city-picker" >',
  202. onRender: function() {
  203. $("#"+fieldData.name).citypicker();
  204. }
  205. };
  206. }
  207. };
  208. var inputSets = [{
  209. label: 'User Details',
  210. icon: '👨',
  211. name: 'user-details', // optional
  212. showHeader: true, // optional
  213. fields: [{
  214. type: 'text',
  215. label: 'First Name',
  216. className: 'form-control'
  217. }, {
  218. type: 'select',
  219. label: 'Profession',
  220. className: 'form-control',
  221. values: [{
  222. label: 'Street Sweeper',
  223. value: 'option-2',
  224. selected: false
  225. }, {
  226. label: 'Brain Surgeon',
  227. value: 'option-3',
  228. selected: false
  229. }]
  230. }, {
  231. type: 'textarea',
  232. label: 'Short Bio:',
  233. className: 'form-control'
  234. }]
  235. }, {
  236. label: 'User Agreement',
  237. fields: [{
  238. type: 'header',
  239. subtype: 'h3',
  240. label: 'Terms & Conditions',
  241. className: 'header'
  242. }, {
  243. type: 'paragraph',
  244. label: 'Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.',
  245. }, {
  246. type: 'paragraph',
  247. label: 'Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.',
  248. }, {
  249. type: 'checkbox',
  250. label: 'Do you agree to the terms and conditions?',
  251. }]
  252. }];
  253. var typeUserDisabledAttrs = {
  254. autocomplete: ['access']
  255. };
  256. // test disabledAttrs
  257. var disabledAttrs = ['placeholder'];
  258. toggleEdit();
  259. var formData = jp.unescapeHTML('${formData}');
  260. $('.render-wrap').formRender({
  261. formData: formData,
  262. templates: templates
  263. });
  264. var fbOptions = {
  265. i18n: {
  266. locale: 'zh-CN'
  267. },
  268. subtypes: {
  269. text: ['datetime-local']
  270. },
  271. stickyControls: {
  272. enable: true
  273. },
  274. sortableControls: true,
  275. fields: fields,
  276. templates: templates,
  277. inputSets: inputSets,
  278. typeUserDisabledAttrs: typeUserDisabledAttrs,
  279. disableInjectedStyle: false,
  280. disableFields: ['autocomplete'],
  281. replaceFields: replaceFields,
  282. disabledFieldButtons: {
  283. text: ['copy']
  284. }
  285. // controlPosition: 'left'
  286. // disabledAttrs
  287. };
  288. var editing = true;
  289. /**
  290. * Toggles the edit mode for the demo
  291. * @return {Boolean} editMode
  292. */
  293. function toggleEdit() {
  294. document.body.classList.toggle('form-rendered', editing);
  295. return editing = !editing;
  296. }
  297. // jp.ajaxForm("#inputForm",function (data) {
  298. // if(data.success){
  299. // jp.toastr.success(data.msg);
  300. // jp.go('${ctx}/form/dynamic/list?form_id=${form_id}');
  301. // }
  302. //
  303. //
  304. // })
  305. });