123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- MWF.xDesktop.requireApp("process.Xform", "Htmleditor", null, false);
- MWF.xApplication.cms.Xform.Htmleditor = MWF.CMSHtmleditor = new Class({
- Extends: MWF.APPHtmleditor,
- // _loadUserInterface: function(){
- // this.node.empty();
- // if (this.readonly){
- // // var html = this.parseImage( this._getBusinessData() );
- // // this.node.set("html", html);
- // this.node.set("html", this._getBusinessData());
- // this.node.setStyles({
- // "-webkit-user-select": "text",
- // "-moz-user-select": "text"
- // });
- // if( layout.mobile ){
- // this.node.getElements("img").each( function( img ){
- // //if( img.height )img.erase("height");
- // img.setStyles({
- // "height": "auto",
- // "max-width" : "100%"
- // });
- // }.bind(this))
- // }
- // }else{
- // var config = Object.clone(this.json.editorProperties);
- // if (this.json.config){
- // if (this.json.config.code){
- // var obj = MWF.CMSMacro.exec(this.json.config.code, this);
- // Object.each(obj, function(v, k){
- // config[k] = v;
- // });
- // }
- // }
- //
- // this.loadCkeditor(config);
- // }
- // },
- // parseImage : function( html ){
- // html = ( html || "" ).replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (img, capture) {
- // if( img.indexOf( "data-id" ) > -1 && img.indexOf("setImageSrc()") > -1 ){
- // var ids = img.match( /(?<=data-id=").*?(?=")/g );
- // if( ids && ids.length > 0 ){
- // var newSrc = MWF.xDesktop.getImageSrc( ids[0] );
- // var newImg = this.replaceAttr( img, "img", "src", newSrc );
- // return newImg;
- // }
- // }
- // return img;
- // }.bind(this));
- // return html
- // },
- // replaceAttr: function(src_str, tag, attr, val) {
- // if(src_str.indexOf(attr) > 0) {
- // //包含attr属性,替换attr
- // var sub_reg = new RegExp(attr + '=[\'\"]([^"]*)[\'\"]', 'gi');
- // return src_str.replace(sub_reg, attr +'=' + val);
- // }else{
- // //不包含attr属性,添加attr
- // return src_str.substr(0, tag.length + 1) + ' ' + attr + '=' + val + ' ' + src_str.substr(tag.length + 2, src_str.length);
- // }
- // },
- loadCkeditor: function (config) {
- _self = this;
- // o2.load("../o2_lib/htmleditor/ckeditor4-major/ckeditor.js", function(){
- COMMON.AjaxModule.loadDom("ckeditor", function () {
- CKEDITOR.disableAutoInline = true;
- var editorDiv = new Element("div").inject(this.node);
- var htmlData = this._getBusinessData();
- if (htmlData) {
- editorDiv.set("html", htmlData);
- } else if (this.json.templateCode) {
- editorDiv.set("html", this.json.templateCode);
- }
- var height = this.node.getSize().y;
- var editorConfig = config || {};
- if (this.form.json.mode == "Mobile") {
- if (!editorConfig.toolbar && !editorConfig.toolbarGroups) {
- editorConfig.toolbar = [
- {
- name: 'paragraph',
- items: ['Bold', 'Italic', "-", 'TextColor', "BGColor", 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', "-", 'Undo', 'Redo']
- },
- {name: 'basicstyles', items: ['Styles', 'FontSize']},
- {name: 'insert', items: ['Image']}
- ];
- }
- }
- // CKEDITOR.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/";
- // CKEDITOR.plugins.basePath = COMMON.contentPath+"/res/framework/htmleditor/ckeditor/plugins/";
- //editorConfig.filebrowserCurrentDocumentImage = function( e, callback ){
- // _self.selectCurrentDocumentImage( e, callback );
- //};
- //editorConfig.filebrowserFilesImage = function( e, callback ){
- // _self.selectCloudFilesImage( e, callback );
- //};
- editorConfig.base64Encode = (this.json.base64Encode === "y");
- editorConfig.enablePreview = (this.json.enablePreview !== "n");
- editorConfig.localImageMaxWidth = 2000;
- editorConfig.reference = this.form.businessData.document.id;
- editorConfig.referenceType = "cmsDocument";
- if (editorConfig && editorConfig.extraPlugins) {
- var extraPlugins = editorConfig.extraPlugins;
- extraPlugins = typeOf(extraPlugins) === "array" ? extraPlugins : extraPlugins.split(",");
- extraPlugins.push( 'lineheight' );
- extraPlugins.push('o2image');
- extraPlugins.push('o2uploadimage');
- extraPlugins.push('o2uploadremoteimage');
- editorConfig.extraPlugins = extraPlugins;
- } else {
- editorConfig.extraPlugins = ['lineheight','o2image', 'o2uploadimage', 'o2uploadremoteimage'];
- }
- if (editorConfig && editorConfig.removePlugins) {
- var removePlugins = editorConfig.removePlugins;
- removePlugins = typeOf(removePlugins) === "array" ? removePlugins : removePlugins.split(",");
- editorConfig.removePlugins = removePlugins.concat(['image', 'easyimage', 'exportpdf', 'cloudservices']);
- } else {
- editorConfig.removePlugins = ['image', 'easyimage', 'exportpdf', 'cloudservices'];
- }
- if (!editorConfig.language) editorConfig.language = MWF.language;
- if (editorConfig.skin) editorConfig.skin = "moono-lisa";
- this.editor = CKEDITOR.replace(editorDiv, editorConfig);
- this._loadEvents();
- //this.editor.on("loaded", function(){
- // this._loadEvents();
- //}.bind(this));
- //this.setData(data)
- this.editor.on("change", function () {
- this._setBusinessData(this.getData());
- }.bind(this));
- // this._loadEvents();
- }.bind(this));
- },
- getText: function () {
- return (this.editor && this.editor.document) ? this.editor.document.getBody().getText() : this.node.get("text");
- },
- getImages: function () {
- var result = [];
- if( this.editor && this.editor.document ){
- var images = this.editor.document.find("img");
- if (images) {
- for (var i = 0; i < images.$.length; i++) {
- result.push(images.getItem(i).$);
- }
- }
- return result;
- }else{
- return this.node.getElements("img");
- }
- },
- getImageIds: function () {
- var result = [];
- var images = this.getImages();
- for (var i = 0; i < images.length; i++) {
- var img = images[i];
- if (img.getAttribute("data-id")) {
- result.push(img.getAttribute("data-id"))
- }
- }
- return result;
- },
- _loadStyles: function () {
- if (this.json.styles) this.node.setStyles(this.json.styles);
- this.node.setStyle("overflow", "hidden");
- },
- //selectCurrentDocumentImage : function( e, callback ){
- // var _self = this;
- // MWF.xDesktop.requireApp("cms.Xform", "Attachment", function(){
- // //_self.form.app.content
- // _self.selector_doc = new MWF.xApplication.cms.Xform.Attachment( document.body , {}, _self.form, {})
- // _self.selector_doc.loadAttachmentSelecter({
- // "style" : "cms",
- // "title": "选择本文档图片",
- // "listStyle": "preview",
- // "toBase64" : true,
- // "selectType" : "images"
- // }, function(url, data, base64Code){
- // if(callback)callback(url, base64Code, data);
- // });
- //
- // }, true);
- //
- //},
- //selectCloudFilesImage : function( e, callback ){
- // var _self = this;
- // MWF.xDesktop.requireApp("File", "FileSelector", function(){
- // //_self.form.app.content
- // _self.selector_cloud = new MWF.xApplication.File.FileSelector( document.body ,{
- // "style" : "default",
- // "title": "选择云文件图片",
- // "toBase64" : true,
- // "listStyle": "preview",
- // "selectType" : "images",
- // "onPostSelectAttachment" : function(url, base64Code){
- // if(callback)callback(url, base64Code);
- // }
- // });
- // _self.selector_cloud.load();
- // }, true);
- //
- //},
- validationConfigItem: function (routeName, data) {
- var flag = (data.status == "all") ? true : (routeName == "publish");
- if (flag) {
- var n = this.getData();
- var v = (data.valueType == "value") ? n : n.length;
- switch (data.operateor) {
- case "isnull":
- if (!v) {
- this.notValidationMode(data.prompt);
- return false;
- }
- break;
- case "notnull":
- if (v) {
- this.notValidationMode(data.prompt);
- return false;
- }
- break;
- case "gt":
- if (v > data.value) {
- this.notValidationMode(data.prompt);
- return false;
- }
- break;
- case "lt":
- if (v < data.value) {
- this.notValidationMode(data.prompt);
- return false;
- }
- break;
- case "equal":
- if (v == data.value) {
- this.notValidationMode(data.prompt);
- return false;
- }
- break;
- case "neq":
- if (v != data.value) {
- this.notValidationMode(data.prompt);
- return false;
- }
- break;
- case "contain":
- if (v.indexOf(data.value) != -1) {
- this.notValidationMode(data.prompt);
- return false;
- }
- break;
- case "notcontain":
- if (v.indexOf(data.value) == -1) {
- this.notValidationMode(data.prompt);
- return false;
- }
- break;
- }
- }
- return true;
- }
- });
|