2) v = 2;
this.scaleTo(v);
o2.UD.putData("documenteditorScale", {"scale": this.scale});
this.documenteditorScale = this.scale;
}.bind(this));
},
fullScreen: function(bt){
var text = bt.node.get("text");
var content = this.form.app.content;
var stopFun = function(e){ e.stopPropagation(); };
if (text===MWF.xApplication.process.Xform.LP.returnScreen){
this.form.node.getParent().show();
this.node.inject(this.positionNode, "before");
this.positionNode.destroy();
// var styles = content.retrieve("tmpStyles");
// content.setStyles({
// "position": styles.position,
// "overflow": styles.overflow
// });
//this.node.setStyles(this.css.returnScreen);
this.node.setStyle("min-height", "");
this.fireEvent("returnScreen");
bt.setText(MWF.xApplication.process.Xform.LP.fullScreen);
// this.fullScreenScrollNode = this.node.getOffsetParent().getFirst().getParentSrcollNode();
// if (this.fullScreenScrollNode){
// if (this.fullScreenScrollResizeToolbarFun) this.fullScreenScrollNode.removeEvent("scroll", this.fullScreenScrollResizeToolbarFun);
// }
//this.node.removeEvent("wheel", stopFun);
this.isFullScreen = false;
this.resizeToolbar();
}else{
// this.positionNode = new Element("div").inject(this.node, "after");
// this.node.inject(content, "top");
// this.form.node.hide();
this.positionNode = new Element("div").inject(this.node, "after");
this.node.inject(this.scrollNode, "top");
this.form.node.getParent().hide();
// var position = content.getStyle("poaition");
// var overflow = content.getStyle("overflow");
// content.store("tmpStyles", {"position": position, "overflow": overflow});
// content.setStyles({
// "position": "relative",
// "overflow": "auto"
// });
//this.node.setStyles(this.css.fullScreen);
this.node.setStyle("min-height", "100%");
this.fireEvent("fullScreen");
// this.fullScreenScrollNode = this.node.getOffsetParent().getFirst().getParentSrcollNode();
// if (this.fullScreenScrollNode){
// this.fullScreenScrollResizeToolbarFun = function(){this.resizeToolbar(this.fullScreenScrollNode);}.bind(this);
// this.fullScreenScrollResizeToolbarFun();
// this.fullScreenScrollNode.addEvent("scroll", this.fullScreenScrollResizeToolbarFun);
// }
bt.setText(MWF.xApplication.process.Xform.LP.returnScreen);
this.isFullScreen = true;
//this.node.addEvent("wheel", stopFun);
this.resizeToolbar();
}
this.reload();
},
/**缩放文件内容
* @param scale{Number} 缩放的比率
* @example
* this.form.get("fieldId").scaleTo(0.5);
*/
scaleTo: function(scale){
this._returnScale();
this.scale = scale;
this.zoom();
//var w = this.contentNode.getSize().x*this.scale;
var w = this.contentNode.offsetWidth*this.scale;
//if (layout.userLayout && layout.userLayout.scale) w = w*layout.userLayout.scale;
var count = 1;
var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
//if (layout.userLayout && layout.userLayout.scale) docPageFullWidth = docPageFullWidth*layout.userLayout.scale;
var pageWidth = count * docPageFullWidth;
var margin = (w-pageWidth)/(count+1);
if (this.isScale){
margin = "10";
}
if (this.scale) margin = margin/this.scale;
if (margin < 10){
var offset = 10-margin;
margin = 10;
this.contentNode.scrollTo(offset, 0);
}
this.pages.each(function(page, i){
page.setStyles({
"float": "left",
"margin-left": ""+margin+"px"
});
});
this.resetNodeSize();
},
_repage: function(delay){
if (this.options.pageShow!=="double"){
this._singlePage();
}else{
this._doublePage();
}
if (delay){
if (!this.form.isLoaded){
this.form.addEvent("afterLoad", this._checkScale.bind(this));
}else{
this._checkScale();
}
}else{
this._checkScale();
}
},
_singlePage: function(){
//if (this.editMode) this._readFiletext();
var scale = this.singlePageZoom || 1;
if( this.singlePageZoom && this.singlePageZoom.toInt() != 1 ){
this.isScale = true;
this.scale = this.singlePageZoom;
this.singlePageZoom = null;
}
this.zoom(scale);
this._checkScale();
var w = this.contentNode.getSize().x;
var count = 1;
var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
//var docPageFullWidth = this.options.docPageFullWidt;
var pageWidth = count * docPageFullWidth;
var margin = (w-pageWidth)/(count+1);
if (this.isScale){
margin = "10";
}
if (this.scale) margin = margin/this.scale;
this.pages.each(function(page, i){
page.setStyles({
"float": "left",
"margin-left": ""+margin+"px"
});
});
this.resetNodeSize();
// this.pages.each(function(page){
// page.setStyle("float", "none");
// });
this.resizeSidebar();
this.options.pageShow="single";
this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.doublePage);
},
resetNodeSize: function(){
//var contentSize = this.contentNode.getSize();
var contentHeight = this.contentNode.offsetHeight;
var toolbarSize = this.toolNode.getSize();
contentHeight = contentHeight*(this.scale || 1);
var h = contentHeight+toolbarSize.y+20;
//h = h - contentSize.y*(1-this.scale);
this.node.setStyles({
"height":""+h+"px"
});
this.resizeSidebar();
},
createWaitSplitPage: function(){
this.node.mask({
"style": {
"background-color": "#cccccc",
"opacity": 0.3
}
});
this.waitSplitPageNode = new Element("div", {"styles": this.form.css.waitSplitPageNode, "text": MWF.xApplication.process.Xform.LP.computePage}).inject(this.node);
this.waitSplitPageNode.position({
"relativeTo": this.node,
"position": "topRight",
"edge": "topRight",
"offset": {
"x": -10,
"y": 45
}
});
//this.form.notice(MWF.xApplication.process.Xform.LP.computePage, "info", this.node);
},
clearWaitSplitPage: function(){
this.node.unmask();
if (this.waitSplitPageNode) this.waitSplitPageNode.destroy();
this.waitSplitPageNode = null;
},
_doublePage: function(){
if (this.editMode) this._switchReadOrEditInline();
if( this.zoomSelectAction ){
this.singlePageZoom = ( this.zoomSelectAction.options[this.zoomSelectAction.selectedIndex].value ).toFloat();
}
this.zoom(1);
this.createWaitSplitPage();
window.setTimeout(function(){
this._checkSplitPage(this.pages[0]);
this.zoom(1);
var w = this.contentNode.getSize().x;
var toPageWidth = (w-100)/2;
scale = toPageWidth/this.options.docPageFullWidth;
if (scale<1) this.zoom(scale);
var docPageFullWidth = (this.scale) ? this.scale*this.options.docPageFullWidth : this.options.docPageFullWidth;
//var docPageFullWidth = this.options.docPageFullWidth;
var w = this.contentNode.getSize().x;
var count = (w/docPageFullWidth).toInt();
var pages = this.contentNode.getElements(".doc_layout_page");
count = Math.min(pages.length, count);
var pageWidth = count * docPageFullWidth;
var margin = (w-pageWidth)/(count+1);
if (this.scale) margin = margin/(this.scale);
this.pages.each(function(page, i){
page.setStyles({
"float": "left",
"margin-left": ""+margin+"px"
});
});
// this.pages.each(function(page, i){
// if ((i % 2)===0){
// page.setStyle("float", "left");
// }else{
// page.setStyle("float", "right");
// }
// });
this.resetNodeSize();
this.options.pageShow="double";
this.doublePageAction.set("text", MWF.xApplication.process.Xform.LP.singlePage);
this.resizeSidebar();
this.clearWaitSplitPage();
}.bind(this), 1000);
},
_getDefaultData: function(){
return Object.clone(this.json.defaultValue);
//return Object.clone(MWF.xApplication.process.Xform.LP.documentEditor);
},
_loadFiletextPage: function(callback){
this.data = this._getBusinessData();
if (!this.data) this.data = this._getDefaultData();
this._computeData(true);
this._createPage(function(control){
this._loadPageLayout(control);
// this.data = this._getBusinessData();
// if (!this.data) this.data = this._getDefaultData();
this.setData(this.data);
// this._checkSplitPage(this.pages[0]);
//this._repage(true);
//this.loadCkeditorFiletext();
if (!this.readonly){
//if (this.json.allowEditFiletext!==false) this.loadCkeditorFiletext();
// if (this.json.allowEditRedheader) this.loadCkeditorRedheader();
// if (this.json.allowEditSubject) this.loadCkeditorSubject();
// if (this.json.allowEditMainSend) this.loadCkeditorMainSend();
// if (this.json.allowEditFileNo) this.loadCkeditorFileNo();
// if (this.json.allowEditSigner) this.loadCkeditorSigner();
// if (this.json.allowEditAttachment) this.loadCkeditorAttachment();
}
if (callback) callback();
}.bind(this));
},
_getEditorConfig: function(){
// var mathElements = [
// 'math',
// 'maction',
// 'maligngroup',
// 'malignmark',
// 'menclose',
// 'merror',
// 'mfenced',
// 'mfrac',
// 'mglyph',
// 'mi',
// 'mlabeledtr',
// 'mlongdiv',
// 'mmultiscripts',
// 'mn',
// 'mo',
// 'mover',
// 'mpadded',
// 'mphantom',
// 'mroot',
// 'mrow',
// 'ms',
// 'mscarries',
// 'mscarry',
// 'msgroup',
// 'msline',
// 'mspace',
// 'msqrt',
// 'msrow',
// 'mstack',
// 'mstyle',
// 'msub',
// 'msup',
// 'msubsup',
// 'mtable',
// 'mtd',
// 'mtext',
// 'mtr',
// 'munder',
// 'munderover',
// 'semantics',
// 'annotation',
// 'annotation-xml'
// ];
//CKEDITOR.plugins.addExternal('ckeditor_wiris', 'https://ckeditor.com/docs/ckeditor4/4.13.0/examples/assets/plugins/ckeditor_wiris/', 'plugin.js');
var editorConfig = {
qtRows: 20, // Count of rows
qtColumns: 20, // Count of columns
qtBorder: '1', // Border of inserted table
qtWidth: '95%', // Width of inserted table
qtStyle: { 'border-collapse' : 'collapse' },
qtClass: 'documenteditor_table'+this.form.json.id+this.json.id, // Class of table
qtCellPadding: '0', // Cell padding table
qtCellSpacing: '0', // Cell spacing table
qtPreviewBorder: '4px double black', // preview table border
qtPreviewSize: '4px', // Preview table cell size
qtPreviewBackground: '#c8def4', // preview table background (hover)
language: o2.language,
// format_tags: '标题一;标题二;标题三;标题四;正文', // entries is displayed in "Paragraph format"
format_tags: '标题一;标题二;正文(标题三,四)', // entries is displayed in "Paragraph format"
'format_标题一': {
name: '标题一(三号黑体)',
element: 'div',
styles: {
'font-family': '黑体',
'font-size': '16pt'
}
},
'format_标题二': {
name: '标题二(三号楷体)',
element: 'div',
styles: {
'font-family': '楷体',
'font-size': '16pt'
}
},
// 'format_标题三': {
// name: '标题三',
// element: 'div',
// styles: {
// 'font-family': '仿宋',
// 'font-size': '16pt'
// }
// },
// 'format_标题四': {
// name: '标题四',
// element: 'div',
// styles: {
// 'font-family': '仿宋',
// 'font-size': '16pt'
// }
// },
'format_正文(标题三,四)': {
name: '正文(标题三,四)',
element: 'div',
styles: {
'font-family': '仿宋',
'font-size': '16pt'
}
}
};
editorConfig.toolbarGroups = [
{ name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker', 'editing' ] },
{ name: 'forms', groups: [ 'forms' ] },
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi', 'paragraph' ] },
{ name: 'links', groups: [ 'links' ] },
{ name: 'insert', groups: [ 'insert' ] },
{ name: 'styles', groups: [ 'styles' ] },
{ name: 'colors', groups: [ 'colors' ] },
{ name: 'tools', groups: [ 'tools' ] },
{ name: 'others', groups: [ 'others' ] },
{ name: 'about', groups: [ 'about' ] }
];
//editorConfig.extraPlugins = "ecnet,colordialog,tableresize,quicktable,mathjax,ckeditor_wiris";
//editorConfig.extraPlugins = "ecnet,colordialog,quicktable,tableresize,eqneditor";
//editorConfig.extraPlugins = "tableresize,quicktable";
editorConfig.extraPlugins = "quicktable,tableresize";
//editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML',
//editorConfig.removeButtons = 'NumberedList,Source,Save,NewPage,Preview,Print,Templates,Paste,PasteFromWord,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Bold,Italic,Underline,Strike,Subscript,Superscript,CopyFormatting,RemoveFormat,BulletedList,Outdent,Indent,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Link,Unlink,Anchor,Image,Flash,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,TextColor,BGColor,Maximize,ShowBlocks,About,Styles,Font,FontSize';
//editorConfig.removeButtons = 'Source,Save,NewPage,Preview,Print,Templates,Paste,PasteFromWord,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Bold,Italic,Underline,Strike,Subscript,Superscript,CopyFormatting,RemoveFormat,Outdent,Indent,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Link,Unlink,Anchor,Image,Flash,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,TextColor,BGColor,Maximize,ShowBlocks,About,Styles,Font,FontSize';
editorConfig.removeButtons = 'Source,Save,NewPage,Preview,Print,Templates,Paste,PasteFromWord,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Bold,Italic,Underline,Strike,Subscript,Superscript,CopyFormatting,RemoveFormat,Outdent,Indent,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Link,Unlink,Anchor,Flash,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,TextColor,BGColor,Maximize,ShowBlocks,About,Styles,Font,FontSize';
//editorConfig.extraAllowedContent = mathElements.join(' ') + '(*)[*]{*};img[data-mathml,data-custom-editor,role](Wirisformula)';
editorConfig.pasteFromWordRemoveFontStyles = false;
editorConfig.pasteFromWordRemoveStyles = false;
//editorConfig.removeButtons = 'NewPage,Templates,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,Bold,Italic,Underline,Strike,Subscript,Superscript,Blockquote,CreateDiv,BidiLtr,BidiRtl,Language,Link,Unlink,Anchor,Image,Flash,HorizontalRule,Smiley,SpecialChar,Iframe,Styles,Font,FontSize,TextColor,BGColor,ShowBlocks,About';
editorConfig.removePlugins = ['magicline'];
editorConfig.enterMode = CKEDITOR.ENTER_DIV;
editorConfig.pasteFilter = "plain-text";
// editorConfig.extraPlugins = ['ecnet','mathjax'];
// editorConfig.removePlugins = ['magicline'];
// editorConfig.mathJaxLib = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js?config=TeX-AMS_HTML';
return editorConfig;
},
_checkSplitPage: function(pageNode){
if (this.layout_edition) this.layout_edition.setStyles({ "position": "static"});
var contentNode = pageNode.getFirst();
if (contentNode.getSize().y>this.options.docPageHeight){
this._splitPage(pageNode);
}
var i = pageNode.get("data-pagecount").toInt();
if (i && this.pages.length-1>=i){
this._checkSplitPage(this.pages[i]);
}
if (this.layout_edition) this.layout_edition.setStyles({ "position": "absolute", "bottom": "0px" });
},
_splitFiletextNodeOneWord:function(lnode, nextPageNode){
var text = lnode.textContent;
var len = text.length;
var left = text.substring(0, len-1);
var right = text.substring(len-1, len);
lnode.textContent = left;
nextPageNode.textContent = right+nextPageNode.textContent;
//nextPageNode.appendText(right, "top");
},
_splitFiletext: function(node, nextPageNode, nextFiletextNode, pageNode){
var contentNode = pageNode.getFirst();
var lnode = node.lastChild;
if (!lnode){
if (node.parentNode) node.parentNode.removeChild(node);
//node.remove();
}else{
while (contentNode.getSize().y>this.options.docPageHeight && lnode) {
var tmpnode = lnode.previousSibling;
var nodeType = lnode.nodeType;
if (!nextPageNode) nextPageNode = nextFiletextNode;
if (nodeType == Node.ELEMENT_NODE) {
if (lnode.tagName == "table") {
lnode.inject(nextPageNode);
} else if (lnode.tagName == "BR") {
if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
} else {
var id = lnode.get("data-pagePart");
if (!id){
id = (new o2.widget.UUID()).toString();
lnode.set("data-pagePart", id);
}
var tmpNode = nextPageNode.getFirst();
if (tmpNode && tmpNode.get("data-pagePart")==id){
nextPageNode = tmpNode;
}else{
nextPageNode = lnode.clone(false).inject(nextPageNode, "top");
}
//var subnode = lnode.getLast();
this._splitFiletext(lnode, nextPageNode, nextFiletextNode, pageNode);
if (!lnode.firstChild) if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
nextPageNode = nextPageNode.getParent();
}
} else if (nodeType == Node.TEXT_NODE) {
var nextPageTextNode = nextPageNode.insertBefore(document.createTextNode(""), nextPageNode.firstChild);
while ((contentNode.getSize().y > this.options.docPageHeight) && lnode.textContent) {
//console.log(contentNode.getSize().y);
this._splitFiletextNodeOneWord(lnode, nextPageTextNode)
}
if (!lnode.textContent) if (lnode.parentNode) lnode.parentNode.removeChild(lnode); //lnode.remove();
} else {
//lnode.remove();
if (lnode.parentNode) lnode.parentNode.removeChild(lnode);
}
lnode = tmpnode;
}
if (!node.lastChild) if (node.parentNode) node.parentNode.removeChild(node); //node.remove();
}
//this._checkSplitPage(pageNode);
},
_splitPage: function(pageNode){
var contentNode = pageNode.getFirst();
var blockNodes = pageNode.getElements(".doc_block");
if (blockNodes.length){
var blockNode = blockNodes[blockNodes.length-1];
var idx = this.pages.indexOf(pageNode);
if (this.pages.length<=idx+1) this._createNewPage();
var nextPage = this.pages[idx+1];
if (blockNode.hasClass("doc_layout_filetext")){
var filetextNode = nextPage.getElement(".doc_layout_filetext");
if (!filetextNode){
filetextNode = new Element("div.doc_layout_filetext").inject(nextPage.getFirst(), "top");
//filetextNode.setAttribute('contenteditable', true);
}
if (!filetextNode.hasClass("doc_block"))filetextNode.addClass("doc_block");
//var nextEditor = filetextNode.retrieve("editor");
var node = blockNode;
var nextPageNode = filetextNode;
this._splitFiletext(node, nextPageNode, filetextNode, pageNode);
}else{
blockNode.inject(nextPage.getFirst(), "top");
//var contentNode = pageNode.getFirst();
if (contentNode.getSize().y>this.options.docPageHeight){
this._splitPage(pageNode);
}
}
}
},
transWidth: function(node){
if (!node) return '';
while (node){
if (node.nodeType==3){
node.nodeValue = node.nodeValue.replace(/\x20/g, " ");
}else if (node.nodeType==8){
//nothing
}else{
this.transWidth(node.firstChild);
}
node = node.nextSibling;
}
},
insertFullWidth: function(node, txt){
if (!node) return '';
while (node){
if (node.nodeType==3){
node.nodeValue = txt+node.nodeValue;
return true;
}else if (node.nodeType==8){
//nothing
}else{
var flag = this.insertFullWidth(node.firstChild, txt);
if (flag) return true;
}
node = node.nextSibling;
}
},
loadCkeditorFiletext: function(callback, inline){
if (this.layout_filetext){
o2.load("../o2_lib/htmleditor/ckeditor4130/ckeditor.js", function(){
CKEDITOR.disableAutoInline = true;
this.layout_filetext.setAttribute('contenteditable', true);
if (inline){
this.filetextEditor = CKEDITOR.inline(this.layout_filetext, this._getEditorConfig());
}else{
this.filetextEditor = CKEDITOR.replace(this.layout_filetext, this._getEditorConfig());
}
this.filetextEditor.on("instanceReady", function(e){
if (callback) callback(e);
}.bind(this));
this.filetextEditor.on( 'focus', function( e ) {
window.setTimeout(this.reLocationFiletextToolbar.bind(this), 10);
}.bind(this) );
this.filetextEditor.on( 'loaded', function( e ) {
this.filetextEditor.element.$.store("module", this);
this.filetextEditor.element.$.store("scale", this.scale);
}.bind(this) );
this.filetextEditor.on( 'afterPaste', function( e ) {
debugger;
}.bind(this));
this.filetextEditor.on( 'afterPasteFromWord', function( e ) {
debugger;
}.bind(this));
this.filetextEditor.on( 'paste', function( e ) {
debugger;
var html = e.data.dataValue;
//if (this.json.fullWidth=="y") html = html.replace(/\x20/g, " ");
var rexbr = /\
|\
|\
/g;
var rexp = /\/g;
if (rexbr.test(html) && !rexp.test(html)){
var ps = html.split(/\
|\
|\
/g);
html = "";
ps.each(function(p){
html = html + "
"+p+"
";
});
}
var tmp = new Element("div")
tmp.set("html", html);
var pList = tmp.getElements("p");
pList.each(function(p, i){
//if (Browser.name=="ie"){
if (this.json.fullWidth!=="n") this.transWidth(p);
if (!p.getParent("table")){
var text = p.get("text");
var rex = /^\u3000*/;
var m = text.match(rex);
var l = (m[0]) ? Math.max((2-m[0].length), 0): 2;
var txt = "";
// for (var i=0; iw){
table.setStyle("width", ""+w+"px");
}
});
tableList.setStyles({
"margin-left": "",
"margin-right": "",
"word-break": "break-all"
});
}
var tdList = tmp.getElements("td");
tdList.each(function(td){
var tbw_top = td.getStyle("border-top-width").toFloat() || 0;
var tbw_bottom = td.getStyle("border-bottom-width").toFloat() || 0;
var tbw_left = td.getStyle("border-left-width").toFloat() || 0;
var tbw_right = td.getStyle("border-right-width").toFloat() || 0;
td.setStyles({
"border-top-width": (tbw_top/2)+"px",
"border-bottom-width": (tbw_bottom/2)+"px",
"border-left-width": (tbw_left/2)+"px",
"border-right-width": (tbw_right/2)+"px",
});
});
e.data.dataValue = tmp.get("html");
tmp.destroy();
this.fireEvent("paste");
}.bind(this) );
this.filetextEditor.on( 'afterPaste', function( e ) {
this.resetNodeSize();
this.fireEvent("afterPaste");
}.bind(this) );
this.filetextEditor.on( 'change', function( e ) {
this.filetextEditor.on( 'change', function( e ) {
var h = document.documentElement.scrollTop;
var scrollNode = this.contentNode;
while (scrollNode && (scrollNode.getScrollSize().y<=scrollNode.getSize().y || (scrollNode.getStyle("overflow")!=="auto" && scrollNode.getStyle("4-y")!=="auto"))){
scrollNode = scrollNode.getParent();
}
if (scrollNode){
var top = scrollNode.scrollTop.toFloat();
scrollNode.scrollTop = h+top;
}
document.documentElement.scrollTop = 0;
}.bind(this) );
}.bind(this) );
this.filetextEditor.on( 'insertElement', function( e ) {
if (e.data.$.tagName.toString().toLowerCase()=="table"){
e.data.$.setStyles({
"margin-left": "",
"margin-right": "",
"word-break": "break-all"
});
}
var tr = e.data.$.getElement("tr");
if (tr){
var tds = tr.getElements("td");
if (tds && tds.length){
var p = 100/tds.length;
tds.setStyle("width", ""+p+"%");
}
}
}.bind(this) );
if (this.json.textIndent!=="n"){
this.layout_filetext.addEvent("keyup", function(ev){
if (ev.code==13) this.filetextEditor.insertText(" ");
}.bind(this));
}
if (this.json.fullWidth!=="n"){
this.filetextEditor.addCommand( 'insertHalfSpace', {
exec: function( editor ) {
editor.insertText(" ");
}
} );
this.filetextEditor.setKeystroke( CKEDITOR.SHIFT + 32, 'insertHalfSpace' );
this.filetextEditor.on("key", function(e){
if (this.json.fullWidth!=="n") if (e.data.keyCode==32){
e.editor.insertText(" ");
e.cancel();
}
}.bind(this));
}
}.bind(this));
}
},
_loadEvents: function(editorConfig){
Object.each(this.json.events, function(e, key){
if (e.code){
this.editor.on(key, function(event){
return this.form.Macro.fire(e.code, this, event);
}.bind(this), this);
}
}.bind(this));
},
_bindFieldChange: function(name,dataItem, dom){
var field = this.form.all[this.json[dataItem]];
if (field){
var bindFun = function(){
this._computeItemFieldData(name, dataItem);
//if (this.data[name]){
if (this[dom]){
if (dom=="layout_redHeader" ||dom=="layout_issuanceUnit" || dom=="layout_meetingAttendContent" || dom=="layout_meetingLeaveContent" || dom=="layout_meetingSitContent" || dom=="layout_meetingRecordContent" || dom=="layout_signer") {
this[dom].set("html", this.data[name] || "");
}else if (dom=="layout_subject"){
this[dom].set("html", (this.data[name] || ""));
}else if (dom=="layout_attachment"){
this.setAttachmentData();
}else if (dom=="layout_annotation"){
var annotation = this.data[name];
if (annotation){
if (annotation.substring(0, 1)!=="(") annotation = "("+annotation;
if (annotation.substring(annotation.length-1, annotation.length)!==")") annotation = annotation+")";
this[dom].set("text", annotation);
}else{
this[dom].set("text", " ");
}
}else{
this[dom].set("text", this.data[name]|| "");
}
}
this.reSetShow();
//}
}.bind(this);
field.node.store(this.json.id+"bindFun", bindFun);
field.addModuleEvent("change", bindFun);
}
},
_computeItemFieldData: function(name, dataItem, dataItemNode){
var v = "";
var module = (dataItemNode) ? this.form.all[dataItemNode] : this.form.all[this.json[dataItem]];
if (module && module.getData) v = module.getData();
if (!v) v = (dataItemNode) ? this.form.businessData.data[dataItemNode] : this.form.businessData.data[this.json[dataItem]];
if (v){
var t = o2.typeOf(v);
switch (t) {
case "string":
switch (name) {
case "issuanceDate":
case "editionDate":
var d = new Date(v);
if (d.isValid() && d.getFullYear()!=1970){
var y = d.getFullYear();
var m = d.getMonth();
var day = d.getDate();
m = m +1;
var lp = MWF.xApplication.process.Xform.LP;
this.data[name] = ""+y+lp.year+m+lp.month+day+lp.date;
}else{
this.data[name] = v;
}
//this.data[name] = (new Date(v).isValid()) ? Date.parse(v).format("%Y年%m月%d%日") : v;
break;
case "mainSend":
this.data[name] = v + ":";
break;
default:
if (name==="subject") v = o2.txt(v);
this.data[name] = v;
}
break;
case "array":
var strs = [];
var strLength = 0;
v.each(function(value){
if (o2.typeOf(value)=="object" && value.distinguishedName){
if (value.name.length>strLength) strLength = value.name.length;
strs.push(value.name);
}else{
if (value.length>strLength) strLength = value.length;
strs.push(value.toString());
}
});
//if (strs.length){
switch (name) {
case "attachment":
// this.data[name] = strs.map(function(n, i){ var j = i+1; return j+"、"+n}).join("
");
var atts = strs.map(function(a){
return (a.indexOf(".")!=-1) ? a.substring(0, a.lastIndexOf(".")) : a;
});
this.data[name] = atts;
break;
case "issuanceDate":
case "editionDate":
var tmpStrs = strs.map(function(n, i){
var d = Date.parse(n);
if (d.isValid() && d.getFullYear()!=1970){
var y = d.getFullYear();
var m = d.getMonth();
var day = d.getDate();
m = m +1;
var lp = MWF.xApplication.process.Xform.LP;
return ""+y+lp.year+m+lp.month+day+lp.date;
}else{
return n;
}
//return () ? d.format("%Y年%m月%d日") : n;
});
this.data[name] = tmpStrs.join(",");
break;
case "signer":
var signers = "";
strs.each(function(name, i){
while (name.length";
}
});
this.data[name] = signers;
break;
case "mainSend":
this.data[name] = strs.join(",") + ":";
break;
default:
this.data[name] = strs.join(",");
}
//}
break;
default:
this.data[name] = v.toString();
}
}else{
this.data[name] = this.json.defaultValue[name];
}
},
computeData: function(){
this._computeData(false);
this.setData(this.data);
},
_computeItemData: function(name, typeItem, dataItem, scriptItem, ev, dom){
switch (this.json[typeItem]) {
case "data":
if (this.json[dataItem]){
if (ev) this._bindFieldChange(name, dataItem, dom);
this._computeItemFieldData(name, dataItem);
}
break;
case "script":
if (this.json[scriptItem] && this.json[scriptItem].code){
var v = this.form.Macro.exec(this.json[scriptItem].code, this);
this.data[name] = v;
if (name=="attachment"){
//this.data[name] = (typeOf(v)=="array") ? v.map(function(n, i){ var j = i+1; return j+"、"+n}).join("
") : v;
this.data[name] = (typeOf(v)=="array") ? v : [v];
}
if (name=="issuanceDate" || name=="editionDate"){
var d = Date.parse(v);
if (d.isValid() && d.getFullYear()!=1970){
var y = d.getFullYear();
var m = d.getMonth();
var day = d.getDate();
m = m +1;
var lp = MWF.xApplication.process.Xform.LP;
this.data[name] = ""+y+lp.year+m+lp.month+day+lp.date;
}else{
this.data[name] = v;
}
//this.data[name] = (d.isValid() && d.getFullYear()!=1970) ? d.format("%Y年%m月%d日") : v;
}
}
break;
}
},
_computeCustomItemData: function(name, field, ev){
//if (this.json.customFields[l.name]){
if (ev) this._bindCustomFieldChange(name, field, name);
this._computeItemFieldData(name, null, field);
//}
},
_bindCustomFieldChange: function(name, dataItem, dom){
var field = this.form.all[dataItem];
if (field){
var bindFun = function(){
this._computeItemFieldData(name, null, dataItem);
//if (this.data[name]){
if (this[dom]){
var value = this.data[name] || "";
var reg = new RegExp("\n","g");
var text = value.replace(reg,"
");
if (dom=="layout_redHeader" || dom=="layout_issuanceUnit") {
this[dom].set("html", this.data[name] || "");
}else if (dom=="layout_subject"){
this[dom].set("html", (this.data[name] || ""));
}else if (dom=="layout_attachment"){
this.setAttachmentData();
}else{
this[dom].set("html", text|| "");
}
}
this.reSetShow();
//}
}.bind(this);
field.node.store(this.json.id+"bindFun", bindFun);
field.addModuleEvent("change", bindFun);
}
},
_computeData: function(ev){
this._computeItemData("copies", "copiesValueType", "copiesValueData", "copiesValueScript", ev, "layout_copies");
this._computeItemData("secret", "secretValueType", "secretValueData", "secretValueScript", ev, "layout_secret");
this._computeItemData("priority", "priorityValueType", "priorityValueData", "priorityValueScript", ev, "layout_priority");
this._computeItemData("redHeader", "redHeaderValueType", "redHeaderValueData", "redHeaderValueScript", ev, "layout_redHeader");
this._computeItemData("fileno", "filenoValueType", "filenoValueData", "filenoValueScript", ev, "layout_fileno");
this._computeItemData("signer", "signerValueType", "signerValueData", "signerValueScript", ev, "layout_signer");
this._computeItemData("subject", "subjectValueType", "subjectValueData", "subjectValueScript", ev, "layout_subject");
this._computeItemData("mainSend", "mainSendValueType", "mainSendValueData", "mainSendValueScript", ev, "layout_mainSend");
this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", ev, "layout_attachment");
this._computeItemData("issuanceUnit", "issuanceUnitValueType", "issuanceUnitValueData", "issuanceUnitValueScript", ev, "layout_issuanceUnit");
this._computeItemData("issuanceDate", "issuanceDateValueType", "issuanceDateValueData", "issuanceDateValueScript", ev, "layout_issuanceDate");
this._computeItemData("annotation", "annotationValueType", "annotationValueData", "annotationValueScript", ev, "layout_annotation");
this._computeItemData("copyto", "copytoValueType", "copytoValueData", "copytoValueScript", ev, "layout_copytoContent");
this._computeItemData("copyto2", "copyto2ValueType", "copyto2ValueData", "copyto2ValueScript", ev, "layout_copyto2Content");
this._computeItemData("editionUnit", "editionUnitValueType", "editionUnitValueData", "editionUnitValueScript", ev, "layout_edition_issuance_unit");
this._computeItemData("editionDate", "editionDateValueType", "editionDateValueData", "editionDateValueScript", ev, "layout_edition_issuance_date");
this._computeItemData("meetingAttend", "meetingAttendValueType", "meetingAttendValueData", "meetingAttendValueScript", ev, "layout_meetingAttendContent");
this._computeItemData("meetingLeave", "meetingLeaveValueType", "meetingLeaveValueData", "meetingLeaveValueScript", ev, "layout_meetingLeaveContent");
this._computeItemData("meetingSit", "meetingSitValueType", "meetingSitValueData", "meetingSitValueScript", ev, "layout_meetingSitContent");
this._computeItemData("meetingRecord", "meetingRecordValueType", "meetingRecordValueData", "meetingRecordValueScript", ev, "layout_meetingRecordContent");
Object.each(this.json.customFields, function(field, k){
this._computeCustomItemData(k, field, ev);
}.bind(this));
// if (this.customLayouts){
// this.customLayouts.each(function(l){
// this._computeCustomItemData(l, ev);
// }.bind(this))
// }
},
_loadValue: function(){
var data = this._getBusinessData();
},
/**重新计算公文编辑器的所有字段,当字段是脚本时可以使用该方法立即更新
* @summary 重新计算公文编辑器的所有字段
* @example
* this.form.get("fieldId").reload();
*/
reload: function(){
this.resetData();
},
resetData: function(diffFiletext){
if (this.editMode){ this._switchReadOrEditInline(); }
this._computeData(false);
this.pages = [];
this.contentNode.empty();
if (this.allowEdit) this.toolbar.childrenButton[0].setText((layout.mobile) ? MWF.xApplication.process.Xform.LP.editdoc_mobile : MWF.xApplication.process.Xform.LP.editdoc);
this.editMode = false;
this._createPage(function(control){
this._loadPageLayout(control);
this.setData(this.data, diffFiletext);
//this._checkSplitPage(this.pages[0]);
this._repage();
}.bind(this));
},
/**
* @summary 判断公文编辑器的正文内容是否已经填写
* @return {Boolean} 是否为空
* @example
* if( this.form.get("fieldId").isEmpty() ){
* this.form.notice('请填写正文内容')
* }
*/
isEmpty: function(){
var data = this.getData();
if( typeOf(data) !== "object" )return true;
return !data.filetext || data.filetext===this.json.defaultValue.filetext;
},
/**
* @summary 获取公文编辑器数据
* @return {Object} 公文编辑器的数据
* @example
* var data = this.form.get("fieldId").getData();
*/
getData: function(){
//if (this.editMode){
if (this.layout_copies) this.data.copies = this.layout_copies.get("text");
if (this.layout_secret) this.data.secret = this.layout_secret.get("text");
if (this.layout_priority) this.data.priority = this.layout_priority.get("text");
if (this.layout_redHeader) this.data.redHeader = this.layout_redHeader.get("html");
if (this.layout_fileno) this.data.fileno = this.layout_fileno.get("text");
if (this.layout_signerTitle) this.data.signerTitle = this.layout_signerTitle.get("text");
if (this.layout_signer) this.data.signer = this.layout_signer.get("html");
if (this.layout_subject) this.data.subject = this.layout_subject.get("html");
if (this.layout_mainSend) this.data.mainSend = this.layout_mainSend.get("text");
if (this.editMode) if (this.layout_filetext){
var text = this.layout_filetext.get("text");
text = text.replace(/\u3000*/g, "");
if (text && text !==this.json.defaultValue.filetext){
this.data.filetext = this.layout_filetext.get("html");
}else{
this.data.filetext = "";
}
}
if (this.layout_signer) this.data.signer = this.layout_signer.get("html");
if (this.layout_attachmentTitle) this.data.attachmentTitle = this.layout_attachmentTitle.get("text");
if (this.layout_attachment){
this._computeItemData("attachment", "attachmentValueType", "attachmentValueData", "attachmentValueScript", false, "layout_attachment");
// var atts = [];
// var nodes = this.layout_attachment.getElements(".doc_layout_attachment_content_name");
// if (nodes.length){
// nodes.each(function(node){
// atts.push(node.get("text"));
// });
// }
// this.data.attachment = atts;
}
if (this.layout_issuanceUnit) this.data.issuanceUnit = this.layout_issuanceUnit.get("html");
if (this.layout_issuanceDate) this.data.issuanceDate = this.layout_issuanceDate.get("text");
if (this.layout_annotation){
var annotation = this.layout_annotation.get("text");
if (annotation.substring(0,1)=="(") annotation = annotation.substring(1, annotation.length);
if (annotation.substring(annotation.length-1, annotation.length)==")") annotation = annotation.substring(0, annotation.length-1);
this.data.annotation = annotation;
}
if (this.layout_copytoTitle) this.data.copytoTitle = this.layout_copytoTitle.get("text");
if (this.layout_copytoContent) this.data.copyto = this.layout_copytoContent.get("text");
if (this.layout_copyto2Title) this.data.copyto2Title = this.layout_copyto2Title.get("text");
if (this.layout_copyto2Content) this.data.copyto2 = this.layout_copyto2Content.get("text");
if (this.layout_edition_issuance_unit) this.data.editionUnit = this.layout_edition_issuance_unit.get("text");
if (this.layout_edition_issuance_date) this.data.editionDate = this.layout_edition_issuance_date.get("text");
if (this.layout_meetingAttendTitle) this.data.meetingAttendTitle = this.layout_meetingAttendTitle.get("text");
if (this.layout_meetingLeaveTitle) this.data.meetingLeaveTitle = this.layout_meetingLeaveTitle.get("text");
if (this.layout_meetingSitTitle) this.data.meetingSitTitle = this.layout_meetingSitTitle.get("text");
if (this.layout_meetingAttendContent) this.data.meetingAttend = this.layout_meetingAttendContent.get("html");
if (this.layout_meetingLeaveContent) this.data.meetingLeave = this.layout_meetingLeaveContent.get("html");
if (this.layout_meetingSitContent) this.data.meetingSit = this.layout_meetingSitContent.get("html");
if (this.layout_meetingRecordContent) this.data.meetingRecord = this.layout_meetingRecordContent.get("html");
this.getSealData();
if (this.customLayouts){
this.customLayouts.each(function(l){
this.data[l.name] = l.node.get("html");
}.bind(this))
}
//}
return this.data;
},
getSealData: function(){
if (this.layout_seals && this.layout_seals.length) {
this.data.seals = [];
this.layout_seals.each(function(seal){
this.data.seals.push(seal.get("src"));
}.bind(this));
}
},
setAttachmentData: function(){
if (!this.attachmentTemplete){
this.attachmentTemplete = this.layout_attachment.get("html");
}
this.layout_attachment.empty();
if (this.data.attachment && this.data.attachment.length && this.data.attachment.each){
//var tmpdiv = new Element("div", {"styles": {"display":"none"}}).inject(document.body);
var tmpdiv = new Element("div");
this.data.attachment.each(function(name, idx){
tmpdiv.set("html", this.attachmentTemplete);
var serialNode = tmpdiv.getElement(".doc_layout_attachment_content_serial");
var nameNode = tmpdiv.getElement(".doc_layout_attachment_content_name");
if (serialNode) serialNode.set("text", idx+1);
if (nameNode) nameNode.set("text", name);
var html = tmpdiv.get("html");
tmpdiv.empty();
this.layout_attachment.appendHTML(html);
}.bind(this));
tmpdiv.destroy();
}
},
/**设置公文编辑器数据
* @param {Object} data
* @example
* var data = this.form.get("fieldId").getData();
* data.filetext = "测试内容";
* this.form.get("fieldId").setData(data);
*/
setData: function(data, diffFiletext){
if (data){
this.data = data;
// this.data["$json"] = this.json;
this._setBusinessData(data);
if (this.layout_copies){
if (data.copies){
this.layout_copies.set("text", data.copies || " ");
}else{
this.layout_copies.set("html", " ");
}
}
if (this.layout_secret){
if (data.secret){
this.layout_secret.set("text", data.secret || " ");
}else{
this.layout_secret.set("html", " ");
}
}
if (this.layout_priority){
if (data.priority){
this.layout_priority.set("text", data.priority || " ");
}else{
this.layout_priority.set("html", " ");
}
}
if (this.layout_redHeader) this.layout_redHeader.set("html", data.redHeader || "");
if (this.layout_fileno) this.layout_fileno.set("text", data.fileno || " ");
if (this.layout_signerTitle) this.layout_signerTitle.set("text", data.signerTitle || " ");
if (this.layout_signer) this.layout_signer.set("html", data.signer || " ");
if (this.layout_subject) this.layout_subject.set("html", data.subject || " ");
if (this.layout_mainSend) this.layout_mainSend.set("text", data.mainSend || " ");
if (diffFiletext) {
this.layout_filetext.set("html", diffFiletext);
}else if (this.layout_filetext){
//this.layout_filetext.set("placeholder", this.json.defaultValue.filetext);
this.layout_filetext.set("html", data.filetext || " ");
var tableList = this.layout_filetext.getElements("table");
if (tableList && tableList.length){
// var w = this.layout_filetext.offsetWidth;
// tableList.setStyle("width", ""+w+"px");
tableList.setStyles({
"margin-left": "",
"margin-right": "",
"word-break": "break-all"
});
}
}
if (this.layout_signer) this.layout_signer.set("html", data.signer || "");
if (this.layout_attachmentTitle) this.layout_attachmentTitle.set("text", data.attachmentTitle || " ");
if (this.layout_attachment){
this.setAttachmentData();
}
if (this.layout_issuanceUnit) this.layout_issuanceUnit.set("html", data.issuanceUnit || " ");
if (this.layout_issuanceDate) this.layout_issuanceDate.set("text", data.issuanceDate || " ");
if (this.layout_annotation){
var annotation = data.annotation;
if (annotation){
if (annotation.substring(0, 1)!=="(") annotation = "("+annotation;
if (annotation.substring(annotation.length-1, annotation.length)!==")") annotation = annotation+")";
this.layout_annotation.set("text", annotation);
}else{
this.layout_annotation.set("text", " ");
}
}
if (this.layout_copytoTitle) this.layout_copytoTitle.set("text", data.copytoTitle || " ");
if (this.layout_copytoContent) this.layout_copytoContent.set("text", data.copyto || " ");
if (this.layout_copyto2Title) this.layout_copyto2Title.set("text", data.copyto2Title || " ");
if (this.layout_copyto2Content) this.layout_copyto2Content.set("text", data.copyto2 || " ");
if (this.layout_edition_issuance_unit) this.layout_edition_issuance_unit.set("text", data.editionUnit || " ");
if (this.layout_edition_issuance_date) this.layout_edition_issuance_date.set("text", data.editionDate || " ");
if (this.layout_meetingAttendTitle) this.layout_meetingAttendTitle.set("text", data.meetingAttendTitle || this.json.defaultValue.meetingAttendTitle || " ");
if (this.layout_meetingLeaveTitle) this.layout_meetingLeaveTitle.set("text", data.meetingLeaveTitle || this.json.defaultValue.meetingLeaveTitle || " ");
if (this.layout_meetingSitTitle) this.layout_meetingSitTitle.set("text", data.meetingSitTitle || this.json.defaultValue.meetingSitTitle || " ");
if (this.layout_meetingAttendContent) this.layout_meetingAttendContent.set("html", data.meetingAttend || " ");
if (this.layout_meetingLeaveContent) this.layout_meetingLeaveContent.set("html", data.meetingLeave || " ");
if (this.layout_meetingSitContent) this.layout_meetingSitContent.set("html", data.meetingSit || " ");
if (this.layout_meetingRecordContent) this.layout_meetingRecordContent.set("html", data.meetingRecord || " ");
if (this.layout_seals){
if (data.seals && data.seals.length){
data.seals.each(function(src, i){
if (this.layout_seals[i] && src){
this.layout_seals[i].src = src;
this.layout_seals[i].show();
this.layout_seals[i].setStyles({
"border": "0",
"border-radius": "0"
});
}
}.bind(this));
}
}
if (this.customLayouts){
this.customLayouts.each(function(l){
var value = this.data[l.name] || "";
var reg = new RegExp("\n","g");
var text = value.replace(reg,"
");
l.node.set("html",text || " ");
}.bind(this))
}
if (this.layout_issuanceUnit && this.layout_issuanceDate ){
var table = this.layout_issuanceUnit.getParent("table")
if (table && !table.hasClass("doc_layout_headIssuance")){
var unitWidth = o2.getTextSize(this.layout_issuanceUnit.get("text"), {
"font-size":"16pt",
"font-family":"'Times New Roman',仿宋",
"letter-spacing": "-0.2pt"
}).x;
var dateWidth = o2.getTextSize(this.layout_issuanceDate.get("text"), {
"font-size":"16pt",
"font-family":"'Times New Roman',仿宋",
"letter-spacing": "-0.2pt"
}).x;
// var unitWidth = this.layout_issuanceUnit.getSize().x;
// var dateWidth = this.layout_issuanceDate.getSize().x;
if (unitWidthdata.value){
this.notValidationMode(data.prompt);
return false;
}
break;
case "lt":
if (v"+htmlStr+"