Attachment.js 75.1 KB
Newer Older
NoSubject's avatar
NoSubject 已提交
1 2 3 4 5
MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
MWF.require("MWF.widget.AttachmentController", null, false);
MWF.xApplication.process.Xform.AttachmentController = new Class({
    Extends: MWF.widget.ATTER,
    "options": {
NoSubject's avatar
NoSubject 已提交
6 7
        "officeFiles": ["doc", "docx", "dotx", "dot", "xls", "xlsx", "xlsm", "xlt", "xltx", "pptx", "ppt", "pot", "potx", "potm", "pdf"],
        "checkTextEnable": true
NoSubject's avatar
NoSubject 已提交
8
    },
NoSubject's avatar
NoSubject 已提交
9 10 11
    checkAttachmentDeleteAction: function () {
        if (this.options.readonly) {
            this.setAttachmentsAction("delete", false);
NoSubject's avatar
NoSubject 已提交
12 13
            return false;
        }
NoSubject's avatar
NoSubject 已提交
14 15
        if (this.options.isDeleteOption !== "n") {
            if (this.attachments.length) {
NoSubject's avatar
NoSubject 已提交
16 17
                var user = layout.session.user.distinguishedName;

NoSubject's avatar
NoSubject 已提交
18
                for (var i = 0; i < this.attachments.length; i++) {
NoSubject's avatar
NoSubject 已提交
19 20
                    var flag = true;
                    var att = this.attachments[i];
NoSubject's avatar
NoSubject 已提交
21 22
                    if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
                    if (this.options.isDeleteOption === "o") {
NoSubject's avatar
NoSubject 已提交
23

NoSubject's avatar
NoSubject 已提交
24 25
                        if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
                        if (att.data.person !== layout.desktop.session.user.distinguishedName) flag = false;
NoSubject's avatar
NoSubject 已提交
26

NoSubject's avatar
NoSubject 已提交
27
                    } else if (this.options.isDeleteOption === "a") {
NoSubject's avatar
NoSubject 已提交
28

NoSubject's avatar
NoSubject 已提交
29 30
                        if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
                        if (att.data.activity !== this.module.form.businessData.activity.id) flag = false;
NoSubject's avatar
NoSubject 已提交
31

NoSubject's avatar
NoSubject 已提交
32
                    } else if (this.options.isDeleteOption === "ao") {
NoSubject's avatar
NoSubject 已提交
33

NoSubject's avatar
NoSubject 已提交
34 35
                        if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
                        if ((att.data.activity !== this.module.form.businessData.activity.id) || (att.data.person !== layout.desktop.session.user.distinguishedName)) flag = false;
NoSubject's avatar
NoSubject 已提交
36

NoSubject's avatar
NoSubject 已提交
37 38
                    } else {
                        if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
NoSubject's avatar
NoSubject 已提交
39 40
                    }

NoSubject's avatar
NoSubject 已提交
41 42 43 44
                    if (flag) {
                        this.setAttachmentAction(att, "delete", true);
                    } else {
                        this.setAttachmentAction(att, "delete", false);
NoSubject's avatar
NoSubject 已提交
45 46 47 48
                    }
                }
            }

NoSubject's avatar
NoSubject 已提交
49 50
        } else {
            this.setAttachmentsAction("delete", false);
NoSubject's avatar
NoSubject 已提交
51 52
        }
    },
NoSubject's avatar
NoSubject 已提交
53
    checkDeleteAction: function () {
NoSubject's avatar
NoSubject 已提交
54 55 56

        this.checkAttachmentDeleteAction();

NoSubject's avatar
NoSubject 已提交
57
        if (this.options.readonly) {
NoSubject's avatar
NoSubject 已提交
58 59 60 61
            this.setActionDisabled(this.deleteAction);
            this.setActionDisabled(this.min_deleteAction);
            return false;
        }
NoSubject's avatar
NoSubject 已提交
62 63
        if (this.options.isDeleteOption !== "n") {
            if (this.selectedAttachments.length) {
NoSubject's avatar
NoSubject 已提交
64
                var user = layout.session.user.distinguishedName;
NoSubject's avatar
NoSubject 已提交
65
                var flag = true;
NoSubject's avatar
NoSubject 已提交
66 67
                if (this.options.isDeleteOption === "o") {
                    for (var i = 0; i < this.selectedAttachments.length; i++) {
R
roo00 已提交
68
                        var att = this.selectedAttachments[i];
NoSubject's avatar
NoSubject 已提交
69 70
                        if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
                        if (!att.data.control.allowEdit && att.data.person !== user) {
NoSubject's avatar
NoSubject 已提交
71 72 73
                            flag = false;
                            break;
                        }
NoSubject's avatar
NoSubject 已提交
74
                        if (att.data.person !== layout.desktop.session.user.distinguishedName) {
NoSubject's avatar
NoSubject 已提交
75 76 77 78
                            flag = false;
                            break;
                        }
                    }
NoSubject's avatar
NoSubject 已提交
79 80
                } else if (this.options.isDeleteOption === "a") {
                    for (var i = 0; i < this.selectedAttachments.length; i++) {
R
roo00 已提交
81
                        var att = this.selectedAttachments[i];
NoSubject's avatar
NoSubject 已提交
82 83
                        if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
                        if (!att.data.control.allowEdit && att.data.person !== user) {
NoSubject's avatar
NoSubject 已提交
84 85 86
                            flag = false;
                            break;
                        }
NoSubject's avatar
NoSubject 已提交
87
                        if (att.data.activity !== this.module.form.businessData.activity.id) {
NoSubject's avatar
NoSubject 已提交
88 89 90 91
                            flag = false;
                            break;
                        }
                    }
NoSubject's avatar
NoSubject 已提交
92 93
                } else if (this.options.isDeleteOption === "ao") {
                    for (var i = 0; i < this.selectedAttachments.length; i++) {
R
roo00 已提交
94
                        var att = this.selectedAttachments[i];
NoSubject's avatar
NoSubject 已提交
95 96
                        if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
                        if (!att.data.control.allowEdit && att.data.person !== user) {
NoSubject's avatar
NoSubject 已提交
97 98 99
                            flag = false;
                            break;
                        }
NoSubject's avatar
NoSubject 已提交
100
                        if ((att.data.activity !== this.module.form.businessData.activity.id) || (att.data.person !== layout.desktop.session.user.distinguishedName)) {
NoSubject's avatar
NoSubject 已提交
101 102 103 104
                            flag = false;
                            break;
                        }
                    }
NoSubject's avatar
NoSubject 已提交
105 106
                } else {
                    for (var i = 0; i < this.selectedAttachments.length; i++) {
R
roo00 已提交
107
                        var att = this.selectedAttachments[i];
NoSubject's avatar
NoSubject 已提交
108 109
                        if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
                        if (!att.data.control.allowEdit && att.data.person !== user) {
NoSubject's avatar
NoSubject 已提交
110 111 112 113
                            flag = false;
                            break;
                        }
                    }
NoSubject's avatar
NoSubject 已提交
114 115
                }

NoSubject's avatar
NoSubject 已提交
116
                if (flag) {
NoSubject's avatar
NoSubject 已提交
117 118
                    this.setActionEnabled(this.deleteAction);
                    this.setActionEnabled(this.min_deleteAction);
NoSubject's avatar
NoSubject 已提交
119
                } else {
NoSubject's avatar
NoSubject 已提交
120 121 122
                    this.setActionDisabled(this.deleteAction);
                    this.setActionDisabled(this.min_deleteAction);
                }
NoSubject's avatar
NoSubject 已提交
123
            } else {
NoSubject's avatar
NoSubject 已提交
124 125 126
                this.setActionDisabled(this.deleteAction);
                this.setActionDisabled(this.min_deleteAction);
            }
NoSubject's avatar
NoSubject 已提交
127
        } else {
NoSubject's avatar
NoSubject 已提交
128
            // if (!this.options.isDelete){
NoSubject's avatar
NoSubject 已提交
129 130
            this.setActionDisabled(this.deleteAction);
            this.setActionDisabled(this.min_deleteAction);
NoSubject's avatar
NoSubject 已提交
131 132 133 134 135 136 137 138 139
            // }else{
            //     if (this.selectedAttachments.length){
            //         this.setActionEnabled(this.deleteAction);
            //         this.setActionEnabled(this.min_deleteAction);
            //     }else{
            //         this.setActionDisabled(this.deleteAction);
            //         this.setActionDisabled(this.min_deleteAction);
            //     }
            // }
NoSubject's avatar
NoSubject 已提交
140 141
        }
    },
NoSubject's avatar
NoSubject 已提交
142 143 144 145
    isAttDeleteAvailable: function (att) {
        if (this.options.readonly) return false;
        if (this.options.toolbarGroupHidden.contains("edit")) return false;
        if (this.options.isDeleteOption === "n") return false;
R
roo00 已提交
146 147 148 149

        var user = layout.session.user.distinguishedName;
        var flag = true;

NoSubject's avatar
NoSubject 已提交
150
        if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
R
roo00 已提交
151

NoSubject's avatar
NoSubject 已提交
152
        if (this.options.isDeleteOption === "o") {
R
roo00 已提交
153

NoSubject's avatar
NoSubject 已提交
154 155
            if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
            if (att.data.person !== layout.desktop.session.user.distinguishedName) flag = false;
R
roo00 已提交
156

NoSubject's avatar
NoSubject 已提交
157
        } else if (this.options.isDeleteOption === "a") {
R
roo00 已提交
158

NoSubject's avatar
NoSubject 已提交
159 160
            if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
            if (att.data.activity !== this.module.form.businessData.activity.id) flag = false;
R
roo00 已提交
161

NoSubject's avatar
NoSubject 已提交
162
        } else if (this.options.isDeleteOption === "ao") {
R
roo00 已提交
163

NoSubject's avatar
NoSubject 已提交
164 165
            if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
            if ((att.data.activity !== this.module.form.businessData.activity.id) || (att.data.person !== layout.desktop.session.user.distinguishedName)) flag = false;
R
roo00 已提交
166

NoSubject's avatar
NoSubject 已提交
167 168
        } else {
            if (!att.data.control.allowEdit && att.data.person !== user) flag = false;
R
roo00 已提交
169 170 171 172
        }

        return flag;
    },
NoSubject's avatar
NoSubject 已提交
173 174 175
    openInOfficeControl: function (att, office) {
        if (office) {
            if (!office.openedAttachment || office.openedAttachment.id !== att.id) {
NoSubject's avatar
NoSubject 已提交
176
                office.save();
NoSubject's avatar
NoSubject 已提交
177 178 179
                if (this.module.form.businessData.workCompleted) {
                    MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentWorkcompletedUrl(att.id, this.module.form.businessData.workCompleted.id, function (url) {
                        office.openedAttachment = { "id": att.id, "site": this.module.json.name, "name": att.name };
NoSubject's avatar
NoSubject 已提交
180 181
                        office.officeOCX.BeginOpenFromURL(url, true, this.readonly);
                    }.bind(this));
NoSubject's avatar
NoSubject 已提交
182 183 184
                } else {
                    MWF.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(att.id, this.module.form.businessData.work.id, function (url) {
                        office.openedAttachment = { "id": att.id, "site": this.module.json.name, "name": att.name };
NoSubject's avatar
NoSubject 已提交
185 186 187 188 189 190 191
                        office.officeOCX.BeginOpenFromURL(url, true, this.readonly);
                    }.bind(this));
                }
            }
        }
    },

NoSubject's avatar
NoSubject 已提交
192 193 194
    checkReplaceAction: function () {
        if (this.options.isReplaceHidden) return;
        if (this.options.readonly) {
NoSubject's avatar
NoSubject 已提交
195 196
            this.setActionDisabled(this.replaceAction);
            this.setActionDisabled(this.min_replaceAction);
NoSubject's avatar
NoSubject 已提交
197
            return false;
NoSubject's avatar
NoSubject 已提交
198 199
        }

NoSubject's avatar
NoSubject 已提交
200 201
        if (this.options.isReplaceOption !== "n") {
            if (this.selectedAttachments.length && this.selectedAttachments.length === 1) {
R
roo00 已提交
202 203

                var att = this.selectedAttachments[0];
NoSubject's avatar
NoSubject 已提交
204
                if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
R
roo00 已提交
205

NoSubject's avatar
NoSubject 已提交
206
                var user = layout.session.user.distinguishedName;
R
roo00 已提交
207
                var flag = true;
NoSubject's avatar
NoSubject 已提交
208

NoSubject's avatar
NoSubject 已提交
209
                if (this.options.isReplaceOption === "o") {
R
roo00 已提交
210
                    flag = att.data.person === layout.desktop.session.user.distinguishedName;
NoSubject's avatar
NoSubject 已提交
211
                }
NoSubject's avatar
NoSubject 已提交
212 213
                if (this.options.isReplaceOption === "a") {
                    flag = att.data.activity === this.module.form.businessData.activity.id;
NoSubject's avatar
NoSubject 已提交
214
                }
NoSubject's avatar
NoSubject 已提交
215 216
                if (this.options.isReplaceOption === "ao") {
                    flag = (att.data.person === layout.desktop.session.user.distinguishedName && att.data.activity === this.module.form.businessData.activity.id);
NoSubject's avatar
NoSubject 已提交
217
                }
NoSubject's avatar
NoSubject 已提交
218
                if (flag && !att.data.control.allowEdit && att.data.person !== user) {
NoSubject's avatar
NoSubject 已提交
219 220
                    flag = false;
                }
NoSubject's avatar
NoSubject 已提交
221 222 223 224

                if (flag) {
                    this.setActionEnabled(this.replaceAction);
                    this.setActionEnabled(this.min_replaceAction);
NoSubject's avatar
NoSubject 已提交
225
                } else {
NoSubject's avatar
NoSubject 已提交
226 227 228 229 230 231 232
                    this.setActionDisabled(this.replaceAction);
                    this.setActionDisabled(this.min_replaceAction);
                }
            } else {
                this.setActionDisabled(this.replaceAction);
                this.setActionDisabled(this.min_replaceAction);
            }
NoSubject's avatar
NoSubject 已提交
233
        } else {
NoSubject's avatar
NoSubject 已提交
234 235 236 237 238 239 240 241 242 243 244 245
            // if (!this.options.isReplace){
            this.setActionDisabled(this.replaceAction);
            this.setActionDisabled(this.min_replaceAction);
            // }else{
            //     if (this.selectedAttachments.length && this.selectedAttachments.length===1){
            //         this.setActionEnabled(this.replaceAction);
            //         this.setActionEnabled(this.min_replaceAction);
            //     }else{
            //         this.setActionDisabled(this.replaceAction);
            //         this.setActionDisabled(this.min_replaceAction);
            //     }
            // }
NoSubject's avatar
NoSubject 已提交
246 247
        }
    },
NoSubject's avatar
NoSubject 已提交
248
    replaceAttachment: function (e, node) {
NoSubject's avatar
NoSubject 已提交
249 250
        var att = this.selectedAttachments[0].data;

NoSubject's avatar
NoSubject 已提交
251
        if (this.module.json.isOpenInOffice && this.module.json.officeControlName && (this.options.officeFiles.indexOf(att.extension) !== -1)) {
NoSubject's avatar
NoSubject 已提交
252
            var office = this.module.form.all[this.module.json.officeControlName];
NoSubject's avatar
NoSubject 已提交
253
            if (office) {
NoSubject's avatar
NoSubject 已提交
254 255 256
                if (this.min_closeOfficeAction) this.setActionEnabled(this.min_closeOfficeAction);
                if (this.closeOfficeAction) this.setActionEnabled(this.closeOfficeAction);
                this.openInOfficeControl(att, office);
NoSubject's avatar
NoSubject 已提交
257 258
            } else {
                if (this.selectedAttachments.length && this.selectedAttachments.length == 1) {
NoSubject's avatar
NoSubject 已提交
259 260 261
                    if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
                }
            }
NoSubject's avatar
NoSubject 已提交
262 263
        } else {
            if (this.selectedAttachments.length && this.selectedAttachments.length == 1) {
NoSubject's avatar
NoSubject 已提交
264 265 266 267
                if (this.module) this.module.replaceAttachment(e, node, this.selectedAttachments[0]);
            }
        }
    },
NoSubject's avatar
NoSubject 已提交
268 269 270
    isAttReplaceAvailable: function (att) {
        if (this.options.readonly) return false;
        if (this.options.toolbarGroupHidden.contains("edit")) return false;
R
roo00 已提交
271

NoSubject's avatar
NoSubject 已提交
272
        if (this.options.isReplaceOption === "n") return false;
R
roo00 已提交
273 274 275 276

        var user = layout.session.user.distinguishedName;
        var flag = true;

NoSubject's avatar
NoSubject 已提交
277
        if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
R
roo00 已提交
278

NoSubject's avatar
NoSubject 已提交
279
        if (this.options.isReplaceOption === "o") {
R
roo00 已提交
280 281
            flag = att.data.person === layout.desktop.session.user.distinguishedName;
        }
NoSubject's avatar
NoSubject 已提交
282 283
        if (this.options.isReplaceOption === "a") {
            flag = att.data.activity === this.module.form.businessData.activity.id;
R
roo00 已提交
284
        }
NoSubject's avatar
NoSubject 已提交
285 286
        if (this.options.isReplaceOption === "ao") {
            flag = (att.data.person === layout.desktop.session.user.distinguishedName && att.data.activity === this.module.form.businessData.activity.id);
R
roo00 已提交
287
        }
NoSubject's avatar
NoSubject 已提交
288
        if (flag && !att.data.control.allowEdit && att.data.person !== user) {
R
roo00 已提交
289 290 291 292 293
            flag = false;
        }

        return flag;
    },
NoSubject's avatar
NoSubject 已提交
294

R
roo00 已提交
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319

    //checkAttachmentOrderAction : function(){
    //    if (this.options.readonly){
    //        this.setAttachmentsAction("order", false );
    //        return false;
    //    }
    //    if (this.attachments.length){
    //        var user = layout.session.user.distinguishedName;
    //        for (var i=0; i<this.attachments.length; i++){
    //            var flag = true;
    //
    //            var att = this.attachments[i];
    //            if( !att.data.person && att.data.creatorUid )att.data.person = att.data.creatorUid;
    //
    //            if ((!att.data.control.allowControl || !att.data.control.allowEdit) && att.data.person!==user){
    //                flag = false;
    //            }
    //            if (flag){
    //                this.setAttachmentAction(att, "order", true );
    //            }else{
    //                this.setAttachmentAction(att, "order", false );
    //            }
    //        }
    //    }
    //},
NoSubject's avatar
NoSubject 已提交
320
    checkOrderAction: function () {
R
roo00 已提交
321
        //this.checkAttachmentOrderAction();
NoSubject's avatar
NoSubject 已提交
322
        if (this.options.readonly) {
R
roo00 已提交
323 324 325 326
            this.setActionDisabled(this.orderAction);
            this.setActionDisabled(this.min_orderAction);
            return false;
        }
NoSubject's avatar
NoSubject 已提交
327
        if (this.attachments.length && this.attachments.length > 1) {
R
roo00 已提交
328 329
            var flag = true;
            var user = layout.session.user.distinguishedName;
NoSubject's avatar
NoSubject 已提交
330
            for (var i = 0; i < this.attachments.length; i++) {
R
roo00 已提交
331
                var att = this.attachments[i];
NoSubject's avatar
NoSubject 已提交
332 333
                if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
                if ((!att.data.control.allowControl && !att.data.control.allowEdit) && att.data.person !== user) { //|| !att.data.control.allowEdit
R
roo00 已提交
334 335 336 337
                    flag = false;
                    break;
                }
            }
NoSubject's avatar
NoSubject 已提交
338
            if (flag) {
R
roo00 已提交
339 340
                this.setActionEnabled(this.orderAction);
                this.setActionEnabled(this.min_orderAction);
NoSubject's avatar
NoSubject 已提交
341
            } else {
R
roo00 已提交
342 343 344 345
                this.setActionDisabled(this.orderAction);
                this.setActionDisabled(this.min_orderAction);
            }
            //this.setActionEnabled(this.min_deleteAction);
NoSubject's avatar
NoSubject 已提交
346
        } else {
R
roo00 已提交
347 348 349 350 351
            this.setActionDisabled(this.orderAction);
            this.setActionDisabled(this.min_orderAction);
            //this.setActionDisabled(this.min_deleteAction);
        }
    },
NoSubject's avatar
NoSubject 已提交
352 353 354
    isAttOrderAvailable: function (att) {
        if (this.options.readonly) return false;
        if (this.options.toolbarGroupHidden.contains("config")) return false;
R
roo00 已提交
355 356 357
        var user = layout.session.user.distinguishedName;
        var flag = true;

NoSubject's avatar
NoSubject 已提交
358
        if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
R
roo00 已提交
359

NoSubject's avatar
NoSubject 已提交
360
        if ((!att.data.control.allowControl || !att.data.control.allowEdit) && att.data.person !== user) {
R
roo00 已提交
361 362 363 364 365
            flag = false;
        }
        return flag;
    },

NoSubject's avatar
NoSubject 已提交
366 367 368
    createTopNode: function () {
        if (this.options.title) {
            if (!this.titleNode) this.titleNode = new Element("div", { "styles": this.css.titleNode, "text": this.options.title }).inject(this.node);
NoSubject's avatar
NoSubject 已提交
369
        }
NoSubject's avatar
NoSubject 已提交
370 371 372
        if (!this.topNode) {
            this.topNode = new Element("div", { "styles": this.css.topNode }).inject(this.node);
        } else {
R
roo00 已提交
373 374
            this.topNode.empty();
            this.editActionBoxNode = null;
NoSubject's avatar
NoSubject 已提交
375 376 377
            this.editActionsGroupNode = null;
            this.topNode.setStyle("display", "");
            if (this.isHiddenTop) {
R
roo00 已提交
378 379
                //this.container.setStyle("height", this.container.getSize().y + 45 );
                //this.node.setStyle("height", this.node.getSize().y + 45 );
NoSubject's avatar
NoSubject 已提交
380 381
                if (this.oldContentScrollNodeHeight && this.contentScrollNode) {
                    this.contentScrollNode.setStyle("min-height", this.oldContentScrollNodeHeight);
R
roo00 已提交
382 383 384 385 386 387
                    this.oldContentScrollNodeHeight = null;
                }
                this.isHiddenTop = false;
            }
        }
        var hiddenGroup = this.options.toolbarGroupHidden;
NoSubject's avatar
NoSubject 已提交
388
        if (hiddenGroup.contains("edit") && hiddenGroup.contains("read") && hiddenGroup.contains("list") &&
R
roo00 已提交
389 390
            hiddenGroup.contains("view") && hiddenGroup.contains("config") &&
            !(this.module.json.isOpenInOffice && this.module.json.officeControlName)
NoSubject's avatar
NoSubject 已提交
391 392
        ) {
            if (this.contentScrollNode) {
R
roo00 已提交
393
                this.oldContentScrollNodeHeight = this.contentScrollNode.getStyle("min-height");
NoSubject's avatar
NoSubject 已提交
394 395
                this.contentScrollNode.setStyle("min-height", this.node.getStyle("min-height"));
                this.topNode.setStyle("display", "none");
R
roo00 已提交
396 397 398
            }
            this.isHiddenTop = true;
        }
NoSubject's avatar
NoSubject 已提交
399 400 401
        if (!hiddenGroup.contains("edit")) this.createEditGroupActions();
        if (!hiddenGroup.contains("read")) this.createReadGroupActions();
        if (!hiddenGroup.contains("list")) this.createListGroupActions();
NoSubject's avatar
NoSubject 已提交
402
        if (this.module.json.isOpenInOffice && this.module.json.officeControlName) this.createOfficeGroupActions();
NoSubject's avatar
NoSubject 已提交
403

NoSubject's avatar
NoSubject 已提交
404 405 406
        if (!hiddenGroup.contains("config")) this.createConfigGroupActions();

        if (!hiddenGroup.contains("view")) this.createViewGroupActions();
R
roo00 已提交
407
        this.checkActions();
NoSubject's avatar
NoSubject 已提交
408
    },
NoSubject's avatar
NoSubject 已提交
409
    checkActions: function () {
NoSubject's avatar
NoSubject 已提交
410 411 412 413 414 415 416 417 418 419 420
        //    if (this.options.readonly){
        //        this.setReadonly();
        //    }else{
        this.checkUploadAction();
        this.checkDeleteAction();
        this.checkReplaceAction();
        //this.checkOfficeAction();
        this.checkDownloadAction();
        this.checkSizeAction();

        this.checkConfigAction();
R
roo00 已提交
421
        this.checkOrderAction();
NoSubject's avatar
NoSubject 已提交
422 423 424 425 426

        this.checkListStyleAction();
        //    }
    },

NoSubject's avatar
NoSubject 已提交
427 428 429
    checkAttachmentConfigAction: function () {
        if (this.options.readonly) {
            this.setAttachmentsAction("config", false);
NoSubject's avatar
NoSubject 已提交
430 431
            return false;
        }
NoSubject's avatar
NoSubject 已提交
432
        if (this.attachments.length) {
NoSubject's avatar
NoSubject 已提交
433
            var user = layout.session.user.distinguishedName;
NoSubject's avatar
NoSubject 已提交
434
            for (var i = 0; i < this.attachments.length; i++) {
NoSubject's avatar
NoSubject 已提交
435
                var flag = true;
R
roo00 已提交
436 437

                var att = this.attachments[i];
NoSubject's avatar
NoSubject 已提交
438
                if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
R
roo00 已提交
439

NoSubject's avatar
NoSubject 已提交
440
                if ((!att.data.control.allowControl || !att.data.control.allowEdit) && att.data.person !== user) {
NoSubject's avatar
NoSubject 已提交
441 442
                    flag = false;
                }
NoSubject's avatar
NoSubject 已提交
443 444 445 446
                if (flag) {
                    this.setAttachmentAction(att, "config", true);
                } else {
                    this.setAttachmentAction(att, "config", false);
NoSubject's avatar
NoSubject 已提交
447 448 449 450
                }
            }
        }
    },
NoSubject's avatar
NoSubject 已提交
451
    checkConfigAction: function () {
NoSubject's avatar
NoSubject 已提交
452
        this.checkAttachmentConfigAction();
NoSubject's avatar
NoSubject 已提交
453
        if (this.options.readonly) {
NoSubject's avatar
NoSubject 已提交
454
            this.setActionDisabled(this.configAction);
NoSubject's avatar
NoSubject 已提交
455
            if (this.checkTextAction) this.setActionDisabled(this.checkTextAction);
NoSubject's avatar
NoSubject 已提交
456 457
            return false;
        }
NoSubject's avatar
NoSubject 已提交
458
        if (this.selectedAttachments.length) {
NoSubject's avatar
NoSubject 已提交
459
            var flag = true;
NoSubject's avatar
NoSubject 已提交
460
            var user = layout.session.user.distinguishedName;
NoSubject's avatar
NoSubject 已提交
461
            for (var i = 0; i < this.selectedAttachments.length; i++) {
R
roo00 已提交
462
                var att = this.selectedAttachments[i];
NoSubject's avatar
NoSubject 已提交
463 464
                if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
                if ((!att.data.control.allowControl) && att.data.person !== user) { //|| !att.data.control.allowEdit
NoSubject's avatar
NoSubject 已提交
465 466 467 468
                    flag = false;
                    break;
                }
            }
NoSubject's avatar
NoSubject 已提交
469
            if (flag) {
NoSubject's avatar
NoSubject 已提交
470
                this.setActionEnabled(this.configAction);
NoSubject's avatar
NoSubject 已提交
471
            } else {
NoSubject's avatar
NoSubject 已提交
472 473 474
                this.setActionDisabled(this.configAction);
            }
            //this.setActionEnabled(this.min_deleteAction);
NoSubject's avatar
NoSubject 已提交
475
        } else {
NoSubject's avatar
NoSubject 已提交
476 477 478 479
            this.setActionDisabled(this.configAction);
            //this.setActionDisabled(this.min_deleteAction);
        }

NoSubject's avatar
NoSubject 已提交
480
        if (this.checkTextAction) {
R
roo00 已提交
481
            this.setActionDisabled(this.checkTextAction);
NoSubject's avatar
NoSubject 已提交
482
            if (this.selectedAttachments.length && this.selectedAttachments.length === 1) {
R
roo00 已提交
483
                var att = this.selectedAttachments[0];
NoSubject's avatar
NoSubject 已提交
484
                if (this.options.images.indexOf(att.data.extension.toLowerCase()) !== -1) {
R
roo00 已提交
485 486
                    this.setActionEnabled(this.checkTextAction);
                }
NoSubject's avatar
NoSubject 已提交
487 488 489
            }
        }
    },
NoSubject's avatar
NoSubject 已提交
490 491 492
    isAttConfigAvailable: function (att) {
        if (this.options.readonly) return false;
        if (this.options.toolbarGroupHidden.contains("config")) return false;
R
roo00 已提交
493 494 495
        var user = layout.session.user.distinguishedName;
        var flag = true;

NoSubject's avatar
NoSubject 已提交
496
        if (!att.data.person && att.data.creatorUid) att.data.person = att.data.creatorUid;
R
roo00 已提交
497

NoSubject's avatar
NoSubject 已提交
498
        if ((!att.data.control.allowControl || !att.data.control.allowEdit) && att.data.person !== user) {
R
roo00 已提交
499 500 501 502
            flag = false;
        }
        return flag;
    },
NoSubject's avatar
NoSubject 已提交
503

NoSubject's avatar
NoSubject 已提交
504 505 506 507
    createEditGroupActions: function () {
        if (!this.editActionBoxNode) this.editActionBoxNode = new Element("div", { "styles": this.css.actionsBoxNode }).inject(this.topNode);
        if (!this.editActionsGroupNode) this.editActionsGroupNode = new Element("div", { "styles": this.css.actionsGroupNode }).inject(this.editActionBoxNode);
        this.uploadAction = this.createAction(this.editActionsGroupNode, "upload", o2.LP.widget.upload, function (e, node) {
R
roo00 已提交
508 509 510
            this.uploadAttachment(e, node);
        }.bind(this));

NoSubject's avatar
NoSubject 已提交
511
        this.deleteAction = this.createAction(this.editActionsGroupNode, "delete", o2.LP.widget["delete"], function (e, node) {
R
roo00 已提交
512 513 514
            this.deleteAttachment(e, node);
        }.bind(this));

NoSubject's avatar
NoSubject 已提交
515 516
        if (!this.options.isReplaceHidden) {
            this.replaceAction = this.createAction(this.editActionsGroupNode, "replace", o2.LP.widget.replace, function (e, node) {
R
roo00 已提交
517 518 519 520 521 522 523 524
                this.replaceAttachment(e, node);
            }.bind(this));
        }

        // this.officeAction = this.createAction(this.editActionsGroupNode, "office", o2.LP.widget.office, function(e, node){
        //     this.openInOfficeControl(e, node);
        // }.bind(this));

NoSubject's avatar
NoSubject 已提交
525
        if (!this.options.toolbarGroupHidden.contains("read")) this.editActionSeparateNode = this.createSeparate(this.editActionsGroupNode);
R
roo00 已提交
526
    },
NoSubject's avatar
NoSubject 已提交
527

NoSubject's avatar
NoSubject 已提交
528 529 530
    createConfigGroupActions: function () {
        this.configActionBoxNode = new Element("div", { "styles": this.css.actionsBoxNode }).inject(this.topNode);
        this.configActionsGroupNode = new Element("div", { "styles": this.css.actionsGroupNode }).inject(this.configActionBoxNode);
NoSubject's avatar
NoSubject 已提交
531

NoSubject's avatar
NoSubject 已提交
532
        this.configAction = this.createAction(this.configActionsGroupNode, "config", MWF.LP.widget.configAttachment, function (e, node) {
NoSubject's avatar
NoSubject 已提交
533 534 535
            this.configAttachment(e, node);
        }.bind(this));

NoSubject's avatar
NoSubject 已提交
536 537
        if (this.options.checkTextEnable) {
            this.checkTextAction = this.createAction(this.configActionsGroupNode, "check", MWF.LP.widget.checkOcrText, function (e, node) {
R
roo00 已提交
538 539 540
                this.checkImageTex(e, node);
            }.bind(this));
        }
R
roo00 已提交
541 542
        this.createSeparate(this.configActionsGroupNode);

NoSubject's avatar
NoSubject 已提交
543
        this.orderAction = this.createAction(this.configActionsGroupNode, "order", MWF.LP.widget.order, function (e, node) {
R
roo00 已提交
544 545
            this.orderAttachment(e, node);
        }.bind(this));
NoSubject's avatar
NoSubject 已提交
546 547 548 549

        if (this.configAction) this.setActionDisabled(this.configAction);
        if (this.checkTextAction) this.setActionDisabled(this.checkTextAction);
    },
NoSubject's avatar
NoSubject 已提交
550

NoSubject's avatar
NoSubject 已提交
551 552 553
    createOfficeGroupActions: function () {
        this.officeActionBoxNode = new Element("div", { "styles": this.css.actionsBoxNode }).inject(this.topNode);
        this.officeActionsGroupNode = new Element("div", { "styles": this.css.actionsGroupNode }).inject(this.officeActionBoxNode);
NoSubject's avatar
NoSubject 已提交
554

NoSubject's avatar
NoSubject 已提交
555
        this.closeOfficeAction = this.createAction(this.officeActionsGroupNode, "closeOffice", MWF.LP.widget.closeOffice, function (e, node) {
NoSubject's avatar
NoSubject 已提交
556 557 558 559
            this.closeAttachmentOffice(e, node);
        }.bind(this));
        if (this.closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
    },
NoSubject's avatar
NoSubject 已提交
560
    loadMinActions: function () {
R
roo00 已提交
561
        debugger;
R
roo00 已提交
562 563
        var hiddenGroup = this.options.toolbarGroupHidden;
        if (!hiddenGroup.contains("edit")) {
NoSubject's avatar
NoSubject 已提交
564
            this.min_uploadAction = this.createAction(this.minActionAreaNode, "upload", MWF.LP.widget.upload, function (e, node) {
R
roo00 已提交
565 566
                this.uploadAttachment(e, node);
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
567

NoSubject's avatar
NoSubject 已提交
568
            this.min_deleteAction = this.createAction(this.minActionAreaNode, "delete", MWF.LP.widget["delete"], function (e, node) {
R
roo00 已提交
569 570
                this.deleteAttachment(e, node);
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
571

NoSubject's avatar
NoSubject 已提交
572
            if (!this.options.isReplaceHidden) {
R
roo00 已提交
573 574 575 576
                this.min_replaceAction = this.createAction(this.minActionAreaNode, "replace", MWF.LP.widget.replace, function (e, node) {
                    this.replaceAttachment(e, node);
                }.bind(this));
            }
R
roo00 已提交
577 578
        }
        if (!hiddenGroup.contains("read")) {
R
roo00 已提交
579
            this.min_downloadAction = this.createAction(this.minActionAreaNode, "download", MWF.LP.widget.download
NoSubject's avatar
NoSubject 已提交
580 581 582
                , function (e, node) {
                    this.downloadAttachment(e, node);
                }.bind(this));
R
roo00 已提交
583
        }
NoSubject's avatar
NoSubject 已提交
584 585
        if (!hiddenGroup.contains("config")) {
            this.min_orderAction = this.createAction(this.minActionAreaNode, "order", MWF.LP.widget.order, function (e, node) {
R
roo00 已提交
586 587 588
                this.orderAttachment(e, node);
            }.bind(this));
        }
NoSubject's avatar
NoSubject 已提交
589

NoSubject's avatar
NoSubject 已提交
590 591
        if (this.module.json.isOpenInOffice && this.module.json.officeControlName) {
            this.min_closeOfficeAction = this.createAction(this.minActionAreaNode, "closeOffice", MWF.LP.widget.closeOffice, function (e, node) {
NoSubject's avatar
NoSubject 已提交
592 593 594 595 596 597
                this.closeAttachmentOffice(e, node);
            }.bind(this));
            if (this.min_closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
        }


NoSubject's avatar
NoSubject 已提交
598
        if (!hiddenGroup.contains("edit") || !hiddenGroup.contains("read")) {
NoSubject's avatar
NoSubject 已提交
599
            this.createSeparate(this.minActionAreaNode);
R
roo00 已提交
600
        }
NoSubject's avatar
NoSubject 已提交
601

R
roo00 已提交
602 603
        //this.createSeparate(this.configActionsGroupNode);

R
roo00 已提交
604 605
        if (this.options.isSizeChange) {
            //this.createSeparate(this.minActionAreaNode);
NoSubject's avatar
NoSubject 已提交
606
            if (!hiddenGroup.contains("view")) {
R
roo00 已提交
607 608 609 610
                this.sizeAction = this.createAction(this.minActionAreaNode, "max", MWF.LP.widget.min, function () {
                    this.changeControllerSize();
                }.bind(this));
            }
NoSubject's avatar
NoSubject 已提交
611
        }
NoSubject's avatar
NoSubject 已提交
612
    },
NoSubject's avatar
NoSubject 已提交
613
    closeAttachmentOffice: function () {
NoSubject's avatar
NoSubject 已提交
614
        var office = this.module.form.all[this.module.json.officeControlName];
NoSubject's avatar
NoSubject 已提交
615
        if (office) {
NoSubject's avatar
NoSubject 已提交
616 617 618 619
            office.openFile();
            if (this.min_closeOfficeAction) this.setActionDisabled(this.min_closeOfficeAction);
            if (this.closeOfficeAction) this.setActionDisabled(this.closeOfficeAction);
        }
NoSubject's avatar
NoSubject 已提交
620
    },
NoSubject's avatar
NoSubject 已提交
621
    configAttachment: function () {
NoSubject's avatar
NoSubject 已提交
622 623
        //this.fireEvent("delete", [attachment.data]);

NoSubject's avatar
NoSubject 已提交
624 625
        var lp = MWF.xApplication.process.Xform.LP;
        var css = this.module.form.css;
NoSubject's avatar
NoSubject 已提交
626 627 628 629 630 631 632 633
        var node = new Element("div", { "styles": css.attachmentPermissionNode }).inject(this.node);
        var attNames = new Element("div", { "styles": css.attachmentPermissionNamesNode }).inject(node);
        var attNamesTitle = new Element("div", { "styles": css.attachmentPermissionNamesTitleNode, "text": lp.attachmentPermissionInfo }).inject(attNames);
        var attNamesArea = new Element("div", { "styles": css.attachmentPermissionNamesAreaNode }).inject(attNames);

        if (this.selectedAttachments.length) {
            this.selectedAttachments.each(function (att) {
                var attNode = new Element("div", { "styles": css.attachmentPermissionAttNode, "text": att.data.name }).inject(attNamesArea);
NoSubject's avatar
NoSubject 已提交
634 635 636
            }.bind(this));
        }

NoSubject's avatar
NoSubject 已提交
637 638 639
        var editArea = new Element("div", { "styles": css.attachmentPermissionEditAreaNode }).inject(node);
        var title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentRead }).inject(editArea);
        var readInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
NoSubject's avatar
NoSubject 已提交
640

NoSubject's avatar
NoSubject 已提交
641 642
        title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentEdit }).inject(editArea);
        var editInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
NoSubject's avatar
NoSubject 已提交
643

NoSubject's avatar
NoSubject 已提交
644 645
        title = new Element("div", { "styles": css.attachmentPermissionTitleNode, "text": lp.attachmentController }).inject(editArea);
        var controllerInput = new Element("div", { "styles": css.attachmentPermissionInputNode }).inject(editArea);
NoSubject's avatar
NoSubject 已提交
646

NoSubject's avatar
NoSubject 已提交
647
        var dlg = o2.DL.open(Object.merge({
NoSubject's avatar
NoSubject 已提交
648
            "title": lp.attachmentPermission,
NoSubject's avatar
NoSubject 已提交
649
            "style": this.module.form.json.dialogStyle || "user",
NoSubject's avatar
NoSubject 已提交
650 651 652 653
            "isResize": false,
            "content": node,
            "buttonList": [
                {
NoSubject's avatar
NoSubject 已提交
654
                    "type": "ok",
NoSubject's avatar
NoSubject 已提交
655
                    "text": MWF.LP.process.button.ok,
NoSubject's avatar
NoSubject 已提交
656
                    "action": function () {
NoSubject's avatar
NoSubject 已提交
657 658 659 660 661
                        this.setAttachmentConfig(readInput, editInput, controllerInput);
                        dlg.close();
                    }.bind(this)
                },
                {
NoSubject's avatar
NoSubject 已提交
662
                    "type": "cancel",
NoSubject's avatar
NoSubject 已提交
663
                    "text": MWF.LP.process.button.cancel,
NoSubject's avatar
NoSubject 已提交
664
                    "action": function () { dlg.close(); }
NoSubject's avatar
NoSubject 已提交
665 666
                }
            ]
NoSubject's avatar
NoSubject 已提交
667
        }, (this.module.form.json.dialogOptions||{})));
NoSubject's avatar
NoSubject 已提交
668

NoSubject's avatar
NoSubject 已提交
669
        if (this.selectedAttachments.length === 1) {
NoSubject's avatar
NoSubject 已提交
670 671 672 673 674 675 676 677 678
            var data = this.selectedAttachments[0].data;

            var readUnitList = (data.readUnitList) || [];
            var readIdentityList = (data.readIdentityList) || [];
            var editUnitList = (data.editUnitList) || [];
            var editIdentityList = (data.editIdentityList) || [];
            var controllerUnitList = (data.controllerUnitList) || [];
            var controllerIdentityList = (data.controllerIdentityList) || [];

NoSubject's avatar
NoSubject 已提交
679
            readInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
NoSubject's avatar
NoSubject 已提交
680 681
                "types": ["unit", "identity"],
                "values": readUnitList.concat(readIdentityList).trim()
R
roo00 已提交
682
            }));
NoSubject's avatar
NoSubject 已提交
683
            editInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
NoSubject's avatar
NoSubject 已提交
684 685
                "types": ["unit", "identity"],
                "values": editUnitList.concat(editIdentityList).trim()
R
roo00 已提交
686
            }));
