/** * jsp引入此js实现国际化 * 通过从cookie得到的language,再调用不同的messages * @author yingp */ var language = getCookie("language"); var basePath = (function() { var fullPath = window.document.location.href; var path = window.document.location.pathname; var subpos = fullPath.indexOf('//'); var subpath = subpos > -1 ? fullPath.substring(0, subpos + 2) : ''; if (subpos > -1) fullPath = fullPath.substring(subpos + 2); var pos = fullPath.indexOf(path), sname = path.substring(0, path.substr(1).indexOf('/') + 1); sname = (['/jsps','/workfloweditor','/resource'].indexOf(sname) > -1 ? '/' : sname); return subpath + fullPath.substring(0, pos) + sname + (sname == '/' ? '' : '/'); })(); var resourcePath = (function(){ var scripts = document.getElementsByTagName('script'), src = null; for(var i in scripts) { src = scripts[i].src; if(src.indexOf("i18n.js") > 0) { return src.substring(0, src.indexOf("i18n")); } } return basePath + "resource/"; })(); var em_name = getCookie("em_name"); var em_uu = getCookie("em_uu"); var en_name = getCookie("en_name"); var en_uu = getCookie("en_uu"); var em_code = getCookie("em_code"); var script = document.createElement("script"); var extScript = document.createElement("script"); script.type = "text/javascript"; extScript.type = "text/javascript"; language = language || 'zh_CN'; Ext.Loader.injectScriptElement(resourcePath + "i18n/messages_" + language + ".js",function(){},function(){}); Ext.Loader.injectScriptElement(resourcePath + "ext/ext-lang-" + language + ".js",function(){},function(){}); /*if (language == "zh_TW") { script.src = resourcePath + "i18n/messages_zh_TW.js"; extScript.src = resourcePath + "ext/ext-lang-zh_TW.js"; } else { if (language == "en_US") { script.src = resourcePath + "i18n/messages_en_US.js"; } else { script.src = resourcePath + "i18n/messages_zh_CN.js"; extScript.src = resourcePath + "ext/ext-lang-zh_CN.js"; } }*/ document.getElementsByTagName("head").item(0).appendChild(script); document.getElementsByTagName("head").item(0).appendChild(extScript); if (Ext.isIE) { var cssLink = document.createElement("link"); cssLink.rel = "stylesheet"; cssLink.type = "text/css"; cssLink.href = resourcePath + "ext/resources/css/ext-ie.css"; document.getElementsByTagName("head").item(0).appendChild(cssLink); String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); }; } // max number //Number.MAX_VALUE = 100000000000000; Ext.onReady(function(){ // extend Ext.Object Ext.Object.equals = (function() { var check = function(o1, o2) { var key; for (key in o1) { if (o1.hasOwnProperty(key)) { if (o1[key] !== o2[key]) { return false; } } } return true; }; return function(object1, object2) { if (object1 === object2) { return true; } if (object1 && object2) { return check(object1, object2) && check(object2, object1); } else if (!object1 && !object2) { return object1 === object2; } else { return false; } }; })(); // 控制同一请求(url及params完全一致)的间隔时间为0.5s var requestStack = {}, delay = 500; Ext.Ajax.on('beforerequest', function(me, options){ var now = new Date(), last = requestStack[options.url]; if(last && Ext.Object.equals(last.params, options.params) && now - last.time < delay) { return false; } else { requestStack[options.url] = {time: now, params: options.params}; } }); }); //读取cookies函数 function getCookie(name) { var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); if(arr != null) return unescape(arr[2]); return null; } //两个参数,一个是cookie的名称,一个是值 function SetCookie(name,value) { var Days = 30; //此 cookie 将被保存 30 天 var exp = new Date(); //new Date("December 31, 9998"); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); } //删除cookie function delCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval=getCookie(name); if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString(); } //解析url,获得传递的参数 function getUrlParam(name){ var reg=new RegExp("(^|&)"+name+"=([^&]*)(&|$)"); var r=window.location.search.substr(1).match(reg); if (r!=null) return decodeURI(r[2]); return null; } function onUrlClick(url){ Ext.Ajax.request({ url: basePath + url, method: 'post', callback: function(options,success,response){ Ext.Msg.alert('提示','确认成功!'); } }); } function saveRedoLog(options){ if(options.params) options.params= unescape(escape(Ext.JSON.encode(options.params))); Ext.Ajax.request({ url: basePath + 'ma/saveReDoLog.action', params:options, method: 'post', callback: function(options,success,response){ } }); } function showAll(val, title){ if(!title){ title='详细信息'; } Ext.create('Ext.window.Window', { height: 200, title:'

