define(function(require, exports, module) {
	var global = require("../../js/global");
	
	function _exportFile(name) {
	    var export_file = $(name);
	    export_file.unbind('change');
	    export_file.change(function(evt) {
	    	//从云端下载故障日志文件
	    	var dstFilePath = $(this).val();
	    	var faultId = $('#faultId').val().trim();
			var path = global.nwPath.join(dstFilePath, faultId + '.tar.gz');
			var data = JSON.stringify({id : parseInt(faultId)});
			var params = {
					fileType : 'faultInfo',
					data : data
			};
			var sessionId = global.userMgrIns.getUserInfo().sessionId;
			var headers = {
                'Cookie': 'JSESSIONID=' + sessionId
            };
			
			var _commonPostCbk = function(err, data) {
				$("#downloadLogModal").modal('hide');
				
				if (err != null) {
					alert(undefined, "该故障日志文件不存在！");
					return;
				}
				
//				$("#faultIdModal").modal('hide');				
				alert(undefined, "故障文件下载完成！");
			};
			
			$("#downloadLogModal").modal('show');
			global.jsUtil.commonDownload(undefined, headers, params, undefined, path, undefined, _commonPostCbk);
	    	
	    	$(this).val("");
	    });
	    export_file.trigger('click');
	}
	
	function init() {
		initEvent();
		initGlobalEvent();
		
		function initEvent() {
			$("#downloadLogBtn").click(function() {
				var faultId = $('#faultId').val().trim();
				if (faultId == '') {
					alert(undefined, "请输入故障ID号！");
					return;
				}
				
				_exportFile("#faultLogDir");
			});
			
			$("#faultIdModal").modal('show');
		}
		function initGlobalEvent() {
			global.exitPageCallback.exitFun = function () {
				return true;
			}
		}
	}
	exports.init = init;
});