NoSubject's avatar
NoSubject 已提交
687
            controllerInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
NoSubject's avatar
NoSubject 已提交
688 689
                "types": ["unit", "identity"],
                "values": controllerUnitList.concat(controllerIdentityList).trim()
R
roo00 已提交
690
            }));
NoSubject's avatar
NoSubject 已提交
691 692 693 694 695 696 697 698 699 700
        } else {
            readInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
                "types": ["unit", "identity"]
            }));
            editInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
                "types": ["unit", "identity"]
            }));
            controllerInput.setSelectPerson(this.module.form.app.content, Object.merge(Object.clone(this.module.form.json.selectorStyle || {}), {
                "types": ["unit", "identity"]
            }));
NoSubject's avatar
NoSubject 已提交
701 702
        }
    },
NoSubject's avatar
NoSubject 已提交
703 704
    setAttachmentConfig: function (readInput, editInput, controllerInput) {
        if (this.selectedAttachments.length) {
NoSubject's avatar
NoSubject 已提交
705 706 707 708 709 710 711 712 713 714 715
            var readList = readInput.retrieve("data-value");
            var editList = editInput.retrieve("data-value");
            var controllerList = controllerInput.retrieve("data-value");

            var readUnitList = [];
            var readIdentityList = [];
            var editUnitList = [];
            var editIdentityList = [];
            var controllerUnitList = [];
            var controllerIdentityList = [];

NoSubject's avatar
NoSubject 已提交
716 717 718
            if (readList) {
                readList.each(function (v) {
                    var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
NoSubject's avatar
NoSubject 已提交
719
                    var len = vName.length;
NoSubject's avatar
NoSubject 已提交
720 721 722
                    var flag = vName.substring(len - 1, len);
                    if (flag === "U") readUnitList.push(vName);
                    if (flag === "I") readIdentityList.push(vName);
NoSubject's avatar
NoSubject 已提交
723 724
                });
            }
NoSubject's avatar
NoSubject 已提交
725 726 727
            if (editList) {
                editList.each(function (v) {
                    var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
NoSubject's avatar
NoSubject 已提交
728
                    var len = vName.length;
NoSubject's avatar
NoSubject 已提交
729 730 731
                    var flag = vName.substring(len - 1, len);
                    if (flag === "U") editUnitList.push(vName);
                    if (flag === "I") editIdentityList.push(vName);
NoSubject's avatar
NoSubject 已提交
732 733
                });
            }
NoSubject's avatar
NoSubject 已提交
734 735 736
            if (controllerList) {
                controllerList.each(function (v) {
                    var vName = (typeOf(v) === "string") ? v : v.distinguishedName;
NoSubject's avatar
NoSubject 已提交
737
                    var len = vName.length;
NoSubject's avatar
NoSubject 已提交
738 739 740
                    var flag = vName.substring(len - 1, len);
                    if (flag === "U") controllerUnitList.push(vName);
                    if (flag === "I") controllerIdentityList.push(vName);
NoSubject's avatar
NoSubject 已提交
741 742 743
                });
            }

NoSubject's avatar
NoSubject 已提交
744
            this.selectedAttachments.each(function (att) {
NoSubject's avatar
NoSubject 已提交
745 746 747 748 749 750 751 752 753 754 755 756
                att.data.readUnitList = readUnitList;
                att.data.readIdentityList = readIdentityList;
                att.data.editUnitList = editUnitList;
                att.data.editIdentityList = editIdentityList;
                att.data.controllerUnitList = controllerUnitList;
                att.data.controllerIdentityList = controllerIdentityList;

                o2.Actions.get("x_processplatform_assemble_surface").configAttachment(att.data.id, this.module.form.businessData.work.id, att.data);
            }.bind(this));
        }
    },

