IWebOffice.js 19.4 KB
Newer Older
傻拖 已提交
1 2
MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
MWF.xApplication.process.Xform.IWebOffice = MWF.APPIWebOffice =  new Class({
傻拖 已提交
3
    Extends: MWF.APP$Module,
傻拖 已提交
4 5 6 7 8 9 10 11
    options:{
        "copyright": "金格科技iWebOffice2015智能文档中间件[演示版];V5.0S0xGAAEAAAAAAAAAEAAAAJ0BAACgAQAALAAAAFgHOIQT3Ejo2JZMmSVxBkTixI2YkNh+cy/HGFlQ3HNIRG8j2V9vAnBWM8B384zkV79hltghTpDkba9QJTjGCDkylzhl3rian7v/AFF5DXQ7HdoXpN2imHbGHf8ieQNf672v38ODXJum7VaWv4P3DXzlzdnmzoaTTukFl+3ntFH29dQSjC94c4v0npn9rnXK5OsjJGR5mVGJJd6GWjE9rP3fo+kWCBYzb+bhn2sL+SKoyFjUuSptNHsOn3nRKrXyqkRd+QaHR/MDuKd1kEbUpRqCz9CjgfZFX00Zaz2l6ChA6LmdMMjjECalHZQA9WuxAc7cynGbvNfEgi277ahRpSZHmjKY5s18dJM/t9gdatg5b/dCqnUEn0+HS511XaM3xvy4DCVnD1n8xC9I5w+16NGrtTMiMSZFpc3QJphdShC0j+1l/ZyVj33YM31JmuxkI5SDL2CAfMUNsioseUfpOKvpxdcA7nmwlKrpxNetm9Bq0kwJn/jUU2bQa2c+bPRX82JcmFUwAz0ctOQ+Tyi+MoRpATEYW35KZtWepeDTGHJRfaJR81x8dVU0Lp1TuxtQiw==",
        "version": "12,7,0,828",
        "clsid": "D89F482C-5045-4DB5-8C53-D2C9EE71D025",
        "codeBase": "../o2_lib/iWebOffice/iWebOffice2015.cab",
        "version64" : "12,5,0,652",
        "clsid64" : "D89F482C-5045-4DB5-8C53-D2C9EE71D024",
        "codeBase64": "../o2_lib/iWebOffice/iWebOffice2015.cab",
傻拖 已提交
12
        "moduleEvents": [,
傻拖 已提交
13 14 15
            "afterOpen",
            "afterCreate",
            "beforeSave",
傻拖 已提交
16
            "afterSave"
傻拖 已提交
17 18 19 20 21 22 23 24 25 26
        ]
    },
    initialize: function(node, json, form, options){
        this.node = $(node);
        this.node.store("module", this);
        this.json = json;
        this.form = form;
        this.field = true;
        this.openedAttachment = null;
    },
傻拖 已提交
27 28 29 30 31 32
    _loadUserInterface: function(){
        this.node.empty();
        this.node.setStyles({
            "min-height": "100px"
        });
        if (Browser.name==="ie"){
傻拖 已提交
33 34 35 36
            this.file = null;
            if (!this.form.officeList) this.form.officeList=[];
            this.form.officeList.push(this);
        }
傻拖 已提交
37 38 39 40 41 42
    },
    _afterLoaded: function(){
        if (Browser.name==="ie"){
            if(!layout.serviceAddressList["x_jg_assemble_control"]){
                this.node.set("html","<h3><font color=red>please install weboffice !!!</font></h3>");
                return false;
傻拖 已提交
43
            }else{
傻拖 已提交
44 45 46
                var host = layout.serviceAddressList["x_jg_assemble_control"].host;
                var port = layout.serviceAddressList["x_jg_assemble_control"].port;
                this.webUrl =  layout.protocol + "//" + host + ":" + port + "/x_jg_assemble_control/IndexServlet";
傻拖 已提交
47
            }
傻拖 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

            this.action = o2.Actions.load("x_jg_assemble_control");
            if (!this.json.isNotLoadNow){

                this.data = this.getData();
                if(this.data.documentId === ""){
                    this.createDocument(function (){
                        this.loadOffice();
                    }.bind(this));
                }else {
                    this.documentId = this.data.documentId;
                    this.loadOffice();
                }
            }
            if (!this.json.isNotLoadNow){
                this.loadOffice();
            }
        }else {
            //console.log(JSON.stringify(this.json))
            this.node.set("html","<h3><font color=red>只支持ie浏览器!</font></h3>");
傻拖 已提交
68 69
        }
    },
傻拖 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
    createDocument : function (callback){
        this.action.ManageJGAction.create({"fileType":this.getFileType()}, function( json ){
            this.fireEvent("afterCreate");
            this.documentId = json.data.message;
            this.setData();
            if (callback) callback();
        }.bind(this),null, false);
    },
    createNew : function (){
        this.officeOCX.CreateFile();
    },
    getData: function(){
        var data = {
            "documentId" : ""
        };
        if(this.form.businessData.data[this.json.id]){
            data.documentId = this.form.businessData.data[this.json.id].documentId;
        }
        return data;
    },
    setData: function(){
        var data = {
            "documentId" : this.documentId
        };
        this._setBusinessData(data);
    },
    loadOffice: function(){
        if (!this.officeLoaded){
            MWF.getJSON("../o2_lib/iWebOffice/config.json", function(json){
                this.officeConfig = json;
            }.bind(this), false);
            this.loadOfficeContorl();
            this.officeLoaded = true;
傻拖 已提交
103 104
        }
    },
傻拖 已提交
105 106 107 108
    defaultParam: function(readonly){
        var o = {
            "copyright": this.json.copyright || this.options.copyright
        };
傻拖 已提交
109
        return o;
傻拖 已提交
110
    },
傻拖 已提交
111 112 113 114 115 116
    loadOfficeContorl: function(file){
        if (this.node.getSize().y<800) this.node.setStyle("height", "800px");

        if (!layout.desktop.offices) layout.desktop.offices = {};
        layout.desktop.offices[this.getOfficeObjectId()] = this;

傻拖 已提交
117
        if (this.json.isReadonly){
傻拖 已提交
118
            this.readonly  = true;
傻拖 已提交
119 120 121 122
        }else if (this.json.readScript && this.json.readScript.code){
            var flag = this.form.Macro.exec(this.json.readScript.code, this);
            if (flag){
                this.readonly = true;
傻拖 已提交
123 124
            }
        }
傻拖 已提交
125 126
        this.loadOfficeEditor();
    },
傻拖 已提交
127
    loadOfficeSpacer: function(){
傻拖 已提交
128
        var size = this.node.getSize();
傻拖 已提交
129 130 131 132 133 134 135 136 137 138 139

        this.officeNode = new Element("div#officeNode", {
            "styles": this.form.css.officeAreaNode
        }).inject(this.node);
        var y = size.y-40;
        this.officeNode.setStyle("height", ""+y+"px");

        this.form.app.addEvent("uncurrent", function(){
            var display = this.officeNode.getStyle("display");
            this.officeNode.store("officeDisplay", display);
            this.officeNode.setStyle("display", "none");
傻拖 已提交
140
        }.bind(this));
傻拖 已提交
141 142 143 144 145 146 147 148 149 150 151 152
        this.form.app.addEvent("current", function(){
            var display = this.officeNode.retrieve("officeDisplay");
            if (display) this.officeNode.setStyle("display", display);
            if (this.officeOCX) this.officeOCX.Activate(true);
        }.bind(this));

        this.form.app.addEvent("queryClose", function(){
            this.fireEvent("queryClose");
            var id = this.getOfficeObjectId();
            layout.desktop.offices[id] = null;
            delete layout.desktop.offices[id];
        }.bind(this));
傻拖 已提交
153
    },
傻拖 已提交
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
    hide: function(){
        if (this.officeNode.getStyle("display")!="none"){
            var display = this.officeNode.getStyle("display");
            this.officeNode.store("officeDisplay", display);
            this.officeNode.setStyle("display", "none");
        }
    },
    show: function(){
        if ((layout.desktop.currentApp && layout.desktop.currentApp.appId===this.form.app.appId) || this.form.app.inBrowser){
            var display = this.officeNode.retrieve("officeDisplay");
            if (display) this.officeNode.setStyle("display", display);
            if (this.officeOCX) this.officeOCX.Activate(true);
        }
    },
    getFormId: function(){
        var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
        return "form"+this.json.id+id;
    },
傻拖 已提交
172
    getFileType: function(){
傻拖 已提交
173 174 175 176 177 178 179 180 181 182 183
        var ename = "docx";
        switch (this.json.officeType){
            case "word":
                ename = "docx";
                break;
            case "excel":
                ename = "xlsx";
                break;
            case "ppt":
                ename = "pptx";
        }
傻拖 已提交
184
        return ename;
傻拖 已提交
185 186 187
    },
    getOfficeObjectId: function(){
        var id = (!this.form.businessData.workCompleted) ? this.form.businessData.work.id : this.form.businessData.workCompleted.id;
傻拖 已提交
188
        return "WebOffice"+this.json.id+id;
傻拖 已提交
189
    },
傻拖 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
    loadOfficeEditor: function(){
        if (!this.officeOCX){
            this.loadOfficeSpacer();

            this.node.setStyle("pisition", "absolute");

            var codeBase = this.officeConfig.codeBase || this.json.codeBase || this.options.codeBase;
            var version = this.officeConfig.version || this.json.version || this.options.version;
            var classid = this.officeConfig.classid || this.json.clsid || this.options.clsid;
            var codeBase64 = this.officeConfig.codeBase64 || this.json.codeBase64 || this.options.codeBase64;
            var classid64 = this.officeConfig.classid64 || this.json.clsid64 || this.options.clsid64;

            var objectHtml = "";

            if(window.navigator.platform=="Win64"){
                objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\" " +
                    "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
                    "codeBase=\""+codeBase64+"#version="+version+"\" " +
                    "classid=\"clsid:"+classid64+"\">";
傻拖 已提交
209
            }else{
傻拖 已提交
210 211 212 213
                objectHtml = "<form id='"+this.getFormId()+"' style='height:100%'><OBJECT id=\""+this.getOfficeObjectId()+"\" " +
                    "style=\"HEIGHT: 99%; WIDTH: 100%\" " +
                    "codeBase=\""+codeBase+"#version="+version+"\" " +
                    "classid=\"clsid:"+classid+"\">";
傻拖 已提交
214
            }
傻拖 已提交
215 216 217 218 219 220 221 222 223 224 225 226

            var pars = this.defaultParam();
            pars = Object.merge(pars, this.json.ntkoEditProperties);
            pars = Object.merge(pars, this.json.editProperties);

            Object.each(pars, function(p, key){
                objectHtml += "<PARAM NAME=\""+key+"\" value=\""+p+"\">";
            });

            objectHtml += "</OBJECT></form>";
            this.officeNode.appendHTML(objectHtml);
            this.officeForm = this.officeNode.getFirst();
傻拖 已提交
227
        }
傻拖 已提交
228
        setTimeout(function() {this.loadIwebOfficeEditor()}.bind(this), 3000);
傻拖 已提交
229
    },
傻拖 已提交
230
    loadIwebOfficeEditor : function (){
傻拖 已提交
231

傻拖 已提交
232 233 234
        // this.officeOCX.EditType="1,1";            //EditType:编辑类型  方式一、方式二  <参考技术文档>
        // //第一位可以为0,1,2,3 其中:0不可编辑;1可以编辑,无痕迹;2可以编辑,有痕迹,不能修订;3可以编辑,有痕迹,能修订;
        // //第二位可以为0,1 其中:0不可批注,1可以批注。可以参考iWebOffice2009的EditType属性,详细参考技术白皮书
傻拖 已提交
235

傻拖 已提交
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
        // //以下为自定义菜单↓
        // this.officeOCX.AppendMenu("1","打开本地文件(&L)", png10);
        // this.officeOCX.AppendMenu("2","保存本地文件(&S)", png2);
        // this.officeOCX.AppendMenu("3","保存到服务器(&U)", png7);
        // this.officeOCX.AppendMenu("7","-");
        // this.officeOCX.AppendMenu("11","保存并退出(&E)", png4);
        // this.officeOCX.AppendMenu("12","-");
        // this.officeOCX.AppendMenu("13","打印文档(&P)", png13);
        // //以上为自定义菜单↑
        // //this.officeOCX.VersionFontColor = "bfdbff";
        // this.officeOCX.AllowEmpty = true;


        this.officeOCX = document.getElementById(this.getOfficeObjectId()).FuncExtModule;

        this.officeOCX.WebUrl = this.webUrl;             //WebUrl:系统服务器路径,与服务器文件交互操作,如保存、打开文档,重要文件
        this.officeOCX.FileName = "文件正文.docx";            //FileName:文档名称
        this.officeOCX.UserName = layout.desktop.session.user.name;            //UserName:操作用户名,痕迹保留需要
        this.officeOCX.RecordID = this.documentId;
        this.officeOCX.FileType="." + this.getFileType();            //FileType:文档类型  .doc  .xls  .wps

        if(this.readonly){
            this.officeOCX.EditType="0,0";
傻拖 已提交
259
        }
傻拖 已提交
260 261
        this.officeOCX.ShowMenu = this.json.iWebOfficeEditProperties.Menubar;                         //控制整体菜单显示
        this.officeOCX.ShowToolBar = this.json.iWebOfficeEditProperties.ToolBars;                      //ShowToolBar:是否显示工具栏:1显示,0不显示
傻拖 已提交
262
        this.officeOCX.ShowWindow = false;                  //控制显示打开或保存文档的进度窗口,默认不显示
傻拖 已提交
263 264 265
        this.officeOCX.MaxFileSize = 32 * 1024;               //最大的文档大小控制,默认是8M,现在设置成4M。
        this.officeOCX.Print="1";
        this.officeOCX.WebOpen();
傻拖 已提交
266

傻拖 已提交
267 268
        this.fireEvent("afterOpen");
        this.loadMenu();
傻拖 已提交
269

傻拖 已提交
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
        if(!this.readonly){

            if(this.json.iWebOfficeEditProperties.IsNoCopy === "1"){
                this.unableCopy();
            }else {

                this.enableCopy();
            }
            if(this.json.trackRevisions === "1"){
                this.showRevision();
            }else {
                this.hideRevision();
            }
        }else {
            if(this.json.iWebOfficeReadProperties.IsNoCopy === "1"){
                this.unableCopy();
            }else {
                this.enableCopy();
傻拖 已提交
288 289 290
            }
        }
    },
傻拖 已提交
291 292 293 294 295 296 297 298
    setBookMark : function (name,value){
        if (!this.officeOCX.WebSetBookMarks(name,value)){
            //console.log("公文域内容设置失败");
            //console.log(WebOffice.Status);
        }else{
            //alert("公文域内容设置成功");
            //console.log(WebOffice.Status);
        }
傻拖 已提交
299
    },
傻拖 已提交
300 301
    getBookMark : function (name){
        return this.officeOCX.WebGetBookMarks(name);
傻拖 已提交
302
    },
傻拖 已提交
303 304 305 306
    openLocal : function (){
        try{
            this.officeOCX.WebOpenLocal();
        }catch(e){this.officeOCX.Alert(e.description);}
傻拖 已提交
307
    },
傻拖 已提交
308 309 310 311 312 313
    saveLocal : function (){
        try{
            this.officeOCX.WebSaveLocal();
            this.officeOCX.Alert("success");
        }catch(e){
            this.officeOCX.Alert(e.description);
傻拖 已提交
314 315
        }
    },
傻拖 已提交
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
    savePdf : function (){
        try{
            if(this.officeOCX.WebSavePDF())
            {
                this.officeOCX.Alert("success");
            }
            else{
                this.officeOCX.Alert("error");
            }
        } catch(e){
            alert(e.description);
        }
    },
    print : function (){
        try{
            var falg = this.officeOCX.WebOpenPrint();
            //alert(falg);
        }catch(e){alert(e.description);}
    },
    protect : function (){
        try{
            this.officeOCX.WebSetProtect(true,"");  //""表示密码为空
        }catch(e){this.officeOCX.Alert(e.description);}
    },
    unProtect : function (){
        try{
            this.officeOCX.WebSetProtect(false,"");  //""表示密码为空
        }catch(e){this.officeOCX.Alert(e.description);}
    },
    enableCopy : function (){
        try{
            this.officeOCX.CopyType=true;
        }catch(e){this.officeOCX.Alert(e.description);}
    },
    unableCopy : function (){
        try{
            this.officeOCX.CopyType=false;
        }catch(e){this.officeOCX.Alert(e.description);}
    },
    showRevision : function (){
        this.officeOCX.WebShow(true);
    },
    hideRevision : function (){
        this.officeOCX.WebShow(false);
    },
    acceptAllRevisions : function (){
        this.officeOCX.WebObject.Application.ActiveDocument.AcceptAllRevisions();
        var mCount = this.officeOCX.WebObject.Application.ActiveDocument.Revisions.Count;
        if(mCount>0){
            return false;
        }else{
            return true;
傻拖 已提交
368 369
        }
    },
傻拖 已提交
370 371 372 373 374 375 376 377
    isEmpty : function(){
    },
    save: function(){
        if (!this.readonly){
            this.fireEvent("beforeSave");
            var ret = this.officeOCX.WebSave();  //交互OfficeServer的OPTION="SAVEFILE"
            if (ret){
                //this.officeOCX.Alert(this.officeOCX.Status);
傻拖 已提交
378
            }else{
傻拖 已提交
379
                //alert(this.officeOCX.Status);
傻拖 已提交
380
            }
傻拖 已提交
381
            this.fireEvent("afterSave");
傻拖 已提交
382 383 384
        }
    },
    loadMenu: function(){
傻拖 已提交
385

傻拖 已提交
386 387
        if (!this.isMenuLoad){
            if (this.json.menuEditButtons && this.json.menuEditButtons.length){
傻拖 已提交
388

傻拖 已提交
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
                this.menuNode = new Element("div", {"styles": this.form.css.officeMenuNode}).inject(this.node, "top");
                MWF.require("MWF.widget.Toolbar", function(){
                    this.toolbarWidget = new MWF.widget.Toolbar(this.menuNode, {"style": "xform_blue_simple"}, this);

                    if (this.json.menuEditButtons.indexOf("new")!==-1){
                        this.newItem = this.createMenuAction("menu_new", "", "99.png");
                    }

                    if (this.json.menuEditButtons.indexOf("open")!==-1){
                        this.openItem = this.createMenuAction("menu_openfile", "", "77.png");
                    }

                    if (this.json.menuEditButtons.indexOf("save")!==-1){
                        this.saveItem = this.createMenuAction("menu_savefile", "", "67.png");
                    }

                    if (this.json.menuEditButtons.indexOf("revisions")!==-1){
                        var text = MWF.xApplication.process.Xform.LP.menu_revisions_show;
                        try {
                            if (this.officeOCX.ActiveDocument.ActiveWindow.View.RevisionsFilter.Markup !== 0){
                                text = MWF.xApplication.process.Xform.LP.menu_revisions_hide;
                            }
                        }catch(e){}

                        this.revisionsItem = this.createMenuAction("revisions", text, "76.png");
                    }
                    if (this.json.menuEditButtons.indexOf("toolbar")!==-1){
                        if (!this.readonly){
                            var text = MWF.xApplication.process.Xform.LP.menu_toolbar_show;
                            if (this.officeOCX.ToolBars){
                                text = MWF.xApplication.process.Xform.LP.menu_toolbar_hide;
                            }
                            this.toolbarItem = this.createMenuAction("toolbar", text, "91.png");
                        }
                    }
                    if (this.json.menuEditButtons.indexOf("preview")!==-1){
                        this.fullscreenItem = this.createMenuAction("menu_preview", "", "21.png");
                    }
                    this.toolbarWidget.load();

                }.bind(this));

            }
            this.isMenuLoad = true;
        }
    },
傻拖 已提交
435 436 437 438 439 440 441 442 443 444
    createMenuAction: function(id, title, img){
        var title = title || MWF.xApplication.process.Xform.LP[id];
        return new Element("div", {
            "MWFnodeid": id,
            "MWFnodetype": "MWFToolBarButton",
            "MWFButtonImage": this.form.path+""+this.form.options.style+"/actionbar/"+img,
            "title": title,
            "MWFButtonAction": "menuAction",
            "MWFButtonText": title
        }).inject(this.menuNode);
傻拖 已提交
445
    },
傻拖 已提交
446
    menuAction: function(button){
傻拖 已提交
447

傻拖 已提交
448 449 450
        switch (button.buttonID){
            case "menu_new":
                this.createNew();
傻拖 已提交
451
                break;
傻拖 已提交
452 453
            case "menu_openfile":
                this.openLocal();
傻拖 已提交
454
                break;
傻拖 已提交
455 456
            case "menu_savefile":
                this.saveLocal();
傻拖 已提交
457
                break;
傻拖 已提交
458 459
            case "revisions":
                this.toggleRevisions(button);
傻拖 已提交
460
                break;
傻拖 已提交
461 462 463 464 465 466 467
            case "toolbar":
                // var text = (this.officeOCX.ToolBars) ? MWF.xApplication.process.Xform.LP.menu_toolbar_show : MWF.xApplication.process.Xform.LP.menu_toolbar_hide;
                // button.setText(text);
                // this.officeOCX.ToolBars = !this.officeOCX.ToolBars;
                break;
            case "menu_preview":
                this.print();
傻拖 已提交
468 469 470
                break;
        }
    },
傻拖 已提交
471 472 473 474
    toggleRevisions: function(button){
        var t = this.revisionsItem.get("text");
        if (t===MWF.xApplication.process.Xform.LP.menu_revisions_show){
            button.setText(MWF.xApplication.process.Xform.LP.menu_revisions_hide);
傻拖 已提交
475

傻拖 已提交
476
            this.showRevision();
傻拖 已提交
477
        }else{
傻拖 已提交
478
            button.setText(MWF.xApplication.process.Xform.LP.menu_revisions_show);
傻拖 已提交
479

傻拖 已提交
480
            this.hideRevision();
傻拖 已提交
481 482 483
        }
    },
    validationMode: function(){},
傻拖 已提交
484
    validation: function(){return true}
傻拖 已提交
485
});