'+title+'

', width: 400, layout: 'fit', html:'

'+val+'

' }).show(); } /** * string:原始字符串 * substr:子字符串 * isIgnoreCase:忽略大小写 */ function contains(string, substr, isIgnoreCase){ if (string == null || substr == null) return false; if (isIgnoreCase === undefined || isIgnoreCase === true) { string = string.toLowerCase(); substr = substr.toLowerCase(); } return string.indexOf(substr) > -1; } /** * WebContent/resource/i18n/i18n.js * 浮动div,显示错误信息,div会自动消失 * @param err 错误信息 */ function showError(err, time, autoClose){ if(err != null) { window.errmessage = err; autoClose = autoClose == null ? true : autoClose; if(err == 'ERR_NETWORK_SESSIONOUT'){//session丢失 showLoginDiv(true); } else if(err == 'ERR_NETWORK_LOCKED') {//锁定 alert('您的账号已被管理员锁定,无法在当前IP登录,请重新登录或切换账号!'); showLoginDiv(true); } else { var isPowerErr = false, errCode = null; if(err.indexOf('ERR_POWER') != -1) {//权限问题 errCode = err.substring(0, err.indexOf(':')); err = err.substr(err.indexOf(':') + 1); isPowerErr = true; } var main = parent.Ext.getCmp('content-panel'); if(main){ parent.Ext.create('erp.view.core.window.Msg', { title: $I18N.common.msg.title_warn, context: err, autoClose: autoClose, autoCloseTime: time }); } else if(main = parent.parent.Ext.getCmp('content-panel')){ if(main._mobile) { Ext.Msg.alert(err); } else { parent.parent.Ext.create('erp.view.core.window.Msg', { title: $I18N.common.msg.title_warn, context: err, autoClose: autoClose, autoCloseTime: time }); } } else { Ext.create('erp.view.core.window.Msg', { title: $I18N.common.msg.title_warn, context: err, autoClose: autoClose, autoCloseTime: time }); } if(isPowerErr) { if(errCode == 'ERR_POWER_026' || errCode == 'ERR_POWER_027' || errCode == 'ERR_POWER_025') {//025查看列表,026查看单据,027查看他人单据---->这些情况下,界面直接关闭 if(main) { main.getActiveTab().close(); } else { window.close(); } } } } } } /** * 右下角出现消息提示 * @param title 消息标题 * @param msg 显示的消息 */ function showMessage(title, msg, time){ if (time == null || time > 3000) { window.errmessage = msg; } try{ if(parent.Ext.version==Ext.version && parent.Ext.getCmp('content-panel')){ parent.Ext.create('erp.view.core.window.Msg', { title: title, context: msg, isError: false, autoCloseTime: time }); } else if(parent.parent.Ext.getCmp('content-panel')){ parent.parent.Ext.create('erp.view.core.window.Msg', { title: title, context: msg, isError: false, autoCloseTime: time }); } else { Ext.create('erp.view.core.window.Msg', { title: title, context: msg, isError: false, autoCloseTime: time }); } }catch(e){ } } //form分组展开收拢 function collapse(id){ var dom = document.getElementById("group" + id); if(dom.getAttribute('class') == 'x-form-group-label'){ dom.setAttribute('class', 'x-form-group-label-close'); dom.title = "展开"; } else { dom.setAttribute('class', 'x-form-group-label'); dom.title = "收拢"; } Ext.each(Ext.getCmp('form').items.items, function(item){ if(item.group && item.group == id){ if(item.hidden == false){ item.getEl().addCls('x-hide-display'); item.hidden = true; } else { item.hidden = false; item.getEl().removeCls('x-hide-display'); } } }); } //messagebox /** * @param fn function */ function warnMsg(msg, fn){ Ext.MessageBox.show({ title: $I18N.common.msg.title_prompt, msg: msg, buttons: Ext.Msg.YESNO, icon: Ext.Msg.WARNING, fn: fn }); } function checkLogin(){ Ext.Ajax.request({ url : basePath + 'common/checkLogin.action', params: { id: id }, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ printSuccess(); } } }); warnMsg('
网络连接中断