NoSubject's avatar
NoSubject 已提交
757 758
    checkImageTex: function () {
        if (this.selectedAttachments.length && this.selectedAttachments.length == 1) {
NoSubject's avatar
NoSubject 已提交
759 760 761 762
            var att = this.selectedAttachments[0];
            var lp = MWF.xApplication.process.Xform.LP;
            var css = this.module.form.css;

NoSubject's avatar
NoSubject 已提交
763 764 765
            var node = new Element("div", { "styles": css.attachmentOCRNode }).inject(this.node);
            var previewNode = new Element("div", { "styles": css.attachmentOCRImageAreaNode }).inject(node);
            var imgNode = new Element("img", { "styles": css.attachmentOCRImageNode }).inject(previewNode);
NoSubject's avatar
NoSubject 已提交
766

NoSubject's avatar
NoSubject 已提交
767
            o2.Actions.get("x_processplatform_assemble_surface").getAttachmentUrl(att.data.id, this.module.form.businessData.work.id, function (url) {
NoSubject's avatar
NoSubject 已提交
768 769 770
                imgNode.set("src", url);
            });

NoSubject's avatar
NoSubject 已提交
771 772
            var areaNode = new Element("div", { "styles": css.attachmentOCRInputAreaNode }).inject(node);
            var inputNode = new Element("textarea", { "styles": css.attachmentOCRInputNode }).inject(areaNode);
NoSubject's avatar
NoSubject 已提交
773 774 775

            var dlg = o2.DL.open({
                "title": lp.attachmentOCRTitle,
NoSubject's avatar
NoSubject 已提交
776
                "style": this.module.form.json.dialogStyle || "user",
NoSubject's avatar
NoSubject 已提交
777 778 779 780
                "isResize": false,
                "content": node,
                "buttonList": [
                    {
NoSubject's avatar
NoSubject 已提交
781
                        "type": "ok",
NoSubject's avatar
NoSubject 已提交
782
                        "text": MWF.LP.process.button.ok,
NoSubject's avatar
NoSubject 已提交
783
                        "action": function () {
NoSubject's avatar
NoSubject 已提交
784 785 786 787 788
                            this.setAttachmentOCR(inputNode, att);
                            dlg.close();
                        }.bind(this)
                    },
                    {
NoSubject's avatar
NoSubject 已提交
789
                        "type": "cancel",
NoSubject's avatar
NoSubject 已提交
790
                        "text": MWF.LP.process.button.cancel,
NoSubject's avatar
NoSubject 已提交
791
                        "action": function () { dlg.close(); }
NoSubject's avatar
NoSubject 已提交
792 793 794
                    }
                ]
            });
NoSubject's avatar
NoSubject 已提交
795
            if (att.data.ocr) {
NoSubject's avatar
NoSubject 已提交
796
                inputNode.set("text", att.data.ocr.text || "");
NoSubject's avatar
NoSubject 已提交
797 798
            } else {
                o2.Actions.get("x_processplatform_assemble_surface").getAttachmentOCR(att.data.id, this.module.form.businessData.work.id, function (json) {
NoSubject's avatar
NoSubject 已提交
799 800 801 802 803 804 805
                    att.data.ocr = json.data;
                    inputNode.set("text", json.data.text || "");
                }.bind(this))
            }

        }
    },
