define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { // 初始化表格参数配置 Table.api.init({ extend: { index_url: 'posts/channel/index', add_url: 'posts/channel/add', edit_url: 'posts/channel/edit', del_url: 'posts/channel/del', multi_url: 'posts/channel/multi', table: 'channel', } }); var table = $("#table"); // 初始化表格 table.bootstrapTable({ url: $.fn.bootstrapTable.defaults.extend.index_url, escape: false, pk: 'id', sortName: 'weigh', pagination: false, escape: false, commonSearch: false, search: false, columns: [ [ {checkbox: true}, {field: 'id', title: __('Id')}, {field: 'sites.name', title: __('Site_id')}, {field: 'type', title: __('Type'), custom: {channel: 'info', list: 'success', redirect: 'primary'}, formatter: Table.api.formatter.flag}, {field: 'name', title: __('Name'), align: 'left', formatter: Controller.api.formatter.catename}, {field: 'diyname', title: __('Redirect'), formatter:function(value,row,index){ return value==''? '' : ''; }}, {field: 'flag', title: __('Flag'), operate: false, formatter: Table.api.formatter.flag}, {field: 'weigh', title: __('Weigh'), visible:true}, {field: 'archives.items', title: __('Items'), formatter:function(value,row,index){return (typeof value === 'number') ? value : 0;}}, {field: 'status', title: __('Status'), operate: false, formatter: Table.api.formatter.status}, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} ] ] }); // 为表格绑定事件 Table.api.bindevent(table); }, add: function () { Controller.api.bindevent(); }, edit: function () { Controller.api.bindevent(); }, api: { formatter: { catename: function(value,row,index){ imgtag = row.image ? '' : ''; return value + ' ' + imgtag; } }, bindevent: function () { $.validator.config({ rules: { diyname: function (element) { if (element.value.toString().match(/^\d+$/)) { return __('Can not be digital'); } return $.ajax({ url: 'posts/channel/check_element_available', type: 'POST', data: {id: $("#channel-id").val(), name: element.name, value: element.value}, dataType: 'json' }); } } }); $(document).on("click", "input[name='row[type]']", function () { $(".tf").addClass("hidden"); $(".tf.tf-" + $(this).val()).removeClass("hidden"); $("select[name='row[model]']").trigger("change"); $('#c-template').val($("input[name='row[model]']:checked").data($(this).val()+'tpl')); }); $(document).on("change", "select[name='row[site_id]']", function () { siteid=$(this).val(); //$("#c-pid option:first").prop("selected", true); //$("#c-pid option").addClass("hide"); //$("#c-pid option[data-siteid='" + $(that).val() + "']").removeClass("hide"); $pid = $('#c-pid'); Fast.api.ajax({url: 'posts/sites/get_site_info', data: {"site_id": siteid}}, function (x,ret) { if(ret.code=="1"){ $pid.empty(); $pid.append(""); $.each(ret.data.list, function(i,k){ $pid.append(""); }); $pid.selectpicker("refresh"); $pid.trigger('change'); $("#language_choose").html(ret.data.lang); } Form.api.bindevent($("#language_choose")); return false; }); }); $(document).on("change", "#c-pid", function () { $("#c-model_"+$('option:selected', this).data('model')).prop("checked", true); }); $(document).on("click", "input[name='row[model]']", function () { type = $("input[name='row[type]']:checked").val(); $('#c-template').val($(this).data(type+'tpl')); }); $("select[name='row[model]']").trigger("change"); $("input[name='row[type]']:checked").trigger("click"); Form.api.bindevent($("form[role=form]")); } } }; return Controller; });