web.ftl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <#include "../function.ftl">
  2. <#include "../variable.ftl">
  3. <#assign classVar=class?uncap_first>
  4. <#assign pkVar=convertUnderLine(pk) >
  5. <#assign baseurl ="/"+app+"/"+module>
  6. <#assign url =baseurl+"/"+classVar>
  7. /**
  8. * ${comment}
  9. *
  10. *
  11. *<pre>
  12. <#if vars.company?exists>
  13. * 开发公司:${vars.company}
  14. </#if>
  15. <#if vars.developer?exists>
  16. * 开发人员:${vars.developer}
  17. </#if>
  18. <#if vars.email?exists>
  19. * 邮箱地址:${vars.email}
  20. </#if>
  21. * 创建时间:${date?string("yyyy-MM-dd HH:mm:ss")}
  22. *</pre>
  23. */
  24. $(function() {
  25. ${classVar} = new ${class}();
  26. ${classVar}.init();
  27. formUrl = ${classVar}.formUrl;
  28. });
  29. (function() {
  30. //定义常量
  31. var _consts = {
  32. GRID : "#${classVar}Grid",// 列表对象
  33. PAGER : "#${classVar}Pager",// 列表分页
  34. FORM : '#${classVar}Form'// 表单form
  35. };
  36. /**
  37. * ${comment} 对象
  38. * @returns {${class}}
  39. */
  40. ${class} = function() {
  41. //定义属性
  42. };
  43. /**
  44. * 方法
  45. */
  46. ${class}.prototype = {
  47. consts: _consts,
  48. /**
  49. * 初始化
  50. */
  51. init : function() {
  52. if (this.hasInit) // 是否已初始化
  53. return false;
  54. this.hasInit = true;
  55. if ($(this.consts.GRID).length > 0)//列表
  56. this._initGridList();
  57. if ($(this.consts.FORM).length > 0)//表单
  58. this._initForm();
  59. },
  60. /**
  61. * 初始列表
  62. */
  63. _initGridList : function() {
  64. var me = this;
  65. $(this.consts.GRID).GridList(
  66. {
  67. url : __ctx+'${url}/listJson.htm',
  68. pager :this.consts.PAGER,
  69. colNames: [<#list colList as col>'${col.getComment()}',</#list>'管理'],
  70. colModel: [<#list colList as col><#assign colName=convertUnderLine(col.columnName)>{
  71. name:'${colName}',
  72. index: '${col.columnName}'<#if (col.colType=="java.util.Date") || (col.isPK) >,</#if>
  73. <#if (col.colType=="java.util.Date")|| (col.isPK)><#if (col.colType=="java.util.Date")>formatter: 'timestamp'
  74. <#elseif (col.isPK) >hidden:true,
  75. key:true</#if>
  76. </#if>
  77. }, </#list> {
  78. name : '__manage',
  79. width : 30,
  80. sortable:false,
  81. classes:'rowOps',
  82. formatter : 'manage',
  83. formatoptions :[{
  84. label:'编辑',
  85. classes:'btn btn-primary fa fa-edit',
  86. action:__ctx+'${url}/edit.htm?id={id}'
  87. },{
  88. label:'删除',
  89. classes:'btn btn-primary fa fa-remove',
  90. action:__ctx+'${url}/remove.htm?id={id}'
  91. },{
  92. label:'明细',
  93. classes:'btn btn-primary fa fa-detail',
  94. action: __ctx+'${url}/get.htm?id={id}'
  95. }]
  96. } ]
  97. });
  98. },
  99. /**
  100. * 初始化表单
  101. */
  102. _initForm : function() {
  103. var me = this, form = $(this.consts.FORM), frm = form.form();
  104. me.formUrl = new com.lc.form.FormData(form);
  105. // 触发表单验证
  106. frm.valid();
  107. <#if hasSub?exists && hasSub==true>
  108. me.formUrl.initSub('${baseurl}');
  109. </#if>
  110. // 处理表单保存
  111. $(document).on('click', 'a.fa-save', function() {
  112. formUrl.submit(me._showResponse);
  113. });
  114. },
  115. /**
  116. * 表单成功返回信息
  117. *
  118. * @param responseText
  119. */
  120. _showResponse : function(responseText) {
  121. var msg = new com.lc.form.ResultMessage(responseText);
  122. if (msg.isSuccess()) {
  123. DialogUtil.confirmAction(msg.getMessage() + ',是否继续操作',
  124. function(rtn) {
  125. if(rtn)
  126. window.location.reload(true);
  127. else
  128. window.location.href = __ctx+'${url}/list.htm';
  129. });
  130. } else {
  131. DialogUtil.error(msg.getMessage());
  132. }
  133. }
  134. };
  135. })();