NoSubject's avatar
NoSubject 已提交
806
    setAttachmentOCR: function (inputNode, att) {
NoSubject's avatar
NoSubject 已提交
807 808 809 810 811
        var data = inputNode.get("text");
        if (!att.data.ocr) att.data.ocr = {};
        att.data.ocr.text = data;
        o2.Actions.get("x_processplatform_assemble_surface").setAttachmentOCR(att.data.id, this.module.form.businessData.work.id, {
            "text": data
NoSubject's avatar
NoSubject 已提交
812
        }, function () {
NoSubject's avatar
NoSubject 已提交
813 814
            this.module.form.app.notice("success", lp.attachmentOCR_saved, this.node);
        }.bind(this));
R
roo00 已提交
815
    },
NoSubject's avatar
NoSubject 已提交
816 817
    checkMoveAction: function (item) {
        if (item) {
R
roo00 已提交
818 819 820 821 822 823 824 825 826 827 828
            var actionArea = item.getFirst().getNext();
            var actionup = actionArea.getFirst().show();
            var actiondown = actionArea.getLast().show();

            tmp = item.getPrevious();
            if (!tmp) actionup.hide();

            tmp = item.getNext();
            if (!tmp) actiondown.hide();
        }
    },
NoSubject's avatar
NoSubject 已提交
829 830 831
    orderAttachment: function () {
        if (this.attachments.length) {
            this.attachments = this.attachments.sort(function (a1, a2) {
R
roo00 已提交
832 833
                if (!a2.data.orderNumber) return 1;
                if (!a1.data.orderNumber) return -1;
NoSubject's avatar
NoSubject 已提交
834
                return a1.data.orderNumber - a2.data.orderNumber;
R
roo00 已提交
835 836 837 838
            }.bind(this));

            var lp = MWF.xApplication.process.Xform.LP;
            var css = this.module.form.css;
NoSubject's avatar
NoSubject 已提交
839 840 841
            var node = new Element("div", { "styles": css.attachmentOrderNode });
            var infoNode = new Element("div", { "styles": css.attachmentOrderInforNode, "text": lp.attachmentOrderInfo }).inject(node);
            var attrchmentsNode = new Element("div", { "styles": css.attachmentOrderAreaNode }).inject(node);
R
roo00 已提交
842 843 844

            var iconUrl = "/x_component_File/$Main/icon.json";
            var icons = null;
NoSubject's avatar
NoSubject 已提交
845
            o2.getJSON(iconUrl, function (json) {
R
roo00 已提交
846 847 848
                icons = json;
            }.bind(this), false, false);

NoSubject's avatar
NoSubject 已提交
849
            this.attachments.each(function (att, idx) {
R
roo00 已提交
850
                var iconName = icons[att.data.extension.toLowerCase()] || icons.unknow;
NoSubject's avatar
NoSubject 已提交
851
                var iconFolderUrl = "/x_component_File/$Main/default/file/" + iconName;
R
roo00 已提交
852

NoSubject's avatar
NoSubject 已提交
853
                var itemNode = new Element("div", { "styles": css.attachmentOrderItemNode }).inject(attrchmentsNode);
R
roo00 已提交
854
                itemNode.store("att", att);
NoSubject's avatar
NoSubject 已提交
855 856
                var icon = new Element("div", { "styles": css.attachmentOrderItemIconNode }).inject(itemNode);
                icon.setStyle("background-image", "url('" + iconFolderUrl + "')");
R
roo00 已提交
857

NoSubject's avatar
NoSubject 已提交
858 859
                var actionArea = new Element("div", { "styles": css.attachmentOrderItemActionNode }).inject(itemNode);
                var text = new Element("div", { "styles": css.attachmentOrderItemTextNode, "text": att.data.name }).inject(itemNode);
R
roo00 已提交
860

NoSubject's avatar
NoSubject 已提交
861 862 863 864
                var actionUp = new Element("div", { "styles": css.attachmentOrderItemActionUpNode, "text": lp.attachmentOrderUp }).inject(actionArea);
                var actionDown = new Element("div", { "styles": css.attachmentOrderItemActionDownNode, "text": lp.attachmentOrderDown }).inject(actionArea);
                if (idx == 0) actionUp.hide();
                if (idx == this.attachments.length - 1) actionDown.hide();
R
roo00 已提交
865

NoSubject's avatar
NoSubject 已提交
866
                actionUp.addEvent("click", function (e) {
R
roo00 已提交
867 868
                    var itemNode = e.target.getParent().getParent();
                    var upNode = itemNode.getPrevious();
NoSubject's avatar
NoSubject 已提交
869
                    if (upNode) {
R
roo00 已提交
870 871 872 873 874 875 876 877
                        itemNode.inject(upNode, "before");
                        this.checkMoveAction(upNode);
                    }
                    this.checkMoveAction(itemNode);
                    itemNode.highlight();
                    //itemNode.setStyle("background-color", "#faf9f1");
                }.bind(this));

NoSubject's avatar
NoSubject 已提交
878
                actionDown.addEvent("click", function (e) {
R
roo00 已提交
879 880
                    var itemNode = e.target.getParent().getParent();
                    var downNode = itemNode.getNext();
NoSubject's avatar
NoSubject 已提交
881
                    if (downNode) {
R
roo00 已提交
882 883 884 885 886 887 888 889 890
                        itemNode.inject(downNode, "after");
                        this.checkMoveAction(downNode);
                    }
                    this.checkMoveAction(itemNode);
                    itemNode.highlight();
                    // /itemNode.setStyle("background-color", "#faf9f1");
                }.bind(this));

                itemNode.addEvents({
NoSubject's avatar
NoSubject 已提交
891 892
                    "mouseover": function (e) { this.setStyle("background-color", "#f1f6fa"); },
                    "mouseout": function (e) { this.setStyle("background-color", "#ffffff"); }
R
roo00 已提交
893 894 895 896 897 898 899 900 901
                });

                //var droppables = attrchmentsNode.getChildren();

                new Drag(itemNode, {
                    "handle": icon,
                    "snap": 5,
                    "stopPropagation": true,
                    "preventDefault": true,
NoSubject's avatar
NoSubject 已提交
902
                    onStart: function (el, e) {
R
roo00 已提交
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
                        var itemNode = el;
                        itemNode.setStyle("background-color", "#f1f6fa");
                        var moveNode = itemNode.clone(true).setStyles(css.attachmentOrderItemNode).setStyles({
                            "background-color": "#faf9f1",
                            "opacity": 0.8,
                            "border": "1px dotted #333333"
                        }).inject(node);
                        moveNode.position({
                            "relativeTo": itemNode,
                            "position": 'upperLeft',
                            "edge": 'upperLeft'
                        });
                        moveNode.owner = itemNode;

                        var move = new Drag.Move(moveNode, {
                            "container": node,
                            "droppables": attrchmentsNode.getChildren(),
NoSubject's avatar
NoSubject 已提交
920 921
                            "onEnter": function (el, drop) {
                                moveNode.flagNode = new Element("div", { "styles": css.attachmentOrderFlagNode }).inject(drop, "before");
R
roo00 已提交
922
                            },
NoSubject's avatar
NoSubject 已提交
923
                            "onLeave": function (el, drop) {
R
roo00 已提交
924 925
                                if (moveNode.flagNode) moveNode.flagNode.destroy();
                            },
NoSubject's avatar
NoSubject 已提交
926 927
                            "onDrop": function (el, drop) {
                                if (moveNode.flagNode) {
R
roo00 已提交
928 929 930 931 932 933 934 935 936 937 938 939 940 941
                                    moveNode.owner.inject(moveNode.flagNode, "after");
                                    moveNode.flagNode.destroy();
                                    moveNode.owner.highlight();
                                    this.checkMoveAction(moveNode.owner);
                                    this.checkMoveAction(drop);
                                    this.checkMoveAction(attrchmentsNode.getLast());
                                    moveNode.destroy()
                                }
                            }.bind(this)
                        });
                        move.start(e);


                    }.bind(this),
NoSubject's avatar
NoSubject 已提交
942
                    enter: function (el) {
R
roo00 已提交
943 944 945 946 947 948 949 950
                        el.removeClass('dragging');
                    }
                });
                //itemNode.dragMove


            }.bind(this));

NoSubject's avatar
NoSubject 已提交
951
            var dlg = o2.DL.open(Object.merge({
R
roo00 已提交
952
                "title": lp.attachmentOrderTitle,
NoSubject's avatar
NoSubject 已提交
953
                "style": this.module.form.json.dialogStyle || "user",
R
roo00 已提交
954 955
                "isResize": false,
                "content": node,
NoSubject's avatar
NoSubject 已提交
956 957
                "width": "auto",
                "height": "auto",
R
roo00 已提交
958 959
                "buttonList": [
                    {
NoSubject's avatar
NoSubject 已提交
960
                        "type": "ok",
R
roo00 已提交
961
                        "text": MWF.LP.process.button.ok,
NoSubject's avatar
NoSubject 已提交
962
                        "action": function () {
R
roo00 已提交
963 964 965 966 967
                            this.sortAttachment(attrchmentsNode);
                            dlg.close();
                        }.bind(this)
                    },
                    {
NoSubject's avatar
NoSubject 已提交
968
                        "type": "cancel",
R
roo00 已提交
969
                        "text": MWF.LP.process.button.cancel,
NoSubject's avatar
NoSubject 已提交
970
                        "action": function () { dlg.close(); }
R
roo00 已提交
971 972
                    }
                ],
NoSubject's avatar
NoSubject 已提交
973
                "onPostLoad": function () {
R
roo00 已提交
974 975 976 977
                    var dlg = this;
                    dlg.node.setStyle("display", "block");

                    var size = {};
NoSubject's avatar
NoSubject 已提交
978 979
                    if (css.attachmentOrderNode) {
                        if (parseFloat(css.attachmentOrderNode.width).toString() !== "NaN") {
R
roo00 已提交
980 981
                            size.x = parseInt(css.attachmentOrderNode.width)
                        }
NoSubject's avatar
NoSubject 已提交
982
                        if (parseFloat(css.attachmentOrderNode.height).toString() !== "NaN") {
R
roo00 已提交
983 984 985 986 987 988 989
                            size.y = parseInt(css.attachmentOrderNode.height)
                        }
                    }

                    node.show();
                    var nodeSize = node.getSize();
                    dlg.content.setStyles({
NoSubject's avatar
NoSubject 已提交
990 991
                        "width": size.x || nodeSize.x,
                        "height": size.y || nodeSize.y
R
roo00 已提交
992 993 994
                    });
                    dlg.setContentSize();
                }
NoSubject's avatar
NoSubject 已提交
995
            },  (this.module.form.json.dialogOptions||{})));
R
roo00 已提交
996 997
        }
    },
