Ext.define('ananas.ModuleOutput',{ alternateClassName : 'MO', singleton : true, baseUrl : '/ananas/', constructor : function(){ var me = this; me.callParent(arguments); me.tpls = {}; Ext.apply(me.tpls,{ 'insertbook' : new Ext.XTemplate( '
', '', '
', { url : function(values){ var url = values.readurl.replace("realRead","innerurl"); if(values.start){ url+="&start="+values.start; } if(values.end){ url+="&end="+values.end; } return url + "&unitid=7719"; } }, { jobid : function(d){ if(d.jobid){ return 'jobid="'+d.jobid+'"'; } return ''; } }, { values : function(values) { values = values || ''; return Ext.encode(values).replace(/\'/, '`'); } } ), 'insertbook-online' : new Ext.XTemplate( '
', '', '
', '
', '
{bookname} - {author}
', '', '
', { url : function(values){ var url = values.readurl.replace("realRead","innerurl"); if(values.start){ url+="&start="+values.start; } if(values.end){ url+="&end="+values.end; } return url + "&unitid=7719"; } }, { jobid : function(d){ if(d.jobid){ return 'jobid="'+d.jobid+'"'; } return ''; } }, { values : function(values) { values = values || ''; return Ext.encode(values).replace(/\'/, '`'); } } ), 'insertvideo-online' : new Ext.XTemplate( '
', '', '
', '
', '', '
', { jobid : function(d){ if(d.jobid){ return 'jobid="'+d.jobid+'"'; } return ''; }, values : function(values) { values = values || ''; return Ext.encode(values).replace(/\'/g, '`'); } } ), 'richvideo' : new Ext.XTemplate( '
', '', '
' ), 'insertvideo' : new Ext.XTemplate( '', '{name}', '{hsize}', '' ), 'insertdoc-online-ppt' : new Ext.XTemplate( '' ), 'insertdoc-online-doc' : new Ext.XTemplate( '' ), 'insertdoc-online-pdf' : new Ext.XTemplate( '' ), 'insertdoc-doc' : new Ext.XTemplate( '', '{name}', '{hsize}', '' ), 'insertdoc-pdf' : new Ext.XTemplate( '', '{name}', '{hsize}', '' ), 'insertdoc-ppt' : new Ext.XTemplate( '', '{name}', '{hsize}', '' ), 'insertcxvideo' : new Ext.XTemplate( '' ), 'insertmooc' : new Ext.XTemplate( '', '', '{label} {name}', '', '', '', '', '{title}', '', '', '', '', '{title}', '', '' ), 'ballchart' : new Ext.XTemplate( '' ), 'insertdoc-online-ppt' : new Ext.XTemplate( '' ), 'erya' : new Ext.XTemplate( '' ), 'work' : new Ext.XTemplate( '
', '', '
', '
', '', '
', { jobid : function(d){ if(d.jobid){ return 'jobid="'+d.jobid+'"'; } return ''; }, values : function(values) { values = values || ''; return Ext.encode(values).replace(/\'/, '`'); } } ), 'realplay': new Ext.XTemplate( '' ), 'insertflash-online': new Ext.XTemplate( '' ), 'insertflash': new Ext.XTemplate( '', '{name}', '{hsize}', '' ), 'insertaudio-online': new Ext.XTemplate( '
', '', '
', '
', '', '
', { jobid : function(d){ if(d.jobid){ return 'jobid="'+d.jobid+'"'; } return ''; } } ), 'questionnaire' : new Ext.XTemplate( '
', '', '
', { values : function(values) { values = values || ''; return Ext.encode(values).replace(/\'/, '`'); } } ) }); }, getTpl : function (module,data,iframe){ var tpl; if(module == 'insertdoc'){ var type = data.type.slice(1); type =type.toLowerCase(); switch(type){ case 'pptx': case 'ppt': type = 'ppt';break; case 'docx': case 'doc': type = 'doc';break; } try { if(iframe.getAttribute('type')=='online'){ tpl = 'insertdoc-online-'+ type; }else{ tpl = 'insertdoc-'+ type; } } catch(e) { tpl = 'insertdoc-online-'+ type; } }else if(module == 'insertvideo'){ try { if(iframe.getAttribute('type')=='online'){ tpl = 'insertvideo-online'; }else{ tpl = 'insertvideo'; } } catch(e) { if (data.jobid) { tpl = 'insertvideo-online'; } else { tpl = 'insertvideo'; } } }else if(module == 'insertbook'){ //ie7 无权限 try { if(iframe.getAttribute('type')=='online'){ tpl = 'insertbook-online'; }else{ tpl = 'insertbook'; } } catch(e) { if (data.jobid) { tpl = 'insertbook-online'; } else { tpl = 'insertbook'; } } }else if(module == 'insertaudio'){ tpl = 'insertaudio-online'; } else if(module == 'insertflash'){ try { if(iframe.getAttribute('type')=='online'){ tpl = 'insertflash-online'; }else{ tpl = 'insertflash'; } } catch(e) { tpl = 'insertflash-online'; } } else { tpl = module; } return this.tpls[tpl]; } }); Ext.define('ananas.JobCounter',{ alternateClassName : 'JC', singleton : true, mixins: { observable: 'Ext.util.Observable' }, jobcounter : 0, attachments : null, constructor: function () { var me = this; me.mixins.observable.constructor.call(me); me.addEvents('completed'); }, completed : function(index){ var me = this; if(me.jobcounter<=0 && !me.attachments){ return; } if(me.attachments[index].job){ me.jobcounter--; me.attachments[index].job = false; //if(me.jobcounter==0){ me.fireEvent('completed'); //} } } }); var $UE = {}; $UE.ajax = function() { var fnStr = 'XMLHttpRequest()'; try { new ActiveXObject("Msxml2.XMLHTTP"); fnStr = 'ActiveXObject(\'Msxml2.XMLHTTP\')'; } catch (e) { try { new ActiveXObject("Microsoft.XMLHTTP"); fnStr = 'ActiveXObject(\'Microsoft.XMLHTTP\')' } catch (e) { } } var creatAjaxRequest = new Function('return new ' + fnStr); function json2str(json) { var strArr = []; for (var i in json) { //忽略默认的几个参数 if(i=="method" || i=="timeout" || i=="async") continue; //传递过来的对象和函数不在提交之列 if (!((typeof json[i]).toLowerCase() == "function" || (typeof json[i]).toLowerCase() == "object")) { strArr.push( encodeURIComponent(i) + "="+encodeURIComponent(json[i]) ); } } return strArr.join("&"); } return { request:function(url, ajaxOptions) { var ajaxRequest = creatAjaxRequest(), //是否超时 timeIsOut = false, //默认参数 defaultAjaxOptions = { method:"POST", timeout:5000, async:true, data:{},//需要传递对象的话只能覆盖 onsuccess:function() { }, onerror:function() { } }; if (typeof url === "object") { ajaxOptions = url; url = ajaxOptions.url; } if (!ajaxRequest || !url) return; var ajaxOpts = ajaxOptions ? Ext.apply(defaultAjaxOptions, ajaxOptions) : defaultAjaxOptions; var submitStr = json2str(ajaxOpts); // { name:"Jim",city:"Beijing" } --> "name=Jim&city=Beijing" //如果用户直接通过data参数传递json对象过来,则也要将此json对象转化为字符串 if (ajaxOpts.data){ submitStr += (submitStr? "&":"") + json2str(ajaxOpts.data); } //超时检测 var timerID = setTimeout(function() { if (ajaxRequest.readyState != 4) { timeIsOut = true; ajaxRequest.abort(); clearTimeout(timerID); } }, ajaxOpts.timeout); var method = ajaxOpts.method.toUpperCase(); var str = url + (url.indexOf("?")==-1?"?":"&") + (method=="POST"?"":submitStr+ "&noCache=" + +new Date); ajaxRequest.open(method, str, ajaxOpts.async); ajaxRequest.onreadystatechange = function() { if (ajaxRequest.readyState == 4) { if (!timeIsOut && ajaxRequest.status == 200) { ajaxOpts.onsuccess(ajaxRequest); } else { ajaxOpts.onerror(ajaxRequest); } } }; if (method == "POST") { ajaxRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); ajaxRequest.send(submitStr); } else { ajaxRequest.send(null); } } }; }(); //by zhanyi function uParse(selector,opt,params){ var unlock = function(){ var p = window; while(p){ if(p.onReadComplete){ if(typeof console == 'object') console.log('call uParse to onReadComplete'); p.onReadComplete(); break; } if(p.parent==p){ break; } p = p.parent; } },jobcounter=0,attachments; window.AttachmentSetting = params; if(params && params.control && params.attachments){ attachments = params.attachments; for(var i=0;i'); return; } if (obj.id && doc.getElementById(obj.id)) { return; } var element = doc.createElement(obj.tag); delete obj.tag; for (var p in obj) { element.setAttribute(p, obj[p]); } element.onload = element.onreadystatechange = function () { if (!this.readyState || /loaded|complete/.test(this.readyState)) { item = getItem(doc,obj); if (item.funs.length > 0) { item.ready = 1; for (var fi; fi = item.funs.pop();) { fi(); } } element.onload = element.onreadystatechange = null; } }; element.onerror = function(){ throw Error('The load '+(obj.href||obj.src)+' fails,check the url'); }; doc.getElementsByTagName("head")[0].appendChild(element); }; }(); //??????????? var defaultOption = { liiconpath : 'http://bs.baidu.com/listicon/', listDefaultPaddingLeft : '20', 'highlightJsUrl':'', 'highlightCssUrl':'', customRule:function(content){} }; if(opt){ for(var p in opt){ defaultOption[p] = opt[p]; } } (function(){ var contents; if(document.querySelectorAll){ contents = document.querySelectorAll(selector); }else{ if(/^#/.test(selector)){ contents = [document.getElementById(selector.replace(/^#/,''))]; }else if(/^\./.test(selector)){ var contents = []; _each(document.getElementsByTagName('*'),function(node){ if(node.className && new RegExp('\\b' + selector.replace(/^\./,'') + '\\b','i').test(node.className)){ contents.push(node); } }); }else{ contents = document.getElementsByTagName(selector); } } _each(contents,function(content){ if(content.tagName.toLowerCase() == 'textarea'){ var tmpNode = document.createElement('div'); if(/^#/.test(selector)){ tmpNode.id = selector.replace(/^#/,''); }else if(/^\./.test(selector)){ tmpNode.className = selector.replace(/^\./,''); } content.parentNode.insertBefore(tmpNode,content); tmpNode.innerHTML = content.value; content.parentNode.removeChild(content); content = tmpNode; } function fillNode(nodes){ _each(nodes,function(node){ if(!node.firstChild){ node.innerHTML = ' '; } }); } function replaceModule(iframes){ var items = []; for(var i=0,len = iframes.length;i'; node.tips = new Tips(node); var filetype = node.title.substring(node.title.lastIndexOf('.')).toLocaleLowerCase(); if ('.txt' == filetype) { node.href = "javascript:void(0)"; } node.onmouseover = function() { if (!node.tips.getContent()) { if (type == 'text') { node.tips.setContent(data); node.tips.show(); } else if (type == 'resource' && data) { $UE.ajax.request('/ananas/status/' + data, { method:"GET", timeout:5000, async:true, onsuccess:function(response) { var oData = eval('(' + response.responseText + ')'); var src = oData.screenshot || oData.download; var aAudio = [".aac", ".ac3", ".aif", ".amr", ".ape", ".flac", ".m4a", ".m4r", ".mka", ".mid", ".mmf", ".mpa", ".mpc", ".ogg", ".pcm", ".mp3", ".ra", ".tta", ".voc", ".wav", ".wv", ".wma"]; var aImg = [".gif", ".jpeg", ".png", ".jpg", ".bmp"]; if ('.txt' == filetype) { $UE.ajax.request('/ananas/file/read?key=' + oData.key + '&url=' + oData.download, { method:"GET", timeout: 1000 * 60 * 5, async:true, onsuccess: function(txtresponse) { var oTxtData = eval('(' + txtresponse.responseText + ')'); node.tips.setContent('
' + oTxtData.con + '
'); }, onerror: function() {} }); return; } var isAudio = false, isImg = false; for (var i = 0, len = aAudio.length; i < len; i++) { if (aImg[i] == filetype) { isImg = true; break; } } for (var i = 0, len = aAudio.length; i < len; i++) { if (aAudio[i] == filetype) { isAudio = true; break; } } var videoBg = ''; if (!isImg) { if (isAudio) { src = '/ananas/css/music.png'; } else { videoBg = '/ananas/css/video.png'; } } var sImg = ''; if (videoBg) { sVideoBg = ''; sImg = ''; sImg = '
' + sVideoBg + sImg + '
'; } else { sImg = ''; } node.tips.setContent(sImg); node.tips.show(); }, onerror:function() { } }); } } else { node.tips.show(); } }; node.onmouseout = function() { node.tips.hide(); }; } }); } function checkList(nodes){ var customCss = [], customStyle = { 'cn' : 'cn-1-', 'cn1' : 'cn-2-', 'cn2' : 'cn-3-', 'num' : 'num-1-', 'num1' : 'num-2-', 'num2' : 'num-3-', 'dash' : 'dash', 'dot' : 'dot' }; _each(nodes,function(list){ if(list.className && /custom_/i.test(list.className)){ var listStyle = list.className.match(/custom_(\w+)/)[1]; if(listStyle == 'dash' || listStyle == 'dot'){ pushItem(customCss,selector +' li.list-' + customStyle[listStyle] + '{background-image:url(' + defaultOption.liiconpath +customStyle[listStyle]+'.gif)}'); pushItem(customCss,selector +' ul.custom_'+listStyle+'{list-style:none;} '+ selector +' ul.custom_'+listStyle+' li{background-position:0 3px;background-repeat:no-repeat}'); }else{ var index = 1; _each(list.childNodes,function(li){ if(li.tagName == 'LI'){ pushItem(customCss,selector + ' li.list-' + customStyle[listStyle] + index + '{background-image:url(' + defaultOption.liiconpath + 'list-'+customStyle[listStyle] +index + '.gif)}'); index++; } }); pushItem(customCss,selector + ' ol.custom_'+listStyle+'{list-style:none;}'+selector+' ol.custom_'+listStyle+' li{background-position:0 3px;background-repeat:no-repeat}'); } switch(listStyle){ case 'cn': pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-1{padding-left:25px}'); pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-2{padding-left:40px}'); pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-3{padding-left:55px}'); break; case 'cn1': pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-1{padding-left:30px}'); pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-2{padding-left:40px}'); pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-3{padding-left:55px}'); break; case 'cn2': pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-1{padding-left:40px}'); pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-2{padding-left:55px}'); pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-3{padding-left:68px}'); break; case 'num': case 'num1': pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-1{padding-left:25px}'); break; case 'num2': pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-1{padding-left:35px}'); pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft-2{padding-left:40px}'); break; case 'dash': pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft{padding-left:35px}'); break; case 'dot': pushItem(customCss,selector + ' li.list-'+listStyle+'-paddingleft{padding-left:20px}'); } } }); customCss.push(selector +' .list-paddingleft-1{padding-left:0}'); customCss.push(selector +' .list-paddingleft-2{padding-left:'+defaultOption.listDefaultPaddingLeft+'px}'); customCss.push(selector +' .list-paddingleft-3{padding-left:'+defaultOption.listDefaultPaddingLeft*2+'px}'); // cssRule('list', selector +' ol,'+selector +' ul{margin:0;padding:0;}li{clear:both;}'+customCss.join('\n'), document); } // var needParseTagName = { 'table' : function(){ cssRule('table', selector +' table.noBorderTable td,'+selector+' table.noBorderTable th,'+selector+' table.noBorderTable caption{border:1px dashed #ddd !important}' + // selector +' table{margin-bottom:10px;border-collapse:collapse;display:table;}' + selector +' td,'+selector+' th{ background:white; padding: 5px 10px;border: 1px solid #DDD;}' + selector +' caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' + selector +' th{border-top:2px solid #BBB;background:#F7F7F7;}' + selector +' td p{margin:0;padding:0;}', document); }, 'ol' : checkList, 'ul' : checkList, /*'pre': function(nodes){ if(typeof XRegExp == "undefined"){ loadFile(document,{ id : "syntaxhighlighter_js", src : defaultOption.highlightJsUrl, tag : "script", type : "text/javascript", defer : "defer" },function(){ _each(nodes,function(pi){ if(/brush/i.test(pi.className)){ SyntaxHighlighter.highlight(pi); var tables = document.getElementsByTagName('table'); for(var t= 0,ti;ti=tables[t++];){ if(/SyntaxHighlighter/i.test(ti.className)){ var tds = ti.getElementsByTagName('td'); for(var i=0,li,ri;li=tds[0].childNodes[i];i++){ ri = tds[1].firstChild.childNodes[i]; if(ri){ ri.style.height = li.style.height = ri.offsetHeight + 'px'; } } } } } }); }); } if(!document.getElementById("syntaxhighlighter_css")){ loadFile(document,{ id : "syntaxhighlighter_css", tag : "link", rel : "stylesheet", type : "text/css", href : defaultOption.highlightCssUrl }); } },*/ 'td':fillNode, 'th':fillNode, 'caption':fillNode, 'iframe':replaceModule, 'blockquote' : addHandler, 'img' : addTray }; for(var tag in needParseTagName){ var nodes = content.getElementsByTagName(tag); if(nodes.length){ needParseTagName[tag](nodes); } } defaultOption.customRule(content); showTips(content); }); })(); }