autoForm-widget.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. String.prototype.trim=function(){
  2. return this.replace(/(^\s*)|(\s*$)/g, "");
  3. }
  4. /*
  5. * 获取插入的HTML
  6. * */
  7. function getHtml(treeNode){
  8. var widgetType = treeNode.widgetType;
  9. if(widgetType == null || widgetType == '' || widgetType == undefined){
  10. widgetType = 'text';
  11. }
  12. var widgetWidth = treeNode.widgetWidth;
  13. if(widgetWidth == null || widgetWidth == '' || widgetWidth == undefined){
  14. widgetWidth = '150';
  15. }
  16. var parentNode = treeNode.getParentNode().name;
  17. var startName = parentNode.substr(parentNode.indexOf("(")+1);
  18. var dbName = startName.substr(0,startName.indexOf(")"));
  19. widgetType = widgetType.trim();
  20. var dataType = treeNode.validateRule;
  21. if(widgetType == 'text'){
  22. return getTextWidgetHtml(dbName,treeNode.name,widgetWidth,dataType);
  23. }else if(widgetType == 'textarea'){
  24. return getTextAreaHtml(dbName,treeNode.name,widgetWidth,dataType);
  25. }else if(widgetType == 'select'){
  26. return getSelectHtml(dbName,treeNode.name,treeNode.dictType,widgetWidth,dataType);
  27. }else if(widgetType == 'radios'){
  28. return getRadioHtml(dbName,treeNode.name,treeNode.dictType,widgetWidth,dataType);
  29. }else if(widgetType == 'checkboxs'){
  30. return getCheckboxHtml(dbName,treeNode.name,treeNode.dictType,widgetWidth,dataType);
  31. }else if(widgetType == 'button'){
  32. return getButtonHtml(treeNode.name);
  33. }else if(widgetType == 'dateText'){
  34. return getDateTextHtml(dbName,treeNode.name,widgetWidth,dataType);
  35. }else if(widgetType == 'timeText'){
  36. return getTimeTextHtml(dbName,treeNode.name,widgetWidth,dataType);
  37. }
  38. }
  39. /**
  40. * 获取精确到秒的文本输入控件
  41. * @param dbName
  42. * @param fieldName
  43. * @param widgetWidth
  44. * @param dataType
  45. * @returns
  46. */
  47. function getTimeTextHtml(dbName,fieldName,widgetWidth,dataType){
  48. var html = '<input type="text" style="text-align:left;width:'+widgetWidth+'px;" ';
  49. html += ' name= "' + dbName + "." + fieldName + '" ';
  50. html += ' autofield="' + dbName + "." + fieldName + '" ';
  51. html += ' title="'+fieldName+'" ';
  52. html += ' orgheight="" orgalign="left" orgfontsize="" orghide="0" ';
  53. html += appendDataType(dataType);
  54. html += ' leipiplugins="text" orgtype="fullDate" orgwidth="'+widgetWidth+'"/>';
  55. return html;
  56. }
  57. /**
  58. * 获取精确到天的文本输入控件
  59. * @param dbName
  60. * @param fieldName
  61. * @param widgetWidth
  62. * @param dataType
  63. * @returns
  64. */
  65. function getDateTextHtml(dbName,fieldName,widgetWidth,dataType){
  66. var html = '<input type="text" style="text-align:left;width:'+widgetWidth+'px;" ';
  67. html += ' name= "' + dbName + "." + fieldName + '" ';
  68. html += ' autofield="' + dbName + "." + fieldName + '" ';
  69. html += ' title="'+fieldName+'" ';
  70. html += ' orgheight="" orgalign="left" orgfontsize="" orghide="0" ';
  71. html += appendDataType(dataType);
  72. html += ' leipiplugins="text" orgtype="standardDate" orgwidth="'+widgetWidth+'"/>';
  73. return html;
  74. }
  75. /**
  76. * 获取按钮控件对应的html
  77. * @param fieldName
  78. * @returns {String}
  79. */
  80. function getButtonHtml(fieldName){
  81. var html = '<span leipiplugins="button"><input name="'+fieldName+'" type="button" leipiplugins="button" style="background-color: #009688;border: medium none;border-radius: 2px;color: #fff;cursor: pointer;display: inline-block;font-size: 14px;height: 38px;line-height: 38px;opacity: 0.9;padding: 0 18px;text-align: center;white-space: nowrap; " value="'+fieldName+'"/></span>';
  82. return html;
  83. }
  84. /**
  85. * 获取多选输入框对应的HTML
  86. * @param dbName
  87. * @param fieldName
  88. * @param dictType
  89. * @param widgetWidth
  90. * @param dataType
  91. */
  92. function getCheckboxHtml(dbName,fieldName,dictType,widgetWidth,dataType){
  93. var name = dbName + "." + fieldName;
  94. var html = '<span leipiplugins="checkboxs" autofield="'+name+'" dictionary="" title="'+fieldName+'" ';
  95. html += appendDataType(dataType);
  96. if(dictType != null && dictType != '' && dictType != undefined){
  97. getDictResult(dictType, function(res){
  98. if(res.success){
  99. var result = res.obj;
  100. var typeList = result.list;
  101. html += appendTypeGroupId(result.groupId);
  102. if(typeList != null && typeList.length > 0){
  103. for(var i = 0; i < typeList.length; i++){
  104. var type = typeList[i];
  105. html +='<input name="leipiNewField" checkedtext="'+type.typename+'" value="'+type.typecode+'" type="checkbox"/>'+type.typename+'&nbsp;';
  106. }
  107. }else{
  108. html+=' selector="" >';
  109. html += '<input name="leipiNewField" checkedtext="" value="" type="checkbox"/>未设置相关的选项值&nbsp;';
  110. }
  111. }else{
  112. html+=' selector="" >';
  113. html += '<input name="leipiNewField" checkedtext="" value="" type="checkbox"/>未设置相关的选项值&nbsp;';
  114. }
  115. });
  116. }else{
  117. html += ' selector="" >'
  118. html += '<input name="leipiNewField" checkedtext="" value="" type="checkbox"/>未设置相关的选项值&nbsp;';
  119. }
  120. html += '</span>';
  121. return html;
  122. }
  123. /**
  124. * 获取单选框对应的HTML
  125. * @param dbName
  126. * @param fieldName
  127. * @param dictType
  128. * @param widgetWidth
  129. * @param dataType
  130. */
  131. function getRadioHtml(dbName,fieldName,dictType,widgetWidth,dataType){
  132. var name = dbName + "." + fieldName;
  133. var html = '<span leipiplugins="radios" autofield="'+name+'" dictionary="" name="leipiNewField" title="'+fieldName+'" ';
  134. html += appendDataType(dataType);
  135. if(dictType != null && dictType != '' && dictType != undefined){
  136. getDictResult(dictType, function(res){
  137. if(res.success){
  138. var result = res.obj;
  139. var typeList = result.list;
  140. html += appendTypeGroupId(result.groupId);
  141. if(typeList != null && typeList.length > 0){
  142. for(var i = 0; i < typeList.length; i++){
  143. var type = typeList[i];
  144. html +='<input name="leipiNewField" checkedtext="'+type.typename+'" value="'+type.typecode+'" type="radio"/>'+type.typename+'&nbsp;';
  145. }
  146. }else{
  147. html+=' selector="" >';
  148. html += '<input name="leipiNewField" checkedtext="" value="" type="radio"/>未设置相关的选项值&nbsp;';
  149. }
  150. }else{
  151. html+=' selector="" >';
  152. html += '<input name="leipiNewField" checkedtext="" value="" type="radio"/>未设置相关的选项值&nbsp;';
  153. }
  154. });
  155. }else{
  156. html+=' selector="" >';
  157. html += '<input name="leipiNewField" checkedtext="" value="" type="radio"/>未设置相关的选项值&nbsp;';
  158. }
  159. html += '</span>';
  160. return html;
  161. }
  162. /**
  163. * 获取下拉选择框对应的HTML
  164. * @param dbName 数据库名称
  165. * @param fieldName 字段名称
  166. * @param dictType 字典类型
  167. * @param widgetWidth 控件宽度
  168. * @param dataType 验证规则
  169. */
  170. function getSelectHtml(dbName,fieldName,dictType,widgetWidth,dataType){
  171. var name = dbName + "." + fieldName;
  172. var html = '<span leipiplugins="select"><select name="leipiNewField" title="'+fieldName+'" leipiplugins="select" size="1" ';
  173. html += appendDataType(dataType);
  174. if(dictType != null && dictType != '' && dictType != undefined){
  175. getDictResult(dictType,function(res){
  176. if(res.success){
  177. var result = res.obj;
  178. var typeList = result.list;
  179. var typeGroupId = result.groupId;
  180. if(typeGroupId != null && typeGroupId != '' && typeGroupId != undefined){
  181. html += ' selector="'+typeGroupId+'" orgwidth="'+widgetWidth+'" autofield="'+name+'" style="width: '+widgetWidth+'px;">';
  182. }
  183. if(typeList != null && typeList.length > 0){
  184. for(var i = 0; i < typeList.length; i++){
  185. var type = typeList[i];
  186. html +='<option value="'+type.typecode+'">'+type.typename+'</option>';
  187. }
  188. }else{
  189. html += ' selector="" orgwidth="'+widgetWidth+'" autofield="'+name+'" style="width: '+widgetWidth+'px;">';
  190. html +='<option value="">---请选择----</option>';
  191. }
  192. }else{
  193. html += ' selector="" orgwidth="'+widgetWidth+'" autofield="'+name+'" style="width: '+widgetWidth+'px;">';
  194. html +='<option value="">---请选择----</option>';
  195. }
  196. });
  197. }else{
  198. html += ' selector="" orgwidth="'+widgetWidth+'" autofield="'+name+'" style="width: '+widgetWidth+'px;">';
  199. html +='<option value="">---请选择----</option>';
  200. }
  201. html += '</select>&nbsp;&nbsp;</span>';
  202. return html;
  203. }
  204. /*
  205. 获取多行文本输入框HTML
  206. */
  207. function getTextAreaHtml(dbName,fieldName,widgetWidth,dataType){
  208. var name = dbName + "." + fieldName;
  209. var html = ' <textarea title="'+fieldName+'" name="'+name+'" leipiplugins="textarea" '
  210. +'value="" autofield="'+name+'" orgrich="1" orgfontsize="" orgwidth="'+widgetWidth+'" orgheight="80" ';
  211. html += appendDataType(dataType);
  212. html +='style="width: '+widgetWidth+'px; height: 80px; margin: 0px;"></textarea>';
  213. return html;
  214. }
  215. /*
  216. 获取单行文本输入框的HTML
  217. */
  218. function getTextWidgetHtml(dbName,fieldName,widgetWidth,dataType){
  219. var html = '<input type="text" style="text-align:left;width:'+widgetWidth+'px;" ';
  220. html += ' name= "' + dbName + "." + fieldName + '" ';
  221. html += ' autofield="' + dbName + "." + fieldName + '" ';
  222. html += ' title="'+fieldName+'" ';
  223. html += ' orgheight="" orgalign="left" orgtype="text" orgfontsize="" orghide="0" ';
  224. html += appendDataType(dataType);
  225. html += ' leipiplugins="text" orgwidth="'+widgetWidth+'"/>';
  226. return html;
  227. }
  228. /**
  229. * 拼接typeGroupId
  230. * @param typeGroupId
  231. * @returns {String}
  232. */
  233. function appendTypeGroupId(typeGroupId){
  234. var html = '';
  235. if(typeGroupId != null && typeGroupId != '' && typeGroupId != undefined){
  236. html+=' selector="'+typeGroupId+'" >';
  237. }else{
  238. html += 'selector="" >';
  239. }
  240. return html;
  241. }
  242. function appendDataType(dataType){
  243. var html = '';
  244. if(dataType != '' && dataType != null && dataType != undefined){
  245. html += ' datatype="'+dataType+'" ';
  246. }else{
  247. html += ' datatype="" ';
  248. }
  249. html += ' ignore="ignore" ';
  250. return html;
  251. }
  252. function getDictResult(dictType,resultFun){
  253. $.ajax({
  254. url:'autoFormController.do?getDictTypeList',
  255. type:'POST',
  256. dataType:'JSON',
  257. async:false,
  258. data:{
  259. dictType:dictType
  260. },
  261. success:function(res){
  262. if(typeof resultFun == 'function'){
  263. resultFun(res);
  264. }
  265. }
  266. });
  267. }