2014-02-10 09:55:22 +00:00
|
|
|
$(function() {
|
|
|
|
var ListCheckData = {},
|
|
|
|
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" />');
|
2014-01-16 10:15:00 +00:00
|
|
|
};
|
|
|
|
|
2014-02-10 09:55:22 +00:00
|
|
|
$.fn.listCheck = function () {
|
|
|
|
$(this).each(function() {
|
|
|
|
var $this = $(this),
|
|
|
|
$el = $this.find('input[type="checkbox"]');
|
|
|
|
$el.each(function (i) {
|
|
|
|
if(!$(this).data('exists')) {
|
|
|
|
new ListCheck(this);
|
|
|
|
};
|
|
|
|
});
|
|
|
|
$this.on(clickEvent, $el, function(e) {
|
|
|
|
if($(e.target).prop('checked')) {
|
|
|
|
$(e.target).siblings('i').addClass('icon-check').removeClass('icon-check-empty').closest('tr').addClass('checkHit');
|
|
|
|
} else {
|
|
|
|
$(e.target).siblings('i').addClass('icon-check-empty').removeClass('icon-check').closest('tr').removeClass('checkHit');
|
|
|
|
};
|
|
|
|
if($(e.target).closest('th').hasClass('listCheckHead')) {
|
|
|
|
$this.find('.listCheck input[type="checkbox"]').prop('checked', $(e.target).prop('checked'));
|
|
|
|
if($(e.target).prop('checked')) {
|
|
|
|
$this.find('.listCheck i').addClass('icon-check').removeClass('icon-check-empty').closest('tr').addClass('checkHit');
|
|
|
|
} else {
|
|
|
|
$this.find('.listCheck i').addClass('icon-check-empty').removeClass('icon-check').closest('tr').removeClass('checkHit');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var _isCheck = $this.find('tbody').find($el).filter(':checked').length,
|
|
|
|
_defaultLength = $this.find('tbody').find($el).length;
|
2014-01-16 10:15:00 +00:00
|
|
|
|
2014-02-10 09:55:22 +00:00
|
|
|
if(_isCheck > 0 && _isCheck < _defaultLength) {
|
|
|
|
$this.find('.listCheckHead i').removeClass('icon-check-empty icon-check').addClass('icon-minus');
|
|
|
|
} else if(!_isCheck) {
|
|
|
|
$this.find('.listCheckHead i').removeClass('icon-minus icon-check').addClass('icon-check-empty');
|
|
|
|
} else {
|
|
|
|
$this.find('.listCheckHead i').removeClass('icon-check-empty icon-minus').addClass('icon-check');
|
|
|
|
}
|
|
|
|
_isCheck ? $this.find('.list-active-btn').removeClass('disabled').data('actionable', true) : $this.find('.list-active-btn').addClass('disabled').data('actionable', false);
|
|
|
|
});
|
|
|
|
$this.on(clickEvent, '.list-active-btn', function(e) {
|
|
|
|
if(!$(this).hasClass('disabled')) {
|
|
|
|
ListCheckData.url = $(this).attr('rel');
|
|
|
|
ListCheckData.name = $this.find('tbody').find('input[type="checkbox"]').attr('name');
|
|
|
|
ListCheckData.action = $(this).data('checkAction');
|
|
|
|
ListCheckData.values = [];
|
|
|
|
ListCheckData.element = $this
|
|
|
|
$this.find('tbody').find('input[type="checkbox"]').each(function (i) {
|
|
|
|
this.checked && ListCheckData.values.push("ids[]=" + this.value);
|
|
|
|
});
|
|
|
|
console.log(ListCheckData.values.join("&"));
|
|
|
|
$('#dialog').modal('show');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
clearCheck($(this));
|
|
|
|
};
|
|
|
|
|
|
|
|
function clearCheck(element) {
|
|
|
|
element.find('input[type="checkbox"]').each(function() {
|
|
|
|
$(this).prop('checked', false).siblings('i').addClass('icon-check-empty').removeClass('icon-check').closest('tr').removeClass('checkHit');
|
|
|
|
});
|
|
|
|
element.find('.list-active-btn').addClass('disabled');
|
|
|
|
};
|
|
|
|
|
|
|
|
function actionSuccess(e) {
|
|
|
|
ListCheckData.element.find('tbody').find('input[type="checkbox"]').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(ListCheckData.element);
|
|
|
|
}
|
2014-01-16 10:15:00 +00:00
|
|
|
$('.list-check').listCheck();
|
|
|
|
$('.delete-item').on(clickEvent, function() {
|
2014-02-10 09:55:22 +00:00
|
|
|
if(ListCheckData.url.indexOf("?") > -1) {
|
|
|
|
$.ajax(ListCheckData.url + "&" + ListCheckData.values.join("&")).done(function() {
|
|
|
|
actionSuccess(ListCheckData.action);
|
2014-01-16 10:15:00 +00:00
|
|
|
});
|
|
|
|
} else {
|
2014-02-10 09:55:22 +00:00
|
|
|
$.ajax(ListCheckData.url + "?" + ListCheckData.values.join("&")).done(function() {
|
|
|
|
actionSuccess(ListCheckData.action);
|
2014-01-16 10:15:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
$('#dialog').modal('hide');
|
|
|
|
$('.list-active-btn').addClass('disabled').data('actionable', false);
|
|
|
|
});
|
|
|
|
});
|