Main.js 30.5 KB
Newer Older
NoSubject's avatar
NoSubject 已提交
1
MWF.xApplication.process.Work.options = Object.clone(o2.xApplication.Common.options);
R
roo00 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14
MWF.xApplication.process.Work.options.multitask = true;
MWF.xApplication.process.Work.Main = new Class({
	Extends: MWF.xApplication.Common.Main,
	Implements: [Options, Events],

	options: {
		"style": "default",
		"name": "process.Work",
		"icon": "icon.png",
		"width": "1200",
		"height": "800",
		"title": MWF.xApplication.process.Work.LP.title,
        "workId": "",
15 16
        "draftId": "",
        "draft": null,
R
roo00 已提交
17 18
        "workCompletedId": "",
        "taskId": "",
NoSubject's avatar
NoSubject 已提交
19 20 21
        "jobId": "",
        "form": null,
        "priorityWork": "",
R
roo00 已提交
22 23
        "isControl": false,
        "taskObject": null,
NoSubject's avatar
NoSubject 已提交
24 25
        "readonly": false,
        "worklogType": "record" //record, worklog
R
roo00 已提交
26 27
	},
	onQueryLoad: function(){
28
	    debugger;
R
roo00 已提交
29
		this.lp = MWF.xApplication.process.Work.LP;
NoSubject's avatar
NoSubject 已提交
30 31
        if (!this.status) {
        } else {
R
roo00 已提交
32 33
            this.options.workId = this.status.workId;
            this.options.workCompletedId = this.status.workCompletedId;
NoSubject's avatar
NoSubject 已提交
34
            this.options.jobId = this.status.jobId;
35
            this.options.draftId = this.status.draftId;
NoSubject's avatar
NoSubject 已提交
36
            this.options.priorityWork = this.status.priorityWork;
NoSubject's avatar
NoSubject 已提交
37
            this.options.readonly = (this.status.readonly === "true");
R
roo00 已提交
38
        }
NoSubject's avatar
NoSubject 已提交
39
        this.action = MWF.Actions.get("x_processplatform_assemble_surface");
R
roo00 已提交
40
	},
NoSubject's avatar
NoSubject 已提交
41
    loadWorkApplication: function(callback, mask){
R
roo00 已提交
42 43 44
	    debugger;
        var maskStyle = (Browser.name=="firefox") ? "work_firefox" : "desktop";
        //alert(maskStyle);
NoSubject's avatar
NoSubject 已提交
45
        if (mask) this.mask = new MWF.widget.Mask({"style": maskStyle, "loading": mask});
NoSubject's avatar
NoSubject 已提交
46 47 48 49 50 51 52 53 54 55 56 57
        this.formNode = new Element("div", {"styles": this.css.formNode}).inject(this.node);
        if (!this.options.isRefresh){
            this.maxSize(function(){
                if (mask) this.mask.loadNode(this.content);
                this.loadWork();
            }.bind(this));
        }else{
            if (mask) this.mask.loadNode(this.content);
            this.loadWork();
        }
        if (callback) callback();
    },
R
roo00 已提交
58 59 60
	loadApplication: function(callback){
        this.node = new Element("div", {"styles": this.css.content}).inject(this.content);

NoSubject's avatar
NoSubject 已提交
61 62 63
        if (layout.mobile){
            this.loadWorkApplication(callback, false)
        }else{
NoSubject's avatar
NoSubject 已提交
64 65 66 67 68 69 70 71
            if (layout.viewMode=="Default"){
                MWF.require("MWF.widget.Mask", function(){
                    this.loadWorkApplication(callback, true);
                }.bind(this));
            }else{
                this.loadWorkApplication(callback, false);
            }

NoSubject's avatar
NoSubject 已提交
72
        }
R
roo00 已提交
73 74 75 76 77 78 79 80 81 82 83

        this.addEvent("postClose", function(){
            //this.refreshTaskCenter();
        }.bind(this));

        this.addKeyboardEvents();

    },
    refreshTaskCenter: function(){
	    if (this.desktop.apps){
            if (this.desktop.apps["TaskCenter"]){
84 85 86 87 88 89
                if(this.desktop.apps["TaskCenter"].content){
                    this.desktop.apps["TaskCenter"].content.unmask();
                }
                if(this.desktop.apps["TaskCenter"].refreshAll){
                    this.desktop.apps["TaskCenter"].refreshAll();
                }
R
roo00 已提交
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
            }
        }
    },
    addKeyboardEvents: function(){
        this.addEvent("keySave", function(e){
            this.keySave(e);
        }.bind(this));
    },
    keySave: function(e){
        if (this.appForm){
            if (!this.options.readonly){
                this.appForm.saveWork();
                e.preventDefault();
            }
        }
    },
    reload: function(data){
        if (this.form){
            this.formNode.empty();
            MWF.release(this.form);
            this.form = null;
        }
        if (data){
            this.parseData(data);
            this.openWork();
        }else{
            this.loadWork();
        }
    },
    loadWork: function(){
NoSubject's avatar
NoSubject 已提交
120
        var id = this.options.workCompletedId || this.options.workId || this.options.workid || this.options.workcompletedid;
NoSubject's avatar
NoSubject 已提交
121 122 123 124 125 126
        // var methods = {
        //     "loadWork": false,
        //     "getWorkControl": false,
        //     "getForm": false
        // };
        if (id){
127 128 129 130 131 132 133 134 135 136 137
            this.loadWorkByWork(id);
           // }.bind(this), "failure": function(){}}, [id, true, true, true], id);
        }else if (this.options.draftId || this.options.draftid){
            var draftId = this.options.draftId || this.options.draftid;
            MWF.Actions.get("x_processplatform_assemble_surface").getDraft(draftId, function(json){
                this.loadWorkByDraft(json.data.work, json.data.data);
            }.bind(this));
        }else if (this.options.draft){
            this.loadWorkByDraft(this.options.draft);
        }else if (this.options.jobId || this.options.jobid || this.options.job){
            var jobId = this.options.jobId || this.options.jobid || this.options.job;
NoSubject's avatar
NoSubject 已提交
138 139 140
            delete this.options.jobId;
            delete this.options.jobid;
            delete this.options.job;
141 142 143 144 145
            this.loadWorkByJob(jobId);
        }
    },
    loadWorkByWork: function(id){
        //var getWorkLogMothed = "getWorkLog";    //以前使用worklog,现在改成record了
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
        //var getWorkLogMothed = (this.options.worklogType.toLowerCase()==="worklog") ? "getWorkLog" : "getRecordLog";
        var loadFormFlag = false;
        var loadWorkFlag = false;

        var json_work, json_log, json_control, json_form;

        var check = function(){
            if (loadWorkFlag && loadFormFlag){
                if (json_work && json_control && json_form && json_log){
                    this.parseData(json_work.data, json_control.data, json_form.data, json_log.data, json_work.data.recordList, json_work.data.attachmentList);
                    if (this.mask) this.mask.hide();
                    //if (layout.mobile) this.loadMobileActions();
                    this.openWork();
                    this.unLoading();
                } else{
                    if (this.options.jobId || this.options.jobid || this.options.job){
                        delete this.options.workCompletedId;
                        delete this.options.workId;
                        delete this.options.workid;
                        delete this.options.workcompletedid;
                        this.loadWork();
                    }else{
                        this.close();
                    }
                }
            }
        }.bind(this);

174
        if (this.options.form && this.options.form.id){
175
            o2.Actions.invokeAsync([
176
                {"action": this.action, "name": "loadWorkV2"},
177
                {"action": this.action, "name": "getWorkLog"},
178
                {"action": this.action, "name": "getWorkControl"},
179
                {"action": this.action, "name": ((layout.mobile) ? "getFormV2Mobile": "getFormV2")}
180 181 182 183 184 185 186 187
            ], {"success": function(jsonWork, jsonLog, jsonControl, jsonForm){
                    json_work = jsonWork;
                    json_log = jsonLog;
                    json_control = jsonControl;
                    json_form = jsonForm;
                    loadWorkFlag = true;
                    loadFormFlag = true;
                    check();
NoSubject's avatar
NoSubject 已提交
188
                }.bind(this), "failure": function(){
NoSubject's avatar
NoSubject 已提交
189
                    //this.close();
190
                }.bind(this)}, id, id, id, [this.options.form.id]);
191
        }else{
192 193
            this.action.lookupFormWithWork(id, function(json){
                var formId = json.data.id;
194 195
                if (json.data.form){
                    json_form = json;
196 197
                    loadFormFlag = true;
                    check();
198 199 200 201 202 203 204 205 206 207 208
                }else{
                    this.action[((layout.mobile) ? "getFormV2Mobile": "getFormV2")](formId, function(formJson){
                        json_form = formJson;
                        loadFormFlag = true;
                        check();
                    }, function(){
                        loadFormFlag = true;
                        check();
                    });
                }

209 210 211 212
            }.bind(this), function(){
                loadFormFlag = true;
                check();
            });
213
            o2.Actions.invokeAsync([
214 215 216 217 218 219 220 221 222 223 224 225 226
                    {"action": this.action, "name": "loadWorkV2"},
                    {"action": this.action, "name": "getWorkLog"},
                    {"action": this.action, "name": "getWorkControl"}
                ], {"success": function(jsonWork, jsonLog, jsonControl){
                        json_work = jsonWork;
                        json_log = jsonLog;
                        json_control = jsonControl;
                        loadWorkFlag = true;
                        check();
                    }.bind(this), "failure": function(){
                        //this.close();
                    }.bind(this)}, id
            );
227
        }
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287

        // if (this.options.form && this.options.form.id && this.options.form.app){
        //     o2.Actions.invokeAsync([
        //         {"action": this.action, "name": "loadWork"},
        //         {"action": this.action, "name": "getWorkLog"},
        //         {"action": this.action, "name": "getRecordLog"},
        //         {"action": this.action, "name": "getWorkControl"},
        //         {"action": this.action, "name": "listAttachments"},
        //         {"action": this.action, "name": "getForm"}
        //     ], {"success": function(json_work, json_log, json_record, json_control, json_att, json_form){
        //             if (json_work && json_control && json_form && json_log && json_att){
        //                 this.parseData(json_work.data, json_control.data, json_form.data, json_log.data, json_record.data, json_att.data);
        //                 if (this.mask) this.mask.hide();
        //                 //if (layout.mobile) this.loadMobileActions();
        //                 this.openWork();
        //                 this.unLoading();
        //             } else{
        //                 if (this.options.jobId || this.options.jobid || this.options.job){
        //                     delete this.options.workCompletedId;
        //                     delete this.options.workId;
        //                     delete this.options.workid;
        //                     delete this.options.workcompletedid;
        //                     this.loadWork();
        //                 }else{
        //                     this.close();
        //                 }
        //             }
        //         }.bind(this), "failure": function(){
        //             //this.close();
        //         }.bind(this)}, id, id, id, id, id, [this.options.form.id, this.options.form.app]);
        // }else{
            // o2.Actions.invokeAsync([
            //     {"action": this.action, "name": "loadWork"},
            //     {"action": this.action, "name": "getWorkLog"},
            //     {"action": this.action, "name": "getRecordLog"},
            //     {"action": this.action, "name": "getWorkControl"},
            //     {"action": this.action, "name": "listAttachments"},
            //     {"action": this.action, "name": (layout.mobile) ? "getWorkFormMobile": "getWorkForm"}
            // ], {"success": function(json_work, json_log, json_record, json_control, json_att, json_form){
            //         if (json_work && json_control && json_form && json_log && json_att){
            //             this.parseData(json_work.data, json_control.data, json_form.data, json_log.data, json_record.data, json_att.data);
            //             if (this.mask) this.mask.hide();
            //             //if (layout.mobile) this.loadMobileActions();
            //             this.openWork();
            //             this.unLoading();
            //         } else{
            //             if (this.options.jobId || this.options.jobid || this.options.job){
            //                 delete this.options.workCompletedId;
            //                 delete this.options.workId;
            //                 delete this.options.workid;
            //                 delete this.options.workcompletedid;
            //                 this.loadWork();
            //             }else{
            //                 this.close();
            //             }
            //         }
            //     }.bind(this), "failure": function(){
            //         //this.close();
            //     }.bind(this)}, id);
        //}
288 289 290 291 292 293 294 295 296 297 298 299 300
    },
    loadWorkByJob: function(jobId){
        MWF.Actions.get("x_processplatform_assemble_surface").listWorkByJob(jobId, function(json){
            var workCompletedCount = json.data.workCompletedList.length;
            var workCount = json.data.workList.length;
            var count = workCount+workCompletedCount;
            if (count===1){
                this.options.workId = (json.data.workList.length) ? json.data.workList[0].id : json.data.workCompletedList[0].id;
                this.loadWork();
            }else if (count>1){
                var id = this.filterId(json.data.workList, json.data.workCompletedList, this.options.priorityWork);
                if (id) {
                    this.options.workId = id;
NoSubject's avatar
NoSubject 已提交
301 302
                    this.loadWork();
                }else{
NoSubject's avatar
NoSubject 已提交
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
                    if (this.options.choice){
                        var worksAreaNode = this.createWorksArea();
                        // for (var x=0;x<3;x++){
                        json.data.workList.each(function(work){
                            this.createWorkNode(work, worksAreaNode);
                        }.bind(this));
                        json.data.workCompletedList.each(function(work){
                            this.createWorkCompletedNode(work, worksAreaNode);
                        }.bind(this));
                        // }
                        if (this.mask) this.mask.hide();
                        this.formNode.setStyles(this.css.formNode_bg);
                    }else{
                        if (json.data.workList.length){
                            this.options.workId =  json.data.workList[0].id;
                        }else{
                            this.options.workId =  json.data.workCompletedList[0].id;
                        }
                        this.loadWork();
                    }
NoSubject's avatar
NoSubject 已提交
323
                }
324
            }else{
NoSubject's avatar
NoSubject 已提交
325
                this.close();
326
            }
NoSubject's avatar
NoSubject 已提交
327 328
        }.bind(this), function(){
            this.close();
329
        }.bind(this));
NoSubject's avatar
NoSubject 已提交
330
    },
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
    loadWorkByDraft: function(work, data){
	    debugger;
        o2.Actions.invokeAsync([
            {"action": this.action, "name": (layout.mobile) ? "getFormMobile": "getForm"}
        ], {"success": function(json_form){
            if (json_form){
                var workData = {
                    "activity": {},
                    "data": data || {},
                    "taskList": [],
                    "work": work
                };
                var control = {
                    "allowVisit": true,
                    "allowProcessing": true,
                    "allowSave": true,
347
                    "allowDelete": true
348 349 350 351 352 353 354 355 356 357 358 359
                };

                this.parseData(workData, control, json_form.data, [], [], []);
                if (this.mask) this.mask.hide();
                //if (layout.mobile) this.loadMobileActions();
                this.openWork();
                this.unLoading();

            }
        }.bind(this), "failure": function(){}}, [work.form, work.application]);
    },

NoSubject's avatar
NoSubject 已提交
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
    createWorkNode: function(work, node, completed){
	    var contentNode = node.getLast();
	    var workNode = new Element("div", {"styles": this.css.workItemNode}).inject(contentNode);
        var titleNode = new Element("div", {"styles": this.css.workItemTitleNode}).inject(workNode);
        titleNode.set("text", work.title);
        var inforNode = new Element("div", {"styles": this.css.workItemInforNode}).inject(workNode);

        if (completed){
            inforNode.set("text", this.lp.completedWork);
        }else{
            var activityTitleNode = new Element("div", {"styles": this.css.workItemInforTitleNode, "text": this.lp.currentActivity}).inject(inforNode);
            var activityContentNode = new Element("div", {"styles": this.css.workItemInforContentNode, "text": work.activityName}).inject(inforNode);

            var userTitleNode = new Element("div", {"styles": this.css.workItemInforTitleNode, "text": this.lp.currentUsers}).inject(inforNode);
            var taskUsers = [];
            MWF.Actions.get("x_processplatform_assemble_surface").listTaskByWork(work.id, function(json){
                json.data.each(function(task){
                    taskUsers.push(MWF.name.cn(task.person));
                }.bind(this));
                var activityContentNode = new Element("div", {"styles": this.css.workItemInforContentNode, "text": taskUsers.join(", ")}).inject(inforNode);
            }.bind(this));
        }

        var _self = this;
        workNode.store("workId", work.id);
        workNode.addEvents({
            "mouseover": function(){
                this.addClass("mainColor_border");
                this.setStyles(_self.css.workItemNode_over);
            },
            "mouseout": function(){
                this.removeClass("mainColor_border");
                this.setStyles(_self.css.workItemNode);
            },
            "click": function(){
                var id = this.retrieve("workId");
                if (id){
                    _self.options.workId = id;
                    _self.loadWork();
                }
            },
        });
    },
    createWorksArea: function(){
        var node = new Element("div", {"styles": this.css.workListArea}).inject(this.formNode);
        var titleNode = new Element("div", {"styles": this.css.workListAreaTitle, "text": this.lp.selectWork}).inject(node);
        var contentNode = new Element("div", {"styles": this.css.workListContent}).inject(node);
        return node;
    },
    filterId: function(list, completedList, id){
	    if (!id) return "";
        if (!list.length && !completedList.length) return "";
        if (list.length){
            var o = list.filter(function(work){
                return work.id == id;
            }.bind(this));
            if (o.length) return o[0].id;
        }
        if (completedList.length) {
            o = completedList.filter(function(work){
                return work.id == id;
            }.bind(this));
            return (o.length) ? o[0].id : "";
        }
        return "";
    },
    parseData: function(workData, controlData, formData, logData, recordData, attData){
NoSubject's avatar
NoSubject 已提交
427 428
        debugger;

NoSubject's avatar
NoSubject 已提交
429
        var title = workData.work.title;
NoSubject's avatar
NoSubject 已提交
430 431 432 433 434 435 436 437 438 439 440 441
        //this.setTitle(this.options.title+"-"+title);
        this.setTitle(title || this.options.title);

        //routeList 等字段放在 properties 中了,这段代码是兼容以前的脚本
        //( workData.taskList || [] ).each(function(task){
        //    if( task.properties && typeOf( task.properties ) === "object"){
        //        if( !task.routeList )task.routeList = task.properties.routeList;
        //        if( !task.routeNameList )task.routeNameList = task.properties.routeNameList;
        //        if( !task.routeOpinionList )task.routeOpinionList = task.properties.routeOpinionList;
        //        if( !task.routeDecisionOpinionList )task.routeDecisionOpinionList = task.properties.routeDecisionOpinionList;
        //    }
        //});
R
roo00 已提交
442

NoSubject's avatar
NoSubject 已提交
443 444 445 446 447 448 449 450
        this.activity = workData.activity;
        this.data = workData.data;
        this.taskList = workData.taskList;
        this.currentTask = this.getCurrentTaskData(workData);
        this.taskList = workData.taskList;
        this.readList = workData.readList;
        this.work = workData.work;
        this.workCompleted = (workData.work.completedTime) ? workData.work : null;
R
roo00 已提交
451

NoSubject's avatar
NoSubject 已提交
452
        this.workLogList = logData;
NoSubject's avatar
NoSubject 已提交
453
        this.recordList = recordData;
NoSubject's avatar
NoSubject 已提交
454 455
        this.attachmentList = attData;
        //this.inheritedAttachmentList = data.inheritedAttachmentList;
R
roo00 已提交
456

NoSubject's avatar
NoSubject 已提交
457

NoSubject's avatar
NoSubject 已提交
458
        this.control = controlData;
459
        if (formData){
NoSubject's avatar
NoSubject 已提交
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
            if (formData.form){
                this.form = (formData.form.data) ? JSON.decode(MWF.decodeJsonString(formData.form.data)): null;
                //
                // var rex = /mwftype="subform"/gi;
                //
                //
                // debugger;
                this.relatedFormMap = formData.relatedFormMap;
                this.relatedScriptMap = formData.relatedScriptMap;
                delete formData.form.data;
                this.formInfor = formData.form;
            }else{
                this.form = (formData.data) ? JSON.decode(MWF.decodeJsonString(formData.data)): null;
                delete formData.data;
                this.formInfor = formData;
            }
476
        }
R
roo00 已提交
477
    },
NoSubject's avatar
NoSubject 已提交
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500

    // loadWork2: function(){
    //     var method = "";
    //     var id = "";
    //
    //     if (this.options.workCompletedId){
    //         method = (layout.mobile) ? "getJobByWorkCompletedMobile" : "getJobByWorkCompleted";
    //         id = this.options.workCompletedId;
    //     }else if (this.options.workId) {
    //         method = (layout.mobile) ? "getJobByWorkMobile" : "getJobByWork";
    //         id = this.options.workId;
    //     }
    //     if (method && id){
    //         this.action[method](function(json){
    //             if (this.mask) this.mask.hide();
    //             this.parseData(json.data);
    //             if (layout.mobile) this.loadMobileActions();
    //             this.openWork();
    //         }.bind(this), function(){
    //             this.close();
    //         }.bind(this), id);
    //     }
    // },
R
roo00 已提交
501 502 503 504 505 506 507 508 509 510 511
    loadMobileActions: function(){
        if( this.control.allowSave || this.control.allowProcessing ){
            this.mobileActionBarNode = new Element("div", {"styles": this.css.mobileActionBarNode}).inject(this.node, "after");
            var size = this.content.getSize();
            var y = size.y-40;
            this.node.setStyles({
                "height": ""+y+"px",
                "min-height": ""+y+"px",
                "overflow": "auto",
                "padding-bottom": "40px"
            });
NoSubject's avatar
NoSubject 已提交
512
            //this.node.set("id", "formNode111111111");
R
roo00 已提交
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577
        }
        if( this.control.allowSave ){
            this.mobileSaveActionNode = new Element("div", {"styles": this.css.mobileSaveActionNode, "text": this.lp.save}).inject(this.mobileActionBarNode);
            this.mobileSaveActionNode.addEvents({
                "click": function(){
                    this.appForm.saveWork();
                }.bind(this),
                "touchstart": function(){
                    this.setStyle("background-color", "#EEEEEE");
                },
                "touchcancel": function(){
                    this.setStyle("background-color", "#ffffff");
                },
                "touchend": function(){
                    this.setStyle("background-color", "#ffffff");
                }
            });
            if (this.control.allowProcessing){
                this.mobileSaveActionNode.setStyles({
                    "width": "49%",
                    "float": "left"
                });
            }
        }
        if( this.control.allowProcessing ){
            this.mobileProcessActionNode = new Element("div", {"styles": this.css.mobileSaveActionNode, "text": this.lp.process}).inject(this.mobileActionBarNode);
            this.mobileProcessActionNode.addEvents({
                "click": function(){
                    this.appForm.processWork();
                }.bind(this),
                "touchstart": function(){
                    this.setStyle("background-color", "#EEEEEE");
                },
                "touchcancel": function(){
                    this.setStyle("background-color", "#ffffff");
                },
                "touchend": function(){
                    this.setStyle("background-color", "#ffffff");
                }
            });
            if (this.control.allowSave){
                this.mobileProcessActionNode.setStyles({
                    "width": "49%",
                    "float": "right"
                });
            }
        }
    },
    errorWork: function(){
        if (this.mask) this.mask.hide();
        this.node.set("text", "openError");
    },
    getCurrentTaskData: function(data){
        if ((data.currentTaskIndex || data.currentTaskIndex===0) && data.currentTaskIndex != -1){
            this.options.taskId = this.taskList[data.currentTaskIndex].id;
            return this.taskList[data.currentTaskIndex];
        }
        //if (this.taskList){
        //    if (this.taskList.length==1){
        //        this.options.taskId = this.taskList[0].id;
        //        return this.taskList[0];
        //    }
        //}
        return null;
    },
NoSubject's avatar
NoSubject 已提交
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607
    // parseData: function(data){
    //     var title = "";
    //     if (this.options.taskId){
    //         title = data.work.title;
    //         this.options.workId = data.work.id;
    //     }else if (this.options.workCompletedId){
    //         title = data.workCompleted.title;
    //         this.options.workCompleted = data.workCompleted.id;
    //     }else if (this.options.workId) {
    //         title = data.work.title;
    //         this.options.workId = data.work.id;
    //     }
    //
    //     this.setTitle(this.options.title+"-"+title);
    //
    //     this.activity = data.activity;
    //     this.data = data.data;
    //     this.taskList = data.taskList;
    //     this.currentTask = this.getCurrentTaskData(data);
    //     this.taskList = data.taskList;
    //     this.readList = data.readList;
    //     this.work = data.work;
    //     this.workCompleted = data.workCompleted;
    //     this.workLogList = data.workLogList;
    //     this.attachmentList = data.attachmentList;
    //     this.inheritedAttachmentList = data.inheritedAttachmentList;
    //     this.control = data.control;
    //     this.form = (data.form) ? JSON.decode(MWF.decodeJsonString(data.form.data)): null;
    //     this.formInfor = data.form;
    // },
R
roo00 已提交
608 609 610 611 612 613 614 615
    openWork: function(){
        if (this.form){
            //this.readonly = true;
            //if (this.currentTask) {
            //    this.readonly = false;
            //}else if(this.options.isControl && this.work){
            //    this.readonly = false;
            //}
NoSubject's avatar
NoSubject 已提交
616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643

            // MWF.xDesktop.requireApp("process.Xform", "Package", function(){
            //     MWF.xApplication.process.Xform.require(function(){
            //         this.appForm = new MWF.APPForm(this.formNode, this.form, {});
            //         this.appForm.businessData = {
            //             "data": this.data,
            //             "taskList": this.taskList,
            //             "readList": this.readList,
            //             "work": this.work,
            //             "workCompleted": this.workCompleted,
            //             "control": this.control,
            //             "activity": this.activity,
            //             "task": this.currentTask,
            //             "workLogList": this.workLogList,
            //             "attachmentList": this.attachmentList,
            //             "inheritedAttachmentList": this.inheritedAttachmentList,
            //             "formInfor": this.formInfor,
            //             "status": {
            //                 //"readonly": (this.options.readonly) ? true : false
            //                 "readonly": this.readonly
            //             }
            //         };
            //         this.appForm.workAction = this.action;
            //         this.appForm.app = this;
            //         this.appForm.load();
            //     }.bind(this));
            // }.bind(this));

NoSubject's avatar
NoSubject 已提交
644 645
            this.formNode.empty();
            this.formNode.setStyles(this.css.formNode);
646 647 648 649 650
            var uri = window.location.href;
            //var cl = (uri.indexOf("$all")!=-1) ? "$all" : "Form";
            var cl = "$all";
            MWF.xDesktop.requireApp("process.Xform", cl, function(){
            //MWF.xDesktop.requireApp("process.Xform", "Form", function(){
R
roo00 已提交
651 652 653
                this.appForm = new MWF.APPForm(this.formNode, this.form, {});
                this.appForm.businessData = {
                    "data": this.data,
R
roo00 已提交
654
                    "originalData" : Object.clone( this.data ),
R
roo00 已提交
655 656 657 658 659 660 661 662
                    "taskList": this.taskList,
                    "readList": this.readList,
                    "work": this.work,
                    "workCompleted": this.workCompleted,
                    "control": this.control,
                    "activity": this.activity,
                    "task": this.currentTask,
                    "workLogList": this.workLogList,
NoSubject's avatar
NoSubject 已提交
663
                    "recordList": this.recordList,
R
roo00 已提交
664 665 666 667 668 669 670 671 672 673
                    "attachmentList": this.attachmentList,
                    "inheritedAttachmentList": this.inheritedAttachmentList,
                    "formInfor": this.formInfor,
                    "status": {
                        //"readonly": (this.options.readonly) ? true : false
                        "readonly": this.readonly
                    }
                };
                this.appForm.workAction = this.action;
                this.appForm.app = this;
674 675 676 677 678 679 680

                if( this.$events && this.$events.queryLoadForm ){
                    this.appForm.addEvent( "queryLoad", function () {
                        this.fireEvent("queryLoadForm");
                    }.bind(this));
                }

NoSubject's avatar
NoSubject 已提交
681
                this.appForm.load(function(){
R
roo00 已提交
682
                    if (this.mask) this.mask.hide();
NoSubject's avatar
NoSubject 已提交
683 684 685 686 687 688 689 690
                    if (window.o2android && window.o2android.appFormLoaded){
                        layout.appForm = this.appForm;
                        window.o2android.appFormLoaded(JSON.stringify(this.appForm.mobileTools));
                    }
                    if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.appFormLoaded){
                        layout.appForm = this.appForm;
                        window.webkit.messageHandlers.appFormLoaded.postMessage(JSON.stringify(this.appForm.mobileTools));
                    }
691 692 693 694 695 696
debugger;

                    if (this.options.action=="processTask"){
                        this.appForm.processWork();
                        this.options.action = "";
                    }
697 698 699

                    this.fireEvent("postLoadForm");

NoSubject's avatar
NoSubject 已提交
700
                }.bind(this));
R
roo00 已提交
701 702 703 704 705 706 707 708 709
            }.bind(this));
        }
    },

    //errorWork: function(){
    //
    //},

    recordStatus: function(){
NoSubject's avatar
NoSubject 已提交
710
	    debugger;
711
        return {"workId": this.options.workId, "workCompletedId": this.options.workCompletedId, "jobId": this.options.jobId, "draftId": this.options.draftId, "priorityWork": this.options.priorityWork, "readonly": this.readonly};
R
roo00 已提交
712 713 714 715 716 717 718 719 720 721
    },
    onPostClose: function(){
        if (this.appForm){
            this.appForm.modules.each(function(module){
                MWF.release(module);
            });
            MWF.release(this.appForm);
        }
    }

R
roo00 已提交
722
});