123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- //去掉特殊字符和转义字符
- function excludeSpecial(s) {
- s = s.replace(/[\\\/\b\f\n\r\t\'\[\]\@\#\$\%\^\&\*\{\}\:\"\L\<\>\?]/g,'');
- return s;
- };
- $(document).on('keyup','#c-description',function () {
- var descrp = $('#c-description').val();
- $('#c-description').val(excludeSpecial(descrp));
- });
- var Controller = {
- index: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'booklistch/media/index',
- add_url: 'booklistch/media/add/from/'+Config.from_window,
- edit_url: 'booklistch/media/edit',
- del_url: 'booklistch/media/del',
- multi_url: 'booklistch/media/multi',
- table: 'book_list_media_ch',
- }
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- search:false,
- commonSearch: false,
- searchFormVisible: false,
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id')},
- {field: 'title', title: __('Title')},
- {field: 'image', title: __('Image'), formatter: Table.api.formatter.image,},
- {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden'),"deleted":__('status deleted')}},
- {field: 'status_text', title: __('Status'), operate:false},
- {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
- ]
- ],
- onPostBody: function () {
- //隐藏禁用操作按钮
- $.each(table.bootstrapTable("getData"), function (index, row) {
- if (row.self == "0") {
- //隐藏操作按钮
- $("a.btn-editone").eq(index).hide();
- $("a.btn-delone").eq(index).hide();
- }
- });
- }
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- if(Config.bnotin.indexOf(parseInt($('#c-book_id').val())) != -1){
- $('#c-book_id').val('');
- $('#c-book_name').val('');
- }
- Controller.api.bindevent();
- },
- select: function () {
- // 初始化表格参数配置
- Table.api.init({
- extend: {
- index_url: 'booklistch/media/select'
- },
- showColumns: false,
- showToggle: false,
- showExport: false,
- searchFormVisible: false,
- search: false
- });
- var table = $("#table");
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id desc',
- sortOrder: '',
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('Id'), operate:false},
- {field: 'image', title: __('Image'), visible: false, operate:false},
- {field: 'book_id', title: __('Bookid'), visible: false, operate:false},
- {field: 'book_name', title: __('Bookname'),visible: false, operate:false},
- {field: 'description', title: __('Description'),visible: false, operate:false},
- {field: 'title', title: __('Title'), operate: 'LIKE %...%'},
- {
- field: 'operate', title: __('Operate'), events: {
- 'click .btn-chooseone': function (e, value, row, index) {
- Fast.api.close([row]);
- },
- }, formatter: function () {
- return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
- }
- }
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- //获取选中数据
- $(document).on('click', "#btn-chooseone", function () {
- Fast.api.close(table.bootstrapTable('getSelections'));
- });
- },
- api: {
- bindevent: function () {
- if (Config.from_window != 'list') {
- Form.api.bindevent($("form[role=form]"), function (data, ret) {
- Fast.api.close(data);
- return false;
- });
- } else {
- Form.api.bindevent($("form[role=form]"));
- }
- var refreshkey = function (data) {
- Layer.closeAll();
- $('#c-book_id').val(data[0].id);
- $('#c-book_name').val(data[0].name);
- $('#c-book_name').trigger('change');
- $('#c-description').val(excludeSpecial(data[0].description));
- };
- $(document).on('click', "#select-resources", function () {
- var block_id = Config.block_id;
- parent.Backend.api.open($(this).data("url") + "?action=blockresoure&block_id=" + block_id, __('Select'), {callback: refreshkey});
- return false;
- });
- }
- }
- };
- return Controller;
- });
|