Dialog.js 34.8 KB
Newer Older
NoSubject's avatar
NoSubject 已提交
1 2 3
o2.require("MWF.widget.Dialog", null, false);
o2.xDesktop.Dialog = o2.DDL = new Class({
	Extends: o2.widget.Dialog,
NoSubject's avatar
NoSubject 已提交
4 5 6
    options : {
        maxHeightPercent : "98%"
    },
R
roo00 已提交
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
//	_markShow: function(){
//
//		if (this.options.mark){
//			if (!this.markNode){
//				
//				this.markNode = new Element("div", {
//					styles: this.css.mark
//				}).inject($(document.body));
//				
//			}
////			if (this.options.markNode){
////				var size = this.options.markNode.getComputedSize();
////				var position = this.options.markNode.getPosition();
////				alert(size.totalHeight);
////				this.markNode.set("styles", {
////					"height": size.totalHeight+"px",
////					"width": size.totalWidth+"px",
////					"top": position.y,
////					"height": position.x
////				});
////
////			}else{
//				var size = MWF.getMarkSize();
//				this.markNode.set("styles", {
//					"height": size.y,
//					"width": size.x,
//					"top": "0xp",
//					"height": "0px"
//				});
////			}
//			
//			this.markNode.setStyle("display", "block");
//		}
//	},
	_markShow: function(){

		if (this.options.mark){
			if (!this.markNode){
				var size = MWF.getMarkSize(this.options.maskNode);
				var topNode = this.options.container || $(document.body);
R
roo00 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59

                this.markNode = new Element("iframe", {
                    styles: this.css.mark
                }).inject(topNode);
                this.markNode.set("styles", {
                    "height": size.y,
                    "width": size.x
                });
				if (!this.markNode_up) this.markNode_up = new Element("div", { styles: this.css.mark }).inject(topNode);
                this.markNode_up.set("styles", {
                    "height": size.y,
                    "width": size.x
                });
R
roo00 已提交
60 61 62 63 64
			}
			this.markNode.setStyle("display", "block");
		}
	},
	getDialogNode: function(){
R
roo00 已提交
65 66 67
        this.width = this.options.width;
        this.height = this.options.height;

R
roo00 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
		this.node.set("styles", this.css.from);
		var topNode = this.options.container || $(document.body);
		this.node.inject(topNode);
//		this.node.addEvent("selectstart", function(e){
//		//	e.preventDefault();
//		});

		this.title = this.node.getElement(".MWF_dialod_title");
		this.titleCenter = this.node.getElement(".MWF_dialod_title_center");
		this.titleText = this.node.getElement(".MWF_dialod_title_text");
		this.titleAction = this.node.getElement(".MWF_dialod_title_action");
		this.content = this.node.getElement(".MWF_dialod_content");
		this.bottom = this.node.getElement(".MWF_dialod_bottom");
		this.resizeNode = this.node.getElement(".MWF_dialod_bottom_resize");
		this.button = this.node.getElement(".MWF_dialod_button");
NoSubject's avatar
NoSubject 已提交
83 84 85 86 87 88 89 90
        if( (!this.options.buttonList || this.options.buttonList.length === 0) && ( !this.options.buttons ) ){
            this.button.setStyle("display","none");
            this.buttonDisable = true;
        }else{
            this.okButton = this.node.getElement(".MWF_dialod_ok_button");
            this.cancelButton = this.node.getElement(".MWF_dialod_cancel_button");
        }
        this.backAction = this.node.getElement(".MWF_dialod_Action_back");
R
roo00 已提交
91

NoSubject's avatar
NoSubject 已提交
92 93 94 95 96 97 98 99 100
        if (!this.options.isTitle) {
            this.title.destroy();
            this.title = null;
            this.titleCenter = null;
            this.titleRefresh = null;
            this.titleText = null;
            this.titleAction = null;
        }

R
roo00 已提交
101 102 103 104 105 106 107 108
		if (this.title) this.setTitleEvent(); 
	//	if (this.titleText) this.getTitle();
		if (this.content) this.getContent();
		if (this.titleAction) this.getAction();
		if (this.resizeNode) this.setResizeNode();
	//	if (this.button) this.getButton();

		if (this.content) this.setContentSize();
NoSubject's avatar
NoSubject 已提交
109
        if (this.backAction)this.backAction.addEvent("click", this.close.bind(this))
R
roo00 已提交
110
	},
NoSubject's avatar
NoSubject 已提交
111 112 113 114 115 116
    getButton: function(){
        for (i in this.options.buttons){
            var button = new Element("input", {
                "type": "button",
                "value": i,
                "styles": this.css.button,
117
                "class": "mainColor_bg",
NoSubject's avatar
NoSubject 已提交
118 119 120 121 122
                "events": {
                    "click": this.options.buttons[i].bind(this)
                }
            }).inject(this.button);
        }
123
        debugger;
NoSubject's avatar
NoSubject 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
        if (this.options.buttonList){
            this.options.buttonList.each(function(bt){
                var styles = this.css.button;
                if( bt.type === "ok" && this.css.okButton )styles = this.css.okButton;
                if( bt.type === "cancel" && this.css.cancelButton )styles = this.css.cancelButton;
                if( bt.styles )styles = bt.styles;
                var button;
                if( bt.type === "ok" && this.okButton ){
                    button = this.okButton;
                    button.show();
                }else if( bt.type === "cancel" && this.cancelButton ){
                    button = this.cancelButton;
                    button.show();
                }else{
                    button = new Element("input", {
                        "type": "button"
                    }).inject(this.button);
                }
                button.set({
                    "value": bt.text,
NoSubject's avatar
NoSubject 已提交
144
                    "title": bt.title,
NoSubject's avatar
NoSubject 已提交
145
                    "styles": styles,
146
                    "class": "mainColor_bg",
NoSubject's avatar
NoSubject 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
                    "events": {
                        "click": function(e){bt.action.call(this, this, e)}.bind(this)
                    }
                })
            }.bind(this));
        }
    },
    setTitleEvent: function(){
        var content;
        if( this.options.isMove ){
            if (layout.app) content = layout.app.content;
            if (layout.desktop.currentApp) content = layout.desktop.currentApp.content;
            this.containerDrag = new Drag.Move(this.node, {
                "handle": this.title,
                "container": this.options.container || this.markNode || content,
                "snap": 5
            });
        }
    },
    getAction: function(){
        //未完成................................
        if (this.options.isClose){
            this.closeAction = new Element("div", {"styles": this.css.closeAction}).inject(this.titleAction);
            this.closeAction.addEvent("click", this.close.bind(this));
        }
        if (this.options.isMax){
            this.maxAction = new Element("div", {"styles": this.css.maxAction}).inject(this.titleAction);
            this.maxAction.addEvent("click", this.maxSize.bind(this));

            this.restoreAction = new Element("div", {"styles": this.css.restoreAction}).inject(this.titleAction);
            this.restoreAction.hide();
            this.restoreAction.addEvent("click", this.restoreSize.bind(this));

            if (this.title){
                this.title.addEvent("dblclick", function(){
                    this.switchMax();
                }.bind(this));
            }
        }
    },
    switchMax : function(){
        if( !this.isMax ){
            this.maxSize();
        }else{
            this.restoreSize();
        }
    },
    maxSize: function(){
        //if(!this.oldCoordinate)this.oldCoordinate = {
        //    height : this.options.height,
        //    width : this.options.width,
        //    top : this.options.top,
        //    left : this.options.left,
        //    fromTop : this.options.fromTop,
        //    fromLeft : this.options.fromLeft,
        //    contentHeight : this.options.contentHeight,
        //    contentWidth : this.options.contentWidth,
        //    maxHeightPercent : this.options.maxHeightPercent,
        //    maxHeight : this.options.maxHeight,
        //    maxWidth : this.options.maxWidth
        //};
        //if( !this.oldSize ){
        //    this.oldSize = {
        //        "width" : this.width,
        //        "height" : this.height
        //    }
        //}
        if( !this.oldNodeSize ){
            this.oldNodeSize = {
                "width" : this.nodeWidth,
                "height" : this.nodeHeight
            }
        }
        if( !this.oldContentSize ){
            this.oldContentSize = {
                "width" : this.contentWidth,
                "height" : this.contentHeight
            }
        }

        //this.options.top = 0;
        //this.options.left = 0;
        //this.options.fromTop = 0;
        //this.options.fromLeft = 0;
        //this.options.contentHeight = 0;
        //this.options.contentWidth = 0;
        //this.options.maxHeightPercent = null;
        //this.options.maxHeight = null;
        //this.options.maxWidth = null;

        //this.height = null;
        //this.width = null;

        var container = $(document.body);
        if (layout.desktop.currentApp){
            container = layout.desktop.currentApp.content;
        }else if (this.options.container){
            if (this.options.container.getSize().y<$(document.body).getSize().y){
                container = this.options.container;
            }
        }
        var containerSize = container.getSize();
        this.options.width = containerSize.x;
        this.options.height = containerSize.y;

        this.setContentSize( containerSize.y, containerSize.x );
        this.node.setStyles({
            width : containerSize.x + "px",
            height : containerSize.y + "px",
            top : "0px",
            left : "0px"
        });

        this.maxAction.setStyle("display","none");
        this.restoreAction.setStyle("display","");
        this.isMax = true;
        this.fireEvent("max");
    },
    restoreSize : function(){
        //if( this.oldCoordinate){
        //    this.options.height = this.oldCoordinate.height;
        //    this.options.width = this.oldCoordinate.width;
        //    this.options.top = this.oldCoordinate.top;
        //    this.options.left = this.oldCoordinate.left;
        //    this.options.fromTop = this.oldCoordinate.fromTop;
        //    this.options.fromLeft = this.oldCoordinate.fromLeft;
        //    this.options.contentHeight = this.oldCoordinate.contentHeight;
        //    this.options.contentWidth = this.oldCoordinate.contentWidth;
        //    this.options.maxHeightPercent = this.oldCoordinate.maxHeightPercent;
        //    this.options.maxHeight = this.oldCoordinate.maxHeight;
        //    this.options.maxWidth = this.oldCoordinate.maxWidth;
        //}
        //
        //if( this.oldSize ){
        //    this.width = this.oldSize.width;
        //    this.height = this.oldSize.height;
        //}

        //this.setContentSize( this.oldNodeSize.height, this.oldNodeSize.width );
        //this.node.setStyles( this.getNodeSize() );

        this.contentHeight = this.oldContentSize.height;
        this.contentWidth = this.oldContentSize.width;

        this.nodeHeight = this.oldNodeSize.height;
        this.nodeWidth = this.oldNodeSize.width;

        this.content.setStyles( this.oldContentSize );

        this.node.setStyles( this.oldNodeSize );

        this.reCenter();

        this.maxAction.setStyle("display","");
        this.restoreAction.setStyle("display","none");
        this.isMax = false;
        this.fireEvent("restore");
    },
R
roo00 已提交
305 306 307
    reCenter: function(){
        var size = this.node.getSize();

R
roo00 已提交
308 309 310 311 312 313 314 315
        if( this.options.positionWidth ){
            size.x = parseInt(this.options.positionWidth);
        }
        if( this.options.positionHeight ){
            size.y = parseInt(this.options.positionHeight);
        }

        var container = $(document.body);
R
roo00 已提交
316 317 318 319 320 321 322 323 324 325 326 327 328
        if( this.options.positionNode && this.options.positionNode.getSize().y<$(document.body).getSize().y ){
            container = this.options.positionNode;
        }else if (layout.desktop.currentApp){
            container = layout.desktop.currentApp.content;
        }else{
            if (this.options.container){
                if (this.options.container.getSize().y<$(document.body).getSize().y){
                    container = this.options.container;
                }
            }
        }

        var p = o2.getCenter(size, container, container);
R
roo00 已提交
329
        if (p.y< ( this.options.minTop || 0 ) ) p.y = this.options.minTop || 0;
R
roo00 已提交
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
        this.options.top = p.y;
        this.options.left = p.x;
        this.css.to.top = this.options.top+"px";
        this.css.to.left = this.options.left+"px";
        this.node.setStyles({
            "top": this.css.to.top,
            "left": this.css.to.left
        });
    },
    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 );
    },
    getOffsetX : function(node){
        return (node.getStyle("margin-left").toInt() || 0 ) +
            (node.getStyle("margin-right").toInt() || 0 ) +
            (node.getStyle("padding-left").toInt() || 0 ) +
            (node.getStyle("padding-right").toInt() || 0 )+
            (node.getStyle("border-left-width").toInt() || 0 ) +
            (node.getStyle("border-right-width").toInt() || 0 );
    },
    setContentHeightAuto : function(){
NoSubject's avatar
NoSubject 已提交
356
        var maxHeight = this.getMaxHeight();
R
roo00 已提交
357

R
roo00 已提交
358 359 360 361 362
        var offsetY = 0;
        var y = 0;
        //y = y + getOffsetY( this.title ) + this.title.getSize().y; //this.titleNode.getStyle("height").toInt();
        if( this.title )offsetY = offsetY + this.getOffsetY( this.title ) + this.title.getSize().y;
        if( this.bottom )offsetY = offsetY + this.getOffsetY( this.bottom ) + this.bottom.getSize().y;
NoSubject's avatar
NoSubject 已提交
363
        if( this.button && !this.buttonDisable )offsetY = offsetY + this.getOffsetY( this.button ) + this.button.getSize().y;
R
roo00 已提交
364 365 366 367 368 369 370 371
        if( this.content ){
            offsetY = offsetY + this.getOffsetY( this.content );
            y = offsetY + this.content.getSize().y;
        }else{
            y = offsetY;
        }


R
roo00 已提交
372
        if (  typeOf(maxHeight) === "number" && y > maxHeight) {
R
roo00 已提交
373 374 375 376 377 378 379 380 381 382
            this.options.height = maxHeight;
            this.options.contentHeight = null;
            this.options.fromTop = this.options.fromTop.toFloat() - offsetY / 2;
            this.options.top = this.options.top.toFloat() - offsetY / 2;
            this.css.to.height = maxHeight + "px";
            this.css.to.top = this.options.top + "px";
            this.css.from.top = this.options.fromTop + "px";
            this.node.setStyles({
                "height": maxHeight
            });
NoSubject's avatar
NoSubject 已提交
383
            this.contentHeight = maxHeight - offsetY;
R
roo00 已提交
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
            if (this.content) {
                this.content.setStyles({
                    "height" : maxHeight - offsetY,
                    "overflow-y": "auto"
                })
            }
        }else{
            this.options.height = y;
            this.options.contentHeight = null;
            this.options.fromTop = this.options.fromTop.toFloat() - offsetY / 2;
            this.options.top = this.options.top.toFloat() - offsetY / 2;
            this.css.to.height = y + "px";
            this.css.to.top = this.options.top + "px";
            this.css.from.top = this.options.fromTop + "px";
            this.node.setStyles({
                "height": y
            });
NoSubject's avatar
NoSubject 已提交
401
            this.contentHeight = y - offsetY;
R
roo00 已提交
402 403 404 405 406 407 408 409
            if (this.content) {
                this.content.setStyles({
                    "height" : y - offsetY,
                    "overflow-y": "hidden"
                })
            }
        }
    },
