OfdView.js 5.0 KB
Newer Older
傻拖 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
MWF.xApplication.process.Xform.OfdView = MWF.APPOfdView =  new Class({
    Extends: MWF.APP$Module,
    options:{
        "moduleEvents": [
            "afterOpen"
        ]
    },
    initialize: function(node, json, form, options){
        this.node = $(node);
        this.node.store("module", this);
        this.json = json;
        this.form = form;

        if (this.json.isReadonly){
            this.mode  = "read";
        }else{
            if (this.json.readScript && this.json.readScript.code){
                var flag = this.form.Macro.exec(this.json.readScript.code, this);
                if (flag){
                    this.mode = "read";
                }
            }
        }

    },
    _loadUserInterface: function(){
        this.node.empty();
    },
    _afterLoaded: function(){
        if(this.mode !== "read"){
            this.createUpload();
        }

        this.data = this.getData();
        this.documentId = this.data.documentId;
        if(this.data.documentId === ""){
            this.createEmpty();
        }else {

            this.loadOfdView();
        }
    },
    createEmpty : function (){
        this.emptyNode = new Element("div").inject(this.node);
        this.emptyNode.set("text",MWF.xApplication.process.Xform.LP.ofdview.nofile);
    },
    createUpload : function (){


        this.uploadNode = new Element("div",{"style":"margin:10px;"}).inject(this.node);

傻拖 已提交
53
        var uploadBtn = new Element("button",{"text":MWF.xApplication.process.Xform.LP.ofdview.upload,"style":"margin-left: 15px; color: rgb(255, 255, 255); cursor: pointer; height: 26px; line-height: 26px; padding: 0px 10px; min-width: 40px; background-color: rgb(74, 144, 226); border: 1px solid rgb(82, 139, 204); border-radius: 15px;"}).inject(this.uploadNode);
傻拖 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
        uploadBtn.addEvent("click",function (){
            o2.require("o2.widget.Upload", null, false);

            if(this.documentId === ""){
                var upload = new o2.widget.Upload(this.form.app.content, {
                    "action": o2.Actions.get("x_processplatform_assemble_surface").action,
                    "method": "uploadAttachment",
                    "parameter": {
                        "id": this.form.businessData.work.id
                    },
                    "accept" : ".ofd",
                    "data":{
                        "site": "ofdAttachement"
                    },
                    "onCompleted": function(json){
                        this.documentId = json.data.id;
                        this.setData();
                        this.loadOfdView();
                    }.bind(this)
                });
            }else {
                var upload = new o2.widget.Upload(this.form.app.content, {
                    "action": o2.Actions.get("x_processplatform_assemble_surface").action,
                    "method": "replaceAttachment",
                    "parameter": {
                        "id" : this.documentId,
                        "workid": this.form.businessData.work.id
                    },
                    "accept" : ".ofd",
                    "data":{
                    },
                    "onCompleted": function(json){
                        this.documentId = json.data.id;
                        this.setData();
                        this.loadOfdView();
                    }.bind(this)
                });
            }

            upload.load();
        }.bind(this));

    },
    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
        };
        debugger
        this._setBusinessData(data);
    },
    loadOfdView: function(){

        this.iframeNode = new Element("div").inject(this.node);
        this.iframeNode.setStyles({
            "height": "100%"
        });
        var host = o2.Actions.getHost( "x_processplatform_assemble_surface" );
        var fileUrl = o2.filterUrl(host + "/x_processplatform_assemble_surface/jaxrs/attachment/download/" + this.documentId);

        if(this.iframe){
            this.iframe.set("src","../o2_lib/ofdjs/index.html?file=" + fileUrl);
        }else {
            this.iframe = new Element("iframe").inject(this.iframeNode);
            this.iframe.set("src","../o2_lib/ofdjs/index.html?file=" + fileUrl);
            this.iframe.set("scrolling","no");
            this.iframe.set("frameborder",0);
            this.iframe.setStyles({
                "height" : "100%",
                "width" : "100%"
            });
        }
        if(this.emptyNode) this.emptyNode.hide();

        this.fireEvent("afterOpen");
    },

    hide: function(){
        this.node.hide();
    },
    show: function(){
        this.node.show();
    },
    isEmpty : function(){
    },
    save: function(){
    },
    validation: function(){return true}
});