NoSubject's avatar
NoSubject 已提交
998
    sortAttachment: function (node) {
R
roo00 已提交
999
        var nodes = node.getChildren();
NoSubject's avatar
NoSubject 已提交
1000
        nodes.each(function (item, idx) {
R
roo00 已提交
1001
            var att = item.retrieve("att", null);
NoSubject's avatar
NoSubject 已提交
1002
            if (att) {
R
roo00 已提交
1003 1004 1005 1006
                att.data.orderNumber = idx;
                o2.Actions.load("x_processplatform_assemble_surface").AttachmentAction.changeOrderNumber(att.data.id, this.module.form.businessData.work.id, idx);
            }
        }.bind(this));
NoSubject's avatar
NoSubject 已提交
1007
        this.attachments = this.attachments.sort(function (a1, a2) {
R
roo00 已提交
1008 1009
            if (!a2.data.orderNumber) return 1;
            if (!a1.data.orderNumber) return -1;
NoSubject's avatar
NoSubject 已提交
1010
            return a1.data.orderNumber - a2.data.orderNumber;
R
roo00 已提交
1011 1012 1013 1014
        }.bind(this));

        this.reloadAttachments();
        this.fireEvent("order");
NoSubject's avatar
NoSubject 已提交
1015
    }
R
roo00 已提交
1016