NoSubject's avatar
NoSubject 已提交
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
    getMaxHeight : function(){
        var maxHeightPercent;
        if( this.options.maxHeightPercent ){
            maxHeightPercent = this.options.maxHeightPercent;
            if( typeOf(maxHeightPercent) === "string" && maxHeightPercent.substr(maxHeightPercent.length - 1, 1) === "%" ) {
                var containerHeight = ( this.options.positionNode || this.options.container || $(document.body)).getSize().y;
                maxHeightPercent = parseInt(containerHeight * parseInt(maxHeightPercent) / 100);
            }
        }

        var maxHeight;
        if( this.options.maxHeight && parseFloat( this.options.maxHeight ).toString() !== "NaN" ){
            maxHeight = parseFloat( this.options.maxHeight );
            if( typeOf(maxHeightPercent) === "number" ){
                maxHeight = Math.min( maxHeight, maxHeightPercent )
            }
        }else if( typeOf(maxHeightPercent) === "number" ){
            maxHeight = maxHeightPercent;
        }
        return maxHeight;
    },
    getNodeSize: function(){
        return {
            "height": this.nodeHeight+"px",
            "width": this.nodeWidth+"px"
        };
    },
    getContentSize: function(height, width){
        var nodeHeight, nodeWidth;
R
roo00 已提交
439 440 441
        if (!height){
            if (this.options.contentHeight){
                nodeHeight = height = this.options.contentHeight.toFloat();
NoSubject's avatar
NoSubject 已提交
442
                this.contentHeight = height;
R
roo00 已提交
443 444
            }else{
                height = this.options.height.toFloat();
NoSubject's avatar
NoSubject 已提交
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462

                var maxHeight = this.getMaxHeight();
                if( typeOf(maxHeight) === "number" &&  maxHeight < height ){
                    height = maxHeight;
                }

                this.nodeHeight = height;
            }
        }else{
            this.nodeHeight = height;
        }
        if (!width){
            if (this.options.contentWidth){
                nodeWidth = width = this.options.contentWidth.toFloat();
                this.contentWidth = width;
            }else{
                width = this.options.width.toFloat();
                this.nodeWidth = width;
R
roo00 已提交
463
            }
NoSubject's avatar
NoSubject 已提交
464 465
        }else{
            this.nodeWidth = width;
R
roo00 已提交
466 467 468
        }

        var offsetHeight = 0;
NoSubject's avatar
NoSubject 已提交
469
        var offsetWidth = 0;
R
roo00 已提交
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
        if (this.title){
            var h1 = this.title.getSize().y;
            var ptop1 = this.title.getStyle("padding-top").toFloat();
            var pbottom1 = this.title.getStyle("padding-bottom").toFloat();
            var mtop1 = this.title.getStyle("margin-top").toFloat();
            var mbottom1 = this.title.getStyle("margin-bottom").toFloat();
            offsetHeight += h1 + ptop1 + pbottom1 + mtop1 + mbottom1;
        }
        if (this.bottom){
            var h2 = this.bottom.getSize().y;
            var ptop2 = this.bottom.getStyle("padding-top").toFloat();
            var pbottom2 = this.bottom.getStyle("padding-bottom").toFloat();
            var mtop2 = this.bottom.getStyle("margin-top").toFloat();
            var mbottom2 = this.bottom.getStyle("margin-bottom").toFloat();

            offsetHeight += h2 + ptop2 + pbottom2 + mtop2 + mbottom2;
        }
NoSubject's avatar
NoSubject 已提交
487
        if (this.button && !this.buttonDisable){
R
roo00 已提交
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
            var h3 = this.button.getSize().y;
            var ptop3 = this.button.getStyle("padding-top").toFloat();
            var pbottom3 = this.button.getStyle("padding-bottom").toFloat();
            var mtop3 = this.button.getStyle("margin-top").toFloat();
            var mbottom3 = this.button.getStyle("margin-bottom").toFloat();

            offsetHeight += h3 + ptop3 + pbottom3 + mtop3 + mbottom3;
        }

        var ptop4 = this.content.getStyle("padding-top").toFloat();
        var pbottom4 = this.content.getStyle("padding-bottom").toFloat();
        var mtop4 = this.content.getStyle("margin-top").toFloat();
        var mbottom4 = this.content.getStyle("margin-bottom").toFloat();
        offsetHeight += ptop4 + pbottom4 + mtop4 + mbottom4;

        if (nodeHeight){
            nodeHeight = nodeHeight + offsetHeight+2;
        }else {
            height = height - offsetHeight;
        }

NoSubject's avatar
NoSubject 已提交
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
        //if (this.content.getParent().getStyle("overflow-x")!="hidden" ) height = height-18;

        var pleft = this.content.getStyle("padding-left").toFloat();
        var pright = this.content.getStyle("padding-right").toFloat();
        var mleft = this.content.getStyle("margin-left").toFloat();
        var mright = this.content.getStyle("margin-right").toFloat();
        offsetWidth = pleft+pright+mleft+mright;
        //width = width-pleft-pright-mleft-mright;
        //if (this.content.getParent().getStyle("overflow-y")!="hidden" ) width = width-18;
        if (nodeWidth){
            nodeWidth = nodeWidth+offsetWidth;
        }else{
            width = width-offsetWidth;
        }


R
roo00 已提交
525
        if (nodeHeight) {
NoSubject's avatar
NoSubject 已提交
526
            this.nodeHeight = nodeHeight;
R
roo00 已提交
527 528 529 530 531 532 533
            this.options.height = nodeHeight;
            this.options.contentHeight = null;
            this.options.fromTop = this.options.fromTop.toFloat()-offsetHeight/2;
            this.options.top = this.options.top.toFloat()-offsetHeight/2;
            this.css.to.height = nodeHeight+"px";
            this.css.to.top = this.options.top+"px";
            this.css.from.top = this.options.fromTop+"px";
NoSubject's avatar
NoSubject 已提交
534 535
        }else{
            this.contentHeight = height;
R
roo00 已提交
536
        }
NoSubject's avatar
NoSubject 已提交
537

R
roo00 已提交
538
        if (nodeWidth){
NoSubject's avatar
NoSubject 已提交
539
            this.nodeWidth = nodeWidth;
R
roo00 已提交
540 541 542 543 544 545 546
            this.options.width = nodeWidth;
            this.options.contentWidth = null;
            this.options.fromLeft = this.options.fromLeft.toFloat()-offsetWidth/2;
            this.options.left = this.options.left.toFloat()-offsetWidth/2;
            this.css.to.width = nodeWidth+"px";
            this.css.to.left = this.options.left+"px";
            this.css.from.left = this.options.fromLeft+"px";
NoSubject's avatar
NoSubject 已提交
547 548
        }else{
            this.contentWidth = width;
R
roo00 已提交
549 550
        }

NoSubject's avatar
NoSubject 已提交
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
        if (!height || height<0){
            this.content.setStyles({"overflow": "hidden", "height": "auto", "width": ""+width+"px"});
            height = this.content.getSize().y;
            var h = height + h1 + ptop1 + pbottom1 + mtop1 + mbottom1;
            h = h + h2 + ptop2 + pbottom2 + mtop2 + mbottom2;
            h = h + h3 + ptop3 + pbottom3 + mtop3 + mbottom3;
            h = h + ptop4 + pbottom4 + mtop4 + mbottom4;
            this.css.to.height = h;
        }

//		var ptop5 = this.node.getStyle("padding-top").toFloat();
//		var pbottom5 = this.node.getStyle("padding-bottom").toFloat();
//		height = height - ptop5 - pbottom5;

        return {"height": height+"px", "width": width+"px"};
    },
    setContentHeight: function(height){
        var nodeHeight;
        if (!height){
            if (this.options.contentHeight){
                nodeHeight = height = this.options.contentHeight.toFloat();
                this.contentHeight = height;
            }else{
                height = this.options.height.toFloat();

                var maxHeight = this.getMaxHeight();
                if( typeOf(maxHeight) === "number" &&  maxHeight < height ){
                    height = maxHeight;
                }

                this.nodeHeight = height;
            }
        }else{
            this.nodeHeight = height;
        }

        var offsetHeight = 0;
        if (this.title){
            var h1 = this.title.getSize().y;
            //offsetHeight += h1 + this.getOffsetY(this.title);
            var ptop1 = this.title.getStyle("padding-top").toFloat();
            var pbottom1 = this.title.getStyle("padding-bottom").toFloat();
            var mtop1 = this.title.getStyle("margin-top").toFloat();
            var mbottom1 = this.title.getStyle("margin-bottom").toFloat();

            offsetHeight += h1 + ptop1 + pbottom1 + mtop1 + mbottom1;
        }
        if (this.bottom){
            var h2 = this.bottom.getSize().y;
            //offsetHeight += h2 + this.getOffsetY(this.bottom);
            var ptop2 = this.bottom.getStyle("padding-top").toFloat();
            var pbottom2 = this.bottom.getStyle("padding-bottom").toFloat();
            var mtop2 = this.bottom.getStyle("margin-top").toFloat();
            var mbottom2 = this.bottom.getStyle("margin-bottom").toFloat();

            offsetHeight += h2 + ptop2 + pbottom2 + mtop2 + mbottom2;
        }
        if (this.button && !this.buttonDisable){
            var h3 = this.button.getSize().y;
            //offsetHeight += h3 + this.getOffsetY(this.button);

            var ptop3 = this.button.getStyle("padding-top").toFloat();
            var pbottom3 = this.button.getStyle("padding-bottom").toFloat();
            var mtop3 = this.button.getStyle("margin-top").toFloat();
            var mbottom3 = this.button.getStyle("margin-bottom").toFloat();

            offsetHeight += h3 + ptop3 + pbottom3 + mtop3 + mbottom3;
        }

        //offsetHeight +=  this.getOffsetY(this.content);
        var ptop4 = this.content.getStyle("padding-top").toFloat();
        var pbottom4 = this.content.getStyle("padding-bottom").toFloat();
        var mtop4 = this.content.getStyle("margin-top").toFloat();
        var mbottom4 = this.content.getStyle("margin-bottom").toFloat();
        offsetHeight += ptop4 + pbottom4 + mtop4 + mbottom4;


        if (nodeHeight){
            nodeHeight = nodeHeight + offsetHeight+2;
        }else {
            height = height - offsetHeight;
        }

        if (nodeHeight) {
            this.nodeHeight = nodeHeight;
            this.options.height = nodeHeight;
            this.options.contentHeight = null;
            this.options.fromTop = this.options.fromTop.toFloat()-offsetHeight/2;
            this.options.top = this.options.top.toFloat()-offsetHeight/2;
            this.css.to.height = nodeHeight+"px";
            this.css.to.top = this.options.top+"px";
            this.css.from.top = this.options.fromTop+"px";
        }else{
            this.contentHeight = height;
        }
        //if (nodeWidth){
        //    this.nodeWidth = nodeWidth;
        //    this.options.width = nodeWidth;
        //    this.options.contentWidth = null;
        //    this.options.fromLeft = this.options.fromLeft.toFloat()-offsetWidth/2;
        //    this.options.left = this.options.left.toFloat()-offsetWidth/2;
        //    this.css.to.width = nodeWidth+"px";
        //    this.css.to.left = this.options.left+"px";
        //    this.css.from.left = this.options.fromLeft+"px";
        //}else{
        //    this.contentWidth = width;
        //}

R
roo00 已提交
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
        if (!height || height<0){
            this.content.setStyles({"overflow": "hidden", "height": "auto"});
            height = this.content.getSize().y;
            var h = height + h1 + ptop1 + pbottom1 + mtop1 + mbottom1;
            h = h + h2 + ptop2 + pbottom2 + mtop2 + mbottom2;
            h = h + h3 + ptop3 + pbottom3 + mtop3 + mbottom3;
            h = h + ptop4 + pbottom4 + mtop4 + mbottom4;
            this.css.to.height = h;
        }else{
            this.content.setStyles( {"height" : height} )
        }

    },
    setContentWidthAuto : function(){
        var maxWidth = this.options.maxWidth || "100%";
        if( typeOf(maxWidth) === "string" && maxWidth.substr(maxWidth.length - 1, 1) === "%" ) {
            var containerWidth = ( this.options.positionNode || this.options.container || $(document.body)).getSize().x;
            maxWidth = parseInt(containerWidth * parseInt(maxWidth) / 100);
        }

        var offsetX = 0;
        var x = 0;
        if( this.content ){
            offsetX = offsetX + this.getOffsetX( this.content );
            x = offsetX + this.content.getSize().x;
        }else{
            x = offsetX;
        }


        if ( x > maxWidth) {
NoSubject's avatar
NoSubject 已提交
690
            this.nodeWidth = maxWidth;
R
roo00 已提交
691 692 693 694 695 696 697 698 699 700
            this.options.width = maxWidth;
            this.options.contentWidth = null;
            this.options.fromLeft = this.options.fromLeft.toFloat() - offsetX / 2;
            this.options.left = this.options.left.toFloat() - offsetX / 2;
            this.css.to.width = maxWidth + "px";
            this.css.to.left = this.options.left + "px";
            this.css.from.left = this.options.fromLeft + "px";
            this.node.setStyles({
                "width": maxWidth
            });
NoSubject's avatar
NoSubject 已提交
701
            this.contentWidth = maxWidth - offsetX;
R
roo00 已提交
702 703 704 705 706 707 708
            if (this.content) {
                this.content.setStyles({
                    "width" : maxWidth - offsetX,
                    "overflow-x": "auto"
                })
            }
        }else{
NoSubject's avatar
NoSubject 已提交
709
            this.nodeWidth = x;
R
roo00 已提交
710 711 712 713 714 715 716 717 718 719
            this.options.width = x;
            this.options.contentHeight = null;
            this.options.fromLeft = this.options.fromLeft.toFloat() - offsetX / 2;
            this.options.left = this.options.left.toFloat() - offsetX / 2;
            this.css.to.width = x + "px";
            this.css.to.left = this.options.left + "px";
            this.css.from.left = this.options.fromLeft + "px";
            this.node.setStyles({
                "width": x
            });
NoSubject's avatar
NoSubject 已提交
720
            this.contentWidth = x - offsetX;
R
roo00 已提交
721 722 723 724 725 726 727 728 729 730 731 732 733
            if (this.content) {
                this.content.setStyles({
                    "width" : x - offsetX,
                    "overflow-x": "hidden"
                })
            }
        }
    },
    setContentWidth: function(width){
        var nodeWidth;
        if (!width){
            if (this.options.contentWidth){
                nodeWidth = width = this.options.contentWidth.toFloat();
NoSubject's avatar
NoSubject 已提交
734
                this.contentWidth = width;
R
roo00 已提交
735 736
            }else{
                width = this.options.width.toFloat();
NoSubject's avatar
NoSubject 已提交
737
                this.nodeWidth = width;
R
roo00 已提交
738
            }
NoSubject's avatar
NoSubject 已提交
739 740
        }else{
            this.nodeWidth = width;
R
roo00 已提交
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
        }


        var offsetWidth = 0;

        //if (this.content.getParent().getStyle("overflow-x")!="hidden" ) height = height-18;

        var pleft = this.content.getStyle("padding-left").toFloat();
        var pright = this.content.getStyle("padding-right").toFloat();
        var mleft = this.content.getStyle("margin-left").toFloat();
        var mright = this.content.getStyle("margin-right").toFloat();
        offsetWidth = pleft+pright+mleft+mright;
        //width = width-pleft-pright-mleft-mright;
        //if (this.content.getParent().getStyle("overflow-y")!="hidden" ) width = width-18;
        if (nodeWidth){
            nodeWidth = nodeWidth+offsetWidth;
        }else{
            var x = width;
            width = width-offsetWidth;
        }

        if (nodeWidth){
NoSubject's avatar
NoSubject 已提交
763
            this.nodeWidth = nodeWidth;
R
roo00 已提交
764 765 766 767 768 769 770 771 772
            this.options.width = nodeWidth;
            this.options.contentWidth = null;
            this.css.to.left = this.options.left+"px";
            this.css.from.left = this.options.fromLeft+"px";
            this.css.to.width = nodeWidth+"px";
            this.options.fromLeft = this.options.fromLeft.toFloat()-offsetWidth/2;
            this.options.left = this.options.left.toFloat()-offsetWidth/2;
            this.node.setStyle("width", nodeWidth )
        }else{
NoSubject's avatar
NoSubject 已提交
773
            this.contentWidth = width;
R
roo00 已提交
774 775 776 777 778 779 780
            this.node.setStyle("width", x )
        }

        this.content.setStyles( {"width" : width} )

    },
    setContentSize: function(height, width){
NoSubject's avatar
NoSubject 已提交
781
        debugger;
R
roo00 已提交
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
        //this.content.setStyle("height", this.getContentSize(height));
        // if (!this.options.height && !height){
        //    this.content.setStyle("height", "auto");
        //    this.content.setStyle("overflow", "hidden");
        //    this.content.setStyle("width", "auto");
        // }else{
        var y = height;
        if (!y){
            if (this.options.contentHeight){
                y = this.options.contentHeight;
            }else{
                y = this.height;
            }
        }

        var x = width;
        if (!x){
            if (this.options.contentWidth){
                x = this.options.contentWidth;
            }else{
                x = this.width;
            }
        }
        if( y === "auto" || x === "auto" ){
            if( y === "auto" ){
                this.setContentHeightAuto();
            }else{
                this.setContentHeight( height );
            }
            if( x === "auto" ){
                this.setContentWidthAuto();
            }else{
                this.setContentWidth( width );
            }
        }else{
            this.content.setStyles(this.getContentSize(height, width));
            this.content.setStyle("width", "auto");
        }
    }
