Main.js 34.7 KB
Newer Older
1 2 3
MWF.xApplication = MWF.xApplication || {};
MWF.xApplication.process = MWF.xApplication.process || {};
MWF.xApplication.process.Work = MWF.xApplication.process.Work || {};
NoSubject's avatar
NoSubject 已提交
4
MWF.xApplication.process.Work.options = Object.clone(o2.xApplication.Common.options);
R
roo00 已提交
5 6 7 8 9 10 11 12 13 14 15
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",
16
		"title": "",
R
roo00 已提交
17
        "workId": "",
18 19
        "draftId": "",
        "draft": null,
R
roo00 已提交
20 21
        "workCompletedId": "",
        "taskId": "",
NoSubject's avatar
NoSubject 已提交
22 23 24
        "jobId": "",
        "form": null,
        "priorityWork": "",
R
roo00 已提交
25 26
        "isControl": false,
        "taskObject": null,
NoSubject's avatar
NoSubject 已提交
27 28
        "readonly": false,
        "worklogType": "record" //record, worklog
R
roo00 已提交
29 30
	},
	onQueryLoad: function(){
31 32 33
        if (!this.options.title) this.setOptions({
            "title": MWF.xApplication.process.Work.LP.title
        });
R
roo00 已提交
34
		this.lp = MWF.xApplication.process.Work.LP;
NoSubject's avatar
NoSubject 已提交
35
        if (!this.status) {
36
            if( this.options.readonly === "true" )this.options.readonly=true;
NoSubject's avatar
NoSubject 已提交
37
        } else {
R
roo00 已提交
38 39
            this.options.workId = this.status.workId;
            this.options.workCompletedId = this.status.workCompletedId;
NoSubject's avatar
NoSubject 已提交
40
            this.options.jobId = this.status.jobId;
41
            this.options.draftId = this.status.draftId;
NoSubject's avatar
NoSubject 已提交
42
            this.options.priorityWork = this.status.priorityWork;
43
            this.options.readonly = (this.status.readonly === true || this.status.readonly === "true");
R
roo00 已提交
44
        }
NoSubject's avatar
NoSubject 已提交
45
        this.action = MWF.Actions.get("x_processplatform_assemble_surface");
R
roo00 已提交
46
	},
NoSubject's avatar
NoSubject 已提交
47
    loadWorkApplication: function(callback, mask){
R
roo00 已提交
48 49 50
	    debugger;
        var maskStyle = (Browser.name=="firefox") ? "work_firefox" : "desktop";
        //alert(maskStyle);
NoSubject's avatar
NoSubject 已提交
51
        if (mask) this.mask = new MWF.widget.Mask({"style": maskStyle, "loading": mask});
NoSubject's avatar
NoSubject 已提交
52 53 54 55 56 57 58 59 60 61 62 63
        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 已提交
64 65 66
	loadApplication: function(callback){
        this.node = new Element("div", {"styles": this.css.content}).inject(this.content);

NoSubject's avatar
NoSubject 已提交
67 68 69
        if (layout.mobile){
            this.loadWorkApplication(callback, false)
        }else{
NoSubject's avatar
NoSubject 已提交
70 71 72 73 74 75 76 77
            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 已提交
78
        }
R
roo00 已提交
79 80 81 82 83 84 85 86 87 88 89

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

        this.addKeyboardEvents();

    },
    refreshTaskCenter: function(){
	    if (this.desktop.apps){
            if (this.desktop.apps["TaskCenter"]){
90 91 92 93 94 95
                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 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
            }
        }
    },
    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){
NoSubject's avatar
NoSubject 已提交
113
        if (this.appForm){
R
roo00 已提交
114
            this.formNode.empty();
NoSubject's avatar
NoSubject 已提交
115 116
            MWF.release(this.appForm);
            this.appForm = null;
R
roo00 已提交
117
            this.form = null;
118
            this.$events = {};
R
roo00 已提交
119 120 121 122 123 124 125 126 127
        }
        if (data){
            this.parseData(data);
            this.openWork();
        }else{
            this.loadWork();
        }
    },
    loadWork: function(){
NoSubject's avatar
NoSubject 已提交
128
        var id = this.options.workCompletedId || this.options.workId || this.options.workid || this.options.workcompletedid;
NoSubject's avatar
NoSubject 已提交
129 130 131 132 133 134
        // var methods = {
        //     "loadWork": false,
        //     "getWorkControl": false,
        //     "getForm": false
        // };
        if (id){
135 136 137 138 139 140 141 142
            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){
143
            this.loadWorkByDraft(this.options.draft, this.options.draftData);
144 145
        }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 已提交
146 147 148
            delete this.options.jobId;
            delete this.options.jobid;
            delete this.options.job;
149 150 151 152
            this.loadWorkByJob(jobId);
        }
    },
    loadWorkByWork: function(id){
NoSubject's avatar
NoSubject 已提交
153
	    debugger;
154
        //var getWorkLogMothed = "getWorkLog";    //以前使用worklog,现在改成record了
155 156 157
        //var getWorkLogMothed = (this.options.worklogType.toLowerCase()==="worklog") ? "getWorkLog" : "getRecordLog";
        var loadFormFlag = false;
        var loadWorkFlag = false;
NoSubject's avatar
NoSubject 已提交
158
        var loadModuleFlag = false;
159 160 161 162

        var json_work, json_log, json_control, json_form;

        var check = function(){
NoSubject's avatar
NoSubject 已提交
163
             if (loadWorkFlag && loadFormFlag && loadModuleFlag){
164 165 166 167
                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();
NoSubject's avatar
NoSubject 已提交
168 169 170 171 172 173 174 175
                    if (layout.session && layout.session.user){
                        this.openWork();
                        this.unLoading();
                    }else{
                        if (layout.sessionPromise){
                            layout.sessionPromise.then(function(){
                                this.openWork();
                                this.unLoading();
NoSubject's avatar
NoSubject 已提交
176
                            }.bind(this), function(){});
NoSubject's avatar
NoSubject 已提交
177 178
                        }
                    }
179 180 181 182 183 184 185 186
                } 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{
NoSubject's avatar
NoSubject 已提交
187 188 189
                        layout.sessionPromise.then(function(){
                            this.close();
                        }.bind(this), function(){});
NoSubject's avatar
NoSubject 已提交
190
                        //this.close();
191 192 193 194 195
                    }
                }
            }
        }.bind(this);

