Main.js 32.4 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
            this.loadWorkByJob(jobId);
        }
    },
    loadWorkByWork: function(id){
NoSubject's avatar
NoSubject 已提交
145
	    debugger;
146
        //var getWorkLogMothed = "getWorkLog";    //以前使用worklog,现在改成record了
147 148 149
        //var getWorkLogMothed = (this.options.worklogType.toLowerCase()==="worklog") ? "getWorkLog" : "getRecordLog";
        var loadFormFlag = false;
        var loadWorkFlag = false;
NoSubject's avatar
NoSubject 已提交
150
        var loadModuleFlag = false;
151 152 153 154

        var json_work, json_log, json_control, json_form;

        var check = function(){
NoSubject's avatar
NoSubject 已提交
155
             if (loadWorkFlag && loadFormFlag && loadModuleFlag){
156 157 158 159
                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 已提交
160 161 162 163 164 165 166 167
                    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 已提交
168
                            }.bind(this), function(){});
NoSubject's avatar
NoSubject 已提交
169 170
                        }
                    }
171 172 173 174 175 176 177 178
                } 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 已提交
179 180 181
                        layout.sessionPromise.then(function(){
                            this.close();
                        }.bind(this), function(){});
NoSubject's avatar
NoSubject 已提交
182
                        //this.close();
183 184 185 186 187
                    }
                }
            }
        }.bind(this);

NoSubject's avatar
NoSubject 已提交
188
        if ((this.options.form && this.options.form.id) || this.options.formid){
189
            o2.Actions.invokeAsync([
190
                {"action": this.action, "name": "loadWorkV2"},
191
                {"action": this.action, "name": "getWorkLog"},
192
                {"action": this.action, "name": "getWorkControl"},
193
                {"action": this.action, "name": ((layout.mobile) ? "getFormV2Mobile": "getFormV2")}
194 195 196 197 198 199 200 201
            ], {"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 已提交
202
                }.bind(this), "failure": function(){
NoSubject's avatar
NoSubject 已提交
203 204 205
                    layout.sessionPromise.then(function(){
                        this.close();
                    }.bind(this), function(){});
NoSubject's avatar
NoSubject 已提交
206
                    //this.close();
NoSubject's avatar
NoSubject 已提交
207
                }.bind(this)}, id, id, id, [this.options.formid || this.options.form.id]);
208
        }else{
209 210
            this.action.lookupFormWithWork(id, function(json){
                var formId = json.data.id;
211 212
                if (json.data.form){
                    json_form = json;
213 214
                    loadFormFlag = true;
                    check();
215
                }else{
NoSubject's avatar
NoSubject 已提交
216 217 218 219 220 221 222 223
                    //临时查看效果
                    // 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 已提交
224 225
                    var cacheTag = json.data.cacheTag || "";
                        this.action[((layout.mobile) ? "getFormV2Mobile": "getFormV2")](formId, cacheTag, function(formJson){
NoSubject's avatar
NoSubject 已提交
226 227 228 229 230 231 232 233 234
                            json_form = formJson;
                            loadFormFlag = true;
                            check();
                        }, function(){
                            loadFormFlag = true;
                            check();
                        });
                    // }

235 236
                }

237 238 239 240
            }.bind(this), function(){
                loadFormFlag = true;
                check();
            });
241
            o2.Actions.invokeAsync([
242 243 244 245 246 247 248 249 250 251
                    {"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 已提交
252 253 254
                        layout.sessionPromise.then(function(){
                            this.close();
                        }.bind(this), function(){});
255 256 257
                        //this.close();
                    }.bind(this)}, id
            );
258
        }
NoSubject's avatar
NoSubject 已提交
259 260 261 262 263
        var cl = "$all";
        MWF.xDesktop.requireApp("process.Xform", cl, function(){
            loadModuleFlag = true;
            check();
        });