NoSubject's avatar
NoSubject 已提交
1017
});
NoSubject's avatar
NoSubject 已提交
1018 1019
MWF.xApplication.process.Xform.Attachment = MWF.APPAttachment = new Class({
    Extends: MWF.APP$Module,
NoSubject's avatar
NoSubject 已提交
1020
    options: {
R
roo00 已提交
1021
        "moduleEvents": ["upload", "delete", "afterDelete", "load", "change"]
NoSubject's avatar
NoSubject 已提交
1022 1023
    },

NoSubject's avatar
NoSubject 已提交
1024
    initialize: function (node, json, form, options) {
NoSubject's avatar
NoSubject 已提交
1025 1026 1027 1028 1029 1030 1031
        this.node = $(node);
        this.node.store("module", this);
        this.json = json;
        this.form = form;
        this.field = true;
    },

NoSubject's avatar
NoSubject 已提交
1032 1033
    _loadUserInterface: function () {
        this.node.empty();
NoSubject's avatar
NoSubject 已提交
1034 1035
        this.loadAttachmentController();
        this.fireEvent("load");
NoSubject's avatar
NoSubject 已提交
1036 1037
    },
    loadAttachmentController: function () {
NoSubject's avatar
NoSubject 已提交
1038
        //MWF.require("MWF.widget.AttachmentController", function() {
NoSubject's avatar
NoSubject 已提交
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
        var options = {
            "style": this.json.style || "default",
            "title": "附件区域",
            "listStyle": this.json.listStyle || "icon",
            "size": this.json.size || "max",
            "resize": (this.json.resize === "y" || this.json.resize === "true"),
            "attachmentCount": this.json.attachmentCount || 0,
            "isUpload": (this.json.isUpload === "y" || this.json.isUpload === "true"),
            "isDelete": (this.json.isDelete === "y" || this.json.isDelete === "true"),
            "isReplace": (this.json.isReplace === "y" || this.json.isReplace === "true"),
            "isDownload": (this.json.isDownload === "y" || this.json.isDownload === "true"),
            "isSizeChange": (this.json.isSizeChange === "y" || this.json.isSizeChange === "true"),
            "readonly": (this.json.readonly === "y" || this.json.readonly === "true"),
            "availableListStyles": this.json.availableListStyles ? this.json.availableListStyles : ["list", "seq", "icon", "preview"],
            "isDeleteOption": this.json.isDelete,
            "isReplaceOption": this.json.isReplace,
            "toolbarGroupHidden": this.json.toolbarGroupHidden || [],
            "onOrder": function () {
                this.fireEvent("change");
            }.bind(this)
        };
        if (this.readonly) options.readonly = true;
        if (this.form.json.attachmentStyle) {
            options = Object.merge(options, this.form.json.attachmentStyle);
        }
        //this.attachmentController = new MWF.widget.ATTER(this.node, this, options);
NoSubject's avatar
NoSubject 已提交
1065

NoSubject's avatar
NoSubject 已提交
1066 1067
        this.attachmentController = new MWF.xApplication.process.Xform.AttachmentController(this.node, this, options);
        this.attachmentController.load();
NoSubject's avatar
NoSubject 已提交
1068

NoSubject's avatar
NoSubject 已提交
1069 1070 1071 1072 1073
        this.form.businessData.attachmentList.each(function (att) {
            //if (att.site===this.json.id || (this.json.isOpenInOffice && this.json.officeControlName===att.site)) this.attachmentController.addAttachment(att);
            if (att.site === this.json.id) this.attachmentController.addAttachment(att);
        }.bind(this));
        this.setAttachmentBusinessData();
NoSubject's avatar
NoSubject 已提交
1074 1075
        //}.bind(this));
    },
NoSubject's avatar
NoSubject 已提交
1076 1077 1078 1079
    setAttachmentBusinessData: function () {
        if (this.attachmentController) {
            if (this.attachmentController.attachments.length) {
                var values = this.attachmentController.attachments.map(function (d) {
R
roo00 已提交
1080 1081 1082
                    return d.data.name;
                });
                this._setBusinessData(values);
NoSubject's avatar
NoSubject 已提交
1083
            } else {
R
roo00 已提交
1084 1085 1086 1087
                this._setBusinessData([]);
            }
        }
    },
NoSubject's avatar
NoSubject 已提交
1088

NoSubject's avatar
NoSubject 已提交
1089 1090 1091 1092 1093
    _loadEvents: function (editorConfig) {
        Object.each(this.json.events, function (e, key) {
            if (e.code) {
                if (this.options.moduleEvents.indexOf(key) !== -1) {
                    this.addEvent(key, function (event) {
NoSubject's avatar
NoSubject 已提交
1094 1095
                        return this.form.Macro.fire(e.code, this, event);
                    }.bind(this));
NoSubject's avatar
NoSubject 已提交
1096 1097
                } else {
                    this.node.addEvent(key, function (event) {
NoSubject's avatar
NoSubject 已提交
1098 1099 1100 1101 1102 1103 1104
                        return this.form.Macro.fire(e.code, this, event);
                    }.bind(this));
                }
            }
        }.bind(this));

    },
NoSubject's avatar
NoSubject 已提交
1105
    getData: function () {
NoSubject's avatar
NoSubject 已提交
1106 1107
        return this.attachmentController.getAttachmentNames();
    },
NoSubject's avatar
NoSubject 已提交
1108
    createUploadFileNode: function () {
NoSubject's avatar
NoSubject 已提交
1109
        var accept = "*";
NoSubject's avatar
NoSubject 已提交
1110 1111
        if (!this.json.attachmentExtType || (this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType)) {
        } else {
NoSubject's avatar
NoSubject 已提交
1112 1113
            accepts = [];
            var otherType = this.json.attachmentExtOtherType;
NoSubject's avatar
NoSubject 已提交
1114
            this.json.attachmentExtType.each(function (v) {
NoSubject's avatar
NoSubject 已提交
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
                switch (v) {
                    case "word":
                        accepts.push(".doc, .docx, .dot, .dotx");
                        break;
                    case "excel":
                        accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
                        break;
                    case "ppt":
                        accepts.push(".pptx, .ppt, .pot, .potx, .potm");
                        break;
                    case "txt":
                        accepts.push(".txt");
                        break;
                    case "pic":
R
roo00 已提交
1129
                        accepts.push(".bmp, .gif, .psd, .jpeg, .jpg, .png");
NoSubject's avatar
NoSubject 已提交
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146
                        break;
                    case "pdf":
                        accepts.push(".pdf");
                        break;
                    case "zip":
                        accepts.push(".zip, .rar");
                        break;
                    case "audio":
                        accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
                        break;
                    case "video":
                        accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
                        break;
                    case "other":
                        if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
                        break;
                }
1147
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
1148 1149 1150 1151
            accept = accepts.join(", ");
        }
        var size = 0;
        if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
NoSubject's avatar
NoSubject 已提交
1152 1153 1154 1155 1156
        this.attachmentController.doUploadAttachment({ "site": this.json.id }, this.form.workAction.action, "uploadAttachment", { "id": this.form.businessData.work.id }, null, function (o) {
            if (o.id) {
                this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function (json) {
                    if (json.data) {
                        if (!json.data.control) json.data.control = {};
NoSubject's avatar
NoSubject 已提交
1157 1158
                        this.attachmentController.addAttachment(json.data);
                    }
NoSubject's avatar
NoSubject 已提交
1159 1160
                    this.attachmentController.checkActions();

R
roo00 已提交
1161
                    this.setAttachmentBusinessData();
NoSubject's avatar
NoSubject 已提交
1162
                    this.fireEvent("upload", [json.data]);
R
roo00 已提交
1163
                    this.fireEvent("change");
NoSubject's avatar
NoSubject 已提交
1164 1165 1166
                }.bind(this))
            }
            this.attachmentController.checkActions();
NoSubject's avatar
NoSubject 已提交
1167 1168 1169
        }.bind(this), function (files) {
            if (files.length) {
                if ((files.length + this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount > 0) {
NoSubject's avatar
NoSubject 已提交
1170 1171 1172 1173 1174 1175 1176
                    var content = MWF.xApplication.process.Xform.LP.uploadMore;
                    content = content.replace("{n}", this.attachmentController.options.attachmentCount);
                    this.form.notice(content, "error");
                    return false;
                }
            }
            return true;
NoSubject's avatar
NoSubject 已提交
1177
        }.bind(this), true, accept, size);
NoSubject's avatar
NoSubject 已提交
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218


        // this.uploadFileAreaNode = new Element("div");
        // var html = "<input name=\"file\" type=\"file\" multiple/>";
        // this.uploadFileAreaNode.set("html", html);
        //
        // this.fileUploadNode = this.uploadFileAreaNode.getFirst();
        // this.fileUploadNode.addEvent("change", function(){
        //
        //     var files = this.fileUploadNode.files;
        //     if (files.length){
        //         if ((files.length+this.attachmentController.attachments.length > this.attachmentController.options.attachmentCount) && this.attachmentController.options.attachmentCount>0){
        //             var content = MWF.xApplication.process.Xform.LP.uploadMore;
        //             content = content.replace("{n}", this.attachmentController.options.attachmentCount);
        //             this.form.notice(content, "error");
        //         }else{
        //             for (var i = 0; i < files.length; i++) {
        //                 var file = files.item(i);
        //
        //                 var formData = new FormData();
        //                 formData.append('site', this.json.id);
        //                 formData.append('file', file);
        //
        //                 //formData.append('folder', folderId);
        //
        //                 this.form.workAction.uploadAttachment(this.form.businessData.work.id ,function(o, text){
        //                     if (o.id){
        //                         this.form.workAction.getAttachment(o.id, this.form.businessData.work.id, function(json){
        //                             if (json.data) this.attachmentController.addAttachment(json.data);
        //                             this.attachmentController.checkActions();
        //
        //                             this.fireEvent("upload", [json.data]);
        //                         }.bind(this))
        //                     }
        //                     this.attachmentController.checkActions();
        //                 }.bind(this), null, formData, file);
        //             }
        //         }
        //     }
        // }.bind(this));
    },
NoSubject's avatar
NoSubject 已提交
1219 1220
    uploadAttachment: function (e, node) {
        if (window.o2android && window.o2android.uploadAttachment) {
NoSubject's avatar
NoSubject 已提交
1221
            window.o2android.uploadAttachment(this.json.id);
NoSubject's avatar
NoSubject 已提交
1222 1223 1224
        } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.uploadAttachment) {
            window.webkit.messageHandlers.uploadAttachment.postMessage({ "site": this.json.id });
        } else {
NoSubject's avatar
NoSubject 已提交
1225
            // if (!this.uploadFileAreaNode){
NoSubject's avatar
NoSubject 已提交
1226
            this.createUploadFileNode();
NoSubject's avatar
NoSubject 已提交
1227 1228 1229 1230
            // }
            // this.fileUploadNode.click();
        }
    },
NoSubject's avatar
NoSubject 已提交
1231
    deleteAttachments: function (e, node, attachments) {
NoSubject's avatar
NoSubject 已提交
1232
        var names = [];
NoSubject's avatar
NoSubject 已提交
1233
        attachments.each(function (attachment) {
NoSubject's avatar
NoSubject 已提交
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
            names.push(attachment.data.name);
        }.bind(this));

        // if ((window.o2 && window.o2.replaceAttachment) || (window.webkit && window.webkit.messageHandlers)){
        //     if (window.confirm(MWF.xApplication.process.Xform.LP.deleteAttachment+"( "+names.join(", ")+" )")){
        //         while (attachments.length){
        //             attachment = attachments.shift();
        //             this.deleteAttachment(attachment);
        //         }
        //     }
        // }else {
        // var tmpNode = new Element("div", {
        //     "styles": {
        //         "background-color": "#0000ff",
        //         "border-style": "solid",
        //         "border-color": "#fff",
        //         "border-width": "1",
        //         "box-shadow": "0px 0px 20px #999",
        //         "z-index": "20000",
        //         "overflow": "hidden",
        //         "font-size": "14px",
        //         "height": "160px",
        //         "padding": "0px",
        //         "width": "300px",
        //         "position": "absolute",
        //         "top": "50px",
        //         "left": "20px",
        //         "opacity": 1,
        //         "border-radius": "5px"
        //     }
        // }).inject(this.form.app.content);

        var _self = this;
NoSubject's avatar
NoSubject 已提交
1267 1268
        this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.deleteAttachmentTitle, MWF.xApplication.process.Xform.LP.deleteAttachment + "( " + names.join(", ") + " )", 300, 120, function () {
            while (attachments.length) {
NoSubject's avatar
NoSubject 已提交
1269 1270 1271 1272
                var attachment = attachments.shift();
                _self.deleteAttachment(attachment);
            }
            this.close();
NoSubject's avatar
NoSubject 已提交
1273
        }, function () {
NoSubject's avatar
NoSubject 已提交
1274
            this.close();
NoSubject's avatar
NoSubject 已提交
1275
        }, null, null, this.form.json.confirmStyle);
NoSubject's avatar
NoSubject 已提交
1276
    },
NoSubject's avatar
NoSubject 已提交
1277
    deleteAttachment: function (attachment) {
NoSubject's avatar
NoSubject 已提交
1278
        this.fireEvent("delete", [attachment.data]);
NoSubject's avatar
NoSubject 已提交
1279
        var id = attachment.data.id;
NoSubject's avatar
NoSubject 已提交
1280
        this.form.workAction.deleteAttachment(attachment.data.id, this.form.businessData.work.id, function (josn) {
NoSubject's avatar
NoSubject 已提交
1281 1282
            this.attachmentController.removeAttachment(attachment);
            this.attachmentController.checkActions();
NoSubject's avatar
NoSubject 已提交
1283

NoSubject's avatar
NoSubject 已提交
1284 1285 1286 1287
            if (this.form.officeList) {
                this.form.officeList.each(function (office) {
                    if (office.openedAttachment) {
                        if (office.openedAttachment.id == id) {
NoSubject's avatar
NoSubject 已提交
1288 1289 1290 1291 1292
                            office.loadOfficeEdit();
                        }
                    }
                }.bind(this));
            }
R
roo00 已提交
1293
            this.setAttachmentBusinessData();
NoSubject's avatar
NoSubject 已提交
1294
            this.fireEvent("afterDelete", [attachment.data]);
R
roo00 已提交
1295
            this.fireEvent("change");
NoSubject's avatar
NoSubject 已提交
1296 1297 1298
        }.bind(this));
    },

NoSubject's avatar
NoSubject 已提交
1299 1300
    replaceAttachment: function (e, node, attachment) {
        if (window.o2android && window.o2android.replaceAttachment) {
NoSubject's avatar
NoSubject 已提交
1301
            window.o2android.replaceAttachment(attachment.data.id, this.json.id);
NoSubject's avatar
NoSubject 已提交
1302 1303 1304
        } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.replaceAttachment) {
            window.webkit.messageHandlers.replaceAttachment.postMessage({ "id": attachment.data.id, "site": this.json.id });
        } else {
NoSubject's avatar
NoSubject 已提交
1305
            var _self = this;
NoSubject's avatar
NoSubject 已提交
1306
            this.form.confirm("warn", e, MWF.xApplication.process.Xform.LP.replaceAttachmentTitle, MWF.xApplication.process.Xform.LP.replaceAttachment + "( " + attachment.data.name + " )", 350, 120, function () {
NoSubject's avatar
NoSubject 已提交
1307 1308
                _self.replaceAttachmentFile(attachment);
                this.close();
NoSubject's avatar
NoSubject 已提交
1309
            }, function () {
NoSubject's avatar
NoSubject 已提交
1310
                this.close();
NoSubject's avatar
NoSubject 已提交
1311
            }, null, null, this.form.json.confirmStyle);
NoSubject's avatar
NoSubject 已提交
1312 1313 1314
        }
    },

NoSubject's avatar
NoSubject 已提交
1315
    createReplaceFileNode: function (attachment) {
NoSubject's avatar
NoSubject 已提交
1316
        var accept = "*";
NoSubject's avatar
NoSubject 已提交
1317 1318
        if (!this.json.attachmentExtType || this.json.attachmentExtType.indexOf("other") != -1 && !this.json.attachmentExtOtherType) {
        } else {
NoSubject's avatar
NoSubject 已提交
1319 1320
            accepts = [];
            var otherType = this.json.attachmentExtOtherType;
NoSubject's avatar
NoSubject 已提交
1321
            this.json.attachmentExtType.each(function (v) {
NoSubject's avatar
NoSubject 已提交
1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
                switch (v) {
                    case "word":
                        accepts.push(".doc, .docx, .dot, .dotx");
                        break;
                    case "excel":
                        accepts.push(".xls, .xlsx, .xlsm, .xlt, .xltx");
                        break;
                    case "ppt":
                        accepts.push(".pptx, .ppt, .pot, .potx, .potm");
                        break;
                    case "txt":
                        accepts.push(".txt");
                        break;
                    case "pic":
                        accepts.push(".bmp, .gif, .psd, .jpeg, .jpg");
                        break;
                    case "pdf":
                        accepts.push(".pdf");
                        break;
                    case "zip":
                        accepts.push(".zip, .rar");
                        break;
                    case "audio":
                        accepts.push(".mp3, .wav, .wma, .wmv, .flac, .ape");
                        break;
                    case "video":
                        accepts.push(".avi, .mkv, .mov, .ogg, .mp4, .mpeg");
                        break;
                    case "other":
                        if (this.json.attachmentExtOtherType) accepts.push(this.json.attachmentExtOtherType);
                        break;
                }
            });
            accept = accepts.join(", ");
        }
        var size = 0;
        if (this.json.attachmentSize) size = this.json.attachmentSize.toFloat();
NoSubject's avatar
NoSubject 已提交
1359 1360 1361 1362 1363 1364 1365 1366
        this.attachmentController.doUploadAttachment({ "site": this.json.id }, this.form.workAction.action, "replaceAttachment",
            { "id": attachment.data.id, "workid": this.form.businessData.work.id }, null, function (o) {
                this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function (json) {
                    attachment.data = json.data;
                    attachment.reload();
                    this.attachmentController.checkActions();
                }.bind(this))
            }.bind(this), null, true, accept, size);
NoSubject's avatar
NoSubject 已提交
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395

        // this.replaceFileAreaNode = new Element("div");
        // var html = "<input name=\"file\" type=\"file\" multiple/>";
        // this.replaceFileAreaNode.set("html", html);
        //
        // this.fileReplaceNode = this.replaceFileAreaNode.getFirst();
        // this.fileReplaceNode.addEvent("change", function(){
        //
        //     var files = this.fileReplaceNode.files;
        //     if (files.length){
        //         for (var i = 0; i < files.length; i++) {
        //             var file = files.item(i);
        //
        //             var formData = new FormData();
        //             formData.append('file', file);
        //         //    formData.append('site', this.json.id);
        //
        //             this.form.workAction.replaceAttachment(attachment.data.id, this.form.businessData.work.id ,function(o, text){
        //                 this.form.workAction.getAttachment(attachment.data.id, this.form.businessData.work.id, function(json){
        //                     attachment.data = json.data;
        //                     attachment.reload();
        //                     this.attachmentController.checkActions();
        //                 }.bind(this))
        //             }.bind(this), null, formData, file);
        //         }
        //     }
        // }.bind(this));
    },

