$(document).ready(function() {
	loadPluginInfo();
});

var table = $('#addPluginTable');
var deleteButton = "<a class='btn btn-info' onClick='deletePlugin(this)'><i class='icon-trash icon-white'></i>Delete</a>";

function loadPluginInfo() {
	$.post("loadPluginUIList", {}, function(data) {

		if (!data.success) {
			information(data.failedMessage);
			return;
		}
		data = data.pluginUIs;// List<PluginUIModel>
		table.dataTable().fnClearTable();
		for (var i = 0; i < data.length; i++) {
			var time = new Date(data[i].createTimeDate);//时间转换
			table.dataTable().fnAddData(
					[ data[i].pluginInfoModel.name, time, deleteButton ]);
		}
	});
}

function deletePlugin(selectedNode){
	var plugin=selectedNode.parentNode.parentNode.firstChild.firstChild.nodeValue;
	var con=confirm("Are you sure you want to delete this plugin?");
	if (con==true) {  
		deleteAPlugin(plugin);
    } 
}

function deleteAPlugin(plugin){
	$.post("deletePluginByPluginName", {
		pluginName:plugin
	}, function(data) {
		if (!data.success) {
			information(data.failedMessage);
			return;
		}
		information("delete success!");
		location.replace(location) ;
	});
}

function addPlugin() {
	$('#myModal_plugin').modal('show');
	$('form').ajaxForm({
		success : function(data) {
			$('#myModal_plugin').modal('hide');
			if (data.success) {
				information("upload success!");
				loadPluginInfo();
			} else {
				information(data.failedMessage);
			}
		}
	});
}
