/** * config: * [String] id: 对应的dom对象的ID。不必填 * [String] module 模块名称
* [String] action 请求对象
* [String] event 请求事件
* [dataSet]dataSet 数据
* [String] config: url: dialog对应的页面。不必填 * [Function] onComplete: dialog关闭后的操作,不必填 * [String] width: 宽度, * [String] height: 高度, * [boolean] modal: 模态, * [boolean] full: 是否全屏,默认为false, * [String] title: 标题, * [String] toolbar: 工具栏, * [String] buttons: 按钮栏, * [String] parentContainer: 按钮栏, * [Object] dlg: easyui本身对应的dialog配置属性。不必填 */ function Dialog(config) { this._cmpName = null; this._container = null;//dialog对相应的容器 this._dialogContainer = null;//当前的dialog对象容器 this._returnObj = null;//返回的数据 this._url = null;//最终的请求串 this._init = function() { if(config["parentContainer"] == null) { config["parentContainer"] = $('body'); } if(config["modal"] == null) { config["modal"] = true; } if(config["width"] == null) { config["width"] = "650"; } if(config["height"] == null) { config["height"] = "450"; } if(config["full"] == null) { config["full"] = false; } if(config["full"]) { config["width"] = $("body").width(); config["height"] = $("body").height(); } } this.show = function() { var allTime = new Date().getTime(); var url = config["url"]; if(url == null && config["action"] != null && config["event"] != null) { url = contextPath + "/" + config["module"] + "/" + config["action"] + "/" + config["event"] +".do"; } this._url = url; var dataSet = config["dataSet"] == null ? new DataSet() : config["dataSet"]; if(_application.getIdentifier()) { dataSet.setHeader(constant.IDENTIFIER, _application.getIdentifier()); } var data = dataSet.clone(); data["requestComponent"] = "1"; data = encodeURIComponent(JSON.toStr(data)); if(url != null) { var _self = this; $.messager.progress(); $.ajax({ url: url, type:"POST", data:"data=" + data, cache:false}).done(function(data) { var startTime = new Date().getTime(); try { var contextData = _application._getContextInfo(data); _self._cmpName = contextData.cmpName; if(config["toolbar"] == null) { config["toolbar"] = "#" + contextData.cmpId + "_toolbar"; } else { config["toolbar"] = "#" + contextData.cmpId + "_" + config["toolbar"]; } if(config["buttons"] == null) { config["buttons"] = "#" + contextData.cmpId + "_buttons"; } else { config["buttons"] = "#" + contextData.cmpId + "_" + config["buttons"]; } config["defineClose"] = function() { _self.close.call(_self); }; config["parentContainer"].append(_application._getInData(data,_self._cmpName)); _self._container = $("#div_" + _self._cmpName,config["parentContainer"]); if(config.id != null && config.id != "") { _application._initCmp(contextData,$("#" + config.id,_self._container),_self); $("#" + config.id,_self._container).extdialog(config.dlg == null ? config : config.dlg); _self._dialogContainer = $("#" + config.id,_self._container); } else { _application._initCmp(contextData,_self._container,_self); _self._container.extdialog(config.dlg == null ? config : config.dlg); _self._dialogContainer = _self._container; } } catch(e) { // $.messager.alert("系统提示","客户端页面跳转出错,错误信息为: \r\n" + e.message,"error"); if(window.console && window.console.log) { window.console.log("错误日志:" + e.stack); } } finally { $.messager.progress('close'); var endTime = new Date().getTime(); if(window.console && window.console.log) { window.console.log("all time:" + (endTime-allTime) + "; client time:" + (endTime-startTime)); } } }).fail(function(jqXHR, textStatus, errorThrown) { $.messager.alert("系统提示",errorThrown,"error"); }); } else { $("#" + config.id,config["parentContainer"]).extdialog(config.dlg == null ? {modal:true} : config.dlg); this._dialogContainer = $("#" + config.id,config["parentContainer"]); } } this.initDialog = function() { var cmp = eval(this._cmpName); if(typeof cmp["init"] == "function") { cmp["init"].call(cmp); } } this.setReturn = function(obj) { this._returnObj = obj; } //关闭方法 this.close = function() { this._dialogContainer.extdialog('close'); if(this._url != null) { this._dialogContainer.extdialog('destroy'); this._container.remove(); } if(config.onComplete) { config.onComplete.call(null,this._returnObj); } } this.getDialogContainer = function() { return this._dialogContainer; } this.getName = function() { return this._cmpName; } this._init(); }