NoSubject's avatar
NoSubject 已提交
196
        if ((this.options.form && this.options.form.id) || this.options.formid){
197
            o2.Actions.invokeAsync([
198
                {"action": this.action, "name": "loadWorkV2"},
199
                {"action": this.action, "name": "getWorkLog"},
200
                {"action": this.action, "name": "getWorkControl"},
201
                {"action": this.action, "name": ((layout.mobile) ? "getFormV2Mobile": "getFormV2")}
202 203 204 205 206 207 208 209
            ], {"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 已提交
210
                }.bind(this), "failure": function(){
NoSubject's avatar
NoSubject 已提交
211 212 213
                    // layout.sessionPromise.then(function(){
                    //     this.close();
                    // }.bind(this), function(){});
NoSubject's avatar
NoSubject 已提交
214
                    //this.close();
215
                }.bind(this)}, id, id, id, [this.options.formid || this.options.form.id , new Date().getTime()]);
216
        }else{
217
            this.action[((layout.mobile) ? "lookupFormWithWorkMobile" : "lookupFormWithWork")](id, function(json){
218
                var formId = json.data.id;
219 220
                if (json.data.form){
                    json_form = json;
221 222
                    loadFormFlag = true;
                    check();
223
                }else{
NoSubject's avatar
NoSubject 已提交
224 225 226 227 228 229 230 231
                    //临时查看效果
                    // if (formId=="4f8b4fde-d963-468c-b6c9-9e7b919f0bd0"){
                    //     o2.JSON.get("../x_desktop/res/form/4f8b4fde-d963-468c-b6c9-9e7b919f0bd0.json", function(formJson){
                    //         json_form = formJson;
                    //         loadFormFlag = true;
                    //         check();
                    //     });
                    // }else{
NoSubject's avatar
NoSubject 已提交
232 233
                    var cacheTag = json.data.cacheTag || "";
                        this.action[((layout.mobile) ? "getFormV2Mobile": "getFormV2")](formId, cacheTag, function(formJson){
NoSubject's avatar
NoSubject 已提交
234 235 236 237 238 239
                            json_form = formJson;
                            loadFormFlag = true;
                            check();
                        }, function(){
                            loadFormFlag = true;
                            check();
240
                            return true;
NoSubject's avatar
NoSubject 已提交
241 242 243
                        });
                    // }

244 245
                }

246 247 248 249
            }.bind(this), function(){
                loadFormFlag = true;
                check();
            });
250
            o2.Actions.invokeAsync([
251 252 253 254 255 256 257 258 259 260
                    {"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(){
NoSubject's avatar
NoSubject 已提交
261 262 263
                        // layout.sessionPromise.then(function(){
                        //     this.close();
                        // }.bind(this), function(){});
264 265 266
                        //this.close();
                    }.bind(this)}, id
            );
267
        }
