From cce28873834a6ed44db318e1158efac66e00f5ed Mon Sep 17 00:00:00 2001 From: devlike Date: Thu, 8 Feb 2018 11:07:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=AB=99=E7=82=B9CMS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/assets/js/backend/posts/archives.js | 306 +++++++++++++++++++++ public/assets/js/backend/posts/channel.js | 127 +++++++++ public/assets/js/backend/posts/modelx.js | 242 ++++++++++++++++ public/assets/js/backend/posts/page.js | 74 +++++ public/assets/js/backend/posts/sites.js | 116 ++++++++ 5 files changed, 865 insertions(+) create mode 100644 public/assets/js/backend/posts/archives.js create mode 100644 public/assets/js/backend/posts/channel.js create mode 100644 public/assets/js/backend/posts/modelx.js create mode 100644 public/assets/js/backend/posts/page.js create mode 100644 public/assets/js/backend/posts/sites.js diff --git a/public/assets/js/backend/posts/archives.js b/public/assets/js/backend/posts/archives.js new file mode 100644 index 00000000..69c7d332 --- /dev/null +++ b/public/assets/js/backend/posts/archives.js @@ -0,0 +1,306 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'posts/archives/index', + add_url: 'posts/archives/add', + edit_url: 'posts/archives/edit', + del_url: 'posts/archives/del', + multi_url: 'posts/archives/multi', + table: 'archives', + } + }); + + var table = $("#table"); + //在普通搜索渲染后 + table.on('post-common-search.bs.table', function (event, table) { + Form.events.cxselect($("form", table.$commonsearch)); + }); + + table.on('post-body.bs.table', function (e, settings, json, xhr) { + $(".btn-editone", this) + .off("click") + .removeClass("btn-editone") + .addClass("btn-addtabs") + .prop("title", __('Edit')); + }); + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'weigh', + sortOrder: 'desc', + columns: [ + [ + {checkbox: true}, + {field: 'id', title: __('id'), operate: false}, + {field: 'channel_id', title: __('Channel_id'),formatter: function (value, row, index) { + return row.channel==null?'':'' + row.channel.name + ''; + }, + searchList: $.getJSON('posts/channel/getlist') + }, + {field: 'type', title: __('type'), formatter: function (value,row,index){ + return ''+value+''; + }, operate:false }, + {field: 'title', align:'left', title: __('title'), operate: 'LIKE %...%', + formatter: function(value,row, index){ + return value + (row.cover==''?'' : ' '); + }}, + {field: 'status', title: __('status'), searchList: {new: __('New'), normal: __('Normal'), hidden: __('Hidden')}, formatter: Table.api.formatter.status}, + {field: 'updatetime', title: __('updatetime'),operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime}, + {field: 'views', title: __('Views'), operate:false}, + {field: 'weigh', title: __('Weigh'), operate:false}, + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, + //buttons: [ + // {name: 'edit', extend: 'title="'+ __('Edit')+'"', classname: 'btn btn-xs btn-success btn-addtabs', icon: 'fa fa-pencil', url: $.fn.bootstrapTable.defaults.extend.edit_url} + //], + formatter: Table.api.formatter.operate + } + ] + ] + }); + + // 为表格绑定事件 + Table.api.bindevent(table); + + $(document).on('click', '.btn-move', function () { + var ids = Table.api.selectedids(table); + Layer.open({ + title: __('Move'), + content: Template("channeltpl", {}), + btn: [__('Move')], + yes: function (index, layero) { + var channel_id = $("select[name='channel']", layero).val(); + if (channel_id == 0) { + Toastr.error(__('Please select channel')); + return; + } + Fast.api.ajax({ + url: "posts/archives/move/ids/" + ids.join(","), + type: "post", + data: {channel_id: channel_id}, + }, function () { + table.bootstrapTable('refresh', {}); + Layer.close(index); + }); + }, + success: function (layero, index) { + } + }); + }); + + + }, + recyclebin: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + multi_url: 'posts/archives/multi', + } + }); + + var table = $("#table"); + + // 初始化表格 + table.bootstrapTable({ + url: 'posts/archives/recyclebin', + pk: 'id', + sortName: 'weigh', + columns: [ + [ + {checkbox: true}, + {field: 'id', title: __('id'), operate: false}, + {field: 'site_id', title: __('Site_id'), operate: false, formatter:function(value,row,index){ + return row.sites==null? __('Main site') : row.sites.name + ' (' + row.sites.domain + ')'; + }}, + {field: 'channel_id', title: __('channel'), + formatter: function(value,row,index){return row.channel.name;}, + searchList: $.getJSON('posts/channel/getlist') + }, + {field: 'title', title: __('title'), operate: 'LIKE %...%'}, + {field: 'deletetime', title: __('deletetime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime}, + {field: 'operate', width: '130px', title: __('Operate'), table: table, events: Table.api.events.operate, + buttons: [ + {name: 'Restore', text: __('Restore'), classname: 'btn btn-xs btn-info btn-restoreit', icon: 'fa fa-rotate-left', url: 'posts/archives/restore'}, + {name: 'Destroy', text: __('Destroy'), classname: 'btn btn-xs btn-danger btn-destroyit', icon: 'fa fa-times', url: 'posts/archives/destroy'} + ], + formatter: Table.api.formatter.operate} + ] + ] + }); + + // 为表格绑定事件 + Table.api.bindevent(table); + + //清空回收站、批量/单个销毁 + $(document).on('click', '.btn-destroyall,.btn-destroy,.btn-destroyit', function (e) { + var that = this; + var top = $(that).offset().top - $(window).scrollTop(); + var left = $(that).offset().left - $(window).scrollLeft(); + //顶部按钮显示下按钮下方 + if(!$(that).hasClass('btn-destroyit')) top += $(that).height(); + //表格中的删除,显示于左侧 + if($(that).hasClass('btn-destroyit')) left -= 260; + if (top + 154 > $(window).height()) { + top = top - 154; + } + if ($(window).width() < 480) { + top = left = undefined; + } + var index=Layer.confirm(__('Are you sure you want to delete this item?'), + {icon: 3, title: __('Warning'), offset: [top, left], shadeClose: true}, + function () { + var options = $(that).attr("href"); + if($(that).hasClass('btn-destroy')){ //批量销毁 + var ids = Table.api.selectedids(table); + options = {url: $(this).attr("href"), data: { ids: ids}}; + } + Fast.api.ajax($(that).attr("href"), function () { + Layer.close(index); + table.bootstrapTable('refresh'); + }); + }); + return false; + }); + //全部恢复、批量/单个恢复 + $(document).on('click', '.btn-restoreall,.btn-restoreit,.btn-restore', function (e) { + var options = $(this).attr("href"); + if($(that).hasClass('btn-restore')){ //批量恢复 + var ids = Table.api.selectedids(table); + options = {url: $(this).attr("href"), data: {ids: ids}}; + } + Fast.api.ajax($(this).attr("href"), function () { + table.bootstrapTable('refresh'); + }); + return false; + }); + }, + add: function () { + //$("form#add-form").data("validator-options", {ignore: ':hidden'}); + + $(document).on("change", "select[name='row[site_id]']", function () { + siteid=$(this).val(); + /* + $("#c-channel_id option:selected").prop("selected", false); + $("#c-channel_id option").addClass("hide"); + $("#c-channel_id option[data-siteid='" + $(that).val() + "']").removeClass("hide"); + + try{ + $("#c-channel_id").selectpicker("refresh"); + }catch(e){} + $('#c-channel_id').trigger('change'); + + Fast.api.ajax({url: 'posts/sites/get_site_langs', data: {"lang": $(that).val()}}, function (data) { + $("#language_choose").html(data.html); + Form.api.bindevent($("#language_choose")); + return false; + }); + */ + + $pid = $('#c-channel_id'); + + Fast.api.ajax({url: 'posts/sites/get_site_info', data: {"site_id": siteid}}, function (x,ret) { + if(ret.code=="1"){ + $pid.empty(); + $.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; + }); + + /* + var ml = $('option:selected', this).data('lang'); + if(ml==undefined) { + $('input[name="row[lang]"]').prop('disabled', false).closest('label').show(); + return false; + } + + $('input[name="row[lang]"]').prop('disabled', true).closest('label').hide(); + $.each(ml.split(','), function(key,value){ + $('input[name="row[lang]"][value="'+value+'"]').prop('disabled', false).closest('label').show(); + }); + */ + }); + + $(document).on("change", "select[name='row[channel_id]']", function () { + var model = $('option:selected',this).data('model'); + if($('input[name="row[type]"]').val()!=model) { + Fast.api.ajax({url: 'posts/archives/get_model_fields', data: {model: model}}, function (data) { + $("#extra").html(data.html); + Form.api.bindevent($("#extra")); + return false; + }); + } + $('input[name="row[type]"]').val(model); + }); + + Controller.edit(); + //if($('#c-site_id').size()>0) $('#c-site_id').trigger('change'); + $("select[name='row[channel_id]']").trigger('change'); + }, + edit: function () { + $("form").data("validator-options", {ignore: ':hidden'}); + + $.validator.config({ + rules: { + diyname: function (element) { + if (element.value.toString().match(/^\d+$/)) { + return __('Can not be digital'); + } + return $.ajax({ + url: 'posts/archives/check_element_available', + type: 'POST', + data: {name: element.name, value: element.value}, + dataType: 'json' + }); + } + } + }); + + + $(document).on("click", ".fieldlist .btn-append", function () { + var rel = parseInt($(this).closest("dl").attr("rel")) + 1; + var name = $(this).closest("dl").data("name"); + var objID = name.replace('[', '_').replace(']','_') + rel; + $(this).closest("dl").attr("rel", rel); + var appendHtml = '
'; + appendHtml += ''; + appendHtml += ' '; + appendHtml += ' '; + appendHtml += ' '; + appendHtml += ' '; + appendHtml += '
'; + $(appendHtml).insertBefore($(this).parent()); + Controller.api.bindevent(); + }); + $(document).on("click", ".fieldlist dd .btn-remove", function () { + var rel = parseInt($(this).closest("dl").attr("rel")); + rel = rel>1? rel-1: 0; + $(this).closest("dl").attr("rel", rel); + $(this).parent().off().remove(); + }); + Controller.api.bindevent(); + }, + api: { + bindevent: function () { + Form.api.bindevent($("form[role=form]"), function () { + var obj = top.window.$("#nav ul li.active"); + top.window.Toastr.success(__('Operation completed')); + top.window.$(".sidebar-menu a[url$='/posts/archives'][addtabs]").click(); + top.window.$(".sidebar-menu a[url$='/posts/archives'][addtabs]").dblclick(); + obj.find(".fa-remove").trigger("click"); + }); + } + } + }; + return Controller; +}); \ No newline at end of file diff --git a/public/assets/js/backend/posts/channel.js b/public/assets/js/backend/posts/channel.js new file mode 100644 index 00000000..fcfa9628 --- /dev/null +++ b/public/assets/js/backend/posts/channel.js @@ -0,0 +1,127 @@ +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; +}); \ No newline at end of file diff --git a/public/assets/js/backend/posts/modelx.js b/public/assets/js/backend/posts/modelx.js new file mode 100644 index 00000000..79f9b5af --- /dev/null +++ b/public/assets/js/backend/posts/modelx.js @@ -0,0 +1,242 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'posts/modelx/index', + add_url: 'posts/modelx/add', + edit_url: 'posts/modelx/edit', + del_url: 'posts/modelx/del', + multi_url: 'posts/modelx/multi', + table: 'postsmodelx', + } + }); + + var table = $("#table"); + + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'id', + commonSearch: false, + search: false, + pagination: false, + columns: [ + [ + {field: 'name', title: __('Name')}, + {field: 'title', title: __('Title')}, + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, + buttons: [ + {name: 'fieldset', extend: 'title="'+ __('Fieldset')+'"', classname: 'btn btn-xs btn-success btn-dialog', icon: 'fa fa-pencil', url: $.fn.bootstrapTable.defaults.extend.edit_url} + ], + formatter: function(value,row,index){ + $btns = $('
').html(Table.api.formatter.operate.call(this, value, row, index)); + $('.btn-editone', $btns).remove(); + return $btns.html(); + } + } + ] + ] + }); + + + $(document).on('click', '.btn-update', function (e) { + e.preventDefault(); + var inx = $(this).data('row'), status=$(this).data('status'); + var fun=function(ret,data){ + if(data!='success') return false; + table.bootstrapTable('updateRow', { + index:inx, + row:{'status': status} + }); + } + + Backend.api.ajax({url : 'posts/modelx/chgstatus', + data:{ids: $(this).data('updateid'), 'status':status } , + complete: fun + }); + }); + // 为表格绑定事件 + Table.api.bindevent(table); + }, + add: function () { + Controller.api.bindevent(); + }, + edit: function () { + $(document).on('click', '.btn-param', function(e){ + e.preventDefault(); + + var fid = $(this).data('fieldid'); + var opennerLayer = parent.Layer.getFrameIndex(window.name); + var params = fid?'¶ms='+fid:''; + //编辑窗口layer的index + parent.Backend.api.open('posts/modelx/fieldset?zl='+opennerLayer+params, $(this).attr('title'), {callback: Controller.api.saveParams}); + + return false; + }); + $(document).on('click', '.btn-change', function(e){ + var that=this; + Backend.api.ajax({ + url: 'posts/modelx/chgstatus', + data: {"ids": $(that).data('ids'), "field": $(that).data('field')} + }, function(ret,data){ + if(data.code==1){ + if ($(that).find('i').hasClass('fa-toggle-on')){ + $(that).find('i').removeClass('fa-toggle-on').addClass('fa-toggle-off'); + }else{ + $(that).find('i').removeClass('fa-toggle-off').addClass('fa-toggle-on'); + } + } + }) + }); + $(document).on('click', '.btn-delparam', function(e){ + e.preventDefault(); + $(this).closest('li').off().remove(); + }); + $(document).on('click', '.btn-submit', function(e){ + e.preventDefault(); + //var data={fieldset: []}; + var data=[]; + if($('#fieldset li').size()>0){ + $('#fieldset li').each(function(i){ + //data.fieldset.push( $(this).data() ); + data.push($(this).data()); + }); + //$('input[name="row[extra]"]').val(JSON.stringify(data)); + + Backend.api.ajax({ + url: 'posts/modelx/fieldset', + data: {ids: $('input[name="ids"]').val(), fieldset: JSON.stringify(data)} + }, function(){ + var index = parent.Layer.getFrameIndex(window.name); + parent.Layer.close(index); + }); + } + //$('#edit-form').submit(); + }); + Controller.api.bindevent(); + }, + fieldset: function(){ + var fieldid = Fast.api.query('params'), + opennerLayer = Fast.api.query('zl'); + + $.validator.config({ + rules: { + fieldname: function (element) { + _value = $.trim(element.value.toString()); + if($(element).attr('name')=='field'){ + _old=$('[name="field-old"]').val(); + if(_value==_old) return ''; + } + if (_value.match(/^\d+$/)) { + return __('Can not be digital'); + } + if (_value.length<3 || _value.length>30) { + return __('Please enter a value between %d and %d characters long',3,30); + } + + let exists = false; + var c = parent.Layer.getChildFrame('body', opennerLayer); + $('#fieldset li',c).each(function(){ + if(_value == $(this).data('field')){ + exists=true; + return false; + } + }); + if(exists) return __('Field already exist'); + + return $.ajax({ + url: 'posts/modelx/check_element_available', + type: 'POST', + data: {"id": $("[name='ids']", c).val(), "value": _value}, + dataType: 'json' + }); + } + } + }); + + $('select#c-type').on('change', function(e){ + $('.tf').addClass("hidden"); + $('.tf.tf-' + $('option:selected', this).val()).removeClass("hidden"); + }); + + $(document).on('click', '.btn-reset', function(e){ + e.preventDefault(); + if(fieldid!=undefined){ + var c = parent.Layer.getChildFrame('body', opennerLayer); + $('input[name="fieldid"]').val(fieldid); + var arr = ['field','fieldname','type','value','rule','tip','extend','length','vars','float','min','max','length','success','error','status']; + $.each(arr, function(index,item){ + let val = $('#fieldset li#'+fieldid, c).attr('data-'+item+''); + val = val!=undefined ? val.indexOf('||') ? val.replace(/(\|\|)/g, '\r\n') : val : ''; + if(item=='status'){ + $('[name="'+item+'"][value="'+val+'"]').prop('checked',true); + }else{ + $('[name="'+item+'"]').val( val ); + } + }); + $('[name="field-old"]').val($('[name="field"]').val()); + } + }); + $('.btn-reset').trigger('click'); + $('select#c-type').trigger('change'); + + Form.api.submit = function(){ + var data={}; + $('select:visible,input:visible,textarea:visible,input[name="fieldid"],input[name="rule"]').each(function(){ + data[$(this).attr('name')]=$(this).val().replace(/([\r\n])/g, '||'); + }); + data['status']=$('input[name="status"]:checked').val(); + Backend.api.close(data); + return false; + } + Controller.api.bindevent(); + }, + api: { + formatter: { + status: function(value,row,index){ + var texts=['' + __('Enabled') + '  ', + '' + __('Disabled') + '  ']; + var btns = ['' + __('Enable') + '', + '' + __('Disable') + '']; + return (value==1)? texts[0]+btns[1] : texts[1]+btns[0]; + } + }, + saveParams: function(res){ + var lidata='', newli=false; + if(res.fieldid==''){ + res.fieldid = 'p'+new Date().getTime(); + newli=true; + } + $.each(res, function(key,value){ + lidata+= (key!='fieldid')? ' data-'+key+ (value==''?'':'='+value) :''; + }); + + var li = Template('fieldTpl', { + fieldid: res.fieldid, + field: res.field, + title: res.fieldname, + type: __(res.type), + status: __(res.status), + datapart: lidata + }); + + if(newli){ + $('#fieldset div#btnAddParam').before($(li)); + }else{ + $('#fieldset li#'+res.fieldid).off().before($(li)).remove(); + } + + Controller.api.bindevent(); + }, + bindevent: function () { + Form.api.bindevent($("form[role=form]")); + } + } + }; + return Controller; +}); \ No newline at end of file diff --git a/public/assets/js/backend/posts/page.js b/public/assets/js/backend/posts/page.js new file mode 100644 index 00000000..b5f68ea0 --- /dev/null +++ b/public/assets/js/backend/posts/page.js @@ -0,0 +1,74 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'posts/page/index', + add_url: 'posts/page/add', + edit_url: 'posts/page/edit', + del_url: 'posts/page/del', + multi_url: 'posts/page/multi', + table: 'page', + } + }); + + var table = $("#table"); + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + sortName: 'weigh', + columns: [ + [ + {field: 'state', checkbox: true}, + {field: 'id', title: __('Id'), operate: false}, + {field: 'site_id', title: __('Site_id'), operate: false, formatter:function(value,row,index){ + return value==0? '-': row.sites.name; + }}, + {field: 'title', title: __('Title'), align:'left', operate: 'LIKE %...%', placeholder: '关键字,模糊搜索', + formatter: function(value,row,index){ + return value + (row.image==''?'' : ''); + }}, + {field: 'flag', title: __('Flag'), formatter: Table.api.formatter.flag, operate: false}, + {field: 'lang', title: __('lang'), formatter: Table.api.formatter.langs, operate: false}, + {field: 'views', title: __('Views'), operate: false}, + //{field: 'comments', title: __('Comments'), operate: false}, + {field: 'weigh', title: __('Weigh'), operate: false}, + {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {'normal': __('Normal'), 'hidden': __('Hidden')}, style: 'min-width:100px;'}, + {field: 'createtime', title: __('Create Time'), formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'}, + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + ] + ], + //普通搜索 + commonSearch: true, + titleForm: '', //为空则不显示标题,不定义默认显示:普通搜索 + }); + + // 为表格绑定事件 + Table.api.bindevent(table); + }, + add: function () { + Controller.api.bindevent(); + }, + edit: function () { + Controller.api.bindevent(); + }, + api: { + bindevent: function () { + $(document).on("change", "#c-site_id", function () { + that=this; + Fast.api.ajax({url: 'posts/sites/get_site_langs', data: {"lang": $(that).val()}}, function (data) { + $("#language_choose").html(data.html); + Form.api.bindevent($("#language_choose")); + return false; + }); + }); + + Form.api.bindevent($("form[role=form]")); + } + } + }; + return Controller; +}); \ No newline at end of file diff --git a/public/assets/js/backend/posts/sites.js b/public/assets/js/backend/posts/sites.js new file mode 100644 index 00000000..1d3dde85 --- /dev/null +++ b/public/assets/js/backend/posts/sites.js @@ -0,0 +1,116 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'posts/sites/index', + add_url: 'posts/sites/add', + edit_url: 'posts/sites/edit', + del_url: 'posts/sites/del', + multi_url: 'posts/sites/multi', + table: 'sites', + } + }); + + var table = $("#table"); + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'id', + columns: [ + [ + {checkbox: true}, + {field: 'id', title: __('Id')}, + {field: 'username', title: __('User_id')}, + {field: 'name', title: __('name')}, + {field: 'domain', title: __('Domain')}, + {field: 'lang', title: __('Lang')}, + {field: 'status', title: __('Status'), formatter: Table.api.formatter.status}, + {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime}, + {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(); + }, + config: function(){ + + $.validator.config({ + rules: { + domain: function(ele){ + _value = $.trim(element.value.toString()); + if (!_value.match(/^[A-Za-z0-9]+$/)) { + return __('Please enter a valid URL'); + } + return $.ajax({ + url: 'posts/sites/check_element_available', + type: 'POST', + data: {"domain": _value}, + dataType: 'json' + }); + }, + url: function (element) { + _value = $.trim(element.value.toString()); + if (!_value.match(/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_\.]+$/)) { + return __('Please enter a valid URL'); + } + return $.ajax({ + url: 'posts/sites/check_element_available', + type: 'POST', + data: {"domain": _value}, + dataType: 'json' + }); + } + } + }); + Controller.api.bindevent(); + }, + api: { + bindevent: function () { + $(document).on("click", ".fieldlist .btn-append", function () { + var rel = parseInt($(this).closest("dl").children('dd').length)-2; + $(this).closest("dl").attr("rel", rel); + $('
').insertBefore($(this).parent()); + }); + $(document).on("click", ".fieldlist dd .btn-remove", function () { + var that=this; + $(that).parent().remove(); + return; + }); + + $(document).on('click', 'input[name*="row[lang]"]', function(e){ + if($(this).val()=='zh-cn'){ + $(this).prop('checked', true); + return false; + } + $('#extraLanguage').html(''); + if($('input[name*="row[lang]"]:checked').length>1){ + $('input[name*="row[lang]"]:checked').each(function(){ + if($(this).val()!='zh-cn'){ + var language = $(this).val(); + var languageText = $(this).closest('label').text(); + var html = Template('seotpl', {lang: language, langName: languageText}); + $('#extraLanguage').append(html) + } + }); + } + }); + + Form.api.bindevent($("form[role=form]")); + } + } + }; + return Controller; +}); \ No newline at end of file