再送ファイル管理システム最適化js

8147 ワード

var table;//  table    vue   

$(function () {

var columnDefsDate=[];

var columnsData=[ CONSTANT.DATA_TABLES.COLUMN.CHECKBOX,//   CONSTANT.js       js

                  { "data": "id","visible": false },

                  { "data": "name" ,"render":function ( data, type, row,  meta ) {

                  if(row.fileType=="file"){

                  return ' '; 

                  }if(row.category=="picture"){

                  return ' ';

                  }else{

                  return ' ';

                  }

                  }},

                  { "data": "createTime"},

                  { "data": "fileSize"},

                  { "data": null ,"render":function ( data, type, row,meta ) {

                  var isAdmin=false;

                  var rootPub=false;

                  var me=false;

                  var flag=false;

                  if(vm.rootEntity!=null){

                  me=vm.rootEntity.userId==row.userId?true:false;//              

                  isAdmin=vm.superAdmin=vm.rootEntity.userId?true:false;//      

                  rootPub=row.userId==0?true:false;//           

                  if(isAdmin||me){

                      flag=true;

                      }

                      if(rootPub){

                      flag=false;

                      }

                  }

                  var data="";

                  if(vm.IsFileManager){

                  if(row.fileType=="file"){

                          if(flag){data='    ';}{data ='';} 

                          }else{

                          flag=true; 

                          data='    ';

                          }

                          if(flag){data+='';}{data +='';}

                  }

                      return data;

                  }},

                  ];

  table=$('#example').DataTable( {

  "responsive": true,

      "serverSide" : true, 

      //l -           f -      t -     i -      p  -     r  -        

      "dom":'tif',//'>rt>' 

      "ordering" :false,//     

        "ajax":{

            "url": '/manager/sys/sysFile/list',

            "type":"post",

            "cache": false,

            "data": function(d){

            d.name=vm.q.query;//    

            d.parentDirectory=vm.q.parentDirectory;//     

            d.category=vm.q.category;//  

            d.code=vm.q.code;

            if(d.parentDirectory==0){//             

            vm.q.code=""; 

            }

            },

            "dataSrc":function (json) {//       data

            json.recordsTotal = json.page.recordsTotal||0;//recordsTotal      

            json.recordsFiltered = json.page.recordsFiltered||0;//recordsFiltered      

            vm.q.category=null;

            vm.q.parentDirectory=null;

            vm.q.label=null;

            vm.rootEntity=json.page.sEcho.rootEntity;//      

            /*vm.id=vm.rootEntity!=null?vm.rootEntity.id:null;*/

            vm.superAdmin=json.page.sEcho.superAdmin;//     

            vm.userId=json.page.sEcho.userId;//    id

            vm.IsFileManager=json.page.sEcho.IsFileManager;//        

            /*console.log(vm.IsFileManager);*/

                return json.page.list;

            },

            },

        "aLengthMenu":[5,10,30,50],

        "pageLength":10,

        "bStateSave": false,//    ,                  ,    cookie ,                   。

        "searching":false,//    (   )

        "paging": true,//                   

        "drawCallback" : function(settings) { 

        /**        */

        $(settings.nTable).find(":checkbox[name='keeperUserGroup-checkable']").click(function(e){

        if($(this).prop('checked')){

        table.$('tr').addClass('warning selected');

        $(settings.nTable).find('tbody tr input:checkbox').prop('checked', true);

        }else{

        table.$('tr').removeClass('warning selected');

        $(settings.nTable).find('tbody tr input:checkbox').prop('checked', false);

        }

        vm.setType();

        });

            /**TR   */

            $(settings.nTable).find("tbody tr").click(function(e) {

            //     

            $(settings.nTable).find(":checkbox[name='keeperUserGroup-checkable']").prop('checked', false);

            //    tr checkbox  ,     

            var tr = $(e.target).parents('tr');

            var checkbox = $(e.target).parents('tr').find(":checkbox");

            var checkedLen = $(settings.nTable).find("input:checkbox:checked").length;

            //       checkbox

            if($(e.target).is('input:checkbox')){

            tr.toggleClass('warning selected');

            vm.setType();

            return true;

            }

            //          checkbox

            tr.siblings().removeClass('warning selected');

            tr.siblings().find(":checkbox").prop('checked', false);

            //            

              if(checkedLen >= 2){

            checkbox.prop('checked', true);

                tr.addClass('warning selected');

            }else{

            //      checkbox

                checkbox.prop('checked', !checkbox.prop('checked'));

                tr.toggleClass('warning selected');

            }

            //        (      )

                vm.setType();

            });

        },

        "columns": columnsData, //     json        ,data json    key

        "columnDefs": columnDefsDate,

        "oLanguage" : { 

            sProcessing : "   ...", 

            sLengthMenu : "   _MENU_  ", 

            sZeroRecords : "      ", 

            sInfo : "  _START_   _TOTAL_  ,  _TOTAL_  ", 

            sInfoEmpty : "   0   0  ,  0  ", 

            sInfoFiltered : "(  _MAX_      )", 

            sInfoPostFix : "", 

            sSearch : "  :", 

            searchPlaceholder : "     ", 

            sUrl : "", 

            sEmptyTable : "      ", 

            sLoadingRecords : "   ...", 

            sInfoThousands : ",", 

            oPaginate : { 

                sFirst : "  ", 

                sPrevious : "  ", 

                sNext : "  ", 

                sLast : "  " 

            }, 

            oAria : { 

                sSortAscending : ":        ", 

                sSortDescending : ":        " 

            } 

        },

    } );

});