264 265 266 267 268 269 270 271 272 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

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

                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 已提交
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 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
    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 已提交
466 467
        debugger;

NoSubject's avatar
NoSubject 已提交
468
        var title = workData.work.title;
NoSubject's avatar
NoSubject 已提交
469 470 471 472 473 474 475 476 477 478 479 480
        //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 已提交
481

NoSubject's avatar
NoSubject 已提交
482 483 484 485 486 487
        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 已提交
488
        this.routeList = workData.routeList;
NoSubject's avatar
NoSubject 已提交
489 490
        this.work = workData.work;
        this.workCompleted = (workData.work.completedTime) ? workData.work : null;
R
roo00 已提交
491

NoSubject's avatar
NoSubject 已提交
492
        this.workLogList = logData;
NoSubject's avatar
NoSubject 已提交
493
        this.recordList = recordData;
NoSubject's avatar
NoSubject 已提交
494 495
        this.attachmentList = attData;
        //this.inheritedAttachmentList = data.inheritedAttachmentList;
R
roo00 已提交
496

NoSubject's avatar
NoSubject 已提交
497

NoSubject's avatar
NoSubject 已提交
498
        this.control = controlData;
499
        if (formData){
NoSubject's avatar
NoSubject 已提交
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
            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;
            }
516
        }
R
roo00 已提交
517
    },
NoSubject's avatar
NoSubject 已提交
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540

    // 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 已提交
541 542 543 544 545 546 547 548 549 550 551
    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 已提交
552
            //this.node.set("id", "formNode111111111");
R
roo00 已提交
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 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 608 609 610 611 612 613 614 615 616 617
        }
        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 已提交
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
    // 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 已提交
648 649 650 651 652 653 654 655
    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 已提交
656 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

            // 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 已提交
684 685
            this.formNode.empty();
            this.formNode.setStyles(this.css.formNode);
686 687
            var uri = window.location.href;
            //var cl = (uri.indexOf("$all")!=-1) ? "$all" : "Form";
NoSubject's avatar
NoSubject 已提交
688 689
           // var cl = "$all";
           // MWF.xDesktop.requireApp("process.Xform", cl, function(){
690
            //MWF.xDesktop.requireApp("process.Xform", "Form", function(){
R
roo00 已提交
691 692 693
                this.appForm = new MWF.APPForm(this.formNode, this.form, {});
                this.appForm.businessData = {
                    "data": this.data,
R
roo00 已提交
694
                    "originalData" : Object.clone( this.data ),
R
roo00 已提交
695 696 697 698 699 700 701 702
                    "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 已提交
703
                    "recordList": this.recordList,
U
unknown 已提交
704
                    "routeList" : this.routeList,
R
roo00 已提交
705 706 707 708 709 710 711 712 713 714
                    "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;
715 716 717 718 719 720 721

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

NoSubject's avatar
NoSubject 已提交
722
                this.appForm.load(function(){
R
roo00 已提交
723
                    if (this.mask) this.mask.hide();
NoSubject's avatar
NoSubject 已提交
724 725 726 727 728 729 730 731
                    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));
                    }
732 733 734 735
                    if (this.options.action=="processTask"){
                        this.appForm.processWork();
                        this.options.action = "";
                    }
736
                    this.fireEvent("postLoadForm");
NoSubject's avatar
NoSubject 已提交
737
                }.bind(this));
NoSubject's avatar
NoSubject 已提交
738
            //}.bind(this));
R
roo00 已提交
739 740 741 742 743 744 745 746
        }
    },

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

    recordStatus: function(){
NoSubject's avatar
NoSubject 已提交
747
	    debugger;
748
        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 已提交
749 750 751 752 753 754 755 756 757 758
    },
    onPostClose: function(){
        if (this.appForm){
            this.appForm.modules.each(function(module){
                MWF.release(module);
            });
            MWF.release(this.appForm);
        }
    }

R
roo00 已提交
759
});