NoSubject's avatar
NoSubject 已提交
268 269 270 271 272
        var cl = "$all";
        MWF.xDesktop.requireApp("process.Xform", cl, function(){
            loadModuleFlag = true;
            check();
        });
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 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 320 321 322 323 324 325 326 327 328 329 330 331 332

        // 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);
        //}
333 334 335 336 337 338 339 340 341 342 343 344 345
    },
    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 已提交
346 347
                    this.loadWork();
                }else{
NoSubject's avatar
NoSubject 已提交
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
                    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 已提交
368
                }
369
            }else{
NoSubject's avatar
NoSubject 已提交
370 371 372
                layout.sessionPromise.then(function(){
                    this.close();
                }.bind(this), function(){});
NoSubject's avatar
NoSubject 已提交
373
                //this.close();
374
            }
NoSubject's avatar
NoSubject 已提交
375
        }.bind(this), function(){
NoSubject's avatar
NoSubject 已提交
376
            //this.close();
377
        }.bind(this));
NoSubject's avatar
NoSubject 已提交
378
    },
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
    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,
395
                    "allowDelete": true
396 397 398 399
                };

                this.parseData(workData, control, json_form.data, [], [], []);
                if (this.mask) this.mask.hide();
NoSubject's avatar
NoSubject 已提交
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414

                if (layout.session && layout.session.user){
                    this.openWork();
                    this.unLoading();
                }else{
                    if (layout.sessionPromise){
                        layout.sessionPromise.then(function(){
                            this.openWork();
                            this.unLoading();
                        }.bind(this), function(){});
                    }
                }

                // this.openWork();
                // this.unLoading();
415 416 417 418 419

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

NoSubject's avatar
NoSubject 已提交
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
    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 已提交
487 488
        debugger;

NoSubject's avatar
NoSubject 已提交
489
        var title = workData.work.title;
NoSubject's avatar
NoSubject 已提交
490 491 492 493 494 495 496 497 498 499 500 501
        //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;
        //    }
        //});
502 503 504 505 506 507 508 509
        // if (workData.activity && workData.activity.customData){
        //     try{
        //         var customData = JSON.parse(workData.activity.customData);
        //         workData.activity.customData = customData;
        //     }catch(e){
        //         console.error(e);
        //     }
        // }
NoSubject's avatar
NoSubject 已提交
510 511 512 513 514 515
        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;
U
unknown 已提交
516
        this.routeList = workData.routeList;
NoSubject's avatar
NoSubject 已提交
517 518
        this.work = workData.work;
        this.workCompleted = (workData.work.completedTime) ? workData.work : null;
R
roo00 已提交
519

NoSubject's avatar
NoSubject 已提交
520
        this.workLogList = logData;
NoSubject's avatar
NoSubject 已提交
521
        this.recordList = recordData;
NoSubject's avatar
NoSubject 已提交
522 523
        this.attachmentList = attData;
        //this.inheritedAttachmentList = data.inheritedAttachmentList;
R
roo00 已提交
524

NoSubject's avatar
NoSubject 已提交
525

NoSubject's avatar
NoSubject 已提交
526
        this.control = controlData;
527 528 529 530
        if( !this.currentTask && this.control.allowReset ){
            this.control.allowReset = false;
        }

531
        if (formData){
NoSubject's avatar
NoSubject 已提交
532
            if (formData.form){
NoSubject's avatar
NoSubject 已提交
533 534 535 536
                this.formDataText = (formData.form.data) ? MWF.decodeJsonString(formData.form.data) : "";
                this.form = (this.formDataText) ? JSON.decode(this.formDataText): null;

                //this.form = (formData.form.data) ? MWF.decodeJsonString(formData.form.data): null;
NoSubject's avatar
NoSubject 已提交
537 538 539 540 541 542 543
                //
                // var rex = /mwftype="subform"/gi;
                //
                //
                // debugger;
                this.relatedFormMap = formData.relatedFormMap;
                this.relatedScriptMap = formData.relatedScriptMap;
NoSubject's avatar
NoSubject 已提交
544
                this.relatedLanguage = formData.relatedLanguage;
NoSubject's avatar
NoSubject 已提交
545 546 547
                delete formData.form.data;
                this.formInfor = formData.form;
            }else{
NoSubject's avatar
NoSubject 已提交
548 549 550 551
                this.formDataText = (formData.data) ? MWF.decodeJsonString(formData.data) : "";
                this.form = (this.formDataText) ? JSON.decode(this.formDataText): null;

                //this.form = (formData.data) ? MWF.decodeJsonString(formData.data): null;
NoSubject's avatar
NoSubject 已提交
552 553 554
                delete formData.data;
                this.formInfor = formData;
            }
555
        }