NoSubject's avatar
NoSubject 已提交
1396
    replaceAttachmentFile: function (attachment) {
NoSubject's avatar
NoSubject 已提交
1397
        //if (!this.replaceFileAreaNode){
NoSubject's avatar
NoSubject 已提交
1398
        this.createReplaceFileNode(attachment);
NoSubject's avatar
NoSubject 已提交
1399 1400 1401
        // }
        // this.fileReplaceNode.click();
    },
NoSubject's avatar
NoSubject 已提交
1402 1403 1404 1405
    downloadAttachment: function (e, node, attachments) {
        if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
            attachments.each(function (att) {
                if (window.o2android && window.o2android.downloadAttachment) {
NoSubject's avatar
NoSubject 已提交
1406
                    window.o2android.downloadAttachment(att.data.id);
NoSubject's avatar
NoSubject 已提交
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418
                } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
                    window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
                } else {
                    if (layout.mobile) {
                        //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
                        this.form.workAction.getAttachmentUrl(att.data.id, this.form.businessData.work.id, function (url) {
                            var xtoken = Cookie.read("x-token");
                            window.location = url + "?x-token=" + xtoken;
                        });
                    } else {
                        this.form.workAction.getAttachmentStream(att.data.id, this.form.businessData.work.id);
                    }
NoSubject's avatar
NoSubject 已提交
1419 1420
                }
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
1421 1422 1423
        } else {
            attachments.each(function (att) {
                if (window.o2android && window.o2android.downloadAttachment) {
NoSubject's avatar
NoSubject 已提交
1424
                    window.o2android.downloadAttachment(att.data.id);
NoSubject's avatar
NoSubject 已提交
1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
                } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
                    window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
                } else {
                    if (layout.mobile) {
                        //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
                        this.form.workAction.getAttachmentWorkcompletedUrl(att.data.id, this.form.businessData.workCompleted.id, function (url) {
                            var xtoken = Cookie.read("x-token");
                            window.location = url + "?x-token=" + xtoken;
                        });
                    } else {
                        this.form.workAction.getWorkcompletedAttachmentStream(att.data.id, this.form.businessData.workCompleted.id);
                    }
NoSubject's avatar
NoSubject 已提交
1437 1438 1439 1440
                }
            }.bind(this));
        }
    },
