106 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			3.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
var ListCheck = function(element) {
 | 
						|
  this.element = $(element);
 | 
						|
  this.element.data('exists', true);
 | 
						|
  if(this.element.context.parentNode.tagName == "TD") {
 | 
						|
    this.elementWrap = $(this.element.context.parentNode);
 | 
						|
    this.elementWrap.addClass('listCheck');
 | 
						|
  } else if(this.element.context.parentNode.tagName == "TH") {
 | 
						|
    this.elementWrap = $(this.element.context.parentNode);
 | 
						|
    this.elementWrap.addClass('listCheckHead');
 | 
						|
  }
 | 
						|
  this.element.before('<i class="icon-check-empty" />');
 | 
						|
};
 | 
						|
 | 
						|
$.fn.listCheck = function (callback) {
 | 
						|
  this.each(function (i) {
 | 
						|
      if(!$(this).data('exists')) {
 | 
						|
         new ListCheck(this);
 | 
						|
      };
 | 
						|
  });
 | 
						|
  this.on(clickEvent, function(e) {
 | 
						|
    if($(this).prop('checked')) {
 | 
						|
      $(this).siblings('i').addClass('icon-check').removeClass('icon-check-empty').closest('tr').addClass('checkHit');
 | 
						|
    } else {
 | 
						|
      $(this).siblings('i').addClass('icon-check-empty').removeClass('icon-check').closest('tr').removeClass('checkHit');
 | 
						|
    };
 | 
						|
    if ($(this).closest('.listCheckHead').length) {
 | 
						|
      $('.listCheck .list-check').prop('checked', $(this).prop('checked'));
 | 
						|
      if($(this).prop('checked')) {
 | 
						|
        $('.listCheck i').addClass('icon-check').removeClass('icon-check-empty').closest('tr').addClass('checkHit');
 | 
						|
      } else {
 | 
						|
        $('.listCheck i').addClass('icon-check-empty').removeClass('icon-check').closest('tr').removeClass('checkHit');
 | 
						|
      }
 | 
						|
    };
 | 
						|
 | 
						|
    var _isCheck = $('tbody .list-check').filter(':checked').length,
 | 
						|
        _defaultLength = $('tbody .list-check').length;
 | 
						|
 | 
						|
    if(_isCheck > 0 && _isCheck < _defaultLength) {
 | 
						|
      $('.listCheckHead i').removeClass('icon-check-empty icon-check').addClass('icon-minus');
 | 
						|
    } else if(!_isCheck) {
 | 
						|
      $('.listCheckHead i').removeClass('icon-minus icon-check').addClass('icon-check-empty');
 | 
						|
    } else {
 | 
						|
      $('.listCheckHead i').removeClass('icon-check-empty icon-minus').addClass('icon-check');
 | 
						|
    }
 | 
						|
    _isCheck ? $('.list-active-btn').removeClass('disabled').data('actionable', true) : $('.list-active-btn').addClass('disabled').data('actionable', false);
 | 
						|
  });
 | 
						|
};
 | 
						|
function clearCheck() {
 | 
						|
  $('.list-check').each(function() {
 | 
						|
    $(this).prop('checked', false);
 | 
						|
  })
 | 
						|
}
 | 
						|
function actionSuccess(e) {
 | 
						|
  $("tbody .list-check").each(function() {
 | 
						|
    switch(e) {
 | 
						|
      case 'list-be-hide':
 | 
						|
        $(this).filter(':checked').closest('tr').addClass('checkHide');
 | 
						|
        break;
 | 
						|
      case 'list-be-show':
 | 
						|
        $(this).filter(':checked').closest('tr').removeClass('checkHide');
 | 
						|
        break;
 | 
						|
      case 'list-be-remove':
 | 
						|
        $(this).filter(':checked').closest('tr').fadeOut(300, function() {
 | 
						|
          $(this).remove();
 | 
						|
        });
 | 
						|
        break;
 | 
						|
    };
 | 
						|
    $('.list-check').siblings('i').removeAttr('class').addClass('icon-check-empty').closest('tr').removeClass('checkHit');
 | 
						|
  });
 | 
						|
  clearCheck();
 | 
						|
}
 | 
						|
$(function() {
 | 
						|
  var $t = null,
 | 
						|
      _data = null;
 | 
						|
  clearCheck();
 | 
						|
  $('.list-check').listCheck();
 | 
						|
  $('.list-active-btn').data('actionable', false).on(clickEvent, function(e) {
 | 
						|
    $t = $(this)
 | 
						|
    _data = $(this).data()
 | 
						|
    _data.actionable ? $('#dialog').modal('show') : "";
 | 
						|
    e.preventDefault();
 | 
						|
  });
 | 
						|
 | 
						|
  $("#dialog").on(clickEvent, '.delete-item', function() {
 | 
						|
    var _v = [],
 | 
						|
        _t = $t.attr("rel");
 | 
						|
 | 
						|
    $("tbody .list-check:checked").each(function() {
 | 
						|
        _v.push(this.value);
 | 
						|
    });
 | 
						|
 | 
						|
    $.ajax({
 | 
						|
      url : _t,
 | 
						|
      type:"get",
 | 
						|
      data : {"ids":_v},
 | 
						|
      dataType : "json",
 | 
						|
      success : function(){
 | 
						|
        actionSuccess(_data.checkAction);
 | 
						|
      }
 | 
						|
    })
 | 
						|
 | 
						|
    $('#dialog').modal('hide');
 | 
						|
    $('.list-active-btn').addClass('disabled').data('actionable', false);
 | 
						|
  })
 | 
						|
 | 
						|
}); |