Processor.js 107.1 KB
Newer Older
R
roo00 已提交
1 2 3
MWF.xApplication.process = MWF.xApplication.process || {};
MWF.xApplication.process.Work = MWF.xApplication.process.Work || {};
MWF.xDesktop.requireApp("process.Work", "lp."+MWF.language, null, false);
NoSubject's avatar
NoSubject 已提交
4 5 6 7 8
//兼容快速流转,所以需要判断
if( MWF.xApplication.process.Xform && MWF.xApplication.process.Xform.Form ){
    MWF.xDesktop.requireApp("process.Xform", "Org", null, false);
}

R
roo00 已提交
9
MWF.xApplication.process.Work.Processor = new Class({
NoSubject's avatar
NoSubject 已提交
10 11 12 13
    Extends: MWF.widget.Common,
    Implements: [Options, Events],
    options: {
        "style": "default",
R
roo00 已提交
14
        "mediaNode": null,
NoSubject's avatar
NoSubject 已提交
15 16
        "opinion": "",
        "tabletWidth" : 0,
R
roo00 已提交
17 18
        "tabletHeight" : 0,
        "orgHeight" : 276,
NoSubject's avatar
NoSubject 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31
        "maxOrgCountPerline" : 2,
        "isManagerProcess" : false //是否为管理员提交
    },

    initialize: function(node, task, options, form){
        this.setOptions(options);

        this.path = "/x_component_process_Work/$Processor/";
        this.cssPath = "/x_component_process_Work/$Processor/"+this.options.style+"/css.wcss";
        this._loadCss();

        this.task = task;
        this.node = $(node);
R
roo00 已提交
32 33
        this.selectedRoute = null;

R
roo00 已提交
34 35
        this.form = form;

R
roo00 已提交
36
        this.load();
NoSubject's avatar
NoSubject 已提交
37
    },
R
roo00 已提交
38
    load: function(){
U
unknown 已提交
39 40 41 42 43
        if( layout.mobile ){
            this.content = new Element("div").inject(this.node);
        }else{
            this.content = this.node;
        }
NoSubject's avatar
NoSubject 已提交
44
        if( !this.form && this.options.isManagerProcess ){
U
unknown 已提交
45 46
            this.managerProcessNoticeNode = new Element("div", {"styles": this.css.managerProcessNoticeNode, "html": MWF.xApplication.process.Work.LP.managerProcessNotice}).inject(this.content);
            this.managerLoginNode = new Element("div", {"styles": this.css.managerLoginNode, "text": MWF.xApplication.process.Work.LP.managerLogin }).inject(this.content);
NoSubject's avatar
NoSubject 已提交
47 48 49 50 51 52

            this.managerLoginNode.addEvent("click", function(ev){
                this.managerLogin(ev);
            }.bind(this));

            //var text = MWF.xApplication.process.Work.LP.managerLoginReturn.replace( "{user}", layout.session.user.name );
U
unknown 已提交
53
            //this.managerLoginReturnNode = new Element("div", {"styles": this.css.managerLoginNode, "text": text }).inject(this.content);
NoSubject's avatar
NoSubject 已提交
54 55 56 57 58 59
            //this.managerLoginReturnNode.hide();
            //this.managerPerson = layout.session.user.distinguishedName;
            //this.managerLoginReturnNode.addEvent("click", function(ev){
            //    this.managerLoginReturn(ev);
            //}.bind(this))
        }
R
roo00 已提交
60

U
unknown 已提交
61 62
        this.routeOpinionTile = new Element("div", {"styles": this.css.routeOpinionTile, "text": MWF.xApplication.process.Work.LP.inputOpinion}).inject(this.content);
        this.routeOpinionArea = new Element("div", {"styles": this.css.routeOpinionArea}).inject(this.content);
NoSubject's avatar
NoSubject 已提交
63

R
roo00 已提交
64 65
        this.setOpinion();

NoSubject's avatar
NoSubject 已提交
66 67
        if( this.form ){
            if( layout.mobile ){
U
unknown 已提交
68
                this.orgsArea = new Element("div", {"styles": this.css.orgsArea}).inject(this.content);
NoSubject's avatar
NoSubject 已提交
69
                this.orgsTile = new Element("div", {"styles": this.css.orgsTitle, "text": MWF.xApplication.process.Work.LP.selectPerson}).inject(this.orgsArea);
70
                this.orgsArea.hide();
NoSubject's avatar
NoSubject 已提交
71
            }else{
U
unknown 已提交
72
                this.orgsArea = new Element("div", {"styles": this.css.orgsArea}).inject(this.content);
NoSubject's avatar
NoSubject 已提交
73 74
                this.orgsTile = new Element("div", {"styles": this.css.orgsTitle, "text": MWF.xApplication.process.Work.LP.selectPerson}).inject(this.orgsArea);
            }
R
roo00 已提交
75
        }
R
roo00 已提交
76

U
unknown 已提交
77 78 79 80 81
        if( layout.mobile ){
            this.buttonsArea = new Element("div", {"styles": this.css.buttonsArea}).inject(this.node);
        }else{
            this.buttonsArea = new Element("div", {"styles": this.css.buttonsArea}).inject(this.content);
        }
R
roo00 已提交
82
        this.setButtons();
R
roo00 已提交
83

NoSubject's avatar
NoSubject 已提交
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        if( this.form ){
            if( layout.mobile ){
                this.getRouteGroupList();
                if( this.hasDecisionOpinion ){
                    this.routeContainer = new Element("div", {
                        "styles" : this.css.routeContainer
                    }).inject(this.routeOpinionTile, "before");
                    this.routeGroupTitle = new Element("div", { "styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRouteGroup }).inject(this.routeContainer);
                    this.routeGroupArea = new Element("div", { "styles": this.css.routeSelectorArea }).inject(this.routeContainer);

                    this.routeSelectorTile = new Element("div", { "styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRoute }).inject(this.routeContainer);
                    this.routeSelectorArea = new Element("div", { "styles": this.css.routeSelectorArea }).inject(this.routeContainer);

                    this.setRouteGroupList();
                }else{
                    this.routeSelectorTile = new Element("div", {"styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRoute}).inject(this.routeOpinionTile, "before");
                    this.routeSelectorArea = new Element("div", {"styles": this.css.routeSelectorArea}).inject(this.routeSelectorTile, "after");
                    this.setRouteList();
                }
            }else{
                this.getRouteGroupList();
                if( this.hasDecisionOpinion ){
                    //if( this.getMaxOrgLength() > 1 ){
R
roo00 已提交
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
                    this.routeContainer = new Element("div", {
                        "styles" : this.css.routeContainer
                    }).inject(this.routeOpinionTile, "before");

                    this.routeLeftWarper =  new Element("div", { "styles":
                        this.getMaxOrgLength() > 1 ? this.css.routeLeftWarper : this.css.routeLeftWarper_single
                    }).inject(this.routeContainer);
                    this.routeGroupTitle = new Element("div", { "styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRouteGroup }).inject(this.routeLeftWarper);
                    this.routeGroupArea = new Element("div", { "styles": this.css.routeSelectorArea_hasGroup }).inject(this.routeLeftWarper);

                    this.routeRightWarper =  new Element("div", { "styles":
                        this.getMaxOrgLength() > 1 ? this.css.routeRightWarper : this.css.routeRightWarper_single
                    }).inject(this.routeContainer);
                    this.routeSelectorTile = new Element("div", { "styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRoute }).inject(this.routeRightWarper);
                    this.routeSelectorArea = new Element("div", { "styles": this.css.routeSelectorArea_hasGroup }).inject(this.routeRightWarper);
                    this.setRouteGroupList();
NoSubject's avatar
NoSubject 已提交
123 124 125 126 127 128 129 130 131 132
                    //}else{
                    //    this.routeGroupTile = new Element("div", {"styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRoute }).inject(this.routeOpinionTile, "before");
                    //    this.routeGroupArea = new Element("div", {"styles": this.css.routeSelectorArea_hasGroup_wide }).inject(this.routeGroupTile, "after");
                    //    this.setRouteGroupList();
                    //}
                }else{
                    this.routeSelectorTile = new Element("div", {"styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRoute}).inject(this.routeOpinionTile, "before");
                    this.routeSelectorArea = new Element("div", {"styles": this.css.routeSelectorArea}).inject(this.routeSelectorTile, "after");
                    this.setRouteList();
                }
R
roo00 已提交
133
            }
NoSubject's avatar
NoSubject 已提交
134 135 136 137 138
        }else{ //快速处理
            this.routeSelectorTile = new Element("div", {"styles": this.css.routeSelectorTile, "text": MWF.xApplication.process.Work.LP.selectRoute}).inject(this.routeOpinionTile, "before");
            this.routeSelectorArea = new Element("div", {"styles": this.css.routeSelectorArea}).inject(this.routeSelectorTile, "after");
            this.setRouteList_noform();
            this.setSize_noform();
R
roo00 已提交
139
        }
R
roo00 已提交
140 141

        this.fireEvent("postLoad");
R
roo00 已提交
142
    },
R
roo00 已提交
143 144 145 146 147 148 149 150
    getRouteGroupList : function(){
        if( this.routeGroupObject )return this.routeGroupObject;
        this.routeGroupObject = {};
        this.routeGroupNameList = [];
        this.hasDecisionOpinion = false;
        var routeList = this.getRouteDataList();
        routeList.each(function(route, i){

NoSubject's avatar
NoSubject 已提交
151
            if( route.hiddenScriptText && this.form && this.form.Macro ){ //如果隐藏路由,返回
R
roo00 已提交
152 153 154
                if( this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true" )return;
            }

NoSubject's avatar
NoSubject 已提交
155
            if( route.displayNameScriptText && this.form && this.form.Macro ){ //如果有显示名称公式
R
roo00 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
                route.displayName = this.form.Macro.exec(route.displayNameScriptText, this);
            }else{
                route.displayName = route.name;
            }

            if( route.decisionOpinion ){
                this.hasDecisionOpinion = true;
                var decisionOpinionList = route.decisionOpinion.split("#");
                decisionOpinionList.each( function( decisionOption ){
                    this.routeGroupNameList.combine( [decisionOption] );
                    var d = this.splitByStartNumber( decisionOption );
                    if( !this.routeGroupObject[ d.name ] )this.routeGroupObject[ d.name ] = [];
                    this.routeGroupObject[ d.name ].push( route );
                }.bind(this))
            }else{
                var defaultName =  MWF.xApplication.process.Work.LP.defaultDecisionOpinionName;
                this.routeGroupNameList.combine( [defaultName] );
                if( !this.routeGroupObject[ defaultName ] )this.routeGroupObject[ defaultName ] = [];
                this.routeGroupObject[ defaultName].push( route );
            }
        }.bind(this));
        return this.routeGroupObject;
    },
    splitByStartNumber : function( str ){
        var obj = {
            name : "",
            order : ""
        };
        for( var i=0; i<str.length; i++ ){
            if( parseInt(str.substr(i,1)).toString() !== "NaN" ){
                obj.order = obj.order + str.substr(i,1);
            }else{
                obj.name = str.substr( i, str.length );
                break;
            }
        }
        return obj;
    },
    setRouteGroupList : function(){
        var _self = this;
        //var keys = Object.keys( this.routeGroupObject );
        //var length = keys.length;
        //var sortArray = MWF.xApplication.process.Work.LP.routeGroupOrderList;
        //keys.sort( function( a, b ){
        //    var aIdx = sortArray.indexOf(a);
        //    var bIdx = sortArray.indexOf(b);
        //    if( aIdx === -1 )aIdx = sortArray.length;
        //    if( bIdx === -1 )aIdx = sortArray.length;
        //    return aIdx - bIdx;
        //});

        var keys = this.routeGroupNameList;
        keys.sort( function( a, b ){
            var aIdx = parseInt(this.splitByStartNumber( a ).order || "9999999");
            var bIdx = parseInt(this.splitByStartNumber( b ).order || "9999999");
            return aIdx - bIdx;
        }.bind(this));

        var list = [];
        keys.each( function( k ){
            list.push( this.splitByStartNumber( k).name )
NoSubject's avatar
NoSubject 已提交
217
        }.bind(this));
R
roo00 已提交
218

U
unknown 已提交
219
        var flag = false;
R
roo00 已提交
220 221 222 223 224 225 226 227 228 229 230 231
        list.each( function( routeGroupName ){
            var routeList = this.routeGroupObject[routeGroupName];
            var routeGroupNode = new Element("div", {"styles": this.css.routeGroupNode, "text": routeGroupName}).inject(this.routeGroupArea);
            routeGroupNode.store( "routeList", routeList );
            routeGroupNode.store( "routeGroupName", routeGroupName );

            routeGroupNode.addEvents({
                "mouseover": function(e){_self.overRouteGroup(this);},
                "mouseout": function(e){_self.outRouteGroup(this);},
                "click": function(e){_self.selectRouteGroup(this);}
            });

NoSubject's avatar
NoSubject 已提交
232
            if ( keys.length === 1 ){
R
roo00 已提交
233 234
                this.selectRouteGroup(routeGroupNode);
            }else{
U
unknown 已提交
235
                flag = true;
R
roo00 已提交
236 237
            }
        }.bind(this))
U
unknown 已提交
238 239 240
        if( flag ){
            this.setSize(0);
        }
R
roo00 已提交
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
    },
    overRouteGroup: function(node){
        if (this.selectedRouteGroup){
            if (this.selectedRouteGroup.get("text") != node.get("text")){
                node.setStyles(this.css.routeGroupNode_over);
            }
        }else{
            node.setStyles(this.css.routeGroupNode_over);
        }
    },
    outRouteGroup: function(node){
        if (this.selectedRouteGroup){
            if (this.selectedRouteGroup.get("text") != node.get("text")){
                node.setStyles(this.css.routeGroupNode);
            }
        }else{
            node.setStyles(this.css.routeGroupNode);
        }
    },
    selectRouteGroup: function(node){
        if (this.selectedRouteGroup){
            if (this.selectedRouteGroup.get("text") != node.get("text")){
                this.selectedRouteGroup.setStyles(this.css.routeGroupNode);
264
                //this.selectedRouteGroup.removeClass("mainColor_bg");
R
roo00 已提交
265 266 267

                this.selectedRouteGroup = node;
                this.selectedRouteGroup.setStyles(this.css.routeGroupNode_selected);
268
                //this.selectedRouteGroup.addClass("mainColor_bg");
R
roo00 已提交
269 270 271 272 273 274 275 276 277 278 279 280 281 282

                var routeList = this.selectedRouteGroup.retrieve("routeList");
                this.setRouteList( routeList );

            }else{
                //this.selectedRouteGroup.setStyles(this.css.routeNode);
                //this.selectedRouteGroup.getFirst().setStyles(this.css.routeIconNode);
                //this.selectedRouteGroup.getLast().setStyles(this.css.routeTextNode);
                //
                //this.selectedRouteGroup = null;
            }
        }else{
            this.selectedRouteGroup = node;
            node.setStyles(this.css.routeGroupNode_selected);
283
            //this.selectedRouteGroup.addClass("mainColor_bg");
R
roo00 已提交
284 285 286 287 288 289

            var routeList = this.selectedRouteGroup.retrieve("routeList");
            this.setRouteList( routeList );
        }
        this.routeGroupArea.setStyle("background-color", "#FFF");
    },
NoSubject's avatar
NoSubject 已提交
290 291 292 293
    setRouteList_noform: function( routeList ){
        var _self = this;
        this.routeSelectorArea.empty();
        this.selectedRoute = null;
R
roo00 已提交
294

NoSubject's avatar
NoSubject 已提交
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
        //this.task.routeNameList = ["送审核", "送办理", "送公司领导阅"];
        if( !routeList )routeList = this.getRouteDataList();
        routeList.each(function(route, i){
            var routeName = route.name;
            var routeNode = new Element("div", {"styles": this.css.routeNode, "text": routeName}).inject(this.routeSelectorArea);
            routeNode.store( "route", route.id );
            routeNode.store( "routeName", route.name );

            routeNode.addEvents({
                "mouseover": function(e){_self.overRoute(this);},
                "mouseout": function(e){_self.outRoute(this);},
                "click": function(e){_self.selectRoute_noform(this);}
            });

            if (routeList.length==1 || route.sole ){
                this.selectRoute_noform(routeNode);
            }

        }.bind(this));
    },
R
roo00 已提交
315
    setRouteList: function( routeList ){
R
roo00 已提交
316
        var _self = this;
R
roo00 已提交
317 318 319 320
        //if( this.hasDecisionOpinion && this.getMaxOrgLength() === 1 ){
        //    if( this.routeSelectorArea )this.routeSelectorArea.destroy();
        //    this.routeSelectorArea = new Element("div", { styles : this.css.routeSelectorArea_hasGroup_single }).inject( this.selectedRouteGroup, "after" );
        //}else{
NoSubject's avatar
NoSubject 已提交
321
        this.routeSelectorArea.empty();
R
roo00 已提交
322 323 324
        //}
        this.selectedRoute = null;

R
roo00 已提交
325
        //this.task.routeNameList = ["送审核", "送办理", "送公司领导阅"];
NoSubject's avatar
NoSubject 已提交
326
        if( !routeList )routeList = this.getRouteDataList();
R
roo00 已提交
327
        //this.task.routeNameList.each(function(route, i){
U
unknown 已提交
328
        var flag = false;
R
roo00 已提交
329
        routeList.each(function(route, i){
NoSubject's avatar
NoSubject 已提交
330
            if( route.hiddenScriptText && this.form && this.form.Macro ){
R
roo00 已提交
331 332 333
                if( this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true" )return;
            }
            var routeName = route.name;
NoSubject's avatar
NoSubject 已提交
334
            if( route.displayNameScriptText && this.form && this.form.Macro ){
R
roo00 已提交
335 336
                routeName = this.form.Macro.exec(route.displayNameScriptText, this);
            }
R
roo00 已提交
337 338 339 340
            var routeNode = new Element("div", {"styles": this.css.routeNode, "text": routeName}).inject(this.routeSelectorArea);
            //var routeIconNode = new Element("div", {"styles": this.css.routeIconNode}).inject(routeNode);
            //var routeTextNode = new Element("div", {"styles": this.css.routeTextNode, "text": routeName}).inject(routeNode);
            routeNode.store( "route", route.id );
R
roo00 已提交
341
            routeNode.store( "routeName", route.name );
R
roo00 已提交
342 343 344 345 346 347 348

            routeNode.addEvents({
                "mouseover": function(e){_self.overRoute(this);},
                "mouseout": function(e){_self.outRoute(this);},
                "click": function(e){_self.selectRoute(this);}
            });

NoSubject's avatar
NoSubject 已提交
349
            if (routeList.length==1 || route.sole ){ //sole表示优先路由
R
roo00 已提交
350 351
                this.selectRoute(routeNode);
            }else{
U
unknown 已提交
352
                flag = true;
R
roo00 已提交
353
            }
R
roo00 已提交
354 355

        }.bind(this));
U
unknown 已提交
356 357 358
        if( flag ){
            this.setSize(0);
        }
R
roo00 已提交
359 360 361 362
    },
    overRoute: function(node){
        if (this.selectedRoute){
            if (this.selectedRoute.get("text") != node.get("text")){
R
roo00 已提交
363
                node.setStyles(this.css.routeNode_over);
364
                node.addClass("lightColor_bg");
R
roo00 已提交
365
                //node.setStyle("background-color", "#f7e1d0");
R
roo00 已提交
366 367
            }
        }else{
R
roo00 已提交
368
            node.setStyles(this.css.routeNode_over);
369
            node.addClass("lightColor_bg");
R
roo00 已提交
370 371 372 373 374
        }
    },
    outRoute: function(node){
        if (this.selectedRoute){
            if (this.selectedRoute.get("text") != node.get("text")){
NoSubject's avatar
NoSubject 已提交
375
                node.setStyles(this.css.routeNode);
376
                node.removeClass("lightColor_bg");
R
roo00 已提交
377 378
            }
        }else{
NoSubject's avatar
NoSubject 已提交
379
            node.setStyles(this.css.routeNode);
380
            node.removeClass("lightColor_bg");
R
roo00 已提交
381 382
        }
    },
NoSubject's avatar
NoSubject 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
    selectRoute_noform: function(node){
        if (this.selectedRoute){
            if (this.selectedRoute.get("text") != node.get("text")){
                this.selectedRoute.setStyles(this.css.routeNode);

                this.selectedRoute = node;
                node.setStyles(this.css.routeNode_selected);

            }else{
                this.selectedRoute.setStyles(this.css.routeNode);
                this.selectedRoute = null;
            }
        }else{
            this.selectedRoute = node;
            node.setStyles(this.css.routeNode_selected);
        }
        this.routeSelectorArea.setStyle("background-color", "#FFF");
    },
R
roo00 已提交
401 402 403 404
    selectRoute: function(node){
        if (this.selectedRoute){
            if (this.selectedRoute.get("text") != node.get("text")){
                this.selectedRoute.setStyles(this.css.routeNode);
405
                this.selectedRoute.removeClass("mainColor_bg");
R
roo00 已提交
406 407
                //this.selectedRoute.getFirst().setStyles(this.css.routeIconNode);
                //this.selectedRoute.getLast().setStyles(this.css.routeTextNode);
R
roo00 已提交
408 409

                this.selectedRoute = node;
R
roo00 已提交
410
                node.setStyles(this.css.routeNode_selected);
411 412
                node.addClass("mainColor_bg");
                node.removeClass("lightColor_bg");
R
roo00 已提交
413 414 415
                //node.setStyle("background-color", "#da7429");
                //node.getFirst().setStyle("background-image", "url("+"/x_component_process_Work/$Processor/default/checked.png)");
                //node.getLast().setStyle("color", "#FFF");
R
roo00 已提交
416

R
roo00 已提交
417 418
            }else{
                this.selectedRoute.setStyles(this.css.routeNode);
U
unknown 已提交
419 420
                this.selectedRoute.addClass("lightColor_bg");
                this.selectedRoute.removeClass("mainColor_bg");
R
roo00 已提交
421 422
                //this.selectedRoute.getFirst().setStyles(this.css.routeIconNode);
                //this.selectedRoute.getLast().setStyles(this.css.routeTextNode);
R
roo00 已提交
423 424 425 426 427

                this.selectedRoute = null;
            }
        }else{
            this.selectedRoute = node;
R
roo00 已提交
428
            node.setStyles(this.css.routeNode_selected);
429 430
            node.addClass("mainColor_bg");
            node.removeClass("lightColor_bg");
R
roo00 已提交
431 432 433
            //node.setStyle("background-color", "#da7429");
            //node.getFirst().setStyle("background-image", "url("+"/x_component_process_Work/$Processor/default/checked.png)");
            //node.getLast().setStyle("color", "#FFF");
R
roo00 已提交
434 435
        }
        this.routeSelectorArea.setStyle("background-color", "#FFF");
R
roo00 已提交
436 437 438 439 440 441 442 443 444 445 446
        if( layout.mobile ){
            this.loadOrgs_mobile( this.selectedRoute ? this.selectedRoute.retrieve("route") : "" );
        }else{
            this.loadOrgs( this.selectedRoute ? this.selectedRoute.retrieve("route") : "" );
        }

        //临时添加
        if(this.form.data.json.events.afterSelectRoute){
            this.form.Macro.exec(this.form.data.json.events.afterSelectRoute.code, node);
        }

R
roo00 已提交
447 448 449 450 451 452 453 454 455 456 457 458 459 460
    },

    setOpinion: function(){
        this.selectIdeaNode = new Element("div", {"styles": this.css.selectIdeaNode}).inject(this.routeOpinionArea);
        this.selectIdeaScrollNode = new Element("div", {"styles": this.css.selectIdeaScrollNode}).inject(this.selectIdeaNode);
        this.selectIdeaAreaNode = new Element("div", {"styles": {
            "overflow": "hidden"
        }}).inject(this.selectIdeaScrollNode);

        this.inputOpinionNode = new Element("div", {"styles": this.css.inputOpinionNode}).inject(this.routeOpinionArea);
        this.inputTextarea = new Element("textarea", {"styles": this.css.inputTextarea, "value": this.options.opinion || MWF.xApplication.process.Work.LP.inputText}).inject(this.inputOpinionNode);
        this.inputTextarea.addEvents({
            "focus": function(){if (this.get("value")==MWF.xApplication.process.Work.LP.inputText) this.set("value", "");},
            "blur": function(){if (!this.get("value")) this.set("value", MWF.xApplication.process.Work.LP.inputText);},
R
roo00 已提交
461
            "keydown": function(){this.inputTextarea.setStyles( this.inputTextareaStyle || this.css.inputTextarea);}.bind(this)
R
roo00 已提交
462 463 464 465 466
        });

        this.mediaActionArea = new Element("div", {"styles": this.css.inputOpinionMediaActionArea}).inject(this.inputOpinionNode);
        this.handwritingAction = new Element("div", {"styles": this.css.inputOpinionHandwritingAction, "text": MWF.xApplication.process.Work.LP.handwriting}).inject(this.mediaActionArea);
        this.handwritingAction.addEvent("click", function(){
NoSubject's avatar
NoSubject 已提交
467 468 469 470 471 472 473
            if( layout.mobile ){
                window.setTimeout( function(){
                    this.handwriting();
                }.bind(this), 100 )
            }else{
                this.handwriting();
            }
R
roo00 已提交
474 475
        }.bind(this));

NoSubject's avatar
NoSubject 已提交
476 477 478 479 480 481
        // if (navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia){
        //     this.audioRecordAction = new Element("div", {"styles": this.css.inputOpinionAudioRecordAction, "text": MWF.xApplication.process.Work.LP.audioRecord}).inject(this.mediaActionArea);
        //     this.audioRecordAction.addEvent("click", function(){
        //         this.audioRecord();
        //     }.bind(this));
        // }
R
roo00 已提交
482

NoSubject's avatar
NoSubject 已提交
483 484 485 486
        if (layout.mobile){
            this.selectIdeaNode.inject(this.routeOpinionArea, "after");
        }

R
roo00 已提交
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 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
        MWF.require("MWF.widget.ScrollBar", function(){
            new MWF.widget.ScrollBar(this.selectIdeaScrollNode, {
                "style":"small", "where": "before", "distance": 30, "friction": 4, "indent": false,	"axis": {"x": false, "y": true}
            });
        }.bind(this));

        MWF.require("MWF.widget.UUID", function(){
            MWF.UD.getDataJson("idea", function(json){
                if (json){
                    if (json.ideas){
                        this.setIdeaList(json.ideas);
                    }
                }else{
                    MWF.UD.getPublicData("idea", function(pjson){
                        if (pjson){
                            if (pjson.ideas){
                                this.setIdeaList(pjson.ideas);
                            }
                        }
                    }.bind(this));
                }
            }.bind(this));
        }.bind(this));
    },
    audioRecord: function(){
        if (!this.audioRecordNode) this.createAudioRecord();
        this.audioRecordNode.show();
        this.audioRecordNode.position({
            "relativeTo": this.options.mediaNode || this.node,
            "position": "center",
            "edge": "center"
        });

        MWF.require("MWF.widget.AudioRecorder", function () {
            this.audioRecorder = new MWF.widget.AudioRecorder(this.audioRecordNode, {
                "onSave" : function( blobFile ){
                    this.soundFile = blobFile;
                    this.audioRecordNode.hide();
                    // this.page.get("div_image").node.set("src",base64Image);
                }.bind(this),
                "onCancel": function(){
                    this.soundFile = null;
                    this.audioRecordNode.hide();
                }.bind(this)
            }, null );
        }.bind(this));
    },
    createAudioRecord: function(){
        this.audioRecordNode = new Element("div", {"styles": this.css.handwritingNode}).inject(this.node, "after");
        var size = (this.options.mediaNode || this.node).getSize();
        // var y = Math.max(size.y, 320);
        // var x = Math.max(size.x, 400);

        // for (k in this.node.style){
        //     if (this.node.style[k]) this.audioRecordNode.style[k] = this.node.style[k];
        // }
        var zidx = this.node.getStyle("z-index");
        this.audioRecordNode.setStyles({
            "height": ""+size.y+"px",
            "width": ""+size.x+"px",
            "z-index": zidx+1
        });
    },

    handwriting: function(){
        if (!this.handwritingNode) this.createHandwriting();
R
roo00 已提交
553
        if(this.handwritingNodeMask)this.handwritingNodeMask.show();
R
roo00 已提交
554
        this.handwritingNode.show();
NoSubject's avatar
NoSubject 已提交
555 556 557 558 559 560 561 562 563 564 565 566
        if( layout.mobile ){
            this.handwritingNode.setStyles({
                "top": "0px",
                "left": "0px"
            });
        }else{
            this.handwritingNode.position({
                "relativeTo": this.options.mediaNode || this.node,
                "position": "center",
                "edge": "center"
            });
        }
R
roo00 已提交
567 568
    },
    createHandwriting: function(){
NoSubject's avatar
NoSubject 已提交
569
        this.handwritingNodeMask = new Element("div.handwritingMask", {"styles": this.css.handwritingMask}).inject(this.node);
R
roo00 已提交
570

NoSubject's avatar
NoSubject 已提交
571
        this.handwritingNode = new Element("div.handwritingNode", {"styles": this.css.handwritingNode}).inject(this.node, "after");
R
roo00 已提交
572 573 574 575 576 577
        //var size = (this.options.mediaNode || this.node).getSize();
        //var y = size.y;
        //var x = size.x;
        //兼容以前的默认高宽
        var x = 600;
        var y = 320;
NoSubject's avatar
NoSubject 已提交
578
        if (!layout.mobile){
NoSubject's avatar
NoSubject 已提交
579 580 581 582 583 584

            x = Math.max( this.options.tabletWidth || x , 500);
            y = Math.max(this.options.tabletHeight ? (parseInt(this.options.tabletHeight) + 110) : y, 320);

            //y = Math.max(size.y, 320);
            //x = Math.max(size.x, 480);
NoSubject's avatar
NoSubject 已提交
585 586 587 588 589 590
        }else{
            var bodySize = $(document.body).getSize();
            x = bodySize.x;
            y = bodySize.y;
            this.options.tabletWidth = 0;
            this.options.tabletHeight = 0;
NoSubject's avatar
NoSubject 已提交
591
        }
R
roo00 已提交
592 593 594 595 596 597 598 599 600
        // for (k in this.node.style){
        //     if (this.node.style[k]) this.handwritingNode.style[k] = this.node.style[k];
        // }
        var zidx = this.node.getStyle("z-index");
        this.handwritingNode.setStyles({
            "height": ""+y+"px",
            "width": ""+x+"px",
            "z-index": zidx+1
        });
NoSubject's avatar
NoSubject 已提交
601
        if( layout.mobile ){
NoSubject's avatar
NoSubject 已提交
602
            debugger;
NoSubject's avatar
NoSubject 已提交
603 604
            this.handwritingNode.addEvent('touchmove' , function(e){
                e.preventDefault();
NoSubject's avatar
NoSubject 已提交
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
            });
            this.handwritingNode.setStyles({
                "top": "0px",
                "left": "0px"
            });
            //this.handwritingNode.position({
            //    "relativeTo": this.node,
            //    "position": "center",
            //    "edge": "center"
            //});
        }else{
            this.handwritingNode.position({
                "relativeTo": this.options.mediaNode || this.node,
                "position": "center",
                "edge": "center"
            });
NoSubject's avatar
NoSubject 已提交
621
        }
R
roo00 已提交
622 623 624 625 626 627 628
        this.handwritingAreaNode = new Element("div", {"styles": this.css.handwritingAreaNode}).inject(this.handwritingNode);
        this.handwritingActionNode = new Element("div", {"styles": this.css.handwritingActionNode, "text": MWF.xApplication.process.Work.LP.saveWrite}).inject(this.handwritingNode);
        var h = this.handwritingActionNode.getSize().y+this.handwritingActionNode.getStyle("margin-top").toInt()+this.handwritingActionNode.getStyle("margin-bottom").toInt();
        h = y - h;
        this.handwritingAreaNode.setStyle("height", ""+h+"px");

        MWF.require("MWF.widget.Tablet", function () {
NoSubject's avatar
NoSubject 已提交
629
            var handWritingOptions = {
R
roo00 已提交
630
                "style": "default",
NoSubject's avatar
NoSubject 已提交
631 632
                "contentWidth" : this.options.tabletWidth || 0,
                "contentHeight" : this.options.tabletHeight || 0,
R
roo00 已提交
633 634 635
                "onSave" : function( base64code, base64Image, imageFile ){
                    this.handwritingFile = imageFile;
                    this.handwritingNode.hide();
R
roo00 已提交
636
                    this.handwritingNodeMask.hide();
R
roo00 已提交
637
                    // this.page.get("div_image").node.set("src",base64Image);
NoSubject's avatar
NoSubject 已提交
638

R
roo00 已提交
639 640 641 642
                }.bind(this),
                "onCancel": function(){
                    this.handwritingFile = null;
                    this.handwritingNode.hide();
R
roo00 已提交
643
                    this.handwritingNodeMask.hide();
R
roo00 已提交
644
                }.bind(this)
NoSubject's avatar
NoSubject 已提交
645 646 647 648 649 650 651 652 653 654 655
            };
            if( layout.mobile ){
                handWritingOptions.tools = [
                    "undo",
                    "redo", "|",
                    "reset", "|",
                    "size",
                    "cancel"
                ]
            }
            this.tablet = new MWF.widget.Tablet(this.handwritingAreaNode, handWritingOptions, null );
R
roo00 已提交
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
            this.tablet.load();
        }.bind(this));

        this.handwritingActionNode.addEvent("click", function(){
            //this.handwritingNode.hide();
            if (this.tablet) this.tablet.save();
        }.bind(this));
    },

    setIdeaList: function(ideas){
        var _self = this;
        ideas.each(function(idea){
            new Element("div", {
                "styles": this.css.selectIdeaItemNode,
                "text": idea,
                "events": {
NoSubject's avatar
NoSubject 已提交
672 673 674 675 676 677 678
                    "click": function(){
                        if (_self.inputTextarea.get("value")==MWF.xApplication.process.Work.LP.inputText){
                            _self.inputTextarea.set("value", this.get("text"));
                        }else{
                            _self.inputTextarea.set("value", _self.inputTextarea.get("value")+", "+this.get("text"));
                        }
                    },
R
roo00 已提交
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
                    "dblclick": function(){
                        if (_self.inputTextarea.get("value")==MWF.xApplication.process.Work.LP.inputText){
                            _self.inputTextarea.set("value", this.get("text"));
                        }else{
                            _self.inputTextarea.set("value", _self.inputTextarea.get("value")+", "+this.get("text"));
                        }
                    },
                    "mouseover": function(){this.setStyles(_self.css.selectIdeaItemNode_over);},
                    "mouseout": function(){this.setStyles(_self.css.selectIdeaItemNode);}
                }
            }).inject(this.selectIdeaAreaNode);
        }.bind(this));
    },
    setButtons: function(){
        this.cancelButton = new Element("div", {"styles": this.css.cancelButton}).inject(this.buttonsArea);
        var iconNode = new Element("div", {"styles": this.css.cancelIconNode}).inject(this.cancelButton);
        var textNode = new Element("div", {"styles": this.css.cancelTextNode, "text": MWF.xApplication.process.Work.LP.cancel}).inject(this.cancelButton);

        this.okButton = new Element("div", {"styles": this.css.okButton}).inject(this.buttonsArea);
        var iconNode = new Element("div", {"styles": this.css.okIconNode}).inject(this.okButton);
        var textNode = new Element("div", {"styles": this.css.okTextNode, "text": MWF.xApplication.process.Work.LP.ok}).inject(this.okButton);

        this.cancelButton.addEvent("click", function(){
            this.destroy();
            this.fireEvent("cancel");
        }.bind(this));

R
roo00 已提交
706
        this.okButton.addEvent("click", function( ev ){
R
roo00 已提交
707 708 709 710 711 712 713 714
            if( layout.mobile ){
                this.submit_mobile(ev)
            }else{
                this.submit_pc(ev)
            }
        }.bind(this));
    },
    submit_mobile : function(ev){
NoSubject's avatar
NoSubject 已提交
715 716 717 718 719 720 721 722 723 724 725 726 727
        if (this.hasDecisionOpinion && !this.selectedRouteGroup) {
            this.routeGroupArea.setStyle("background-color", "#ffe9e9");
            MWF.xDesktop.notice(
                "error",
                {"x": "center", "y": "top"},
                MWF.xApplication.process.Work.LP.mustSelectRouteGroup,
                this.routeGroupArea,
                null,  //{"x": 0, "y": 30}
                { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
            );
            return false;
        }

R
roo00 已提交
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824
        if (!this.selectedRoute) {
            this.routeSelectorArea.setStyle("background-color", "#ffe9e9");
            new mBox.Notice({
                type: "error",
                position: {"x": "center", "y": "top"},
                move: false,
                target: this.routeSelectorArea,
                delayClose: 6000,
                content: MWF.xApplication.process.Work.LP.mustSelectRoute
            });
            return false;
        }
        var routeName = this.selectedRoute.retrieve("routeName") || this.selectedRoute.get("text");
        var opinion = this.inputTextarea.get("value");
        if (opinion === MWF.xApplication.process.Work.LP.inputText) opinion = "";
        var medias = [];
        if (this.handwritingFile) medias.push(this.handwritingFile);
        if (this.soundFile) medias.push(this.soundFile);
        if (this.videoFile) medias.push(this.videoFile);

        var currentRouteId = this.selectedRoute.retrieve("route");
        var routeData = this.getRouteData( currentRouteId );
        if( !opinion && medias.length === 0  ){
            if( routeData.opinionRequired == true ){
                this.inputTextarea.setStyle("background-color", "#ffe9e9");
                new mBox.Notice({
                    type: "error",
                    position: {"x": "center", "y": "top"},
                    move: false,
                    target: this.inputTextarea,
                    delayClose: 6000,
                    content: MWF.xApplication.process.Work.LP.opinionRequired
                });
                return false;
            }
        }

        if( routeData.validationScriptText ){
            var validation = this.form.Macro.exec(routeData.validationScriptText, this);
            if( !validation || validation.toString() !== "true" ){
                if( typeOf(validation) === "string" ){
                    new mBox.Notice({
                        type: "error",
                        position: {"x": "center", "y": "top"},
                        move: false,
                        target: this.node,
                        delayClose: 6000,
                        content: validation
                    });
                    return false;
                }else{
                    //"路由校验失败"
                    new mBox.Notice({
                        type: "error",
                        position: {"x": "center", "y": "top"},
                        move: false,
                        target: this.node,
                        delayClose: 6000,
                        content: MWF.xApplication.process.Work.LP.routeValidFailure
                    });
                    return false;
                }
            }
        }

        //var array = [routeName, opinion, medias];
        //this.node.mask({
        //    "inject": {"where": "bottom", "target": this.node},
        //    "destroyOnHide": true,
        //    "style": {
        //        "background-color": "#999",
        //        "opacity": 0.3,
        //        "z-index":600
        //    }
        //});
        //this.fireEvent("submit", array );

        var appendTaskOrgItem;
        if( routeData.type === "appendTask" && routeData.appendTaskIdentityType === "select" ){
            if( !this.orgItems || this.orgItems.length === 0 ){
                new mBox.Notice({
                    type: "error",
                    position: {"x": "center", "y": "top"},
                    move: false,
                    target: this.orgsArea,
                    delayClose: 6000,
                    content: MWF.xApplication.process.Work.LP.noAppendTaskIdentityConfig //"没有配置转交人,请联系管理员"
                });
                return false;
            }else{
                appendTaskOrgItem = this.orgItems[0]
            }
        }

        if( !this.saveOrgs() )return false;

        //this.saveOrgsWithCheckEmpower( function(){
NoSubject's avatar
NoSubject 已提交
825
        var appandTaskIdentityList;
R
roo00 已提交
826
        if( appendTaskOrgItem ){
NoSubject's avatar
NoSubject 已提交
827
            appandTaskIdentityList = appendTaskOrgItem.getData();
R
roo00 已提交
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877
            if( !appandTaskIdentityList || appandTaskIdentityList.length === 0){
                new mBox.Notice({
                    type: "error",
                    position: {"x": "center", "y": "top"},
                    move: false,
                    target: this.orgsArea,
                    delayClose: 6000,
                    content:  MWF.xApplication.process.Work.LP.selectAppendTaskIdentityNotice //"请选择转交人"
                });
                return;
            }
        }

        if( routeData.validationScriptText ){
            var validation = this.form.Macro.exec(routeData.validationScriptText, this);
            if( !validation || validation.toString() !== "true" ){
                if( typeOf(validation) === "string" ){
                    MWF.xDesktop.notice(
                        "error",
                        {"x": "center", "y": "center"},
                        validation,
                        this.node,
                        {"x": 0, "y": 30},
                        { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
                    );
                    return false;
                }else{
                    //"路由校验失败"
                    MWF.xDesktop.notice(
                        "error",
                        {"x": "center", "y": "center"},
                        MWF.xApplication.process.Work.LP.routeValidFailure,
                        this.node,
                        {"x": 0, "y": 30},
                        { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
                    );
                    return false;
                }
            }
        }

        this.node.mask({
            "inject": {"where": "bottom", "target": this.node},
            "destroyOnHide": true,
            "style": {
                "background-color": "#999",
                "opacity": 0.3,
                "z-index":600
            }
        });
NoSubject's avatar
NoSubject 已提交
878 879 880 881 882

        var array = [ routeName, opinion, medias, appandTaskIdentityList, this.orgItems, function(){
            if(appendTaskOrgItem)appendTaskOrgItem.setData([]);
        }];

R
roo00 已提交
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
        this.fireEvent("submit", array );
        //}.bind(this))
    },
    submit_pc : function(ev){
        if (this.hasDecisionOpinion && !this.selectedRouteGroup) {
            this.routeGroupArea.setStyle("background-color", "#ffe9e9");
            MWF.xDesktop.notice(
                "error",
                {"x": "center", "y": "top"},
                MWF.xApplication.process.Work.LP.mustSelectRouteGroup,
                this.routeGroupArea,
                null,  //{"x": 0, "y": 30}
                { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
            );
            return false;
        }

        if (!this.selectedRoute) {
            this.routeSelectorArea.setStyle("background-color", "#ffe9e9");
            //new mBox.Notice({
            //    type: "error",
            //    position: {"x": "center", "y": "top"},
            //    move: false,
            //    target: this.routeSelectorArea,
            //    delayClose: 6000,
            //    content: MWF.xApplication.process.Work.LP.mustSelectRoute
            //});
            MWF.xDesktop.notice(
                "error",
                {"x": "center", "y": "top"},
                MWF.xApplication.process.Work.LP.mustSelectRoute,
                this.routeSelectorArea,
                null,  //{"x": 0, "y": 30}
                { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
            );
            return false;
        }
        var routeName = this.selectedRoute.retrieve("routeName") || this.selectedRoute.get("text");
        var opinion = this.inputTextarea.get("value");
        if (opinion === MWF.xApplication.process.Work.LP.inputText) opinion = "";
        var medias = [];
        if (this.handwritingFile) medias.push(this.handwritingFile);
        if (this.soundFile) medias.push(this.soundFile);
        if (this.videoFile) medias.push(this.videoFile);

        var currentRouteId = this.selectedRoute.retrieve("route");
        var routeData = this.getRouteData( currentRouteId );
        if( !opinion && medias.length === 0  ){
            if( routeData.opinionRequired == true ){
                this.inputTextarea.setStyle("background-color", "#ffe9e9");
R
roo00 已提交
933 934 935 936
                //new mBox.Notice({
                //    type: "error",
                //    position: {"x": "center", "y": "top"},
                //    move: false,
R
roo00 已提交
937
                //    target: this.inputTextarea,
R
roo00 已提交
938
                //    delayClose: 6000,
R
roo00 已提交
939
                //    content: MWF.xApplication.process.Work.LP.opinionRequired
R
roo00 已提交
940 941 942 943
                //});
                MWF.xDesktop.notice(
                    "error",
                    {"x": "center", "y": "top"},
R
roo00 已提交
944 945
                    MWF.xApplication.process.Work.LP.opinionRequired,
                    this.inputTextarea,
R
roo00 已提交
946 947 948
                    null,  //{"x": 0, "y": 30}
                    { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
                );
R
roo00 已提交
949 950
                return false;
            }
R
roo00 已提交
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
        }

        var appendTaskOrgItem = "";
        if( routeData.type === "appendTask" && routeData.appendTaskIdentityType === "select" ){
            if( !this.orgItems || this.orgItems.length === 0 ){
                //new mBox.Notice({
                //    type: "error",
                //    position: {"x": "center", "y": "top"},
                //    move: false,
                //    target: this.orgsArea,
                //    delayClose: 6000,
                //    content: MWF.xApplication.process.Work.LP.noAppendTaskIdentityConfig //"没有配置转交人,请联系管理员"
                //});
                MWF.xDesktop.notice(
                    "error",
                    {"x": "center", "y": "center"},
                    MWF.xApplication.process.Work.LP.noAppendTaskIdentityConfig,
                    this.node,
                    null,  //{"x": 0, "y": 30}
                    { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
                );
                return false;
            }else{
                appendTaskOrgItem = this.orgItems[0]
R
roo00 已提交
975
            }
R
roo00 已提交
976
        }
R
roo00 已提交
977

R
roo00 已提交
978 979

        this.saveOrgsWithCheckEmpower( function(){
NoSubject's avatar
NoSubject 已提交
980
            var appandTaskIdentityList;
R
roo00 已提交
981
            if( appendTaskOrgItem ){
NoSubject's avatar
NoSubject 已提交
982
                appandTaskIdentityList = appendTaskOrgItem.getData();
R
roo00 已提交
983
                if( !appandTaskIdentityList || appandTaskIdentityList.length === 0){
R
roo00 已提交
984 985 986 987 988 989
                    //new mBox.Notice({
                    //    type: "error",
                    //    position: {"x": "center", "y": "top"},
                    //    move: false,
                    //    target: this.orgsArea,
                    //    delayClose: 6000,
R
roo00 已提交
990
                    //    content:  MWF.xApplication.process.Work.LP.selectAppendTaskIdentityNotice //"请选择转交人"
R
roo00 已提交
991 992 993 994
                    //});
                    MWF.xDesktop.notice(
                        "error",
                        {"x": "center", "y": "center"},
R
roo00 已提交
995
                        MWF.xApplication.process.Work.LP.selectAppendTaskIdentityNotice,
R
roo00 已提交
996
                        this.node,
R
roo00 已提交
997
                        {"x": 0, "y": 30},
R
roo00 已提交
998 999
                        { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
                    );
R
roo00 已提交
1000
                    return;
R
roo00 已提交
1001 1002 1003
                }
            }

R
roo00 已提交
1004 1005 1006 1007
            if( routeData.validationScriptText ){
                var validation = this.form.Macro.exec(routeData.validationScriptText, this);
                if( !validation || validation.toString() !== "true" ){
                    if( typeOf(validation) === "string" ){
R
roo00 已提交
1008 1009 1010
                        MWF.xDesktop.notice(
                            "error",
                            {"x": "center", "y": "center"},
R
roo00 已提交
1011
                            validation,
R
roo00 已提交
1012 1013 1014 1015
                            this.node,
                            {"x": 0, "y": 30},
                            { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
                        );
R
roo00 已提交
1016
                        return false;
R
roo00 已提交
1017
                    }else{
R
roo00 已提交
1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
                        //"路由校验失败"
                        MWF.xDesktop.notice(
                            "error",
                            {"x": "center", "y": "center"},
                            MWF.xApplication.process.Work.LP.routeValidFailure,
                            this.node,
                            {"x": 0, "y": 30},
                            { "closeOnBoxClick" : true, "closeOnBodyClick" : true, "fixed" : true, "delayClose" : 6000 }
                        );
                        return false;
R
roo00 已提交
1028 1029
                    }
                }
R
roo00 已提交
1030
            }
R
roo00 已提交
1031

R
roo00 已提交
1032 1033 1034 1035 1036 1037 1038
            this.node.mask({
                "inject": {"where": "bottom", "target": this.node},
                "destroyOnHide": true,
                "style": {
                    "background-color": "#999",
                    "opacity": 0.3,
                    "z-index":600
R
roo00 已提交
1039
                }
R
roo00 已提交
1040
            });
NoSubject's avatar
NoSubject 已提交
1041 1042 1043 1044 1045 1046


            var array = [ routeName, opinion, medias, appandTaskIdentityList, this.orgItems, function(){
                if(appendTaskOrgItem)appendTaskOrgItem.setData([]);
            }];

R
roo00 已提交
1047 1048
            this.fireEvent("submit", array );
        }.bind(this))
R
roo00 已提交
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
    },


    destroy: function(){
        this.node.empty();
        delete this.task;
        delete this.node;
        delete this.routeSelectorTile;
        delete this.routeSelectorArea;
        delete this.routeOpinionTile;
        delete this.routeOpinionArea;
        delete this.buttonsArea;
        delete this.inputOpinionNode;
        delete this.inputTextarea;
        delete this.cancelButton;
        delete this.okButton;
R
roo00 已提交
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
    },
    getRouteDataList : function(){
        if( !this.routeDataList ){
            o2.Actions.get("x_processplatform_assemble_surface").listRoute( {"valueList":this.task.routeList} , function( json ){
                json.data.each( function(d){
                    d.selectConfigList = JSON.parse( d.selectConfig || "[]" );
                }.bind(this));
                this.routeDataList = json.data;
            }.bind(this), null, false );
        }
        return this.routeDataList;
    },
    getRouteData : function( routeId ){
        var routeList = this.getRouteDataList();
        for( var i=0; i<routeList.length; i++ ){
            if( routeList[i].id === routeId ){
                return routeList[i];
            }
        }
    },
    getMaxOrgLength : function(){
        var routeList = this.getRouteDataList();
        var length = 0;
        routeList.each( function(route){
R
roo00 已提交
1089 1090 1091
            if( route.hiddenScriptText ){ //如果隐藏路由,返回
                if( this.form.Macro.exec(route.hiddenScriptText, this).toString() === "true" )return;
            }
R
roo00 已提交
1092
            length = Math.max( length, route.selectConfigList.length);
R
roo00 已提交
1093
        }.bind(this));
R
roo00 已提交
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
        return length;
    },
    getOrgData : function( routeId ){
        var routeList = this.getRouteDataList();
        for( var i=0; i<routeList.length; i++ ){
            if( routeList[i].id === routeId ){
                return routeList[i].selectConfigList;
            }
        }
    },
R
roo00 已提交
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129
    loadOrgs_mobile : function( route ){
        if( !this.form || !route ){
            this.orgsArea.hide();
            return;
        }else{
            this.orgsArea.show();
        }
        if( !this.orgTableObject )this.orgTableObject = {};
        if( !this.orgItemsObject )this.orgItemsObject = {};
        var isLoaded = false;
        for( var key in this.orgTableObject ){
            if( route === key ){
                this.orgTableObject[key].show();
                this.orgItems = this.orgItemsObject[key] || [];
                var data = this.getOrgData( route );
                isLoaded = true;
            }else{
                this.orgTableObject[key].hide();
            }
        }
        if( isLoaded )return;

        this.orgItems = [];
        this.orgItemsObject[route] = this.orgItems;

        var data = this.getOrgData( route );
NoSubject's avatar
NoSubject 已提交
1130 1131
        var routeConfig = this.getRouteData( route );
        var ignoreFirstOrgOldData = false; //(routeConfig.type === "appendTask" && routeConfig.appendTaskIdentityType === "select");
U
unknown 已提交
1132
        this.setSize( data.length );
R
roo00 已提交
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
        if( data.length  ){
            this.orgsArea.show();

            var routeOrgTable = new Element("div",{
                "styles" : this.css.routeOrgTable
            }).inject( this.orgsArea );
            this.orgTableObject[route] = routeOrgTable;

            data.each( function( config, i ){
                var sNode = new Element("div",{
                    "styles" : this.css.routeOrgTr
                }).inject( routeOrgTable );
NoSubject's avatar
NoSubject 已提交
1145
                this.loadOrg_mobile( sNode, config, ignoreFirstOrgOldData && i==0 )
R
roo00 已提交
1146 1147 1148 1149 1150
            }.bind(this))
        }else{
            this.orgsArea.hide();
        }
    },
NoSubject's avatar
NoSubject 已提交
1151
    loadOrg_mobile : function( container, json, ignoreOldData ){
R
roo00 已提交
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
        var titleNode = new Element("div.selectorTitle", {
            "styles" : this.css.selectorTitle
        }).inject(container);
        var titleTextNode = new Element("div.selectorTitleText", {
            "text": json.title,
            "styles" : this.css.selectorTitleText
        }).inject(titleNode);

        var contentNode = new Element("div.selectorContent", {
            "styles" : this.css.selectorContent
        }).inject(container);

        var errorNode = new Element("div.selectorErrorNode", {
            "styles" : this.css.selectorErrorNode
        }).inject(container);

        var org = new MWF.xApplication.process.Work.Processor.Org( contentNode, this.form, json, this, {
            onSelect : function(items, data){
                if( !data || !data.length ){
                    contentNode.setStyles( this.css.selectorContent_noItem );
                }else{
                    contentNode.setStyles( this.css.selectorContent );
                }
            }.bind(this)
        });
NoSubject's avatar
NoSubject 已提交
1177
        org.ignoreOldData = ignoreOldData;
R
roo00 已提交
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
        org.errContainer = errorNode;
        org.summitDlalog = this;
        this.orgItems.push( org );

        titleNode.addEvent("click", function(){
            this.load();
        }.bind(org));
        contentNode.addEvent("click", function(){
            this.load();
        }.bind(org));

        var defaultValue = org.getValue();
        org.loadOrgWidget( defaultValue, contentNode );
        if( !defaultValue || defaultValue.length == 0){{
            contentNode.setStyles( this.css.selectorContent_noItem );
        }}

    },
R
roo00 已提交
1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223
    loadOrgs : function( route ){
        if( !this.form || !route ){
            this.orgsArea.hide();
            this.setSize( 0 );
            return;
        }else{
            this.orgsArea.show();
        }
        if( !this.orgTableObject )this.orgTableObject = {};
        if( !this.orgItemsObject )this.orgItemsObject = {};
        var isLoaded = false;
        for( var key in this.orgTableObject ){
            if( route === key ){
                this.orgTableObject[key].show();
                this.orgItems = this.orgItemsObject[key] || [];
                var data = this.getOrgData( route );
                this.setSize( data.length );
                isLoaded = true;
            }else{
                this.orgTableObject[key].hide();
            }
        }
        if( isLoaded )return;

        this.orgItems = [];
        this.orgItemsObject[route] = this.orgItems;

        var data = this.getOrgData( route );
NoSubject's avatar
NoSubject 已提交
1224 1225
        var routeConfig = this.getRouteData( route );
        var ignoreFirstOrgOldData = false; //(routeConfig.type === "appendTask" && routeConfig.appendTaskIdentityType === "select");
R
roo00 已提交
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
        this.setSize( data.length );
        if( data.length  ){
            this.orgsArea.show();

            var len = data.length;

            var routeOrgTable = new Element("table",{
                "cellspacing" : 0, "cellpadding" : 0, "border" : 0, "width" : "100%",
                "styles" : this.css.routeOrgTable
            }).inject( this.orgsArea );
            this.orgTableObject[route] = routeOrgTable;

            //if( len <= this.options.maxOrgCountPerline ){
            //    var width = 1 / len * 100;
            //    var tr = new Element("tr").inject( routeOrgTable );
            //    for (var n=0; n<len; n++){
            //        new Element("td", { "width" : width+"%", "styles" : this.css.routeOrgOddTd }).inject( tr );
            //    }
            //}else{
            //    var lines = ((len+1)/this.options.maxOrgCountPerline).toInt();
            //    var width = 1 / this.options.maxOrgCountPerline * 100;
            //    for( var n=0; n<lines; n++ ){
            //        var tr = new Element("tr").inject( routeOrgTable );
            //        for( var i=0; i<this.options.maxOrgCountPerline; i++ ){
            //            new Element("td", { "width" : width+"%", "styles" : this.css.routeOrgOddTd }).inject( tr );
            //        }
            //    }
            //}
            //
            //var tds = routeOrgTable.getElements("td");
            //data.each( function( config, i ){
            //    this.loadOrg( tds[i], config )
            //}.bind(this))

            var lines = ((len+1)/2).toInt();
            for (var n=0; n<lines; n++){
                var tr = new Element("tr").inject( routeOrgTable );
                new Element("td", { "width" : "50%", "styles" : this.css.routeOrgOddTd }).inject( tr );
                new Element("td", { "width" : "50%", "styles" : this.css.routeOrgEvenTd }).inject( tr );
            }

            var trs = routeOrgTable.getElements("tr");
            data.each( function( config, i ){
                var sNode;
                var width;
                if (i+1==len && (len % 2===1)){
                    sNode = trs[trs.length-1].getFirst("td");
                    sNode.set("colspan", 2);
                    trs[trs.length-1].getLast("td").destroy();
                    sNode.setStyle("border","0px");
                    sNode.set("width","100%");
NoSubject's avatar
NoSubject 已提交
1277
                    this.loadOrg( sNode, config, "all", ignoreFirstOrgOldData && i==0)
R
roo00 已提交
1278 1279 1280 1281
                }else{
                    var row = ((i+2)/2).toInt();
                    var tr = trs[row-1];
                    sNode = (i % 2===0) ? tr.getFirst("td") : tr.getLast("td");
NoSubject's avatar
NoSubject 已提交
1282
                    this.loadOrg( sNode, config, (i % 2===0) ? "left" : "right", ignoreFirstOrgOldData && i==0 )
R
roo00 已提交
1283 1284 1285 1286 1287 1288 1289
                }
            }.bind(this))
        }else{
            this.orgsArea.hide();
        }

    },
NoSubject's avatar
NoSubject 已提交
1290
    loadOrg : function( container, json, position, ignoreOldData ){
R
roo00 已提交
1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306
        var titleNode = new Element("div.selectorTitle", {
            "styles" : this.css.selectorTitle
        }).inject(container);
        var titleTextNode = new Element("div.selectorTitleText", {
            "text": json.title,
            "styles" : this.css.selectorTitleText
        }).inject(titleNode);

        var errorNode = new Element("div.selectorErrorNode", {
            "styles" : this.css.selectorErrorNode
        }).inject(titleNode);

        var contentNode = new Element("div.selectorContent", {
            "styles" : this.css.selectorContent
        }).inject(container);
        var org = new MWF.xApplication.process.Work.Processor.Org( contentNode, this.form, json, this );
NoSubject's avatar
NoSubject 已提交
1307
        org.ignoreOldData = ignoreOldData;
R
roo00 已提交
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
        org.errContainer = errorNode;
        org.summitDlalog = this;
        org.load();
        this.orgItems.push( org )

    },
    getCurrentRouteSelectorList : function(){
        var selectorList = [];
        var currentRoute = this.selectedRoute ? this.selectedRoute.retrieve("route") : "";
        var orgList = this.orgItemsObject[currentRoute];
        if( !orgList )return [];
        orgList.each( function( org ){
            if( org.selector && org.selector.selector ){
                selectorList.push( org.selector.selector );
            }
        }.bind(this))
        return selectorList;
    },
R
roo00 已提交
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
    getCurrentRouteOrgList : function(){
        var currentRoute = this.selectedRoute ? this.selectedRoute.retrieve("route") : "";
        var orgList = this.orgItemsObject[currentRoute];
        return orgList || [];
    },
    getSelectorSelectedData : function( filedName ){
        var data = [];
        var orgList = this.getCurrentRouteOrgList();
        for( var i=0; i<orgList.length; i++ ){
            var org = orgList[i];
            if( org.json.name === filedName ){
                var selector = org.selector.selector;
                selector.selectedItems.each( function(item){
                    data.push( item.data )
                })
            }
        }
        return data;
    },
R
roo00 已提交
1345 1346 1347 1348 1349 1350 1351 1352
    getOffsetY : function(node){
        return (node.getStyle("margin-top").toInt() || 0 ) +
            (node.getStyle("margin-bottom").toInt() || 0 ) +
            (node.getStyle("padding-top").toInt() || 0 ) +
            (node.getStyle("padding-bottom").toInt() || 0 )+
            (node.getStyle("border-top-width").toInt() || 0 ) +
            (node.getStyle("border-bottom-width").toInt() || 0 );
    },
NoSubject's avatar
NoSubject 已提交
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
    setSize_noform : function(){
        var height = 0;
        if( this.managerProcessNoticeNode )height = height + this.getOffsetY(this.managerProcessNoticeNode) +  this.managerProcessNoticeNode.getStyle("height").toInt();
        if( this.managerLoginNode )height = height + this.getOffsetY(this.managerLoginNode) +  this.managerLoginNode.getStyle("height").toInt();
        if( this.routeSelectorTile )height = height + this.getOffsetY(this.routeSelectorTile) +  this.routeSelectorTile.getStyle("height").toInt();
        if( this.routeSelectorArea )height = height + this.getOffsetY(this.routeSelectorArea) +  this.routeSelectorArea.getStyle("height").toInt();
        if( this.routeOpinionTile )height = height + this.getOffsetY(this.routeOpinionTile) +  this.routeOpinionTile.getStyle("height").toInt();
        if( this.routeOpinionArea )height = height + this.getOffsetY(this.routeOpinionArea) +  this.routeOpinionArea.getStyle("height").toInt();
        this.node.setStyle( "height", height );
        this.fireEvent("resize");
    },
R
roo00 已提交
1364
    setSize : function( currentOrgLength ){
U
unknown 已提交
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389
        if( layout.mobile ){
            this.setSize_mobile();
        }else{
            this.setSize_pc( currentOrgLength );
        }
        //this.node.store("width", this.node.getStyle("width").toInt() + ( flag ? 20 : 0 ));
        this.fireEvent("resize");
    },
    setSize_mobile : function(){
        if( this.buttonsArea ){
            debugger;
            var bodySize = $(document.body).getSize();
            var nodeHeight = bodySize.y - this.getOffsetY(this.node);
            this.node.setStyles({
                "overflow-y": "hidden",
                "height" : nodeHeight
            });
            var buttonsAreaSize = this.buttonsArea.getSize();
            this.content.setStyles({
                "height" : nodeHeight - buttonsAreaSize.y - this.getOffsetY(this.buttonsArea) - this.getOffsetY(this.content),
                "overflow-y" : "auto"
            })
        }
    },
    setSize_pc : function( currentOrgLength ){
R
roo00 已提交
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400
        var lines = ((currentOrgLength+1)/2).toInt();
        var flag = false;

        var height = 0;
        if( this.routeSelectorTile )height = height + this.getOffsetY(this.routeSelectorTile) +  this.routeSelectorTile.getStyle("height").toInt();
        if( this.routeSelectorArea )height = height + this.getOffsetY(this.routeSelectorArea) +  this.routeSelectorArea.getStyle("height").toInt();
        if( this.routeOpinionTile )height = height + this.getOffsetY(this.routeOpinionTile) +  this.routeOpinionTile.getStyle("height").toInt();
        if( this.routeOpinionArea )height = height + this.getOffsetY(this.routeOpinionArea) +  this.routeOpinionArea.getStyle("height").toInt();
        //if( this.buttonsArea )height = height + this.getOffsetY(this.buttonsArea) +  this.buttonsArea.getStyle("height").toInt();

        if( lines > 0 ){
U
unknown 已提交
1401
            if(this.orgsArea)this.orgsArea.show();
R
roo00 已提交
1402 1403 1404 1405 1406 1407 1408
            if( this.orgsTile )height = height + this.getOffsetY(this.orgsTile) +  this.orgsTile.getStyle("height").toInt();
            height = height + lines*this.options.orgHeight + this.getOffsetY(this.orgsArea);
            this.node.setStyle( "height", height );

            //flag = (lines*this.options.orgHeight + 431) > Math.floor( this.form.app.content.getSize().y * 0.9);
            //this.node.store("height", Math.min( Math.floor( this.form.app.content.getSize().y * 0.9) , lines*this.options.orgHeight + 431 ));
        }else{
U
unknown 已提交
1409
            if(this.orgsArea)this.orgsArea.hide();
R
roo00 已提交
1410 1411 1412
            this.node.setStyle( "height", height );
            //this.node.store("height", 401 );
        }
U
unknown 已提交
1413
        debugger;
R
roo00 已提交
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457
        if( this.getMaxOrgLength() > 1 ){
            this.node.setStyles( this.css.node_wide );
            this.inputOpinionNode.setStyles( this.css.inputOpinionNode_wide );
            this.inputTextarea.setStyles( this.css.inputTextarea_wide );
            this.inputTextareaStyle = this.css.inputTextarea_wide;
            this.selectIdeaNode.setStyles( this.css.selectIdeaNode_wide );

        }else{
            this.node.setStyles( this.css.node );
            this.inputOpinionNode.setStyles( this.css.inputOpinionNode );
            this.inputTextarea.setStyles( this.css.inputTextarea );
            this.inputTextareaStyle = this.css.inputTextarea;
            this.selectIdeaNode.setStyles( this.css.selectIdeaNode );
        }
    },
    validationOrgs : function(){
        if( !this.orgItems || !this.orgItems.length )return true;
        var flag = true;
        this.orgItems.each( function(item){
            if( !item.validation() )flag = false;
        }.bind(this));
        return flag;
    },
    isOrgsHasEmpower: function(){
        if( !this.orgItems || !this.orgItems.length )return true;
        var flag = false;
        this.needCheckEmpowerOrg = [];
        this.orgItems.each( function(item){
            if( item.hasEmpowerIdentity() ){
                this.needCheckEmpowerOrg.push(item);
                flag = true;
            }
        }.bind(this));
        return flag;
    },
    saveOrgs : function( keepSilent ){
        if( !this.orgItems || !this.orgItems.length )return true;
        var flag = true;
        this.orgItems.each( function(item){
            if( !item.save( !keepSilent ) )flag = false;
        }.bind(this));
        return flag;
    },
    saveOrgsWithCheckEmpower : function( callback ){
NoSubject's avatar
NoSubject 已提交
1458
        debugger;
R
roo00 已提交
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589
        if( !this.orgItems || !this.orgItems.length ){
            if( callback )callback();
            return true;
        }
        if( !this.validationOrgs() )return false;
        if( !this.isOrgsHasEmpower() ){
            if( callback )callback();
            return true;
        }
        //this.checkEmpowerMode = true;
        this.showEmpowerDlg( callback );
    },
    showEmpowerDlg : function( callback ){
        //this.empowerMask = new Element("div", {"styles": this.css.handwritingMask}).inject(this.node);

        //this.needCheckEmpowerOrg.each( function(org){
        //    org.saveCheckedEmpowerData();
        //}.bind(this));

        var empowerNode = new Element("div.empowerNode", {"styles": this.css.empowerNode});
        var empowerTitleNode = new Element("div",{
            text : MWF.xApplication.process.Xform.LP.empowerDlgText,
            styles : this.css.empowerTitleNode
        }).inject(empowerNode);

        var orgs = this.needCheckEmpowerOrg;
        var len = orgs.length;
        var lines = ((len+1)/2).toInt();

        var empowerTable = new Element("table",{
            "cellspacing" : 0, "cellpadding" : 0, "border" : 0, "width" : "100%",
            "styles" : this.css.empowerTable
        }).inject( empowerNode );

        for (var n=0; n<lines; n++){
            var tr = new Element("tr").inject( empowerTable );
            new Element("td", { "width" : "50%", "styles" : this.css.empowerOddTd }).inject( tr );
            new Element("td", { "width" : "50%", "styles" : this.css.empowerEvenTd }).inject( tr );
        }

        var trs = empowerTable.getElements("tr");
        orgs.each( function( org, i ){
            var sNode;
            var width;
            if (i+1==len && (len % 2===1)){
                sNode = trs[trs.length-1].getFirst("td");
                sNode.set("colspan", 2);
                trs[trs.length-1].getLast("td").destroy();
                width = "50%";
            }else{
                var row = ((i+2)/2).toInt();
                var tr = trs[row-1];
                sNode = (i % 2===0) ? tr.getFirst("td") : tr.getLast("td");
            }

            var titleNode = new Element("div.empowerAreaTitle", {
                "styles" : this.css.empowerAreaTitle
            }).inject(sNode);

            var titleTextNode = new Element("div.empowerAreaTitleText", {
                "text": org.json.title,
                "styles" : this.css.empowerAreaTitleText
            }).inject(titleNode);

            var selectAllNode = new Element("div",{
                styles : {
                    float : "right"
                }
            }).inject(titleNode);

            var contentNode = new Element("div.empowerAreaContent", {
                "styles" : this.css.empowerAreaContent
            }).inject(sNode);

            org.loadCheckEmpower( null, contentNode, selectAllNode );

        }.bind(this));

        empowerNode.setStyle( "height", lines*this.options.orgHeight + 20 );
        //var dlgHeight = Math.min( Math.floor( this.form.app.content.getSize().y * 0.9) , lines*this.options.orgHeight + 151 );

        //var width = this.node.retrieve("width");
        //empowerNode.setStyle( "width", width );
        var width = "880";
        //if( len > 1 ){
        //    width = "840"
        //}else{
        //    width = "420"
        //}
        empowerNode.setStyle( "width", width+"px" );

        this.node.getParent().mask( {
            "style": this.css.mask
        });
        this.empowerDlg = o2.DL.open({
            "title": MWF.xApplication.process.Xform.LP.selectEmpower,
            "style": this.form.json.dialogStyle || "user",
            "isResize": false,
            "content": empowerNode,
            //"container" : this.node,
            "width": width, //600,
            "height": "auto", //dlgHeight,
            "mark" : false,
            "buttonList": [
                {
                    "type" : "ok",
                    "text": MWF.LP.process.button.ok,
                    "action": function(d, e){
                        //if (this.empowerDlg) this.empowerDlg.okButton.click();

                        orgs.each( function( org, i ){
                            org.saveCheckedEmpowerData( function(){
                                if( i === orgs.length-1 ){
                                    if( callback )callback();
                                    this.node.getParent().unmask();
                                    this.empowerDlg.close();
                                }
                            }.bind(this))
                        }.bind(this))
                    }.bind(this)
                },
                {
                    "type" : "cancel",
                    "text": MWF.LP.process.button.cancel,
                    "action": function(){
                        this.node.getParent().unmask();
                        this.empowerDlg.close();
                    }.bind(this)
                }
            ]
        });
NoSubject's avatar
NoSubject 已提交
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605
    },
    managerLogin : function(e){
        debugger;
        var _self = this;
        var user = (this.task.identityDn || this.task.identity).split("@")[0];
        var text = MWF.xApplication.process.Work.LP.managerLoginConfirmContent.replace("{user}", user );
        MWF.xDesktop.confirm("infor", e, MWF.xApplication.process.Work.LP.managerLoginConfirmTitle, text, 450, 120, function () {
            o2.Actions.load("x_organization_assemble_authentication").AuthenticationAction.switchUser({"credential": ( _self.task.personDn || _self.task.person ) }, function(){
                var text = MWF.xApplication.process.Work.LP.managerLoginSuccess.replace("{user}", user );
                MWF.xDesktop.notice("success", {x: "right", y:"top"}, text );
                window.open("/x_desktop/work.html?workid="+_self.task.work);
            }.bind(this));
            this.close();
        }, function () {
            this.close();
        }, null, null);
R
roo00 已提交
1606 1607 1608 1609 1610
    }

});


NoSubject's avatar
NoSubject 已提交
1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630
if( MWF.xApplication.process.Xform && MWF.xApplication.process.Xform.Form ){
    MWF.xApplication.process.Work.Processor.Org = new Class({
        Implements: [Options, Events],
        options: {
            moduleEvents : ["queryLoadSelector","postLoadSelector","postLoadContent","queryLoadCategory","postLoadCategory",
                "selectCategory", "unselectCategory","queryLoadItem","postLoadItem","selectItem", "unselectItem","change"]
        },
        initialize: function (container, form, json, processor, options) {
            this.form = form;
            this.json = json;
            this.processor = processor;
            this.container = $(container);
            this.orgAction = MWF.Actions.get("x_organization_assemble_control");
            this.setOptions(options);
        },
        load : function(){
            if( layout.mobile ){
                setTimeout( function(){ //如果有输入法界面,这个时候页面的计算不对,所以等100毫秒
                    var options = this.getOptions();
                    if(options){
1631 1632
                        //this.selector = new MWF.O2Selector(this.container, options);
                        this.selector = new MWF.O2Selector($(document.body), options);
NoSubject's avatar
NoSubject 已提交
1633 1634 1635 1636 1637 1638
                    }
                }.bind(this), 100 )
            }else{
                var options = this.getOptions();
                if(options){
                    this.selector = new MWF.O2Selector(this.container, options);
R
roo00 已提交
1639 1640
                }
            }
NoSubject's avatar
NoSubject 已提交
1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671
        },
        _getOrgOptions: function(){
            this.selectTypeList = typeOf( this.json.selectType ) == "array" ? this.json.selectType : [this.json.selectType];
            if( this.selectTypeList.contains( "identity" ) ) {
                this.identityOptions = new MWF.xApplication.process.Work.Processor.IdentityOptions(this.form, this.json);
            }
            if( this.selectTypeList.contains( "unit" ) ) {
                this.unitOptions = new MWF.xApplication.process.Work.Processor.UnitOptions(this.form, this.json);
            }
            //if( this.selectTypeList.contains( "group" ) ){
            //    this.groupOptions = new MWF.APPOrg.GroupOptions( this.form, this.json );
            //}
        },
        getOptions: function(){
            var _self = this;
            this._getOrgOptions();
            if( this.selectTypeList.length === 0 )return false;
            var exclude = [];
            if( this.json.exclude ){
                var v = this.form.Macro.exec(this.json.exclude.code, this);
                exclude = typeOf(v)==="array" ? v : [v];
            }

            var identityOpt;
            if( this.identityOptions ){
                identityOpt = this.identityOptions.getOptions();
                if (this.json.identityRange!=="all"){
                    if ( !identityOpt.noUnit && (!identityOpt.units || !identityOpt.units.length) ){
                        this.form.notice(MWF.xApplication.process.Xform.LP.noIdentitySelectRange, "error", this.node);
                        return false;
                    }
R
roo00 已提交
1672
                }
NoSubject's avatar
NoSubject 已提交
1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684
                if ( !identityOpt.noUnit && this.json.dutyRange && this.json.dutyRange!=="all"){
                    if (!identityOpt.dutys || !identityOpt.dutys.length){
                        this.form.notice(MWF.xApplication.process.Xform.LP.noIdentityDutySelectRange, "error", this.node);
                        return false;
                    }
                }
                if( this.ignoreOldData ){
                    identityOpt.values = this._computeValue() || [];
                }else{
                    identityOpt.values = this.getValue();
                }
                identityOpt.exclude = exclude;
R
roo00 已提交
1685 1686
            }

NoSubject's avatar
NoSubject 已提交
1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699
            var unitOpt;
            if( this.unitOptions ){
                unitOpt = this.unitOptions.getOptions();
                if (this.json.unitRange!=="all"){
                    if ( !unitOpt.units || !unitOpt.units.length){
                        this.form.notice(MWF.xApplication.process.Xform.LP.noUnitSelectRange, "error", this.node);
                        return false;
                    }
                }
                if( this.ignoreOldData ){
                    unitOpt.values = this._computeValue() || [];
                }else{
                    unitOpt.values = this.getValue();
R
roo00 已提交
1700
                }
NoSubject's avatar
NoSubject 已提交
1701
                unitOpt.exclude = exclude;
R
roo00 已提交
1702 1703
            }

NoSubject's avatar
NoSubject 已提交
1704 1705 1706 1707 1708 1709
            //var groupOpt;
            //if( this.groupOptions ){
            //    groupOpt = this.groupOptions.getOptions();
            //    groupOpt.values = (this.json.isInput) ? [] : values;
            //    groupOpt.exclude = exclude;
            //}
R
roo00 已提交
1710

NoSubject's avatar
NoSubject 已提交
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726
            var defaultOpt;
            if( layout.mobile ){
                defaultOpt = {
                    "style" : "default",
                    "zIndex" : 3000
                };
            }else{
                defaultOpt = {
                    "style" : "process",
                    "width" : "auto",
                    "height" : "240",
                    "embedded" : true,
                    "hasLetter" : false, //字母
                    "hasTop" : true //可选、已选的标题
                };
            }
R
roo00 已提交
1727

NoSubject's avatar
NoSubject 已提交
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747
            if( this.json.events && typeOf(this.json.events) === "object" ){
                Object.each(this.json.events, function(e, key){
                    if (e.code){
                        if (this.options.moduleEvents.indexOf(key)!==-1){
                            //this.addEvent(key, function(event){
                            //    return this.form.Macro.fire(e.code, this, event);
                            //}.bind(this));
                            if( key === "postLoadSelector" ) {
                                this.addEvent("loadSelector", function (selector) {
                                    return this.form.Macro.fire(e.code, selector);
                                }.bind(this))
                            }else if( key === "queryLoadSelector"){
                                defaultOpt["onQueryLoad"] = function(target){
                                    return this.form.Macro.fire(e.code, target);
                                }.bind(this)
                            }else{
                                defaultOpt["on"+key.capitalize()] = function(target){
                                    return this.form.Macro.fire(e.code, target);
                                }.bind(this)
                            }
R
roo00 已提交
1748 1749
                        }
                    }
NoSubject's avatar
NoSubject 已提交
1750 1751
                }.bind(this));
            }
R
roo00 已提交
1752

NoSubject's avatar
NoSubject 已提交
1753 1754 1755 1756
            if( this.form.json.selectorStyle ){
                defaultOpt = Object.merge( Object.clone(this.form.json.selectorStyle), defaultOpt );
                if( this.form.json.selectorStyle.style )defaultOpt.style = this.form.json.selectorStyle.style;
            }
R
roo00 已提交
1757

NoSubject's avatar
NoSubject 已提交
1758 1759 1760 1761 1762 1763 1764
            var mobileEvents = {
                "onComplete": function(items){
                    this.selectOnComplete(items);
                }.bind(this),
                "onCancel": this.selectOnCancel.bind(this),
                "onClose": this.selectOnClose.bind(this)
            };
R
roo00 已提交
1765

NoSubject's avatar
NoSubject 已提交
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787
            if( this.selectTypeList.length === 1 ){
                return Object.merge(
                    defaultOpt,
                    {
                        "type": this.selectTypeList[0],
                        "onLoad": function(){
                            //this 为 selector
                            _self.selectOnLoad(this, this.selector )
                        }
                        //"onComplete": function(items){
                        //    this.selectOnComplete(items);
                        //}.bind(this),
                        //"onCancel": this.selectOnCancel.bind(this),
                        //"onClose": this.selectOnClose.bind(this)
                    },
                    layout.mobile ? mobileEvents : {} ,
                    identityOpt || unitOpt
                )
            }else if( this.selectTypeList.length > 1 ){
                var options = {
                    "type" : "",
                    "types" : this.selectTypeList,
R
roo00 已提交
1788 1789
                    "onLoad": function(){
                        //this 为 selector
NoSubject's avatar
NoSubject 已提交
1790
                        _self.selectOnLoad(this)
R
roo00 已提交
1791 1792 1793 1794 1795 1796
                    }
                    //"onComplete": function(items){
                    //    this.selectOnComplete(items);
                    //}.bind(this),
                    //"onCancel": this.selectOnCancel.bind(this),
                    //"onClose": this.selectOnClose.bind(this)
NoSubject's avatar
NoSubject 已提交
1797 1798 1799 1800 1801 1802 1803
                };
                if( identityOpt ){
                    options.identityOptions = Object.merge(
                        defaultOpt,
                        layout.mobile ? mobileEvents : {},
                        identityOpt
                    );
R
roo00 已提交
1804
                }
NoSubject's avatar
NoSubject 已提交
1805 1806 1807 1808 1809 1810 1811 1812 1813
                if( unitOpt ){
                    options.unitOptions = Object.merge(
                        defaultOpt,
                        layout.mobile ? mobileEvents : {},
                        unitOpt
                    );
                }
                //if( groupOpt )options.groupOptions = groupOpt;
                return options;
R
roo00 已提交
1814
            }
NoSubject's avatar
NoSubject 已提交
1815 1816 1817 1818 1819
        },
        selectOnComplete: function(items){ //移动端才执行
            var array = [];
            items.each(function(item){
                array.push(item.data);
R
roo00 已提交
1820
            }.bind(this));
NoSubject's avatar
NoSubject 已提交
1821 1822 1823 1824 1825
            this.checkEmpower( array, function( data ){
                var values = [];
                data.each(function(d){
                    values.push(MWF.org.parseOrgData(d, true));
                }.bind(this));
R
roo00 已提交
1826

NoSubject's avatar
NoSubject 已提交
1827
                this.setData(values);
R
roo00 已提交
1828

NoSubject's avatar
NoSubject 已提交
1829 1830
                //this.validationMode();
                //this.validation();
R
roo00 已提交
1831

NoSubject's avatar
NoSubject 已提交
1832 1833
                this.container.empty();
                this.loadOrgWidget(values, this.container);
R
roo00 已提交
1834

NoSubject's avatar
NoSubject 已提交
1835
                this.selector = null;
R
roo00 已提交
1836

NoSubject's avatar
NoSubject 已提交
1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
                this.fireEvent("select", [items, values]);
            }.bind(this))
        },
        selectOnCancel: function(){ //移动端才执行
            //this.validation();
        },
        selectOnLoad: function( selector ){
            //if (this.descriptionNode) this.descriptionNode.setStyle("display", "none");
            this.fireEvent("loadSelector", [selector])
        },
        selectOnClose: function(){
            var v = this._getBusinessData();
            //if (!v || !v.length) if (this.descriptionNode)  this.descriptionNode.setStyle("display", "block");
        },
        loadOrgWidget: function(value, node){
            var height = node.getStyle("height").toInt();
            if (node.getStyle("overflow")==="visible" && !height) node.setStyle("overflow", "hidden");
            if (value && value.length){
                value.each(function(data){
                    var flag = data.distinguishedName.substr(data.distinguishedName.length-1, 1);
                    var copyData = Object.clone(data);
                    if( this.json.displayTextScript && this.json.displayTextScript.code ){
                        this.currentData = copyData;
                        var displayName = this.form.Macro.exec(this.json.displayTextScript.code, this);
                        if( displayName ){
                            copyData.displayName = displayName;
                        }
                        this.currentData = null;
R
roo00 已提交
1865 1866
                    }

NoSubject's avatar
NoSubject 已提交
1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
                    var widget;
                    switch (flag.toLowerCase()){
                        case "i":
                            widget = new MWF.widget.O2Identity(copyData, node, {"style": "xform","lazy":true});
                            break;
                        case "p":
                            widget = new MWF.widget.O2Person(copyData, node, {"style": "xform","lazy":true});
                            break;
                        case "u":
                            widget = new MWF.widget.O2Unit(copyData, node, {"style": "xform","lazy":true});
                            break;
                        case "g":
                            widget = new MWF.widget.O2Group(copyData, node, {"style": "xform","lazy":true});
                            break;
                        default:
                            widget = new MWF.widget.O2Other(copyData, node, {"style": "xform","lazy":true});
                    }
                    widget.field = this;
                    if( layout.mobile ){
                        //widget.node.setStyles({
                        //    "float" : "none"
                        //})
                    }
                }.bind(this));
            }
        },
R
roo00 已提交
1893

NoSubject's avatar
NoSubject 已提交
1894 1895
        hasEmpowerIdentity : function(){
            var data = this.getData();
R
roo00 已提交
1896
            if(!this.empowerChecker )this.empowerChecker = new MWF.xApplication.process.Work.Processor.EmpowerChecker(this.form, this.json, this.processor);
NoSubject's avatar
NoSubject 已提交
1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953
            return this.empowerChecker.hasEmpowerIdentity( data );
        },
        checkEmpower : function( data, callback, container, selectAllNode ){
            if( typeOf(data)==="array" && this.identityOptions && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
                if(!this.empowerChecker )this.empowerChecker = new MWF.xApplication.process.Work.Processor.EmpowerChecker(this.form, this.json, this.processor);
                this.empowerChecker.selectAllNode = selectAllNode;
                this.empowerChecker.load(data, callback, container);
            }else{
                if( callback )callback( data );
            }
        },

        loadCheckEmpower : function( callback, container, selectAllNode ){
            this.checkEmpower( this.getData(), callback, container, selectAllNode)
        },
        saveCheckedEmpowerData:function( callback ){
            var data = this.getData();
            //this.empowerChecker.replaceEmpowerIdentity(data, function( newData ){
            this.empowerChecker.setIgnoreEmpowerFlag(data, function( newData ){
                var values = [];
                newData.each(function(d){
                    values.push(MWF.org.parseOrgData(d, true));
                }.bind(this));
                this.setData( values );
                if( callback )callback(values)
            }.bind(this))
        },

        //saveWithCheckEmpower: function( isValid, callback ){
        //    var checkEmpowerData = function(){
        //        var array = this.getData();
        //        this.checkEmpower( array, function( data ){
        //            var values = [];
        //            data.each(function(d){
        //                values.push(MWF.org.parseOrgData(d, true));
        //            }.bind(this));
        //            this.setData( values );
        //            if( callback )callback(values)
        //        }.bind(this), container, selectAllNode)
        //    }.bind(this)
        //    if( isValid ){
        //        if( this.validation() ){
        //            checkEmpowerData( function(){
        //                if(callback)callback();
        //            }.bind(this));
        //            return true;
        //        }else{
        //            return false;
        //        }
        //    }else{
        //        //this.setData( this.getData() );
        //        checkEmpowerData( function(){
        //            if(callback)callback();
        //        }.bind(this));
        //        return true;
        //    }
        //},
R
roo00 已提交
1954

NoSubject's avatar
NoSubject 已提交
1955 1956 1957 1958 1959 1960 1961
        save: function( isValid ){
            if( isValid ){
                if( this.validation() ){
                    return true;
                }else{
                    return false;
                }
R
roo00 已提交
1962
            }else{
NoSubject's avatar
NoSubject 已提交
1963 1964
                this.setData( this.getData() );
                return true;
R
roo00 已提交
1965
            }
NoSubject's avatar
NoSubject 已提交
1966
        },
R
roo00 已提交
1967

NoSubject's avatar
NoSubject 已提交
1968 1969 1970 1971 1972
        resetSelectorData : function(){
            if( this.selector && this.selector.selector ){
                this.selector.selector.emptySelectedItems();
                this.selector.selector.options.values = this.getValue();
                this.selector.selector.setSelectedItem();
R
roo00 已提交
1973
            }
NoSubject's avatar
NoSubject 已提交
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
        },
        resetData: function(){
            var v = this.getValue();
            //this.setData((v) ? v.join(", ") : "");
            this.setData(v);
        },
        getData: function(){
            if( this.selector && !layout.mobile ){
                return this.getSelectedData();
            }else{
                return this.getValue();
            }
        },
        getSelectedData : function(){
            if( layout.mobile ){
                return this.getValue();
            }else{
                var data = [];
                if( this.selector && this.selector.selector){
                    this.selector.selector.selectedItems.each( function( item ){
                        data.push( MWF.org.parseOrgData(item.data, true) );
                    })
                }
                return data;
            }
        },
        getValue: function(){
            var value = this._getBusinessData();
            if (!value) value = this._computeValue();
            return value || "";
        },
        _computeValue: function(){
            var values = [];
            if (this.json.identityValue) {
                this.json.identityValue.each(function(v){ if (v) values.push(v)});
            }
            if (this.json.unitValue) {
                this.json.unitValue.each(function(v){ if (v) values.push(v)});
            }
            if (this.json.dutyValue) {
                var dutys = JSON.decode(this.json.dutyValue);
                var par;
                if (dutys.length){
                    dutys.each(function(duty){
                        if (duty.code) par = this.form.Macro.exec(duty.code, this);
                        var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\")";

                        var d = this.form.Macro.exec(code, this);
                        if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
                        d.each(function(dd){if (dd) values.push(dd);});
R
roo00 已提交
2024

NoSubject's avatar
NoSubject 已提交
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040
                    }.bind(this));
                }
            }
            if (this.json.defaultValue && this.json.defaultValue.code){
                var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
                if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
                fd.each(function(fdd){
                    if (fdd){
                        if (typeOf(fdd)==="string"){
                            var data;
                            this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = json.data }.bind(this), null, fdd, false);
                            values.push(data);
                        }else{
                            values.push(fdd);
                        }
                    }
R
roo00 已提交
2041 2042
                }.bind(this));
            }
NoSubject's avatar
NoSubject 已提交
2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066
            if (this.json.count>0){
                return values.slice(0, this.json.count);
            }
            return values;
            //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
        },
        getOrgAction: function(){
            if (!this.orgAction) this.orgAction = MWF.Actions.get("x_organization_assemble_control");
            //if (!this.orgAction) this.orgAction = new MWF.xApplication.Selector.Actions.RestActions();
            return this.orgAction;
        },
        setData: function(value){

            if (!value) return false;
            var oldValues = this.getValue();
            var values = [];

            var type = typeOf(value);
            if (type==="array"){
                value.each(function(v){
                    var vtype = typeOf(v);
                    var data = null;
                    if (vtype==="string"){
                        this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true); }.bind(this), error, v, false);
R
roo00 已提交
2067
                    }
NoSubject's avatar
NoSubject 已提交
2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093
                    if (vtype==="object") {
                        data = MWF.org.parseOrgData(v, true);
                        if(data.woPerson)delete data.woPerson;
                    }
                    if (data)values.push(data);
                }.bind(this));
            }
            if (type==="string"){
                var vData;
                this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true); }.bind(this), error, value, false);
                if (vData)values.push(vData);
            }
            if (type==="object"){
                var vData = MWF.org.parseOrgData(value, true);
                if(vData.woPerson)delete vData.woPerson;
                values.push( vData );
            }

            var change = false;
            if (oldValues.length && values.length){
                if (oldValues.length === values.length){
                    for (var i=0; i<oldValues.length; i++){
                        if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
                            change = true;
                            break;
                        }
R
roo00 已提交
2094
                    }
NoSubject's avatar
NoSubject 已提交
2095 2096
                }else{
                    change = true;
R
roo00 已提交
2097
                }
NoSubject's avatar
NoSubject 已提交
2098
            }else if (values.length || oldValues.length) {
R
roo00 已提交
2099 2100
                change = true;
            }
NoSubject's avatar
NoSubject 已提交
2101 2102 2103
            this._setBusinessData(values);
            if (change) this.fireEvent("change");
        },
R
roo00 已提交
2104

NoSubject's avatar
NoSubject 已提交
2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119
        getValueMethod: function(value){
            if (value){
                var flag = value.substr(value.length-1, 1);
                switch (flag.toLowerCase()){
                    case "i":
                        return "getIdentity";
                    case "p":
                        return "getPerson";
                    case "u":
                        return "getUnit";
                    case "g":
                        return "getGroup";
                    default:
                        return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
                }
R
roo00 已提交
2120
            }
NoSubject's avatar
NoSubject 已提交
2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132
            return (this.json.selectType==="unit") ? "getUnit" : "getIdentity";
        },

        _getBusinessData: function(){
            if (this.json.section=="yes"){
                return this._getBusinessSectionData();
            }else {
                if (this.json.type==="Opinion"){
                    return this._getBusinessSectionDataByPerson();
                }else{
                    return this.form.businessData.data[this.json.name] || "";
                }
R
roo00 已提交
2133
            }
NoSubject's avatar
NoSubject 已提交
2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195
        },
        _getBusinessSectionData: function(){
            switch (this.json.sectionBy){
                case "person":
                    return this._getBusinessSectionDataByPerson();
                case "unit":
                    return this._getBusinessSectionDataByUnit();
                case "activity":
                    return this._getBusinessSectionDataByActivity();
                case "splitValue":
                    return this._getBusinessSectionDataBySplitValue();
                case "script":
                    return this._getBusinessSectionDataByScript(this.json.sectionByScript.code);
                default:
                    return this.form.businessData.data[this.json.name] || "";
            }
        },
        _getBusinessSectionDataByPerson: function(){
            this.form.sectionListObj[this.json.name] = layout.desktop.session.user.id;
            var dataObj = this.form.businessData.data[this.json.name];
            return (dataObj) ? (dataObj[layout.desktop.session.user.id] || "") : "";
        },
        _getBusinessSectionDataByUnit: function(){
            this.form.sectionListObj[this.json.name] = "";
            var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";
            if (key) this.form.sectionListObj[this.json.name] = key;
            var dataObj = this.form.businessData.data[this.json.name];
            if (!dataObj) return "";
            return (key) ? (dataObj[key] || "") : "";
        },
        _getBusinessSectionDataByActivity: function(){
            this.form.sectionListObj[this.json.name] = "";
            var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";
            if (key) this.form.sectionListObj[this.json.name] = key;
            var dataObj = this.form.businessData.data[this.json.name];
            if (!dataObj) return "";
            return (key) ? (dataObj[key] || "") : "";
        },
        _getBusinessSectionDataBySplitValue: function(){
            this.form.sectionListObj[this.json.name] = "";
            var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";
            if (key) this.form.sectionListObj[this.json.name] = key;
            var dataObj = this.form.businessData.data[this.json.name];
            if (!dataObj) return "";
            return (key) ? (dataObj[key] || "") : "";
        },
        _getBusinessSectionDataByScript: function(code){
            this.form.sectionListObj[this.json.name] = "";
            var dataObj = this.form.businessData.data[this.json.name];
            if (!dataObj) return "";
            var key = this.form.Macro.exec(code, this);
            if (key) this.form.sectionListObj[this.json.name] = key;
            return (key) ? (dataObj[key] || "") : "";
        },

        loadPathData: function(path){
            var data = null;
            this.form.workAction.getJobDataByPath(this.form.businessData.work.job, path, function(json){
                data = json.data ||  null;
            }, null, false);
            return data;
        },
R
roo00 已提交
2196

NoSubject's avatar
NoSubject 已提交
2197 2198
        _setBusinessData: function(v){
            if (this.json.section=="yes"){
R
roo00 已提交
2199 2200
                // var d = this.loadPathData(this.json.name);
                // if (d) this.form.businessData.data[this.json.name] = d;
NoSubject's avatar
NoSubject 已提交
2201 2202 2203 2204 2205 2206
                this._setBusinessSectionData(v);
            }else {
                if (this.json.type==="Opinion"){
                    // var d = this.loadPathData(this.json.name);
                    // if (d) this.form.businessData.data[this.json.name] = d;
                    this._setBusinessSectionDataByPerson(v);
R
roo00 已提交
2207
                }else{
NoSubject's avatar
NoSubject 已提交
2208 2209 2210 2211 2212 2213 2214
                    if (this.form.businessData.data[this.json.name]){
                        this.form.businessData.data[this.json.name] = v;
                    }else{
                        this.form.businessData.data[this.json.name] = v;
                        this.form.Macro.environment.setData(this.form.businessData.data);
                    }
                    if (this.json.isTitle) this.form.businessData.work.title = v;
R
roo00 已提交
2215 2216
                }
            }
NoSubject's avatar
NoSubject 已提交
2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241
        },
        _setBusinessSectionData: function(v){
            switch (this.json.sectionBy){
                case "person":
                    this._setBusinessSectionDataByPerson(v);
                    break;
                case "unit":
                    this._setBusinessSectionDataByUnit(v);
                    break;
                case "activity":
                    this._setBusinessSectionDataByActivity(v);
                    break;
                case "splitValue":
                    this._setBusinessSectionDataBySplitValue(v);
                    break;
                case "script":
                    this._setBusinessSectionDataByScript(this.json.sectionByScript.code, v);
                    break;
                default:
                    if (this.form.businessData.data[this.json.name]){
                        this.form.businessData.data[this.json.name] = v;
                    }else{
                        this.form.businessData.data[this.json.name] = v;
                        this.form.Macro.environment.setData(this.form.businessData.data);
                    }
R
roo00 已提交
2242
            }
NoSubject's avatar
NoSubject 已提交
2243 2244 2245 2246
        },
        _setBusinessSectionDataByPerson: function(v){
            var resetData = false;
            var key = layout.desktop.session.user.id;
R
roo00 已提交
2247
            this.form.sectionListObj[this.json.name] = key;
NoSubject's avatar
NoSubject 已提交
2248

R
roo00 已提交
2249 2250 2251 2252 2253 2254 2255 2256 2257
            var dataObj = this.form.businessData.data[this.json.name];
            if (!dataObj){
                dataObj = {};
                this.form.businessData.data[this.json.name] = dataObj;
                resetData = true;
            }
            if (!dataObj[key]) resetData = true;
            dataObj[key] = v;

NoSubject's avatar
NoSubject 已提交
2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274
            if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
        },
        _setBusinessSectionDataByUnit: function(v){
            var resetData = false;
            var key = (this.form.businessData.task) ? this.form.businessData.task.unit : "";

            if (key){
                this.form.sectionListObj[this.json.name] = key;
                var dataObj = this.form.businessData.data[this.json.name];
                if (!dataObj){
                    dataObj = {};
                    this.form.businessData.data[this.json.name] = dataObj;
                    resetData = true;
                }
                if (!dataObj[key]) resetData = true;
                dataObj[key] = v;
            }
R
roo00 已提交
2275

NoSubject's avatar
NoSubject 已提交
2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291
            if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
        },
        _setBusinessSectionDataByActivity: function(v){
            var resetData = false;
            var key = (this.form.businessData.work) ? this.form.businessData.work.activity : "";

            if (key){
                this.form.sectionListObj[this.json.name] = key;
                var dataObj = this.form.businessData.data[this.json.name];
                if (!dataObj){
                    dataObj = {};
                    this.form.businessData.data[this.json.name] = dataObj;
                    resetData = true;
                }
                if (!dataObj[key]) resetData = true;
                dataObj[key] = v;
R
roo00 已提交
2292 2293
            }

NoSubject's avatar
NoSubject 已提交
2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310
            if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
        },
        _setBusinessSectionDataBySplitValue: function(v){
            var resetData = false;
            var key = (this.form.businessData.work) ? this.form.businessData.work.splitValue : "";

            if (key){
                this.form.sectionListObj[this.json.name] = key;
                var dataObj = this.form.businessData.data[this.json.name];
                if (!dataObj){
                    dataObj = {};
                    this.form.businessData.data[this.json.name] = dataObj;
                    resetData = true;
                }
                if (!dataObj[key]) resetData = true;
                dataObj[key] = v;
            }
R
roo00 已提交
2311

NoSubject's avatar
NoSubject 已提交
2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327
            if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
        },
        _setBusinessSectionDataByScript: function(code, v){
            var resetData = false;
            var key = this.form.Macro.exec(code, this);

            if (key){
                this.form.sectionListObj[this.json.name] = key;
                var dataObj = this.form.businessData.data[this.json.name];
                if (!dataObj){
                    dataObj = {};
                    this.form.businessData.data[this.json.name] = dataObj;
                    resetData = true;
                }
                if (!dataObj[key]) resetData = true;
                dataObj[key] = v;
R
roo00 已提交
2328 2329
            }

NoSubject's avatar
NoSubject 已提交
2330 2331
            if (resetData) this.form.Macro.environment.setData(this.form.businessData.data);
        },
R
roo00 已提交
2332

NoSubject's avatar
NoSubject 已提交
2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357
        createErrorNode: function(text){
            var node;
            if( this.processor.css.errorContentNode ){
                node = new Element("div",{
                    "styles" : this.processor.css.errorContentNode,
                    "text": text
                });
                if( this.processor.css.errorCloseNode ){
                    var closeNode = new Element("div",{
                        "styles" : this.processor.css.errorCloseNode ,
                        "events": {
                            "click" : function(){
                                this.destroy();
                            }.bind(node)
                        }
                    }).inject(node);
                }
            }else {
                node = new Element("div");
                var iconNode = new Element("div", {
                    "styles": {
                        "width": "20px",
                        "height": "20px",
                        "float": "left",
                        "background": "url(" + "/x_component_process_Xform/$Form/default/icon/error.png) center center no-repeat"
R
roo00 已提交
2358 2359
                    }
                }).inject(node);
NoSubject's avatar
NoSubject 已提交
2360 2361 2362 2363 2364 2365 2366 2367 2368 2369
                var textNode = new Element("div", {
                    "styles": {
                        "height": "20px",
                        "line-height": "20px",
                        "margin-left": "20px",
                        "color": "red",
                        "word-break": "keep-all"
                    },
                    "text": text
                }).inject(node);
R
roo00 已提交
2370
            }
NoSubject's avatar
NoSubject 已提交
2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384
            return node;
        },
        notValidationMode: function(text){
            if (!this.isNotValidationMode){
                //this.isNotValidationMode = true;
                //this.node.store("borderStyle", this.node.getStyles("border-left", "border-right", "border-top", "border-bottom"));
                //this.node.setStyle("border-color", "red");

                this.errNode = this.createErrorNode(text);
                if( this.errContainer ){
                    this.errContainer.empty();
                    this.errNode.inject(this.errContainer);
                }else{
                    this.errNode.inject(this.container, "after");
R
roo00 已提交
2385
                }
NoSubject's avatar
NoSubject 已提交
2386 2387
                //this.showNotValidationMode(this.node);
                //if (!this.node.isIntoView()) this.node.scrollIntoView();
R
roo00 已提交
2388
            }
NoSubject's avatar
NoSubject 已提交
2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402
        },
        validation: function(){
            var data = this.getData();
            this.setData( data );
            var flag=true;
            if( this.json.validationCount && typeOf( this.json.validationCount.toInt() ) === "number" ){
                if( data.length < this.json.validationCount.toInt() ){
                    //if( this.json.validationCount.toInt() === 1 ){
                    //    flag = "请选择"
                    //}else{
                    //    flag = "请至少选择"+this.json.validationCount+"项"
                    //}
                    flag = "请至少选择"+this.json.validationCount+""
                }
R
roo00 已提交
2403 2404
            }

NoSubject's avatar
NoSubject 已提交
2405 2406 2407 2408 2409
            if( flag === true ){
                if ( this.json.validation && this.json.validation.code){
                    flag = this.form.Macro.exec(this.json.validation.code, this);
                    if (!flag) flag = MWF.xApplication.process.Xform.LP.notValidation;
                }
R
roo00 已提交
2410 2411
            }

NoSubject's avatar
NoSubject 已提交
2412 2413 2414 2415 2416 2417 2418
            if (flag.toString()!="true"){
                this.notValidationMode(flag);
                return false;
            }else if(this.errNode){
                this.errNode.destroy()
            }
            return true;
R
roo00 已提交
2419
        }
NoSubject's avatar
NoSubject 已提交
2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438
    });

    MWF.xApplication.process.Work.Processor.EmpowerChecker = new Class({
        Extends : MWF.APPOrg.EmpowerChecker,
        initialize: function (form, json, processor) {
            this.form = form;
            this.json = json;
            this.processor = processor;
            this.css = this.processor.css;
            this.checkedAllItems = true;
        },
        hasEmpowerIdentity: function( data ){
            var flag = false;
            if( typeOf(data)==="array" && this.json.isCheckEmpower && this.json.identityResultType === "identity" ) {
                var array = [];
                data.each(function (d) {
                    if (d.distinguishedName) {
                        var flag = d.distinguishedName.substr(d.distinguishedName.length - 1, 1).toLowerCase();
                        if (flag === "i")array.push(d.distinguishedName)
R
roo00 已提交
2439
                    }
NoSubject's avatar
NoSubject 已提交
2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457
                }.bind(this));
                if (array.length > 0) {
                    o2.Actions.get("x_organization_assemble_express").listEmpowerWithIdentity({
                        "application": (this.form.businessData.work || this.form.businessData.workCompleted).application,
                        "process": (this.form.businessData.work || this.form.businessData.workCompleted).process,
                        "work" : (this.form.businessData.work || this.form.businessData.workCompleted).id,
                        "identityList": array
                    }, function (json) {
                        var arr = [];
                        json.data.each(function (d) {
                            if (d.fromIdentity !== d.toIdentity)
                                arr.push(d);
                        });
                        if (arr.length > 0) {
                            flag = true;
                        }
                    }.bind(this), null, false)
                }
R
roo00 已提交
2458
            }
NoSubject's avatar
NoSubject 已提交
2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476
            return flag;
        },
        openSelectEmpowerDlg : function( data, orgData, callback, container ){
            var node = new Element("div", {"styles": this.css.empowerAreaNode});
            //var html = "<div style=\"line-height: 30px; color: #333333; overflow: hidden\">"+MWF.xApplication.process.Xform.LP.empowerDlgText+"</div>";
            var html = "<div style=\"margin-bottom:10px; margin-top:10px; overflow-y:auto;\"></div>";
            node.set("html", html);
            var itemNode = node.getLast();
            this.getEmpowerItems(itemNode, data);
            node.inject( container || this.container );

            if( this.selectAllNode ){
                var selectNode = this.createSelectAllEmpowerNode();
                selectNode.inject( this.selectAllNode );
                if( this.checkedAllItems ){
                    selectNode.store("isSelected", true);
                    selectNode.setStyles( this.css.empowerSelectAllItemNode_selected );
                }
R
roo00 已提交
2477
            }
NoSubject's avatar
NoSubject 已提交
2478 2479 2480 2481 2482 2483 2484 2485 2486 2487
        },
        getSelectedData : function( callback ){
            var json = {};
            this.empowerSelectNodes.each(function(node){
                if( node.retrieve("isSelected") ){
                    var d = node.retrieve("data");
                    json[ d.fromIdentity ] = d;
                }
            }.bind(this));
            if( callback )callback( json );
R
roo00 已提交
2488
        }
NoSubject's avatar
NoSubject 已提交
2489
    });
R
roo00 已提交
2490

NoSubject's avatar
NoSubject 已提交
2491 2492 2493
    MWF.xApplication.process.Work.Processor.UnitOptions = new Class({
        Extends : MWF.APPOrg.UnitOptions
    });
R
roo00 已提交
2494

NoSubject's avatar
NoSubject 已提交
2495 2496 2497 2498 2499 2500
    MWF.xApplication.process.Work.Processor.IdentityOptions = new Class({
        Extends : MWF.APPOrg.IdentityOptions
    });


}