可能原因:
' + '
' + '' + '', function(){}); } function showLoginDiv(isSessionOut){ if(!Ext.getCmp('login')){ var title = '重 新 登 录'; if(isSessionOut){ title = '会话过期,请重新登录'; } Ext.create('erp.view.core.window.ReLogin', { isSessionOut: isSessionOut, title: title, id: 'login' }); } else { Ext.getCmp('login').show(); Ext.getCmp('login').refresh(); } } function openUrl(url, newMaster ,winId){ if(winId && Ext.getCmp(winId))Ext.getCmp(winId).close(); var main = parent.Ext.getCmp("content-panel"); if(!main && parent.parent.Ext) { main = parent.parent.Ext.getCmp("content-panel"); } if(main) { var item = main.items.items[0]; item.firstGrid=Ext.getCmp('task_grid'); } url = url.toString().replace(/IS/g, '='); if(contains(url, 'formCondition')) { var fr = url.substr(url.indexOf('formCondition=') + 14); if(contains(fr, '&')) { fr = fr.substring(0, fr.indexOf('&')); } var keyField = fr.split('=')[0]; var value = fr.split('=')[1]; url = url.replace(keyField + '=' + value, keyField + '=\'' + value + '\''); } if(contains(url, 'gridCondition')) { var gr = url.substr(url.indexOf('gridCondition=') + 14); if(contains(gr, '&')) { gr = gr.substring(0, gr.indexOf('&')); } var gField = gr.split('=')[0]; var gValue = gr.split('=')[1]; url = url.replace(gField + '=' + gValue, gField + '=\'' + gValue + '\''); } if(newMaster){ var currentMaster = parent.window.sob; if ( currentMaster && currentMaster != newMaster) {// 与当前账套不一致 if (parent.Ext) { Ext.Ajax.request({ url: basePath + 'common/changeMaster.action', params: { to: newMaster }, callback: function(opt, s, r) { if (s) { var win = parent.Ext.create('Ext.Window', { width: '100%', height: '100%', draggable: false, closable: false, modal: true, title: '创建到账套' + newMaster + '的临时会话', html : '', buttonAlign: 'center', buttons: [{ text: $I18N.common.button.erpCloseButton, cls: 'x-btn-blue', id: 'close', handler: function(b) { Ext.Ajax.request({ url: basePath + 'common/changeMaster.action', params: { to: currentMaster }, callback: function(opt, s, r) { if (s) { b.up('window').close(); } else { alert('切换到原账套失败!'); } } }); } }] }); win.show(); } else { alert('无法创建到账套' + newMaster + '的临时会话!'); } } }); } return; } } var panel = Ext.getCmp(keyField + "=" + value); var main = parent.Ext.getCmp("content-panel") || parent.parent.Ext.getCmp("content-panel"); if(!panel){ var title = ""; if (value&&value.toString().length>4) { title = value.toString().substring(value.toString().length-4); } else { title = value; } panel = { title : $I18N.common.msg.title_info + '(' + title + ')', tag : 'iframe', tabConfig: {tooltip:$I18N.common.msg.title_info + '(' + keyField + "=" + value + ')'}, frame : true, border : false, layout : 'fit', iconCls : 'x-tree-icon-tab-tab', html : '', closable : true, listeners : { close : function(){ main.setActiveTab(main.getActiveTab().id); } } }; var p = main.add(panel); main.setActiveTab(p); }else{ main.setActiveTab(panel); } } function openUrl2(url,title,keyField,value){ var panel = Ext.getCmp(keyField + "=" + value); var main = parent.Ext.getCmp("content-panel"); if(!panel){ panel = { title : title, tag : 'iframe', tabConfig: {tooltip:title}, frame : true, border : false, layout : 'fit', iconCls : 'x-tree-icon-tab-tab', html : '', closable : true, listeners : { close : function(){ main.setActiveTab(main.getActiveTab().id); } } }; var p = main.add(panel); main.setActiveTab(p); }else{ main.setActiveTab(panel); } } function openFormUrl(value, keyField, url, title,newMaster,winId){ if(contains(url,'?')){ url =url+'&formCondition='+keyField+"="+value; }else url =url+'?formCondition='+keyField+"="+value; var panel = Ext.getCmp(keyField + "=" + value); var main = parent.Ext.getCmp("content-panel"); var showtitle=''; url = url.replace(/IS/g, "=\'").replace(/&/g, "\'&"); if(winId){ if (Ext.getCmp(winId))Ext.getCmp(winId).close(); else if (contains(url,'jsps/common/jprocessDeal.jsp'))url=url+'&_do=1'; } if(newMaster){ var currentMaster = parent.window.sob; if ( currentMaster && currentMaster != newMaster) {// 与当前账套不一致 if (parent.Ext) { Ext.Ajax.request({ url: basePath + 'common/changeMaster.action', params: { to: newMaster }, callback: function(opt, s, r) { if (s) { var win = parent.Ext.create('Ext.Window', { width: '100%', height: '100%', draggable: false, closable: false, modal: true, title: '创建到账套' + newMaster + '的临时会话', html : '', buttonAlign: 'center', buttons: [{ text: $I18N.common.button.erpCloseButton, cls: 'x-btn-blue', id: 'close', handler: function(b) { Ext.Ajax.request({ url: basePath + 'common/changeMaster.action', params: { to: currentMaster }, callback: function(opt, s, r) { if (s) { b.up('window').close(); } else { alert('切换到原账套失败!'); } } }); } }] }); win.show(); } else { alert('无法创建到账套' + newMaster + '的临时会话!'); } } }); } return; } } if(!panel){ if (title && title.toString().length>4) { showtitle = title.toString().substring(0,4); }else if(title){ showtitle=title; } panel = { title : showtitle, tag : 'iframe', tabConfig:{tooltip:title.toString() + '(' + keyField + "=" + value + ')'}, frame : true, border : false, layout : 'fit', iconCls : 'x-tree-icon-tab-tab', html : '', closable : true, listeners : { close : function(){ main.setActiveTab(main.getActiveTab().id); } } }; openTab(panel, keyField + "=" + value); }else{ main.setActiveTab(panel); } } function openGridUrl(value, keyField, mainField, url, title){ url = basePath + url + '?formCondition=' + keyField + "IS'" + value +"'"+ '&gridCondition=' + mainField + "IS'" + value+"'"; var panel = Ext.getCmp(keyField + "=" + value); var main = parent.Ext.getCmp("content-panel"); var showtitle=''; if(!panel){ if (title && title.toString().length>4) { showtitle = title.toString().substring(0,5); } panel = { title : showtitle, tag : 'iframe', tabConfig:{tooltip:title + '(' + keyField + "=" + value + ')'}, frame : true, border : false, layout : 'fit', iconCls : 'x-tree-icon-tab-tab', html : '', closable : true, listeners : { close : function(){ main.setActiveTab(main.getActiveTab().id); } } }; openTab(panel, keyField + "=" + value); }else{ main.setActiveTab(panel); } } function getSetting(type) { var result = false; Ext.Ajax.request({ url : basePath + 'common/getFieldData.action', async: false, params: { caller: 'Setting', field: 'se_value', condition: 'se_what=\'' + type + '\'' }, method : 'post', callback : function(opt, s, res){ var r = new Ext.decode(res.responseText); if(r.exceptionInfo){ showError(r.exceptionInfo);return; } else if(r.success && r.data){ result = r.data == 'true'; } } }); return result; } function openTable(title, url,caller){ var panel = Ext.getCmp('datalist' + caller); var main = parent.Ext.getCmp("content-panel"); if(!panel){ panel = { title : title, tag : 'iframe', tabConfig:{tooltip: title}, frame : true, border : false, layout : 'fit', iconCls : 'x-tree-icon-tab-tab', html : '', closable : true, listeners : { close : function(){ main.setActiveTab(main.getActiveTab().id); } } }; var p = main.add(panel); main.setActiveTab(p); }else{ main.setActiveTab(panel); } } function downLoadById(id){ Ext.Ajax.request({ method:'POST', params:{ id:id }, url:basePath+'common/downloadbyId.action', callback: function(options,success,response){ } }); } function openTab(panel,id){ var o = (typeof panel == "string" ? panel : id || panel.id); var main = parent.Ext.getCmp("content-panel"); /*var tab = main.getComponent(o); */ if(!main) { main =parent.parent.Ext.getCmp("content-panel"); } var tab = main.getComponent(o); if (tab) { main.setActiveTab(tab); } else if(typeof panel!="string"){ panel.id = o; var p = main.add(panel); main.setActiveTab(p); } } function delSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_del, fn); } function delFailure(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.failure_del, fn); } function delFailure(){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.failure_del); } function updateSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_update, fn); } function updateFailure(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_update, fn); } function updateFailure(){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_update); } function addSuccess(fn){ } function addSuccess(){ } function closeFailure(msg, fn){ } function closeFailure(msg){ } function saveSuccess(fn){ var box = Ext.create('Ext.window.MessageBox', { buttonAlign : 'center', buttons: [{ text: '确定', handler: function(b) { var scope = b.ownerCt.ownerCt; scope.fireEvent('hide', scope, true); } },{ text: '继续添加', handler: function(b) { var scope = b.ownerCt.ownerCt; scope.fireEvent('hide', scope, false); } }], listeners: { hide: function(w, ok) { w.close(); if(typeof ok == 'boolean') { if(ok) fn && fn.call(); else window.location.reload(); } else fn && fn.call(); } } }); box.show({ title : $I18N.common.msg.title_prompt, msg : $I18N.common.msg.success_save, icon : Ext.MessageBox.QUESTION }); } function turnSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_turn, fn); } function saveFaliure(fn){ Ext.Msg.alert($I18N.common.msg.title_warn, $I18N.common.msg.failure_save, fn); } function catchFailure(){ Ext.Msg.alert($I18N.common.msg.title_warn, $I18N.common.msg.failure_catch); } function cleanFailure(){ Ext.Msg.alert($I18N.common.msg.title_warn, $I18N.common.msg.failure_clean); } function saveFailure(){ Ext.Msg.alert($I18N.common.msg.title_warn, $I18N.common.msg.failure_save); } function submitSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_submit, fn); } function resSubmitSuccess(){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_resSubmit); } function bannedSuccess(){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_banned); } function resBannedSuccess(){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_resBanned); } function postSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_post, fn); } function resPostSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_resPost, fn); } function turninSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_turnin, fn); } function submitFailure(fn){ } function submitFailure(){ } function printSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_print, fn); } function catchSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_catch, fn); } function cleanSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_clean, fn); } function printSuccess(){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_print); } function turnBugSuccess(){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_turnbug); } function turnBugFailure(){ Ext.Msg.alert($I18N.common.msg.title_warn, $I18N.common.msg.failure_turnbug); } function auditSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_audit, fn || Ext.emptyFn); } function printFaliure(fn){ Ext.Msg.alert($I18N.common.msg.title_warn, $I18N.common.msg.failure_print, fn); } function resAuditSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_resAudit, fn || Ext.emptyFn); } function accountedSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_accounted, fn || Ext.emptyFn); } function resAccountedSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_resAccounted, fn || Ext.emptyFn); } function printFailure(){ Ext.Msg.alert($I18N.common.msg.title_warn, $I18N.common.msg.print_save); } function endSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_end, fn); } function nullifySuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_nullify, fn); } function endFailure(){ Ext.Msg.alert($I18N.common.msg.title_warn, $I18N.common.msg.failure_end); } function resEndSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_resEnd, fn); } function importSuccess(){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_import); } function checkSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_check, fn || Ext.emptyFn); } function resCheckSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_resCheck, fn || Ext.emptyFn); } function endArSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_endar, fn || Ext.emptyFn); } function attendDataComSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_attendDataCom, fn || Ext.emptyFn); } function cardLogImpSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_cardlogimp, fn || Ext.emptyFn); } function unEndArSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_unendar, fn || Ext.emptyFn); } function turnGSSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_turnGs, fn || Ext.emptyFn); } function turnESSuccess(fn){ Ext.Msg.alert($I18N.common.msg.title_prompt, $I18N.common.msg.success_turnEs, fn || Ext.emptyFn); }