NoSubject's avatar
NoSubject 已提交
1441 1442 1443 1444
    openAttachment: function (e, node, attachments) {
        if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
            attachments.each(function (att) {
                if (window.o2android && window.o2android.downloadAttachment) {
NoSubject's avatar
NoSubject 已提交
1445
                    window.o2android.downloadAttachment(att.data.id);
NoSubject's avatar
NoSubject 已提交
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
                } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
                    window.webkit.messageHandlers.downloadAttachment.postMessage({ "id": att.data.id, "site": this.json.id });
                } else {
                    if (layout.mobile) {
                        //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
                        this.form.workAction.getAttachmentUrl(att.data.id, this.form.businessData.work.id, function (url) {
                            var xtoken = Cookie.read("x-token");
                            window.location = url + "?x-token=" + xtoken;
                        });
                    } else {
                        this.form.workAction.getAttachmentData(att.data.id, this.form.businessData.work.id);
                    }

NoSubject's avatar
NoSubject 已提交
1459 1460
                }
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
1461 1462 1463
        } else {
            attachments.each(function (att) {
                if (window.o2android && window.o2android.downloadAttachment) {
NoSubject's avatar
NoSubject 已提交
1464
                    window.o2android.downloadAttachment(att.data.id);
NoSubject's avatar
NoSubject 已提交
1465
                } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.downloadAttachment) {
NoSubject's avatar
NoSubject 已提交
1466
                    window.webkit.messageHandlers.downloadAttachment.postMessage(att.data.id, this.json.id);
NoSubject's avatar
NoSubject 已提交
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477
                } else {

                    if (layout.mobile) {
                        //移动端 企业微信 钉钉 用本地打开 防止弹出自带浏览器 无权限问题
                        this.form.workAction.getAttachmentWorkcompletedUrl(att.data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id), function (url) {
                            var xtoken = Cookie.read("x-token");
                            window.location = url + "?x-token=" + xtoken;
                        });
                    } else {
                        this.form.workAction.getWorkcompletedAttachmentData(att.data.id, ((this.form.businessData.workCompleted) ? this.form.businessData.workCompleted.id : this.form.businessData.work.id));
                    }
NoSubject's avatar
NoSubject 已提交
1478 1479 1480 1481 1482
                }
            }.bind(this));
        }
        //this.downloadAttachment(e, node, attachment);
    },
NoSubject's avatar
NoSubject 已提交
1483 1484
    getAttachmentUrl: function (attachment, callback) {
        if (this.form.businessData.work && !this.form.businessData.work.completedTime) {
NoSubject's avatar
NoSubject 已提交
1485
            this.form.workAction.getAttachmentUrl(attachment.data.id, this.form.businessData.work.id, callback);
NoSubject's avatar
NoSubject 已提交
1486
        } else {
NoSubject's avatar
NoSubject 已提交
1487 1488 1489
            this.form.workAction.getAttachmentWorkcompletedUrl(attachment.data.id, this.form.businessData.workCompleted.id, callback);
        }
    },
NoSubject's avatar
NoSubject 已提交
1490
    createErrorNode: function (text) {
NoSubject's avatar
NoSubject 已提交
1491 1492 1493 1494 1495 1496
        var node = new Element("div");
        var iconNode = new Element("div", {
            "styles": {
                "width": "20px",
                "height": "20px",
                "float": "left",
NoSubject's avatar
NoSubject 已提交
1497
                "background": "url(" + "/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
NoSubject's avatar
NoSubject 已提交
1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510
            }
        }).inject(node);
        var textNode = new Element("div", {
            "styles": {
                "line-height": "20px",
                "margin-left": "20px",
                "color": "red",
                "word-break": "keep-all"
            },
            "text": text
        }).inject(node);
        return node;
    },
NoSubject's avatar
NoSubject 已提交
1511 1512
    notValidationMode: function (text) {
        if (!this.isNotValidationMode) {
NoSubject's avatar
NoSubject 已提交
1513 1514 1515 1516 1517 1518 1519 1520
            this.isNotValidationMode = true;
            this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
            this.node.setStyle("border", "1px solid red");

            this.errNode = this.createErrorNode(text).inject(this.node, "after");
            this.showNotValidationMode(this.node);
        }
    },
NoSubject's avatar
NoSubject 已提交
1521
    showNotValidationMode: function (node) {
NoSubject's avatar
NoSubject 已提交
1522
        var p = node.getParent("div");
NoSubject's avatar
NoSubject 已提交
1523 1524 1525
        if (p) {
            if (p.get("MWFtype") == "tab$Content") {
                if (p.getParent("div").getStyle("display") == "none") {
NoSubject's avatar
NoSubject 已提交
1526 1527 1528
                    var contentAreaNode = p.getParent("div").getParent("div");
                    var tabAreaNode = contentAreaNode.getPrevious("div");
                    var idx = contentAreaNode.getChildren().indexOf(p.getParent("div"));
NoSubject's avatar
NoSubject 已提交
1529
                    var tabNode = tabAreaNode.getLast().getFirst().getChildren()[idx];
NoSubject's avatar
NoSubject 已提交
1530 1531 1532 1533 1534 1535 1536
                    tabNode.click();
                    p = tabAreaNode.getParent("div");
                }
            }
            this.showNotValidationMode(p);
        }
    },
NoSubject's avatar
NoSubject 已提交
1537 1538
    validationMode: function () {
        if (this.isNotValidationMode) {
NoSubject's avatar
NoSubject 已提交
1539 1540
            this.isNotValidationMode = false;
            this.node.setStyles(this.node.retrieve("borderStyle"));
NoSubject's avatar
NoSubject 已提交
1541
            if (this.errNode) {
NoSubject's avatar
NoSubject 已提交
1542 1543 1544 1545 1546
                this.errNode.destroy();
                this.errNode = null;
            }
        }
    },
NoSubject's avatar
NoSubject 已提交
1547 1548 1549
    validationConfigItem: function (routeName, data) {
        var flag = (data.status == "all") ? true : (routeName == data.decision);
        if (flag) {
NoSubject's avatar
NoSubject 已提交
1550
            var n = this.getData();
NoSubject's avatar
NoSubject 已提交
1551 1552
            var v = (data.valueType == "value") ? n : n.length;
            switch (data.operateor) {
NoSubject's avatar
NoSubject 已提交
1553
                case "isnull":
NoSubject's avatar
NoSubject 已提交
1554
                    if (!v) {
NoSubject's avatar
NoSubject 已提交
1555 1556 1557 1558 1559
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "notnull":
NoSubject's avatar
NoSubject 已提交
1560
                    if (v) {
NoSubject's avatar
NoSubject 已提交
1561 1562 1563 1564 1565
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "gt":
NoSubject's avatar
NoSubject 已提交
1566
                    if (v > data.value) {
NoSubject's avatar
NoSubject 已提交
1567 1568 1569 1570 1571
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "lt":
NoSubject's avatar
NoSubject 已提交
1572
                    if (v < data.value) {
NoSubject's avatar
NoSubject 已提交
1573 1574 1575 1576 1577
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "equal":
NoSubject's avatar
NoSubject 已提交
1578
                    if (v == data.value) {
NoSubject's avatar
NoSubject 已提交
1579 1580 1581 1582 1583
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "neq":
NoSubject's avatar
NoSubject 已提交
1584
                    if (v != data.value) {
NoSubject's avatar
NoSubject 已提交
1585 1586 1587 1588 1589
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "contain":
NoSubject's avatar
NoSubject 已提交
1590
                    if (v.indexOf(data.value) != -1) {
NoSubject's avatar
NoSubject 已提交
1591 1592 1593 1594 1595
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
                case "notcontain":
NoSubject's avatar
NoSubject 已提交
1596
                    if (v.indexOf(data.value) == -1) {
NoSubject's avatar
NoSubject 已提交
1597 1598 1599 1600 1601 1602 1603 1604
                        this.notValidationMode(data.prompt);
                        return false;
                    }
                    break;
            }
        }
        return true;
    },
NoSubject's avatar
NoSubject 已提交
1605 1606 1607 1608
    validationConfig: function (routeName, opinion) {
        if (this.json.validationConfig) {
            if (this.json.validationConfig.length) {
                for (var i = 0; i < this.json.validationConfig.length; i++) {
NoSubject's avatar
NoSubject 已提交
1609 1610 1611 1612 1613 1614 1615 1616
                    var data = this.json.validationConfig[i];
                    if (!this.validationConfigItem(routeName, data)) return false;
                }
            }
            return true;
        }
        return true;
    },
NoSubject's avatar
NoSubject 已提交
1617 1618
    validation: function (routeName, opinion) {
        if (!this.validationConfig(routeName, opinion)) return false;
NoSubject's avatar
NoSubject 已提交
1619 1620 1621 1622 1623

        if (!this.json.validation) return true;
        if (!this.json.validation.code) return true;
        var flag = this.form.Macro.exec(this.json.validation.code, this);
        if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
NoSubject's avatar
NoSubject 已提交
1624
        if (flag.toString() != "true") {
NoSubject's avatar
NoSubject 已提交
1625 1626 1627 1628 1629 1630 1631
            this.notValidationMode(flag);
            return false;
        }
        return true;
    }

});