R
roo00 已提交
821
});
NoSubject's avatar
NoSubject 已提交
822
o2.DL.open = function(options){
823
    debugger;
NoSubject's avatar
NoSubject 已提交
824 825 826 827 828 829 830
    if (!options) options = {};
    if (!options.style) options.style = "user";
    //if (!options.transition) options.transition = Fx.Transitions.Back.easeOut;
    if (!options.duration) options.duration = 200;
    if (options.isClose!==false) options.isClose = true;

    var size;
831
    if ((!options.width || options.width=="auto") && !options.contentWidth){
NoSubject's avatar
NoSubject 已提交
832 833 834 835 836 837
        if (options.content){
            options.content.show();
            size = options.content.getComputedSize();
            options.contentWidth = size.totalWidth.toFloat();
        }
    }
838
    if ((!options.height || options.height=="auto") && !options.contentHeight){
NoSubject's avatar
NoSubject 已提交
839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
        if (options.content){
            if (!size){
                options.content.show();
                size = options.content.getComputedSize();
            }
            options.contentHeight = size.totalHeight.toFloat()+2;
        }
    }
    if (!options.width && !options.contentWidth) options.width = 300;
    if (!options.height && !options.contentHeight) options.height = 150;

    if (!options.container && layout){
        if (layout.desktop.currentApp){
            options.container = layout.desktop.currentApp.content;
        }
    }
    var container = (options.positionNode || options.container || $(document.body));

R
roo00 已提交
857
    if( options.width !== "auto" && options.height !== "auto" ){
NoSubject's avatar
NoSubject 已提交
858 859 860 861 862 863 864 865 866 867

        //如果是百分比
        if( "string" == typeOf(options.width)  && (1 < options.width.length && "%" == options.width.substr(options.width.length - 1, 1)) ){
            options.width = parseInt( container.getSize().x * parseInt(options.width, 10) / 100, 10);
        }

        if( "string" == typeOf(options.height)  && (1 < options.height.length && "%" == options.height.substr(options.height.length - 1, 1)) ){
            options.height = parseInt( container.getSize().y * parseInt(options.height, 10) / 100, 10);
        }

R
roo00 已提交
868 869 870 871 872 873 874 875 876
        if ((options.top===undefined ) && (options.left===undefined)){
            var p = o2.getCenter({"x":(options.width || options.contentWidth), "y": (options.height || options.contentHeight+120)}, container, container);
            options.top = (p.y<0) ? 0 : p.y;
            options.left  = (p.x<0) ? 0 : p.x;
        }
        if ((options.fromTop===undefined ) && (options.fromLeft===undefined)){
            var p = o2.getCenter({"x":(options.width || options.contentWidth)*0, "y": (options.height || options.contentHeight+120)*0}, container, container);
            options.fromTop = (p.y<0) ? 0 : p.y;
            options.fromLeft  = (p.x<0) ? 0 : p.x;
NoSubject's avatar
NoSubject 已提交
877
        }
R
roo00 已提交
878 879 880 881 882 883 884 885 886
        if (options.offset){
            if (options.offset.y){
                options.top = options.top+options.offset.y.toInt();
                options.fromTop = options.fromTop+options.offset.y.toInt();
            }
            if (options.offset.x){
                options.left = options.left+options.offset.x.toInt();
                options.fromLeft = options.fromLeft+options.offset.x.toInt();
            }
NoSubject's avatar
NoSubject 已提交
887
        }
R
roo00 已提交
888 889 890 891 892 893 894 895 896
        if (options.top<0) options.top = 0;
        if (options.left<0) options.left = 0;
        if (options.fromTop<0) options.fromTop = 0;
        if (options.fromLeft<0) options.fromLeft = 0;
    }else{
        if(options.top===undefined )options.top = 0;
        if(options.left===undefined)options.left = 0;
        if(options.fromTop===undefined)options.fromTop = 0;
        if(options.fromLeft===undefined)options.fromLeft = 0;
NoSubject's avatar
NoSubject 已提交
897
    }
R
roo00 已提交
898

NoSubject's avatar
NoSubject 已提交
899 900 901 902

    options.mark = !(options.mask===false);

    var dlg = new o2.DDL(options);
R
roo00 已提交
903 904 905
    if( options.width === "auto" || options.height === "auto" ){
        dlg.reCenter();
    }
NoSubject's avatar
NoSubject 已提交
906 907 908
    dlg.show();
    return dlg;
};