diyform.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. //设置弹窗宽高
  3. Fast.config.openArea = ['80%', '80%'];
  4. var Controller = {
  5. index: function () {
  6. // 初始化表格参数配置
  7. Table.api.init({
  8. extend: {
  9. index_url: 'cms/diyform/index',
  10. add_url: 'cms/diyform/add',
  11. edit_url: 'cms/diyform/edit',
  12. del_url: 'cms/diyform/del',
  13. multi_url: 'cms/diyform/multi',
  14. table: 'cms_model',
  15. }
  16. });
  17. var table = $("#table");
  18. // 初始化表格
  19. table.bootstrapTable({
  20. url: $.fn.bootstrapTable.defaults.extend.index_url,
  21. pk: 'id',
  22. sortName: 'id',
  23. columns: [
  24. [
  25. {checkbox: true},
  26. {field: 'id', title: __('Id')},
  27. {field: 'name', title: __('Name'), operate: 'like'},
  28. {field: 'table', title: __('Table')},
  29. {
  30. field: 'createtime',
  31. sortable: true,
  32. visible: false,
  33. title: __('Createtime'),
  34. operate: 'RANGE',
  35. addclass: 'datetimerange',
  36. formatter: Table.api.formatter.datetime
  37. },
  38. {
  39. field: 'updatetime',
  40. sortable: true,
  41. visible: false,
  42. title: __('Updatetime'),
  43. operate: 'RANGE',
  44. addclass: 'datetimerange',
  45. formatter: Table.api.formatter.datetime
  46. },
  47. {
  48. field: 'url', title: __('Url'), operate: false, formatter: function (value, row, index) {
  49. return '<a href="' + value + '" target="_blank" class="btn btn-default btn-xs"><i class="fa fa-link"></i></a>';
  50. }
  51. },
  52. {
  53. field: 'datalist', title: __('Operate'), table: table,
  54. buttons: [
  55. {
  56. name: 'content',
  57. text: __('数据列表'),
  58. classname: 'btn btn-xs btn-success btn-addtabs',
  59. icon: 'fa fa-file',
  60. url: 'cms/diydata/index/diyform_id/{ids}'
  61. },
  62. {
  63. name: 'fields',
  64. text: __('字段列表'),
  65. classname: 'btn btn-xs btn-info btn-fields btn-addtabs',
  66. icon: 'fa fa-list',
  67. url: 'cms/fields/index/source/diyform/source_id/{ids}'
  68. },
  69. ],
  70. formatter: Table.api.formatter.buttons
  71. },
  72. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status},
  73. {
  74. field: 'operate',
  75. title: __('Operate'),
  76. table: table,
  77. events: Table.api.events.operate,
  78. formatter: Table.api.formatter.operate
  79. }
  80. ]
  81. ]
  82. });
  83. // 为表格绑定事件
  84. Table.api.bindevent(table);
  85. },
  86. add: function () {
  87. //获取标题拼音
  88. var si;
  89. $(document).on("keyup", "#c-name", function () {
  90. var value = $(this).val();
  91. if (value != '' && !value.match(/\n/)) {
  92. clearTimeout(si);
  93. si = setTimeout(function () {
  94. Fast.api.ajax({
  95. loading: false,
  96. url: "cms/ajax/get_title_pinyin",
  97. data: {title: value}
  98. }, function (data, ret) {
  99. $("#c-table").val("cms_diyform_" + data.pinyin);
  100. $("#c-diyname").val(data.pinyin.substr(0, 100));
  101. return false;
  102. }, function (data, ret) {
  103. return false;
  104. });
  105. }, 200);
  106. }
  107. });
  108. Controller.api.bindevent();
  109. },
  110. edit: function () {
  111. Controller.api.bindevent();
  112. },
  113. api: {
  114. bindevent: function () {
  115. $.validator.config({
  116. rules: {
  117. diyname: function (element) {
  118. if (element.value.toString().match(/^\d+$/)) {
  119. return __('Can not be only digital');
  120. }
  121. if (!element.value.toString().match(/^[a-zA-Z0-9\-_]+$/)) {
  122. return __('Please input character or digital');
  123. }
  124. return $.ajax({
  125. url: 'cms/diyform/check_element_available',
  126. type: 'POST',
  127. data: {id: $("#diyform-id").val(), name: element.name, value: element.value},
  128. dataType: 'json'
  129. });
  130. }
  131. }
  132. });
  133. Form.api.bindevent($("form[role=form]"));
  134. }
  135. }
  136. };
  137. return Controller;
  138. });