R
roo00 已提交
556
    },
NoSubject's avatar
NoSubject 已提交
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579

    // 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 已提交
580 581 582 583 584 585 586 587 588 589 590
    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 已提交
591
            //this.node.set("id", "formNode111111111");
R
roo00 已提交
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 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 644 645 646 647 648 649 650 651 652 653 654 655 656
        }
        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 已提交
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
    // 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 已提交
687 688
    openWork: function(){
        if (this.form){
689 690
            if( this.options.readonly )this.readonly = true;

R
roo00 已提交
691 692 693 694 695 696
            //this.readonly = true;
            //if (this.currentTask) {
            //    this.readonly = false;
            //}else if(this.options.isControl && this.work){
            //    this.readonly = false;
            //}
NoSubject's avatar
NoSubject 已提交
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724

            // 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 已提交
725 726
            this.formNode.empty();
            this.formNode.setStyles(this.css.formNode);
727 728
            var uri = window.location.href;
            //var cl = (uri.indexOf("$all")!=-1) ? "$all" : "Form";
729 730
            var cl = "$all";
            MWF.xDesktop.requireApp("process.Xform", cl, function(){
731
            //MWF.xDesktop.requireApp("process.Xform", "Form", function(){
U
unknown 已提交
732
                this.appForm = new MWF.APPForm(this.formNode, this.form, {"readonly": this.readonly});
R
roo00 已提交
733 734
                this.appForm.businessData = {
                    "data": this.data,
R
roo00 已提交
735
                    "originalData" : Object.clone( this.data ),
R
roo00 已提交
736 737 738 739 740 741 742 743
                    "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 已提交
744
                    "recordList": this.recordList,
U
unknown 已提交
745
                    "routeList" : this.routeList,
R
roo00 已提交
746 747 748 749 750 751 752 753 754 755
                    "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;
NoSubject's avatar
NoSubject 已提交
756
                this.appForm.formDataText = this.formDataText;
757

NoSubject's avatar
NoSubject 已提交
758
                if( this.$events && this.$events.queryLoadForm ){
759
                    this.appForm.addEvent( "queryLoad", function () {
760
                        this.fireEvent("queryLoadForm", [this]);
761 762 763
                    }.bind(this));
                }

NoSubject's avatar
NoSubject 已提交
764
                this.appForm.load(function(){
R
roo00 已提交
765
                    if (this.mask) this.mask.hide();
766 767 768 769 770 771 772
                    if (window.o2android && window.o2android.postMessage) {
                        var body = {
                            type: "appFormLoaded",
                            data: this.appForm.mobileTools
                        }
                        window.o2android.postMessage(JSON.stringify(body));
                    } else if (window.o2android && window.o2android.appFormLoaded){
NoSubject's avatar
NoSubject 已提交
773 774
                        layout.appForm = this.appForm;
                        window.o2android.appFormLoaded(JSON.stringify(this.appForm.mobileTools));
775
                    } else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.appFormLoaded){
NoSubject's avatar
NoSubject 已提交
776 777 778
                        layout.appForm = this.appForm;
                        window.webkit.messageHandlers.appFormLoaded.postMessage(JSON.stringify(this.appForm.mobileTools));
                    }
779 780 781 782
                    if (this.options.action=="processTask"){
                        this.appForm.processWork();
                        this.options.action = "";
                    }
NoSubject's avatar
NoSubject 已提交
783

784
                    this.fireEvent("postLoadForm", [this]);
NoSubject's avatar
NoSubject 已提交
785
                }.bind(this));
786
            }.bind(this));
R
roo00 已提交
787 788 789 790 791 792 793 794
        }
    },

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

    recordStatus: function(){
NoSubject's avatar
NoSubject 已提交
795
	    debugger;
796
        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 已提交
797 798 799 800 801 802 803 804 805 806
    },
    onPostClose: function(){
        if (this.appForm){
            this.appForm.modules.each(function(module){
                MWF.release(module);
            });
            MWF.release(this.appForm);
        }
    }

R
roo00 已提交
807
});