//全选
try {
	$(".checkbox-all").on('change', function() {
		var the = $(this);
		if(the.prop('checked')) {
			$('[name="ids[]"],[name="id[]"]').prop('checked', true);
		} else {
			$('[name="ids[]"],[name="id[]"]').prop('checked', false);
		}
	})
} catch(e) {}

//多条删除
try {
	$(".del-more").on('click', function() {
		if(!confirm("即将删除数据，且不可恢复，是否确认？")) {
			return false;
		}
		var the = jQuery(this);
		the.html(the.html() + ' 中...');
		$.post(
			$("form.list").attr('action'),
			$("form.list").serializeArray(),
			function(data) {
				if(data.status == 1) {
					window.location.reload();
				}
			}
		);
	})
} catch(e) {}

//单条删除
try {
	$(".del.ajax-post").on("click", function() {
		if(!confirm("即将删除数据，且不可恢复，是否确认？")) {
			return false;
		}
		var the = $(this);
		$.get(
			the.attr('href'),
			function(data) {
				window.location.reload();
			}
		);
		return false;
	})
} catch(e) {}

//快速编辑
try {
	jQuery("[data-mod]").on('change', function() {
		wd_alert({
			background: "#4BBD00"
		});
		var the = jQuery(this);
		var opts = the.attr("data-mod");
		opts = eval("(" + opts + ")");
		var action=opts.action;
		delete opts.action;
		jQuery.post(
			action,
			opts,
			function(data) {
				console.log(data);
				if(data.status == 1) {
					wd_alert_del({
						timeout: 100
					});
				}
			}

		);
	});
} catch(e) {}


function insertText(obj, str) {
	if(document.selection) {
		var sel = document.selection.createRange();
		sel.text = str;
	} else if(typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
		var startPos = obj.selectionStart,
			endPos = obj.selectionEnd,
			cursorPos = startPos,
			tmpStr = obj.value;
		obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
		cursorPos += str.length;
		obj.selectionStart = obj.selectionEnd = cursorPos;
	} else {
		obj.value += str;
	}
}