info.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'building/info/index' + location.search,
  8. add_url: 'building/info/add',
  9. edit_url: 'building/info/edit',
  10. del_url: 'building/info/del',
  11. multi_url: 'building/info/multi',
  12. import_url: 'building/info/import',
  13. table: 'building_info',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('Id')},
  26. {field: 'content', title: __('Content')},
  27. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  28. ]
  29. ]
  30. });
  31. // 给上传按钮添加上传成功事件
  32. $("#faupload-avatar").data("upload-success", function (data) {
  33. var url = Backend.api.cdnurl(data.url);
  34. $(".profile-user-img").prop("src", url);
  35. Toastr.success("上传成功!");
  36. });
  37. // 给表单绑定事件
  38. Form.api.bindevent($("#update-form"), function () {
  39. $("input[name='row[password]']").val('');
  40. var url = Backend.api.cdnurl($("#c-avatar").val());
  41. top.window.$(".user-panel .image img,.user-menu > a > img,.user-header > img").prop("src", url);
  42. return true;
  43. });
  44. // 为表格绑定事件
  45. Table.api.bindevent(table);
  46. },
  47. add: function () {
  48. Controller.api.bindevent();
  49. },
  50. edit: function () {
  51. Controller.api.bindevent();
  52. },
  53. api: {
  54. bindevent: function () {
  55. Form.api.bindevent($("form[role=form]"));
  56. }
  57. }
  58. };
  59. return Controller;
  60. });