4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
15 * These classes are derivatives of the similarly named classes in the YUI Library.
16 * The original license:
17 * Copyright (c) 2006, Yahoo! Inc. All rights reserved.
18 * Code licensed under the BSD License:
19 * http://developer.yahoo.net/yui/license.txt
24 var Event=Roo.EventManager;
28 * @class Roo.dd.DragDrop
29 * Defines the interface and base operation of items that that can be
30 * dragged or can be drop targets. It was designed to be extended, overriding
31 * the event handlers for startDrag, onDrag, onDragOver and onDragOut.
32 * Up to three html elements can be associated with a DragDrop instance:
34 * <li>linked element: the element that is passed into the constructor.
35 * This is the element which defines the boundaries for interaction with
36 * other DragDrop objects.</li>
37 * <li>handle element(s): The drag operation only occurs if the element that
38 * was clicked matches a handle element. By default this is the linked
39 * element, but there are times that you will want only a portion of the
40 * linked element to initiate the drag operation, and the setHandleElId()
41 * method provides a way to define this.</li>
42 * <li>drag element: this represents the element that would be moved along
43 * with the cursor during a drag operation. By default, this is the linked
44 * element itself as in {@link Roo.dd.DD}. setDragElId() lets you define
45 * a separate element that would be moved, as in {@link Roo.dd.DDProxy}.
48 * This class should not be instantiated until the onload event to ensure that
49 * the associated elements are available.
50 * The following would define a DragDrop obj that would interact with any
51 * other DragDrop obj in the "group1" group:
53 * dd = new Roo.dd.DragDrop("div1", "group1");
55 * Since none of the event handlers have been implemented, nothing would
56 * actually happen if you were to run the code above. Normally you would
57 * override this class or one of the default implementations, but you can
58 * also override the methods you want on an instance of the class...
60 * dd.onDragDrop = function(e, id) {
61 * alert("dd was dropped on " + id);
65 * @param {String} id of the element that is linked to this instance
66 * @param {String} sGroup the group of related DragDrop objects
67 * @param {object} config an object containing configurable attributes
68 * Valid properties for DragDrop:
69 * padding, isTarget, maintainOffset, primaryButtonOnly
71 Roo.dd.DragDrop = function(id, sGroup, config) {
73 this.init(id, sGroup, config);
78 Roo.extend(Roo.dd.DragDrop, Roo.util.Observable , {
81 * The id of the element associated with this object. This is what we
82 * refer to as the "linked element" because the size and position of
83 * this element is used to determine when the drag and drop objects have
91 * Configuration attributes passed into the constructor
98 * The id of the element that will be dragged. By default this is same
99 * as the linked element , but could be changed to another element. Ex:
108 * the id of the element that initiates the drag operation. By default
109 * this is the linked element, but could be changed to be a child of this
110 * element. This lets us do things like only starting the drag when the
111 * header element within the linked html element is clicked.
112 * @property handleElId
119 * An associative array of HTML tags that will be ignored if clicked.
120 * @property invalidHandleTypes
121 * @type {string: string}
123 invalidHandleTypes: null,
126 * An associative array of ids for elements that will be ignored if clicked
127 * @property invalidHandleIds
128 * @type {string: string}
130 invalidHandleIds: null,
133 * An indexted array of css class names for elements that will be ignored
135 * @property invalidHandleClasses
138 invalidHandleClasses: null,
141 * The linked element's absolute X position at the time the drag was
143 * @property startPageX
150 * The linked element's absolute X position at the time the drag was
152 * @property startPageY
159 * The group defines a logical collection of DragDrop objects that are
160 * related. Instances only get events when interacting with other
161 * DragDrop object in the same group. This lets us define multiple
162 * groups using a single DragDrop subclass if we want.
164 * @type {string: string}
169 * Individual drag/drop instances can be locked. This will prevent
170 * onmousedown start drag.
181 lock: function() { this.locked = true; },
184 * Unlock this instace
187 unlock: function() { this.locked = false; },
190 * By default, all insances can be a drop target. This can be disabled by
191 * setting isTarget to false.
198 * The padding configured for this drag and drop object for calculating
199 * the drop zone intersection with this object.
206 * Cached reference to the linked element
213 * Internal typeof flag
214 * @property __ygDragDrop
220 * Set to true when horizontal contraints are applied
221 * @property constrainX
228 * Set to true when vertical contraints are applied
229 * @property constrainY
236 * The left constraint
244 * The right constraint
261 * The down constraint
269 * Maintain offsets when we resetconstraints. Set to true when you want
270 * the position of the element relative to its parent to stay the same
271 * when the page changes
273 * @property maintainOffset
276 maintainOffset: false,
279 * Array of pixel locations the element will snap to if we specified a
280 * horizontal graduation/interval. This array is generated automatically
281 * when you define a tick interval.
288 * Array of pixel locations the element will snap to if we specified a
289 * vertical graduation/interval. This array is generated automatically
290 * when you define a tick interval.
297 * By default the drag and drop instance will only respond to the primary
298 * button click (left button for a right-handed mouse). Set to true to
299 * allow drag and drop to start with any mouse click that is propogated
301 * @property primaryButtonOnly
304 primaryButtonOnly: true,
307 * The availabe property is false until the linked dom element is accessible.
308 * @property available
314 * By default, drags can only be initiated if the mousedown occurs in the
315 * region the linked element is. This is done in part to work around a
316 * bug in some browsers that mis-report the mousedown if the previous
317 * mouseup happened outside of the window. This property is set to true
318 * if outer handles are defined.
320 * @property hasOuterHandles
324 hasOuterHandles: false,
327 * Code that executes immediately before the startDrag event
328 * @method b4StartDrag
331 b4StartDrag: function(x, y) { },
334 * Abstract method called after a drag/drop object is clicked
335 * and the drag or mousedown time thresholds have beeen met.
337 * @param {int} X click location
338 * @param {int} Y click location
340 startDrag: function(x, y) { /* override this */ },
343 * Code that executes immediately before the onDrag event
347 b4Drag: function(e) { },
350 * Abstract method called during the onMouseMove event while dragging an
353 * @param {Event} e the mousemove event
355 onDrag: function(e) { /* override this */ },
358 * Abstract method called when this element fist begins hovering over
359 * another DragDrop obj
360 * @method onDragEnter
361 * @param {Event} e the mousemove event
362 * @param {String|DragDrop[]} id In POINT mode, the element
363 * id this is hovering over. In INTERSECT mode, an array of one or more
364 * dragdrop items being hovered over.
366 onDragEnter: function(e, id) { /* override this */ },
369 * Code that executes immediately before the onDragOver event
373 b4DragOver: function(e) { },
376 * Abstract method called when this element is hovering over another
379 * @param {Event} e the mousemove event
380 * @param {String|DragDrop[]} id In POINT mode, the element
381 * id this is hovering over. In INTERSECT mode, an array of dd items
382 * being hovered over.
384 onDragOver: function(e, id) { /* override this */ },
387 * Code that executes immediately before the onDragOut event
391 b4DragOut: function(e) { },
394 * Abstract method called when we are no longer hovering over an element
396 * @param {Event} e the mousemove event
397 * @param {String|DragDrop[]} id In POINT mode, the element
398 * id this was hovering over. In INTERSECT mode, an array of dd items
399 * that the mouse is no longer over.
401 onDragOut: function(e, id) { /* override this */ },
404 * Code that executes immediately before the onDragDrop event
408 b4DragDrop: function(e) { },
411 * Abstract method called when this item is dropped on another DragDrop
414 * @param {Event} e the mouseup event
415 * @param {String|DragDrop[]} id In POINT mode, the element
416 * id this was dropped on. In INTERSECT mode, an array of dd items this
419 onDragDrop: function(e, id) { /* override this */ },
422 * Abstract method called when this item is dropped on an area with no
424 * @method onInvalidDrop
425 * @param {Event} e the mouseup event
427 onInvalidDrop: function(e) { /* override this */ },
430 * Code that executes immediately before the endDrag event
434 b4EndDrag: function(e) { },
437 * Fired when we are done dragging the object
439 * @param {Event} e the mouseup event
441 endDrag: function(e) { /* override this */ },
444 * Code executed immediately before the onMouseDown event
445 * @method b4MouseDown
446 * @param {Event} e the mousedown event
449 b4MouseDown: function(e) { },
452 * Event handler that fires when a drag/drop obj gets a mousedown
453 * @method onMouseDown
454 * @param {Event} e the mousedown event
456 onMouseDown: function(e) { /* override this */ },
459 * Event handler that fires when a drag/drop obj gets a mouseup
461 * @param {Event} e the mouseup event
463 onMouseUp: function(e) { /* override this */ },
466 * Override the onAvailable method to do what is needed after the initial
467 * position was determined.
468 * @method onAvailable
470 onAvailable: function () {
474 * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
477 defaultPadding : {left:0, right:0, top:0, bottom:0},
480 * Initializes the drag drop object's constraints to restrict movement to a certain element.
484 var dd = new Roo.dd.DDProxy("dragDiv1", "proxytest",
485 { dragElId: "existingProxyDiv" });
486 dd.startDrag = function(){
487 this.constrainTo("parent-id");
490 * Or you can initalize it using the {@link Roo.Element} object:
492 Roo.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
493 startDrag : function(){
494 this.constrainTo("parent-id");
498 * @param {String/HTMLElement/Element} constrainTo The element to constrain to.
499 * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
500 * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
501 * an object containing the sides to pad. For example: {right:10, bottom:10}
502 * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
504 constrainTo : function(constrainTo, pad, inContent){
505 if(typeof pad == "number"){
506 pad = {left: pad, right:pad, top:pad, bottom:pad};
508 pad = pad || this.defaultPadding;
509 var b = Roo.get(this.getEl()).getBox();
510 var ce = Roo.get(constrainTo);
511 var s = ce.getScroll();
513 if(cd == document.body){
514 c = { x: s.left, y: s.top, width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
517 c = {x : xy[0]+s.left, y: xy[1]+s.top, width: cd.clientWidth, height: cd.clientHeight};
521 var topSpace = b.y - c.y;
522 var leftSpace = b.x - c.x;
524 this.resetConstraints();
525 this.setXConstraint(leftSpace - (pad.left||0), // left
526 c.width - leftSpace - b.width - (pad.right||0) //right
528 this.setYConstraint(topSpace - (pad.top||0), //top
529 c.height - topSpace - b.height - (pad.bottom||0) //bottom
534 * Returns a reference to the linked element
536 * @return {HTMLElement} the html element
540 this._domRef = Roo.getDom(this.id);
547 * Returns a reference to the actual element to drag. By default this is
548 * the same as the html element, but it can be assigned to another
549 * element. An example of this can be found in Roo.dd.DDProxy
551 * @return {HTMLElement} the html element
553 getDragEl: function() {
554 return Roo.getDom(this.dragElId);
558 * Sets up the DragDrop object. Must be called in the constructor of any
559 * Roo.dd.DragDrop subclass
561 * @param id the id of the linked element
562 * @param {String} sGroup the group of related items
563 * @param {object} config configuration attributes
565 init: function(id, sGroup, config) {
566 this.initTarget(id, sGroup, config);
567 Event.on(this.id, "mousedown", this.handleMouseDown, this);
568 // Event.on(this.id, "selectstart", Event.preventDefault);
572 * Initializes Targeting functionality only... the object does not
573 * get a mousedown handler.
575 * @param id the id of the linked element
576 * @param {String} sGroup the group of related items
577 * @param {object} config configuration attributes
579 initTarget: function(id, sGroup, config) {
581 // configuration attributes
582 this.config = config || {};
584 // create a local reference to the drag and drop manager
585 this.DDM = Roo.dd.DDM;
586 // initialize the groups array
589 // assume that we have an element reference instead of an id if the
590 // parameter is not a string
591 if (typeof id !== "string") {
598 // add to an interaction group
599 this.addToGroup((sGroup) ? sGroup : "default");
601 // We don't want to register this as the handle with the manager
602 // so we just set the id rather than calling the setter.
603 this.handleElId = id;
605 // the linked element is the element that gets dragged by default
606 this.setDragElId(id);
608 // by default, clicked anchors will not start drag operations.
609 this.invalidHandleTypes = { A: "A" };
610 this.invalidHandleIds = {};
611 this.invalidHandleClasses = [];
615 this.handleOnAvailable();
619 * Applies the configuration parameters that were passed into the constructor.
620 * This is supposed to happen at each level through the inheritance chain. So
621 * a DDProxy implentation will execute apply config on DDProxy, DD, and
622 * DragDrop in order to get all of the parameters that are available in
624 * @method applyConfig
626 applyConfig: function() {
628 // configurable properties:
629 // padding, isTarget, maintainOffset, primaryButtonOnly
630 this.padding = this.config.padding || [0, 0, 0, 0];
631 this.isTarget = (this.config.isTarget !== false);
632 this.maintainOffset = (this.config.maintainOffset);
633 this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
638 * Executed when the linked element is available
639 * @method handleOnAvailable
642 handleOnAvailable: function() {
643 this.available = true;
644 this.resetConstraints();
649 * Configures the padding for the target zone in px. Effectively expands
650 * (or reduces) the virtual object size for targeting calculations.
651 * Supports css-style shorthand; if only one parameter is passed, all sides
652 * will have that padding, and if only two are passed, the top and bottom
653 * will have the first param, the left and right the second.
655 * @param {int} iTop Top pad
656 * @param {int} iRight Right pad
657 * @param {int} iBot Bot pad
658 * @param {int} iLeft Left pad
660 setPadding: function(iTop, iRight, iBot, iLeft) {
661 // this.padding = [iLeft, iRight, iTop, iBot];
662 if (!iRight && 0 !== iRight) {
663 this.padding = [iTop, iTop, iTop, iTop];
664 } else if (!iBot && 0 !== iBot) {
665 this.padding = [iTop, iRight, iTop, iRight];
667 this.padding = [iTop, iRight, iBot, iLeft];
672 * Stores the initial placement of the linked element.
673 * @method setInitialPosition
674 * @param {int} diffX the X offset, default 0
675 * @param {int} diffY the Y offset, default 0
677 setInitPosition: function(diffX, diffY) {
678 var el = this.getEl();
680 if (!this.DDM.verifyEl(el)) {
687 var p = Dom.getXY( el );
689 this.initPageX = p[0] - dx;
690 this.initPageY = p[1] - dy;
692 this.lastPageX = p[0];
693 this.lastPageY = p[1];
696 this.setStartPosition(p);
700 * Sets the start position of the element. This is set when the obj
701 * is initialized, the reset when a drag is started.
702 * @method setStartPosition
703 * @param pos current position (from previous lookup)
706 setStartPosition: function(pos) {
707 var p = pos || Dom.getXY( this.getEl() );
708 this.deltaSetXY = null;
710 this.startPageX = p[0];
711 this.startPageY = p[1];
715 * Add this instance to a group of related drag/drop objects. All
716 * instances belong to at least one group, and can belong to as many
719 * @param sGroup {string} the name of the group
721 addToGroup: function(sGroup) {
722 this.groups[sGroup] = true;
723 this.DDM.regDragDrop(this, sGroup);
727 * Remove's this instance from the supplied interaction group
728 * @method removeFromGroup
729 * @param {string} sGroup The group to drop
731 removeFromGroup: function(sGroup) {
732 if (this.groups[sGroup]) {
733 delete this.groups[sGroup];
736 this.DDM.removeDDFromGroup(this, sGroup);
740 * Allows you to specify that an element other than the linked element
741 * will be moved with the cursor during a drag
742 * @method setDragElId
743 * @param id {string} the id of the element that will be used to initiate the drag
745 setDragElId: function(id) {
750 * Allows you to specify a child of the linked element that should be
751 * used to initiate the drag operation. An example of this would be if
752 * you have a content div with text and links. Clicking anywhere in the
753 * content area would normally start the drag operation. Use this method
754 * to specify that an element inside of the content div is the element
755 * that starts the drag operation.
756 * @method setHandleElId
757 * @param id {string} the id of the element that will be used to
760 setHandleElId: function(id) {
761 if (typeof id !== "string") {
764 this.handleElId = id;
765 this.DDM.regHandle(this.id, id);
769 * Allows you to set an element outside of the linked element as a drag
771 * @method setOuterHandleElId
772 * @param id the id of the element that will be used to initiate the drag
774 setOuterHandleElId: function(id) {
775 if (typeof id !== "string") {
778 Event.on(id, "mousedown",
779 this.handleMouseDown, this);
780 this.setHandleElId(id);
782 this.hasOuterHandles = true;
786 * Remove all drag and drop hooks for this element
790 Event.un(this.id, "mousedown",
791 this.handleMouseDown);
793 this.DDM._remove(this);
796 destroy : function(){
801 * Returns true if this instance is locked, or the drag drop mgr is locked
802 * (meaning that all drag/drop is disabled on the page.)
804 * @return {boolean} true if this obj or all drag/drop is locked, else
807 isLocked: function() {
808 return (this.DDM.isLocked() || this.locked);
812 * Fired when this object is clicked
813 * @method handleMouseDown
815 * @param {Roo.dd.DragDrop} oDD the clicked dd object (this dd obj)
818 handleMouseDown: function(e, oDD){
819 if (this.primaryButtonOnly && e.button != 0) {
823 if (this.isLocked()) {
827 this.DDM.refreshCache(this.groups);
829 var pt = new Roo.lib.Point(Roo.lib.Event.getPageX(e), Roo.lib.Event.getPageY(e));
830 if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) {
832 if (this.clickValidator(e)) {
834 // set the initial element position
835 this.setStartPosition();
841 this.DDM.handleMouseDown(e, this);
843 this.DDM.stopEvent(e);
851 clickValidator: function(e) {
852 var target = e.getTarget();
853 return ( this.isValidHandleChild(target) &&
854 (this.id == this.handleElId ||
855 this.DDM.handleWasClicked(target, this.id)) );
859 * Allows you to specify a tag name that should not start a drag operation
860 * when clicked. This is designed to facilitate embedding links within a
861 * drag handle that do something other than start the drag.
862 * @method addInvalidHandleType
863 * @param {string} tagName the type of element to exclude
865 addInvalidHandleType: function(tagName) {
866 var type = tagName.toUpperCase();
867 this.invalidHandleTypes[type] = type;
871 * Lets you to specify an element id for a child of a drag handle
872 * that should not initiate a drag
873 * @method addInvalidHandleId
874 * @param {string} id the element id of the element you wish to ignore
876 addInvalidHandleId: function(id) {
877 if (typeof id !== "string") {
880 this.invalidHandleIds[id] = id;
884 * Lets you specify a css class of elements that will not initiate a drag
885 * @method addInvalidHandleClass
886 * @param {string} cssClass the class of the elements you wish to ignore
888 addInvalidHandleClass: function(cssClass) {
889 this.invalidHandleClasses.push(cssClass);
893 * Unsets an excluded tag name set by addInvalidHandleType
894 * @method removeInvalidHandleType
895 * @param {string} tagName the type of element to unexclude
897 removeInvalidHandleType: function(tagName) {
898 var type = tagName.toUpperCase();
899 // this.invalidHandleTypes[type] = null;
900 delete this.invalidHandleTypes[type];
904 * Unsets an invalid handle id
905 * @method removeInvalidHandleId
906 * @param {string} id the id of the element to re-enable
908 removeInvalidHandleId: function(id) {
909 if (typeof id !== "string") {
912 delete this.invalidHandleIds[id];
916 * Unsets an invalid css class
917 * @method removeInvalidHandleClass
918 * @param {string} cssClass the class of the element(s) you wish to
921 removeInvalidHandleClass: function(cssClass) {
922 for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
923 if (this.invalidHandleClasses[i] == cssClass) {
924 delete this.invalidHandleClasses[i];
930 * Checks the tag exclusion list to see if this click should be ignored
931 * @method isValidHandleChild
932 * @param {HTMLElement} node the HTMLElement to evaluate
933 * @return {boolean} true if this is a valid tag type, false if not
935 isValidHandleChild: function(node) {
938 // var n = (node.nodeName == "#text") ? node.parentNode : node;
941 nodeName = node.nodeName.toUpperCase();
943 nodeName = node.nodeName;
945 valid = valid && !this.invalidHandleTypes[nodeName];
946 valid = valid && !this.invalidHandleIds[node.id];
948 for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
949 valid = !Dom.hasClass(node, this.invalidHandleClasses[i]);
958 * Create the array of horizontal tick marks if an interval was specified
959 * in setXConstraint().
963 setXTicks: function(iStartX, iTickSize) {
965 this.xTickSize = iTickSize;
969 for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
971 this.xTicks[this.xTicks.length] = i;
976 for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
978 this.xTicks[this.xTicks.length] = i;
983 this.xTicks.sort(this.DDM.numericSort) ;
987 * Create the array of vertical tick marks if an interval was specified in
992 setYTicks: function(iStartY, iTickSize) {
994 this.yTickSize = iTickSize;
998 for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
1000 this.yTicks[this.yTicks.length] = i;
1005 for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
1007 this.yTicks[this.yTicks.length] = i;
1012 this.yTicks.sort(this.DDM.numericSort) ;
1016 * By default, the element can be dragged any place on the screen. Use
1017 * this method to limit the horizontal travel of the element. Pass in
1018 * 0,0 for the parameters if you want to lock the drag to the y axis.
1019 * @method setXConstraint
1020 * @param {int} iLeft the number of pixels the element can move to the left
1021 * @param {int} iRight the number of pixels the element can move to the
1023 * @param {int} iTickSize optional parameter for specifying that the
1025 * should move iTickSize pixels at a time.
1027 setXConstraint: function(iLeft, iRight, iTickSize) {
1028 this.leftConstraint = iLeft;
1029 this.rightConstraint = iRight;
1031 this.minX = this.initPageX - iLeft;
1032 this.maxX = this.initPageX + iRight;
1033 if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
1035 this.constrainX = true;
1039 * Clears any constraints applied to this instance. Also clears ticks
1040 * since they can't exist independent of a constraint at this time.
1041 * @method clearConstraints
1043 clearConstraints: function() {
1044 this.constrainX = false;
1045 this.constrainY = false;
1050 * Clears any tick interval defined for this instance
1051 * @method clearTicks
1053 clearTicks: function() {
1061 * By default, the element can be dragged any place on the screen. Set
1062 * this to limit the vertical travel of the element. Pass in 0,0 for the
1063 * parameters if you want to lock the drag to the x axis.
1064 * @method setYConstraint
1065 * @param {int} iUp the number of pixels the element can move up
1066 * @param {int} iDown the number of pixels the element can move down
1067 * @param {int} iTickSize optional parameter for specifying that the
1068 * element should move iTickSize pixels at a time.
1070 setYConstraint: function(iUp, iDown, iTickSize) {
1071 this.topConstraint = iUp;
1072 this.bottomConstraint = iDown;
1074 this.minY = this.initPageY - iUp;
1075 this.maxY = this.initPageY + iDown;
1076 if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
1078 this.constrainY = true;
1083 * resetConstraints must be called if you manually reposition a dd element.
1084 * @method resetConstraints
1085 * @param {boolean} maintainOffset
1087 resetConstraints: function() {
1090 // Maintain offsets if necessary
1091 if (this.initPageX || this.initPageX === 0) {
1092 // figure out how much this thing has moved
1093 var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0;
1094 var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0;
1096 this.setInitPosition(dx, dy);
1098 // This is the first time we have detected the element's position
1100 this.setInitPosition();
1103 if (this.constrainX) {
1104 this.setXConstraint( this.leftConstraint,
1105 this.rightConstraint,
1109 if (this.constrainY) {
1110 this.setYConstraint( this.topConstraint,
1111 this.bottomConstraint,
1117 * Normally the drag element is moved pixel by pixel, but we can specify
1118 * that it move a number of pixels at a time. This method resolves the
1119 * location when we have it set up like this.
1121 * @param {int} val where we want to place the object
1122 * @param {int[]} tickArray sorted array of valid points
1123 * @return {int} the closest tick
1126 getTick: function(val, tickArray) {
1129 // If tick interval is not defined, it is effectively 1 pixel,
1130 // so we return the value passed to us.
1132 } else if (tickArray[0] >= val) {
1133 // The value is lower than the first tick, so we return the first
1135 return tickArray[0];
1137 for (var i=0, len=tickArray.length; i<len; ++i) {
1139 if (tickArray[next] && tickArray[next] >= val) {
1140 var diff1 = val - tickArray[i];
1141 var diff2 = tickArray[next] - val;
1142 return (diff2 > diff1) ? tickArray[i] : tickArray[next];
1146 // The value is larger than the last tick, so we return the last
1148 return tickArray[tickArray.length - 1];
1155 * @return {string} string representation of the dd obj
1157 toString: function() {
1158 return ("DragDrop " + this.id);
1166 * Ext JS Library 1.1.1
1167 * Copyright(c) 2006-2007, Ext JS, LLC.
1169 * Originally Released Under LGPL - original licence link has changed is not relivant.
1172 * <script type="text/javascript">
1177 * The drag and drop utility provides a framework for building drag and drop
1178 * applications. In addition to enabling drag and drop for specific elements,
1179 * the drag and drop elements are tracked by the manager class, and the
1180 * interactions between the various elements are tracked during the drag and
1181 * the implementing code is notified about these important moments.
1184 // Only load the library once. Rewriting the manager class would orphan
1185 // existing drag and drop instances.
1186 if (!Roo.dd.DragDropMgr) {
1189 * @class Roo.dd.DragDropMgr
1190 * DragDropMgr is a singleton that tracks the element interaction for
1191 * all DragDrop items in the window. Generally, you will not call
1192 * this class directly, but it does have helper methods that could
1193 * be useful in your DragDrop implementations.
1196 Roo.dd.DragDropMgr = function() {
1198 var Event = Roo.EventManager;
1203 * Two dimensional Array of registered DragDrop objects. The first
1204 * dimension is the DragDrop item group, the second the DragDrop
1207 * @type {string: string}
1214 * Array of element ids defined as drag handles. Used to determine
1215 * if the element that generated the mousedown event is actually the
1216 * handle and not the html element itself.
1217 * @property handleIds
1218 * @type {string: string}
1225 * the DragDrop object that is currently being dragged
1226 * @property dragCurrent
1234 * the DragDrop object(s) that are being hovered over
1235 * @property dragOvers
1243 * the X distance between the cursor and the object being dragged
1252 * the Y distance between the cursor and the object being dragged
1261 * Flag to determine if we should prevent the default behavior of the
1262 * events we define. By default this is true, but this can be set to
1263 * false if you need the default behavior (not recommended)
1264 * @property preventDefault
1268 preventDefault: true,
1271 * Flag to determine if we should stop the propagation of the events
1272 * we generate. This is true by default but you may want to set it to
1273 * false if the html element contains other features that require the
1275 * @property stopPropagation
1279 stopPropagation: true,
1282 * Internal flag that is set to true when drag and drop has been
1284 * @property initialized
1291 * All drag and drop can be disabled.
1299 * Called the first time an element is registered.
1305 this.initialized = true;
1309 * In point mode, drag and drop interaction is defined by the
1310 * location of the cursor during the drag/drop
1318 * In intersect mode, drag and drop interactio nis defined by the
1319 * overlap of two or more drag and drop objects.
1320 * @property INTERSECT
1327 * The current drag and drop mode. Default: POINT
1335 * Runs method on all drag and drop objects
1336 * @method _execOnAll
1340 _execOnAll: function(sMethod, args) {
1341 for (var i in this.ids) {
1342 for (var j in this.ids[i]) {
1343 var oDD = this.ids[i][j];
1344 if (! this.isTypeOfDD(oDD)) {
1347 oDD[sMethod].apply(oDD, args);
1353 * Drag and drop initialization. Sets up the global event handlers
1358 _onLoad: function() {
1363 Event.on(document, "mouseup", this.handleMouseUp, this, true);
1364 Event.on(document, "mousemove", this.handleMouseMove, this, true);
1365 Event.on(window, "unload", this._onUnload, this, true);
1366 Event.on(window, "resize", this._onResize, this, true);
1367 // Event.on(window, "mouseout", this._test);
1372 * Reset constraints on all drag and drop objs
1377 _onResize: function(e) {
1378 this._execOnAll("resetConstraints", []);
1382 * Lock all drag and drop functionality
1386 lock: function() { this.locked = true; },
1389 * Unlock all drag and drop functionality
1393 unlock: function() { this.locked = false; },
1396 * Is drag and drop locked?
1398 * @return {boolean} True if drag and drop is locked, false otherwise.
1401 isLocked: function() { return this.locked; },
1404 * Location cache that is set for all drag drop objects when a drag is
1405 * initiated, cleared when the drag is finished.
1406 * @property locationCache
1413 * Set useCache to false if you want to force object the lookup of each
1414 * drag and drop linked element constantly during a drag.
1415 * @property useCache
1422 * The number of pixels that the mouse needs to move after the
1423 * mousedown before the drag is initiated. Default=3;
1424 * @property clickPixelThresh
1428 clickPixelThresh: 3,
1431 * The number of milliseconds after the mousedown event to initiate the
1432 * drag if we don't get a mouseup event. Default=1000
1433 * @property clickTimeThresh
1437 clickTimeThresh: 350,
1440 * Flag that indicates that either the drag pixel threshold or the
1441 * mousdown time threshold has been met
1442 * @property dragThreshMet
1447 dragThreshMet: false,
1450 * Timeout used for the click time threshold
1451 * @property clickTimeout
1459 * The X position of the mousedown event stored for later use when a
1460 * drag threshold is met.
1469 * The Y position of the mousedown event stored for later use when a
1470 * drag threshold is met.
1479 * Each DragDrop instance must be registered with the DragDropMgr.
1480 * This is executed in DragDrop.init()
1481 * @method regDragDrop
1482 * @param {DragDrop} oDD the DragDrop object to register
1483 * @param {String} sGroup the name of the group this element belongs to
1486 regDragDrop: function(oDD, sGroup) {
1487 if (!this.initialized) { this.init(); }
1489 if (!this.ids[sGroup]) {
1490 this.ids[sGroup] = {};
1492 this.ids[sGroup][oDD.id] = oDD;
1496 * Removes the supplied dd instance from the supplied group. Executed
1497 * by DragDrop.removeFromGroup, so don't call this function directly.
1498 * @method removeDDFromGroup
1502 removeDDFromGroup: function(oDD, sGroup) {
1503 if (!this.ids[sGroup]) {
1504 this.ids[sGroup] = {};
1507 var obj = this.ids[sGroup];
1508 if (obj && obj[oDD.id]) {
1514 * Unregisters a drag and drop item. This is executed in
1515 * DragDrop.unreg, use that method instead of calling this directly.
1520 _remove: function(oDD) {
1521 for (var g in oDD.groups) {
1522 if (g && this.ids[g][oDD.id]) {
1523 delete this.ids[g][oDD.id];
1526 delete this.handleIds[oDD.id];
1530 * Each DragDrop handle element must be registered. This is done
1531 * automatically when executing DragDrop.setHandleElId()
1533 * @param {String} sDDId the DragDrop id this element is a handle for
1534 * @param {String} sHandleId the id of the element that is the drag
1538 regHandle: function(sDDId, sHandleId) {
1539 if (!this.handleIds[sDDId]) {
1540 this.handleIds[sDDId] = {};
1542 this.handleIds[sDDId][sHandleId] = sHandleId;
1546 * Utility function to determine if a given element has been
1547 * registered as a drag drop item.
1548 * @method isDragDrop
1549 * @param {String} id the element id to check
1550 * @return {boolean} true if this element is a DragDrop item,
1554 isDragDrop: function(id) {
1555 return ( this.getDDById(id) ) ? true : false;
1559 * Returns the drag and drop instances that are in all groups the
1560 * passed in instance belongs to.
1561 * @method getRelated
1562 * @param {DragDrop} p_oDD the obj to get related data for
1563 * @param {boolean} bTargetsOnly if true, only return targetable objs
1564 * @return {DragDrop[]} the related instances
1567 getRelated: function(p_oDD, bTargetsOnly) {
1569 for (var i in p_oDD.groups) {
1570 for (j in this.ids[i]) {
1571 var dd = this.ids[i][j];
1572 if (! this.isTypeOfDD(dd)) {
1575 if (!bTargetsOnly || dd.isTarget) {
1576 oDDs[oDDs.length] = dd;
1585 * Returns true if the specified dd target is a legal target for
1586 * the specifice drag obj
1587 * @method isLegalTarget
1588 * @param {DragDrop} the drag obj
1589 * @param {DragDrop} the target
1590 * @return {boolean} true if the target is a legal target for the
1594 isLegalTarget: function (oDD, oTargetDD) {
1595 var targets = this.getRelated(oDD, true);
1596 for (var i=0, len=targets.length;i<len;++i) {
1597 if (targets[i].id == oTargetDD.id) {
1606 * My goal is to be able to transparently determine if an object is
1607 * typeof DragDrop, and the exact subclass of DragDrop. typeof
1608 * returns "object", oDD.constructor.toString() always returns
1609 * "DragDrop" and not the name of the subclass. So for now it just
1610 * evaluates a well-known variable in DragDrop.
1611 * @method isTypeOfDD
1612 * @param {Object} the object to evaluate
1613 * @return {boolean} true if typeof oDD = DragDrop
1616 isTypeOfDD: function (oDD) {
1617 return (oDD && oDD.__ygDragDrop);
1621 * Utility function to determine if a given element has been
1622 * registered as a drag drop handle for the given Drag Drop object.
1624 * @param {String} id the element id to check
1625 * @return {boolean} true if this element is a DragDrop handle, false
1629 isHandle: function(sDDId, sHandleId) {
1630 return ( this.handleIds[sDDId] &&
1631 this.handleIds[sDDId][sHandleId] );
1635 * Returns the DragDrop instance for a given id
1637 * @param {String} id the id of the DragDrop object
1638 * @return {DragDrop} the drag drop object, null if it is not found
1641 getDDById: function(id) {
1642 for (var i in this.ids) {
1643 if (this.ids[i][id]) {
1644 return this.ids[i][id];
1651 * Fired after a registered DragDrop object gets the mousedown event.
1652 * Sets up the events required to track the object being dragged
1653 * @method handleMouseDown
1654 * @param {Event} e the event
1655 * @param oDD the DragDrop object being dragged
1659 handleMouseDown: function(e, oDD) {
1661 Roo.QuickTips.disable();
1663 this.currentTarget = e.getTarget();
1665 this.dragCurrent = oDD;
1667 var el = oDD.getEl();
1669 // track start position
1670 this.startX = e.getPageX();
1671 this.startY = e.getPageY();
1673 this.deltaX = this.startX - el.offsetLeft;
1674 this.deltaY = this.startY - el.offsetTop;
1676 this.dragThreshMet = false;
1678 this.clickTimeout = setTimeout(
1680 var DDM = Roo.dd.DDM;
1681 DDM.startDrag(DDM.startX, DDM.startY);
1683 this.clickTimeThresh );
1687 * Fired when either the drag pixel threshol or the mousedown hold
1688 * time threshold has been met.
1690 * @param x {int} the X position of the original mousedown
1691 * @param y {int} the Y position of the original mousedown
1694 startDrag: function(x, y) {
1695 clearTimeout(this.clickTimeout);
1696 if (this.dragCurrent) {
1697 this.dragCurrent.b4StartDrag(x, y);
1698 this.dragCurrent.startDrag(x, y);
1700 this.dragThreshMet = true;
1704 * Internal function to handle the mouseup event. Will be invoked
1705 * from the context of the document.
1706 * @method handleMouseUp
1707 * @param {Event} e the event
1711 handleMouseUp: function(e) {
1714 Roo.QuickTips.enable();
1716 if (! this.dragCurrent) {
1720 clearTimeout(this.clickTimeout);
1722 if (this.dragThreshMet) {
1723 this.fireEvents(e, true);
1733 * Utility to stop event propagation and event default, if these
1734 * features are turned on.
1736 * @param {Event} e the event as returned by this.getEvent()
1739 stopEvent: function(e){
1740 if(this.stopPropagation) {
1741 e.stopPropagation();
1744 if (this.preventDefault) {
1750 * Internal function to clean up event handlers after the drag
1751 * operation is complete
1753 * @param {Event} e the event
1757 stopDrag: function(e) {
1758 // Fire the drag end event for the item that was dragged
1759 if (this.dragCurrent) {
1760 if (this.dragThreshMet) {
1761 this.dragCurrent.b4EndDrag(e);
1762 this.dragCurrent.endDrag(e);
1765 this.dragCurrent.onMouseUp(e);
1768 this.dragCurrent = null;
1769 this.dragOvers = {};
1773 * Internal function to handle the mousemove event. Will be invoked
1774 * from the context of the html element.
1776 * @TODO figure out what we can do about mouse events lost when the
1777 * user drags objects beyond the window boundary. Currently we can
1778 * detect this in internet explorer by verifying that the mouse is
1779 * down during the mousemove event. Firefox doesn't give us the
1780 * button state on the mousemove event.
1781 * @method handleMouseMove
1782 * @param {Event} e the event
1786 handleMouseMove: function(e) {
1787 if (! this.dragCurrent) {
1791 // var button = e.which || e.button;
1793 // check for IE mouseup outside of page boundary
1794 if (Roo.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
1796 return this.handleMouseUp(e);
1799 if (!this.dragThreshMet) {
1800 var diffX = Math.abs(this.startX - e.getPageX());
1801 var diffY = Math.abs(this.startY - e.getPageY());
1802 if (diffX > this.clickPixelThresh ||
1803 diffY > this.clickPixelThresh) {
1804 this.startDrag(this.startX, this.startY);
1808 if (this.dragThreshMet) {
1809 this.dragCurrent.b4Drag(e);
1810 this.dragCurrent.onDrag(e);
1811 if(!this.dragCurrent.moveOnly){
1812 this.fireEvents(e, false);
1822 * Iterates over all of the DragDrop elements to find ones we are
1823 * hovering over or dropping on
1824 * @method fireEvents
1825 * @param {Event} e the event
1826 * @param {boolean} isDrop is this a drop op or a mouseover op?
1830 fireEvents: function(e, isDrop) {
1831 var dc = this.dragCurrent;
1833 // If the user did the mouse up outside of the window, we could
1834 // get here even though we have ended the drag.
1835 if (!dc || dc.isLocked()) {
1839 var pt = e.getPoint();
1841 // cache the previous dragOver array
1849 // Check to see if the object(s) we were hovering over is no longer
1850 // being hovered over so we can fire the onDragOut event
1851 for (var i in this.dragOvers) {
1853 var ddo = this.dragOvers[i];
1855 if (! this.isTypeOfDD(ddo)) {
1859 if (! this.isOverTarget(pt, ddo, this.mode)) {
1860 outEvts.push( ddo );
1864 delete this.dragOvers[i];
1867 for (var sGroup in dc.groups) {
1869 if ("string" != typeof sGroup) {
1873 for (i in this.ids[sGroup]) {
1874 var oDD = this.ids[sGroup][i];
1875 if (! this.isTypeOfDD(oDD)) {
1879 if (oDD.isTarget && !oDD.isLocked() && oDD != dc) {
1880 if (this.isOverTarget(pt, oDD, this.mode)) {
1881 // look for drop interactions
1883 dropEvts.push( oDD );
1884 // look for drag enter and drag over interactions
1887 // initial drag over: dragEnter fires
1888 if (!oldOvers[oDD.id]) {
1889 enterEvts.push( oDD );
1890 // subsequent drag overs: dragOver fires
1892 overEvts.push( oDD );
1895 this.dragOvers[oDD.id] = oDD;
1903 if (outEvts.length) {
1904 dc.b4DragOut(e, outEvts);
1905 dc.onDragOut(e, outEvts);
1908 if (enterEvts.length) {
1909 dc.onDragEnter(e, enterEvts);
1912 if (overEvts.length) {
1913 dc.b4DragOver(e, overEvts);
1914 dc.onDragOver(e, overEvts);
1917 if (dropEvts.length) {
1918 dc.b4DragDrop(e, dropEvts);
1919 dc.onDragDrop(e, dropEvts);
1923 // fire dragout events
1925 for (i=0, len=outEvts.length; i<len; ++i) {
1926 dc.b4DragOut(e, outEvts[i].id);
1927 dc.onDragOut(e, outEvts[i].id);
1930 // fire enter events
1931 for (i=0,len=enterEvts.length; i<len; ++i) {
1932 // dc.b4DragEnter(e, oDD.id);
1933 dc.onDragEnter(e, enterEvts[i].id);
1937 for (i=0,len=overEvts.length; i<len; ++i) {
1938 dc.b4DragOver(e, overEvts[i].id);
1939 dc.onDragOver(e, overEvts[i].id);
1943 for (i=0, len=dropEvts.length; i<len; ++i) {
1944 dc.b4DragDrop(e, dropEvts[i].id);
1945 dc.onDragDrop(e, dropEvts[i].id);
1950 // notify about a drop that did not find a target
1951 if (isDrop && !dropEvts.length) {
1952 dc.onInvalidDrop(e);
1958 * Helper function for getting the best match from the list of drag
1959 * and drop objects returned by the drag and drop events when we are
1960 * in INTERSECT mode. It returns either the first object that the
1961 * cursor is over, or the object that has the greatest overlap with
1962 * the dragged element.
1963 * @method getBestMatch
1964 * @param {DragDrop[]} dds The array of drag and drop objects
1966 * @return {DragDrop} The best single match
1969 getBestMatch: function(dds) {
1971 // Return null if the input is not what we expect
1972 //if (!dds || !dds.length || dds.length == 0) {
1974 // If there is only one item, it wins
1975 //} else if (dds.length == 1) {
1977 var len = dds.length;
1982 // Loop through the targeted items
1983 for (var i=0; i<len; ++i) {
1985 // If the cursor is over the object, it wins. If the
1986 // cursor is over multiple matches, the first one we come
1988 if (dd.cursorIsOver) {
1991 // Otherwise the object with the most overlap wins
1994 winner.overlap.getArea() < dd.overlap.getArea()) {
2005 * Refreshes the cache of the top-left and bottom-right points of the
2006 * drag and drop objects in the specified group(s). This is in the
2007 * format that is stored in the drag and drop instance, so typical
2010 * Roo.dd.DragDropMgr.refreshCache(ddinstance.groups);
2014 * Roo.dd.DragDropMgr.refreshCache({group1:true, group2:true});
2016 * @TODO this really should be an indexed array. Alternatively this
2017 * method could accept both.
2018 * @method refreshCache
2019 * @param {Object} groups an associative array of groups to refresh
2022 refreshCache: function(groups) {
2023 for (var sGroup in groups) {
2024 if ("string" != typeof sGroup) {
2027 for (var i in this.ids[sGroup]) {
2028 var oDD = this.ids[sGroup][i];
2030 if (this.isTypeOfDD(oDD)) {
2031 // if (this.isTypeOfDD(oDD) && oDD.isTarget) {
2032 var loc = this.getLocation(oDD);
2034 this.locationCache[oDD.id] = loc;
2036 delete this.locationCache[oDD.id];
2037 // this will unregister the drag and drop object if
2038 // the element is not in a usable state
2047 * This checks to make sure an element exists and is in the DOM. The
2048 * main purpose is to handle cases where innerHTML is used to remove
2049 * drag and drop objects from the DOM. IE provides an 'unspecified
2050 * error' when trying to access the offsetParent of such an element
2052 * @param {HTMLElement} el the element to check
2053 * @return {boolean} true if the element looks usable
2056 verifyEl: function(el) {
2061 parent = el.offsetParent;
2064 parent = el.offsetParent;
2075 * Returns a Region object containing the drag and drop element's position
2076 * and size, including the padding configured for it
2077 * @method getLocation
2078 * @param {DragDrop} oDD the drag and drop object to get the
2080 * @return {Roo.lib.Region} a Region object representing the total area
2081 * the element occupies, including any padding
2082 * the instance is configured for.
2085 getLocation: function(oDD) {
2086 if (! this.isTypeOfDD(oDD)) {
2090 var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l;
2093 pos= Roo.lib.Dom.getXY(el);
2101 x2 = x1 + el.offsetWidth;
2103 y2 = y1 + el.offsetHeight;
2105 t = y1 - oDD.padding[0];
2106 r = x2 + oDD.padding[1];
2107 b = y2 + oDD.padding[2];
2108 l = x1 - oDD.padding[3];
2110 return new Roo.lib.Region( t, r, b, l );
2114 * Checks the cursor location to see if it over the target
2115 * @method isOverTarget
2116 * @param {Roo.lib.Point} pt The point to evaluate
2117 * @param {DragDrop} oTarget the DragDrop object we are inspecting
2118 * @return {boolean} true if the mouse is over the target
2122 isOverTarget: function(pt, oTarget, intersect) {
2123 // use cache if available
2124 var loc = this.locationCache[oTarget.id];
2125 if (!loc || !this.useCache) {
2126 loc = this.getLocation(oTarget);
2127 this.locationCache[oTarget.id] = loc;
2135 oTarget.cursorIsOver = loc.contains( pt );
2137 // DragDrop is using this as a sanity check for the initial mousedown
2138 // in this case we are done. In POINT mode, if the drag obj has no
2139 // contraints, we are also done. Otherwise we need to evaluate the
2140 // location of the target as related to the actual location of the
2142 var dc = this.dragCurrent;
2143 if (!dc || !dc.getTargetCoord ||
2144 (!intersect && !dc.constrainX && !dc.constrainY)) {
2145 return oTarget.cursorIsOver;
2148 oTarget.overlap = null;
2150 // Get the current location of the drag element, this is the
2151 // location of the mouse event less the delta that represents
2152 // where the original mousedown happened on the element. We
2153 // need to consider constraints and ticks as well.
2154 var pos = dc.getTargetCoord(pt.x, pt.y);
2156 var el = dc.getDragEl();
2157 var curRegion = new Roo.lib.Region( pos.y,
2158 pos.x + el.offsetWidth,
2159 pos.y + el.offsetHeight,
2162 var overlap = curRegion.intersect(loc);
2165 oTarget.overlap = overlap;
2166 return (intersect) ? true : oTarget.cursorIsOver;
2173 * unload event handler
2178 _onUnload: function(e, me) {
2179 Roo.dd.DragDropMgr.unregAll();
2183 * Cleans up the drag and drop events and objects.
2188 unregAll: function() {
2190 if (this.dragCurrent) {
2192 this.dragCurrent = null;
2195 this._execOnAll("unreg", []);
2197 for (i in this.elementCache) {
2198 delete this.elementCache[i];
2201 this.elementCache = {};
2206 * A cache of DOM elements
2207 * @property elementCache
2214 * Get the wrapper for the DOM element specified
2215 * @method getElWrapper
2216 * @param {String} id the id of the element to get
2217 * @return {Roo.dd.DDM.ElementWrapper} the wrapped element
2219 * @deprecated This wrapper isn't that useful
2222 getElWrapper: function(id) {
2223 var oWrapper = this.elementCache[id];
2224 if (!oWrapper || !oWrapper.el) {
2225 oWrapper = this.elementCache[id] =
2226 new this.ElementWrapper(Roo.getDom(id));
2232 * Returns the actual DOM element
2233 * @method getElement
2234 * @param {String} id the id of the elment to get
2235 * @return {Object} The element
2236 * @deprecated use Roo.getDom instead
2239 getElement: function(id) {
2240 return Roo.getDom(id);
2244 * Returns the style property for the DOM element (i.e.,
2245 * document.getElById(id).style)
2247 * @param {String} id the id of the elment to get
2248 * @return {Object} The style property of the element
2249 * @deprecated use Roo.getDom instead
2252 getCss: function(id) {
2253 var el = Roo.getDom(id);
2254 return (el) ? el.style : null;
2258 * Inner class for cached elements
2259 * @class DragDropMgr.ElementWrapper
2264 ElementWrapper: function(el) {
2269 this.el = el || null;
2274 this.id = this.el && el.id;
2276 * A reference to the style property
2279 this.css = this.el && el.style;
2283 * Returns the X position of an html element
2285 * @param el the element for which to get the position
2286 * @return {int} the X coordinate
2288 * @deprecated use Roo.lib.Dom.getX instead
2291 getPosX: function(el) {
2292 return Roo.lib.Dom.getX(el);
2296 * Returns the Y position of an html element
2298 * @param el the element for which to get the position
2299 * @return {int} the Y coordinate
2300 * @deprecated use Roo.lib.Dom.getY instead
2303 getPosY: function(el) {
2304 return Roo.lib.Dom.getY(el);
2308 * Swap two nodes. In IE, we use the native method, for others we
2309 * emulate the IE behavior
2311 * @param n1 the first node to swap
2312 * @param n2 the other node to swap
2315 swapNode: function(n1, n2) {
2319 var p = n2.parentNode;
2320 var s = n2.nextSibling;
2323 p.insertBefore(n1, n2);
2324 } else if (n2 == n1.nextSibling) {
2325 p.insertBefore(n2, n1);
2327 n1.parentNode.replaceChild(n2, n1);
2328 p.insertBefore(n1, s);
2334 * Returns the current scroll position
2339 getScroll: function () {
2340 var t, l, dde=document.documentElement, db=document.body;
2341 if (dde && (dde.scrollTop || dde.scrollLeft)) {
2350 return { top: t, left: l };
2354 * Returns the specified element style property
2356 * @param {HTMLElement} el the element
2357 * @param {string} styleProp the style property
2358 * @return {string} The value of the style property
2359 * @deprecated use Roo.lib.Dom.getStyle
2362 getStyle: function(el, styleProp) {
2363 return Roo.fly(el).getStyle(styleProp);
2367 * Gets the scrollTop
2368 * @method getScrollTop
2369 * @return {int} the document's scrollTop
2372 getScrollTop: function () { return this.getScroll().top; },
2375 * Gets the scrollLeft
2376 * @method getScrollLeft
2377 * @return {int} the document's scrollTop
2380 getScrollLeft: function () { return this.getScroll().left; },
2383 * Sets the x/y position of an element to the location of the
2386 * @param {HTMLElement} moveEl The element to move
2387 * @param {HTMLElement} targetEl The position reference element
2390 moveToEl: function (moveEl, targetEl) {
2391 var aCoord = Roo.lib.Dom.getXY(targetEl);
2392 Roo.lib.Dom.setXY(moveEl, aCoord);
2396 * Numeric array sort function
2397 * @method numericSort
2400 numericSort: function(a, b) { return (a - b); },
2404 * @property _timeoutCount
2411 * Trying to make the load order less important. Without this we get
2412 * an error if this file is loaded before the Event Utility.
2413 * @method _addListeners
2417 _addListeners: function() {
2418 var DDM = Roo.dd.DDM;
2419 if ( Roo.lib.Event && document ) {
2422 if (DDM._timeoutCount > 2000) {
2424 setTimeout(DDM._addListeners, 10);
2425 if (document && document.body) {
2426 DDM._timeoutCount += 1;
2433 * Recursively searches the immediate parent and all child nodes for
2434 * the handle element in order to determine wheter or not it was
2436 * @method handleWasClicked
2437 * @param node the html element to inspect
2440 handleWasClicked: function(node, id) {
2441 if (this.isHandle(id, node.id)) {
2444 // check to see if this is a text node child of the one we want
2445 var p = node.parentNode;
2448 if (this.isHandle(id, p.id)) {
2463 // shorter alias, save a few bytes
2464 Roo.dd.DDM = Roo.dd.DragDropMgr;
2465 Roo.dd.DDM._addListeners();
2469 * Ext JS Library 1.1.1
2470 * Copyright(c) 2006-2007, Ext JS, LLC.
2472 * Originally Released Under LGPL - original licence link has changed is not relivant.
2475 * <script type="text/javascript">
2480 * A DragDrop implementation where the linked element follows the
2481 * mouse cursor during a drag.
2482 * @extends Roo.dd.DragDrop
2484 * @param {String} id the id of the linked element
2485 * @param {String} sGroup the group of related DragDrop items
2486 * @param {object} config an object containing configurable attributes
2487 * Valid properties for DD:
2490 Roo.dd.DD = function(id, sGroup, config) {
2492 this.init(id, sGroup, config);
2496 Roo.extend(Roo.dd.DD, Roo.dd.DragDrop, {
2499 * When set to true, the utility automatically tries to scroll the browser
2500 * window wehn a drag and drop element is dragged near the viewport boundary.
2508 * Sets the pointer offset to the distance between the linked element's top
2509 * left corner and the location the element was clicked
2510 * @method autoOffset
2511 * @param {int} iPageX the X coordinate of the click
2512 * @param {int} iPageY the Y coordinate of the click
2514 autoOffset: function(iPageX, iPageY) {
2515 var x = iPageX - this.startPageX;
2516 var y = iPageY - this.startPageY;
2517 this.setDelta(x, y);
2521 * Sets the pointer offset. You can call this directly to force the
2522 * offset to be in a particular location (e.g., pass in 0,0 to set it
2523 * to the center of the object)
2525 * @param {int} iDeltaX the distance from the left
2526 * @param {int} iDeltaY the distance from the top
2528 setDelta: function(iDeltaX, iDeltaY) {
2529 this.deltaX = iDeltaX;
2530 this.deltaY = iDeltaY;
2534 * Sets the drag element to the location of the mousedown or click event,
2535 * maintaining the cursor location relative to the location on the element
2536 * that was clicked. Override this if you want to place the element in a
2537 * location other than where the cursor is.
2538 * @method setDragElPos
2539 * @param {int} iPageX the X coordinate of the mousedown or drag event
2540 * @param {int} iPageY the Y coordinate of the mousedown or drag event
2542 setDragElPos: function(iPageX, iPageY) {
2543 // the first time we do this, we are going to check to make sure
2544 // the element has css positioning
2546 var el = this.getDragEl();
2547 this.alignElWithMouse(el, iPageX, iPageY);
2551 * Sets the element to the location of the mousedown or click event,
2552 * maintaining the cursor location relative to the location on the element
2553 * that was clicked. Override this if you want to place the element in a
2554 * location other than where the cursor is.
2555 * @method alignElWithMouse
2556 * @param {HTMLElement} el the element to move
2557 * @param {int} iPageX the X coordinate of the mousedown or drag event
2558 * @param {int} iPageY the Y coordinate of the mousedown or drag event
2560 alignElWithMouse: function(el, iPageX, iPageY) {
2561 var oCoord = this.getTargetCoord(iPageX, iPageY);
2562 var fly = el.dom ? el : Roo.fly(el);
2563 if (!this.deltaSetXY) {
2564 var aCoord = [oCoord.x, oCoord.y];
2566 var newLeft = fly.getLeft(true);
2567 var newTop = fly.getTop(true);
2568 this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
2570 fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]);
2573 this.cachePosition(oCoord.x, oCoord.y);
2574 this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
2579 * Saves the most recent position so that we can reset the constraints and
2580 * tick marks on-demand. We need to know this so that we can calculate the
2581 * number of pixels the element is offset from its original position.
2582 * @method cachePosition
2583 * @param iPageX the current x position (optional, this just makes it so we
2584 * don't have to look it up again)
2585 * @param iPageY the current y position (optional, this just makes it so we
2586 * don't have to look it up again)
2588 cachePosition: function(iPageX, iPageY) {
2590 this.lastPageX = iPageX;
2591 this.lastPageY = iPageY;
2593 var aCoord = Roo.lib.Dom.getXY(this.getEl());
2594 this.lastPageX = aCoord[0];
2595 this.lastPageY = aCoord[1];
2600 * Auto-scroll the window if the dragged object has been moved beyond the
2601 * visible window boundary.
2602 * @method autoScroll
2603 * @param {int} x the drag element's x position
2604 * @param {int} y the drag element's y position
2605 * @param {int} h the height of the drag element
2606 * @param {int} w the width of the drag element
2609 autoScroll: function(x, y, h, w) {
2612 // The client height
2613 var clientH = Roo.lib.Dom.getViewWidth();
2616 var clientW = Roo.lib.Dom.getViewHeight();
2618 // The amt scrolled down
2619 var st = this.DDM.getScrollTop();
2621 // The amt scrolled right
2622 var sl = this.DDM.getScrollLeft();
2624 // Location of the bottom of the element
2627 // Location of the right of the element
2630 // The distance from the cursor to the bottom of the visible area,
2631 // adjusted so that we don't scroll if the cursor is beyond the
2632 // element drag constraints
2633 var toBot = (clientH + st - y - this.deltaY);
2635 // The distance from the cursor to the right of the visible area
2636 var toRight = (clientW + sl - x - this.deltaX);
2639 // How close to the edge the cursor must be before we scroll
2640 // var thresh = (document.all) ? 100 : 40;
2643 // How many pixels to scroll per autoscroll op. This helps to reduce
2644 // clunky scrolling. IE is more sensitive about this ... it needs this
2645 // value to be higher.
2646 var scrAmt = (document.all) ? 80 : 30;
2648 // Scroll down if we are near the bottom of the visible page and the
2649 // obj extends below the crease
2650 if ( bot > clientH && toBot < thresh ) {
2651 window.scrollTo(sl, st + scrAmt);
2654 // Scroll up if the window is scrolled down and the top of the object
2655 // goes above the top border
2656 if ( y < st && st > 0 && y - st < thresh ) {
2657 window.scrollTo(sl, st - scrAmt);
2660 // Scroll right if the obj is beyond the right border and the cursor is
2662 if ( right > clientW && toRight < thresh ) {
2663 window.scrollTo(sl + scrAmt, st);
2666 // Scroll left if the window has been scrolled to the right and the obj
2667 // extends past the left border
2668 if ( x < sl && sl > 0 && x - sl < thresh ) {
2669 window.scrollTo(sl - scrAmt, st);
2675 * Finds the location the element should be placed if we want to move
2676 * it to where the mouse location less the click offset would place us.
2677 * @method getTargetCoord
2678 * @param {int} iPageX the X coordinate of the click
2679 * @param {int} iPageY the Y coordinate of the click
2680 * @return an object that contains the coordinates (Object.x and Object.y)
2683 getTargetCoord: function(iPageX, iPageY) {
2686 var x = iPageX - this.deltaX;
2687 var y = iPageY - this.deltaY;
2689 if (this.constrainX) {
2690 if (x < this.minX) { x = this.minX; }
2691 if (x > this.maxX) { x = this.maxX; }
2694 if (this.constrainY) {
2695 if (y < this.minY) { y = this.minY; }
2696 if (y > this.maxY) { y = this.maxY; }
2699 x = this.getTick(x, this.xTicks);
2700 y = this.getTick(y, this.yTicks);
2707 * Sets up config options specific to this class. Overrides
2708 * Roo.dd.DragDrop, but all versions of this method through the
2709 * inheritance chain are called
2711 applyConfig: function() {
2712 Roo.dd.DD.superclass.applyConfig.call(this);
2713 this.scroll = (this.config.scroll !== false);
2717 * Event that fires prior to the onMouseDown event. Overrides
2720 b4MouseDown: function(e) {
2721 // this.resetConstraints();
2722 this.autoOffset(e.getPageX(),
2727 * Event that fires prior to the onDrag event. Overrides
2730 b4Drag: function(e) {
2731 this.setDragElPos(e.getPageX(),
2735 toString: function() {
2736 return ("DD " + this.id);
2739 //////////////////////////////////////////////////////////////////////////
2740 // Debugging ygDragDrop events that can be overridden
2741 //////////////////////////////////////////////////////////////////////////
2743 startDrag: function(x, y) {
2746 onDrag: function(e) {
2749 onDragEnter: function(e, id) {
2752 onDragOver: function(e, id) {
2755 onDragOut: function(e, id) {
2758 onDragDrop: function(e, id) {
2761 endDrag: function(e) {
2768 * Ext JS Library 1.1.1
2769 * Copyright(c) 2006-2007, Ext JS, LLC.
2771 * Originally Released Under LGPL - original licence link has changed is not relivant.
2774 * <script type="text/javascript">
2778 * @class Roo.dd.DDProxy
2779 * A DragDrop implementation that inserts an empty, bordered div into
2780 * the document that follows the cursor during drag operations. At the time of
2781 * the click, the frame div is resized to the dimensions of the linked html
2782 * element, and moved to the exact location of the linked element.
2784 * References to the "frame" element refer to the single proxy element that
2785 * was created to be dragged in place of all DDProxy elements on the
2788 * @extends Roo.dd.DD
2790 * @param {String} id the id of the linked html element
2791 * @param {String} sGroup the group of related DragDrop objects
2792 * @param {object} config an object containing configurable attributes
2793 * Valid properties for DDProxy in addition to those in DragDrop:
2794 * resizeFrame, centerFrame, dragElId
2796 Roo.dd.DDProxy = function(id, sGroup, config) {
2798 this.init(id, sGroup, config);
2804 * The default drag frame div id
2805 * @property Roo.dd.DDProxy.dragElId
2809 Roo.dd.DDProxy.dragElId = "ygddfdiv";
2811 Roo.extend(Roo.dd.DDProxy, Roo.dd.DD, {
2814 * By default we resize the drag frame to be the same size as the element
2815 * we want to drag (this is to get the frame effect). We can turn it off
2816 * if we want a different behavior.
2817 * @property resizeFrame
2823 * By default the frame is positioned exactly where the drag element is, so
2824 * we use the cursor offset provided by Roo.dd.DD. Another option that works only if
2825 * you do not have constraints on the obj is to have the drag frame centered
2826 * around the cursor. Set centerFrame to true for this effect.
2827 * @property centerFrame
2833 * Creates the proxy element if it does not yet exist
2834 * @method createFrame
2836 createFrame: function() {
2838 var body = document.body;
2840 if (!body || !body.firstChild) {
2841 setTimeout( function() { self.createFrame(); }, 50 );
2845 var div = this.getDragEl();
2848 div = document.createElement("div");
2849 div.id = this.dragElId;
2852 s.position = "absolute";
2853 s.visibility = "hidden";
2855 s.border = "2px solid #aaa";
2858 // appendChild can blow up IE if invoked prior to the window load event
2859 // while rendering a table. It is possible there are other scenarios
2860 // that would cause this to happen as well.
2861 body.insertBefore(div, body.firstChild);
2866 * Initialization for the drag frame element. Must be called in the
2867 * constructor of all subclasses
2870 initFrame: function() {
2874 applyConfig: function() {
2875 Roo.dd.DDProxy.superclass.applyConfig.call(this);
2877 this.resizeFrame = (this.config.resizeFrame !== false);
2878 this.centerFrame = (this.config.centerFrame);
2879 this.setDragElId(this.config.dragElId || Roo.dd.DDProxy.dragElId);
2883 * Resizes the drag frame to the dimensions of the clicked object, positions
2884 * it over the object, and finally displays it
2886 * @param {int} iPageX X click position
2887 * @param {int} iPageY Y click position
2890 showFrame: function(iPageX, iPageY) {
2891 var el = this.getEl();
2892 var dragEl = this.getDragEl();
2893 var s = dragEl.style;
2895 this._resizeProxy();
2897 if (this.centerFrame) {
2898 this.setDelta( Math.round(parseInt(s.width, 10)/2),
2899 Math.round(parseInt(s.height, 10)/2) );
2902 this.setDragElPos(iPageX, iPageY);
2904 Roo.fly(dragEl).show();
2908 * The proxy is automatically resized to the dimensions of the linked
2909 * element when a drag is initiated, unless resizeFrame is set to false
2910 * @method _resizeProxy
2913 _resizeProxy: function() {
2914 if (this.resizeFrame) {
2915 var el = this.getEl();
2916 Roo.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
2920 // overrides Roo.dd.DragDrop
2921 b4MouseDown: function(e) {
2922 var x = e.getPageX();
2923 var y = e.getPageY();
2924 this.autoOffset(x, y);
2925 this.setDragElPos(x, y);
2928 // overrides Roo.dd.DragDrop
2929 b4StartDrag: function(x, y) {
2930 // show the drag frame
2931 this.showFrame(x, y);
2934 // overrides Roo.dd.DragDrop
2935 b4EndDrag: function(e) {
2936 Roo.fly(this.getDragEl()).hide();
2939 // overrides Roo.dd.DragDrop
2940 // By default we try to move the element to the last location of the frame.
2941 // This is so that the default behavior mirrors that of Roo.dd.DD.
2942 endDrag: function(e) {
2944 var lel = this.getEl();
2945 var del = this.getDragEl();
2947 // Show the drag frame briefly so we can get its position
2948 del.style.visibility = "";
2951 // Hide the linked element before the move to get around a Safari
2953 lel.style.visibility = "hidden";
2954 Roo.dd.DDM.moveToEl(lel, del);
2955 del.style.visibility = "hidden";
2956 lel.style.visibility = "";
2961 beforeMove : function(){
2965 afterDrag : function(){
2969 toString: function() {
2970 return ("DDProxy " + this.id);
2976 * Ext JS Library 1.1.1
2977 * Copyright(c) 2006-2007, Ext JS, LLC.
2979 * Originally Released Under LGPL - original licence link has changed is not relivant.
2982 * <script type="text/javascript">
2986 * @class Roo.dd.DDTarget
2987 * A DragDrop implementation that does not move, but can be a drop
2988 * target. You would get the same result by simply omitting implementation
2989 * for the event callbacks, but this way we reduce the processing cost of the
2990 * event listener and the callbacks.
2991 * @extends Roo.dd.DragDrop
2993 * @param {String} id the id of the element that is a drop target
2994 * @param {String} sGroup the group of related DragDrop objects
2995 * @param {object} config an object containing configurable attributes
2996 * Valid properties for DDTarget in addition to those in
3000 Roo.dd.DDTarget = function(id, sGroup, config) {
3002 this.initTarget(id, sGroup, config);
3004 if (config.listeners || config.events) {
3005 Roo.dd.DragDrop.superclass.constructor.call(this, {
3006 listeners : config.listeners || {},
3007 events : config.events || {}
3012 // Roo.dd.DDTarget.prototype = new Roo.dd.DragDrop();
3013 Roo.extend(Roo.dd.DDTarget, Roo.dd.DragDrop, {
3014 toString: function() {
3015 return ("DDTarget " + this.id);
3020 * Ext JS Library 1.1.1
3021 * Copyright(c) 2006-2007, Ext JS, LLC.
3023 * Originally Released Under LGPL - original licence link has changed is not relivant.
3026 * <script type="text/javascript">
3031 * @class Roo.dd.ScrollManager
3032 * Provides automatic scrolling of overflow regions in the page during drag operations.<br><br>
3033 * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
3036 Roo.dd.ScrollManager = function(){
3037 var ddm = Roo.dd.DragDropMgr;
3042 var onStop = function(e){
3047 var triggerRefresh = function(){
3048 if(ddm.dragCurrent){
3049 ddm.refreshCache(ddm.dragCurrent.groups);
3053 var doScroll = function(){
3054 if(ddm.dragCurrent){
3055 var dds = Roo.dd.ScrollManager;
3057 if(proc.el.scroll(proc.dir, dds.increment)){
3061 proc.el.scroll(proc.dir, dds.increment, true, dds.animDuration, triggerRefresh);
3066 var clearProc = function(){
3068 clearInterval(proc.id);
3075 var startProc = function(el, dir){
3079 proc.id = setInterval(doScroll, Roo.dd.ScrollManager.frequency);
3082 var onFire = function(e, isDrop){
3083 if(isDrop || !ddm.dragCurrent){ return; }
3084 var dds = Roo.dd.ScrollManager;
3085 if(!dragEl || dragEl != ddm.dragCurrent){
3086 dragEl = ddm.dragCurrent;
3087 // refresh regions on drag start
3091 var xy = Roo.lib.Event.getXY(e);
3092 var pt = new Roo.lib.Point(xy[0], xy[1]);
3094 var el = els[id], r = el._region;
3095 if(r && r.contains(pt) && el.isScrollable()){
3096 if(r.bottom - pt.y <= dds.thresh){
3098 startProc(el, "down");
3101 }else if(r.right - pt.x <= dds.thresh){
3103 startProc(el, "left");
3106 }else if(pt.y - r.top <= dds.thresh){
3108 startProc(el, "up");
3111 }else if(pt.x - r.left <= dds.thresh){
3113 startProc(el, "right");
3122 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
3123 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
3127 * Registers new overflow element(s) to auto scroll
3128 * @param {String/HTMLElement/Element/Array} el The id of or the element to be scrolled or an array of either
3130 register : function(el){
3131 if(el instanceof Array){
3132 for(var i = 0, len = el.length; i < len; i++) {
3133 this.register(el[i]);
3142 * Unregisters overflow element(s) so they are no longer scrolled
3143 * @param {String/HTMLElement/Element/Array} el The id of or the element to be removed or an array of either
3145 unregister : function(el){
3146 if(el instanceof Array){
3147 for(var i = 0, len = el.length; i < len; i++) {
3148 this.unregister(el[i]);
3157 * The number of pixels from the edge of a container the pointer needs to be to
3158 * trigger scrolling (defaults to 25)
3164 * The number of pixels to scroll in each scroll increment (defaults to 50)
3170 * The frequency of scrolls in milliseconds (defaults to 500)
3176 * True to animate the scroll (defaults to true)
3182 * The animation duration in seconds -
3183 * MUST BE less than Roo.dd.ScrollManager.frequency! (defaults to .4)
3189 * Manually trigger a cache refresh.
3191 refreshCache : function(){
3193 if(typeof els[id] == 'object'){ // for people extending the object prototype
3194 els[id]._region = els[id].getRegion();
3201 * Ext JS Library 1.1.1
3202 * Copyright(c) 2006-2007, Ext JS, LLC.
3204 * Originally Released Under LGPL - original licence link has changed is not relivant.
3207 * <script type="text/javascript">
3212 * @class Roo.dd.Registry
3213 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
3214 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
3217 Roo.dd.Registry = function(){
3222 var getId = function(el, autogen){
3223 if(typeof el == "string"){
3227 if(!id && autogen !== false){
3228 id = "roodd-" + (++autoIdSeed);
3236 * Register a drag drop element
3237 * @param {String|HTMLElement} element The id or DOM node to register
3238 * @param {Object} data (optional) A custom data object that will be passed between the elements that are involved
3239 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
3240 * knows how to interpret, plus there are some specific properties known to the Registry that should be
3241 * populated in the data object (if applicable):
3243 Value Description<br />
3244 --------- ------------------------------------------<br />
3245 handles Array of DOM nodes that trigger dragging<br />
3246 for the element being registered<br />
3247 isHandle True if the element passed in triggers<br />
3248 dragging itself, else false
3251 register : function(el, data){
3253 if(typeof el == "string"){
3254 el = document.getElementById(el);
3257 elements[getId(el)] = data;
3258 if(data.isHandle !== false){
3259 handles[data.ddel.id] = data;
3262 var hs = data.handles;
3263 for(var i = 0, len = hs.length; i < len; i++){
3264 handles[getId(hs[i])] = data;
3270 * Unregister a drag drop element
3271 * @param {String|HTMLElement} element The id or DOM node to unregister
3273 unregister : function(el){
3274 var id = getId(el, false);
3275 var data = elements[id];
3277 delete elements[id];
3279 var hs = data.handles;
3280 for(var i = 0, len = hs.length; i < len; i++){
3281 delete handles[getId(hs[i], false)];
3288 * Returns the handle registered for a DOM Node by id
3289 * @param {String|HTMLElement} id The DOM node or id to look up
3290 * @return {Object} handle The custom handle data
3292 getHandle : function(id){
3293 if(typeof id != "string"){ // must be element?
3300 * Returns the handle that is registered for the DOM node that is the target of the event
3301 * @param {Event} e The event
3302 * @return {Object} handle The custom handle data
3304 getHandleFromEvent : function(e){
3305 var t = Roo.lib.Event.getTarget(e);
3306 return t ? handles[t.id] : null;
3310 * Returns a custom data object that is registered for a DOM node by id
3311 * @param {String|HTMLElement} id The DOM node or id to look up
3312 * @return {Object} data The custom data
3314 getTarget : function(id){
3315 if(typeof id != "string"){ // must be element?
3318 return elements[id];
3322 * Returns a custom data object that is registered for the DOM node that is the target of the event
3323 * @param {Event} e The event
3324 * @return {Object} data The custom data
3326 getTargetFromEvent : function(e){
3327 var t = Roo.lib.Event.getTarget(e);
3328 return t ? elements[t.id] || handles[t.id] : null;
3333 * Ext JS Library 1.1.1
3334 * Copyright(c) 2006-2007, Ext JS, LLC.
3336 * Originally Released Under LGPL - original licence link has changed is not relivant.
3339 * <script type="text/javascript">
3344 * @class Roo.dd.StatusProxy
3345 * A specialized drag proxy that supports a drop status icon, {@link Roo.Layer} styles and auto-repair. This is the
3346 * default drag proxy used by all Roo.dd components.
3348 * @param {Object} config
3350 Roo.dd.StatusProxy = function(config){
3351 Roo.apply(this, config);
3352 this.id = this.id || Roo.id();
3353 this.el = new Roo.Layer({
3355 id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
3356 {tag: "div", cls: "x-dd-drop-icon"},
3357 {tag: "div", cls: "x-dd-drag-ghost"}
3360 shadow: !config || config.shadow !== false
3362 this.ghost = Roo.get(this.el.dom.childNodes[1]);
3363 this.dropStatus = this.dropNotAllowed;
3366 Roo.dd.StatusProxy.prototype = {
3368 * @cfg {String} dropAllowed
3369 * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").
3371 dropAllowed : "x-dd-drop-ok",
3373 * @cfg {String} dropNotAllowed
3374 * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").
3376 dropNotAllowed : "x-dd-drop-nodrop",
3379 * Updates the proxy's visual element to indicate the status of whether or not drop is allowed
3380 * over the current target element.
3381 * @param {String} cssClass The css class for the new drop status indicator image
3383 setStatus : function(cssClass){
3384 cssClass = cssClass || this.dropNotAllowed;
3385 if(this.dropStatus != cssClass){
3386 this.el.replaceClass(this.dropStatus, cssClass);
3387 this.dropStatus = cssClass;
3392 * Resets the status indicator to the default dropNotAllowed value
3393 * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
3395 reset : function(clearGhost){
3396 this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
3397 this.dropStatus = this.dropNotAllowed;
3399 this.ghost.update("");
3404 * Updates the contents of the ghost element
3405 * @param {String} html The html that will replace the current innerHTML of the ghost element
3407 update : function(html){
3408 if(typeof html == "string"){
3409 this.ghost.update(html);
3411 this.ghost.update("");
3412 html.style.margin = "0";
3413 this.ghost.dom.appendChild(html);
3415 // ensure float = none set?? cant remember why though.
3416 var el = this.ghost.dom.firstChild;
3418 Roo.fly(el).setStyle('float', 'none');
3423 * Returns the underlying proxy {@link Roo.Layer}
3424 * @return {Roo.Layer} el
3431 * Returns the ghost element
3432 * @return {Roo.Element} el
3434 getGhost : function(){
3440 * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them
3442 hide : function(clear){
3450 * Stops the repair animation if it's currently running
3453 if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){
3459 * Displays this proxy
3466 * Force the Layer to sync its shadow and shim positions to the element
3473 * Causes the proxy to return to its position of origin via an animation. Should be called after an
3474 * invalid drop operation by the item being dragged.
3475 * @param {Array} xy The XY position of the element ([x, y])
3476 * @param {Function} callback The function to call after the repair is complete
3477 * @param {Object} scope The scope in which to execute the callback
3479 repair : function(xy, callback, scope){
3480 this.callback = callback;
3482 if(xy && this.animRepair !== false){
3483 this.el.addClass("x-dd-drag-repair");
3484 this.el.hideUnders(true);
3485 this.anim = this.el.shift({
3486 duration: this.repairDuration || .5,
3490 callback: this.afterRepair,
3499 afterRepair : function(){
3501 if(typeof this.callback == "function"){
3502 this.callback.call(this.scope || this);
3504 this.callback = null;
3509 * Ext JS Library 1.1.1
3510 * Copyright(c) 2006-2007, Ext JS, LLC.
3512 * Originally Released Under LGPL - original licence link has changed is not relivant.
3515 * <script type="text/javascript">
3519 * @class Roo.dd.DragSource
3520 * @extends Roo.dd.DDProxy
3521 * A simple class that provides the basic implementation needed to make any element draggable.
3523 * @param {String/HTMLElement/Element} el The container element
3524 * @param {Object} config
3526 Roo.dd.DragSource = function(el, config){
3527 this.el = Roo.get(el);
3530 Roo.apply(this, config);
3533 this.proxy = new Roo.dd.StatusProxy();
3536 Roo.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
3537 {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
3539 this.dragging = false;
3542 Roo.extend(Roo.dd.DragSource, Roo.dd.DDProxy, {
3544 * @cfg {String} dropAllowed
3545 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
3547 dropAllowed : "x-dd-drop-ok",
3549 * @cfg {String} dropNotAllowed
3550 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
3552 dropNotAllowed : "x-dd-drop-nodrop",
3555 * Returns the data object associated with this drag source
3556 * @return {Object} data An object containing arbitrary data
3558 getDragData : function(e){
3559 return this.dragData;
3563 onDragEnter : function(e, id){
3564 var target = Roo.dd.DragDropMgr.getDDById(id);
3565 this.cachedTarget = target;
3566 if(this.beforeDragEnter(target, e, id) !== false){
3567 if(target.isNotifyTarget){
3568 var status = target.notifyEnter(this, e, this.dragData);
3569 this.proxy.setStatus(status);
3571 this.proxy.setStatus(this.dropAllowed);
3574 if(this.afterDragEnter){
3576 * An empty function by default, but provided so that you can perform a custom action
3577 * when the dragged item enters the drop target by providing an implementation.
3578 * @param {Roo.dd.DragDrop} target The drop target
3579 * @param {Event} e The event object
3580 * @param {String} id The id of the dragged element
3581 * @method afterDragEnter
3583 this.afterDragEnter(target, e, id);
3589 * An empty function by default, but provided so that you can perform a custom action
3590 * before the dragged item enters the drop target and optionally cancel the onDragEnter.
3591 * @param {Roo.dd.DragDrop} target The drop target
3592 * @param {Event} e The event object
3593 * @param {String} id The id of the dragged element
3594 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3596 beforeDragEnter : function(target, e, id){
3601 alignElWithMouse: function() {
3602 Roo.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
3607 onDragOver : function(e, id){
3608 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
3609 if(this.beforeDragOver(target, e, id) !== false){
3610 if(target.isNotifyTarget){
3611 var status = target.notifyOver(this, e, this.dragData);
3612 this.proxy.setStatus(status);
3615 if(this.afterDragOver){
3617 * An empty function by default, but provided so that you can perform a custom action
3618 * while the dragged item is over the drop target by providing an implementation.
3619 * @param {Roo.dd.DragDrop} target The drop target
3620 * @param {Event} e The event object
3621 * @param {String} id The id of the dragged element
3622 * @method afterDragOver
3624 this.afterDragOver(target, e, id);
3630 * An empty function by default, but provided so that you can perform a custom action
3631 * while the dragged item is over the drop target and optionally cancel the onDragOver.
3632 * @param {Roo.dd.DragDrop} target The drop target
3633 * @param {Event} e The event object
3634 * @param {String} id The id of the dragged element
3635 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3637 beforeDragOver : function(target, e, id){
3642 onDragOut : function(e, id){
3643 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
3644 if(this.beforeDragOut(target, e, id) !== false){
3645 if(target.isNotifyTarget){
3646 target.notifyOut(this, e, this.dragData);
3649 if(this.afterDragOut){
3651 * An empty function by default, but provided so that you can perform a custom action
3652 * after the dragged item is dragged out of the target without dropping.
3653 * @param {Roo.dd.DragDrop} target The drop target
3654 * @param {Event} e The event object
3655 * @param {String} id The id of the dragged element
3656 * @method afterDragOut
3658 this.afterDragOut(target, e, id);
3661 this.cachedTarget = null;
3665 * An empty function by default, but provided so that you can perform a custom action before the dragged
3666 * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
3667 * @param {Roo.dd.DragDrop} target The drop target
3668 * @param {Event} e The event object
3669 * @param {String} id The id of the dragged element
3670 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3672 beforeDragOut : function(target, e, id){
3677 onDragDrop : function(e, id){
3678 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
3679 if(this.beforeDragDrop(target, e, id) !== false){
3680 if(target.isNotifyTarget){
3681 if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
3682 this.onValidDrop(target, e, id);
3684 this.onInvalidDrop(target, e, id);
3687 this.onValidDrop(target, e, id);
3690 if(this.afterDragDrop){
3692 * An empty function by default, but provided so that you can perform a custom action
3693 * after a valid drag drop has occurred by providing an implementation.
3694 * @param {Roo.dd.DragDrop} target The drop target
3695 * @param {Event} e The event object
3696 * @param {String} id The id of the dropped element
3697 * @method afterDragDrop
3699 this.afterDragDrop(target, e, id);
3702 delete this.cachedTarget;
3706 * An empty function by default, but provided so that you can perform a custom action before the dragged
3707 * item is dropped onto the target and optionally cancel the onDragDrop.
3708 * @param {Roo.dd.DragDrop} target The drop target
3709 * @param {Event} e The event object
3710 * @param {String} id The id of the dragged element
3711 * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
3713 beforeDragDrop : function(target, e, id){
3718 onValidDrop : function(target, e, id){
3720 if(this.afterValidDrop){
3722 * An empty function by default, but provided so that you can perform a custom action
3723 * after a valid drop has occurred by providing an implementation.
3724 * @param {Object} target The target DD
3725 * @param {Event} e The event object
3726 * @param {String} id The id of the dropped element
3727 * @method afterInvalidDrop
3729 this.afterValidDrop(target, e, id);
3734 getRepairXY : function(e, data){
3735 return this.el.getXY();
3739 onInvalidDrop : function(target, e, id){
3740 this.beforeInvalidDrop(target, e, id);
3741 if(this.cachedTarget){
3742 if(this.cachedTarget.isNotifyTarget){
3743 this.cachedTarget.notifyOut(this, e, this.dragData);
3745 this.cacheTarget = null;
3747 this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
3749 if(this.afterInvalidDrop){
3751 * An empty function by default, but provided so that you can perform a custom action
3752 * after an invalid drop has occurred by providing an implementation.
3753 * @param {Event} e The event object
3754 * @param {String} id The id of the dropped element
3755 * @method afterInvalidDrop
3757 this.afterInvalidDrop(e, id);
3762 afterRepair : function(){
3764 this.el.highlight(this.hlColor || "c3daf9");
3766 this.dragging = false;
3770 * An empty function by default, but provided so that you can perform a custom action after an invalid
3771 * drop has occurred.
3772 * @param {Roo.dd.DragDrop} target The drop target
3773 * @param {Event} e The event object
3774 * @param {String} id The id of the dragged element
3775 * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
3777 beforeInvalidDrop : function(target, e, id){
3782 handleMouseDown : function(e){
3786 var data = this.getDragData(e);
3787 if(data && this.onBeforeDrag(data, e) !== false){
3788 this.dragData = data;
3790 Roo.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
3795 * An empty function by default, but provided so that you can perform a custom action before the initial
3796 * drag event begins and optionally cancel it.
3797 * @param {Object} data An object containing arbitrary data to be shared with drop targets
3798 * @param {Event} e The event object
3799 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3801 onBeforeDrag : function(data, e){
3806 * An empty function by default, but provided so that you can perform a custom action once the initial
3807 * drag event has begun. The drag cannot be canceled from this function.
3808 * @param {Number} x The x position of the click on the dragged object
3809 * @param {Number} y The y position of the click on the dragged object
3811 onStartDrag : Roo.emptyFn,
3813 // private - YUI override
3814 startDrag : function(x, y){
3816 this.dragging = true;
3817 this.proxy.update("");
3818 this.onInitDrag(x, y);
3823 onInitDrag : function(x, y){
3824 var clone = this.el.dom.cloneNode(true);
3825 clone.id = Roo.id(); // prevent duplicate ids
3826 this.proxy.update(clone);
3827 this.onStartDrag(x, y);
3832 * Returns the drag source's underlying {@link Roo.dd.StatusProxy}
3833 * @return {Roo.dd.StatusProxy} proxy The StatusProxy
3835 getProxy : function(){
3840 * Hides the drag source's {@link Roo.dd.StatusProxy}
3842 hideProxy : function(){
3844 this.proxy.reset(true);
3845 this.dragging = false;
3849 triggerCacheRefresh : function(){
3850 Roo.dd.DDM.refreshCache(this.groups);
3853 // private - override to prevent hiding
3854 b4EndDrag: function(e) {
3857 // private - override to prevent moving
3858 endDrag : function(e){
3859 this.onEndDrag(this.dragData, e);
3863 onEndDrag : function(data, e){
3866 // private - pin to cursor
3867 autoOffset : function(x, y) {
3868 this.setDelta(-12, -20);
3872 * Ext JS Library 1.1.1
3873 * Copyright(c) 2006-2007, Ext JS, LLC.
3875 * Originally Released Under LGPL - original licence link has changed is not relivant.
3878 * <script type="text/javascript">
3883 * @class Roo.dd.DropTarget
3884 * @extends Roo.dd.DDTarget
3885 * A simple class that provides the basic implementation needed to make any element a drop target that can have
3886 * draggable items dropped onto it. The drop has no effect until an implementation of notifyDrop is provided.
3888 * @param {String/HTMLElement/Element} el The container element
3889 * @param {Object} config
3891 Roo.dd.DropTarget = function(el, config){
3892 this.el = Roo.get(el);
3894 var listeners = false; ;
3895 if (config && config.listeners) {
3896 listeners= config.listeners;
3897 delete config.listeners;
3899 Roo.apply(this, config);
3901 if(this.containerScroll){
3902 Roo.dd.ScrollManager.register(this.el);
3906 * @scope Roo.dd.DropTarget
3911 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source is now over the
3912 * target. This default implementation adds the CSS class specified by overClass (if any) to the drop element
3913 * and returns the dropAllowed config value. This method should be overridden if drop validation is required.
3915 * IMPORTANT : it should set this.overClass and this.dropAllowed
3917 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3918 * @param {Event} e The event
3919 * @param {Object} data An object containing arbitrary data supplied by the drag source
3925 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the target.
3926 * This method will be called on every mouse movement while the drag source is over the drop target.
3927 * This default implementation simply returns the dropAllowed config value.
3929 * IMPORTANT : it should set this.dropAllowed
3931 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3932 * @param {Event} e The event
3933 * @param {Object} data An object containing arbitrary data supplied by the drag source
3939 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source has been dragged
3940 * out of the target without dropping. This default implementation simply removes the CSS class specified by
3941 * overClass (if any) from the drop element.
3942 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3943 * @param {Event} e The event
3944 * @param {Object} data An object containing arbitrary data supplied by the drag source
3950 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the dragged item has
3951 * been dropped on it. This method has no default implementation and returns false, so you must provide an
3952 * implementation that does something to process the drop event and returns true so that the drag source's
3953 * repair action does not run.
3955 * IMPORTANT : it should set this.success
3957 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3958 * @param {Event} e The event
3959 * @param {Object} data An object containing arbitrary data supplied by the drag source
3965 Roo.dd.DropTarget.superclass.constructor.call( this,
3967 this.ddGroup || this.group,
3970 listeners : listeners || {}
3978 Roo.extend(Roo.dd.DropTarget, Roo.dd.DDTarget, {
3980 * @cfg {String} overClass
3981 * The CSS class applied to the drop target element while the drag source is over it (defaults to "").
3984 * @cfg {String} ddGroup
3985 * The drag drop group to handle drop events for
3989 * @cfg {String} dropAllowed
3990 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
3992 dropAllowed : "x-dd-drop-ok",
3994 * @cfg {String} dropNotAllowed
3995 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
3997 dropNotAllowed : "x-dd-drop-nodrop",
3999 * @cfg {boolean} success
4000 * set this after drop listener..
4004 * @cfg {boolean} valid
4005 * if the drop point is valid for over/enter..
4012 isNotifyTarget : true,
4017 notifyEnter : function(dd, e, data){
4019 this.fireEvent('enter', this, dd, e, data);
4021 this.el.addClass(this.overClass);
4023 return this.valid ? this.dropAllowed : this.dropNotAllowed;
4029 notifyOver : function(dd, e, data){
4031 this.fireEvent('over', this, dd, e, data);
4032 return this.valid ? this.dropAllowed : this.dropNotAllowed;
4038 notifyOut : function(dd, e, data){
4039 this.fireEvent('out', this, dd, e, data);
4041 this.el.removeClass(this.overClass);
4048 notifyDrop : function(dd, e, data){
4049 this.success = false;
4050 this.fireEvent('drop', this, dd, e, data);
4051 return this.success;
4055 * Ext JS Library 1.1.1
4056 * Copyright(c) 2006-2007, Ext JS, LLC.
4058 * Originally Released Under LGPL - original licence link has changed is not relivant.
4061 * <script type="text/javascript">
4066 * @class Roo.dd.DragZone
4067 * @extends Roo.dd.DragSource
4068 * This class provides a container DD instance that proxies for multiple child node sources.<br />
4069 * By default, this class requires that draggable child nodes are registered with {@link Roo.dd.Registry}.
4071 * @param {String/HTMLElement/Element} el The container element
4072 * @param {Object} config
4074 Roo.dd.DragZone = function(el, config){
4075 Roo.dd.DragZone.superclass.constructor.call(this, el, config);
4076 if(this.containerScroll){
4077 Roo.dd.ScrollManager.register(this.el);
4081 Roo.extend(Roo.dd.DragZone, Roo.dd.DragSource, {
4083 * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
4084 * for auto scrolling during drag operations.
4087 * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
4088 * method after a failed drop (defaults to "c3daf9" - light blue)
4092 * Called when a mousedown occurs in this container. Looks in {@link Roo.dd.Registry}
4093 * for a valid target to drag based on the mouse down. Override this method
4094 * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
4095 * object has a "ddel" attribute (with an HTML Element) for other functions to work.
4096 * @param {EventObject} e The mouse down event
4097 * @return {Object} The dragData
4099 getDragData : function(e){
4100 return Roo.dd.Registry.getHandleFromEvent(e);
4104 * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
4105 * this.dragData.ddel
4106 * @param {Number} x The x position of the click on the dragged object
4107 * @param {Number} y The y position of the click on the dragged object
4108 * @return {Boolean} true to continue the drag, false to cancel
4110 onInitDrag : function(x, y){
4111 this.proxy.update(this.dragData.ddel.cloneNode(true));
4112 this.onStartDrag(x, y);
4117 * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
4119 afterRepair : function(){
4121 Roo.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
4123 this.dragging = false;
4127 * Called before a repair of an invalid drop to get the XY to animate to. By default returns
4128 * the XY of this.dragData.ddel
4129 * @param {EventObject} e The mouse up event
4130 * @return {Array} The xy location (e.g. [100, 200])
4132 getRepairXY : function(e){
4133 return Roo.Element.fly(this.dragData.ddel).getXY();
4137 * Ext JS Library 1.1.1
4138 * Copyright(c) 2006-2007, Ext JS, LLC.
4140 * Originally Released Under LGPL - original licence link has changed is not relivant.
4143 * <script type="text/javascript">
4146 * @class Roo.dd.DropZone
4147 * @extends Roo.dd.DropTarget
4148 * This class provides a container DD instance that proxies for multiple child node targets.<br />
4149 * By default, this class requires that child nodes accepting drop are registered with {@link Roo.dd.Registry}.
4151 * @param {String/HTMLElement/Element} el The container element
4152 * @param {Object} config
4154 Roo.dd.DropZone = function(el, config){
4155 Roo.dd.DropZone.superclass.constructor.call(this, el, config);
4158 Roo.extend(Roo.dd.DropZone, Roo.dd.DropTarget, {
4160 * Returns a custom data object associated with the DOM node that is the target of the event. By default
4161 * this looks up the event target in the {@link Roo.dd.Registry}, although you can override this method to
4162 * provide your own custom lookup.
4163 * @param {Event} e The event
4164 * @return {Object} data The custom data
4166 getTargetFromEvent : function(e){
4167 return Roo.dd.Registry.getTargetFromEvent(e);
4171 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has entered a drop node
4172 * that it has registered. This method has no default implementation and should be overridden to provide
4173 * node-specific processing if necessary.
4174 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4175 * {@link #getTargetFromEvent} for this node)
4176 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4177 * @param {Event} e The event
4178 * @param {Object} data An object containing arbitrary data supplied by the drag source
4180 onNodeEnter : function(n, dd, e, data){
4185 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is over a drop node
4186 * that it has registered. The default implementation returns this.dropNotAllowed, so it should be
4187 * overridden to provide the proper feedback.
4188 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4189 * {@link #getTargetFromEvent} for this node)
4190 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4191 * @param {Event} e The event
4192 * @param {Object} data An object containing arbitrary data supplied by the drag source
4193 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4194 * underlying {@link Roo.dd.StatusProxy} can be updated
4196 onNodeOver : function(n, dd, e, data){
4197 return this.dropAllowed;
4201 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dragged out of
4202 * the drop node without dropping. This method has no default implementation and should be overridden to provide
4203 * node-specific processing if necessary.
4204 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4205 * {@link #getTargetFromEvent} for this node)
4206 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4207 * @param {Event} e The event
4208 * @param {Object} data An object containing arbitrary data supplied by the drag source
4210 onNodeOut : function(n, dd, e, data){
4215 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped onto
4216 * the drop node. The default implementation returns false, so it should be overridden to provide the
4217 * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
4218 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4219 * {@link #getTargetFromEvent} for this node)
4220 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4221 * @param {Event} e The event
4222 * @param {Object} data An object containing arbitrary data supplied by the drag source
4223 * @return {Boolean} True if the drop was valid, else false
4225 onNodeDrop : function(n, dd, e, data){
4230 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is being dragged over it,
4231 * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
4232 * it should be overridden to provide the proper feedback if necessary.
4233 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4234 * @param {Event} e The event
4235 * @param {Object} data An object containing arbitrary data supplied by the drag source
4236 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4237 * underlying {@link Roo.dd.StatusProxy} can be updated
4239 onContainerOver : function(dd, e, data){
4240 return this.dropNotAllowed;
4244 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped on it,
4245 * but not on any of its registered drop nodes. The default implementation returns false, so it should be
4246 * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
4247 * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
4248 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4249 * @param {Event} e The event
4250 * @param {Object} data An object containing arbitrary data supplied by the drag source
4251 * @return {Boolean} True if the drop was valid, else false
4253 onContainerDrop : function(dd, e, data){
4258 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source is now over
4259 * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
4260 * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
4261 * you should override this method and provide a custom implementation.
4262 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4263 * @param {Event} e The event
4264 * @param {Object} data An object containing arbitrary data supplied by the drag source
4265 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4266 * underlying {@link Roo.dd.StatusProxy} can be updated
4268 notifyEnter : function(dd, e, data){
4269 return this.dropNotAllowed;
4273 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the drop zone.
4274 * This method will be called on every mouse movement while the drag source is over the drop zone.
4275 * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
4276 * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
4277 * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
4278 * registered node, it will call {@link #onContainerOver}.
4279 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4280 * @param {Event} e The event
4281 * @param {Object} data An object containing arbitrary data supplied by the drag source
4282 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4283 * underlying {@link Roo.dd.StatusProxy} can be updated
4285 notifyOver : function(dd, e, data){
4286 var n = this.getTargetFromEvent(e);
4287 if(!n){ // not over valid drop target
4288 if(this.lastOverNode){
4289 this.onNodeOut(this.lastOverNode, dd, e, data);
4290 this.lastOverNode = null;
4292 return this.onContainerOver(dd, e, data);
4294 if(this.lastOverNode != n){
4295 if(this.lastOverNode){
4296 this.onNodeOut(this.lastOverNode, dd, e, data);
4298 this.onNodeEnter(n, dd, e, data);
4299 this.lastOverNode = n;
4301 return this.onNodeOver(n, dd, e, data);
4305 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source has been dragged
4306 * out of the zone without dropping. If the drag source is currently over a registered node, the notification
4307 * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
4308 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
4309 * @param {Event} e The event
4310 * @param {Object} data An object containing arbitrary data supplied by the drag zone
4312 notifyOut : function(dd, e, data){
4313 if(this.lastOverNode){
4314 this.onNodeOut(this.lastOverNode, dd, e, data);
4315 this.lastOverNode = null;
4320 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the dragged item has
4321 * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
4322 * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
4323 * otherwise it will call {@link #onContainerDrop}.
4324 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4325 * @param {Event} e The event
4326 * @param {Object} data An object containing arbitrary data supplied by the drag source
4327 * @return {Boolean} True if the drop was valid, else false
4329 notifyDrop : function(dd, e, data){
4330 if(this.lastOverNode){
4331 this.onNodeOut(this.lastOverNode, dd, e, data);
4332 this.lastOverNode = null;
4334 var n = this.getTargetFromEvent(e);
4336 this.onNodeDrop(n, dd, e, data) :
4337 this.onContainerDrop(dd, e, data);
4341 triggerCacheRefresh : function(){
4342 Roo.dd.DDM.refreshCache(this.groups);
4346 * Ext JS Library 1.1.1
4347 * Copyright(c) 2006-2007, Ext JS, LLC.
4349 * Originally Released Under LGPL - original licence link has changed is not relivant.
4352 * <script type="text/javascript">
4357 * @class Roo.data.SortTypes
4359 * Defines the default sorting (casting?) comparison functions used when sorting data.
4361 Roo.data.SortTypes = {
4363 * Default sort that does nothing
4364 * @param {Mixed} s The value being converted
4365 * @return {Mixed} The comparison value
4372 * The regular expression used to strip tags
4376 stripTagsRE : /<\/?[^>]+>/gi,
4379 * Strips all HTML tags to sort on text only
4380 * @param {Mixed} s The value being converted
4381 * @return {String} The comparison value
4383 asText : function(s){
4384 return String(s).replace(this.stripTagsRE, "");
4388 * Strips all HTML tags to sort on text only - Case insensitive
4389 * @param {Mixed} s The value being converted
4390 * @return {String} The comparison value
4392 asUCText : function(s){
4393 return String(s).toUpperCase().replace(this.stripTagsRE, "");
4397 * Case insensitive string
4398 * @param {Mixed} s The value being converted
4399 * @return {String} The comparison value
4401 asUCString : function(s) {
4402 return String(s).toUpperCase();
4407 * @param {Mixed} s The value being converted
4408 * @return {Number} The comparison value
4410 asDate : function(s) {
4414 if(s instanceof Date){
4417 return Date.parse(String(s));
4422 * @param {Mixed} s The value being converted
4423 * @return {Float} The comparison value
4425 asFloat : function(s) {
4426 var val = parseFloat(String(s).replace(/,/g, ""));
4427 if(isNaN(val)) val = 0;
4433 * @param {Mixed} s The value being converted
4434 * @return {Number} The comparison value
4436 asInt : function(s) {
4437 var val = parseInt(String(s).replace(/,/g, ""));
4438 if(isNaN(val)) val = 0;
4443 * Ext JS Library 1.1.1
4444 * Copyright(c) 2006-2007, Ext JS, LLC.
4446 * Originally Released Under LGPL - original licence link has changed is not relivant.
4449 * <script type="text/javascript">
4453 * @class Roo.data.Record
4454 * Instances of this class encapsulate both record <em>definition</em> information, and record
4455 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
4456 * to access Records cached in an {@link Roo.data.Store} object.<br>
4458 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
4459 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
4462 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
4464 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
4465 * {@link #create}. The parameters are the same.
4466 * @param {Array} data An associative Array of data values keyed by the field name.
4467 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
4468 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
4469 * not specified an integer id is generated.
4471 Roo.data.Record = function(data, id){
4472 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
4477 * Generate a constructor for a specific record layout.
4478 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
4479 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
4480 * Each field definition object may contain the following properties: <ul>
4481 * <li><b>name</b> : String<p style="margin-left:1em">The name by which the field is referenced within the Record. This is referenced by,
4482 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
4483 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
4484 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
4485 * is being used, then this is a string containing the javascript expression to reference the data relative to
4486 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
4487 * to the data item relative to the record element. If the mapping expression is the same as the field name,
4488 * this may be omitted.</p></li>
4489 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
4490 * <ul><li>auto (Default, implies no conversion)</li>
4495 * <li>date</li></ul></p></li>
4496 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
4497 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
4498 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
4499 * by the Reader into an object that will be stored in the Record. It is passed the
4500 * following parameters:<ul>
4501 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
4503 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
4505 * <br>usage:<br><pre><code>
4506 var TopicRecord = Roo.data.Record.create(
4507 {name: 'title', mapping: 'topic_title'},
4508 {name: 'author', mapping: 'username'},
4509 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
4510 {name: 'lastPost', mapping: 'post_time', type: 'date'},
4511 {name: 'lastPoster', mapping: 'user2'},
4512 {name: 'excerpt', mapping: 'post_text'}
4515 var myNewRecord = new TopicRecord({
4516 title: 'Do my job please',
4519 lastPost: new Date(),
4520 lastPoster: 'Animal',
4521 excerpt: 'No way dude!'
4523 myStore.add(myNewRecord);
4528 Roo.data.Record.create = function(o){
4530 f.superclass.constructor.apply(this, arguments);
4532 Roo.extend(f, Roo.data.Record);
4533 var p = f.prototype;
4534 p.fields = new Roo.util.MixedCollection(false, function(field){
4537 for(var i = 0, len = o.length; i < len; i++){
4538 p.fields.add(new Roo.data.Field(o[i]));
4540 f.getField = function(name){
4541 return p.fields.get(name);
4546 Roo.data.Record.AUTO_ID = 1000;
4547 Roo.data.Record.EDIT = 'edit';
4548 Roo.data.Record.REJECT = 'reject';
4549 Roo.data.Record.COMMIT = 'commit';
4551 Roo.data.Record.prototype = {
4553 * Readonly flag - true if this record has been modified.
4562 join : function(store){
4567 * Set the named field to the specified value.
4568 * @param {String} name The name of the field to set.
4569 * @param {Object} value The value to set the field to.
4571 set : function(name, value){
4572 if(this.data[name] == value){
4579 if(typeof this.modified[name] == 'undefined'){
4580 this.modified[name] = this.data[name];
4582 this.data[name] = value;
4584 this.store.afterEdit(this);
4589 * Get the value of the named field.
4590 * @param {String} name The name of the field to get the value of.
4591 * @return {Object} The value of the field.
4593 get : function(name){
4594 return this.data[name];
4598 beginEdit : function(){
4599 this.editing = true;
4604 cancelEdit : function(){
4605 this.editing = false;
4606 delete this.modified;
4610 endEdit : function(){
4611 this.editing = false;
4612 if(this.dirty && this.store){
4613 this.store.afterEdit(this);
4618 * Usually called by the {@link Roo.data.Store} which owns the Record.
4619 * Rejects all changes made to the Record since either creation, or the last commit operation.
4620 * Modified fields are reverted to their original values.
4622 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
4623 * of reject operations.
4625 reject : function(){
4626 var m = this.modified;
4628 if(typeof m[n] != "function"){
4629 this.data[n] = m[n];
4633 delete this.modified;
4634 this.editing = false;
4636 this.store.afterReject(this);
4641 * Usually called by the {@link Roo.data.Store} which owns the Record.
4642 * Commits all changes made to the Record since either creation, or the last commit operation.
4644 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
4645 * of commit operations.
4647 commit : function(){
4649 delete this.modified;
4650 this.editing = false;
4652 this.store.afterCommit(this);
4657 hasError : function(){
4658 return this.error != null;
4662 clearError : function(){
4667 * Creates a copy of this record.
4668 * @param {String} id (optional) A new record id if you don't want to use this record's id
4671 copy : function(newId) {
4672 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
4676 * Ext JS Library 1.1.1
4677 * Copyright(c) 2006-2007, Ext JS, LLC.
4679 * Originally Released Under LGPL - original licence link has changed is not relivant.
4682 * <script type="text/javascript">
4688 * @class Roo.data.Store
4689 * @extends Roo.util.Observable
4690 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
4691 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
4693 * A Store object uses an implementation of {@link Roo.data.DataProxy} to access a data object unless you call loadData() directly and pass in your data. The Store object
4694 * has no knowledge of the format of the data returned by the Proxy.<br>
4696 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
4697 * instances from the data object. These records are cached and made available through accessor functions.
4699 * Creates a new Store.
4700 * @param {Object} config A config object containing the objects needed for the Store to access data,
4701 * and read the data into Records.
4703 Roo.data.Store = function(config){
4704 this.data = new Roo.util.MixedCollection(false);
4705 this.data.getKey = function(o){
4708 this.baseParams = {};
4717 if(config && config.data){
4718 this.inlineData = config.data;
4722 Roo.apply(this, config);
4724 if(this.reader){ // reader passed
4725 this.reader = Roo.factory(this.reader, Roo.data);
4726 this.reader.xmodule = this.xmodule || false;
4727 if(!this.recordType){
4728 this.recordType = this.reader.recordType;
4730 if(this.reader.onMetaChange){
4731 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
4735 if(this.recordType){
4736 this.fields = this.recordType.prototype.fields;
4742 * @event datachanged
4743 * Fires when the data cache has changed, and a widget which is using this Store
4744 * as a Record cache should refresh its view.
4745 * @param {Store} this
4750 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
4751 * @param {Store} this
4752 * @param {Object} meta The JSON metadata
4757 * Fires when Records have been added to the Store
4758 * @param {Store} this
4759 * @param {Roo.data.Record[]} records The array of Records added
4760 * @param {Number} index The index at which the record(s) were added
4765 * Fires when a Record has been removed from the Store
4766 * @param {Store} this
4767 * @param {Roo.data.Record} record The Record that was removed
4768 * @param {Number} index The index at which the record was removed
4773 * Fires when a Record has been updated
4774 * @param {Store} this
4775 * @param {Roo.data.Record} record The Record that was updated
4776 * @param {String} operation The update operation being performed. Value may be one of:
4778 Roo.data.Record.EDIT
4779 Roo.data.Record.REJECT
4780 Roo.data.Record.COMMIT
4786 * Fires when the data cache has been cleared.
4787 * @param {Store} this
4792 * Fires before a request is made for a new data object. If the beforeload handler returns false
4793 * the load action will be canceled.
4794 * @param {Store} this
4795 * @param {Object} options The loading options that were specified (see {@link #load} for details)
4800 * Fires after a new set of Records has been loaded.
4801 * @param {Store} this
4802 * @param {Roo.data.Record[]} records The Records that were loaded
4803 * @param {Object} options The loading options that were specified (see {@link #load} for details)
4807 * @event loadexception
4808 * Fires if an exception occurs in the Proxy during loading.
4809 * Called with the signature of the Proxy's "loadexception" event.
4810 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
4813 * @param {Object} return from JsonData.reader() - success, totalRecords, records
4814 * @param {Object} load options
4815 * @param {Object} jsonData from your request (normally this contains the Exception)
4817 loadexception : true
4821 this.proxy = Roo.factory(this.proxy, Roo.data);
4822 this.proxy.xmodule = this.xmodule || false;
4823 this.relayEvents(this.proxy, ["loadexception"]);
4825 this.sortToggle = {};
4827 Roo.data.Store.superclass.constructor.call(this);
4829 if(this.inlineData){
4830 this.loadData(this.inlineData);
4831 delete this.inlineData;
4834 Roo.extend(Roo.data.Store, Roo.util.Observable, {
4836 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
4837 * without a remote query - used by combo/forms at present.
4841 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
4844 * @cfg {Array} data Inline data to be loaded when the store is initialized.
4847 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
4848 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
4851 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
4852 * on any HTTP request
4855 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
4858 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
4859 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
4864 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
4865 * loaded or when a record is removed. (defaults to false).
4867 pruneModifiedRecords : false,
4873 * Add Records to the Store and fires the add event.
4874 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
4876 add : function(records){
4877 records = [].concat(records);
4878 for(var i = 0, len = records.length; i < len; i++){
4879 records[i].join(this);
4881 var index = this.data.length;
4882 this.data.addAll(records);
4883 this.fireEvent("add", this, records, index);
4887 * Remove a Record from the Store and fires the remove event.
4888 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
4890 remove : function(record){
4891 var index = this.data.indexOf(record);
4892 this.data.removeAt(index);
4893 if(this.pruneModifiedRecords){
4894 this.modified.remove(record);
4896 this.fireEvent("remove", this, record, index);
4900 * Remove all Records from the Store and fires the clear event.
4902 removeAll : function(){
4904 if(this.pruneModifiedRecords){
4907 this.fireEvent("clear", this);
4911 * Inserts Records to the Store at the given index and fires the add event.
4912 * @param {Number} index The start index at which to insert the passed Records.
4913 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
4915 insert : function(index, records){
4916 records = [].concat(records);
4917 for(var i = 0, len = records.length; i < len; i++){
4918 this.data.insert(index, records[i]);
4919 records[i].join(this);
4921 this.fireEvent("add", this, records, index);
4925 * Get the index within the cache of the passed Record.
4926 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
4927 * @return {Number} The index of the passed Record. Returns -1 if not found.
4929 indexOf : function(record){
4930 return this.data.indexOf(record);
4934 * Get the index within the cache of the Record with the passed id.
4935 * @param {String} id The id of the Record to find.
4936 * @return {Number} The index of the Record. Returns -1 if not found.
4938 indexOfId : function(id){
4939 return this.data.indexOfKey(id);
4943 * Get the Record with the specified id.
4944 * @param {String} id The id of the Record to find.
4945 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
4947 getById : function(id){
4948 return this.data.key(id);
4952 * Get the Record at the specified index.
4953 * @param {Number} index The index of the Record to find.
4954 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
4956 getAt : function(index){
4957 return this.data.itemAt(index);
4961 * Returns a range of Records between specified indices.
4962 * @param {Number} startIndex (optional) The starting index (defaults to 0)
4963 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
4964 * @return {Roo.data.Record[]} An array of Records
4966 getRange : function(start, end){
4967 return this.data.getRange(start, end);
4971 storeOptions : function(o){
4972 o = Roo.apply({}, o);
4975 this.lastOptions = o;
4979 * Loads the Record cache from the configured Proxy using the configured Reader.
4981 * If using remote paging, then the first load call must specify the <em>start</em>
4982 * and <em>limit</em> properties in the options.params property to establish the initial
4983 * position within the dataset, and the number of Records to cache on each read from the Proxy.
4985 * <strong>It is important to note that for remote data sources, loading is asynchronous,
4986 * and this call will return before the new data has been loaded. Perform any post-processing
4987 * in a callback function, or in a "load" event handler.</strong>
4989 * @param {Object} options An object containing properties which control loading options:<ul>
4990 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
4991 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
4992 * passed the following arguments:<ul>
4993 * <li>r : Roo.data.Record[]</li>
4994 * <li>options: Options object from the load call</li>
4995 * <li>success: Boolean success indicator</li></ul></li>
4996 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
4997 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
5000 load : function(options){
5001 options = options || {};
5002 if(this.fireEvent("beforeload", this, options) !== false){
5003 this.storeOptions(options);
5004 var p = Roo.apply(options.params || {}, this.baseParams);
5005 // if meta was not loaded from remote source.. try requesting it.
5006 if (!this.reader.metaFromRemote) {
5009 if(this.sortInfo && this.remoteSort){
5010 var pn = this.paramNames;
5011 p[pn["sort"]] = this.sortInfo.field;
5012 p[pn["dir"]] = this.sortInfo.direction;
5014 this.proxy.load(p, this.reader, this.loadRecords, this, options);
5019 * Reloads the Record cache from the configured Proxy using the configured Reader and
5020 * the options from the last load operation performed.
5021 * @param {Object} options (optional) An object containing properties which may override the options
5022 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
5023 * the most recently used options are reused).
5025 reload : function(options){
5026 this.load(Roo.applyIf(options||{}, this.lastOptions));
5030 // Called as a callback by the Reader during a load operation.
5031 loadRecords : function(o, options, success){
5032 if(!o || success === false){
5033 if(success !== false){
5034 this.fireEvent("load", this, [], options);
5036 if(options.callback){
5037 options.callback.call(options.scope || this, [], options, false);
5041 // if data returned failure - throw an exception.
5042 if (o.success === false) {
5043 this.fireEvent("loadexception", this, o, options, this.reader.jsonData);
5046 var r = o.records, t = o.totalRecords || r.length;
5047 if(!options || options.add !== true){
5048 if(this.pruneModifiedRecords){
5051 for(var i = 0, len = r.length; i < len; i++){
5055 this.data = this.snapshot;
5056 delete this.snapshot;
5059 this.data.addAll(r);
5060 this.totalLength = t;
5062 this.fireEvent("datachanged", this);
5064 this.totalLength = Math.max(t, this.data.length+r.length);
5067 this.fireEvent("load", this, r, options);
5068 if(options.callback){
5069 options.callback.call(options.scope || this, r, options, true);
5074 * Loads data from a passed data block. A Reader which understands the format of the data
5075 * must have been configured in the constructor.
5076 * @param {Object} data The data block from which to read the Records. The format of the data expected
5077 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
5078 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
5080 loadData : function(o, append){
5081 var r = this.reader.readRecords(o);
5082 this.loadRecords(r, {add: append}, true);
5086 * Gets the number of cached records.
5088 * <em>If using paging, this may not be the total size of the dataset. If the data object
5089 * used by the Reader contains the dataset size, then the getTotalCount() function returns
5090 * the data set size</em>
5092 getCount : function(){
5093 return this.data.length || 0;
5097 * Gets the total number of records in the dataset as returned by the server.
5099 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
5100 * the dataset size</em>
5102 getTotalCount : function(){
5103 return this.totalLength || 0;
5107 * Returns the sort state of the Store as an object with two properties:
5109 field {String} The name of the field by which the Records are sorted
5110 direction {String} The sort order, "ASC" or "DESC"
5113 getSortState : function(){
5114 return this.sortInfo;
5118 applySort : function(){
5119 if(this.sortInfo && !this.remoteSort){
5120 var s = this.sortInfo, f = s.field;
5121 var st = this.fields.get(f).sortType;
5122 var fn = function(r1, r2){
5123 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
5124 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
5126 this.data.sort(s.direction, fn);
5127 if(this.snapshot && this.snapshot != this.data){
5128 this.snapshot.sort(s.direction, fn);
5134 * Sets the default sort column and order to be used by the next load operation.
5135 * @param {String} fieldName The name of the field to sort by.
5136 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
5138 setDefaultSort : function(field, dir){
5139 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
5144 * If remote sorting is used, the sort is performed on the server, and the cache is
5145 * reloaded. If local sorting is used, the cache is sorted internally.
5146 * @param {String} fieldName The name of the field to sort by.
5147 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
5149 sort : function(fieldName, dir){
5150 var f = this.fields.get(fieldName);
5152 if(this.sortInfo && this.sortInfo.field == f.name){ // toggle sort dir
5153 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
5158 this.sortToggle[f.name] = dir;
5159 this.sortInfo = {field: f.name, direction: dir};
5160 if(!this.remoteSort){
5162 this.fireEvent("datachanged", this);
5164 this.load(this.lastOptions);
5169 * Calls the specified function for each of the Records in the cache.
5170 * @param {Function} fn The function to call. The Record is passed as the first parameter.
5171 * Returning <em>false</em> aborts and exits the iteration.
5172 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
5174 each : function(fn, scope){
5175 this.data.each(fn, scope);
5179 * Gets all records modified since the last commit. Modified records are persisted across load operations
5180 * (e.g., during paging).
5181 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
5183 getModifiedRecords : function(){
5184 return this.modified;
5188 createFilterFn : function(property, value, anyMatch){
5189 if(!value.exec){ // not a regex
5190 value = String(value);
5191 if(value.length == 0){
5194 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
5197 return value.test(r.data[property]);
5202 * Sums the value of <i>property</i> for each record between start and end and returns the result.
5203 * @param {String} property A field on your records
5204 * @param {Number} start The record index to start at (defaults to 0)
5205 * @param {Number} end The last record index to include (defaults to length - 1)
5206 * @return {Number} The sum
5208 sum : function(property, start, end){
5209 var rs = this.data.items, v = 0;
5211 end = (end || end === 0) ? end : rs.length-1;
5213 for(var i = start; i <= end; i++){
5214 v += (rs[i].data[property] || 0);
5220 * Filter the records by a specified property.
5221 * @param {String} field A field on your records
5222 * @param {String/RegExp} value Either a string that the field
5223 * should start with or a RegExp to test against the field
5224 * @param {Boolean} anyMatch True to match any part not just the beginning
5226 filter : function(property, value, anyMatch){
5227 var fn = this.createFilterFn(property, value, anyMatch);
5228 return fn ? this.filterBy(fn) : this.clearFilter();
5232 * Filter by a function. The specified function will be called with each
5233 * record in this data source. If the function returns true the record is included,
5234 * otherwise it is filtered.
5235 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
5236 * @param {Object} scope (optional) The scope of the function (defaults to this)
5238 filterBy : function(fn, scope){
5239 this.snapshot = this.snapshot || this.data;
5240 this.data = this.queryBy(fn, scope||this);
5241 this.fireEvent("datachanged", this);
5245 * Query the records by a specified property.
5246 * @param {String} field A field on your records
5247 * @param {String/RegExp} value Either a string that the field
5248 * should start with or a RegExp to test against the field
5249 * @param {Boolean} anyMatch True to match any part not just the beginning
5250 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
5252 query : function(property, value, anyMatch){
5253 var fn = this.createFilterFn(property, value, anyMatch);
5254 return fn ? this.queryBy(fn) : this.data.clone();
5258 * Query by a function. The specified function will be called with each
5259 * record in this data source. If the function returns true the record is included
5261 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
5262 * @param {Object} scope (optional) The scope of the function (defaults to this)
5263 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
5265 queryBy : function(fn, scope){
5266 var data = this.snapshot || this.data;
5267 return data.filterBy(fn, scope||this);
5271 * Collects unique values for a particular dataIndex from this store.
5272 * @param {String} dataIndex The property to collect
5273 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
5274 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
5275 * @return {Array} An array of the unique values
5277 collect : function(dataIndex, allowNull, bypassFilter){
5278 var d = (bypassFilter === true && this.snapshot) ?
5279 this.snapshot.items : this.data.items;
5280 var v, sv, r = [], l = {};
5281 for(var i = 0, len = d.length; i < len; i++){
5282 v = d[i].data[dataIndex];
5284 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
5293 * Revert to a view of the Record cache with no filtering applied.
5294 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
5296 clearFilter : function(suppressEvent){
5297 if(this.snapshot && this.snapshot != this.data){
5298 this.data = this.snapshot;
5299 delete this.snapshot;
5300 if(suppressEvent !== true){
5301 this.fireEvent("datachanged", this);
5307 afterEdit : function(record){
5308 if(this.modified.indexOf(record) == -1){
5309 this.modified.push(record);
5311 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
5315 afterReject : function(record){
5316 this.modified.remove(record);
5317 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
5321 afterCommit : function(record){
5322 this.modified.remove(record);
5323 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
5327 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
5328 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
5330 commitChanges : function(){
5331 var m = this.modified.slice(0);
5333 for(var i = 0, len = m.length; i < len; i++){
5339 * Cancel outstanding changes on all changed records.
5341 rejectChanges : function(){
5342 var m = this.modified.slice(0);
5344 for(var i = 0, len = m.length; i < len; i++){
5349 onMetaChange : function(meta, rtype, o){
5350 this.recordType = rtype;
5351 this.fields = rtype.prototype.fields;
5352 delete this.snapshot;
5353 this.sortInfo = meta.sortInfo || this.sortInfo;
5355 this.fireEvent('metachange', this, this.reader.meta);
5359 * Ext JS Library 1.1.1
5360 * Copyright(c) 2006-2007, Ext JS, LLC.
5362 * Originally Released Under LGPL - original licence link has changed is not relivant.
5365 * <script type="text/javascript">
5369 * @class Roo.data.SimpleStore
5370 * @extends Roo.data.Store
5371 * Small helper class to make creating Stores from Array data easier.
5372 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
5373 * @cfg {Array} fields An array of field definition objects, or field name strings.
5374 * @cfg {Array} data The multi-dimensional array of data
5376 * @param {Object} config
5378 Roo.data.SimpleStore = function(config){
5379 Roo.data.SimpleStore.superclass.constructor.call(this, {
5381 reader: new Roo.data.ArrayReader({
5384 Roo.data.Record.create(config.fields)
5386 proxy : new Roo.data.MemoryProxy(config.data)
5390 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
5392 * Ext JS Library 1.1.1
5393 * Copyright(c) 2006-2007, Ext JS, LLC.
5395 * Originally Released Under LGPL - original licence link has changed is not relivant.
5398 * <script type="text/javascript">
5403 * @extends Roo.data.Store
5404 * @class Roo.data.JsonStore
5405 * Small helper class to make creating Stores for JSON data easier. <br/>
5407 var store = new Roo.data.JsonStore({
5408 url: 'get-images.php',
5410 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
5413 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
5414 * JsonReader and HttpProxy (unless inline data is provided).</b>
5415 * @cfg {Array} fields An array of field definition objects, or field name strings.
5417 * @param {Object} config
5419 Roo.data.JsonStore = function(c){
5420 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
5421 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
5422 reader: new Roo.data.JsonReader(c, c.fields)
5425 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
5427 * Ext JS Library 1.1.1
5428 * Copyright(c) 2006-2007, Ext JS, LLC.
5430 * Originally Released Under LGPL - original licence link has changed is not relivant.
5433 * <script type="text/javascript">
5437 Roo.data.Field = function(config){
5438 if(typeof config == "string"){
5439 config = {name: config};
5441 Roo.apply(this, config);
5447 var st = Roo.data.SortTypes;
5448 // named sortTypes are supported, here we look them up
5449 if(typeof this.sortType == "string"){
5450 this.sortType = st[this.sortType];
5453 // set default sortType for strings and dates
5457 this.sortType = st.asUCString;
5460 this.sortType = st.asDate;
5463 this.sortType = st.none;
5468 var stripRe = /[\$,%]/g;
5470 // prebuilt conversion function for this field, instead of
5471 // switching every time we're reading a value
5473 var cv, dateFormat = this.dateFormat;
5478 cv = function(v){ return v; };
5481 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
5485 return v !== undefined && v !== null && v !== '' ?
5486 parseInt(String(v).replace(stripRe, ""), 10) : '';
5491 return v !== undefined && v !== null && v !== '' ?
5492 parseFloat(String(v).replace(stripRe, ""), 10) : '';
5497 cv = function(v){ return v === true || v === "true" || v == 1; };
5504 if(v instanceof Date){
5508 if(dateFormat == "timestamp"){
5509 return new Date(v*1000);
5511 return Date.parseDate(v, dateFormat);
5513 var parsed = Date.parse(v);
5514 return parsed ? new Date(parsed) : null;
5523 Roo.data.Field.prototype = {
5531 * Ext JS Library 1.1.1
5532 * Copyright(c) 2006-2007, Ext JS, LLC.
5534 * Originally Released Under LGPL - original licence link has changed is not relivant.
5537 * <script type="text/javascript">
5540 // Base class for reading structured data from a data source. This class is intended to be
5541 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
5544 * @class Roo.data.DataReader
5545 * Base class for reading structured data from a data source. This class is intended to be
5546 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
5549 Roo.data.DataReader = function(meta, recordType){
5553 this.recordType = recordType instanceof Array ?
5554 Roo.data.Record.create(recordType) : recordType;
5557 Roo.data.DataReader.prototype = {
5559 * Create an empty record
5560 * @param {Object} data (optional) - overlay some values
5561 * @return {Roo.data.Record} record created.
5563 newRow : function(d) {
5565 this.recordType.prototype.fields.each(function(c) {
5567 case 'int' : da[c.name] = 0; break;
5568 case 'date' : da[c.name] = new Date(); break;
5569 case 'float' : da[c.name] = 0.0; break;
5570 case 'boolean' : da[c.name] = false; break;
5571 default : da[c.name] = ""; break;
5575 return new this.recordType(Roo.apply(da, d));
5580 * Ext JS Library 1.1.1
5581 * Copyright(c) 2006-2007, Ext JS, LLC.
5583 * Originally Released Under LGPL - original licence link has changed is not relivant.
5586 * <script type="text/javascript">
5590 * @class Roo.data.DataProxy
5591 * @extends Roo.data.Observable
5592 * This class is an abstract base class for implementations which provide retrieval of
5593 * unformatted data objects.<br>
5595 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
5596 * (of the appropriate type which knows how to parse the data object) to provide a block of
5597 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
5599 * Custom implementations must implement the load method as described in
5600 * {@link Roo.data.HttpProxy#load}.
5602 Roo.data.DataProxy = function(){
5606 * Fires before a network request is made to retrieve a data object.
5607 * @param {Object} This DataProxy object.
5608 * @param {Object} params The params parameter to the load function.
5613 * Fires before the load method's callback is called.
5614 * @param {Object} This DataProxy object.
5615 * @param {Object} o The data object.
5616 * @param {Object} arg The callback argument object passed to the load function.
5620 * @event loadexception
5621 * Fires if an Exception occurs during data retrieval.
5622 * @param {Object} This DataProxy object.
5623 * @param {Object} o The data object.
5624 * @param {Object} arg The callback argument object passed to the load function.
5625 * @param {Object} e The Exception.
5627 loadexception : true
5629 Roo.data.DataProxy.superclass.constructor.call(this);
5632 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
5635 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
5639 * Ext JS Library 1.1.1
5640 * Copyright(c) 2006-2007, Ext JS, LLC.
5642 * Originally Released Under LGPL - original licence link has changed is not relivant.
5645 * <script type="text/javascript">
5648 * @class Roo.data.MemoryProxy
5649 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
5650 * to the Reader when its load method is called.
5652 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
5654 Roo.data.MemoryProxy = function(data){
5658 Roo.data.MemoryProxy.superclass.constructor.call(this);
5662 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
5664 * Load data from the requested source (in this case an in-memory
5665 * data object passed to the constructor), read the data object into
5666 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
5667 * process that block using the passed callback.
5668 * @param {Object} params This parameter is not used by the MemoryProxy class.
5669 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5670 * object into a block of Roo.data.Records.
5671 * @param {Function} callback The function into which to pass the block of Roo.data.records.
5672 * The function must be passed <ul>
5673 * <li>The Record block object</li>
5674 * <li>The "arg" argument from the load function</li>
5675 * <li>A boolean success indicator</li>
5677 * @param {Object} scope The scope in which to call the callback
5678 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5680 load : function(params, reader, callback, scope, arg){
5681 params = params || {};
5684 result = reader.readRecords(this.data);
5686 this.fireEvent("loadexception", this, arg, null, e);
5687 callback.call(scope, null, arg, false);
5690 callback.call(scope, result, arg, true);
5694 update : function(params, records){
5699 * Ext JS Library 1.1.1
5700 * Copyright(c) 2006-2007, Ext JS, LLC.
5702 * Originally Released Under LGPL - original licence link has changed is not relivant.
5705 * <script type="text/javascript">
5708 * @class Roo.data.HttpProxy
5709 * @extends Roo.data.DataProxy
5710 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
5711 * configured to reference a certain URL.<br><br>
5713 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
5714 * from which the running page was served.<br><br>
5716 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
5718 * Be aware that to enable the browser to parse an XML document, the server must set
5719 * the Content-Type header in the HTTP response to "text/xml".
5721 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
5722 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
5723 * will be used to make the request.
5725 Roo.data.HttpProxy = function(conn){
5726 Roo.data.HttpProxy.superclass.constructor.call(this);
5727 // is conn a conn config or a real conn?
5729 this.useAjax = !conn || !conn.events;
5733 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
5734 // thse are take from connection...
5737 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
5740 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
5741 * extra parameters to each request made by this object. (defaults to undefined)
5744 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
5745 * to each request made by this object. (defaults to undefined)
5748 * @cfg {String} method (Optional) The default HTTP method to be used for requests. (defaults to undefined; if not set but parms are present will use POST, otherwise GET)
5751 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
5754 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
5760 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
5764 * Return the {@link Roo.data.Connection} object being used by this Proxy.
5765 * @return {Connection} The Connection object. This object may be used to subscribe to events on
5766 * a finer-grained basis than the DataProxy events.
5768 getConnection : function(){
5769 return this.useAjax ? Roo.Ajax : this.conn;
5773 * Load data from the configured {@link Roo.data.Connection}, read the data object into
5774 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
5775 * process that block using the passed callback.
5776 * @param {Object} params An object containing properties which are to be used as HTTP parameters
5777 * for the request to the remote server.
5778 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5779 * object into a block of Roo.data.Records.
5780 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
5781 * The function must be passed <ul>
5782 * <li>The Record block object</li>
5783 * <li>The "arg" argument from the load function</li>
5784 * <li>A boolean success indicator</li>
5786 * @param {Object} scope The scope in which to call the callback
5787 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5789 load : function(params, reader, callback, scope, arg){
5790 if(this.fireEvent("beforeload", this, params) !== false){
5792 params : params || {},
5794 callback : callback,
5799 callback : this.loadResponse,
5803 Roo.applyIf(o, this.conn);
5804 if(this.activeRequest){
5805 Roo.Ajax.abort(this.activeRequest);
5807 this.activeRequest = Roo.Ajax.request(o);
5809 this.conn.request(o);
5812 callback.call(scope||this, null, arg, false);
5817 loadResponse : function(o, success, response){
5818 delete this.activeRequest;
5820 this.fireEvent("loadexception", this, o, response);
5821 o.request.callback.call(o.request.scope, null, o.request.arg, false);
5826 result = o.reader.read(response);
5828 this.fireEvent("loadexception", this, o, response, e);
5829 o.request.callback.call(o.request.scope, null, o.request.arg, false);
5833 this.fireEvent("load", this, o, o.request.arg);
5834 o.request.callback.call(o.request.scope, result, o.request.arg, true);
5838 update : function(dataSet){
5843 updateResponse : function(dataSet){
5848 * Ext JS Library 1.1.1
5849 * Copyright(c) 2006-2007, Ext JS, LLC.
5851 * Originally Released Under LGPL - original licence link has changed is not relivant.
5854 * <script type="text/javascript">
5858 * @class Roo.data.ScriptTagProxy
5859 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
5860 * other than the originating domain of the running page.<br><br>
5862 * <em>Note that if you are retrieving data from a page that is in a domain that is NOT the same as the originating domain
5863 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
5865 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
5866 * source code that is used as the source inside a <script> tag.<br><br>
5868 * In order for the browser to process the returned data, the server must wrap the data object
5869 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
5870 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
5871 * depending on whether the callback name was passed:
5874 boolean scriptTag = false;
5875 String cb = request.getParameter("callback");
5878 response.setContentType("text/javascript");
5880 response.setContentType("application/x-json");
5882 Writer out = response.getWriter();
5884 out.write(cb + "(");
5886 out.print(dataBlock.toJsonString());
5893 * @param {Object} config A configuration object.
5895 Roo.data.ScriptTagProxy = function(config){
5896 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
5897 Roo.apply(this, config);
5898 this.head = document.getElementsByTagName("head")[0];
5901 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
5903 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
5905 * @cfg {String} url The URL from which to request the data object.
5908 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
5912 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
5913 * the server the name of the callback function set up by the load call to process the returned data object.
5914 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
5915 * javascript output which calls this named function passing the data object as its only parameter.
5917 callbackParam : "callback",
5919 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
5920 * name to the request.
5925 * Load data from the configured URL, read the data object into
5926 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
5927 * process that block using the passed callback.
5928 * @param {Object} params An object containing properties which are to be used as HTTP parameters
5929 * for the request to the remote server.
5930 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5931 * object into a block of Roo.data.Records.
5932 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
5933 * The function must be passed <ul>
5934 * <li>The Record block object</li>
5935 * <li>The "arg" argument from the load function</li>
5936 * <li>A boolean success indicator</li>
5938 * @param {Object} scope The scope in which to call the callback
5939 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5941 load : function(params, reader, callback, scope, arg){
5942 if(this.fireEvent("beforeload", this, params) !== false){
5944 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
5947 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
5949 url += "&_dc=" + (new Date().getTime());
5951 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
5954 cb : "stcCallback"+transId,
5955 scriptId : "stcScript"+transId,
5959 callback : callback,
5965 window[trans.cb] = function(o){
5966 conn.handleResponse(o, trans);
5969 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
5971 if(this.autoAbort !== false){
5975 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
5977 var script = document.createElement("script");
5978 script.setAttribute("src", url);
5979 script.setAttribute("type", "text/javascript");
5980 script.setAttribute("id", trans.scriptId);
5981 this.head.appendChild(script);
5985 callback.call(scope||this, null, arg, false);
5990 isLoading : function(){
5991 return this.trans ? true : false;
5995 * Abort the current server request.
5998 if(this.isLoading()){
5999 this.destroyTrans(this.trans);
6004 destroyTrans : function(trans, isLoaded){
6005 this.head.removeChild(document.getElementById(trans.scriptId));
6006 clearTimeout(trans.timeoutId);
6008 window[trans.cb] = undefined;
6010 delete window[trans.cb];
6013 // if hasn't been loaded, wait for load to remove it to prevent script error
6014 window[trans.cb] = function(){
6015 window[trans.cb] = undefined;
6017 delete window[trans.cb];
6024 handleResponse : function(o, trans){
6026 this.destroyTrans(trans, true);
6029 result = trans.reader.readRecords(o);
6031 this.fireEvent("loadexception", this, o, trans.arg, e);
6032 trans.callback.call(trans.scope||window, null, trans.arg, false);
6035 this.fireEvent("load", this, o, trans.arg);
6036 trans.callback.call(trans.scope||window, result, trans.arg, true);
6040 handleFailure : function(trans){
6042 this.destroyTrans(trans, false);
6043 this.fireEvent("loadexception", this, null, trans.arg);
6044 trans.callback.call(trans.scope||window, null, trans.arg, false);
6048 * Ext JS Library 1.1.1
6049 * Copyright(c) 2006-2007, Ext JS, LLC.
6051 * Originally Released Under LGPL - original licence link has changed is not relivant.
6054 * <script type="text/javascript">
6058 * @class Roo.data.JsonReader
6059 * @extends Roo.data.DataReader
6060 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
6061 * based on mappings in a provided Roo.data.Record constructor.
6063 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
6064 * in the reply previously.
6069 var RecordDef = Roo.data.Record.create([
6070 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
6071 {name: 'occupation'} // This field will use "occupation" as the mapping.
6073 var myReader = new Roo.data.JsonReader({
6074 totalProperty: "results", // The property which contains the total dataset size (optional)
6075 root: "rows", // The property which contains an Array of row objects
6076 id: "id" // The property within each row object that provides an ID for the record (optional)
6080 * This would consume a JSON file like this:
6082 { 'results': 2, 'rows': [
6083 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
6084 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
6087 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
6088 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
6089 * paged from the remote server.
6090 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
6091 * @cfg {String} root name of the property which contains the Array of row objects.
6092 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
6094 * Create a new JsonReader
6095 * @param {Object} meta Metadata configuration options
6096 * @param {Object} recordType Either an Array of field definition objects,
6097 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
6099 Roo.data.JsonReader = function(meta, recordType){
6102 // set some defaults:
6104 totalProperty: 'total',
6105 successProperty : 'success',
6110 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
6112 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
6115 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
6116 * Used by Store query builder to append _requestMeta to params.
6119 metaFromRemote : false,
6121 * This method is only used by a DataProxy which has retrieved data from a remote server.
6122 * @param {Object} response The XHR object which contains the JSON data in its responseText.
6123 * @return {Object} data A data block which is used by an Roo.data.Store object as
6124 * a cache of Roo.data.Records.
6126 read : function(response){
6127 var json = response.responseText;
6129 var o = /* eval:var:o */ eval("("+json+")");
6131 throw {message: "JsonReader.read: Json object not found"};
6137 this.metaFromRemote = true;
6138 this.meta = o.metaData;
6139 this.recordType = Roo.data.Record.create(o.metaData.fields);
6140 this.onMetaChange(this.meta, this.recordType, o);
6142 return this.readRecords(o);
6145 // private function a store will implement
6146 onMetaChange : function(meta, recordType, o){
6153 simpleAccess: function(obj, subsc) {
6160 getJsonAccessor: function(){
6162 return function(expr) {
6164 return(re.test(expr))
6165 ? new Function("obj", "return obj." + expr)
6175 * Create a data block containing Roo.data.Records from an XML document.
6176 * @param {Object} o An object which contains an Array of row objects in the property specified
6177 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
6178 * which contains the total size of the dataset.
6179 * @return {Object} data A data block which is used by an Roo.data.Store object as
6180 * a cache of Roo.data.Records.
6182 readRecords : function(o){
6184 * After any data loads, the raw JSON data is available for further custom processing.
6188 var s = this.meta, Record = this.recordType,
6189 f = Record.prototype.fields, fi = f.items, fl = f.length;
6191 // Generate extraction functions for the totalProperty, the root, the id, and for each field
6193 if(s.totalProperty) {
6194 this.getTotal = this.getJsonAccessor(s.totalProperty);
6196 if(s.successProperty) {
6197 this.getSuccess = this.getJsonAccessor(s.successProperty);
6199 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
6201 var g = this.getJsonAccessor(s.id);
6202 this.getId = function(rec) {
6204 return (r === undefined || r === "") ? null : r;
6207 this.getId = function(){return null;};
6210 for(var jj = 0; jj < fl; jj++){
6212 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
6213 this.ef[jj] = this.getJsonAccessor(map);
6217 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
6218 if(s.totalProperty){
6219 var vt = parseInt(this.getTotal(o), 10);
6224 if(s.successProperty){
6225 var vs = this.getSuccess(o);
6226 if(vs === false || vs === 'false'){
6231 for(var i = 0; i < c; i++){
6234 var id = this.getId(n);
6235 for(var j = 0; j < fl; j++){
6237 var v = this.ef[j](n);
6239 Roo.log('missing convert for ' + f.name);
6243 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
6245 var record = new Record(values, id);
6247 records[i] = record;
6252 totalRecords : totalRecords
6257 * Ext JS Library 1.1.1
6258 * Copyright(c) 2006-2007, Ext JS, LLC.
6260 * Originally Released Under LGPL - original licence link has changed is not relivant.
6263 * <script type="text/javascript">
6267 * @class Roo.data.XmlReader
6268 * @extends Roo.data.DataReader
6269 * Data reader class to create an Array of {@link Roo.data.Record} objects from an XML document
6270 * based on mappings in a provided Roo.data.Record constructor.<br><br>
6272 * <em>Note that in order for the browser to parse a returned XML document, the Content-Type
6273 * header in the HTTP response must be set to "text/xml".</em>
6277 var RecordDef = Roo.data.Record.create([
6278 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
6279 {name: 'occupation'} // This field will use "occupation" as the mapping.
6281 var myReader = new Roo.data.XmlReader({
6282 totalRecords: "results", // The element which contains the total dataset size (optional)
6283 record: "row", // The repeated element which contains row information
6284 id: "id" // The element within the row that provides an ID for the record (optional)
6288 * This would consume an XML file like this:
6292 <results>2</results>
6295 <name>Bill</name>
6296 <occupation>Gardener</occupation>
6300 <name>Ben</name>
6301 <occupation>Horticulturalist</occupation>
6305 * @cfg {String} totalRecords The DomQuery path from which to retrieve the total number of records
6306 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
6307 * paged from the remote server.
6308 * @cfg {String} record The DomQuery path to the repeated element which contains record information.
6309 * @cfg {String} success The DomQuery path to the success attribute used by forms.
6310 * @cfg {String} id The DomQuery path relative from the record element to the element that contains
6311 * a record identifier value.
6313 * Create a new XmlReader
6314 * @param {Object} meta Metadata configuration options
6315 * @param {Mixed} recordType The definition of the data record type to produce. This can be either a valid
6316 * Record subclass created with {@link Roo.data.Record#create}, or an array of objects with which to call
6317 * Roo.data.Record.create. See the {@link Roo.data.Record} class for more details.
6319 Roo.data.XmlReader = function(meta, recordType){
6321 Roo.data.XmlReader.superclass.constructor.call(this, meta, recordType||meta.fields);
6323 Roo.extend(Roo.data.XmlReader, Roo.data.DataReader, {
6325 * This method is only used by a DataProxy which has retrieved data from a remote server.
6326 * @param {Object} response The XHR object which contains the parsed XML document. The response is expected
6327 * to contain a method called 'responseXML' that returns an XML document object.
6328 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
6329 * a cache of Roo.data.Records.
6331 read : function(response){
6332 var doc = response.responseXML;
6334 throw {message: "XmlReader.read: XML Document not available"};
6336 return this.readRecords(doc);
6340 * Create a data block containing Roo.data.Records from an XML document.
6341 * @param {Object} doc A parsed XML document.
6342 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
6343 * a cache of Roo.data.Records.
6345 readRecords : function(doc){
6347 * After any data loads/reads, the raw XML Document is available for further custom processing.
6351 var root = doc.documentElement || doc;
6352 var q = Roo.DomQuery;
6353 var recordType = this.recordType, fields = recordType.prototype.fields;
6354 var sid = this.meta.id;
6355 var totalRecords = 0, success = true;
6356 if(this.meta.totalRecords){
6357 totalRecords = q.selectNumber(this.meta.totalRecords, root, 0);
6360 if(this.meta.success){
6361 var sv = q.selectValue(this.meta.success, root, true);
6362 success = sv !== false && sv !== 'false';
6365 var ns = q.select(this.meta.record, root);
6366 for(var i = 0, len = ns.length; i < len; i++) {
6369 var id = sid ? q.selectValue(sid, n) : undefined;
6370 for(var j = 0, jlen = fields.length; j < jlen; j++){
6371 var f = fields.items[j];
6372 var v = q.selectValue(f.mapping || f.name, n, f.defaultValue);
6376 var record = new recordType(values, id);
6378 records[records.length] = record;
6384 totalRecords : totalRecords || records.length
6389 * Ext JS Library 1.1.1
6390 * Copyright(c) 2006-2007, Ext JS, LLC.
6392 * Originally Released Under LGPL - original licence link has changed is not relivant.
6395 * <script type="text/javascript">
6399 * @class Roo.data.ArrayReader
6400 * @extends Roo.data.DataReader
6401 * Data reader class to create an Array of Roo.data.Record objects from an Array.
6402 * Each element of that Array represents a row of data fields. The
6403 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
6404 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
6408 var RecordDef = Roo.data.Record.create([
6409 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
6410 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
6412 var myReader = new Roo.data.ArrayReader({
6413 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
6417 * This would consume an Array like this:
6419 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
6421 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
6423 * Create a new JsonReader
6424 * @param {Object} meta Metadata configuration options.
6425 * @param {Object} recordType Either an Array of field definition objects
6426 * as specified to {@link Roo.data.Record#create},
6427 * or an {@link Roo.data.Record} object
6428 * created using {@link Roo.data.Record#create}.
6430 Roo.data.ArrayReader = function(meta, recordType){
6431 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
6434 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
6436 * Create a data block containing Roo.data.Records from an XML document.
6437 * @param {Object} o An Array of row objects which represents the dataset.
6438 * @return {Object} data A data block which is used by an Roo.data.Store object as
6439 * a cache of Roo.data.Records.
6441 readRecords : function(o){
6442 var sid = this.meta ? this.meta.id : null;
6443 var recordType = this.recordType, fields = recordType.prototype.fields;
6446 for(var i = 0; i < root.length; i++){
6449 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
6450 for(var j = 0, jlen = fields.length; j < jlen; j++){
6451 var f = fields.items[j];
6452 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
6453 var v = n[k] !== undefined ? n[k] : f.defaultValue;
6457 var record = new recordType(values, id);
6459 records[records.length] = record;
6463 totalRecords : records.length
6468 * Ext JS Library 1.1.1
6469 * Copyright(c) 2006-2007, Ext JS, LLC.
6471 * Originally Released Under LGPL - original licence link has changed is not relivant.
6474 * <script type="text/javascript">
6479 * @class Roo.data.Tree
6480 * @extends Roo.util.Observable
6481 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
6482 * in the tree have most standard DOM functionality.
6484 * @param {Node} root (optional) The root node
6486 Roo.data.Tree = function(root){
6489 * The root node for this tree
6494 this.setRootNode(root);
6499 * Fires when a new child node is appended to a node in this tree.
6500 * @param {Tree} tree The owner tree
6501 * @param {Node} parent The parent node
6502 * @param {Node} node The newly appended node
6503 * @param {Number} index The index of the newly appended node
6508 * Fires when a child node is removed from a node in this tree.
6509 * @param {Tree} tree The owner tree
6510 * @param {Node} parent The parent node
6511 * @param {Node} node The child node removed
6516 * Fires when a node is moved to a new location in the tree
6517 * @param {Tree} tree The owner tree
6518 * @param {Node} node The node moved
6519 * @param {Node} oldParent The old parent of this node
6520 * @param {Node} newParent The new parent of this node
6521 * @param {Number} index The index it was moved to
6526 * Fires when a new child node is inserted in a node in this tree.
6527 * @param {Tree} tree The owner tree
6528 * @param {Node} parent The parent node
6529 * @param {Node} node The child node inserted
6530 * @param {Node} refNode The child node the node was inserted before
6534 * @event beforeappend
6535 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
6536 * @param {Tree} tree The owner tree
6537 * @param {Node} parent The parent node
6538 * @param {Node} node The child node to be appended
6540 "beforeappend" : true,
6542 * @event beforeremove
6543 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
6544 * @param {Tree} tree The owner tree
6545 * @param {Node} parent The parent node
6546 * @param {Node} node The child node to be removed
6548 "beforeremove" : true,
6551 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
6552 * @param {Tree} tree The owner tree
6553 * @param {Node} node The node being moved
6554 * @param {Node} oldParent The parent of the node
6555 * @param {Node} newParent The new parent the node is moving to
6556 * @param {Number} index The index it is being moved to
6558 "beforemove" : true,
6560 * @event beforeinsert
6561 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
6562 * @param {Tree} tree The owner tree
6563 * @param {Node} parent The parent node
6564 * @param {Node} node The child node to be inserted
6565 * @param {Node} refNode The child node the node is being inserted before
6567 "beforeinsert" : true
6570 Roo.data.Tree.superclass.constructor.call(this);
6573 Roo.extend(Roo.data.Tree, Roo.util.Observable, {
6576 proxyNodeEvent : function(){
6577 return this.fireEvent.apply(this, arguments);
6581 * Returns the root node for this tree.
6584 getRootNode : function(){
6589 * Sets the root node for this tree.
6590 * @param {Node} node
6593 setRootNode : function(node){
6595 node.ownerTree = this;
6597 this.registerNode(node);
6602 * Gets a node in this tree by its id.
6603 * @param {String} id
6606 getNodeById : function(id){
6607 return this.nodeHash[id];
6610 registerNode : function(node){
6611 this.nodeHash[node.id] = node;
6614 unregisterNode : function(node){
6615 delete this.nodeHash[node.id];
6618 toString : function(){
6619 return "[Tree"+(this.id?" "+this.id:"")+"]";
6624 * @class Roo.data.Node
6625 * @extends Roo.util.Observable
6626 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
6627 * @cfg {String} id The id for this node. If one is not specified, one is generated.
6629 * @param {Object} attributes The attributes/config for the node
6631 Roo.data.Node = function(attributes){
6633 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
6636 this.attributes = attributes || {};
6637 this.leaf = this.attributes.leaf;
6639 * The node id. @type String
6641 this.id = this.attributes.id;
6643 this.id = Roo.id(null, "ynode-");
6644 this.attributes.id = this.id;
6647 * All child nodes of this node. @type Array
6649 this.childNodes = [];
6650 if(!this.childNodes.indexOf){ // indexOf is a must
6651 this.childNodes.indexOf = function(o){
6652 for(var i = 0, len = this.length; i < len; i++){
6661 * The parent node for this node. @type Node
6663 this.parentNode = null;
6665 * The first direct child node of this node, or null if this node has no child nodes. @type Node
6667 this.firstChild = null;
6669 * The last direct child node of this node, or null if this node has no child nodes. @type Node
6671 this.lastChild = null;
6673 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
6675 this.previousSibling = null;
6677 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
6679 this.nextSibling = null;
6684 * Fires when a new child node is appended
6685 * @param {Tree} tree The owner tree
6686 * @param {Node} this This node
6687 * @param {Node} node The newly appended node
6688 * @param {Number} index The index of the newly appended node
6693 * Fires when a child node is removed
6694 * @param {Tree} tree The owner tree
6695 * @param {Node} this This node
6696 * @param {Node} node The removed node
6701 * Fires when this node is moved to a new location in the tree
6702 * @param {Tree} tree The owner tree
6703 * @param {Node} this This node
6704 * @param {Node} oldParent The old parent of this node
6705 * @param {Node} newParent The new parent of this node
6706 * @param {Number} index The index it was moved to
6711 * Fires when a new child node is inserted.
6712 * @param {Tree} tree The owner tree
6713 * @param {Node} this This node
6714 * @param {Node} node The child node inserted
6715 * @param {Node} refNode The child node the node was inserted before
6719 * @event beforeappend
6720 * Fires before a new child is appended, return false to cancel the append.
6721 * @param {Tree} tree The owner tree
6722 * @param {Node} this This node
6723 * @param {Node} node The child node to be appended
6725 "beforeappend" : true,
6727 * @event beforeremove
6728 * Fires before a child is removed, return false to cancel the remove.
6729 * @param {Tree} tree The owner tree
6730 * @param {Node} this This node
6731 * @param {Node} node The child node to be removed
6733 "beforeremove" : true,
6736 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
6737 * @param {Tree} tree The owner tree
6738 * @param {Node} this This node
6739 * @param {Node} oldParent The parent of this node
6740 * @param {Node} newParent The new parent this node is moving to
6741 * @param {Number} index The index it is being moved to
6743 "beforemove" : true,
6745 * @event beforeinsert
6746 * Fires before a new child is inserted, return false to cancel the insert.
6747 * @param {Tree} tree The owner tree
6748 * @param {Node} this This node
6749 * @param {Node} node The child node to be inserted
6750 * @param {Node} refNode The child node the node is being inserted before
6752 "beforeinsert" : true
6754 this.listeners = this.attributes.listeners;
6755 Roo.data.Node.superclass.constructor.call(this);
6758 Roo.extend(Roo.data.Node, Roo.util.Observable, {
6759 fireEvent : function(evtName){
6760 // first do standard event for this node
6761 if(Roo.data.Node.superclass.fireEvent.apply(this, arguments) === false){
6764 // then bubble it up to the tree if the event wasn't cancelled
6765 var ot = this.getOwnerTree();
6767 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
6775 * Returns true if this node is a leaf
6778 isLeaf : function(){
6779 return this.leaf === true;
6783 setFirstChild : function(node){
6784 this.firstChild = node;
6788 setLastChild : function(node){
6789 this.lastChild = node;
6794 * Returns true if this node is the last child of its parent
6797 isLast : function(){
6798 return (!this.parentNode ? true : this.parentNode.lastChild == this);
6802 * Returns true if this node is the first child of its parent
6805 isFirst : function(){
6806 return (!this.parentNode ? true : this.parentNode.firstChild == this);
6809 hasChildNodes : function(){
6810 return !this.isLeaf() && this.childNodes.length > 0;
6814 * Insert node(s) as the last child node of this node.
6815 * @param {Node/Array} node The node or Array of nodes to append
6816 * @return {Node} The appended node if single append, or null if an array was passed
6818 appendChild : function(node){
6820 if(node instanceof Array){
6822 }else if(arguments.length > 1){
6825 // if passed an array or multiple args do them one by one
6827 for(var i = 0, len = multi.length; i < len; i++) {
6828 this.appendChild(multi[i]);
6831 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
6834 var index = this.childNodes.length;
6835 var oldParent = node.parentNode;
6836 // it's a move, make sure we move it cleanly
6838 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
6841 oldParent.removeChild(node);
6843 index = this.childNodes.length;
6845 this.setFirstChild(node);
6847 this.childNodes.push(node);
6848 node.parentNode = this;
6849 var ps = this.childNodes[index-1];
6851 node.previousSibling = ps;
6852 ps.nextSibling = node;
6854 node.previousSibling = null;
6856 node.nextSibling = null;
6857 this.setLastChild(node);
6858 node.setOwnerTree(this.getOwnerTree());
6859 this.fireEvent("append", this.ownerTree, this, node, index);
6861 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
6868 * Removes a child node from this node.
6869 * @param {Node} node The node to remove
6870 * @return {Node} The removed node
6872 removeChild : function(node){
6873 var index = this.childNodes.indexOf(node);
6877 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
6881 // remove it from childNodes collection
6882 this.childNodes.splice(index, 1);
6885 if(node.previousSibling){
6886 node.previousSibling.nextSibling = node.nextSibling;
6888 if(node.nextSibling){
6889 node.nextSibling.previousSibling = node.previousSibling;
6892 // update child refs
6893 if(this.firstChild == node){
6894 this.setFirstChild(node.nextSibling);
6896 if(this.lastChild == node){
6897 this.setLastChild(node.previousSibling);
6900 node.setOwnerTree(null);
6901 // clear any references from the node
6902 node.parentNode = null;
6903 node.previousSibling = null;
6904 node.nextSibling = null;
6905 this.fireEvent("remove", this.ownerTree, this, node);
6910 * Inserts the first node before the second node in this nodes childNodes collection.
6911 * @param {Node} node The node to insert
6912 * @param {Node} refNode The node to insert before (if null the node is appended)
6913 * @return {Node} The inserted node
6915 insertBefore : function(node, refNode){
6916 if(!refNode){ // like standard Dom, refNode can be null for append
6917 return this.appendChild(node);
6920 if(node == refNode){
6924 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
6927 var index = this.childNodes.indexOf(refNode);
6928 var oldParent = node.parentNode;
6929 var refIndex = index;
6931 // when moving internally, indexes will change after remove
6932 if(oldParent == this && this.childNodes.indexOf(node) < index){
6936 // it's a move, make sure we move it cleanly
6938 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
6941 oldParent.removeChild(node);
6944 this.setFirstChild(node);
6946 this.childNodes.splice(refIndex, 0, node);
6947 node.parentNode = this;
6948 var ps = this.childNodes[refIndex-1];
6950 node.previousSibling = ps;
6951 ps.nextSibling = node;
6953 node.previousSibling = null;
6955 node.nextSibling = refNode;
6956 refNode.previousSibling = node;
6957 node.setOwnerTree(this.getOwnerTree());
6958 this.fireEvent("insert", this.ownerTree, this, node, refNode);
6960 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
6966 * Returns the child node at the specified index.
6967 * @param {Number} index
6970 item : function(index){
6971 return this.childNodes[index];
6975 * Replaces one child node in this node with another.
6976 * @param {Node} newChild The replacement node
6977 * @param {Node} oldChild The node to replace
6978 * @return {Node} The replaced node
6980 replaceChild : function(newChild, oldChild){
6981 this.insertBefore(newChild, oldChild);
6982 this.removeChild(oldChild);
6987 * Returns the index of a child node
6988 * @param {Node} node
6989 * @return {Number} The index of the node or -1 if it was not found
6991 indexOf : function(child){
6992 return this.childNodes.indexOf(child);
6996 * Returns the tree this node is in.
6999 getOwnerTree : function(){
7000 // if it doesn't have one, look for one
7001 if(!this.ownerTree){
7005 this.ownerTree = p.ownerTree;
7011 return this.ownerTree;
7015 * Returns depth of this node (the root node has a depth of 0)
7018 getDepth : function(){
7021 while(p.parentNode){
7029 setOwnerTree : function(tree){
7030 // if it's move, we need to update everyone
7031 if(tree != this.ownerTree){
7033 this.ownerTree.unregisterNode(this);
7035 this.ownerTree = tree;
7036 var cs = this.childNodes;
7037 for(var i = 0, len = cs.length; i < len; i++) {
7038 cs[i].setOwnerTree(tree);
7041 tree.registerNode(this);
7047 * Returns the path for this node. The path can be used to expand or select this node programmatically.
7048 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
7049 * @return {String} The path
7051 getPath : function(attr){
7052 attr = attr || "id";
7053 var p = this.parentNode;
7054 var b = [this.attributes[attr]];
7056 b.unshift(p.attributes[attr]);
7059 var sep = this.getOwnerTree().pathSeparator;
7060 return sep + b.join(sep);
7064 * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
7065 * function call will be the scope provided or the current node. The arguments to the function
7066 * will be the args provided or the current node. If the function returns false at any point,
7067 * the bubble is stopped.
7068 * @param {Function} fn The function to call
7069 * @param {Object} scope (optional) The scope of the function (defaults to current node)
7070 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
7072 bubble : function(fn, scope, args){
7075 if(fn.call(scope || p, args || p) === false){
7083 * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
7084 * function call will be the scope provided or the current node. The arguments to the function
7085 * will be the args provided or the current node. If the function returns false at any point,
7086 * the cascade is stopped on that branch.
7087 * @param {Function} fn The function to call
7088 * @param {Object} scope (optional) The scope of the function (defaults to current node)
7089 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
7091 cascade : function(fn, scope, args){
7092 if(fn.call(scope || this, args || this) !== false){
7093 var cs = this.childNodes;
7094 for(var i = 0, len = cs.length; i < len; i++) {
7095 cs[i].cascade(fn, scope, args);
7101 * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
7102 * function call will be the scope provided or the current node. The arguments to the function
7103 * will be the args provided or the current node. If the function returns false at any point,
7104 * the iteration stops.
7105 * @param {Function} fn The function to call
7106 * @param {Object} scope (optional) The scope of the function (defaults to current node)
7107 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
7109 eachChild : function(fn, scope, args){
7110 var cs = this.childNodes;
7111 for(var i = 0, len = cs.length; i < len; i++) {
7112 if(fn.call(scope || this, args || cs[i]) === false){
7119 * Finds the first child that has the attribute with the specified value.
7120 * @param {String} attribute The attribute name
7121 * @param {Mixed} value The value to search for
7122 * @return {Node} The found child or null if none was found
7124 findChild : function(attribute, value){
7125 var cs = this.childNodes;
7126 for(var i = 0, len = cs.length; i < len; i++) {
7127 if(cs[i].attributes[attribute] == value){
7135 * Finds the first child by a custom function. The child matches if the function passed
7137 * @param {Function} fn
7138 * @param {Object} scope (optional)
7139 * @return {Node} The found child or null if none was found
7141 findChildBy : function(fn, scope){
7142 var cs = this.childNodes;
7143 for(var i = 0, len = cs.length; i < len; i++) {
7144 if(fn.call(scope||cs[i], cs[i]) === true){
7152 * Sorts this nodes children using the supplied sort function
7153 * @param {Function} fn
7154 * @param {Object} scope (optional)
7156 sort : function(fn, scope){
7157 var cs = this.childNodes;
7158 var len = cs.length;
7160 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
7162 for(var i = 0; i < len; i++){
7164 n.previousSibling = cs[i-1];
7165 n.nextSibling = cs[i+1];
7167 this.setFirstChild(n);
7170 this.setLastChild(n);
7177 * Returns true if this node is an ancestor (at any point) of the passed node.
7178 * @param {Node} node
7181 contains : function(node){
7182 return node.isAncestor(this);
7186 * Returns true if the passed node is an ancestor (at any point) of this node.
7187 * @param {Node} node
7190 isAncestor : function(node){
7191 var p = this.parentNode;
7201 toString : function(){
7202 return "[Node"+(this.id?" "+this.id:"")+"]";
7206 * Ext JS Library 1.1.1
7207 * Copyright(c) 2006-2007, Ext JS, LLC.
7209 * Originally Released Under LGPL - original licence link has changed is not relivant.
7212 * <script type="text/javascript">
7217 * @class Roo.ComponentMgr
7218 * Provides a common registry of all components on a page so that they can be easily accessed by component id (see {@link Roo.getCmp}).
7221 Roo.ComponentMgr = function(){
7222 var all = new Roo.util.MixedCollection();
7226 * Registers a component.
7227 * @param {Roo.Component} c The component
7229 register : function(c){
7234 * Unregisters a component.
7235 * @param {Roo.Component} c The component
7237 unregister : function(c){
7242 * Returns a component by id
7243 * @param {String} id The component id
7250 * Registers a function that will be called when a specified component is added to ComponentMgr
7251 * @param {String} id The component id
7252 * @param {Funtction} fn The callback function
7253 * @param {Object} scope The scope of the callback
7255 onAvailable : function(id, fn, scope){
7256 all.on("add", function(index, o){
7258 fn.call(scope || o, o);
7259 all.un("add", fn, scope);
7266 * Ext JS Library 1.1.1
7267 * Copyright(c) 2006-2007, Ext JS, LLC.
7269 * Originally Released Under LGPL - original licence link has changed is not relivant.
7272 * <script type="text/javascript">
7276 * @class Roo.Component
7277 * @extends Roo.util.Observable
7278 * Base class for all major Roo components. All subclasses of Component can automatically participate in the standard
7279 * Roo component lifecycle of creation, rendering and destruction. They also have automatic support for basic hide/show
7280 * and enable/disable behavior. Component allows any subclass to be lazy-rendered into any {@link Roo.Container} and
7281 * to be automatically registered with the {@link Roo.ComponentMgr} so that it can be referenced at any time via {@link Roo.getCmp}.
7282 * All visual components (widgets) that require rendering into a layout should subclass Component.
7284 * @param {Roo.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal
7285 * element and its id used as the component id. If a string is passed, it is assumed to be the id of an existing element
7286 * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component.
7288 Roo.Component = function(config){
7289 config = config || {};
7290 if(config.tagName || config.dom || typeof config == "string"){ // element object
7291 config = {el: config, id: config.id || config};
7293 this.initialConfig = config;
7295 Roo.apply(this, config);
7299 * Fires after the component is disabled.
7300 * @param {Roo.Component} this
7305 * Fires after the component is enabled.
7306 * @param {Roo.Component} this
7311 * Fires before the component is shown. Return false to stop the show.
7312 * @param {Roo.Component} this
7317 * Fires after the component is shown.
7318 * @param {Roo.Component} this
7323 * Fires before the component is hidden. Return false to stop the hide.
7324 * @param {Roo.Component} this
7329 * Fires after the component is hidden.
7330 * @param {Roo.Component} this
7334 * @event beforerender
7335 * Fires before the component is rendered. Return false to stop the render.
7336 * @param {Roo.Component} this
7338 beforerender : true,
7341 * Fires after the component is rendered.
7342 * @param {Roo.Component} this
7346 * @event beforedestroy
7347 * Fires before the component is destroyed. Return false to stop the destroy.
7348 * @param {Roo.Component} this
7350 beforedestroy : true,
7353 * Fires after the component is destroyed.
7354 * @param {Roo.Component} this
7359 this.id = "ext-comp-" + (++Roo.Component.AUTO_ID);
7361 Roo.ComponentMgr.register(this);
7362 Roo.Component.superclass.constructor.call(this);
7363 this.initComponent();
7364 if(this.renderTo){ // not supported by all components yet. use at your own risk!
7365 this.render(this.renderTo);
7366 delete this.renderTo;
7371 Roo.Component.AUTO_ID = 1000;
7373 Roo.extend(Roo.Component, Roo.util.Observable, {
7375 * @property {Boolean} hidden
7376 * true if this component is hidden. Read-only.
7380 * true if this component is disabled. Read-only.
7384 * true if this component has been rendered. Read-only.
7388 /** @cfg {String} disableClass
7389 * CSS class added to the component when it is disabled (defaults to "x-item-disabled").
7391 disabledClass : "x-item-disabled",
7392 /** @cfg {Boolean} allowDomMove
7393 * Whether the component can move the Dom node when rendering (defaults to true).
7395 allowDomMove : true,
7396 /** @cfg {String} hideMode
7397 * How this component should hidden. Supported values are
7398 * "visibility" (css visibility), "offsets" (negative offset position) and
7399 * "display" (css display) - defaults to "display".
7401 hideMode: 'display',
7404 ctype : "Roo.Component",
7406 /** @cfg {String} actionMode
7407 * which property holds the element that used for hide() / show() / disable() / enable()
7413 getActionEl : function(){
7414 return this[this.actionMode];
7417 initComponent : Roo.emptyFn,
7419 * If this is a lazy rendering component, render it to its container element.
7420 * @param {String/HTMLElement/Element} container (optional) The element this component should be rendered into. If it is being applied to existing markup, this should be left off.
7422 render : function(container, position){
7423 if(!this.rendered && this.fireEvent("beforerender", this) !== false){
7424 if(!container && this.el){
7425 this.el = Roo.get(this.el);
7426 container = this.el.dom.parentNode;
7427 this.allowDomMove = false;
7429 this.container = Roo.get(container);
7430 this.rendered = true;
7431 if(position !== undefined){
7432 if(typeof position == 'number'){
7433 position = this.container.dom.childNodes[position];
7435 position = Roo.getDom(position);
7438 this.onRender(this.container, position || null);
7440 this.el.addClass(this.cls);
7444 this.el.applyStyles(this.style);
7447 this.fireEvent("render", this);
7448 this.afterRender(this.container);
7460 // default function is not really useful
7461 onRender : function(ct, position){
7463 this.el = Roo.get(this.el);
7464 if(this.allowDomMove !== false){
7465 ct.dom.insertBefore(this.el.dom, position);
7471 getAutoCreate : function(){
7472 var cfg = typeof this.autoCreate == "object" ?
7473 this.autoCreate : Roo.apply({}, this.defaultAutoCreate);
7474 if(this.id && !cfg.id){
7481 afterRender : Roo.emptyFn,
7484 * Destroys this component by purging any event listeners, removing the component's element from the DOM,
7485 * removing the component from its {@link Roo.Container} (if applicable) and unregistering it from {@link Roo.ComponentMgr}.
7487 destroy : function(){
7488 if(this.fireEvent("beforedestroy", this) !== false){
7489 this.purgeListeners();
7490 this.beforeDestroy();
7492 this.el.removeAllListeners();
7494 if(this.actionMode == "container"){
7495 this.container.remove();
7499 Roo.ComponentMgr.unregister(this);
7500 this.fireEvent("destroy", this);
7505 beforeDestroy : function(){
7510 onDestroy : function(){
7515 * Returns the underlying {@link Roo.Element}.
7516 * @return {Roo.Element} The element
7523 * Returns the id of this component.
7531 * Try to focus this component.
7532 * @param {Boolean} selectText True to also select the text in this component (if applicable)
7533 * @return {Roo.Component} this
7535 focus : function(selectText){
7538 if(selectText === true){
7539 this.el.dom.select();
7554 * Disable this component.
7555 * @return {Roo.Component} this
7557 disable : function(){
7561 this.disabled = true;
7562 this.fireEvent("disable", this);
7567 onDisable : function(){
7568 this.getActionEl().addClass(this.disabledClass);
7569 this.el.dom.disabled = true;
7573 * Enable this component.
7574 * @return {Roo.Component} this
7576 enable : function(){
7580 this.disabled = false;
7581 this.fireEvent("enable", this);
7586 onEnable : function(){
7587 this.getActionEl().removeClass(this.disabledClass);
7588 this.el.dom.disabled = false;
7592 * Convenience function for setting disabled/enabled by boolean.
7593 * @param {Boolean} disabled
7595 setDisabled : function(disabled){
7596 this[disabled ? "disable" : "enable"]();
7600 * Show this component.
7601 * @return {Roo.Component} this
7604 if(this.fireEvent("beforeshow", this) !== false){
7605 this.hidden = false;
7609 this.fireEvent("show", this);
7615 onShow : function(){
7616 var ae = this.getActionEl();
7617 if(this.hideMode == 'visibility'){
7618 ae.dom.style.visibility = "visible";
7619 }else if(this.hideMode == 'offsets'){
7620 ae.removeClass('x-hidden');
7622 ae.dom.style.display = "";
7627 * Hide this component.
7628 * @return {Roo.Component} this
7631 if(this.fireEvent("beforehide", this) !== false){
7636 this.fireEvent("hide", this);
7642 onHide : function(){
7643 var ae = this.getActionEl();
7644 if(this.hideMode == 'visibility'){
7645 ae.dom.style.visibility = "hidden";
7646 }else if(this.hideMode == 'offsets'){
7647 ae.addClass('x-hidden');
7649 ae.dom.style.display = "none";
7654 * Convenience function to hide or show this component by boolean.
7655 * @param {Boolean} visible True to show, false to hide
7656 * @return {Roo.Component} this
7658 setVisible: function(visible){
7668 * Returns true if this component is visible.
7670 isVisible : function(){
7671 return this.getActionEl().isVisible();
7674 cloneConfig : function(overrides){
7675 overrides = overrides || {};
7676 var id = overrides.id || Roo.id();
7677 var cfg = Roo.applyIf(overrides, this.initialConfig);
7678 cfg.id = id; // prevent dup id
7679 return new this.constructor(cfg);
7683 * Ext JS Library 1.1.1
7684 * Copyright(c) 2006-2007, Ext JS, LLC.
7686 * Originally Released Under LGPL - original licence link has changed is not relivant.
7689 * <script type="text/javascript">
7694 * @extends Roo.Element
7695 * An extended {@link Roo.Element} object that supports a shadow and shim, constrain to viewport and
7696 * automatic maintaining of shadow/shim positions.
7697 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
7698 * @cfg {String/Boolean} shadow True to create a shadow element with default class "x-layer-shadow", or
7699 * you can pass a string with a CSS class name. False turns off the shadow.
7700 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: "div", cls: "x-layer"}).
7701 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
7702 * @cfg {String} cls CSS class to add to the element
7703 * @cfg {Number} zindex Starting z-index (defaults to 11000)
7704 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 3)
7706 * @param {Object} config An object with config options.
7707 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
7710 Roo.Layer = function(config, existingEl){
7711 config = config || {};
7712 var dh = Roo.DomHelper;
7713 var cp = config.parentEl, pel = cp ? Roo.getDom(cp) : document.body;
7715 this.dom = Roo.getDom(existingEl);
7718 var o = config.dh || {tag: "div", cls: "x-layer"};
7719 this.dom = dh.append(pel, o);
7722 this.addClass(config.cls);
7724 this.constrain = config.constrain !== false;
7725 this.visibilityMode = Roo.Element.VISIBILITY;
7727 this.id = this.dom.id = config.id;
7729 this.id = Roo.id(this.dom);
7731 this.zindex = config.zindex || this.getZIndex();
7732 this.position("absolute", this.zindex);
7734 this.shadowOffset = config.shadowOffset || 4;
7735 this.shadow = new Roo.Shadow({
7736 offset : this.shadowOffset,
7737 mode : config.shadow
7740 this.shadowOffset = 0;
7742 this.useShim = config.shim !== false && Roo.useShims;
7743 this.useDisplay = config.useDisplay;
7747 var supr = Roo.Element.prototype;
7749 // shims are shared among layer to keep from having 100 iframes
7752 Roo.extend(Roo.Layer, Roo.Element, {
7754 getZIndex : function(){
7755 return this.zindex || parseInt(this.getStyle("z-index"), 10) || 11000;
7758 getShim : function(){
7765 var shim = shims.shift();
7767 shim = this.createShim();
7768 shim.enableDisplayMode('block');
7769 shim.dom.style.display = 'none';
7770 shim.dom.style.visibility = 'visible';
7772 var pn = this.dom.parentNode;
7773 if(shim.dom.parentNode != pn){
7774 pn.insertBefore(shim.dom, this.dom);
7776 shim.setStyle('z-index', this.getZIndex()-2);
7781 hideShim : function(){
7783 this.shim.setDisplayed(false);
7784 shims.push(this.shim);
7789 disableShadow : function(){
7791 this.shadowDisabled = true;
7793 this.lastShadowOffset = this.shadowOffset;
7794 this.shadowOffset = 0;
7798 enableShadow : function(show){
7800 this.shadowDisabled = false;
7801 this.shadowOffset = this.lastShadowOffset;
7802 delete this.lastShadowOffset;
7810 // this code can execute repeatedly in milliseconds (i.e. during a drag) so
7811 // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
7812 sync : function(doShow){
7813 var sw = this.shadow;
7814 if(!this.updating && this.isVisible() && (sw || this.useShim)){
7815 var sh = this.getShim();
7817 var w = this.getWidth(),
7818 h = this.getHeight();
7820 var l = this.getLeft(true),
7821 t = this.getTop(true);
7823 if(sw && !this.shadowDisabled){
7824 if(doShow && !sw.isVisible()){
7827 sw.realign(l, t, w, h);
7833 // fit the shim behind the shadow, so it is shimmed too
7834 var a = sw.adjusts, s = sh.dom.style;
7835 s.left = (Math.min(l, l+a.l))+"px";
7836 s.top = (Math.min(t, t+a.t))+"px";
7837 s.width = (w+a.w)+"px";
7838 s.height = (h+a.h)+"px";
7845 sh.setLeftTop(l, t);
7852 destroy : function(){
7857 this.removeAllListeners();
7858 var pn = this.dom.parentNode;
7860 pn.removeChild(this.dom);
7862 Roo.Element.uncache(this.id);
7865 remove : function(){
7870 beginUpdate : function(){
7871 this.updating = true;
7875 endUpdate : function(){
7876 this.updating = false;
7881 hideUnders : function(negOffset){
7889 constrainXY : function(){
7891 var vw = Roo.lib.Dom.getViewWidth(),
7892 vh = Roo.lib.Dom.getViewHeight();
7893 var s = Roo.get(document).getScroll();
7895 var xy = this.getXY();
7896 var x = xy[0], y = xy[1];
7897 var w = this.dom.offsetWidth+this.shadowOffset, h = this.dom.offsetHeight+this.shadowOffset;
7898 // only move it if it needs it
7900 // first validate right/bottom
7901 if((x + w) > vw+s.left){
7902 x = vw - w - this.shadowOffset;
7905 if((y + h) > vh+s.top){
7906 y = vh - h - this.shadowOffset;
7909 // then make sure top/left isn't negative
7920 var ay = this.avoidY;
7921 if(y <= ay && (y+h) >= ay){
7927 supr.setXY.call(this, xy);
7933 isVisible : function(){
7934 return this.visible;
7938 showAction : function(){
7939 this.visible = true; // track visibility to prevent getStyle calls
7940 if(this.useDisplay === true){
7941 this.setDisplayed("");
7942 }else if(this.lastXY){
7943 supr.setXY.call(this, this.lastXY);
7944 }else if(this.lastLT){
7945 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
7950 hideAction : function(){
7951 this.visible = false;
7952 if(this.useDisplay === true){
7953 this.setDisplayed(false);
7955 this.setLeftTop(-10000,-10000);
7959 // overridden Element method
7960 setVisible : function(v, a, d, c, e){
7965 var cb = function(){
7970 }.createDelegate(this);
7971 supr.setVisible.call(this, true, true, d, cb, e);
7974 this.hideUnders(true);
7983 }.createDelegate(this);
7985 supr.setVisible.call(this, v, a, d, cb, e);
7994 storeXY : function(xy){
7999 storeLeftTop : function(left, top){
8001 this.lastLT = [left, top];
8005 beforeFx : function(){
8006 this.beforeAction();
8007 return Roo.Layer.superclass.beforeFx.apply(this, arguments);
8011 afterFx : function(){
8012 Roo.Layer.superclass.afterFx.apply(this, arguments);
8013 this.sync(this.isVisible());
8017 beforeAction : function(){
8018 if(!this.updating && this.shadow){
8023 // overridden Element method
8024 setLeft : function(left){
8025 this.storeLeftTop(left, this.getTop(true));
8026 supr.setLeft.apply(this, arguments);
8030 setTop : function(top){
8031 this.storeLeftTop(this.getLeft(true), top);
8032 supr.setTop.apply(this, arguments);
8036 setLeftTop : function(left, top){
8037 this.storeLeftTop(left, top);
8038 supr.setLeftTop.apply(this, arguments);
8042 setXY : function(xy, a, d, c, e){
8044 this.beforeAction();
8046 var cb = this.createCB(c);
8047 supr.setXY.call(this, xy, a, d, cb, e);
8054 createCB : function(c){
8065 // overridden Element method
8066 setX : function(x, a, d, c, e){
8067 this.setXY([x, this.getY()], a, d, c, e);
8070 // overridden Element method
8071 setY : function(y, a, d, c, e){
8072 this.setXY([this.getX(), y], a, d, c, e);
8075 // overridden Element method
8076 setSize : function(w, h, a, d, c, e){
8077 this.beforeAction();
8078 var cb = this.createCB(c);
8079 supr.setSize.call(this, w, h, a, d, cb, e);
8085 // overridden Element method
8086 setWidth : function(w, a, d, c, e){
8087 this.beforeAction();
8088 var cb = this.createCB(c);
8089 supr.setWidth.call(this, w, a, d, cb, e);
8095 // overridden Element method
8096 setHeight : function(h, a, d, c, e){
8097 this.beforeAction();
8098 var cb = this.createCB(c);
8099 supr.setHeight.call(this, h, a, d, cb, e);
8105 // overridden Element method
8106 setBounds : function(x, y, w, h, a, d, c, e){
8107 this.beforeAction();
8108 var cb = this.createCB(c);
8110 this.storeXY([x, y]);
8111 supr.setXY.call(this, [x, y]);
8112 supr.setSize.call(this, w, h, a, d, cb, e);
8115 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
8121 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
8122 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
8123 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
8124 * @param {Number} zindex The new z-index to set
8125 * @return {this} The Layer
8127 setZIndex : function(zindex){
8128 this.zindex = zindex;
8129 this.setStyle("z-index", zindex + 2);
8131 this.shadow.setZIndex(zindex + 1);
8134 this.shim.setStyle("z-index", zindex);
8140 * Ext JS Library 1.1.1
8141 * Copyright(c) 2006-2007, Ext JS, LLC.
8143 * Originally Released Under LGPL - original licence link has changed is not relivant.
8146 * <script type="text/javascript">
8152 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
8153 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
8154 * functionality that can also provide the same shadow effect, see the {@link Roo.Layer} class.
8156 * Create a new Shadow
8157 * @param {Object} config The config object
8159 Roo.Shadow = function(config){
8160 Roo.apply(this, config);
8161 if(typeof this.mode != "string"){
8162 this.mode = this.defaultMode;
8164 var o = this.offset, a = {h: 0};
8165 var rad = Math.floor(this.offset/2);
8166 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
8172 a.l -= this.offset + rad;
8173 a.t -= this.offset + rad;
8184 a.l -= (this.offset - rad);
8185 a.t -= this.offset + rad;
8187 a.w -= (this.offset - rad)*2;
8198 a.l -= (this.offset - rad);
8199 a.t -= (this.offset - rad);
8201 a.w -= (this.offset + rad + 1);
8202 a.h -= (this.offset + rad);
8211 Roo.Shadow.prototype = {
8213 * @cfg {String} mode
8214 * The shadow display mode. Supports the following options:<br />
8215 * sides: Shadow displays on both sides and bottom only<br />
8216 * frame: Shadow displays equally on all four sides<br />
8217 * drop: Traditional bottom-right drop shadow (default)
8220 * @cfg {String} offset
8221 * The number of pixels to offset the shadow from the element (defaults to 4)
8226 defaultMode: "drop",
8229 * Displays the shadow under the target element
8230 * @param {String/HTMLElement/Element} targetEl The id or element under which the shadow should display
8232 show : function(target){
8233 target = Roo.get(target);
8235 this.el = Roo.Shadow.Pool.pull();
8236 if(this.el.dom.nextSibling != target.dom){
8237 this.el.insertBefore(target);
8240 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
8242 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
8245 target.getLeft(true),
8246 target.getTop(true),
8250 this.el.dom.style.display = "block";
8254 * Returns true if the shadow is visible, else false
8256 isVisible : function(){
8257 return this.el ? true : false;
8261 * Direct alignment when values are already available. Show must be called at least once before
8262 * calling this method to ensure it is initialized.
8263 * @param {Number} left The target element left position
8264 * @param {Number} top The target element top position
8265 * @param {Number} width The target element width
8266 * @param {Number} height The target element height
8268 realign : function(l, t, w, h){
8272 var a = this.adjusts, d = this.el.dom, s = d.style;
8274 s.left = (l+a.l)+"px";
8275 s.top = (t+a.t)+"px";
8276 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
8278 if(s.width != sws || s.height != shs){
8282 var cn = d.childNodes;
8283 var sww = Math.max(0, (sw-12))+"px";
8284 cn[0].childNodes[1].style.width = sww;
8285 cn[1].childNodes[1].style.width = sww;
8286 cn[2].childNodes[1].style.width = sww;
8287 cn[1].style.height = Math.max(0, (sh-12))+"px";
8297 this.el.dom.style.display = "none";
8298 Roo.Shadow.Pool.push(this.el);
8304 * Adjust the z-index of this shadow
8305 * @param {Number} zindex The new z-index
8307 setZIndex : function(z){
8310 this.el.setStyle("z-index", z);
8315 // Private utility class that manages the internal Shadow cache
8316 Roo.Shadow.Pool = function(){
8318 var markup = Roo.isIE ?
8319 '<div class="x-ie-shadow"></div>' :
8320 '<div class="x-shadow"><div class="xst"><div class="xstl"></div><div class="xstc"></div><div class="xstr"></div></div><div class="xsc"><div class="xsml"></div><div class="xsmc"></div><div class="xsmr"></div></div><div class="xsb"><div class="xsbl"></div><div class="xsbc"></div><div class="xsbr"></div></div></div>';
8325 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
8326 sh.autoBoxAdjust = false;
8331 push : function(sh){
8337 * Ext JS Library 1.1.1
8338 * Copyright(c) 2006-2007, Ext JS, LLC.
8340 * Originally Released Under LGPL - original licence link has changed is not relivant.
8343 * <script type="text/javascript">
8347 * @class Roo.BoxComponent
8348 * @extends Roo.Component
8349 * Base class for any visual {@link Roo.Component} that uses a box container. BoxComponent provides automatic box
8350 * model adjustments for sizing and positioning and will work correctly withnin the Component rendering model. All
8351 * container classes should subclass BoxComponent so that they will work consistently when nested within other Ext
8352 * layout containers.
8354 * @param {Roo.Element/String/Object} config The configuration options.
8356 Roo.BoxComponent = function(config){
8357 Roo.Component.call(this, config);
8361 * Fires after the component is resized.
8362 * @param {Roo.Component} this
8363 * @param {Number} adjWidth The box-adjusted width that was set
8364 * @param {Number} adjHeight The box-adjusted height that was set
8365 * @param {Number} rawWidth The width that was originally specified
8366 * @param {Number} rawHeight The height that was originally specified
8371 * Fires after the component is moved.
8372 * @param {Roo.Component} this
8373 * @param {Number} x The new x position
8374 * @param {Number} y The new y position
8380 Roo.extend(Roo.BoxComponent, Roo.Component, {
8381 // private, set in afterRender to signify that the component has been rendered
8383 // private, used to defer height settings to subclasses
8385 /** @cfg {Number} width
8386 * width (optional) size of component
8388 /** @cfg {Number} height
8389 * height (optional) size of component
8393 * Sets the width and height of the component. This method fires the resize event. This method can accept
8394 * either width and height as separate numeric arguments, or you can pass a size object like {width:10, height:20}.
8395 * @param {Number/Object} width The new width to set, or a size object in the format {width, height}
8396 * @param {Number} height The new height to set (not required if a size object is passed as the first arg)
8397 * @return {Roo.BoxComponent} this
8399 setSize : function(w, h){
8400 // support for standard size objects
8401 if(typeof w == 'object'){
8412 // prevent recalcs when not needed
8413 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
8416 this.lastSize = {width: w, height: h};
8418 var adj = this.adjustSize(w, h);
8419 var aw = adj.width, ah = adj.height;
8420 if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
8421 var rz = this.getResizeEl();
8422 if(!this.deferHeight && aw !== undefined && ah !== undefined){
8424 }else if(!this.deferHeight && ah !== undefined){
8426 }else if(aw !== undefined){
8429 this.onResize(aw, ah, w, h);
8430 this.fireEvent('resize', this, aw, ah, w, h);
8436 * Gets the current size of the component's underlying element.
8437 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
8439 getSize : function(){
8440 return this.el.getSize();
8444 * Gets the current XY position of the component's underlying element.
8445 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
8446 * @return {Array} The XY position of the element (e.g., [100, 200])
8448 getPosition : function(local){
8450 return [this.el.getLeft(true), this.el.getTop(true)];
8452 return this.xy || this.el.getXY();
8456 * Gets the current box measurements of the component's underlying element.
8457 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
8458 * @returns {Object} box An object in the format {x, y, width, height}
8460 getBox : function(local){
8461 var s = this.el.getSize();
8463 s.x = this.el.getLeft(true);
8464 s.y = this.el.getTop(true);
8466 var xy = this.xy || this.el.getXY();
8474 * Sets the current box measurements of the component's underlying element.
8475 * @param {Object} box An object in the format {x, y, width, height}
8476 * @returns {Roo.BoxComponent} this
8478 updateBox : function(box){
8479 this.setSize(box.width, box.height);
8480 this.setPagePosition(box.x, box.y);
8485 getResizeEl : function(){
8486 return this.resizeEl || this.el;
8490 getPositionEl : function(){
8491 return this.positionEl || this.el;
8495 * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
8496 * This method fires the move event.
8497 * @param {Number} left The new left
8498 * @param {Number} top The new top
8499 * @returns {Roo.BoxComponent} this
8501 setPosition : function(x, y){
8507 var adj = this.adjustPosition(x, y);
8508 var ax = adj.x, ay = adj.y;
8510 var el = this.getPositionEl();
8511 if(ax !== undefined || ay !== undefined){
8512 if(ax !== undefined && ay !== undefined){
8513 el.setLeftTop(ax, ay);
8514 }else if(ax !== undefined){
8516 }else if(ay !== undefined){
8519 this.onPosition(ax, ay);
8520 this.fireEvent('move', this, ax, ay);
8526 * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
8527 * This method fires the move event.
8528 * @param {Number} x The new x position
8529 * @param {Number} y The new y position
8530 * @returns {Roo.BoxComponent} this
8532 setPagePosition : function(x, y){
8538 if(x === undefined || y === undefined){ // cannot translate undefined points
8541 var p = this.el.translatePoints(x, y);
8542 this.setPosition(p.left, p.top);
8547 onRender : function(ct, position){
8548 Roo.BoxComponent.superclass.onRender.call(this, ct, position);
8550 this.resizeEl = Roo.get(this.resizeEl);
8552 if(this.positionEl){
8553 this.positionEl = Roo.get(this.positionEl);
8558 afterRender : function(){
8559 Roo.BoxComponent.superclass.afterRender.call(this);
8560 this.boxReady = true;
8561 this.setSize(this.width, this.height);
8562 if(this.x || this.y){
8563 this.setPosition(this.x, this.y);
8565 if(this.pageX || this.pageY){
8566 this.setPagePosition(this.pageX, this.pageY);
8571 * Force the component's size to recalculate based on the underlying element's current height and width.
8572 * @returns {Roo.BoxComponent} this
8574 syncSize : function(){
8575 delete this.lastSize;
8576 this.setSize(this.el.getWidth(), this.el.getHeight());
8581 * Called after the component is resized, this method is empty by default but can be implemented by any
8582 * subclass that needs to perform custom logic after a resize occurs.
8583 * @param {Number} adjWidth The box-adjusted width that was set
8584 * @param {Number} adjHeight The box-adjusted height that was set
8585 * @param {Number} rawWidth The width that was originally specified
8586 * @param {Number} rawHeight The height that was originally specified
8588 onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
8593 * Called after the component is moved, this method is empty by default but can be implemented by any
8594 * subclass that needs to perform custom logic after a move occurs.
8595 * @param {Number} x The new x position
8596 * @param {Number} y The new y position
8598 onPosition : function(x, y){
8603 adjustSize : function(w, h){
8607 if(this.autoHeight){
8610 return {width : w, height: h};
8614 adjustPosition : function(x, y){
8615 return {x : x, y: y};
8619 * Ext JS Library 1.1.1
8620 * Copyright(c) 2006-2007, Ext JS, LLC.
8622 * Originally Released Under LGPL - original licence link has changed is not relivant.
8625 * <script type="text/javascript">
8630 * @class Roo.SplitBar
8631 * @extends Roo.util.Observable
8632 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
8636 var split = new Roo.SplitBar("elementToDrag", "elementToSize",
8637 Roo.SplitBar.HORIZONTAL, Roo.SplitBar.LEFT);
8638 split.setAdapter(new Roo.SplitBar.AbsoluteLayoutAdapter("container"));
8639 split.minSize = 100;
8640 split.maxSize = 600;
8641 split.animate = true;
8642 split.on('moved', splitterMoved);
8645 * Create a new SplitBar
8646 * @param {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
8647 * @param {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
8648 * @param {Number} orientation (optional) Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
8649 * @param {Number} placement (optional) Either Roo.SplitBar.LEFT or Roo.SplitBar.RIGHT for horizontal or
8650 Roo.SplitBar.TOP or Roo.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
8651 position of the SplitBar).
8653 Roo.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
8656 this.el = Roo.get(dragElement, true);
8657 this.el.dom.unselectable = "on";
8659 this.resizingEl = Roo.get(resizingElement, true);
8663 * The orientation of the split. Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
8664 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
8667 this.orientation = orientation || Roo.SplitBar.HORIZONTAL;
8670 * The minimum size of the resizing element. (Defaults to 0)
8676 * The maximum size of the resizing element. (Defaults to 2000)
8679 this.maxSize = 2000;
8682 * Whether to animate the transition to the new size
8685 this.animate = false;
8688 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
8691 this.useShim = false;
8698 this.proxy = Roo.SplitBar.createProxy(this.orientation);
8700 this.proxy = Roo.get(existingProxy).dom;
8703 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
8706 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
8709 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
8712 this.dragSpecs = {};
8715 * @private The adapter to use to positon and resize elements
8717 this.adapter = new Roo.SplitBar.BasicLayoutAdapter();
8718 this.adapter.init(this);
8720 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8722 this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Roo.SplitBar.LEFT : Roo.SplitBar.RIGHT);
8723 this.el.addClass("x-splitbar-h");
8726 this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Roo.SplitBar.TOP : Roo.SplitBar.BOTTOM);
8727 this.el.addClass("x-splitbar-v");
8733 * Fires when the splitter is moved (alias for {@link #event-moved})
8734 * @param {Roo.SplitBar} this
8735 * @param {Number} newSize the new width or height
8740 * Fires when the splitter is moved
8741 * @param {Roo.SplitBar} this
8742 * @param {Number} newSize the new width or height
8746 * @event beforeresize
8747 * Fires before the splitter is dragged
8748 * @param {Roo.SplitBar} this
8750 "beforeresize" : true,
8752 "beforeapply" : true
8755 Roo.util.Observable.call(this);
8758 Roo.extend(Roo.SplitBar, Roo.util.Observable, {
8759 onStartProxyDrag : function(x, y){
8760 this.fireEvent("beforeresize", this);
8762 var o = Roo.DomHelper.insertFirst(document.body, {cls: "x-drag-overlay", html: " "}, true);
8764 o.enableDisplayMode("block");
8765 // all splitbars share the same overlay
8766 Roo.SplitBar.prototype.overlay = o;
8768 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
8769 this.overlay.show();
8770 Roo.get(this.proxy).setDisplayed("block");
8771 var size = this.adapter.getElementSize(this);
8772 this.activeMinSize = this.getMinimumSize();;
8773 this.activeMaxSize = this.getMaximumSize();;
8774 var c1 = size - this.activeMinSize;
8775 var c2 = Math.max(this.activeMaxSize - size, 0);
8776 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8777 this.dd.resetConstraints();
8778 this.dd.setXConstraint(
8779 this.placement == Roo.SplitBar.LEFT ? c1 : c2,
8780 this.placement == Roo.SplitBar.LEFT ? c2 : c1
8782 this.dd.setYConstraint(0, 0);
8784 this.dd.resetConstraints();
8785 this.dd.setXConstraint(0, 0);
8786 this.dd.setYConstraint(
8787 this.placement == Roo.SplitBar.TOP ? c1 : c2,
8788 this.placement == Roo.SplitBar.TOP ? c2 : c1
8791 this.dragSpecs.startSize = size;
8792 this.dragSpecs.startPoint = [x, y];
8793 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
8797 * @private Called after the drag operation by the DDProxy
8799 onEndProxyDrag : function(e){
8800 Roo.get(this.proxy).setDisplayed(false);
8801 var endPoint = Roo.lib.Event.getXY(e);
8803 this.overlay.hide();
8806 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8807 newSize = this.dragSpecs.startSize +
8808 (this.placement == Roo.SplitBar.LEFT ?
8809 endPoint[0] - this.dragSpecs.startPoint[0] :
8810 this.dragSpecs.startPoint[0] - endPoint[0]
8813 newSize = this.dragSpecs.startSize +
8814 (this.placement == Roo.SplitBar.TOP ?
8815 endPoint[1] - this.dragSpecs.startPoint[1] :
8816 this.dragSpecs.startPoint[1] - endPoint[1]
8819 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
8820 if(newSize != this.dragSpecs.startSize){
8821 if(this.fireEvent('beforeapply', this, newSize) !== false){
8822 this.adapter.setElementSize(this, newSize);
8823 this.fireEvent("moved", this, newSize);
8824 this.fireEvent("resize", this, newSize);
8830 * Get the adapter this SplitBar uses
8831 * @return The adapter object
8833 getAdapter : function(){
8834 return this.adapter;
8838 * Set the adapter this SplitBar uses
8839 * @param {Object} adapter A SplitBar adapter object
8841 setAdapter : function(adapter){
8842 this.adapter = adapter;
8843 this.adapter.init(this);
8847 * Gets the minimum size for the resizing element
8848 * @return {Number} The minimum size
8850 getMinimumSize : function(){
8851 return this.minSize;
8855 * Sets the minimum size for the resizing element
8856 * @param {Number} minSize The minimum size
8858 setMinimumSize : function(minSize){
8859 this.minSize = minSize;
8863 * Gets the maximum size for the resizing element
8864 * @return {Number} The maximum size
8866 getMaximumSize : function(){
8867 return this.maxSize;
8871 * Sets the maximum size for the resizing element
8872 * @param {Number} maxSize The maximum size
8874 setMaximumSize : function(maxSize){
8875 this.maxSize = maxSize;
8879 * Sets the initialize size for the resizing element
8880 * @param {Number} size The initial size
8882 setCurrentSize : function(size){
8883 var oldAnimate = this.animate;
8884 this.animate = false;
8885 this.adapter.setElementSize(this, size);
8886 this.animate = oldAnimate;
8890 * Destroy this splitbar.
8891 * @param {Boolean} removeEl True to remove the element
8893 destroy : function(removeEl){
8898 this.proxy.parentNode.removeChild(this.proxy);
8906 * @private static Create our own proxy element element. So it will be the same same size on all browsers, we won't use borders. Instead we use a background color.
8908 Roo.SplitBar.createProxy = function(dir){
8909 var proxy = new Roo.Element(document.createElement("div"));
8910 proxy.unselectable();
8911 var cls = 'x-splitbar-proxy';
8912 proxy.addClass(cls + ' ' + (dir == Roo.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
8913 document.body.appendChild(proxy.dom);
8918 * @class Roo.SplitBar.BasicLayoutAdapter
8919 * Default Adapter. It assumes the splitter and resizing element are not positioned
8920 * elements and only gets/sets the width of the element. Generally used for table based layouts.
8922 Roo.SplitBar.BasicLayoutAdapter = function(){
8925 Roo.SplitBar.BasicLayoutAdapter.prototype = {
8926 // do nothing for now
8931 * Called before drag operations to get the current size of the resizing element.
8932 * @param {Roo.SplitBar} s The SplitBar using this adapter
8934 getElementSize : function(s){
8935 if(s.orientation == Roo.SplitBar.HORIZONTAL){
8936 return s.resizingEl.getWidth();
8938 return s.resizingEl.getHeight();
8943 * Called after drag operations to set the size of the resizing element.
8944 * @param {Roo.SplitBar} s The SplitBar using this adapter
8945 * @param {Number} newSize The new size to set
8946 * @param {Function} onComplete A function to be invoked when resizing is complete
8948 setElementSize : function(s, newSize, onComplete){
8949 if(s.orientation == Roo.SplitBar.HORIZONTAL){
8951 s.resizingEl.setWidth(newSize);
8953 onComplete(s, newSize);
8956 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
8961 s.resizingEl.setHeight(newSize);
8963 onComplete(s, newSize);
8966 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
8973 *@class Roo.SplitBar.AbsoluteLayoutAdapter
8974 * @extends Roo.SplitBar.BasicLayoutAdapter
8975 * Adapter that moves the splitter element to align with the resized sizing element.
8976 * Used with an absolute positioned SplitBar.
8977 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
8978 * document.body, make sure you assign an id to the body element.
8980 Roo.SplitBar.AbsoluteLayoutAdapter = function(container){
8981 this.basic = new Roo.SplitBar.BasicLayoutAdapter();
8982 this.container = Roo.get(container);
8985 Roo.SplitBar.AbsoluteLayoutAdapter.prototype = {
8990 getElementSize : function(s){
8991 return this.basic.getElementSize(s);
8994 setElementSize : function(s, newSize, onComplete){
8995 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
8998 moveSplitter : function(s){
8999 var yes = Roo.SplitBar;
9000 switch(s.placement){
9002 s.el.setX(s.resizingEl.getRight());
9005 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
9008 s.el.setY(s.resizingEl.getBottom());
9011 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
9018 * Orientation constant - Create a vertical SplitBar
9022 Roo.SplitBar.VERTICAL = 1;
9025 * Orientation constant - Create a horizontal SplitBar
9029 Roo.SplitBar.HORIZONTAL = 2;
9032 * Placement constant - The resizing element is to the left of the splitter element
9036 Roo.SplitBar.LEFT = 1;
9039 * Placement constant - The resizing element is to the right of the splitter element
9043 Roo.SplitBar.RIGHT = 2;
9046 * Placement constant - The resizing element is positioned above the splitter element
9050 Roo.SplitBar.TOP = 3;
9053 * Placement constant - The resizing element is positioned under splitter element
9057 Roo.SplitBar.BOTTOM = 4;
9060 * Ext JS Library 1.1.1
9061 * Copyright(c) 2006-2007, Ext JS, LLC.
9063 * Originally Released Under LGPL - original licence link has changed is not relivant.
9066 * <script type="text/javascript">
9071 * @extends Roo.util.Observable
9072 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
9073 * This class also supports single and multi selection modes. <br>
9074 * Create a data model bound view:
9076 var store = new Roo.data.Store(...);
9078 var view = new Roo.View({
9080 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
9083 selectedClass: "ydataview-selected",
9087 // listen for node click?
9088 view.on("click", function(vw, index, node, e){
9089 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
9093 dataModel.load("foobar.xml");
9095 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
9097 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
9098 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
9100 * Note: old style constructor is still suported (container, template, config)
9104 * @param {Object} config The config object
9107 Roo.View = function(config, depreciated_tpl, depreciated_config){
9109 if (typeof(depreciated_tpl) == 'undefined') {
9110 // new way.. - universal constructor.
9111 Roo.apply(this, config);
9112 this.el = Roo.get(this.el);
9115 this.el = Roo.get(config);
9116 this.tpl = depreciated_tpl;
9117 Roo.apply(this, depreciated_config);
9121 if(typeof(this.tpl) == "string"){
9122 this.tpl = new Roo.Template(this.tpl);
9124 // support xtype ctors..
9125 this.tpl = new Roo.factory(this.tpl, Roo);
9136 * @event beforeclick
9137 * Fires before a click is processed. Returns false to cancel the default action.
9138 * @param {Roo.View} this
9139 * @param {Number} index The index of the target node
9140 * @param {HTMLElement} node The target node
9141 * @param {Roo.EventObject} e The raw event object
9143 "beforeclick" : true,
9146 * Fires when a template node is clicked.
9147 * @param {Roo.View} this
9148 * @param {Number} index The index of the target node
9149 * @param {HTMLElement} node The target node
9150 * @param {Roo.EventObject} e The raw event object
9155 * Fires when a template node is double clicked.
9156 * @param {Roo.View} this
9157 * @param {Number} index The index of the target node
9158 * @param {HTMLElement} node The target node
9159 * @param {Roo.EventObject} e The raw event object
9163 * @event contextmenu
9164 * Fires when a template node is right clicked.
9165 * @param {Roo.View} this
9166 * @param {Number} index The index of the target node
9167 * @param {HTMLElement} node The target node
9168 * @param {Roo.EventObject} e The raw event object
9170 "contextmenu" : true,
9172 * @event selectionchange
9173 * Fires when the selected nodes change.
9174 * @param {Roo.View} this
9175 * @param {Array} selections Array of the selected nodes
9177 "selectionchange" : true,
9180 * @event beforeselect
9181 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
9182 * @param {Roo.View} this
9183 * @param {HTMLElement} node The node to be selected
9184 * @param {Array} selections Array of currently selected nodes
9186 "beforeselect" : true
9190 "click": this.onClick,
9191 "dblclick": this.onDblClick,
9192 "contextmenu": this.onContextMenu,
9196 this.selections = [];
9198 this.cmp = new Roo.CompositeElementLite([]);
9200 this.store = Roo.factory(this.store, Roo.data);
9201 this.setStore(this.store, true);
9203 Roo.View.superclass.constructor.call(this);
9206 Roo.extend(Roo.View, Roo.util.Observable, {
9209 * @cfg {Roo.data.Store} store Data store to load data from.
9214 * @cfg {String|Roo.Element} el The container element.
9219 * @cfg {String|Roo.Template} tpl The template used by this View
9224 * @cfg {String} selectedClass The css class to add to selected nodes
9226 selectedClass : "x-view-selected",
9228 * @cfg {String} emptyText The empty text to show when nothing is loaded.
9232 * @cfg {Boolean} multiSelect Allow multiple selection
9235 multiSelect : false,
9237 * @cfg {Boolean} singleSelect Allow single selection
9239 singleSelect: false,
9242 * Returns the element this view is bound to.
9243 * @return {Roo.Element}
9250 * Refreshes the view.
9252 refresh : function(){
9254 this.clearSelections();
9257 var records = this.store.getRange();
9258 if(records.length < 1){
9259 this.el.update(this.emptyText);
9262 for(var i = 0, len = records.length; i < len; i++){
9263 var data = this.prepareData(records[i].data, i, records[i]);
9264 html[html.length] = t.apply(data);
9266 this.el.update(html.join(""));
9267 this.nodes = this.el.dom.childNodes;
9268 this.updateIndexes(0);
9272 * Function to override to reformat the data that is sent to
9273 * the template for each node.
9274 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
9275 * a JSON object for an UpdateManager bound view).
9277 prepareData : function(data){
9281 onUpdate : function(ds, record){
9282 this.clearSelections();
9283 var index = this.store.indexOf(record);
9284 var n = this.nodes[index];
9285 this.tpl.insertBefore(n, this.prepareData(record.data));
9286 n.parentNode.removeChild(n);
9287 this.updateIndexes(index, index);
9290 onAdd : function(ds, records, index){
9291 this.clearSelections();
9292 if(this.nodes.length == 0){
9296 var n = this.nodes[index];
9297 for(var i = 0, len = records.length; i < len; i++){
9298 var d = this.prepareData(records[i].data);
9300 this.tpl.insertBefore(n, d);
9302 this.tpl.append(this.el, d);
9305 this.updateIndexes(index);
9308 onRemove : function(ds, record, index){
9309 this.clearSelections();
9310 this.el.dom.removeChild(this.nodes[index]);
9311 this.updateIndexes(index);
9315 * Refresh an individual node.
9316 * @param {Number} index
9318 refreshNode : function(index){
9319 this.onUpdate(this.store, this.store.getAt(index));
9322 updateIndexes : function(startIndex, endIndex){
9323 var ns = this.nodes;
9324 startIndex = startIndex || 0;
9325 endIndex = endIndex || ns.length - 1;
9326 for(var i = startIndex; i <= endIndex; i++){
9327 ns[i].nodeIndex = i;
9332 * Changes the data store this view uses and refresh the view.
9333 * @param {Store} store
9335 setStore : function(store, initial){
9336 if(!initial && this.store){
9337 this.store.un("datachanged", this.refresh);
9338 this.store.un("add", this.onAdd);
9339 this.store.un("remove", this.onRemove);
9340 this.store.un("update", this.onUpdate);
9341 this.store.un("clear", this.refresh);
9345 store.on("datachanged", this.refresh, this);
9346 store.on("add", this.onAdd, this);
9347 store.on("remove", this.onRemove, this);
9348 store.on("update", this.onUpdate, this);
9349 store.on("clear", this.refresh, this);
9358 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
9359 * @param {HTMLElement} node
9360 * @return {HTMLElement} The template node
9362 findItemFromChild : function(node){
9363 var el = this.el.dom;
9364 if(!node || node.parentNode == el){
9367 var p = node.parentNode;
9368 while(p && p != el){
9369 if(p.parentNode == el){
9378 onClick : function(e){
9379 var item = this.findItemFromChild(e.getTarget());
9381 var index = this.indexOf(item);
9382 if(this.onItemClick(item, index, e) !== false){
9383 this.fireEvent("click", this, index, item, e);
9386 this.clearSelections();
9391 onContextMenu : function(e){
9392 var item = this.findItemFromChild(e.getTarget());
9394 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
9399 onDblClick : function(e){
9400 var item = this.findItemFromChild(e.getTarget());
9402 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
9406 onItemClick : function(item, index, e){
9407 if(this.fireEvent("beforeclick", this, index, item, e) === false){
9410 if(this.multiSelect || this.singleSelect){
9411 if(this.multiSelect && e.shiftKey && this.lastSelection){
9412 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
9414 this.select(item, this.multiSelect && e.ctrlKey);
9415 this.lastSelection = item;
9423 * Get the number of selected nodes.
9426 getSelectionCount : function(){
9427 return this.selections.length;
9431 * Get the currently selected nodes.
9432 * @return {Array} An array of HTMLElements
9434 getSelectedNodes : function(){
9435 return this.selections;
9439 * Get the indexes of the selected nodes.
9442 getSelectedIndexes : function(){
9443 var indexes = [], s = this.selections;
9444 for(var i = 0, len = s.length; i < len; i++){
9445 indexes.push(s[i].nodeIndex);
9451 * Clear all selections
9452 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
9454 clearSelections : function(suppressEvent){
9455 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
9456 this.cmp.elements = this.selections;
9457 this.cmp.removeClass(this.selectedClass);
9458 this.selections = [];
9460 this.fireEvent("selectionchange", this, this.selections);
9466 * Returns true if the passed node is selected
9467 * @param {HTMLElement/Number} node The node or node index
9470 isSelected : function(node){
9471 var s = this.selections;
9475 node = this.getNode(node);
9476 return s.indexOf(node) !== -1;
9481 * @param {Array/HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node, id of a template node or an array of any of those to select
9482 * @param {Boolean} keepExisting (optional) true to keep existing selections
9483 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
9485 select : function(nodeInfo, keepExisting, suppressEvent){
9486 if(nodeInfo instanceof Array){
9488 this.clearSelections(true);
9490 for(var i = 0, len = nodeInfo.length; i < len; i++){
9491 this.select(nodeInfo[i], true, true);
9494 var node = this.getNode(nodeInfo);
9495 if(node && !this.isSelected(node)){
9497 this.clearSelections(true);
9499 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
9500 Roo.fly(node).addClass(this.selectedClass);
9501 this.selections.push(node);
9503 this.fireEvent("selectionchange", this, this.selections);
9511 * Gets a template node.
9512 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
9513 * @return {HTMLElement} The node or null if it wasn't found
9515 getNode : function(nodeInfo){
9516 if(typeof nodeInfo == "string"){
9517 return document.getElementById(nodeInfo);
9518 }else if(typeof nodeInfo == "number"){
9519 return this.nodes[nodeInfo];
9525 * Gets a range template nodes.
9526 * @param {Number} startIndex
9527 * @param {Number} endIndex
9528 * @return {Array} An array of nodes
9530 getNodes : function(start, end){
9531 var ns = this.nodes;
9533 end = typeof end == "undefined" ? ns.length - 1 : end;
9536 for(var i = start; i <= end; i++){
9540 for(var i = start; i >= end; i--){
9548 * Finds the index of the passed node
9549 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
9550 * @return {Number} The index of the node or -1
9552 indexOf : function(node){
9553 node = this.getNode(node);
9554 if(typeof node.nodeIndex == "number"){
9555 return node.nodeIndex;
9557 var ns = this.nodes;
9558 for(var i = 0, len = ns.length; i < len; i++){
9568 * Ext JS Library 1.1.1
9569 * Copyright(c) 2006-2007, Ext JS, LLC.
9571 * Originally Released Under LGPL - original licence link has changed is not relivant.
9574 * <script type="text/javascript">
9578 * @class Roo.JsonView
9580 * Shortcut class to create a JSON + {@link Roo.UpdateManager} template view. Usage:
9582 var view = new Roo.JsonView({
9583 container: "my-element",
9584 tpl: '<div id="{id}">{foo} - {bar}</div>', // auto create template
9589 // listen for node click?
9590 view.on("click", function(vw, index, node, e){
9591 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
9594 // direct load of JSON data
9595 view.load("foobar.php");
9597 // Example from my blog list
9598 var tpl = new Roo.Template(
9599 '<div class="entry">' +
9600 '<a class="entry-title" href="{link}">{title}</a>' +
9601 "<h4>{date} by {author} | {comments} Comments</h4>{description}" +
9602 "</div><hr />"
9605 var moreView = new Roo.JsonView({
9606 container : "entry-list",
9610 moreView.on("beforerender", this.sortEntries, this);
9612 url: "/blog/get-posts.php",
9613 params: "allposts=true",
9614 text: "Loading Blog Entries..."
9618 * Note: old code is supported with arguments : (container, template, config)
9622 * Create a new JsonView
9624 * @param {Object} config The config object
9627 Roo.JsonView = function(config, depreciated_tpl, depreciated_config){
9630 Roo.JsonView.superclass.constructor.call(this, config, depreciated_tpl, depreciated_config);
9632 var um = this.el.getUpdateManager();
9633 um.setRenderer(this);
9634 um.on("update", this.onLoad, this);
9635 um.on("failure", this.onLoadException, this);
9638 * @event beforerender
9639 * Fires before rendering of the downloaded JSON data.
9640 * @param {Roo.JsonView} this
9641 * @param {Object} data The JSON data loaded
9645 * Fires when data is loaded.
9646 * @param {Roo.JsonView} this
9647 * @param {Object} data The JSON data loaded
9648 * @param {Object} response The raw Connect response object
9651 * @event loadexception
9652 * Fires when loading fails.
9653 * @param {Roo.JsonView} this
9654 * @param {Object} response The raw Connect response object
9657 'beforerender' : true,
9659 'loadexception' : true
9662 Roo.extend(Roo.JsonView, Roo.View, {
9664 * @type {String} The root property in the loaded JSON object that contains the data
9669 * Refreshes the view.
9671 refresh : function(){
9672 this.clearSelections();
9675 var o = this.jsonData;
9676 if(o && o.length > 0){
9677 for(var i = 0, len = o.length; i < len; i++){
9678 var data = this.prepareData(o[i], i, o);
9679 html[html.length] = this.tpl.apply(data);
9682 html.push(this.emptyText);
9684 this.el.update(html.join(""));
9685 this.nodes = this.el.dom.childNodes;
9686 this.updateIndexes(0);
9690 * Performs an async HTTP request, and loads the JSON from the response. If <i>params</i> are specified it uses POST, otherwise it uses GET.
9691 * @param {Object/String/Function} url The URL for this request, or a function to call to get the URL, or a config object containing any of the following options:
9694 url: "your-url.php",
9695 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
9696 callback: yourFunction,
9697 scope: yourObject, //(optional scope)
9705 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
9706 * are respectively shorthand for <i>disableCaching</i>, <i>indicatorText</i>, and <i>loadScripts</i> and are used to set their associated property on this UpdateManager instance.
9707 * @param {String/Object} params (optional) The parameters to pass, as either a URL encoded string "param1=1&param2=2" or an object {param1: 1, param2: 2}
9708 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
9709 * @param {Boolean} discardUrl (optional) By default when you execute an update the defaultUrl is changed to the last used URL. If true, it will not store the URL.
9712 var um = this.el.getUpdateManager();
9713 um.update.apply(um, arguments);
9716 render : function(el, response){
9717 this.clearSelections();
9721 o = Roo.util.JSON.decode(response.responseText);
9724 o = o[this.jsonRoot];
9729 * The current JSON data or null
9732 this.beforeRender();
9737 * Get the number of records in the current JSON dataset
9740 getCount : function(){
9741 return this.jsonData ? this.jsonData.length : 0;
9745 * Returns the JSON object for the specified node(s)
9746 * @param {HTMLElement/Array} node The node or an array of nodes
9747 * @return {Object/Array} If you pass in an array, you get an array back, otherwise
9748 * you get the JSON object for the node
9750 getNodeData : function(node){
9751 if(node instanceof Array){
9753 for(var i = 0, len = node.length; i < len; i++){
9754 data.push(this.getNodeData(node[i]));
9758 return this.jsonData[this.indexOf(node)] || null;
9761 beforeRender : function(){
9762 this.snapshot = this.jsonData;
9764 this.sort.apply(this, this.sortInfo);
9766 this.fireEvent("beforerender", this, this.jsonData);
9769 onLoad : function(el, o){
9770 this.fireEvent("load", this, this.jsonData, o);
9773 onLoadException : function(el, o){
9774 this.fireEvent("loadexception", this, o);
9778 * Filter the data by a specific property.
9779 * @param {String} property A property on your JSON objects
9780 * @param {String/RegExp} value Either string that the property values
9781 * should start with, or a RegExp to test against the property
9783 filter : function(property, value){
9786 var ss = this.snapshot;
9787 if(typeof value == "string"){
9788 var vlen = value.length;
9793 value = value.toLowerCase();
9794 for(var i = 0, len = ss.length; i < len; i++){
9796 if(o[property].substr(0, vlen).toLowerCase() == value){
9800 } else if(value.exec){ // regex?
9801 for(var i = 0, len = ss.length; i < len; i++){
9803 if(value.test(o[property])){
9810 this.jsonData = data;
9816 * Filter by a function. The passed function will be called with each
9817 * object in the current dataset. If the function returns true the value is kept,
9818 * otherwise it is filtered.
9819 * @param {Function} fn
9820 * @param {Object} scope (optional) The scope of the function (defaults to this JsonView)
9822 filterBy : function(fn, scope){
9825 var ss = this.snapshot;
9826 for(var i = 0, len = ss.length; i < len; i++){
9828 if(fn.call(scope || this, o)){
9832 this.jsonData = data;
9838 * Clears the current filter.
9840 clearFilter : function(){
9841 if(this.snapshot && this.jsonData != this.snapshot){
9842 this.jsonData = this.snapshot;
9849 * Sorts the data for this view and refreshes it.
9850 * @param {String} property A property on your JSON objects to sort on
9851 * @param {String} direction (optional) "desc" or "asc" (defaults to "asc")
9852 * @param {Function} sortType (optional) A function to call to convert the data to a sortable value.
9854 sort : function(property, dir, sortType){
9855 this.sortInfo = Array.prototype.slice.call(arguments, 0);
9858 var dsc = dir && dir.toLowerCase() == "desc";
9859 var f = function(o1, o2){
9860 var v1 = sortType ? sortType(o1[p]) : o1[p];
9861 var v2 = sortType ? sortType(o2[p]) : o2[p];
9864 return dsc ? +1 : -1;
9866 return dsc ? -1 : +1;
9871 this.jsonData.sort(f);
9873 if(this.jsonData != this.snapshot){
9874 this.snapshot.sort(f);
9880 * Ext JS Library 1.1.1
9881 * Copyright(c) 2006-2007, Ext JS, LLC.
9883 * Originally Released Under LGPL - original licence link has changed is not relivant.
9886 * <script type="text/javascript">
9891 * @class Roo.ColorPalette
9892 * @extends Roo.Component
9893 * Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
9894 * Here's an example of typical usage:
9896 var cp = new Roo.ColorPalette({value:'993300'}); // initial selected color
9897 cp.render('my-div');
9899 cp.on('select', function(palette, selColor){
9900 // do something with selColor
9904 * Create a new ColorPalette
9905 * @param {Object} config The config object
9907 Roo.ColorPalette = function(config){
9908 Roo.ColorPalette.superclass.constructor.call(this, config);
9912 * Fires when a color is selected
9913 * @param {ColorPalette} this
9914 * @param {String} color The 6-digit color hex code (without the # symbol)
9920 this.on("select", this.handler, this.scope, true);
9923 Roo.extend(Roo.ColorPalette, Roo.Component, {
9925 * @cfg {String} itemCls
9926 * The CSS class to apply to the containing element (defaults to "x-color-palette")
9928 itemCls : "x-color-palette",
9930 * @cfg {String} value
9931 * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
9932 * the hex codes are case-sensitive.
9937 ctype: "Roo.ColorPalette",
9940 * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the selection event
9942 allowReselect : false,
9945 * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
9946 * of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
9947 * the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
9948 * of colors with the width setting until the box is symmetrical.</p>
9949 * <p>You can override individual colors if needed:</p>
9951 var cp = new Roo.ColorPalette();
9952 cp.colors[0] = "FF0000"; // change the first box to red
9955 Or you can provide a custom array of your own for complete control:
9957 var cp = new Roo.ColorPalette();
9958 cp.colors = ["000000", "993300", "333300"];
9963 "000000", "993300", "333300", "003300", "003366", "000080", "333399", "333333",
9964 "800000", "FF6600", "808000", "008000", "008080", "0000FF", "666699", "808080",
9965 "FF0000", "FF9900", "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696",
9966 "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF", "993366", "C0C0C0",
9967 "FF99CC", "FFCC99", "FFFF99", "CCFFCC", "CCFFFF", "99CCFF", "CC99FF", "FFFFFF"
9971 onRender : function(container, position){
9972 var t = new Roo.MasterTemplate(
9973 '<tpl><a href="#" class="color-{0}" hidefocus="on"><em><span style="background:#{0}" unselectable="on"> </span></em></a></tpl>'
9975 var c = this.colors;
9976 for(var i = 0, len = c.length; i < len; i++){
9979 var el = document.createElement("div");
9980 el.className = this.itemCls;
9982 container.dom.insertBefore(el, position);
9983 this.el = Roo.get(el);
9984 this.el.on(this.clickEvent, this.handleClick, this, {delegate: "a"});
9985 if(this.clickEvent != 'click'){
9986 this.el.on('click', Roo.emptyFn, this, {delegate: "a", preventDefault:true});
9991 afterRender : function(){
9992 Roo.ColorPalette.superclass.afterRender.call(this);
10001 handleClick : function(e, t){
10002 e.preventDefault();
10003 if(!this.disabled){
10004 var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
10005 this.select(c.toUpperCase());
10010 * Selects the specified color in the palette (fires the select event)
10011 * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
10013 select : function(color){
10014 color = color.replace("#", "");
10015 if(color != this.value || this.allowReselect){
10018 el.child("a.color-"+this.value).removeClass("x-color-palette-sel");
10020 el.child("a.color-"+color).addClass("x-color-palette-sel");
10021 this.value = color;
10022 this.fireEvent("select", this, color);
10027 * Ext JS Library 1.1.1
10028 * Copyright(c) 2006-2007, Ext JS, LLC.
10030 * Originally Released Under LGPL - original licence link has changed is not relivant.
10033 * <script type="text/javascript">
10037 * @class Roo.DatePicker
10038 * @extends Roo.Component
10039 * Simple date picker class.
10041 * Create a new DatePicker
10042 * @param {Object} config The config object
10044 Roo.DatePicker = function(config){
10045 Roo.DatePicker.superclass.constructor.call(this, config);
10047 this.value = config && config.value ?
10048 config.value.clearTime() : new Date().clearTime();
10053 * Fires when a date is selected
10054 * @param {DatePicker} this
10055 * @param {Date} date The selected date
10061 this.on("select", this.handler, this.scope || this);
10063 // build the disabledDatesRE
10064 if(!this.disabledDatesRE && this.disabledDates){
10065 var dd = this.disabledDates;
10067 for(var i = 0; i < dd.length; i++){
10069 if(i != dd.length-1) re += "|";
10071 this.disabledDatesRE = new RegExp(re + ")");
10075 Roo.extend(Roo.DatePicker, Roo.Component, {
10077 * @cfg {String} todayText
10078 * The text to display on the button that selects the current date (defaults to "Today")
10080 todayText : "Today",
10082 * @cfg {String} okText
10083 * The text to display on the ok button
10085 okText : " OK ", //   to give the user extra clicking room
10087 * @cfg {String} cancelText
10088 * The text to display on the cancel button
10090 cancelText : "Cancel",
10092 * @cfg {String} todayTip
10093 * The tooltip to display for the button that selects the current date (defaults to "{current date} (Spacebar)")
10095 todayTip : "{0} (Spacebar)",
10097 * @cfg {Date} minDate
10098 * Minimum allowable date (JavaScript date object, defaults to null)
10102 * @cfg {Date} maxDate
10103 * Maximum allowable date (JavaScript date object, defaults to null)
10107 * @cfg {String} minText
10108 * The error text to display if the minDate validation fails (defaults to "This date is before the minimum date")
10110 minText : "This date is before the minimum date",
10112 * @cfg {String} maxText
10113 * The error text to display if the maxDate validation fails (defaults to "This date is after the maximum date")
10115 maxText : "This date is after the maximum date",
10117 * @cfg {String} format
10118 * The default date format string which can be overriden for localization support. The format must be
10119 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
10123 * @cfg {Array} disabledDays
10124 * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
10126 disabledDays : null,
10128 * @cfg {String} disabledDaysText
10129 * The tooltip to display when the date falls on a disabled day (defaults to "")
10131 disabledDaysText : "",
10133 * @cfg {RegExp} disabledDatesRE
10134 * JavaScript regular expression used to disable a pattern of dates (defaults to null)
10136 disabledDatesRE : null,
10138 * @cfg {String} disabledDatesText
10139 * The tooltip text to display when the date falls on a disabled date (defaults to "")
10141 disabledDatesText : "",
10143 * @cfg {Boolean} constrainToViewport
10144 * True to constrain the date picker to the viewport (defaults to true)
10146 constrainToViewport : true,
10148 * @cfg {Array} monthNames
10149 * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
10151 monthNames : Date.monthNames,
10153 * @cfg {Array} dayNames
10154 * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
10156 dayNames : Date.dayNames,
10158 * @cfg {String} nextText
10159 * The next month navigation button tooltip (defaults to 'Next Month (Control+Right)')
10161 nextText: 'Next Month (Control+Right)',
10163 * @cfg {String} prevText
10164 * The previous month navigation button tooltip (defaults to 'Previous Month (Control+Left)')
10166 prevText: 'Previous Month (Control+Left)',
10168 * @cfg {String} monthYearText
10169 * The header month selector tooltip (defaults to 'Choose a month (Control+Up/Down to move years)')
10171 monthYearText: 'Choose a month (Control+Up/Down to move years)',
10173 * @cfg {Number} startDay
10174 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
10178 * @cfg {Bool} showClear
10179 * Show a clear button (usefull for date form elements that can be blank.)
10185 * Sets the value of the date field
10186 * @param {Date} value The date to set
10188 setValue : function(value){
10189 var old = this.value;
10190 this.value = value.clearTime(true);
10192 this.update(this.value);
10197 * Gets the current selected value of the date field
10198 * @return {Date} The selected date
10200 getValue : function(){
10205 focus : function(){
10207 this.update(this.activeDate);
10212 onRender : function(container, position){
10214 '<table cellspacing="0">',
10215 '<tr><td class="x-date-left"><a href="#" title="', this.prevText ,'"> </a></td><td class="x-date-middle" align="center"></td><td class="x-date-right"><a href="#" title="', this.nextText ,'"> </a></td></tr>',
10216 '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'];
10217 var dn = this.dayNames;
10218 for(var i = 0; i < 7; i++){
10219 var d = this.startDay+i;
10223 m.push("<th><span>", dn[d].substr(0,1), "</span></th>");
10225 m[m.length] = "</tr></thead><tbody><tr>";
10226 for(var i = 0; i < 42; i++) {
10227 if(i % 7 == 0 && i != 0){
10228 m[m.length] = "</tr><tr>";
10230 m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
10232 m[m.length] = '</tr></tbody></table></td></tr><tr>'+
10233 '<td colspan="3" class="x-date-bottom" align="center"></td></tr></table><div class="x-date-mp"></div>';
10235 var el = document.createElement("div");
10236 el.className = "x-date-picker";
10237 el.innerHTML = m.join("");
10239 container.dom.insertBefore(el, position);
10241 this.el = Roo.get(el);
10242 this.eventEl = Roo.get(el.firstChild);
10244 new Roo.util.ClickRepeater(this.el.child("td.x-date-left a"), {
10245 handler: this.showPrevMonth,
10247 preventDefault:true,
10251 new Roo.util.ClickRepeater(this.el.child("td.x-date-right a"), {
10252 handler: this.showNextMonth,
10254 preventDefault:true,
10258 this.eventEl.on("mousewheel", this.handleMouseWheel, this);
10260 this.monthPicker = this.el.down('div.x-date-mp');
10261 this.monthPicker.enableDisplayMode('block');
10263 var kn = new Roo.KeyNav(this.eventEl, {
10264 "left" : function(e){
10266 this.showPrevMonth() :
10267 this.update(this.activeDate.add("d", -1));
10270 "right" : function(e){
10272 this.showNextMonth() :
10273 this.update(this.activeDate.add("d", 1));
10276 "up" : function(e){
10278 this.showNextYear() :
10279 this.update(this.activeDate.add("d", -7));
10282 "down" : function(e){
10284 this.showPrevYear() :
10285 this.update(this.activeDate.add("d", 7));
10288 "pageUp" : function(e){
10289 this.showNextMonth();
10292 "pageDown" : function(e){
10293 this.showPrevMonth();
10296 "enter" : function(e){
10297 e.stopPropagation();
10304 this.eventEl.on("click", this.handleDateClick, this, {delegate: "a.x-date-date"});
10306 this.eventEl.addKeyListener(Roo.EventObject.SPACE, this.selectToday, this);
10308 this.el.unselectable();
10310 this.cells = this.el.select("table.x-date-inner tbody td");
10311 this.textNodes = this.el.query("table.x-date-inner tbody span");
10313 this.mbtn = new Roo.Button(this.el.child("td.x-date-middle", true), {
10315 tooltip: this.monthYearText
10318 this.mbtn.on('click', this.showMonthPicker, this);
10319 this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu");
10322 var today = (new Date()).dateFormat(this.format);
10324 var baseTb = new Roo.Toolbar(this.el.child("td.x-date-bottom", true));
10325 if (this.showClear) {
10326 baseTb.add( new Roo.Toolbar.Fill());
10329 text: String.format(this.todayText, today),
10330 tooltip: String.format(this.todayTip, today),
10331 handler: this.selectToday,
10335 //var todayBtn = new Roo.Button(this.el.child("td.x-date-bottom", true), {
10338 if (this.showClear) {
10340 baseTb.add( new Roo.Toolbar.Fill());
10343 cls: 'x-btn-icon x-btn-clear',
10344 handler: function() {
10346 this.fireEvent("select", this, '');
10356 this.update(this.value);
10359 createMonthPicker : function(){
10360 if(!this.monthPicker.dom.firstChild){
10361 var buf = ['<table border="0" cellspacing="0">'];
10362 for(var i = 0; i < 6; i++){
10364 '<tr><td class="x-date-mp-month"><a href="#">', this.monthNames[i].substr(0, 3), '</a></td>',
10365 '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', this.monthNames[i+6].substr(0, 3), '</a></td>',
10367 '<td class="x-date-mp-ybtn" align="center"><a class="x-date-mp-prev"></a></td><td class="x-date-mp-ybtn" align="center"><a class="x-date-mp-next"></a></td></tr>' :
10368 '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
10372 '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
10374 '</button><button type="button" class="x-date-mp-cancel">',
10376 '</button></td></tr>',
10379 this.monthPicker.update(buf.join(''));
10380 this.monthPicker.on('click', this.onMonthClick, this);
10381 this.monthPicker.on('dblclick', this.onMonthDblClick, this);
10383 this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
10384 this.mpYears = this.monthPicker.select('td.x-date-mp-year');
10386 this.mpMonths.each(function(m, a, i){
10389 m.dom.xmonth = 5 + Math.round(i * .5);
10391 m.dom.xmonth = Math.round((i-1) * .5);
10397 showMonthPicker : function(){
10398 this.createMonthPicker();
10399 var size = this.el.getSize();
10400 this.monthPicker.setSize(size);
10401 this.monthPicker.child('table').setSize(size);
10403 this.mpSelMonth = (this.activeDate || this.value).getMonth();
10404 this.updateMPMonth(this.mpSelMonth);
10405 this.mpSelYear = (this.activeDate || this.value).getFullYear();
10406 this.updateMPYear(this.mpSelYear);
10408 this.monthPicker.slideIn('t', {duration:.2});
10411 updateMPYear : function(y){
10413 var ys = this.mpYears.elements;
10414 for(var i = 1; i <= 10; i++){
10415 var td = ys[i-1], y2;
10417 y2 = y + Math.round(i * .5);
10418 td.firstChild.innerHTML = y2;
10421 y2 = y - (5-Math.round(i * .5));
10422 td.firstChild.innerHTML = y2;
10425 this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
10429 updateMPMonth : function(sm){
10430 this.mpMonths.each(function(m, a, i){
10431 m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
10435 selectMPMonth: function(m){
10439 onMonthClick : function(e, t){
10441 var el = new Roo.Element(t), pn;
10442 if(el.is('button.x-date-mp-cancel')){
10443 this.hideMonthPicker();
10445 else if(el.is('button.x-date-mp-ok')){
10446 this.update(new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
10447 this.hideMonthPicker();
10449 else if(pn = el.up('td.x-date-mp-month', 2)){
10450 this.mpMonths.removeClass('x-date-mp-sel');
10451 pn.addClass('x-date-mp-sel');
10452 this.mpSelMonth = pn.dom.xmonth;
10454 else if(pn = el.up('td.x-date-mp-year', 2)){
10455 this.mpYears.removeClass('x-date-mp-sel');
10456 pn.addClass('x-date-mp-sel');
10457 this.mpSelYear = pn.dom.xyear;
10459 else if(el.is('a.x-date-mp-prev')){
10460 this.updateMPYear(this.mpyear-10);
10462 else if(el.is('a.x-date-mp-next')){
10463 this.updateMPYear(this.mpyear+10);
10467 onMonthDblClick : function(e, t){
10469 var el = new Roo.Element(t), pn;
10470 if(pn = el.up('td.x-date-mp-month', 2)){
10471 this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
10472 this.hideMonthPicker();
10474 else if(pn = el.up('td.x-date-mp-year', 2)){
10475 this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
10476 this.hideMonthPicker();
10480 hideMonthPicker : function(disableAnim){
10481 if(this.monthPicker){
10482 if(disableAnim === true){
10483 this.monthPicker.hide();
10485 this.monthPicker.slideOut('t', {duration:.2});
10491 showPrevMonth : function(e){
10492 this.update(this.activeDate.add("mo", -1));
10496 showNextMonth : function(e){
10497 this.update(this.activeDate.add("mo", 1));
10501 showPrevYear : function(){
10502 this.update(this.activeDate.add("y", -1));
10506 showNextYear : function(){
10507 this.update(this.activeDate.add("y", 1));
10511 handleMouseWheel : function(e){
10512 var delta = e.getWheelDelta();
10514 this.showPrevMonth();
10516 } else if(delta < 0){
10517 this.showNextMonth();
10523 handleDateClick : function(e, t){
10525 if(t.dateValue && !Roo.fly(t.parentNode).hasClass("x-date-disabled")){
10526 this.setValue(new Date(t.dateValue));
10527 this.fireEvent("select", this, this.value);
10532 selectToday : function(){
10533 this.setValue(new Date().clearTime());
10534 this.fireEvent("select", this, this.value);
10538 update : function(date){
10539 var vd = this.activeDate;
10540 this.activeDate = date;
10542 var t = date.getTime();
10543 if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
10544 this.cells.removeClass("x-date-selected");
10545 this.cells.each(function(c){
10546 if(c.dom.firstChild.dateValue == t){
10547 c.addClass("x-date-selected");
10548 setTimeout(function(){
10549 try{c.dom.firstChild.focus();}catch(e){}
10557 var days = date.getDaysInMonth();
10558 var firstOfMonth = date.getFirstDateOfMonth();
10559 var startingPos = firstOfMonth.getDay()-this.startDay;
10561 if(startingPos <= this.startDay){
10565 var pm = date.add("mo", -1);
10566 var prevStart = pm.getDaysInMonth()-startingPos;
10568 var cells = this.cells.elements;
10569 var textEls = this.textNodes;
10570 days += startingPos;
10572 // convert everything to numbers so it's fast
10573 var day = 86400000;
10574 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
10575 var today = new Date().clearTime().getTime();
10576 var sel = date.clearTime().getTime();
10577 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
10578 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
10579 var ddMatch = this.disabledDatesRE;
10580 var ddText = this.disabledDatesText;
10581 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
10582 var ddaysText = this.disabledDaysText;
10583 var format = this.format;
10585 var setCellClass = function(cal, cell){
10587 var t = d.getTime();
10588 cell.firstChild.dateValue = t;
10590 cell.className += " x-date-today";
10591 cell.title = cal.todayText;
10594 cell.className += " x-date-selected";
10595 setTimeout(function(){
10596 try{cell.firstChild.focus();}catch(e){}
10601 cell.className = " x-date-disabled";
10602 cell.title = cal.minText;
10606 cell.className = " x-date-disabled";
10607 cell.title = cal.maxText;
10611 if(ddays.indexOf(d.getDay()) != -1){
10612 cell.title = ddaysText;
10613 cell.className = " x-date-disabled";
10616 if(ddMatch && format){
10617 var fvalue = d.dateFormat(format);
10618 if(ddMatch.test(fvalue)){
10619 cell.title = ddText.replace("%0", fvalue);
10620 cell.className = " x-date-disabled";
10626 for(; i < startingPos; i++) {
10627 textEls[i].innerHTML = (++prevStart);
10628 d.setDate(d.getDate()+1);
10629 cells[i].className = "x-date-prevday";
10630 setCellClass(this, cells[i]);
10632 for(; i < days; i++){
10633 intDay = i - startingPos + 1;
10634 textEls[i].innerHTML = (intDay);
10635 d.setDate(d.getDate()+1);
10636 cells[i].className = "x-date-active";
10637 setCellClass(this, cells[i]);
10640 for(; i < 42; i++) {
10641 textEls[i].innerHTML = (++extraDays);
10642 d.setDate(d.getDate()+1);
10643 cells[i].className = "x-date-nextday";
10644 setCellClass(this, cells[i]);
10647 this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear());
10649 if(!this.internalRender){
10650 var main = this.el.dom.firstChild;
10651 var w = main.offsetWidth;
10652 this.el.setWidth(w + this.el.getBorderWidth("lr"));
10653 Roo.fly(main).setWidth(w);
10654 this.internalRender = true;
10655 // opera does not respect the auto grow header center column
10656 // then, after it gets a width opera refuses to recalculate
10657 // without a second pass
10658 if(Roo.isOpera && !this.secondPass){
10659 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
10660 this.secondPass = true;
10661 this.update.defer(10, this, [date]);
10667 * Ext JS Library 1.1.1
10668 * Copyright(c) 2006-2007, Ext JS, LLC.
10670 * Originally Released Under LGPL - original licence link has changed is not relivant.
10673 * <script type="text/javascript">
10676 * @class Roo.TabPanel
10677 * @extends Roo.util.Observable
10678 * A lightweight tab container.
10682 // basic tabs 1, built from existing content
10683 var tabs = new Roo.TabPanel("tabs1");
10684 tabs.addTab("script", "View Script");
10685 tabs.addTab("markup", "View Markup");
10686 tabs.activate("script");
10688 // more advanced tabs, built from javascript
10689 var jtabs = new Roo.TabPanel("jtabs");
10690 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
10692 // set up the UpdateManager
10693 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
10694 var updater = tab2.getUpdateManager();
10695 updater.setDefaultUrl("ajax1.htm");
10696 tab2.on('activate', updater.refresh, updater, true);
10698 // Use setUrl for Ajax loading
10699 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
10700 tab3.setUrl("ajax2.htm", null, true);
10703 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
10706 jtabs.activate("jtabs-1");
10709 * Create a new TabPanel.
10710 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
10711 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
10713 Roo.TabPanel = function(container, config){
10715 * The container element for this TabPanel.
10716 * @type Roo.Element
10718 this.el = Roo.get(container, true);
10720 if(typeof config == "boolean"){
10721 this.tabPosition = config ? "bottom" : "top";
10723 Roo.apply(this, config);
10726 if(this.tabPosition == "bottom"){
10727 this.bodyEl = Roo.get(this.createBody(this.el.dom));
10728 this.el.addClass("x-tabs-bottom");
10730 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
10731 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
10732 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
10734 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
10736 if(this.tabPosition != "bottom"){
10737 /** The body element that contains {@link Roo.TabPanelItem} bodies.
10738 * @type Roo.Element
10740 this.bodyEl = Roo.get(this.createBody(this.el.dom));
10741 this.el.addClass("x-tabs-top");
10745 this.bodyEl.setStyle("position", "relative");
10747 this.active = null;
10748 this.activateDelegate = this.activate.createDelegate(this);
10753 * Fires when the active tab changes
10754 * @param {Roo.TabPanel} this
10755 * @param {Roo.TabPanelItem} activePanel The new active tab
10759 * @event beforetabchange
10760 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
10761 * @param {Roo.TabPanel} this
10762 * @param {Object} e Set cancel to true on this object to cancel the tab change
10763 * @param {Roo.TabPanelItem} tab The tab being changed to
10765 "beforetabchange" : true
10768 Roo.EventManager.onWindowResize(this.onResize, this);
10769 this.cpad = this.el.getPadding("lr");
10770 this.hiddenCount = 0;
10772 Roo.TabPanel.superclass.constructor.call(this);
10775 Roo.extend(Roo.TabPanel, Roo.util.Observable, {
10777 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
10779 tabPosition : "top",
10781 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
10783 currentTabWidth : 0,
10785 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
10789 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
10793 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
10795 preferredTabWidth : 175,
10797 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
10799 resizeTabs : false,
10801 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
10803 monitorResize : true,
10806 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
10807 * @param {String} id The id of the div to use <b>or create</b>
10808 * @param {String} text The text for the tab
10809 * @param {String} content (optional) Content to put in the TabPanelItem body
10810 * @param {Boolean} closable (optional) True to create a close icon on the tab
10811 * @return {Roo.TabPanelItem} The created TabPanelItem
10813 addTab : function(id, text, content, closable){
10814 var item = new Roo.TabPanelItem(this, id, text, closable);
10815 this.addTabItem(item);
10817 item.setContent(content);
10823 * Returns the {@link Roo.TabPanelItem} with the specified id/index
10824 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
10825 * @return {Roo.TabPanelItem}
10827 getTab : function(id){
10828 return this.items[id];
10832 * Hides the {@link Roo.TabPanelItem} with the specified id/index
10833 * @param {String/Number} id The id or index of the TabPanelItem to hide.
10835 hideTab : function(id){
10836 var t = this.items[id];
10839 this.hiddenCount++;
10840 this.autoSizeTabs();
10845 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
10846 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
10848 unhideTab : function(id){
10849 var t = this.items[id];
10851 t.setHidden(false);
10852 this.hiddenCount--;
10853 this.autoSizeTabs();
10858 * Adds an existing {@link Roo.TabPanelItem}.
10859 * @param {Roo.TabPanelItem} item The TabPanelItem to add
10861 addTabItem : function(item){
10862 this.items[item.id] = item;
10863 this.items.push(item);
10864 if(this.resizeTabs){
10865 item.setWidth(this.currentTabWidth || this.preferredTabWidth);
10866 this.autoSizeTabs();
10873 * Removes a {@link Roo.TabPanelItem}.
10874 * @param {String/Number} id The id or index of the TabPanelItem to remove.
10876 removeTab : function(id){
10877 var items = this.items;
10878 var tab = items[id];
10879 if(!tab) { return; }
10880 var index = items.indexOf(tab);
10881 if(this.active == tab && items.length > 1){
10882 var newTab = this.getNextAvailable(index);
10887 this.stripEl.dom.removeChild(tab.pnode.dom);
10888 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
10889 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
10891 items.splice(index, 1);
10892 delete this.items[tab.id];
10893 tab.fireEvent("close", tab);
10894 tab.purgeListeners();
10895 this.autoSizeTabs();
10898 getNextAvailable : function(start){
10899 var items = this.items;
10901 // look for a next tab that will slide over to
10902 // replace the one being removed
10903 while(index < items.length){
10904 var item = items[++index];
10905 if(item && !item.isHidden()){
10909 // if one isn't found select the previous tab (on the left)
10912 var item = items[--index];
10913 if(item && !item.isHidden()){
10921 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
10922 * @param {String/Number} id The id or index of the TabPanelItem to disable.
10924 disableTab : function(id){
10925 var tab = this.items[id];
10926 if(tab && this.active != tab){
10932 * Enables a {@link Roo.TabPanelItem} that is disabled.
10933 * @param {String/Number} id The id or index of the TabPanelItem to enable.
10935 enableTab : function(id){
10936 var tab = this.items[id];
10941 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
10942 * @param {String/Number} id The id or index of the TabPanelItem to activate.
10943 * @return {Roo.TabPanelItem} The TabPanelItem.
10945 activate : function(id){
10946 var tab = this.items[id];
10950 if(tab == this.active || tab.disabled){
10954 this.fireEvent("beforetabchange", this, e, tab);
10955 if(e.cancel !== true && !tab.disabled){
10957 this.active.hide();
10959 this.active = this.items[id];
10960 this.active.show();
10961 this.fireEvent("tabchange", this, this.active);
10967 * Gets the active {@link Roo.TabPanelItem}.
10968 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
10970 getActiveTab : function(){
10971 return this.active;
10975 * Updates the tab body element to fit the height of the container element
10976 * for overflow scrolling
10977 * @param {Number} targetHeight (optional) Override the starting height from the elements height
10979 syncHeight : function(targetHeight){
10980 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
10981 var bm = this.bodyEl.getMargins();
10982 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
10983 this.bodyEl.setHeight(newHeight);
10987 onResize : function(){
10988 if(this.monitorResize){
10989 this.autoSizeTabs();
10994 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
10996 beginUpdate : function(){
10997 this.updating = true;
11001 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
11003 endUpdate : function(){
11004 this.updating = false;
11005 this.autoSizeTabs();
11009 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
11011 autoSizeTabs : function(){
11012 var count = this.items.length;
11013 var vcount = count - this.hiddenCount;
11014 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) return;
11015 var w = Math.max(this.el.getWidth() - this.cpad, 10);
11016 var availWidth = Math.floor(w / vcount);
11017 var b = this.stripBody;
11018 if(b.getWidth() > w){
11019 var tabs = this.items;
11020 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
11021 if(availWidth < this.minTabWidth){
11022 /*if(!this.sleft){ // incomplete scrolling code
11023 this.createScrollButtons();
11026 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
11029 if(this.currentTabWidth < this.preferredTabWidth){
11030 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
11036 * Returns the number of tabs in this TabPanel.
11039 getCount : function(){
11040 return this.items.length;
11044 * Resizes all the tabs to the passed width
11045 * @param {Number} The new width
11047 setTabWidth : function(width){
11048 this.currentTabWidth = width;
11049 for(var i = 0, len = this.items.length; i < len; i++) {
11050 if(!this.items[i].isHidden())this.items[i].setWidth(width);
11055 * Destroys this TabPanel
11056 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
11058 destroy : function(removeEl){
11059 Roo.EventManager.removeResizeListener(this.onResize, this);
11060 for(var i = 0, len = this.items.length; i < len; i++){
11061 this.items[i].purgeListeners();
11063 if(removeEl === true){
11064 this.el.update("");
11071 * @class Roo.TabPanelItem
11072 * @extends Roo.util.Observable
11073 * Represents an individual item (tab plus body) in a TabPanel.
11074 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
11075 * @param {String} id The id of this TabPanelItem
11076 * @param {String} text The text for the tab of this TabPanelItem
11077 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
11079 Roo.TabPanelItem = function(tabPanel, id, text, closable){
11081 * The {@link Roo.TabPanel} this TabPanelItem belongs to
11082 * @type Roo.TabPanel
11084 this.tabPanel = tabPanel;
11086 * The id for this TabPanelItem
11091 this.disabled = false;
11095 this.loaded = false;
11096 this.closable = closable;
11099 * The body element for this TabPanelItem.
11100 * @type Roo.Element
11102 this.bodyEl = Roo.get(tabPanel.createItemBody(tabPanel.bodyEl.dom, id));
11103 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
11104 this.bodyEl.setStyle("display", "block");
11105 this.bodyEl.setStyle("zoom", "1");
11108 var els = tabPanel.createStripElements(tabPanel.stripEl.dom, text, closable);
11110 this.el = Roo.get(els.el, true);
11111 this.inner = Roo.get(els.inner, true);
11112 this.textEl = Roo.get(this.el.dom.firstChild.firstChild.firstChild, true);
11113 this.pnode = Roo.get(els.el.parentNode, true);
11114 this.el.on("mousedown", this.onTabMouseDown, this);
11115 this.el.on("click", this.onTabClick, this);
11118 var c = Roo.get(els.close, true);
11119 c.dom.title = this.closeText;
11120 c.addClassOnOver("close-over");
11121 c.on("click", this.closeClick, this);
11127 * Fires when this tab becomes the active tab.
11128 * @param {Roo.TabPanel} tabPanel The parent TabPanel
11129 * @param {Roo.TabPanelItem} this
11133 * @event beforeclose
11134 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
11135 * @param {Roo.TabPanelItem} this
11136 * @param {Object} e Set cancel to true on this object to cancel the close.
11138 "beforeclose": true,
11141 * Fires when this tab is closed.
11142 * @param {Roo.TabPanelItem} this
11146 * @event deactivate
11147 * Fires when this tab is no longer the active tab.
11148 * @param {Roo.TabPanel} tabPanel The parent TabPanel
11149 * @param {Roo.TabPanelItem} this
11151 "deactivate" : true
11153 this.hidden = false;
11155 Roo.TabPanelItem.superclass.constructor.call(this);
11158 Roo.extend(Roo.TabPanelItem, Roo.util.Observable, {
11159 purgeListeners : function(){
11160 Roo.util.Observable.prototype.purgeListeners.call(this);
11161 this.el.removeAllListeners();
11164 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
11167 this.pnode.addClass("on");
11170 this.tabPanel.stripWrap.repaint();
11172 this.fireEvent("activate", this.tabPanel, this);
11176 * Returns true if this tab is the active tab.
11177 * @return {Boolean}
11179 isActive : function(){
11180 return this.tabPanel.getActiveTab() == this;
11184 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
11187 this.pnode.removeClass("on");
11189 this.fireEvent("deactivate", this.tabPanel, this);
11192 hideAction : function(){
11193 this.bodyEl.hide();
11194 this.bodyEl.setStyle("position", "absolute");
11195 this.bodyEl.setLeft("-20000px");
11196 this.bodyEl.setTop("-20000px");
11199 showAction : function(){
11200 this.bodyEl.setStyle("position", "relative");
11201 this.bodyEl.setTop("");
11202 this.bodyEl.setLeft("");
11203 this.bodyEl.show();
11207 * Set the tooltip for the tab.
11208 * @param {String} tooltip The tab's tooltip
11210 setTooltip : function(text){
11211 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
11212 this.textEl.dom.qtip = text;
11213 this.textEl.dom.removeAttribute('title');
11215 this.textEl.dom.title = text;
11219 onTabClick : function(e){
11220 e.preventDefault();
11221 this.tabPanel.activate(this.id);
11224 onTabMouseDown : function(e){
11225 e.preventDefault();
11226 this.tabPanel.activate(this.id);
11229 getWidth : function(){
11230 return this.inner.getWidth();
11233 setWidth : function(width){
11234 var iwidth = width - this.pnode.getPadding("lr");
11235 this.inner.setWidth(iwidth);
11236 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
11237 this.pnode.setWidth(width);
11241 * Show or hide the tab
11242 * @param {Boolean} hidden True to hide or false to show.
11244 setHidden : function(hidden){
11245 this.hidden = hidden;
11246 this.pnode.setStyle("display", hidden ? "none" : "");
11250 * Returns true if this tab is "hidden"
11251 * @return {Boolean}
11253 isHidden : function(){
11254 return this.hidden;
11258 * Returns the text for this tab
11261 getText : function(){
11265 autoSize : function(){
11266 //this.el.beginMeasure();
11267 this.textEl.setWidth(1);
11268 this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr"));
11269 //this.el.endMeasure();
11273 * Sets the text for the tab (Note: this also sets the tooltip text)
11274 * @param {String} text The tab's text and tooltip
11276 setText : function(text){
11278 this.textEl.update(text);
11279 this.setTooltip(text);
11280 if(!this.tabPanel.resizeTabs){
11285 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
11287 activate : function(){
11288 this.tabPanel.activate(this.id);
11292 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
11294 disable : function(){
11295 if(this.tabPanel.active != this){
11296 this.disabled = true;
11297 this.pnode.addClass("disabled");
11302 * Enables this TabPanelItem if it was previously disabled.
11304 enable : function(){
11305 this.disabled = false;
11306 this.pnode.removeClass("disabled");
11310 * Sets the content for this TabPanelItem.
11311 * @param {String} content The content
11312 * @param {Boolean} loadScripts true to look for and load scripts
11314 setContent : function(content, loadScripts){
11315 this.bodyEl.update(content, loadScripts);
11319 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
11320 * @return {Roo.UpdateManager} The UpdateManager
11322 getUpdateManager : function(){
11323 return this.bodyEl.getUpdateManager();
11327 * Set a URL to be used to load the content for this TabPanelItem.
11328 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
11329 * @param {String/Object} params (optional) The string params for the update call or an object of the params. See {@link Roo.UpdateManager#update} for more details. (Defaults to null)
11330 * @param {Boolean} loadOnce (optional) Whether to only load the content once. If this is false it makes the Ajax call every time this TabPanelItem is activated. (Defaults to false)
11331 * @return {Roo.UpdateManager} The UpdateManager
11333 setUrl : function(url, params, loadOnce){
11334 if(this.refreshDelegate){
11335 this.un('activate', this.refreshDelegate);
11337 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
11338 this.on("activate", this.refreshDelegate);
11339 return this.bodyEl.getUpdateManager();
11343 _handleRefresh : function(url, params, loadOnce){
11344 if(!loadOnce || !this.loaded){
11345 var updater = this.bodyEl.getUpdateManager();
11346 updater.update(url, params, this._setLoaded.createDelegate(this));
11351 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
11352 * Will fail silently if the setUrl method has not been called.
11353 * This does not activate the panel, just updates its content.
11355 refresh : function(){
11356 if(this.refreshDelegate){
11357 this.loaded = false;
11358 this.refreshDelegate();
11363 _setLoaded : function(){
11364 this.loaded = true;
11368 closeClick : function(e){
11371 this.fireEvent("beforeclose", this, o);
11372 if(o.cancel !== true){
11373 this.tabPanel.removeTab(this.id);
11377 * The text displayed in the tooltip for the close icon.
11380 closeText : "Close this tab"
11384 Roo.TabPanel.prototype.createStrip = function(container){
11385 var strip = document.createElement("div");
11386 strip.className = "x-tabs-wrap";
11387 container.appendChild(strip);
11391 Roo.TabPanel.prototype.createStripList = function(strip){
11392 // div wrapper for retard IE
11393 strip.innerHTML = '<div class="x-tabs-strip-wrap"><table class="x-tabs-strip" cellspacing="0" cellpadding="0" border="0"><tbody><tr></tr></tbody></table></div>';
11394 return strip.firstChild.firstChild.firstChild.firstChild;
11397 Roo.TabPanel.prototype.createBody = function(container){
11398 var body = document.createElement("div");
11399 Roo.id(body, "tab-body");
11400 Roo.fly(body).addClass("x-tabs-body");
11401 container.appendChild(body);
11405 Roo.TabPanel.prototype.createItemBody = function(bodyEl, id){
11406 var body = Roo.getDom(id);
11408 body = document.createElement("div");
11411 Roo.fly(body).addClass("x-tabs-item-body");
11412 bodyEl.insertBefore(body, bodyEl.firstChild);
11416 Roo.TabPanel.prototype.createStripElements = function(stripEl, text, closable){
11417 var td = document.createElement("td");
11418 stripEl.appendChild(td);
11420 td.className = "x-tabs-closable";
11421 if(!this.closeTpl){
11422 this.closeTpl = new Roo.Template(
11423 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
11424 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
11425 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
11428 var el = this.closeTpl.overwrite(td, {"text": text});
11429 var close = el.getElementsByTagName("div")[0];
11430 var inner = el.getElementsByTagName("em")[0];
11431 return {"el": el, "close": close, "inner": inner};
11434 this.tabTpl = new Roo.Template(
11435 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
11436 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
11439 var el = this.tabTpl.overwrite(td, {"text": text});
11440 var inner = el.getElementsByTagName("em")[0];
11441 return {"el": el, "inner": inner};
11445 * Ext JS Library 1.1.1
11446 * Copyright(c) 2006-2007, Ext JS, LLC.
11448 * Originally Released Under LGPL - original licence link has changed is not relivant.
11451 * <script type="text/javascript">
11455 * @class Roo.Button
11456 * @extends Roo.util.Observable
11457 * Simple Button class
11458 * @cfg {String} text The button text
11459 * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
11460 * CSS property of the button by default, so if you want a mixed icon/text button, set cls:"x-btn-text-icon")
11461 * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event)
11462 * @cfg {Object} scope The scope of the handler
11463 * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width)
11464 * @cfg {String/Object} tooltip The tooltip for the button - can be a string or QuickTips config object
11465 * @cfg {Boolean} hidden True to start hidden (defaults to false)
11466 * @cfg {Boolean} disabled True to start disabled (defaults to false)
11467 * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
11468 * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed, only
11469 applies if enableToggle = true)
11470 * @cfg {String/HTMLElement/Element} renderTo The element to append the button to
11471 * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
11472 an {@link Roo.util.ClickRepeater} config object (defaults to false).
11474 * Create a new button
11475 * @param {Object} config The config object
11477 Roo.Button = function(renderTo, config)
11481 renderTo = config.renderTo || false;
11484 Roo.apply(this, config);
11488 * Fires when this button is clicked
11489 * @param {Button} this
11490 * @param {EventObject} e The click event
11495 * Fires when the "pressed" state of this button changes (only if enableToggle = true)
11496 * @param {Button} this
11497 * @param {Boolean} pressed
11502 * Fires when the mouse hovers over the button
11503 * @param {Button} this
11504 * @param {Event} e The event object
11506 'mouseover' : true,
11509 * Fires when the mouse exits the button
11510 * @param {Button} this
11511 * @param {Event} e The event object
11516 * Fires when the button is rendered
11517 * @param {Button} this
11522 this.menu = Roo.menu.MenuMgr.get(this.menu);
11524 // register listeners first!! - so render can be captured..
11525 Roo.util.Observable.call(this);
11527 this.render(renderTo);
11533 Roo.extend(Roo.Button, Roo.util.Observable, {
11539 * Read-only. True if this button is hidden
11544 * Read-only. True if this button is disabled
11549 * Read-only. True if this button is pressed (only if enableToggle = true)
11555 * @cfg {Number} tabIndex
11556 * The DOM tabIndex for this button (defaults to undefined)
11558 tabIndex : undefined,
11561 * @cfg {Boolean} enableToggle
11562 * True to enable pressed/not pressed toggling (defaults to false)
11564 enableToggle: false,
11566 * @cfg {Mixed} menu
11567 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
11571 * @cfg {String} menuAlign
11572 * The position to align the menu to (see {@link Roo.Element#alignTo} for more details, defaults to 'tl-bl?').
11574 menuAlign : "tl-bl?",
11577 * @cfg {String} iconCls
11578 * A css class which sets a background image to be used as the icon for this button (defaults to undefined).
11580 iconCls : undefined,
11582 * @cfg {String} type
11583 * The button's type, corresponding to the DOM input element type attribute. Either "submit," "reset" or "button" (default).
11588 menuClassTarget: 'tr',
11591 * @cfg {String} clickEvent
11592 * The type of event to map to the button's event handler (defaults to 'click')
11594 clickEvent : 'click',
11597 * @cfg {Boolean} handleMouseEvents
11598 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
11600 handleMouseEvents : true,
11603 * @cfg {String} tooltipType
11604 * The type of tooltip to use. Either "qtip" (default) for QuickTips or "title" for title attribute.
11606 tooltipType : 'qtip',
11609 * @cfg {String} cls
11610 * A CSS class to apply to the button's main element.
11614 * @cfg {Roo.Template} template (Optional)
11615 * An {@link Roo.Template} with which to create the Button's main element. This Template must
11616 * contain numeric substitution parameter 0 if it is to display the tRoo property. Changing the template could
11617 * require code modifications if required elements (e.g. a button) aren't present.
11621 render : function(renderTo){
11623 if(this.hideParent){
11624 this.parentEl = Roo.get(renderTo);
11626 if(!this.dhconfig){
11627 if(!this.template){
11628 if(!Roo.Button.buttonTemplate){
11629 // hideous table template
11630 Roo.Button.buttonTemplate = new Roo.Template(
11631 '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
11632 '<td class="x-btn-left"><i> </i></td><td class="x-btn-center"><em unselectable="on"><button class="x-btn-text" type="{1}">{0}</button></em></td><td class="x-btn-right"><i> </i></td>',
11633 "</tr></tbody></table>");
11635 this.template = Roo.Button.buttonTemplate;
11637 btn = this.template.append(renderTo, [this.text || ' ', this.type], true);
11638 var btnEl = btn.child("button:first");
11639 btnEl.on('focus', this.onFocus, this);
11640 btnEl.on('blur', this.onBlur, this);
11642 btn.addClass(this.cls);
11645 btnEl.setStyle('background-image', 'url(' +this.icon +')');
11648 btnEl.addClass(this.iconCls);
11650 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
11653 if(this.tabIndex !== undefined){
11654 btnEl.dom.tabIndex = this.tabIndex;
11657 if(typeof this.tooltip == 'object'){
11658 Roo.QuickTips.tips(Roo.apply({
11662 btnEl.dom[this.tooltipType] = this.tooltip;
11666 btn = Roo.DomHelper.append(Roo.get(renderTo).dom, this.dhconfig, true);
11670 this.el.dom.id = this.el.id = this.id;
11673 this.el.child(this.menuClassTarget).addClass("x-btn-with-menu");
11674 this.menu.on("show", this.onMenuShow, this);
11675 this.menu.on("hide", this.onMenuHide, this);
11677 btn.addClass("x-btn");
11678 if(Roo.isIE && !Roo.isIE7){
11679 this.autoWidth.defer(1, this);
11683 if(this.handleMouseEvents){
11684 btn.on("mouseover", this.onMouseOver, this);
11685 btn.on("mouseout", this.onMouseOut, this);
11686 btn.on("mousedown", this.onMouseDown, this);
11688 btn.on(this.clickEvent, this.onClick, this);
11689 //btn.on("mouseup", this.onMouseUp, this);
11696 Roo.ButtonToggleMgr.register(this);
11698 this.el.addClass("x-btn-pressed");
11701 var repeater = new Roo.util.ClickRepeater(btn,
11702 typeof this.repeat == "object" ? this.repeat : {}
11704 repeater.on("click", this.onClick, this);
11707 this.fireEvent('render', this);
11711 * Returns the button's underlying element
11712 * @return {Roo.Element} The element
11714 getEl : function(){
11719 * Destroys this Button and removes any listeners.
11721 destroy : function(){
11722 Roo.ButtonToggleMgr.unregister(this);
11723 this.el.removeAllListeners();
11724 this.purgeListeners();
11729 autoWidth : function(){
11731 this.el.setWidth("auto");
11732 if(Roo.isIE7 && Roo.isStrict){
11733 var ib = this.el.child('button');
11734 if(ib && ib.getWidth() > 20){
11736 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
11741 this.el.beginMeasure();
11743 if(this.el.getWidth() < this.minWidth){
11744 this.el.setWidth(this.minWidth);
11747 this.el.endMeasure();
11754 * Assigns this button's click handler
11755 * @param {Function} handler The function to call when the button is clicked
11756 * @param {Object} scope (optional) Scope for the function passed in
11758 setHandler : function(handler, scope){
11759 this.handler = handler;
11760 this.scope = scope;
11764 * Sets this button's text
11765 * @param {String} text The button text
11767 setText : function(text){
11770 this.el.child("td.x-btn-center button.x-btn-text").update(text);
11776 * Gets the text for this button
11777 * @return {String} The button text
11779 getText : function(){
11787 this.hidden = false;
11789 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "");
11797 this.hidden = true;
11799 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "none");
11804 * Convenience function for boolean show/hide
11805 * @param {Boolean} visible True to show, false to hide
11807 setVisible: function(visible){
11816 * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
11817 * @param {Boolean} state (optional) Force a particular state
11819 toggle : function(state){
11820 state = state === undefined ? !this.pressed : state;
11821 if(state != this.pressed){
11823 this.el.addClass("x-btn-pressed");
11824 this.pressed = true;
11825 this.fireEvent("toggle", this, true);
11827 this.el.removeClass("x-btn-pressed");
11828 this.pressed = false;
11829 this.fireEvent("toggle", this, false);
11831 if(this.toggleHandler){
11832 this.toggleHandler.call(this.scope || this, this, state);
11840 focus : function(){
11841 this.el.child('button:first').focus();
11845 * Disable this button
11847 disable : function(){
11849 this.el.addClass("x-btn-disabled");
11851 this.disabled = true;
11855 * Enable this button
11857 enable : function(){
11859 this.el.removeClass("x-btn-disabled");
11861 this.disabled = false;
11865 * Convenience function for boolean enable/disable
11866 * @param {Boolean} enabled True to enable, false to disable
11868 setDisabled : function(v){
11869 this[v !== true ? "enable" : "disable"]();
11873 onClick : function(e){
11875 e.preventDefault();
11880 if(!this.disabled){
11881 if(this.enableToggle){
11884 if(this.menu && !this.menu.isVisible()){
11885 this.menu.show(this.el, this.menuAlign);
11887 this.fireEvent("click", this, e);
11889 this.el.removeClass("x-btn-over");
11890 this.handler.call(this.scope || this, this, e);
11895 onMouseOver : function(e){
11896 if(!this.disabled){
11897 this.el.addClass("x-btn-over");
11898 this.fireEvent('mouseover', this, e);
11902 onMouseOut : function(e){
11903 if(!e.within(this.el, true)){
11904 this.el.removeClass("x-btn-over");
11905 this.fireEvent('mouseout', this, e);
11909 onFocus : function(e){
11910 if(!this.disabled){
11911 this.el.addClass("x-btn-focus");
11915 onBlur : function(e){
11916 this.el.removeClass("x-btn-focus");
11919 onMouseDown : function(e){
11920 if(!this.disabled && e.button == 0){
11921 this.el.addClass("x-btn-click");
11922 Roo.get(document).on('mouseup', this.onMouseUp, this);
11926 onMouseUp : function(e){
11928 this.el.removeClass("x-btn-click");
11929 Roo.get(document).un('mouseup', this.onMouseUp, this);
11933 onMenuShow : function(e){
11934 this.el.addClass("x-btn-menu-active");
11937 onMenuHide : function(e){
11938 this.el.removeClass("x-btn-menu-active");
11942 // Private utility class used by Button
11943 Roo.ButtonToggleMgr = function(){
11946 function toggleGroup(btn, state){
11948 var g = groups[btn.toggleGroup];
11949 for(var i = 0, l = g.length; i < l; i++){
11951 g[i].toggle(false);
11958 register : function(btn){
11959 if(!btn.toggleGroup){
11962 var g = groups[btn.toggleGroup];
11964 g = groups[btn.toggleGroup] = [];
11967 btn.on("toggle", toggleGroup);
11970 unregister : function(btn){
11971 if(!btn.toggleGroup){
11974 var g = groups[btn.toggleGroup];
11977 btn.un("toggle", toggleGroup);
11983 * Ext JS Library 1.1.1
11984 * Copyright(c) 2006-2007, Ext JS, LLC.
11986 * Originally Released Under LGPL - original licence link has changed is not relivant.
11989 * <script type="text/javascript">
11993 * @class Roo.SplitButton
11994 * @extends Roo.Button
11995 * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
11996 * click event of the button. Typically this would be used to display a dropdown menu that provides additional
11997 * options to the primary button action, but any custom handler can provide the arrowclick implementation.
11998 * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
11999 * @cfg {String} arrowTooltip The title attribute of the arrow
12001 * Create a new menu button
12002 * @param {String/HTMLElement/Element} renderTo The element to append the button to
12003 * @param {Object} config The config object
12005 Roo.SplitButton = function(renderTo, config){
12006 Roo.SplitButton.superclass.constructor.call(this, renderTo, config);
12008 * @event arrowclick
12009 * Fires when this button's arrow is clicked
12010 * @param {SplitButton} this
12011 * @param {EventObject} e The click event
12013 this.addEvents({"arrowclick":true});
12016 Roo.extend(Roo.SplitButton, Roo.Button, {
12017 render : function(renderTo){
12018 // this is one sweet looking template!
12019 var tpl = new Roo.Template(
12020 '<table cellspacing="0" class="x-btn-menu-wrap x-btn"><tr><td>',
12021 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-text-wrap"><tbody>',
12022 '<tr><td class="x-btn-left"><i> </i></td><td class="x-btn-center"><button class="x-btn-text" type="{1}">{0}</button></td></tr>',
12023 "</tbody></table></td><td>",
12024 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-arrow-wrap"><tbody>',
12025 '<tr><td class="x-btn-center"><button class="x-btn-menu-arrow-el" type="button"> </button></td><td class="x-btn-right"><i> </i></td></tr>',
12026 "</tbody></table></td></tr></table>"
12028 var btn = tpl.append(renderTo, [this.text, this.type], true);
12029 var btnEl = btn.child("button");
12031 btn.addClass(this.cls);
12034 btnEl.setStyle('background-image', 'url(' +this.icon +')');
12037 btnEl.addClass(this.iconCls);
12039 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
12043 if(this.handleMouseEvents){
12044 btn.on("mouseover", this.onMouseOver, this);
12045 btn.on("mouseout", this.onMouseOut, this);
12046 btn.on("mousedown", this.onMouseDown, this);
12047 btn.on("mouseup", this.onMouseUp, this);
12049 btn.on(this.clickEvent, this.onClick, this);
12051 if(typeof this.tooltip == 'object'){
12052 Roo.QuickTips.tips(Roo.apply({
12056 btnEl.dom[this.tooltipType] = this.tooltip;
12059 if(this.arrowTooltip){
12060 btn.child("button:nth(2)").dom[this.tooltipType] = this.arrowTooltip;
12069 this.el.addClass("x-btn-pressed");
12071 if(Roo.isIE && !Roo.isIE7){
12072 this.autoWidth.defer(1, this);
12077 this.menu.on("show", this.onMenuShow, this);
12078 this.menu.on("hide", this.onMenuHide, this);
12080 this.fireEvent('render', this);
12084 autoWidth : function(){
12086 var tbl = this.el.child("table:first");
12087 var tbl2 = this.el.child("table:last");
12088 this.el.setWidth("auto");
12089 tbl.setWidth("auto");
12090 if(Roo.isIE7 && Roo.isStrict){
12091 var ib = this.el.child('button:first');
12092 if(ib && ib.getWidth() > 20){
12094 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
12099 this.el.beginMeasure();
12101 if((tbl.getWidth()+tbl2.getWidth()) < this.minWidth){
12102 tbl.setWidth(this.minWidth-tbl2.getWidth());
12105 this.el.endMeasure();
12108 this.el.setWidth(tbl.getWidth()+tbl2.getWidth());
12112 * Sets this button's click handler
12113 * @param {Function} handler The function to call when the button is clicked
12114 * @param {Object} scope (optional) Scope for the function passed above
12116 setHandler : function(handler, scope){
12117 this.handler = handler;
12118 this.scope = scope;
12122 * Sets this button's arrow click handler
12123 * @param {Function} handler The function to call when the arrow is clicked
12124 * @param {Object} scope (optional) Scope for the function passed above
12126 setArrowHandler : function(handler, scope){
12127 this.arrowHandler = handler;
12128 this.scope = scope;
12134 focus : function(){
12136 this.el.child("button:first").focus();
12141 onClick : function(e){
12142 e.preventDefault();
12143 if(!this.disabled){
12144 if(e.getTarget(".x-btn-menu-arrow-wrap")){
12145 if(this.menu && !this.menu.isVisible()){
12146 this.menu.show(this.el, this.menuAlign);
12148 this.fireEvent("arrowclick", this, e);
12149 if(this.arrowHandler){
12150 this.arrowHandler.call(this.scope || this, this, e);
12153 this.fireEvent("click", this, e);
12155 this.handler.call(this.scope || this, this, e);
12161 onMouseDown : function(e){
12162 if(!this.disabled){
12163 Roo.fly(e.getTarget("table")).addClass("x-btn-click");
12167 onMouseUp : function(e){
12168 Roo.fly(e.getTarget("table")).removeClass("x-btn-click");
12173 // backwards compat
12174 Roo.MenuButton = Roo.SplitButton;/*
12176 * Ext JS Library 1.1.1
12177 * Copyright(c) 2006-2007, Ext JS, LLC.
12179 * Originally Released Under LGPL - original licence link has changed is not relivant.
12182 * <script type="text/javascript">
12186 * @class Roo.Toolbar
12187 * Basic Toolbar class.
12189 * Creates a new Toolbar
12190 * @param {Object} config The config object
12192 Roo.Toolbar = function(container, buttons, config)
12194 /// old consturctor format still supported..
12195 if(container instanceof Array){ // omit the container for later rendering
12196 buttons = container;
12200 if (typeof(container) == 'object' && container.xtype) {
12201 config = container;
12202 container = config.container;
12203 buttons = config.buttons; // not really - use items!!
12206 if (config && config.items) {
12207 xitems = config.items;
12208 delete config.items;
12210 Roo.apply(this, config);
12211 this.buttons = buttons;
12214 this.render(container);
12216 Roo.each(xitems, function(b) {
12222 Roo.Toolbar.prototype = {
12224 * @cfg {Roo.data.Store} items
12225 * array of button configs or elements to add
12229 * @cfg {String/HTMLElement/Element} container
12230 * The id or element that will contain the toolbar
12233 render : function(ct){
12234 this.el = Roo.get(ct);
12236 this.el.addClass(this.cls);
12238 // using a table allows for vertical alignment
12239 // 100% width is needed by Safari...
12240 this.el.update('<div class="x-toolbar x-small-editor"><table cellspacing="0"><tr></tr></table></div>');
12241 this.tr = this.el.child("tr", true);
12243 this.items = new Roo.util.MixedCollection(false, function(o){
12244 return o.id || ("item" + (++autoId));
12247 this.add.apply(this, this.buttons);
12248 delete this.buttons;
12253 * Adds element(s) to the toolbar -- this function takes a variable number of
12254 * arguments of mixed type and adds them to the toolbar.
12255 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
12257 * <li>{@link Roo.Toolbar.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
12258 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
12259 * <li>Field: Any form field (equivalent to {@link #addField})</li>
12260 * <li>Item: Any subclass of {@link Roo.Toolbar.Item} (equivalent to {@link #addItem})</li>
12261 * <li>String: Any generic string (gets wrapped in a {@link Roo.Toolbar.TextItem}, equivalent to {@link #addText}).
12262 * Note that there are a few special strings that are treated differently as explained nRoo.</li>
12263 * <li>'separator' or '-': Creates a separator element (equivalent to {@link #addSeparator})</li>
12264 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
12265 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
12267 * @param {Mixed} arg2
12268 * @param {Mixed} etc.
12271 var a = arguments, l = a.length;
12272 for(var i = 0; i < l; i++){
12277 _add : function(el) {
12280 el = Roo.factory(el, typeof(Roo.Toolbar[el.xtype]) == 'undefined' ? Roo.form : Roo.Toolbar);
12283 if (el.applyTo){ // some kind of form field
12284 return this.addField(el);
12286 if (el.render){ // some kind of Toolbar.Item
12287 return this.addItem(el);
12289 if (typeof el == "string"){ // string
12290 if(el == "separator" || el == "-"){
12291 return this.addSeparator();
12294 return this.addSpacer();
12297 return this.addFill();
12299 return this.addText(el);
12302 if(el.tagName){ // element
12303 return this.addElement(el);
12305 if(typeof el == "object"){ // must be button config?
12306 return this.addButton(el);
12308 // and now what?!?!
12314 * Add an Xtype element
12315 * @param {Object} xtype Xtype Object
12316 * @return {Object} created Object
12318 addxtype : function(e){
12319 return this.add(e);
12323 * Returns the Element for this toolbar.
12324 * @return {Roo.Element}
12326 getEl : function(){
12332 * @return {Roo.Toolbar.Item} The separator item
12334 addSeparator : function(){
12335 return this.addItem(new Roo.Toolbar.Separator());
12339 * Adds a spacer element
12340 * @return {Roo.Toolbar.Spacer} The spacer item
12342 addSpacer : function(){
12343 return this.addItem(new Roo.Toolbar.Spacer());
12347 * Adds a fill element that forces subsequent additions to the right side of the toolbar
12348 * @return {Roo.Toolbar.Fill} The fill item
12350 addFill : function(){
12351 return this.addItem(new Roo.Toolbar.Fill());
12355 * Adds any standard HTML element to the toolbar
12356 * @param {String/HTMLElement/Element} el The element or id of the element to add
12357 * @return {Roo.Toolbar.Item} The element's item
12359 addElement : function(el){
12360 return this.addItem(new Roo.Toolbar.Item(el));
12363 * Collection of items on the toolbar.. (only Toolbar Items, so use fields to retrieve fields)
12364 * @type Roo.util.MixedCollection
12369 * Adds any Toolbar.Item or subclass
12370 * @param {Roo.Toolbar.Item} item
12371 * @return {Roo.Toolbar.Item} The item
12373 addItem : function(item){
12374 var td = this.nextBlock();
12376 this.items.add(item);
12381 * Adds a button (or buttons). See {@link Roo.Toolbar.Button} for more info on the config.
12382 * @param {Object/Array} config A button config or array of configs
12383 * @return {Roo.Toolbar.Button/Array}
12385 addButton : function(config){
12386 if(config instanceof Array){
12388 for(var i = 0, len = config.length; i < len; i++) {
12389 buttons.push(this.addButton(config[i]));
12394 if(!(config instanceof Roo.Toolbar.Button)){
12396 new Roo.Toolbar.SplitButton(config) :
12397 new Roo.Toolbar.Button(config);
12399 var td = this.nextBlock();
12406 * Adds text to the toolbar
12407 * @param {String} text The text to add
12408 * @return {Roo.Toolbar.Item} The element's item
12410 addText : function(text){
12411 return this.addItem(new Roo.Toolbar.TextItem(text));
12415 * Inserts any {@link Roo.Toolbar.Item}/{@link Roo.Toolbar.Button} at the specified index.
12416 * @param {Number} index The index where the item is to be inserted
12417 * @param {Object/Roo.Toolbar.Item/Roo.Toolbar.Button (may be Array)} item The button, or button config object to be inserted.
12418 * @return {Roo.Toolbar.Button/Item}
12420 insertButton : function(index, item){
12421 if(item instanceof Array){
12423 for(var i = 0, len = item.length; i < len; i++) {
12424 buttons.push(this.insertButton(index + i, item[i]));
12428 if (!(item instanceof Roo.Toolbar.Button)){
12429 item = new Roo.Toolbar.Button(item);
12431 var td = document.createElement("td");
12432 this.tr.insertBefore(td, this.tr.childNodes[index]);
12434 this.items.insert(index, item);
12439 * Adds a new element to the toolbar from the passed {@link Roo.DomHelper} config.
12440 * @param {Object} config
12441 * @return {Roo.Toolbar.Item} The element's item
12443 addDom : function(config, returnEl){
12444 var td = this.nextBlock();
12445 Roo.DomHelper.overwrite(td, config);
12446 var ti = new Roo.Toolbar.Item(td.firstChild);
12448 this.items.add(ti);
12453 * Collection of fields on the toolbar.. usefull for quering (value is false if there are no fields)
12454 * @type Roo.util.MixedCollection
12459 * Adds a dynamically rendered Roo.form field (TextField, ComboBox, etc). Note: the field should not have
12460 * been rendered yet. For a field that has already been rendered, use {@link #addElement}.
12461 * @param {Roo.form.Field} field
12462 * @return {Roo.ToolbarItem}
12466 addField : function(field) {
12467 if (!this.fields) {
12469 this.fields = new Roo.util.MixedCollection(false, function(o){
12470 return o.id || ("item" + (++autoId));
12475 var td = this.nextBlock();
12477 var ti = new Roo.Toolbar.Item(td.firstChild);
12479 this.items.add(ti);
12480 this.fields.add(field);
12491 this.el.child('div').setVisibilityMode(Roo.Element.DISPLAY);
12492 this.el.child('div').hide();
12500 this.el.child('div').show();
12504 nextBlock : function(){
12505 var td = document.createElement("td");
12506 this.tr.appendChild(td);
12511 destroy : function(){
12512 if(this.items){ // rendered?
12513 Roo.destroy.apply(Roo, this.items.items);
12515 if(this.fields){ // rendered?
12516 Roo.destroy.apply(Roo, this.fields.items);
12518 Roo.Element.uncache(this.el, this.tr);
12523 * @class Roo.Toolbar.Item
12524 * The base class that other classes should extend in order to get some basic common toolbar item functionality.
12526 * Creates a new Item
12527 * @param {HTMLElement} el
12529 Roo.Toolbar.Item = function(el){
12530 this.el = Roo.getDom(el);
12531 this.id = Roo.id(this.el);
12532 this.hidden = false;
12535 Roo.Toolbar.Item.prototype = {
12538 * Get this item's HTML Element
12539 * @return {HTMLElement}
12541 getEl : function(){
12546 render : function(td){
12548 td.appendChild(this.el);
12552 * Removes and destroys this item.
12554 destroy : function(){
12555 this.td.parentNode.removeChild(this.td);
12562 this.hidden = false;
12563 this.td.style.display = "";
12570 this.hidden = true;
12571 this.td.style.display = "none";
12575 * Convenience function for boolean show/hide.
12576 * @param {Boolean} visible true to show/false to hide
12578 setVisible: function(visible){
12587 * Try to focus this item.
12589 focus : function(){
12590 Roo.fly(this.el).focus();
12594 * Disables this item.
12596 disable : function(){
12597 Roo.fly(this.td).addClass("x-item-disabled");
12598 this.disabled = true;
12599 this.el.disabled = true;
12603 * Enables this item.
12605 enable : function(){
12606 Roo.fly(this.td).removeClass("x-item-disabled");
12607 this.disabled = false;
12608 this.el.disabled = false;
12614 * @class Roo.Toolbar.Separator
12615 * @extends Roo.Toolbar.Item
12616 * A simple toolbar separator class
12618 * Creates a new Separator
12620 Roo.Toolbar.Separator = function(){
12621 var s = document.createElement("span");
12622 s.className = "ytb-sep";
12623 Roo.Toolbar.Separator.superclass.constructor.call(this, s);
12625 Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, {
12626 enable:Roo.emptyFn,
12627 disable:Roo.emptyFn,
12632 * @class Roo.Toolbar.Spacer
12633 * @extends Roo.Toolbar.Item
12634 * A simple element that adds extra horizontal space to a toolbar.
12636 * Creates a new Spacer
12638 Roo.Toolbar.Spacer = function(){
12639 var s = document.createElement("div");
12640 s.className = "ytb-spacer";
12641 Roo.Toolbar.Spacer.superclass.constructor.call(this, s);
12643 Roo.extend(Roo.Toolbar.Spacer, Roo.Toolbar.Item, {
12644 enable:Roo.emptyFn,
12645 disable:Roo.emptyFn,
12650 * @class Roo.Toolbar.Fill
12651 * @extends Roo.Toolbar.Spacer
12652 * A simple element that adds a greedy (100% width) horizontal space to a toolbar.
12654 * Creates a new Spacer
12656 Roo.Toolbar.Fill = Roo.extend(Roo.Toolbar.Spacer, {
12658 render : function(td){
12659 td.style.width = '100%';
12660 Roo.Toolbar.Fill.superclass.render.call(this, td);
12665 * @class Roo.Toolbar.TextItem
12666 * @extends Roo.Toolbar.Item
12667 * A simple class that renders text directly into a toolbar.
12669 * Creates a new TextItem
12670 * @param {String} text
12672 Roo.Toolbar.TextItem = function(text){
12673 if (typeof(text) == 'object') {
12676 var s = document.createElement("span");
12677 s.className = "ytb-text";
12678 s.innerHTML = text;
12679 Roo.Toolbar.TextItem.superclass.constructor.call(this, s);
12681 Roo.extend(Roo.Toolbar.TextItem, Roo.Toolbar.Item, {
12682 enable:Roo.emptyFn,
12683 disable:Roo.emptyFn,
12688 * @class Roo.Toolbar.Button
12689 * @extends Roo.Button
12690 * A button that renders into a toolbar.
12692 * Creates a new Button
12693 * @param {Object} config A standard {@link Roo.Button} config object
12695 Roo.Toolbar.Button = function(config){
12696 Roo.Toolbar.Button.superclass.constructor.call(this, null, config);
12698 Roo.extend(Roo.Toolbar.Button, Roo.Button, {
12699 render : function(td){
12701 Roo.Toolbar.Button.superclass.render.call(this, td);
12705 * Removes and destroys this button
12707 destroy : function(){
12708 Roo.Toolbar.Button.superclass.destroy.call(this);
12709 this.td.parentNode.removeChild(this.td);
12713 * Shows this button
12716 this.hidden = false;
12717 this.td.style.display = "";
12721 * Hides this button
12724 this.hidden = true;
12725 this.td.style.display = "none";
12729 * Disables this item
12731 disable : function(){
12732 Roo.fly(this.td).addClass("x-item-disabled");
12733 this.disabled = true;
12737 * Enables this item
12739 enable : function(){
12740 Roo.fly(this.td).removeClass("x-item-disabled");
12741 this.disabled = false;
12744 // backwards compat
12745 Roo.ToolbarButton = Roo.Toolbar.Button;
12748 * @class Roo.Toolbar.SplitButton
12749 * @extends Roo.SplitButton
12750 * A menu button that renders into a toolbar.
12752 * Creates a new SplitButton
12753 * @param {Object} config A standard {@link Roo.SplitButton} config object
12755 Roo.Toolbar.SplitButton = function(config){
12756 Roo.Toolbar.SplitButton.superclass.constructor.call(this, null, config);
12758 Roo.extend(Roo.Toolbar.SplitButton, Roo.SplitButton, {
12759 render : function(td){
12761 Roo.Toolbar.SplitButton.superclass.render.call(this, td);
12765 * Removes and destroys this button
12767 destroy : function(){
12768 Roo.Toolbar.SplitButton.superclass.destroy.call(this);
12769 this.td.parentNode.removeChild(this.td);
12773 * Shows this button
12776 this.hidden = false;
12777 this.td.style.display = "";
12781 * Hides this button
12784 this.hidden = true;
12785 this.td.style.display = "none";
12789 // backwards compat
12790 Roo.Toolbar.MenuButton = Roo.Toolbar.SplitButton;/*
12792 * Ext JS Library 1.1.1
12793 * Copyright(c) 2006-2007, Ext JS, LLC.
12795 * Originally Released Under LGPL - original licence link has changed is not relivant.
12798 * <script type="text/javascript">
12802 * @class Roo.PagingToolbar
12803 * @extends Roo.Toolbar
12804 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
12806 * Create a new PagingToolbar
12807 * @param {Object} config The config object
12809 Roo.PagingToolbar = function(el, ds, config)
12811 // old args format still supported... - xtype is prefered..
12812 if (typeof(el) == 'object' && el.xtype) {
12813 // created from xtype...
12815 ds = el.dataSource;
12816 el = config.container;
12819 if (config.items) {
12820 items = config.items;
12824 Roo.PagingToolbar.superclass.constructor.call(this, el, null, config);
12827 this.renderButtons(this.el);
12830 // supprot items array.
12832 Roo.each(items, function(e) {
12833 this.add(Roo.factory(e));
12838 Roo.extend(Roo.PagingToolbar, Roo.Toolbar, {
12840 * @cfg {Roo.data.Store} dataSource
12841 * The underlying data store providing the paged data
12844 * @cfg {String/HTMLElement/Element} container
12845 * container The id or element that will contain the toolbar
12848 * @cfg {Boolean} displayInfo
12849 * True to display the displayMsg (defaults to false)
12852 * @cfg {Number} pageSize
12853 * The number of records to display per page (defaults to 20)
12857 * @cfg {String} displayMsg
12858 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
12860 displayMsg : 'Displaying {0} - {1} of {2}',
12862 * @cfg {String} emptyMsg
12863 * The message to display when no records are found (defaults to "No data to display")
12865 emptyMsg : 'No data to display',
12867 * Customizable piece of the default paging text (defaults to "Page")
12870 beforePageText : "Page",
12872 * Customizable piece of the default paging text (defaults to "of %0")
12875 afterPageText : "of {0}",
12877 * Customizable piece of the default paging text (defaults to "First Page")
12880 firstText : "First Page",
12882 * Customizable piece of the default paging text (defaults to "Previous Page")
12885 prevText : "Previous Page",
12887 * Customizable piece of the default paging text (defaults to "Next Page")
12890 nextText : "Next Page",
12892 * Customizable piece of the default paging text (defaults to "Last Page")
12895 lastText : "Last Page",
12897 * Customizable piece of the default paging text (defaults to "Refresh")
12900 refreshText : "Refresh",
12903 renderButtons : function(el){
12904 Roo.PagingToolbar.superclass.render.call(this, el);
12905 this.first = this.addButton({
12906 tooltip: this.firstText,
12907 cls: "x-btn-icon x-grid-page-first",
12909 handler: this.onClick.createDelegate(this, ["first"])
12911 this.prev = this.addButton({
12912 tooltip: this.prevText,
12913 cls: "x-btn-icon x-grid-page-prev",
12915 handler: this.onClick.createDelegate(this, ["prev"])
12917 //this.addSeparator();
12918 this.add(this.beforePageText);
12919 this.field = Roo.get(this.addDom({
12924 cls: "x-grid-page-number"
12926 this.field.on("keydown", this.onPagingKeydown, this);
12927 this.field.on("focus", function(){this.dom.select();});
12928 this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
12929 this.field.setHeight(18);
12930 //this.addSeparator();
12931 this.next = this.addButton({
12932 tooltip: this.nextText,
12933 cls: "x-btn-icon x-grid-page-next",
12935 handler: this.onClick.createDelegate(this, ["next"])
12937 this.last = this.addButton({
12938 tooltip: this.lastText,
12939 cls: "x-btn-icon x-grid-page-last",
12941 handler: this.onClick.createDelegate(this, ["last"])
12943 //this.addSeparator();
12944 this.loading = this.addButton({
12945 tooltip: this.refreshText,
12946 cls: "x-btn-icon x-grid-loading",
12947 handler: this.onClick.createDelegate(this, ["refresh"])
12950 if(this.displayInfo){
12951 this.displayEl = Roo.fly(this.el.dom.firstChild).createChild({cls:'x-paging-info'});
12956 updateInfo : function(){
12957 if(this.displayEl){
12958 var count = this.ds.getCount();
12959 var msg = count == 0 ?
12963 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
12965 this.displayEl.update(msg);
12970 onLoad : function(ds, r, o){
12971 this.cursor = o.params ? o.params.start : 0;
12972 var d = this.getPageData(), ap = d.activePage, ps = d.pages;
12974 this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
12975 this.field.dom.value = ap;
12976 this.first.setDisabled(ap == 1);
12977 this.prev.setDisabled(ap == 1);
12978 this.next.setDisabled(ap == ps);
12979 this.last.setDisabled(ap == ps);
12980 this.loading.enable();
12985 getPageData : function(){
12986 var total = this.ds.getTotalCount();
12989 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
12990 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
12995 onLoadError : function(){
12996 this.loading.enable();
13000 onPagingKeydown : function(e){
13001 var k = e.getKey();
13002 var d = this.getPageData();
13004 var v = this.field.dom.value, pageNum;
13005 if(!v || isNaN(pageNum = parseInt(v, 10))){
13006 this.field.dom.value = d.activePage;
13009 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
13010 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
13013 else if(k == e.HOME || (k == e.UP && e.ctrlKey) || (k == e.PAGEUP && e.ctrlKey) || (k == e.RIGHT && e.ctrlKey) || k == e.END || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey))
13015 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
13016 this.field.dom.value = pageNum;
13017 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
13020 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
13022 var v = this.field.dom.value, pageNum;
13023 var increment = (e.shiftKey) ? 10 : 1;
13024 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
13026 if(!v || isNaN(pageNum = parseInt(v, 10))) {
13027 this.field.dom.value = d.activePage;
13030 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
13032 this.field.dom.value = parseInt(v, 10) + increment;
13033 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
13034 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
13041 beforeLoad : function(){
13043 this.loading.disable();
13048 onClick : function(which){
13052 ds.load({params:{start: 0, limit: this.pageSize}});
13055 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
13058 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
13061 var total = ds.getTotalCount();
13062 var extra = total % this.pageSize;
13063 var lastStart = extra ? (total - extra) : total-this.pageSize;
13064 ds.load({params:{start: lastStart, limit: this.pageSize}});
13067 ds.load({params:{start: this.cursor, limit: this.pageSize}});
13073 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
13074 * @param {Roo.data.Store} store The data store to unbind
13076 unbind : function(ds){
13077 ds.un("beforeload", this.beforeLoad, this);
13078 ds.un("load", this.onLoad, this);
13079 ds.un("loadexception", this.onLoadError, this);
13080 ds.un("remove", this.updateInfo, this);
13081 ds.un("add", this.updateInfo, this);
13082 this.ds = undefined;
13086 * Binds the paging toolbar to the specified {@link Roo.data.Store}
13087 * @param {Roo.data.Store} store The data store to bind
13089 bind : function(ds){
13090 ds.on("beforeload", this.beforeLoad, this);
13091 ds.on("load", this.onLoad, this);
13092 ds.on("loadexception", this.onLoadError, this);
13093 ds.on("remove", this.updateInfo, this);
13094 ds.on("add", this.updateInfo, this);
13099 * Ext JS Library 1.1.1
13100 * Copyright(c) 2006-2007, Ext JS, LLC.
13102 * Originally Released Under LGPL - original licence link has changed is not relivant.
13105 * <script type="text/javascript">
13109 * @class Roo.Resizable
13110 * @extends Roo.util.Observable
13111 * <p>Applies drag handles to an element to make it resizable. The drag handles are inserted into the element
13112 * and positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you can wrap
13113 * the textarea in a div and set "resizeChild" to true (or to the id of the element), <b>or</b> set wrap:true in your config and
13114 * the element will be wrapped for you automatically.</p>
13115 * <p>Here is the list of valid resize handles:</p>
13118 ------ -------------------
13127 'hd' horizontal drag
13130 * <p>Here's an example showing the creation of a typical Resizable:</p>
13132 var resizer = new Roo.Resizable("element-id", {
13140 resizer.on("resize", myHandler);
13142 * <p>To hide a particular handle, set its display to none in CSS, or through script:<br>
13143 * resizer.east.setDisplayed(false);</p>
13144 * @cfg {Boolean/String/Element} resizeChild True to resize the first child, or id/element to resize (defaults to false)
13145 * @cfg {Array/String} adjustments String "auto" or an array [width, height] with values to be <b>added</b> to the
13146 * resize operation's new size (defaults to [0, 0])
13147 * @cfg {Number} minWidth The minimum width for the element (defaults to 5)
13148 * @cfg {Number} minHeight The minimum height for the element (defaults to 5)
13149 * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)
13150 * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)
13151 * @cfg {Boolean} enabled False to disable resizing (defaults to true)
13152 * @cfg {Boolean} wrap True to wrap an element with a div if needed (required for textareas and images, defaults to false)
13153 * @cfg {Number} width The width of the element in pixels (defaults to null)
13154 * @cfg {Number} height The height of the element in pixels (defaults to null)
13155 * @cfg {Boolean} animate True to animate the resize (not compatible with dynamic sizing, defaults to false)
13156 * @cfg {Number} duration Animation duration if animate = true (defaults to .35)
13157 * @cfg {Boolean} dynamic True to resize the element while dragging instead of using a proxy (defaults to false)
13158 * @cfg {String} handles String consisting of the resize handles to display (defaults to undefined)
13159 * @cfg {Boolean} multiDirectional <b>Deprecated</b>. The old style of adding multi-direction resize handles, deprecated
13160 * in favor of the handles config option (defaults to false)
13161 * @cfg {Boolean} disableTrackOver True to disable mouse tracking. This is only applied at config time. (defaults to false)
13162 * @cfg {String} easing Animation easing if animate = true (defaults to 'easingOutStrong')
13163 * @cfg {Number} widthIncrement The increment to snap the width resize in pixels (dynamic must be true, defaults to 0)
13164 * @cfg {Number} heightIncrement The increment to snap the height resize in pixels (dynamic must be true, defaults to 0)
13165 * @cfg {Boolean} pinned True to ensure that the resize handles are always visible, false to display them only when the
13166 * user mouses over the resizable borders. This is only applied at config time. (defaults to false)
13167 * @cfg {Boolean} preserveRatio True to preserve the original ratio between height and width during resize (defaults to false)
13168 * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)
13169 * @cfg {Number} minX The minimum allowed page X for the element (only used for west resizing, defaults to 0)
13170 * @cfg {Number} minY The minimum allowed page Y for the element (only used for north resizing, defaults to 0)
13171 * @cfg {Boolean} draggable Convenience to initialize drag drop (defaults to false)
13173 * Create a new resizable component
13174 * @param {String/HTMLElement/Roo.Element} el The id or element to resize
13175 * @param {Object} config configuration options
13177 Roo.Resizable = function(el, config)
13179 this.el = Roo.get(el);
13181 if(config && config.wrap){
13182 config.resizeChild = this.el;
13183 this.el = this.el.wrap(typeof config.wrap == "object" ? config.wrap : {cls:"xresizable-wrap"});
13184 this.el.id = this.el.dom.id = config.resizeChild.id + "-rzwrap";
13185 this.el.setStyle("overflow", "hidden");
13186 this.el.setPositioning(config.resizeChild.getPositioning());
13187 config.resizeChild.clearPositioning();
13188 if(!config.width || !config.height){
13189 var csize = config.resizeChild.getSize();
13190 this.el.setSize(csize.width, csize.height);
13192 if(config.pinned && !config.adjustments){
13193 config.adjustments = "auto";
13197 this.proxy = this.el.createProxy({tag: "div", cls: "x-resizable-proxy", id: this.el.id + "-rzproxy"});
13198 this.proxy.unselectable();
13199 this.proxy.enableDisplayMode('block');
13201 Roo.apply(this, config);
13204 this.disableTrackOver = true;
13205 this.el.addClass("x-resizable-pinned");
13207 // if the element isn't positioned, make it relative
13208 var position = this.el.getStyle("position");
13209 if(position != "absolute" && position != "fixed"){
13210 this.el.setStyle("position", "relative");
13212 if(!this.handles){ // no handles passed, must be legacy style
13213 this.handles = 's,e,se';
13214 if(this.multiDirectional){
13215 this.handles += ',n,w';
13218 if(this.handles == "all"){
13219 this.handles = "n s e w ne nw se sw";
13221 var hs = this.handles.split(/\s*?[,;]\s*?| /);
13222 var ps = Roo.Resizable.positions;
13223 for(var i = 0, len = hs.length; i < len; i++){
13224 if(hs[i] && ps[hs[i]]){
13225 var pos = ps[hs[i]];
13226 this[pos] = new Roo.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent);
13230 this.corner = this.southeast;
13232 // updateBox = the box can move..
13233 if(this.handles.indexOf("n") != -1 || this.handles.indexOf("w") != -1 || this.handles.indexOf("hd") != -1) {
13234 this.updateBox = true;
13237 this.activeHandle = null;
13239 if(this.resizeChild){
13240 if(typeof this.resizeChild == "boolean"){
13241 this.resizeChild = Roo.get(this.el.dom.firstChild, true);
13243 this.resizeChild = Roo.get(this.resizeChild, true);
13247 if(this.adjustments == "auto"){
13248 var rc = this.resizeChild;
13249 var hw = this.west, he = this.east, hn = this.north, hs = this.south;
13250 if(rc && (hw || hn)){
13251 rc.position("relative");
13252 rc.setLeft(hw ? hw.el.getWidth() : 0);
13253 rc.setTop(hn ? hn.el.getHeight() : 0);
13255 this.adjustments = [
13256 (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),
13257 (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1
13261 if(this.draggable){
13262 this.dd = this.dynamic ?
13263 this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});
13264 this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);
13270 * @event beforeresize
13271 * Fired before resize is allowed. Set enabled to false to cancel resize.
13272 * @param {Roo.Resizable} this
13273 * @param {Roo.EventObject} e The mousedown event
13275 "beforeresize" : true,
13278 * Fired after a resize.
13279 * @param {Roo.Resizable} this
13280 * @param {Number} width The new width
13281 * @param {Number} height The new height
13282 * @param {Roo.EventObject} e The mouseup event
13287 if(this.width !== null && this.height !== null){
13288 this.resizeTo(this.width, this.height);
13290 this.updateChildSize();
13293 this.el.dom.style.zoom = 1;
13295 Roo.Resizable.superclass.constructor.call(this);
13298 Roo.extend(Roo.Resizable, Roo.util.Observable, {
13299 resizeChild : false,
13300 adjustments : [0, 0],
13310 multiDirectional : false,
13311 disableTrackOver : false,
13312 easing : 'easeOutStrong',
13313 widthIncrement : 0,
13314 heightIncrement : 0,
13318 preserveRatio : false,
13319 transparent: false,
13325 * @cfg {String/HTMLElement/Element} constrainTo Constrain the resize to a particular element
13327 constrainTo: undefined,
13329 * @cfg {Roo.lib.Region} resizeRegion Constrain the resize to a particular region
13331 resizeRegion: undefined,
13335 * Perform a manual resize
13336 * @param {Number} width
13337 * @param {Number} height
13339 resizeTo : function(width, height){
13340 this.el.setSize(width, height);
13341 this.updateChildSize();
13342 this.fireEvent("resize", this, width, height, null);
13346 startSizing : function(e, handle){
13347 this.fireEvent("beforeresize", this, e);
13348 if(this.enabled){ // 2nd enabled check in case disabled before beforeresize handler
13351 this.overlay = this.el.createProxy({tag: "div", cls: "x-resizable-overlay", html: " "});
13352 this.overlay.unselectable();
13353 this.overlay.enableDisplayMode("block");
13354 this.overlay.on("mousemove", this.onMouseMove, this);
13355 this.overlay.on("mouseup", this.onMouseUp, this);
13357 this.overlay.setStyle("cursor", handle.el.getStyle("cursor"));
13359 this.resizing = true;
13360 this.startBox = this.el.getBox();
13361 this.startPoint = e.getXY();
13362 this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],
13363 (this.startBox.y + this.startBox.height) - this.startPoint[1]];
13365 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
13366 this.overlay.show();
13368 if(this.constrainTo) {
13369 var ct = Roo.get(this.constrainTo);
13370 this.resizeRegion = ct.getRegion().adjust(
13371 ct.getFrameWidth('t'),
13372 ct.getFrameWidth('l'),
13373 -ct.getFrameWidth('b'),
13374 -ct.getFrameWidth('r')
13378 this.proxy.setStyle('visibility', 'hidden'); // workaround display none
13380 this.proxy.setBox(this.startBox);
13382 this.proxy.setStyle('visibility', 'visible');
13388 onMouseDown : function(handle, e){
13391 this.activeHandle = handle;
13392 this.startSizing(e, handle);
13397 onMouseUp : function(e){
13398 var size = this.resizeElement();
13399 this.resizing = false;
13401 this.overlay.hide();
13403 this.fireEvent("resize", this, size.width, size.height, e);
13407 updateChildSize : function(){
13408 if(this.resizeChild){
13410 var child = this.resizeChild;
13411 var adj = this.adjustments;
13412 if(el.dom.offsetWidth){
13413 var b = el.getSize(true);
13414 child.setSize(b.width+adj[0], b.height+adj[1]);
13416 // Second call here for IE
13417 // The first call enables instant resizing and
13418 // the second call corrects scroll bars if they
13421 setTimeout(function(){
13422 if(el.dom.offsetWidth){
13423 var b = el.getSize(true);
13424 child.setSize(b.width+adj[0], b.height+adj[1]);
13432 snap : function(value, inc, min){
13433 if(!inc || !value) return value;
13434 var newValue = value;
13435 var m = value % inc;
13438 newValue = value + (inc-m);
13440 newValue = value - m;
13443 return Math.max(min, newValue);
13447 resizeElement : function(){
13448 var box = this.proxy.getBox();
13449 if(this.updateBox){
13450 this.el.setBox(box, false, this.animate, this.duration, null, this.easing);
13452 this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing);
13454 this.updateChildSize();
13462 constrain : function(v, diff, m, mx){
13465 }else if(v - diff > mx){
13472 onMouseMove : function(e){
13474 try{// try catch so if something goes wrong the user doesn't get hung
13476 if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {
13480 //var curXY = this.startPoint;
13481 var curSize = this.curSize || this.startBox;
13482 var x = this.startBox.x, y = this.startBox.y;
13483 var ox = x, oy = y;
13484 var w = curSize.width, h = curSize.height;
13485 var ow = w, oh = h;
13486 var mw = this.minWidth, mh = this.minHeight;
13487 var mxw = this.maxWidth, mxh = this.maxHeight;
13488 var wi = this.widthIncrement;
13489 var hi = this.heightIncrement;
13491 var eventXY = e.getXY();
13492 var diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0]));
13493 var diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1]));
13495 var pos = this.activeHandle.position;
13500 w = Math.min(Math.max(mw, w), mxw);
13505 h = Math.min(Math.max(mh, h), mxh);
13510 w = Math.min(Math.max(mw, w), mxw);
13511 h = Math.min(Math.max(mh, h), mxh);
13514 diffY = this.constrain(h, diffY, mh, mxh);
13521 var adiffX = Math.abs(diffX);
13522 var sub = (adiffX % wi); // how much
13523 if (sub > (wi/2)) { // far enough to snap
13524 diffX = (diffX > 0) ? diffX-sub + wi : diffX+sub - wi;
13526 // remove difference..
13527 diffX = (diffX > 0) ? diffX-sub : diffX+sub;
13531 x = Math.max(this.minX, x);
13534 diffX = this.constrain(w, diffX, mw, mxw);
13540 w = Math.min(Math.max(mw, w), mxw);
13541 diffY = this.constrain(h, diffY, mh, mxh);
13546 diffX = this.constrain(w, diffX, mw, mxw);
13547 diffY = this.constrain(h, diffY, mh, mxh);
13554 diffX = this.constrain(w, diffX, mw, mxw);
13556 h = Math.min(Math.max(mh, h), mxh);
13562 var sw = this.snap(w, wi, mw);
13563 var sh = this.snap(h, hi, mh);
13564 if(sw != w || sh != h){
13587 if(this.preserveRatio){
13592 h = Math.min(Math.max(mh, h), mxh);
13597 w = Math.min(Math.max(mw, w), mxw);
13602 w = Math.min(Math.max(mw, w), mxw);
13608 w = Math.min(Math.max(mw, w), mxw);
13614 h = Math.min(Math.max(mh, h), mxh);
13622 h = Math.min(Math.max(mh, h), mxh);
13632 h = Math.min(Math.max(mh, h), mxh);
13640 if (pos == 'hdrag') {
13643 this.proxy.setBounds(x, y, w, h);
13645 this.resizeElement();
13652 handleOver : function(){
13654 this.el.addClass("x-resizable-over");
13659 handleOut : function(){
13660 if(!this.resizing){
13661 this.el.removeClass("x-resizable-over");
13666 * Returns the element this component is bound to.
13667 * @return {Roo.Element}
13669 getEl : function(){
13674 * Returns the resizeChild element (or null).
13675 * @return {Roo.Element}
13677 getResizeChild : function(){
13678 return this.resizeChild;
13682 * Destroys this resizable. If the element was wrapped and
13683 * removeEl is not true then the element remains.
13684 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
13686 destroy : function(removeEl){
13687 this.proxy.remove();
13689 this.overlay.removeAllListeners();
13690 this.overlay.remove();
13692 var ps = Roo.Resizable.positions;
13694 if(typeof ps[k] != "function" && this[ps[k]]){
13695 var h = this[ps[k]];
13696 h.el.removeAllListeners();
13701 this.el.update("");
13708 // hash to map config positions to true positions
13709 Roo.Resizable.positions = {
13710 n: "north", s: "south", e: "east", w: "west", se: "southeast", sw: "southwest", nw: "northwest", ne: "northeast",
13715 Roo.Resizable.Handle = function(rz, pos, disableTrackOver, transparent){
13717 // only initialize the template if resizable is used
13718 var tpl = Roo.DomHelper.createTemplate(
13719 {tag: "div", cls: "x-resizable-handle x-resizable-handle-{0}"}
13722 Roo.Resizable.Handle.prototype.tpl = tpl;
13724 this.position = pos;
13726 // show north drag fro topdra
13727 var handlepos = pos == 'hdrag' ? 'north' : pos;
13729 this.el = this.tpl.append(rz.el.dom, [handlepos], true);
13730 if (pos == 'hdrag') {
13731 this.el.setStyle('cursor', 'pointer');
13733 this.el.unselectable();
13735 this.el.setOpacity(0);
13737 this.el.on("mousedown", this.onMouseDown, this);
13738 if(!disableTrackOver){
13739 this.el.on("mouseover", this.onMouseOver, this);
13740 this.el.on("mouseout", this.onMouseOut, this);
13745 Roo.Resizable.Handle.prototype = {
13746 afterResize : function(rz){
13750 onMouseDown : function(e){
13751 this.rz.onMouseDown(this, e);
13754 onMouseOver : function(e){
13755 this.rz.handleOver(this, e);
13758 onMouseOut : function(e){
13759 this.rz.handleOut(this, e);
13763 * Ext JS Library 1.1.1
13764 * Copyright(c) 2006-2007, Ext JS, LLC.
13766 * Originally Released Under LGPL - original licence link has changed is not relivant.
13769 * <script type="text/javascript">
13773 * @class Roo.Editor
13774 * @extends Roo.Component
13775 * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
13777 * Create a new Editor
13778 * @param {Roo.form.Field} field The Field object (or descendant)
13779 * @param {Object} config The config object
13781 Roo.Editor = function(field, config){
13782 Roo.Editor.superclass.constructor.call(this, config);
13783 this.field = field;
13786 * @event beforestartedit
13787 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
13788 * false from the handler of this event.
13789 * @param {Editor} this
13790 * @param {Roo.Element} boundEl The underlying element bound to this editor
13791 * @param {Mixed} value The field value being set
13793 "beforestartedit" : true,
13796 * Fires when this editor is displayed
13797 * @param {Roo.Element} boundEl The underlying element bound to this editor
13798 * @param {Mixed} value The starting field value
13800 "startedit" : true,
13802 * @event beforecomplete
13803 * Fires after a change has been made to the field, but before the change is reflected in the underlying
13804 * field. Saving the change to the field can be canceled by returning false from the handler of this event.
13805 * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
13806 * event will not fire since no edit actually occurred.
13807 * @param {Editor} this
13808 * @param {Mixed} value The current field value
13809 * @param {Mixed} startValue The original field value
13811 "beforecomplete" : true,
13814 * Fires after editing is complete and any changed value has been written to the underlying field.
13815 * @param {Editor} this
13816 * @param {Mixed} value The current field value
13817 * @param {Mixed} startValue The original field value
13821 * @event specialkey
13822 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
13823 * {@link Roo.EventObject#getKey} to determine which key was pressed.
13824 * @param {Roo.form.Field} this
13825 * @param {Roo.EventObject} e The event object
13827 "specialkey" : true
13831 Roo.extend(Roo.Editor, Roo.Component, {
13833 * @cfg {Boolean/String} autosize
13834 * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
13835 * or "height" to adopt the height only (defaults to false)
13838 * @cfg {Boolean} revertInvalid
13839 * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
13840 * validation fails (defaults to true)
13843 * @cfg {Boolean} ignoreNoChange
13844 * True to skip the the edit completion process (no save, no events fired) if the user completes an edit and
13845 * the value has not changed (defaults to false). Applies only to string values - edits for other data types
13846 * will never be ignored.
13849 * @cfg {Boolean} hideEl
13850 * False to keep the bound element visible while the editor is displayed (defaults to true)
13853 * @cfg {Mixed} value
13854 * The data value of the underlying field (defaults to "")
13858 * @cfg {String} alignment
13859 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "c-c?").
13863 * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
13864 * for bottom-right shadow (defaults to "frame")
13868 * @cfg {Boolean} constrain True to constrain the editor to the viewport
13872 * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed (defaults to false)
13874 completeOnEnter : false,
13876 * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed (defaults to false)
13878 cancelOnEsc : false,
13880 * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
13885 onRender : function(ct, position){
13886 this.el = new Roo.Layer({
13887 shadow: this.shadow,
13893 constrain: this.constrain
13895 this.el.setStyle("overflow", Roo.isGecko ? "auto" : "hidden");
13896 if(this.field.msgTarget != 'title'){
13897 this.field.msgTarget = 'qtip';
13899 this.field.render(this.el);
13901 this.field.el.dom.setAttribute('autocomplete', 'off');
13903 this.field.on("specialkey", this.onSpecialKey, this);
13904 if(this.swallowKeys){
13905 this.field.el.swallowEvent(['keydown','keypress']);
13908 this.field.on("blur", this.onBlur, this);
13909 if(this.field.grow){
13910 this.field.on("autosize", this.el.sync, this.el, {delay:1});
13914 onSpecialKey : function(field, e){
13915 //Roo.log('editor onSpecialKey');
13916 if(this.completeOnEnter && e.getKey() == e.ENTER){
13918 this.completeEdit();
13919 }else if(this.cancelOnEsc && e.getKey() == e.ESC){
13922 this.fireEvent('specialkey', field, e);
13927 * Starts the editing process and shows the editor.
13928 * @param {String/HTMLElement/Element} el The element to edit
13929 * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
13930 * to the innerHTML of el.
13932 startEdit : function(el, value){
13934 this.completeEdit();
13936 this.boundEl = Roo.get(el);
13937 var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
13938 if(!this.rendered){
13939 this.render(this.parentEl || document.body);
13941 if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
13944 this.startValue = v;
13945 this.field.setValue(v);
13947 var sz = this.boundEl.getSize();
13948 switch(this.autoSize){
13950 this.setSize(sz.width, "");
13953 this.setSize("", sz.height);
13956 this.setSize(sz.width, sz.height);
13959 this.el.alignTo(this.boundEl, this.alignment);
13960 this.editing = true;
13962 Roo.QuickTips.disable();
13968 * Sets the height and width of this editor.
13969 * @param {Number} width The new width
13970 * @param {Number} height The new height
13972 setSize : function(w, h){
13973 this.field.setSize(w, h);
13980 * Realigns the editor to the bound field based on the current alignment config value.
13982 realign : function(){
13983 this.el.alignTo(this.boundEl, this.alignment);
13987 * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
13988 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
13990 completeEdit : function(remainVisible){
13994 var v = this.getValue();
13995 if(this.revertInvalid !== false && !this.field.isValid()){
13996 v = this.startValue;
13997 this.cancelEdit(true);
13999 if(String(v) === String(this.startValue) && this.ignoreNoChange){
14000 this.editing = false;
14004 if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
14005 this.editing = false;
14006 if(this.updateEl && this.boundEl){
14007 this.boundEl.update(v);
14009 if(remainVisible !== true){
14012 this.fireEvent("complete", this, v, this.startValue);
14017 onShow : function(){
14019 if(this.hideEl !== false){
14020 this.boundEl.hide();
14023 if(Roo.isIE && !this.fixIEFocus){ // IE has problems with focusing the first time
14024 this.fixIEFocus = true;
14025 this.deferredFocus.defer(50, this);
14027 this.field.focus();
14029 this.fireEvent("startedit", this.boundEl, this.startValue);
14032 deferredFocus : function(){
14034 this.field.focus();
14039 * Cancels the editing process and hides the editor without persisting any changes. The field value will be
14040 * reverted to the original starting value.
14041 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
14042 * cancel (defaults to false)
14044 cancelEdit : function(remainVisible){
14046 this.setValue(this.startValue);
14047 if(remainVisible !== true){
14054 onBlur : function(){
14055 if(this.allowBlur !== true && this.editing){
14056 this.completeEdit();
14061 onHide : function(){
14063 this.completeEdit();
14067 if(this.field.collapse){
14068 this.field.collapse();
14071 if(this.hideEl !== false){
14072 this.boundEl.show();
14075 Roo.QuickTips.enable();
14080 * Sets the data value of the editor
14081 * @param {Mixed} value Any valid value supported by the underlying field
14083 setValue : function(v){
14084 this.field.setValue(v);
14088 * Gets the data value of the editor
14089 * @return {Mixed} The data value
14091 getValue : function(){
14092 return this.field.getValue();
14096 * Ext JS Library 1.1.1
14097 * Copyright(c) 2006-2007, Ext JS, LLC.
14099 * Originally Released Under LGPL - original licence link has changed is not relivant.
14102 * <script type="text/javascript">
14106 * @class Roo.BasicDialog
14107 * @extends Roo.util.Observable
14108 * Lightweight Dialog Class. The code below shows the creation of a typical dialog using existing HTML markup:
14110 var dlg = new Roo.BasicDialog("my-dlg", {
14119 dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
14120 dlg.addButton('OK', dlg.hide, dlg); // Could call a save function instead of hiding
14121 dlg.addButton('Cancel', dlg.hide, dlg);
14124 <b>A Dialog should always be a direct child of the body element.</b>
14125 * @cfg {Boolean/DomHelper} autoCreate True to auto create from scratch, or using a DomHelper Object (defaults to false)
14126 * @cfg {String} title Default text to display in the title bar (defaults to null)
14127 * @cfg {Number} width Width of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
14128 * @cfg {Number} height Height of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
14129 * @cfg {Number} x The default left page coordinate of the dialog (defaults to center screen)
14130 * @cfg {Number} y The default top page coordinate of the dialog (defaults to center screen)
14131 * @cfg {String/Element} animateTarget Id or element from which the dialog should animate while opening
14132 * (defaults to null with no animation)
14133 * @cfg {Boolean} resizable False to disable manual dialog resizing (defaults to true)
14134 * @cfg {String} resizeHandles Which resize handles to display - see the {@link Roo.Resizable} handles config
14135 * property for valid values (defaults to 'all')
14136 * @cfg {Number} minHeight The minimum allowable height for a resizable dialog (defaults to 80)
14137 * @cfg {Number} minWidth The minimum allowable width for a resizable dialog (defaults to 200)
14138 * @cfg {Boolean} modal True to show the dialog modally, preventing user interaction with the rest of the page (defaults to false)
14139 * @cfg {Boolean} autoScroll True to allow the dialog body contents to overflow and display scrollbars (defaults to false)
14140 * @cfg {Boolean} closable False to remove the built-in top-right corner close button (defaults to true)
14141 * @cfg {Boolean} collapsible False to remove the built-in top-right corner collapse button (defaults to true)
14142 * @cfg {Boolean} constraintoviewport True to keep the dialog constrained within the visible viewport boundaries (defaults to true)
14143 * @cfg {Boolean} syncHeightBeforeShow True to cause the dimensions to be recalculated before the dialog is shown (defaults to false)
14144 * @cfg {Boolean} draggable False to disable dragging of the dialog within the viewport (defaults to true)
14145 * @cfg {Boolean} autoTabs If true, all elements with class 'x-dlg-tab' will get automatically converted to tabs (defaults to false)
14146 * @cfg {String} tabTag The tag name of tab elements, used when autoTabs = true (defaults to 'div')
14147 * @cfg {Boolean} proxyDrag True to drag a lightweight proxy element rather than the dialog itself, used when
14148 * draggable = true (defaults to false)
14149 * @cfg {Boolean} fixedcenter True to ensure that anytime the dialog is shown or resized it gets centered (defaults to false)
14150 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
14151 * shadow (defaults to false)
14152 * @cfg {Number} shadowOffset The number of pixels to offset the shadow if displayed (defaults to 5)
14153 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "right")
14154 * @cfg {Number} minButtonWidth Minimum width of all dialog buttons (defaults to 75)
14155 * @cfg {Array} buttons Array of buttons
14156 * @cfg {Boolean} shim True to create an iframe shim that prevents selects from showing through (defaults to false)
14158 * Create a new BasicDialog.
14159 * @param {String/HTMLElement/Roo.Element} el The container element or DOM node, or its id
14160 * @param {Object} config Configuration options
14162 Roo.BasicDialog = function(el, config){
14163 this.el = Roo.get(el);
14164 var dh = Roo.DomHelper;
14165 if(!this.el && config && config.autoCreate){
14166 if(typeof config.autoCreate == "object"){
14167 if(!config.autoCreate.id){
14168 config.autoCreate.id = el;
14170 this.el = dh.append(document.body,
14171 config.autoCreate, true);
14173 this.el = dh.append(document.body,
14174 {tag: "div", id: el, style:'visibility:hidden;'}, true);
14178 el.setDisplayed(true);
14179 el.hide = this.hideAction;
14181 el.addClass("x-dlg");
14183 Roo.apply(this, config);
14185 this.proxy = el.createProxy("x-dlg-proxy");
14186 this.proxy.hide = this.hideAction;
14187 this.proxy.setOpacity(.5);
14191 el.setWidth(config.width);
14194 el.setHeight(config.height);
14196 this.size = el.getSize();
14197 if(typeof config.x != "undefined" && typeof config.y != "undefined"){
14198 this.xy = [config.x,config.y];
14200 this.xy = el.getCenterXY(true);
14202 /** The header element @type Roo.Element */
14203 this.header = el.child("> .x-dlg-hd");
14204 /** The body element @type Roo.Element */
14205 this.body = el.child("> .x-dlg-bd");
14206 /** The footer element @type Roo.Element */
14207 this.footer = el.child("> .x-dlg-ft");
14210 this.header = el.createChild({tag: "div", cls:"x-dlg-hd", html: " "}, this.body ? this.body.dom : null);
14213 this.body = el.createChild({tag: "div", cls:"x-dlg-bd"});
14216 this.header.unselectable();
14218 this.header.update(this.title);
14220 // this element allows the dialog to be focused for keyboard event
14221 this.focusEl = el.createChild({tag: "a", href:"#", cls:"x-dlg-focus", tabIndex:"-1"});
14222 this.focusEl.swallowEvent("click", true);
14224 this.header.wrap({cls:"x-dlg-hd-right"}).wrap({cls:"x-dlg-hd-left"}, true);
14226 // wrap the body and footer for special rendering
14227 this.bwrap = this.body.wrap({tag: "div", cls:"x-dlg-dlg-body"});
14229 this.bwrap.dom.appendChild(this.footer.dom);
14232 this.bg = this.el.createChild({
14233 tag: "div", cls:"x-dlg-bg",
14234 html: '<div class="x-dlg-bg-left"><div class="x-dlg-bg-right"><div class="x-dlg-bg-center"> </div></div></div>'
14236 this.centerBg = this.bg.child("div.x-dlg-bg-center");
14239 if(this.autoScroll !== false && !this.autoTabs){
14240 this.body.setStyle("overflow", "auto");
14243 this.toolbox = this.el.createChild({cls: "x-dlg-toolbox"});
14245 if(this.closable !== false){
14246 this.el.addClass("x-dlg-closable");
14247 this.close = this.toolbox.createChild({cls:"x-dlg-close"});
14248 this.close.on("click", this.closeClick, this);
14249 this.close.addClassOnOver("x-dlg-close-over");
14251 if(this.collapsible !== false){
14252 this.collapseBtn = this.toolbox.createChild({cls:"x-dlg-collapse"});
14253 this.collapseBtn.on("click", this.collapseClick, this);
14254 this.collapseBtn.addClassOnOver("x-dlg-collapse-over");
14255 this.header.on("dblclick", this.collapseClick, this);
14257 if(this.resizable !== false){
14258 this.el.addClass("x-dlg-resizable");
14259 this.resizer = new Roo.Resizable(el, {
14260 minWidth: this.minWidth || 80,
14261 minHeight:this.minHeight || 80,
14262 handles: this.resizeHandles || "all",
14265 this.resizer.on("beforeresize", this.beforeResize, this);
14266 this.resizer.on("resize", this.onResize, this);
14268 if(this.draggable !== false){
14269 el.addClass("x-dlg-draggable");
14270 if (!this.proxyDrag) {
14271 var dd = new Roo.dd.DD(el.dom.id, "WindowDrag");
14274 var dd = new Roo.dd.DDProxy(el.dom.id, "WindowDrag", {dragElId: this.proxy.id});
14276 dd.setHandleElId(this.header.id);
14277 dd.endDrag = this.endMove.createDelegate(this);
14278 dd.startDrag = this.startMove.createDelegate(this);
14279 dd.onDrag = this.onDrag.createDelegate(this);
14284 this.mask = dh.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
14285 this.mask.enableDisplayMode("block");
14287 this.el.addClass("x-dlg-modal");
14290 this.shadow = new Roo.Shadow({
14291 mode : typeof this.shadow == "string" ? this.shadow : "sides",
14292 offset : this.shadowOffset
14295 this.shadowOffset = 0;
14297 if(Roo.useShims && this.shim !== false){
14298 this.shim = this.el.createShim();
14299 this.shim.hide = this.hideAction;
14307 if (this.buttons) {
14308 var bts= this.buttons;
14310 Roo.each(bts, function(b) {
14319 * Fires when a key is pressed
14320 * @param {Roo.BasicDialog} this
14321 * @param {Roo.EventObject} e
14326 * Fires when this dialog is moved by the user.
14327 * @param {Roo.BasicDialog} this
14328 * @param {Number} x The new page X
14329 * @param {Number} y The new page Y
14334 * Fires when this dialog is resized by the user.
14335 * @param {Roo.BasicDialog} this
14336 * @param {Number} width The new width
14337 * @param {Number} height The new height
14341 * @event beforehide
14342 * Fires before this dialog is hidden.
14343 * @param {Roo.BasicDialog} this
14345 "beforehide" : true,
14348 * Fires when this dialog is hidden.
14349 * @param {Roo.BasicDialog} this
14353 * @event beforeshow
14354 * Fires before this dialog is shown.
14355 * @param {Roo.BasicDialog} this
14357 "beforeshow" : true,
14360 * Fires when this dialog is shown.
14361 * @param {Roo.BasicDialog} this
14365 el.on("keydown", this.onKeyDown, this);
14366 el.on("mousedown", this.toFront, this);
14367 Roo.EventManager.onWindowResize(this.adjustViewport, this, true);
14369 Roo.DialogManager.register(this);
14370 Roo.BasicDialog.superclass.constructor.call(this);
14373 Roo.extend(Roo.BasicDialog, Roo.util.Observable, {
14374 shadowOffset: Roo.isIE ? 6 : 5,
14377 minButtonWidth: 75,
14378 defaultButton: null,
14379 buttonAlign: "right",
14384 * Sets the dialog title text
14385 * @param {String} text The title text to display
14386 * @return {Roo.BasicDialog} this
14388 setTitle : function(text){
14389 this.header.update(text);
14394 closeClick : function(){
14399 collapseClick : function(){
14400 this[this.collapsed ? "expand" : "collapse"]();
14404 * Collapses the dialog to its minimized state (only the title bar is visible).
14405 * Equivalent to the user clicking the collapse dialog button.
14407 collapse : function(){
14408 if(!this.collapsed){
14409 this.collapsed = true;
14410 this.el.addClass("x-dlg-collapsed");
14411 this.restoreHeight = this.el.getHeight();
14412 this.resizeTo(this.el.getWidth(), this.header.getHeight());
14417 * Expands a collapsed dialog back to its normal state. Equivalent to the user
14418 * clicking the expand dialog button.
14420 expand : function(){
14421 if(this.collapsed){
14422 this.collapsed = false;
14423 this.el.removeClass("x-dlg-collapsed");
14424 this.resizeTo(this.el.getWidth(), this.restoreHeight);
14429 * Reinitializes the tabs component, clearing out old tabs and finding new ones.
14430 * @return {Roo.TabPanel} The tabs component
14432 initTabs : function(){
14433 var tabs = this.getTabs();
14434 while(tabs.getTab(0)){
14437 this.el.select(this.tabTag+'.x-dlg-tab').each(function(el){
14439 tabs.addTab(Roo.id(dom), dom.title);
14447 beforeResize : function(){
14448 this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
14452 onResize : function(){
14453 this.refreshSize();
14454 this.syncBodyHeight();
14455 this.adjustAssets();
14457 this.fireEvent("resize", this, this.size.width, this.size.height);
14461 onKeyDown : function(e){
14462 if(this.isVisible()){
14463 this.fireEvent("keydown", this, e);
14468 * Resizes the dialog.
14469 * @param {Number} width
14470 * @param {Number} height
14471 * @return {Roo.BasicDialog} this
14473 resizeTo : function(width, height){
14474 this.el.setSize(width, height);
14475 this.size = {width: width, height: height};
14476 this.syncBodyHeight();
14477 if(this.fixedcenter){
14480 if(this.isVisible()){
14481 this.constrainXY();
14482 this.adjustAssets();
14484 this.fireEvent("resize", this, width, height);
14490 * Resizes the dialog to fit the specified content size.
14491 * @param {Number} width
14492 * @param {Number} height
14493 * @return {Roo.BasicDialog} this
14495 setContentSize : function(w, h){
14496 h += this.getHeaderFooterHeight() + this.body.getMargins("tb");
14497 w += this.body.getMargins("lr") + this.bwrap.getMargins("lr") + this.centerBg.getPadding("lr");
14498 //if(!this.el.isBorderBox()){
14499 h += this.body.getPadding("tb") + this.bwrap.getBorderWidth("tb") + this.body.getBorderWidth("tb") + this.el.getBorderWidth("tb");
14500 w += this.body.getPadding("lr") + this.bwrap.getBorderWidth("lr") + this.body.getBorderWidth("lr") + this.bwrap.getPadding("lr") + this.el.getBorderWidth("lr");
14503 h += this.tabs.stripWrap.getHeight() + this.tabs.bodyEl.getMargins("tb") + this.tabs.bodyEl.getPadding("tb");
14504 w += this.tabs.bodyEl.getMargins("lr") + this.tabs.bodyEl.getPadding("lr");
14506 this.resizeTo(w, h);
14511 * Adds a key listener for when this dialog is displayed. This allows you to hook in a function that will be
14512 * executed in response to a particular key being pressed while the dialog is active.
14513 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the following options:
14514 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
14515 * @param {Function} fn The function to call
14516 * @param {Object} scope (optional) The scope of the function
14517 * @return {Roo.BasicDialog} this
14519 addKeyListener : function(key, fn, scope){
14520 var keyCode, shift, ctrl, alt;
14521 if(typeof key == "object" && !(key instanceof Array)){
14522 keyCode = key["key"];
14523 shift = key["shift"];
14524 ctrl = key["ctrl"];
14529 var handler = function(dlg, e){
14530 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
14531 var k = e.getKey();
14532 if(keyCode instanceof Array){
14533 for(var i = 0, len = keyCode.length; i < len; i++){
14534 if(keyCode[i] == k){
14535 fn.call(scope || window, dlg, k, e);
14541 fn.call(scope || window, dlg, k, e);
14546 this.on("keydown", handler);
14551 * Returns the TabPanel component (creates it if it doesn't exist).
14552 * Note: If you wish to simply check for the existence of tabs without creating them,
14553 * check for a null 'tabs' property.
14554 * @return {Roo.TabPanel} The tabs component
14556 getTabs : function(){
14558 this.el.addClass("x-dlg-auto-tabs");
14559 this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
14560 this.tabs = new Roo.TabPanel(this.body.dom, this.tabPosition == "bottom");
14566 * Adds a button to the footer section of the dialog.
14567 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
14568 * object or a valid Roo.DomHelper element config
14569 * @param {Function} handler The function called when the button is clicked
14570 * @param {Object} scope (optional) The scope of the handler function (accepts position as a property)
14571 * @return {Roo.Button} The new button
14573 addButton : function(config, handler, scope){
14574 var dh = Roo.DomHelper;
14576 this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
14578 if(!this.btnContainer){
14579 var tb = this.footer.createChild({
14581 cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
14582 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
14584 this.btnContainer = tb.firstChild.firstChild.firstChild;
14589 minWidth: this.minButtonWidth,
14592 if(typeof config == "string"){
14593 bconfig.text = config;
14596 bconfig.dhconfig = config;
14598 Roo.apply(bconfig, config);
14602 if ((typeof(bconfig.position) != 'undefined') && bconfig.position < this.btnContainer.childNodes.length-1) {
14603 bconfig.position = Math.max(0, bconfig.position);
14604 fc = this.btnContainer.childNodes[bconfig.position];
14607 var btn = new Roo.Button(
14609 this.btnContainer.insertBefore(document.createElement("td"),fc)
14610 : this.btnContainer.appendChild(document.createElement("td")),
14611 //Roo.get(this.btnContainer).createChild( { tag: 'td'}, fc ),
14614 this.syncBodyHeight();
14617 * Array of all the buttons that have been added to this dialog via addButton
14622 this.buttons.push(btn);
14627 * Sets the default button to be focused when the dialog is displayed.
14628 * @param {Roo.BasicDialog.Button} btn The button object returned by {@link #addButton}
14629 * @return {Roo.BasicDialog} this
14631 setDefaultButton : function(btn){
14632 this.defaultButton = btn;
14637 getHeaderFooterHeight : function(safe){
14640 height += this.header.getHeight();
14643 var fm = this.footer.getMargins();
14644 height += (this.footer.getHeight()+fm.top+fm.bottom);
14646 height += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
14647 height += this.centerBg.getPadding("tb");
14652 syncBodyHeight : function(){
14653 var bd = this.body, cb = this.centerBg, bw = this.bwrap;
14654 var height = this.size.height - this.getHeaderFooterHeight(false);
14655 bd.setHeight(height-bd.getMargins("tb"));
14656 var hh = this.header.getHeight();
14657 var h = this.size.height-hh;
14659 bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
14660 bw.setHeight(h-cb.getPadding("tb"));
14661 bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
14662 bd.setWidth(bw.getWidth(true));
14664 this.tabs.syncHeight();
14666 this.tabs.el.repaint();
14672 * Restores the previous state of the dialog if Roo.state is configured.
14673 * @return {Roo.BasicDialog} this
14675 restoreState : function(){
14676 var box = Roo.state.Manager.get(this.stateId || (this.el.id + "-state"));
14677 if(box && box.width){
14678 this.xy = [box.x, box.y];
14679 this.resizeTo(box.width, box.height);
14685 beforeShow : function(){
14687 if(this.fixedcenter){
14688 this.xy = this.el.getCenterXY(true);
14691 Roo.get(document.body).addClass("x-body-masked");
14692 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
14695 this.constrainXY();
14699 animShow : function(){
14700 var b = Roo.get(this.animateTarget).getBox();
14701 this.proxy.setSize(b.width, b.height);
14702 this.proxy.setLocation(b.x, b.y);
14704 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
14705 true, .35, this.showEl.createDelegate(this));
14709 * Shows the dialog.
14710 * @param {String/HTMLElement/Roo.Element} animateTarget (optional) Reset the animation target
14711 * @return {Roo.BasicDialog} this
14713 show : function(animateTarget){
14714 if (this.fireEvent("beforeshow", this) === false){
14717 if(this.syncHeightBeforeShow){
14718 this.syncBodyHeight();
14719 }else if(this.firstShow){
14720 this.firstShow = false;
14721 this.syncBodyHeight(); // sync the height on the first show instead of in the constructor
14723 this.animateTarget = animateTarget || this.animateTarget;
14724 if(!this.el.isVisible()){
14726 if(this.animateTarget && Roo.get(this.animateTarget)){
14736 showEl : function(){
14738 this.el.setXY(this.xy);
14740 this.adjustAssets(true);
14743 // IE peekaboo bug - fix found by Dave Fenwick
14747 this.fireEvent("show", this);
14751 * Focuses the dialog. If a defaultButton is set, it will receive focus, otherwise the
14752 * dialog itself will receive focus.
14754 focus : function(){
14755 if(this.defaultButton){
14756 this.defaultButton.focus();
14758 this.focusEl.focus();
14763 constrainXY : function(){
14764 if(this.constraintoviewport !== false){
14765 if(!this.viewSize){
14766 if(this.container){
14767 var s = this.container.getSize();
14768 this.viewSize = [s.width, s.height];
14770 this.viewSize = [Roo.lib.Dom.getViewWidth(),Roo.lib.Dom.getViewHeight()];
14773 var s = Roo.get(this.container||document).getScroll();
14775 var x = this.xy[0], y = this.xy[1];
14776 var w = this.size.width, h = this.size.height;
14777 var vw = this.viewSize[0], vh = this.viewSize[1];
14778 // only move it if it needs it
14780 // first validate right/bottom
14781 if(x + w > vw+s.left){
14785 if(y + h > vh+s.top){
14789 // then make sure top/left isn't negative
14801 if(this.isVisible()){
14802 this.el.setLocation(x, y);
14803 this.adjustAssets();
14810 onDrag : function(){
14811 if(!this.proxyDrag){
14812 this.xy = this.el.getXY();
14813 this.adjustAssets();
14818 adjustAssets : function(doShow){
14819 var x = this.xy[0], y = this.xy[1];
14820 var w = this.size.width, h = this.size.height;
14821 if(doShow === true){
14823 this.shadow.show(this.el);
14829 if(this.shadow && this.shadow.isVisible()){
14830 this.shadow.show(this.el);
14832 if(this.shim && this.shim.isVisible()){
14833 this.shim.setBounds(x, y, w, h);
14838 adjustViewport : function(w, h){
14840 w = Roo.lib.Dom.getViewWidth();
14841 h = Roo.lib.Dom.getViewHeight();
14844 this.viewSize = [w, h];
14845 if(this.modal && this.mask.isVisible()){
14846 this.mask.setSize(w, h); // first make sure the mask isn't causing overflow
14847 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
14849 if(this.isVisible()){
14850 this.constrainXY();
14855 * Destroys this dialog and all its supporting elements (including any tabs, shim,
14856 * shadow, proxy, mask, etc.) Also removes all event listeners.
14857 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
14859 destroy : function(removeEl){
14860 if(this.isVisible()){
14861 this.animateTarget = null;
14864 Roo.EventManager.removeResizeListener(this.adjustViewport, this);
14866 this.tabs.destroy(removeEl);
14879 for(var i = 0, len = this.buttons.length; i < len; i++){
14880 this.buttons[i].destroy();
14883 this.el.removeAllListeners();
14884 if(removeEl === true){
14885 this.el.update("");
14888 Roo.DialogManager.unregister(this);
14892 startMove : function(){
14893 if(this.proxyDrag){
14896 if(this.constraintoviewport !== false){
14897 this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
14902 endMove : function(){
14903 if(!this.proxyDrag){
14904 Roo.dd.DD.prototype.endDrag.apply(this.dd, arguments);
14906 Roo.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
14909 this.refreshSize();
14910 this.adjustAssets();
14912 this.fireEvent("move", this, this.xy[0], this.xy[1]);
14916 * Brings this dialog to the front of any other visible dialogs
14917 * @return {Roo.BasicDialog} this
14919 toFront : function(){
14920 Roo.DialogManager.bringToFront(this);
14925 * Sends this dialog to the back (under) of any other visible dialogs
14926 * @return {Roo.BasicDialog} this
14928 toBack : function(){
14929 Roo.DialogManager.sendToBack(this);
14934 * Centers this dialog in the viewport
14935 * @return {Roo.BasicDialog} this
14937 center : function(){
14938 var xy = this.el.getCenterXY(true);
14939 this.moveTo(xy[0], xy[1]);
14944 * Moves the dialog's top-left corner to the specified point
14945 * @param {Number} x
14946 * @param {Number} y
14947 * @return {Roo.BasicDialog} this
14949 moveTo : function(x, y){
14951 if(this.isVisible()){
14952 this.el.setXY(this.xy);
14953 this.adjustAssets();
14959 * Aligns the dialog to the specified element
14960 * @param {String/HTMLElement/Roo.Element} element The element to align to.
14961 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details).
14962 * @param {Array} offsets (optional) Offset the positioning by [x, y]
14963 * @return {Roo.BasicDialog} this
14965 alignTo : function(element, position, offsets){
14966 this.xy = this.el.getAlignToXY(element, position, offsets);
14967 if(this.isVisible()){
14968 this.el.setXY(this.xy);
14969 this.adjustAssets();
14975 * Anchors an element to another element and realigns it when the window is resized.
14976 * @param {String/HTMLElement/Roo.Element} element The element to align to.
14977 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details)
14978 * @param {Array} offsets (optional) Offset the positioning by [x, y]
14979 * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
14980 * is a number, it is used as the buffer delay (defaults to 50ms).
14981 * @return {Roo.BasicDialog} this
14983 anchorTo : function(el, alignment, offsets, monitorScroll){
14984 var action = function(){
14985 this.alignTo(el, alignment, offsets);
14987 Roo.EventManager.onWindowResize(action, this);
14988 var tm = typeof monitorScroll;
14989 if(tm != 'undefined'){
14990 Roo.EventManager.on(window, 'scroll', action, this,
14991 {buffer: tm == 'number' ? monitorScroll : 50});
14998 * Returns true if the dialog is visible
14999 * @return {Boolean}
15001 isVisible : function(){
15002 return this.el.isVisible();
15006 animHide : function(callback){
15007 var b = Roo.get(this.animateTarget).getBox();
15009 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
15011 this.proxy.setBounds(b.x, b.y, b.width, b.height, true, .35,
15012 this.hideEl.createDelegate(this, [callback]));
15016 * Hides the dialog.
15017 * @param {Function} callback (optional) Function to call when the dialog is hidden
15018 * @return {Roo.BasicDialog} this
15020 hide : function(callback){
15021 if (this.fireEvent("beforehide", this) === false){
15025 this.shadow.hide();
15030 // sometimes animateTarget seems to get set.. causing problems...
15031 // this just double checks..
15032 if(this.animateTarget && Roo.get(this.animateTarget)) {
15033 this.animHide(callback);
15036 this.hideEl(callback);
15042 hideEl : function(callback){
15046 Roo.get(document.body).removeClass("x-body-masked");
15048 this.fireEvent("hide", this);
15049 if(typeof callback == "function"){
15055 hideAction : function(){
15056 this.setLeft("-10000px");
15057 this.setTop("-10000px");
15058 this.setStyle("visibility", "hidden");
15062 refreshSize : function(){
15063 this.size = this.el.getSize();
15064 this.xy = this.el.getXY();
15065 Roo.state.Manager.set(this.stateId || this.el.id + "-state", this.el.getBox());
15069 // z-index is managed by the DialogManager and may be overwritten at any time
15070 setZIndex : function(index){
15072 this.mask.setStyle("z-index", index);
15075 this.shim.setStyle("z-index", ++index);
15078 this.shadow.setZIndex(++index);
15080 this.el.setStyle("z-index", ++index);
15082 this.proxy.setStyle("z-index", ++index);
15085 this.resizer.proxy.setStyle("z-index", ++index);
15088 this.lastZIndex = index;
15092 * Returns the element for this dialog
15093 * @return {Roo.Element} The underlying dialog Element
15095 getEl : function(){
15101 * @class Roo.DialogManager
15102 * Provides global access to BasicDialogs that have been created and
15103 * support for z-indexing (layering) multiple open dialogs.
15105 Roo.DialogManager = function(){
15107 var accessList = [];
15111 var sortDialogs = function(d1, d2){
15112 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
15116 var orderDialogs = function(){
15117 accessList.sort(sortDialogs);
15118 var seed = Roo.DialogManager.zseed;
15119 for(var i = 0, len = accessList.length; i < len; i++){
15120 var dlg = accessList[i];
15122 dlg.setZIndex(seed + (i*10));
15129 * The starting z-index for BasicDialogs (defaults to 9000)
15130 * @type Number The z-index value
15135 register : function(dlg){
15136 list[dlg.id] = dlg;
15137 accessList.push(dlg);
15141 unregister : function(dlg){
15142 delete list[dlg.id];
15145 if(!accessList.indexOf){
15146 for( i = 0, len = accessList.length; i < len; i++){
15147 if(accessList[i] == dlg){
15148 accessList.splice(i, 1);
15153 i = accessList.indexOf(dlg);
15155 accessList.splice(i, 1);
15161 * Gets a registered dialog by id
15162 * @param {String/Object} id The id of the dialog or a dialog
15163 * @return {Roo.BasicDialog} this
15165 get : function(id){
15166 return typeof id == "object" ? id : list[id];
15170 * Brings the specified dialog to the front
15171 * @param {String/Object} dlg The id of the dialog or a dialog
15172 * @return {Roo.BasicDialog} this
15174 bringToFront : function(dlg){
15175 dlg = this.get(dlg);
15178 dlg._lastAccess = new Date().getTime();
15185 * Sends the specified dialog to the back
15186 * @param {String/Object} dlg The id of the dialog or a dialog
15187 * @return {Roo.BasicDialog} this
15189 sendToBack : function(dlg){
15190 dlg = this.get(dlg);
15191 dlg._lastAccess = -(new Date().getTime());
15197 * Hides all dialogs
15199 hideAll : function(){
15200 for(var id in list){
15201 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
15210 * @class Roo.LayoutDialog
15211 * @extends Roo.BasicDialog
15212 * Dialog which provides adjustments for working with a layout in a Dialog.
15213 * Add your necessary layout config options to the dialog's config.<br>
15214 * Example usage (including a nested layout):
15217 dialog = new Roo.LayoutDialog("download-dlg", {
15226 // layout config merges with the dialog config
15228 tabPosition: "top",
15229 alwaysShowTabs: true
15232 dialog.addKeyListener(27, dialog.hide, dialog);
15233 dialog.setDefaultButton(dialog.addButton("Close", dialog.hide, dialog));
15234 dialog.addButton("Build It!", this.getDownload, this);
15236 // we can even add nested layouts
15237 var innerLayout = new Roo.BorderLayout("dl-inner", {
15247 innerLayout.beginUpdate();
15248 innerLayout.add("east", new Roo.ContentPanel("dl-details"));
15249 innerLayout.add("center", new Roo.ContentPanel("selection-panel"));
15250 innerLayout.endUpdate(true);
15252 var layout = dialog.getLayout();
15253 layout.beginUpdate();
15254 layout.add("center", new Roo.ContentPanel("standard-panel",
15255 {title: "Download the Source", fitToFrame:true}));
15256 layout.add("center", new Roo.NestedLayoutPanel(innerLayout,
15257 {title: "Build your own roo.js"}));
15258 layout.getRegion("center").showPanel(sp);
15259 layout.endUpdate();
15263 * @param {String/HTMLElement/Roo.Element} el The id of or container element, or config
15264 * @param {Object} config configuration options
15266 Roo.LayoutDialog = function(el, cfg){
15269 if (typeof(cfg) == 'undefined') {
15270 config = Roo.apply({}, el);
15271 // not sure why we use documentElement here.. - it should always be body.
15272 // IE7 borks horribly if we use documentElement.
15273 el = Roo.get( Roo.isIE ? (document.body || document.documentElement) : (document.documentElement || document.body) ).createChild();
15274 //config.autoCreate = true;
15278 config.autoTabs = false;
15279 Roo.LayoutDialog.superclass.constructor.call(this, el, config);
15280 this.body.setStyle({overflow:"hidden", position:"relative"});
15281 this.layout = new Roo.BorderLayout(this.body.dom, config);
15282 this.layout.monitorWindowResize = false;
15283 this.el.addClass("x-dlg-auto-layout");
15284 // fix case when center region overwrites center function
15285 this.center = Roo.BasicDialog.prototype.center;
15286 this.on("show", this.layout.layout, this.layout, true);
15287 if (config.items) {
15288 var xitems = config.items;
15289 delete config.items;
15290 Roo.each(xitems, this.addxtype, this);
15295 Roo.extend(Roo.LayoutDialog, Roo.BasicDialog, {
15297 * Ends update of the layout <strike>and resets display to none</strike>. Use standard beginUpdate/endUpdate on the layout.
15300 endUpdate : function(){
15301 this.layout.endUpdate();
15305 * Begins an update of the layout <strike>and sets display to block and visibility to hidden</strike>. Use standard beginUpdate/endUpdate on the layout.
15308 beginUpdate : function(){
15309 this.layout.beginUpdate();
15313 * Get the BorderLayout for this dialog
15314 * @return {Roo.BorderLayout}
15316 getLayout : function(){
15317 return this.layout;
15320 showEl : function(){
15321 Roo.LayoutDialog.superclass.showEl.apply(this, arguments);
15323 this.layout.layout();
15328 // Use the syncHeightBeforeShow config option to control this automatically
15329 syncBodyHeight : function(){
15330 Roo.LayoutDialog.superclass.syncBodyHeight.call(this);
15331 if(this.layout){this.layout.layout();}
15335 * Add an xtype element (actually adds to the layout.)
15336 * @return {Object} xdata xtype object data.
15339 addxtype : function(c) {
15340 return this.layout.addxtype(c);
15344 * Ext JS Library 1.1.1
15345 * Copyright(c) 2006-2007, Ext JS, LLC.
15347 * Originally Released Under LGPL - original licence link has changed is not relivant.
15350 * <script type="text/javascript">
15354 * @class Roo.MessageBox
15355 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
15359 Roo.Msg.alert('Status', 'Changes saved successfully.');
15361 // Prompt for user data:
15362 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
15364 // process text value...
15368 // Show a dialog using config options:
15370 title:'Save Changes?',
15371 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
15372 buttons: Roo.Msg.YESNOCANCEL,
15379 Roo.MessageBox = function(){
15380 var dlg, opt, mask, waitTimer;
15381 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
15382 var buttons, activeTextEl, bwidth;
15385 var handleButton = function(button){
15387 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
15391 var handleHide = function(){
15392 if(opt && opt.cls){
15393 dlg.el.removeClass(opt.cls);
15396 Roo.TaskMgr.stop(waitTimer);
15402 var updateButtons = function(b){
15405 buttons["ok"].hide();
15406 buttons["cancel"].hide();
15407 buttons["yes"].hide();
15408 buttons["no"].hide();
15409 dlg.footer.dom.style.display = 'none';
15412 dlg.footer.dom.style.display = '';
15413 for(var k in buttons){
15414 if(typeof buttons[k] != "function"){
15417 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.MessageBox.buttonText[k]);
15418 width += buttons[k].el.getWidth()+15;
15428 var handleEsc = function(d, k, e){
15429 if(opt && opt.closable !== false){
15439 * Returns a reference to the underlying {@link Roo.BasicDialog} element
15440 * @return {Roo.BasicDialog} The BasicDialog element
15442 getDialog : function(){
15444 dlg = new Roo.BasicDialog("x-msg-box", {
15449 constraintoviewport:false,
15451 collapsible : false,
15454 width:400, height:100,
15455 buttonAlign:"center",
15456 closeClick : function(){
15457 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
15458 handleButton("no");
15460 handleButton("cancel");
15464 dlg.on("hide", handleHide);
15466 dlg.addKeyListener(27, handleEsc);
15468 var bt = this.buttonText;
15469 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
15470 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
15471 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
15472 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
15473 bodyEl = dlg.body.createChild({
15475 html:'<span class="roo-mb-text"></span><br /><input type="text" class="roo-mb-input" /><textarea class="roo-mb-textarea"></textarea><div class="roo-mb-progress-wrap"><div class="roo-mb-progress"><div class="roo-mb-progress-bar"> </div></div></div>'
15477 msgEl = bodyEl.dom.firstChild;
15478 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
15479 textboxEl.enableDisplayMode();
15480 textboxEl.addKeyListener([10,13], function(){
15481 if(dlg.isVisible() && opt && opt.buttons){
15482 if(opt.buttons.ok){
15483 handleButton("ok");
15484 }else if(opt.buttons.yes){
15485 handleButton("yes");
15489 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
15490 textareaEl.enableDisplayMode();
15491 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
15492 progressEl.enableDisplayMode();
15493 var pf = progressEl.dom.firstChild;
15495 pp = Roo.get(pf.firstChild);
15496 pp.setHeight(pf.offsetHeight);
15504 * Updates the message box body text
15505 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
15506 * the XHTML-compliant non-breaking space character '&#160;')
15507 * @return {Roo.MessageBox} This message box
15509 updateText : function(text){
15510 if(!dlg.isVisible() && !opt.width){
15511 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
15513 msgEl.innerHTML = text || ' ';
15514 var w = Math.max(Math.min(opt.width || msgEl.offsetWidth, this.maxWidth),
15515 Math.max(opt.minWidth || this.minWidth, bwidth));
15517 activeTextEl.setWidth(w);
15519 if(dlg.isVisible()){
15520 dlg.fixedcenter = false;
15522 dlg.setContentSize(w, bodyEl.getHeight());
15523 if(dlg.isVisible()){
15524 dlg.fixedcenter = true;
15530 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
15531 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
15532 * @param {Number} value Any number between 0 and 1 (e.g., .5)
15533 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
15534 * @return {Roo.MessageBox} This message box
15536 updateProgress : function(value, text){
15538 this.updateText(text);
15540 if (pp) { // weird bug on my firefox - for some reason this is not defined
15541 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
15547 * Returns true if the message box is currently displayed
15548 * @return {Boolean} True if the message box is visible, else false
15550 isVisible : function(){
15551 return dlg && dlg.isVisible();
15555 * Hides the message box if it is displayed
15558 if(this.isVisible()){
15564 * Displays a new message box, or reinitializes an existing message box, based on the config options
15565 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
15566 * The following config object properties are supported:
15568 Property Type Description
15569 ---------- --------------- ------------------------------------------------------------------------------------
15570 animEl String/Element An id or Element from which the message box should animate as it opens and
15571 closes (defaults to undefined)
15572 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
15573 cancel:'Bar'}), or false to not show any buttons (defaults to false)
15574 closable Boolean False to hide the top-right close button (defaults to true). Note that
15575 progress and wait dialogs will ignore this property and always hide the
15576 close button as they can only be closed programmatically.
15577 cls String A custom CSS class to apply to the message box element
15578 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
15579 displayed (defaults to 75)
15580 fn Function A callback function to execute after closing the dialog. The arguments to the
15581 function will be btn (the name of the button that was clicked, if applicable,
15582 e.g. "ok"), and text (the value of the active text field, if applicable).
15583 Progress and wait dialogs will ignore this option since they do not respond to
15584 user actions and can only be closed programmatically, so any required function
15585 should be called by the same code after it closes the dialog.
15586 icon String A CSS class that provides a background image to be used as an icon for
15587 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
15588 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
15589 minWidth Number The minimum width in pixels of the message box (defaults to 100)
15590 modal Boolean False to allow user interaction with the page while the message box is
15591 displayed (defaults to true)
15592 msg String A string that will replace the existing message box body text (defaults
15593 to the XHTML-compliant non-breaking space character ' ')
15594 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
15595 progress Boolean True to display a progress bar (defaults to false)
15596 progressText String The text to display inside the progress bar if progress = true (defaults to '')
15597 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
15598 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
15599 title String The title text
15600 value String The string value to set into the active textbox element if displayed
15601 wait Boolean True to display a progress bar (defaults to false)
15602 width Number The width of the dialog in pixels
15609 msg: 'Please enter your address:',
15611 buttons: Roo.MessageBox.OKCANCEL,
15614 animEl: 'addAddressBtn'
15617 * @param {Object} config Configuration options
15618 * @return {Roo.MessageBox} This message box
15620 show : function(options){
15621 if(this.isVisible()){
15624 var d = this.getDialog();
15626 d.setTitle(opt.title || " ");
15627 d.close.setDisplayed(opt.closable !== false);
15628 activeTextEl = textboxEl;
15629 opt.prompt = opt.prompt || (opt.multiline ? true : false);
15634 textareaEl.setHeight(typeof opt.multiline == "number" ?
15635 opt.multiline : this.defaultTextHeight);
15636 activeTextEl = textareaEl;
15645 progressEl.setDisplayed(opt.progress === true);
15646 this.updateProgress(0);
15647 activeTextEl.dom.value = opt.value || "";
15649 dlg.setDefaultButton(activeTextEl);
15651 var bs = opt.buttons;
15654 db = buttons["ok"];
15655 }else if(bs && bs.yes){
15656 db = buttons["yes"];
15658 dlg.setDefaultButton(db);
15660 bwidth = updateButtons(opt.buttons);
15661 this.updateText(opt.msg);
15663 d.el.addClass(opt.cls);
15665 d.proxyDrag = opt.proxyDrag === true;
15666 d.modal = opt.modal !== false;
15667 d.mask = opt.modal !== false ? mask : false;
15668 if(!d.isVisible()){
15669 // force it to the end of the z-index stack so it gets a cursor in FF
15670 document.body.appendChild(dlg.el.dom);
15671 d.animateTarget = null;
15672 d.show(options.animEl);
15678 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
15679 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
15680 * and closing the message box when the process is complete.
15681 * @param {String} title The title bar text
15682 * @param {String} msg The message box body text
15683 * @return {Roo.MessageBox} This message box
15685 progress : function(title, msg){
15692 minWidth: this.minProgressWidth,
15699 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
15700 * If a callback function is passed it will be called after the user clicks the button, and the
15701 * id of the button that was clicked will be passed as the only parameter to the callback
15702 * (could also be the top-right close button).
15703 * @param {String} title The title bar text
15704 * @param {String} msg The message box body text
15705 * @param {Function} fn (optional) The callback function invoked after the message box is closed
15706 * @param {Object} scope (optional) The scope of the callback function
15707 * @return {Roo.MessageBox} This message box
15709 alert : function(title, msg, fn, scope){
15722 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
15723 * interaction while waiting for a long-running process to complete that does not have defined intervals.
15724 * You are responsible for closing the message box when the process is complete.
15725 * @param {String} msg The message box body text
15726 * @param {String} title (optional) The title bar text
15727 * @return {Roo.MessageBox} This message box
15729 wait : function(msg, title){
15740 waitTimer = Roo.TaskMgr.start({
15742 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
15750 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
15751 * If a callback function is passed it will be called after the user clicks either button, and the id of the
15752 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
15753 * @param {String} title The title bar text
15754 * @param {String} msg The message box body text
15755 * @param {Function} fn (optional) The callback function invoked after the message box is closed
15756 * @param {Object} scope (optional) The scope of the callback function
15757 * @return {Roo.MessageBox} This message box
15759 confirm : function(title, msg, fn, scope){
15763 buttons: this.YESNO,
15772 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
15773 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
15774 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
15775 * (could also be the top-right close button) and the text that was entered will be passed as the two
15776 * parameters to the callback.
15777 * @param {String} title The title bar text
15778 * @param {String} msg The message box body text
15779 * @param {Function} fn (optional) The callback function invoked after the message box is closed
15780 * @param {Object} scope (optional) The scope of the callback function
15781 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
15782 * property, or the height in pixels to create the textbox (defaults to false / single-line)
15783 * @return {Roo.MessageBox} This message box
15785 prompt : function(title, msg, fn, scope, multiline){
15789 buttons: this.OKCANCEL,
15794 multiline: multiline,
15801 * Button config that displays a single OK button
15806 * Button config that displays Yes and No buttons
15809 YESNO : {yes:true, no:true},
15811 * Button config that displays OK and Cancel buttons
15814 OKCANCEL : {ok:true, cancel:true},
15816 * Button config that displays Yes, No and Cancel buttons
15819 YESNOCANCEL : {yes:true, no:true, cancel:true},
15822 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
15825 defaultTextHeight : 75,
15827 * The maximum width in pixels of the message box (defaults to 600)
15832 * The minimum width in pixels of the message box (defaults to 100)
15837 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
15838 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
15841 minProgressWidth : 250,
15843 * An object containing the default button text strings that can be overriden for localized language support.
15844 * Supported properties are: ok, cancel, yes and no.
15845 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
15858 * Shorthand for {@link Roo.MessageBox}
15860 Roo.Msg = Roo.MessageBox;/*
15862 * Ext JS Library 1.1.1
15863 * Copyright(c) 2006-2007, Ext JS, LLC.
15865 * Originally Released Under LGPL - original licence link has changed is not relivant.
15868 * <script type="text/javascript">
15871 * @class Roo.QuickTips
15872 * Provides attractive and customizable tooltips for any element.
15875 Roo.QuickTips = function(){
15876 var el, tipBody, tipBodyText, tipTitle, tm, cfg, close, tagEls = {}, esc, removeCls = null, bdLeft, bdRight;
15877 var ce, bd, xy, dd;
15878 var visible = false, disabled = true, inited = false;
15879 var showProc = 1, hideProc = 1, dismissProc = 1, locks = [];
15881 var onOver = function(e){
15885 var t = e.getTarget();
15886 if(!t || t.nodeType !== 1 || t == document || t == document.body){
15889 if(ce && t == ce.el){
15890 clearTimeout(hideProc);
15893 if(t && tagEls[t.id]){
15894 tagEls[t.id].el = t;
15895 showProc = show.defer(tm.showDelay, tm, [tagEls[t.id]]);
15898 var ttp, et = Roo.fly(t);
15899 var ns = cfg.namespace;
15900 if(tm.interceptTitles && t.title){
15903 t.removeAttribute("title");
15904 e.preventDefault();
15906 ttp = t.qtip || et.getAttributeNS(ns, cfg.attribute);
15909 showProc = show.defer(tm.showDelay, tm, [{
15912 width: et.getAttributeNS(ns, cfg.width),
15913 autoHide: et.getAttributeNS(ns, cfg.hide) != "user",
15914 title: et.getAttributeNS(ns, cfg.title),
15915 cls: et.getAttributeNS(ns, cfg.cls)
15920 var onOut = function(e){
15921 clearTimeout(showProc);
15922 var t = e.getTarget();
15923 if(t && ce && ce.el == t && (tm.autoHide && ce.autoHide !== false)){
15924 hideProc = setTimeout(hide, tm.hideDelay);
15928 var onMove = function(e){
15934 if(tm.trackMouse && ce){
15939 var onDown = function(e){
15940 clearTimeout(showProc);
15941 clearTimeout(hideProc);
15943 if(tm.hideOnClick){
15946 tm.enable.defer(100, tm);
15951 var getPad = function(){
15952 return 2;//bdLeft.getPadding('l')+bdRight.getPadding('r');
15955 var show = function(o){
15959 clearTimeout(dismissProc);
15961 if(removeCls){ // in case manually hidden
15962 el.removeClass(removeCls);
15966 el.addClass(ce.cls);
15967 removeCls = ce.cls;
15970 tipTitle.update(ce.title);
15973 tipTitle.update('');
15976 el.dom.style.width = tm.maxWidth+'px';
15977 //tipBody.dom.style.width = '';
15978 tipBodyText.update(o.text);
15979 var p = getPad(), w = ce.width;
15981 var td = tipBodyText.dom;
15982 var aw = Math.max(td.offsetWidth, td.clientWidth, td.scrollWidth);
15983 if(aw > tm.maxWidth){
15985 }else if(aw < tm.minWidth){
15991 //tipBody.setWidth(w);
15992 el.setWidth(parseInt(w, 10) + p);
15993 if(ce.autoHide === false){
15994 close.setDisplayed(true);
15999 close.setDisplayed(false);
16005 el.avoidY = xy[1]-18;
16010 el.setStyle("visibility", "visible");
16011 el.fadeIn({callback: afterShow});
16017 var afterShow = function(){
16021 if(tm.autoDismiss && ce.autoHide !== false){
16022 dismissProc = setTimeout(hide, tm.autoDismissDelay);
16027 var hide = function(noanim){
16028 clearTimeout(dismissProc);
16029 clearTimeout(hideProc);
16031 if(el.isVisible()){
16033 if(noanim !== true && tm.animate){
16034 el.fadeOut({callback: afterHide});
16041 var afterHide = function(){
16044 el.removeClass(removeCls);
16051 * @cfg {Number} minWidth
16052 * The minimum width of the quick tip (defaults to 40)
16056 * @cfg {Number} maxWidth
16057 * The maximum width of the quick tip (defaults to 300)
16061 * @cfg {Boolean} interceptTitles
16062 * True to automatically use the element's DOM title value if available (defaults to false)
16064 interceptTitles : false,
16066 * @cfg {Boolean} trackMouse
16067 * True to have the quick tip follow the mouse as it moves over the target element (defaults to false)
16069 trackMouse : false,
16071 * @cfg {Boolean} hideOnClick
16072 * True to hide the quick tip if the user clicks anywhere in the document (defaults to true)
16074 hideOnClick : true,
16076 * @cfg {Number} showDelay
16077 * Delay in milliseconds before the quick tip displays after the mouse enters the target element (defaults to 500)
16081 * @cfg {Number} hideDelay
16082 * Delay in milliseconds before the quick tip hides when autoHide = true (defaults to 200)
16086 * @cfg {Boolean} autoHide
16087 * True to automatically hide the quick tip after the mouse exits the target element (defaults to true).
16088 * Used in conjunction with hideDelay.
16093 * True to automatically hide the quick tip after a set period of time, regardless of the user's actions
16094 * (defaults to true). Used in conjunction with autoDismissDelay.
16096 autoDismiss : true,
16099 * Delay in milliseconds before the quick tip hides when autoDismiss = true (defaults to 5000)
16101 autoDismissDelay : 5000,
16103 * @cfg {Boolean} animate
16104 * True to turn on fade animation. Defaults to false (ClearType/scrollbar flicker issues in IE7).
16109 * @cfg {String} title
16110 * Title text to display (defaults to ''). This can be any valid HTML markup.
16114 * @cfg {String} text
16115 * Body text to display (defaults to ''). This can be any valid HTML markup.
16119 * @cfg {String} cls
16120 * A CSS class to apply to the base quick tip element (defaults to '').
16124 * @cfg {Number} width
16125 * Width in pixels of the quick tip (defaults to auto). Width will be ignored if it exceeds the bounds of
16126 * minWidth or maxWidth.
16131 * Initialize and enable QuickTips for first use. This should be called once before the first attempt to access
16132 * or display QuickTips in a page.
16135 tm = Roo.QuickTips;
16136 cfg = tm.tagConfig;
16138 if(!Roo.isReady){ // allow calling of init() before onReady
16139 Roo.onReady(Roo.QuickTips.init, Roo.QuickTips);
16142 el = new Roo.Layer({cls:"x-tip", shadow:"drop", shim: true, constrain:true, shadowOffset:4});
16143 el.fxDefaults = {stopFx: true};
16144 // maximum custom styling
16145 //el.update('<div class="x-tip-top-left"><div class="x-tip-top-right"><div class="x-tip-top"></div></div></div><div class="x-tip-bd-left"><div class="x-tip-bd-right"><div class="x-tip-bd"><div class="x-tip-close"></div><h3></h3><div class="x-tip-bd-inner"></div><div class="x-clear"></div></div></div></div><div class="x-tip-ft-left"><div class="x-tip-ft-right"><div class="x-tip-ft"></div></div></div>');
16146 el.update('<div class="x-tip-bd"><div class="x-tip-close"></div><h3></h3><div class="x-tip-bd-inner"></div><div class="x-clear"></div></div>');
16147 tipTitle = el.child('h3');
16148 tipTitle.enableDisplayMode("block");
16149 tipBody = el.child('div.x-tip-bd');
16150 tipBodyText = el.child('div.x-tip-bd-inner');
16151 //bdLeft = el.child('div.x-tip-bd-left');
16152 //bdRight = el.child('div.x-tip-bd-right');
16153 close = el.child('div.x-tip-close');
16154 close.enableDisplayMode("block");
16155 close.on("click", hide);
16156 var d = Roo.get(document);
16157 d.on("mousedown", onDown);
16158 d.on("mouseover", onOver);
16159 d.on("mouseout", onOut);
16160 d.on("mousemove", onMove);
16161 esc = d.addKeyListener(27, hide);
16164 dd = el.initDD("default", null, {
16165 onDrag : function(){
16169 dd.setHandleElId(tipTitle.id);
16178 * Configures a new quick tip instance and assigns it to a target element. The following config options
16181 Property Type Description
16182 ---------- --------------------- ------------------------------------------------------------------------
16183 target Element/String/Array An Element, id or array of ids that this quick tip should be tied to
16185 * @param {Object} config The config object
16187 register : function(config){
16188 var cs = config instanceof Array ? config : arguments;
16189 for(var i = 0, len = cs.length; i < len; i++) {
16191 var target = c.target;
16193 if(target instanceof Array){
16194 for(var j = 0, jlen = target.length; j < jlen; j++){
16195 tagEls[target[j]] = c;
16198 tagEls[typeof target == 'string' ? target : Roo.id(target)] = c;
16205 * Removes this quick tip from its element and destroys it.
16206 * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
16208 unregister : function(el){
16209 delete tagEls[Roo.id(el)];
16213 * Enable this quick tip.
16215 enable : function(){
16216 if(inited && disabled){
16218 if(locks.length < 1){
16225 * Disable this quick tip.
16227 disable : function(){
16229 clearTimeout(showProc);
16230 clearTimeout(hideProc);
16231 clearTimeout(dismissProc);
16239 * Returns true if the quick tip is enabled, else false.
16241 isEnabled : function(){
16248 attribute : "qtip",
16258 // backwards compat
16259 Roo.QuickTips.tips = Roo.QuickTips.register;/*
16261 * Ext JS Library 1.1.1
16262 * Copyright(c) 2006-2007, Ext JS, LLC.
16264 * Originally Released Under LGPL - original licence link has changed is not relivant.
16267 * <script type="text/javascript">
16272 * @class Roo.tree.TreePanel
16273 * @extends Roo.data.Tree
16275 * @cfg {Boolean} rootVisible false to hide the root node (defaults to true)
16276 * @cfg {Boolean} lines false to disable tree lines (defaults to true)
16277 * @cfg {Boolean} enableDD true to enable drag and drop
16278 * @cfg {Boolean} enableDrag true to enable just drag
16279 * @cfg {Boolean} enableDrop true to enable just drop
16280 * @cfg {Object} dragConfig Custom config to pass to the {@link Roo.tree.TreeDragZone} instance
16281 * @cfg {Object} dropConfig Custom config to pass to the {@link Roo.tree.TreeDropZone} instance
16282 * @cfg {String} ddGroup The DD group this TreePanel belongs to
16283 * @cfg {String} ddAppendOnly True if the tree should only allow append drops (use for trees which are sorted)
16284 * @cfg {Boolean} ddScroll true to enable YUI body scrolling
16285 * @cfg {Boolean} containerScroll true to register this container with ScrollManager
16286 * @cfg {Boolean} hlDrop false to disable node highlight on drop (defaults to the value of Roo.enableFx)
16287 * @cfg {String} hlColor The color of the node highlight (defaults to C3DAF9)
16288 * @cfg {Boolean} animate true to enable animated expand/collapse (defaults to the value of Roo.enableFx)
16289 * @cfg {Boolean} singleExpand true if only 1 node per branch may be expanded
16290 * @cfg {Boolean} selModel A tree selection model to use with this TreePanel (defaults to a {@link Roo.tree.DefaultSelectionModel})
16291 * @cfg {Boolean} loader A TreeLoader for use with this TreePanel
16292 * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to '/')
16293 * @cfg {Function} renderer Sets the rendering (formatting) function for the nodes. to return HTML markup for the tree view. The render function is called with the following parameters:<ul><li>The {Object} The data for the node.</li></ul>
16294 * @cfg {Function} rendererTip Sets the rendering (formatting) function for the nodes hovertip to return HTML markup for the tree view. The render function is called with the following parameters:<ul><li>The {Object} The data for the node.</li></ul>
16297 * @param {String/HTMLElement/Element} el The container element
16298 * @param {Object} config
16300 Roo.tree.TreePanel = function(el, config){
16302 var loader = false;
16304 root = config.root;
16305 delete config.root;
16307 if (config.loader) {
16308 loader = config.loader;
16309 delete config.loader;
16312 Roo.apply(this, config);
16313 Roo.tree.TreePanel.superclass.constructor.call(this);
16314 this.el = Roo.get(el);
16315 this.el.addClass('x-tree');
16316 //console.log(root);
16318 this.setRootNode( Roo.factory(root, Roo.tree));
16321 this.loader = Roo.factory(loader, Roo.tree);
16324 * Read-only. The id of the container element becomes this TreePanel's id.
16326 this.id = this.el.id;
16329 * @event beforeload
16330 * Fires before a node is loaded, return false to cancel
16331 * @param {Node} node The node being loaded
16333 "beforeload" : true,
16336 * Fires when a node is loaded
16337 * @param {Node} node The node that was loaded
16341 * @event textchange
16342 * Fires when the text for a node is changed
16343 * @param {Node} node The node
16344 * @param {String} text The new text
16345 * @param {String} oldText The old text
16347 "textchange" : true,
16349 * @event beforeexpand
16350 * Fires before a node is expanded, return false to cancel.
16351 * @param {Node} node The node
16352 * @param {Boolean} deep
16353 * @param {Boolean} anim
16355 "beforeexpand" : true,
16357 * @event beforecollapse
16358 * Fires before a node is collapsed, return false to cancel.
16359 * @param {Node} node The node
16360 * @param {Boolean} deep
16361 * @param {Boolean} anim
16363 "beforecollapse" : true,
16366 * Fires when a node is expanded
16367 * @param {Node} node The node
16371 * @event disabledchange
16372 * Fires when the disabled status of a node changes
16373 * @param {Node} node The node
16374 * @param {Boolean} disabled
16376 "disabledchange" : true,
16379 * Fires when a node is collapsed
16380 * @param {Node} node The node
16384 * @event beforeclick
16385 * Fires before click processing on a node. Return false to cancel the default action.
16386 * @param {Node} node The node
16387 * @param {Roo.EventObject} e The event object
16389 "beforeclick":true,
16391 * @event checkchange
16392 * Fires when a node with a checkbox's checked property changes
16393 * @param {Node} this This node
16394 * @param {Boolean} checked
16396 "checkchange":true,
16399 * Fires when a node is clicked
16400 * @param {Node} node The node
16401 * @param {Roo.EventObject} e The event object
16406 * Fires when a node is double clicked
16407 * @param {Node} node The node
16408 * @param {Roo.EventObject} e The event object
16412 * @event contextmenu
16413 * Fires when a node is right clicked
16414 * @param {Node} node The node
16415 * @param {Roo.EventObject} e The event object
16417 "contextmenu":true,
16419 * @event beforechildrenrendered
16420 * Fires right before the child nodes for a node are rendered
16421 * @param {Node} node The node
16423 "beforechildrenrendered":true,
16426 * Fires when a node starts being dragged
16427 * @param {Roo.tree.TreePanel} this
16428 * @param {Roo.tree.TreeNode} node
16429 * @param {event} e The raw browser event
16431 "startdrag" : true,
16434 * Fires when a drag operation is complete
16435 * @param {Roo.tree.TreePanel} this
16436 * @param {Roo.tree.TreeNode} node
16437 * @param {event} e The raw browser event
16442 * Fires when a dragged node is dropped on a valid DD target
16443 * @param {Roo.tree.TreePanel} this
16444 * @param {Roo.tree.TreeNode} node
16445 * @param {DD} dd The dd it was dropped on
16446 * @param {event} e The raw browser event
16450 * @event beforenodedrop
16451 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
16452 * passed to handlers has the following properties:<br />
16453 * <ul style="padding:5px;padding-left:16px;">
16454 * <li>tree - The TreePanel</li>
16455 * <li>target - The node being targeted for the drop</li>
16456 * <li>data - The drag data from the drag source</li>
16457 * <li>point - The point of the drop - append, above or below</li>
16458 * <li>source - The drag source</li>
16459 * <li>rawEvent - Raw mouse event</li>
16460 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
16461 * to be inserted by setting them on this object.</li>
16462 * <li>cancel - Set this to true to cancel the drop.</li>
16464 * @param {Object} dropEvent
16466 "beforenodedrop" : true,
16469 * Fires after a DD object is dropped on a node in this tree. The dropEvent
16470 * passed to handlers has the following properties:<br />
16471 * <ul style="padding:5px;padding-left:16px;">
16472 * <li>tree - The TreePanel</li>
16473 * <li>target - The node being targeted for the drop</li>
16474 * <li>data - The drag data from the drag source</li>
16475 * <li>point - The point of the drop - append, above or below</li>
16476 * <li>source - The drag source</li>
16477 * <li>rawEvent - Raw mouse event</li>
16478 * <li>dropNode - Dropped node(s).</li>
16480 * @param {Object} dropEvent
16484 * @event nodedragover
16485 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
16486 * passed to handlers has the following properties:<br />
16487 * <ul style="padding:5px;padding-left:16px;">
16488 * <li>tree - The TreePanel</li>
16489 * <li>target - The node being targeted for the drop</li>
16490 * <li>data - The drag data from the drag source</li>
16491 * <li>point - The point of the drop - append, above or below</li>
16492 * <li>source - The drag source</li>
16493 * <li>rawEvent - Raw mouse event</li>
16494 * <li>dropNode - Drop node(s) provided by the source.</li>
16495 * <li>cancel - Set this to true to signal drop not allowed.</li>
16497 * @param {Object} dragOverEvent
16499 "nodedragover" : true
16502 if(this.singleExpand){
16503 this.on("beforeexpand", this.restrictExpand, this);
16506 Roo.extend(Roo.tree.TreePanel, Roo.data.Tree, {
16507 rootVisible : true,
16508 animate: Roo.enableFx,
16511 hlDrop : Roo.enableFx,
16515 rendererTip: false,
16517 restrictExpand : function(node){
16518 var p = node.parentNode;
16520 if(p.expandedChild && p.expandedChild.parentNode == p){
16521 p.expandedChild.collapse();
16523 p.expandedChild = node;
16527 // private override
16528 setRootNode : function(node){
16529 Roo.tree.TreePanel.superclass.setRootNode.call(this, node);
16530 if(!this.rootVisible){
16531 node.ui = new Roo.tree.RootTreeNodeUI(node);
16537 * Returns the container element for this TreePanel
16539 getEl : function(){
16544 * Returns the default TreeLoader for this TreePanel
16546 getLoader : function(){
16547 return this.loader;
16553 expandAll : function(){
16554 this.root.expand(true);
16558 * Collapse all nodes
16560 collapseAll : function(){
16561 this.root.collapse(true);
16565 * Returns the selection model used by this TreePanel
16567 getSelectionModel : function(){
16568 if(!this.selModel){
16569 this.selModel = new Roo.tree.DefaultSelectionModel();
16571 return this.selModel;
16575 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
16576 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
16577 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
16580 getChecked : function(a, startNode){
16581 startNode = startNode || this.root;
16583 var f = function(){
16584 if(this.attributes.checked){
16585 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
16588 startNode.cascade(f);
16593 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
16594 * @param {String} path
16595 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
16596 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
16597 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
16599 expandPath : function(path, attr, callback){
16600 attr = attr || "id";
16601 var keys = path.split(this.pathSeparator);
16602 var curNode = this.root;
16603 if(curNode.attributes[attr] != keys[1]){ // invalid root
16605 callback(false, null);
16610 var f = function(){
16611 if(++index == keys.length){
16613 callback(true, curNode);
16617 var c = curNode.findChild(attr, keys[index]);
16620 callback(false, curNode);
16625 c.expand(false, false, f);
16627 curNode.expand(false, false, f);
16631 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
16632 * @param {String} path
16633 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
16634 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
16635 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
16637 selectPath : function(path, attr, callback){
16638 attr = attr || "id";
16639 var keys = path.split(this.pathSeparator);
16640 var v = keys.pop();
16641 if(keys.length > 0){
16642 var f = function(success, node){
16643 if(success && node){
16644 var n = node.findChild(attr, v);
16650 }else if(callback){
16651 callback(false, n);
16655 callback(false, n);
16659 this.expandPath(keys.join(this.pathSeparator), attr, f);
16661 this.root.select();
16663 callback(true, this.root);
16668 getTreeEl : function(){
16673 * Trigger rendering of this TreePanel
16675 render : function(){
16676 if (this.innerCt) {
16677 return this; // stop it rendering more than once!!
16680 this.innerCt = this.el.createChild({tag:"ul",
16681 cls:"x-tree-root-ct " +
16682 (this.lines ? "x-tree-lines" : "x-tree-no-lines")});
16684 if(this.containerScroll){
16685 Roo.dd.ScrollManager.register(this.el);
16687 if((this.enableDD || this.enableDrop) && !this.dropZone){
16689 * The dropZone used by this tree if drop is enabled
16690 * @type Roo.tree.TreeDropZone
16692 this.dropZone = new Roo.tree.TreeDropZone(this, this.dropConfig || {
16693 ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
16696 if((this.enableDD || this.enableDrag) && !this.dragZone){
16698 * The dragZone used by this tree if drag is enabled
16699 * @type Roo.tree.TreeDragZone
16701 this.dragZone = new Roo.tree.TreeDragZone(this, this.dragConfig || {
16702 ddGroup: this.ddGroup || "TreeDD",
16703 scroll: this.ddScroll
16706 this.getSelectionModel().init(this);
16708 console.log("ROOT not set in tree");
16711 this.root.render();
16712 if(!this.rootVisible){
16713 this.root.renderChildren();
16719 * Ext JS Library 1.1.1
16720 * Copyright(c) 2006-2007, Ext JS, LLC.
16722 * Originally Released Under LGPL - original licence link has changed is not relivant.
16725 * <script type="text/javascript">
16730 * @class Roo.tree.DefaultSelectionModel
16731 * @extends Roo.util.Observable
16732 * The default single selection for a TreePanel.
16734 Roo.tree.DefaultSelectionModel = function(){
16735 this.selNode = null;
16739 * @event selectionchange
16740 * Fires when the selected node changes
16741 * @param {DefaultSelectionModel} this
16742 * @param {TreeNode} node the new selection
16744 "selectionchange" : true,
16747 * @event beforeselect
16748 * Fires before the selected node changes, return false to cancel the change
16749 * @param {DefaultSelectionModel} this
16750 * @param {TreeNode} node the new selection
16751 * @param {TreeNode} node the old selection
16753 "beforeselect" : true
16757 Roo.extend(Roo.tree.DefaultSelectionModel, Roo.util.Observable, {
16758 init : function(tree){
16760 tree.getTreeEl().on("keydown", this.onKeyDown, this);
16761 tree.on("click", this.onNodeClick, this);
16764 onNodeClick : function(node, e){
16765 if (e.ctrlKey && this.selNode == node) {
16766 this.unselect(node);
16774 * @param {TreeNode} node The node to select
16775 * @return {TreeNode} The selected node
16777 select : function(node){
16778 var last = this.selNode;
16779 if(last != node && this.fireEvent('beforeselect', this, node, last) !== false){
16781 last.ui.onSelectedChange(false);
16783 this.selNode = node;
16784 node.ui.onSelectedChange(true);
16785 this.fireEvent("selectionchange", this, node, last);
16792 * @param {TreeNode} node The node to unselect
16794 unselect : function(node){
16795 if(this.selNode == node){
16796 this.clearSelections();
16801 * Clear all selections
16803 clearSelections : function(){
16804 var n = this.selNode;
16806 n.ui.onSelectedChange(false);
16807 this.selNode = null;
16808 this.fireEvent("selectionchange", this, null);
16814 * Get the selected node
16815 * @return {TreeNode} The selected node
16817 getSelectedNode : function(){
16818 return this.selNode;
16822 * Returns true if the node is selected
16823 * @param {TreeNode} node The node to check
16824 * @return {Boolean}
16826 isSelected : function(node){
16827 return this.selNode == node;
16831 * Selects the node above the selected node in the tree, intelligently walking the nodes
16832 * @return TreeNode The new selection
16834 selectPrevious : function(){
16835 var s = this.selNode || this.lastSelNode;
16839 var ps = s.previousSibling;
16841 if(!ps.isExpanded() || ps.childNodes.length < 1){
16842 return this.select(ps);
16844 var lc = ps.lastChild;
16845 while(lc && lc.isExpanded() && lc.childNodes.length > 0){
16848 return this.select(lc);
16850 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
16851 return this.select(s.parentNode);
16857 * Selects the node above the selected node in the tree, intelligently walking the nodes
16858 * @return TreeNode The new selection
16860 selectNext : function(){
16861 var s = this.selNode || this.lastSelNode;
16865 if(s.firstChild && s.isExpanded()){
16866 return this.select(s.firstChild);
16867 }else if(s.nextSibling){
16868 return this.select(s.nextSibling);
16869 }else if(s.parentNode){
16871 s.parentNode.bubble(function(){
16872 if(this.nextSibling){
16873 newS = this.getOwnerTree().selModel.select(this.nextSibling);
16882 onKeyDown : function(e){
16883 var s = this.selNode || this.lastSelNode;
16884 // undesirable, but required
16889 var k = e.getKey();
16897 this.selectPrevious();
16900 e.preventDefault();
16901 if(s.hasChildNodes()){
16902 if(!s.isExpanded()){
16904 }else if(s.firstChild){
16905 this.select(s.firstChild, e);
16910 e.preventDefault();
16911 if(s.hasChildNodes() && s.isExpanded()){
16913 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
16914 this.select(s.parentNode, e);
16922 * @class Roo.tree.MultiSelectionModel
16923 * @extends Roo.util.Observable
16924 * Multi selection for a TreePanel.
16926 Roo.tree.MultiSelectionModel = function(){
16927 this.selNodes = [];
16931 * @event selectionchange
16932 * Fires when the selected nodes change
16933 * @param {MultiSelectionModel} this
16934 * @param {Array} nodes Array of the selected nodes
16936 "selectionchange" : true
16940 Roo.extend(Roo.tree.MultiSelectionModel, Roo.util.Observable, {
16941 init : function(tree){
16943 tree.getTreeEl().on("keydown", this.onKeyDown, this);
16944 tree.on("click", this.onNodeClick, this);
16947 onNodeClick : function(node, e){
16948 this.select(node, e, e.ctrlKey);
16953 * @param {TreeNode} node The node to select
16954 * @param {EventObject} e (optional) An event associated with the selection
16955 * @param {Boolean} keepExisting True to retain existing selections
16956 * @return {TreeNode} The selected node
16958 select : function(node, e, keepExisting){
16959 if(keepExisting !== true){
16960 this.clearSelections(true);
16962 if(this.isSelected(node)){
16963 this.lastSelNode = node;
16966 this.selNodes.push(node);
16967 this.selMap[node.id] = node;
16968 this.lastSelNode = node;
16969 node.ui.onSelectedChange(true);
16970 this.fireEvent("selectionchange", this, this.selNodes);
16976 * @param {TreeNode} node The node to unselect
16978 unselect : function(node){
16979 if(this.selMap[node.id]){
16980 node.ui.onSelectedChange(false);
16981 var sn = this.selNodes;
16984 index = sn.indexOf(node);
16986 for(var i = 0, len = sn.length; i < len; i++){
16994 this.selNodes.splice(index, 1);
16996 delete this.selMap[node.id];
16997 this.fireEvent("selectionchange", this, this.selNodes);
17002 * Clear all selections
17004 clearSelections : function(suppressEvent){
17005 var sn = this.selNodes;
17007 for(var i = 0, len = sn.length; i < len; i++){
17008 sn[i].ui.onSelectedChange(false);
17010 this.selNodes = [];
17012 if(suppressEvent !== true){
17013 this.fireEvent("selectionchange", this, this.selNodes);
17019 * Returns true if the node is selected
17020 * @param {TreeNode} node The node to check
17021 * @return {Boolean}
17023 isSelected : function(node){
17024 return this.selMap[node.id] ? true : false;
17028 * Returns an array of the selected nodes
17031 getSelectedNodes : function(){
17032 return this.selNodes;
17035 onKeyDown : Roo.tree.DefaultSelectionModel.prototype.onKeyDown,
17037 selectNext : Roo.tree.DefaultSelectionModel.prototype.selectNext,
17039 selectPrevious : Roo.tree.DefaultSelectionModel.prototype.selectPrevious
17042 * Ext JS Library 1.1.1
17043 * Copyright(c) 2006-2007, Ext JS, LLC.
17045 * Originally Released Under LGPL - original licence link has changed is not relivant.
17048 * <script type="text/javascript">
17052 * @class Roo.tree.TreeNode
17053 * @extends Roo.data.Node
17054 * @cfg {String} text The text for this node
17055 * @cfg {Boolean} expanded true to start the node expanded
17056 * @cfg {Boolean} allowDrag false to make this node undraggable if DD is on (defaults to true)
17057 * @cfg {Boolean} allowDrop false if this node cannot be drop on
17058 * @cfg {Boolean} disabled true to start the node disabled
17059 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
17060 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
17061 * @cfg {String} cls A css class to be added to the node
17062 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
17063 * @cfg {String} href URL of the link used for the node (defaults to #)
17064 * @cfg {String} hrefTarget target frame for the link
17065 * @cfg {String} qtip An Ext QuickTip for the node
17066 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
17067 * @cfg {Boolean} singleClickExpand True for single click expand on this node
17068 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Roo.tree.TreeNodeUI)
17069 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
17070 * (defaults to undefined with no checkbox rendered)
17072 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
17074 Roo.tree.TreeNode = function(attributes){
17075 attributes = attributes || {};
17076 if(typeof attributes == "string"){
17077 attributes = {text: attributes};
17079 this.childrenRendered = false;
17080 this.rendered = false;
17081 Roo.tree.TreeNode.superclass.constructor.call(this, attributes);
17082 this.expanded = attributes.expanded === true;
17083 this.isTarget = attributes.isTarget !== false;
17084 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
17085 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
17088 * Read-only. The text for this node. To change it use setText().
17091 this.text = attributes.text;
17093 * True if this node is disabled.
17096 this.disabled = attributes.disabled === true;
17100 * @event textchange
17101 * Fires when the text for this node is changed
17102 * @param {Node} this This node
17103 * @param {String} text The new text
17104 * @param {String} oldText The old text
17106 "textchange" : true,
17108 * @event beforeexpand
17109 * Fires before this node is expanded, return false to cancel.
17110 * @param {Node} this This node
17111 * @param {Boolean} deep
17112 * @param {Boolean} anim
17114 "beforeexpand" : true,
17116 * @event beforecollapse
17117 * Fires before this node is collapsed, return false to cancel.
17118 * @param {Node} this This node
17119 * @param {Boolean} deep
17120 * @param {Boolean} anim
17122 "beforecollapse" : true,
17125 * Fires when this node is expanded
17126 * @param {Node} this This node
17130 * @event disabledchange
17131 * Fires when the disabled status of this node changes
17132 * @param {Node} this This node
17133 * @param {Boolean} disabled
17135 "disabledchange" : true,
17138 * Fires when this node is collapsed
17139 * @param {Node} this This node
17143 * @event beforeclick
17144 * Fires before click processing. Return false to cancel the default action.
17145 * @param {Node} this This node
17146 * @param {Roo.EventObject} e The event object
17148 "beforeclick":true,
17150 * @event checkchange
17151 * Fires when a node with a checkbox's checked property changes
17152 * @param {Node} this This node
17153 * @param {Boolean} checked
17155 "checkchange":true,
17158 * Fires when this node is clicked
17159 * @param {Node} this This node
17160 * @param {Roo.EventObject} e The event object
17165 * Fires when this node is double clicked
17166 * @param {Node} this This node
17167 * @param {Roo.EventObject} e The event object
17171 * @event contextmenu
17172 * Fires when this node is right clicked
17173 * @param {Node} this This node
17174 * @param {Roo.EventObject} e The event object
17176 "contextmenu":true,
17178 * @event beforechildrenrendered
17179 * Fires right before the child nodes for this node are rendered
17180 * @param {Node} this This node
17182 "beforechildrenrendered":true
17185 var uiClass = this.attributes.uiProvider || Roo.tree.TreeNodeUI;
17188 * Read-only. The UI for this node
17191 this.ui = new uiClass(this);
17193 Roo.extend(Roo.tree.TreeNode, Roo.data.Node, {
17194 preventHScroll: true,
17196 * Returns true if this node is expanded
17197 * @return {Boolean}
17199 isExpanded : function(){
17200 return this.expanded;
17204 * Returns the UI object for this node
17205 * @return {TreeNodeUI}
17207 getUI : function(){
17211 // private override
17212 setFirstChild : function(node){
17213 var of = this.firstChild;
17214 Roo.tree.TreeNode.superclass.setFirstChild.call(this, node);
17215 if(this.childrenRendered && of && node != of){
17216 of.renderIndent(true, true);
17219 this.renderIndent(true, true);
17223 // private override
17224 setLastChild : function(node){
17225 var ol = this.lastChild;
17226 Roo.tree.TreeNode.superclass.setLastChild.call(this, node);
17227 if(this.childrenRendered && ol && node != ol){
17228 ol.renderIndent(true, true);
17231 this.renderIndent(true, true);
17235 // these methods are overridden to provide lazy rendering support
17236 // private override
17237 appendChild : function(){
17238 var node = Roo.tree.TreeNode.superclass.appendChild.apply(this, arguments);
17239 if(node && this.childrenRendered){
17242 this.ui.updateExpandIcon();
17246 // private override
17247 removeChild : function(node){
17248 this.ownerTree.getSelectionModel().unselect(node);
17249 Roo.tree.TreeNode.superclass.removeChild.apply(this, arguments);
17250 // if it's been rendered remove dom node
17251 if(this.childrenRendered){
17254 if(this.childNodes.length < 1){
17255 this.collapse(false, false);
17257 this.ui.updateExpandIcon();
17259 if(!this.firstChild) {
17260 this.childrenRendered = false;
17265 // private override
17266 insertBefore : function(node, refNode){
17267 var newNode = Roo.tree.TreeNode.superclass.insertBefore.apply(this, arguments);
17268 if(newNode && refNode && this.childrenRendered){
17271 this.ui.updateExpandIcon();
17276 * Sets the text for this node
17277 * @param {String} text
17279 setText : function(text){
17280 var oldText = this.text;
17282 this.attributes.text = text;
17283 if(this.rendered){ // event without subscribing
17284 this.ui.onTextChange(this, text, oldText);
17286 this.fireEvent("textchange", this, text, oldText);
17290 * Triggers selection of this node
17292 select : function(){
17293 this.getOwnerTree().getSelectionModel().select(this);
17297 * Triggers deselection of this node
17299 unselect : function(){
17300 this.getOwnerTree().getSelectionModel().unselect(this);
17304 * Returns true if this node is selected
17305 * @return {Boolean}
17307 isSelected : function(){
17308 return this.getOwnerTree().getSelectionModel().isSelected(this);
17312 * Expand this node.
17313 * @param {Boolean} deep (optional) True to expand all children as well
17314 * @param {Boolean} anim (optional) false to cancel the default animation
17315 * @param {Function} callback (optional) A callback to be called when
17316 * expanding this node completes (does not wait for deep expand to complete).
17317 * Called with 1 parameter, this node.
17319 expand : function(deep, anim, callback){
17320 if(!this.expanded){
17321 if(this.fireEvent("beforeexpand", this, deep, anim) === false){
17324 if(!this.childrenRendered){
17325 this.renderChildren();
17327 this.expanded = true;
17328 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
17329 this.ui.animExpand(function(){
17330 this.fireEvent("expand", this);
17331 if(typeof callback == "function"){
17335 this.expandChildNodes(true);
17337 }.createDelegate(this));
17341 this.fireEvent("expand", this);
17342 if(typeof callback == "function"){
17347 if(typeof callback == "function"){
17352 this.expandChildNodes(true);
17356 isHiddenRoot : function(){
17357 return this.isRoot && !this.getOwnerTree().rootVisible;
17361 * Collapse this node.
17362 * @param {Boolean} deep (optional) True to collapse all children as well
17363 * @param {Boolean} anim (optional) false to cancel the default animation
17365 collapse : function(deep, anim){
17366 if(this.expanded && !this.isHiddenRoot()){
17367 if(this.fireEvent("beforecollapse", this, deep, anim) === false){
17370 this.expanded = false;
17371 if((this.getOwnerTree().animate && anim !== false) || anim){
17372 this.ui.animCollapse(function(){
17373 this.fireEvent("collapse", this);
17375 this.collapseChildNodes(true);
17377 }.createDelegate(this));
17380 this.ui.collapse();
17381 this.fireEvent("collapse", this);
17385 var cs = this.childNodes;
17386 for(var i = 0, len = cs.length; i < len; i++) {
17387 cs[i].collapse(true, false);
17393 delayedExpand : function(delay){
17394 if(!this.expandProcId){
17395 this.expandProcId = this.expand.defer(delay, this);
17400 cancelExpand : function(){
17401 if(this.expandProcId){
17402 clearTimeout(this.expandProcId);
17404 this.expandProcId = false;
17408 * Toggles expanded/collapsed state of the node
17410 toggle : function(){
17419 * Ensures all parent nodes are expanded
17421 ensureVisible : function(callback){
17422 var tree = this.getOwnerTree();
17423 tree.expandPath(this.parentNode.getPath(), false, function(){
17424 tree.getTreeEl().scrollChildIntoView(this.ui.anchor);
17425 Roo.callback(callback);
17426 }.createDelegate(this));
17430 * Expand all child nodes
17431 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
17433 expandChildNodes : function(deep){
17434 var cs = this.childNodes;
17435 for(var i = 0, len = cs.length; i < len; i++) {
17436 cs[i].expand(deep);
17441 * Collapse all child nodes
17442 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
17444 collapseChildNodes : function(deep){
17445 var cs = this.childNodes;
17446 for(var i = 0, len = cs.length; i < len; i++) {
17447 cs[i].collapse(deep);
17452 * Disables this node
17454 disable : function(){
17455 this.disabled = true;
17457 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
17458 this.ui.onDisableChange(this, true);
17460 this.fireEvent("disabledchange", this, true);
17464 * Enables this node
17466 enable : function(){
17467 this.disabled = false;
17468 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
17469 this.ui.onDisableChange(this, false);
17471 this.fireEvent("disabledchange", this, false);
17475 renderChildren : function(suppressEvent){
17476 if(suppressEvent !== false){
17477 this.fireEvent("beforechildrenrendered", this);
17479 var cs = this.childNodes;
17480 for(var i = 0, len = cs.length; i < len; i++){
17481 cs[i].render(true);
17483 this.childrenRendered = true;
17487 sort : function(fn, scope){
17488 Roo.tree.TreeNode.superclass.sort.apply(this, arguments);
17489 if(this.childrenRendered){
17490 var cs = this.childNodes;
17491 for(var i = 0, len = cs.length; i < len; i++){
17492 cs[i].render(true);
17498 render : function(bulkRender){
17499 this.ui.render(bulkRender);
17500 if(!this.rendered){
17501 this.rendered = true;
17503 this.expanded = false;
17504 this.expand(false, false);
17510 renderIndent : function(deep, refresh){
17512 this.ui.childIndent = null;
17514 this.ui.renderIndent();
17515 if(deep === true && this.childrenRendered){
17516 var cs = this.childNodes;
17517 for(var i = 0, len = cs.length; i < len; i++){
17518 cs[i].renderIndent(true, refresh);
17524 * Ext JS Library 1.1.1
17525 * Copyright(c) 2006-2007, Ext JS, LLC.
17527 * Originally Released Under LGPL - original licence link has changed is not relivant.
17530 * <script type="text/javascript">
17534 * @class Roo.tree.AsyncTreeNode
17535 * @extends Roo.tree.TreeNode
17536 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
17538 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
17540 Roo.tree.AsyncTreeNode = function(config){
17541 this.loaded = false;
17542 this.loading = false;
17543 Roo.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
17545 * @event beforeload
17546 * Fires before this node is loaded, return false to cancel
17547 * @param {Node} this This node
17549 this.addEvents({'beforeload':true, 'load': true});
17552 * Fires when this node is loaded
17553 * @param {Node} this This node
17556 * The loader used by this node (defaults to using the tree's defined loader)
17561 Roo.extend(Roo.tree.AsyncTreeNode, Roo.tree.TreeNode, {
17562 expand : function(deep, anim, callback){
17563 if(this.loading){ // if an async load is already running, waiting til it's done
17565 var f = function(){
17566 if(!this.loading){ // done loading
17567 clearInterval(timer);
17568 this.expand(deep, anim, callback);
17570 }.createDelegate(this);
17571 timer = setInterval(f, 200);
17575 if(this.fireEvent("beforeload", this) === false){
17578 this.loading = true;
17579 this.ui.beforeLoad(this);
17580 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
17582 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback]));
17586 Roo.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback);
17590 * Returns true if this node is currently loading
17591 * @return {Boolean}
17593 isLoading : function(){
17594 return this.loading;
17597 loadComplete : function(deep, anim, callback){
17598 this.loading = false;
17599 this.loaded = true;
17600 this.ui.afterLoad(this);
17601 this.fireEvent("load", this);
17602 this.expand(deep, anim, callback);
17606 * Returns true if this node has been loaded
17607 * @return {Boolean}
17609 isLoaded : function(){
17610 return this.loaded;
17613 hasChildNodes : function(){
17614 if(!this.isLeaf() && !this.loaded){
17617 return Roo.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
17622 * Trigger a reload for this node
17623 * @param {Function} callback
17625 reload : function(callback){
17626 this.collapse(false, false);
17627 while(this.firstChild){
17628 this.removeChild(this.firstChild);
17630 this.childrenRendered = false;
17631 this.loaded = false;
17632 if(this.isHiddenRoot()){
17633 this.expanded = false;
17635 this.expand(false, false, callback);
17639 * Ext JS Library 1.1.1
17640 * Copyright(c) 2006-2007, Ext JS, LLC.
17642 * Originally Released Under LGPL - original licence link has changed is not relivant.
17645 * <script type="text/javascript">
17649 * @class Roo.tree.TreeNodeUI
17651 * @param {Object} node The node to render
17652 * The TreeNode UI implementation is separate from the
17653 * tree implementation. Unless you are customizing the tree UI,
17654 * you should never have to use this directly.
17656 Roo.tree.TreeNodeUI = function(node){
17658 this.rendered = false;
17659 this.animating = false;
17660 this.emptyIcon = Roo.BLANK_IMAGE_URL;
17663 Roo.tree.TreeNodeUI.prototype = {
17664 removeChild : function(node){
17666 this.ctNode.removeChild(node.ui.getEl());
17670 beforeLoad : function(){
17671 this.addClass("x-tree-node-loading");
17674 afterLoad : function(){
17675 this.removeClass("x-tree-node-loading");
17678 onTextChange : function(node, text, oldText){
17680 this.textNode.innerHTML = text;
17684 onDisableChange : function(node, state){
17685 this.disabled = state;
17687 this.addClass("x-tree-node-disabled");
17689 this.removeClass("x-tree-node-disabled");
17693 onSelectedChange : function(state){
17696 this.addClass("x-tree-selected");
17699 this.removeClass("x-tree-selected");
17703 onMove : function(tree, node, oldParent, newParent, index, refNode){
17704 this.childIndent = null;
17706 var targetNode = newParent.ui.getContainer();
17707 if(!targetNode){//target not rendered
17708 this.holder = document.createElement("div");
17709 this.holder.appendChild(this.wrap);
17712 var insertBefore = refNode ? refNode.ui.getEl() : null;
17714 targetNode.insertBefore(this.wrap, insertBefore);
17716 targetNode.appendChild(this.wrap);
17718 this.node.renderIndent(true);
17722 addClass : function(cls){
17724 Roo.fly(this.elNode).addClass(cls);
17728 removeClass : function(cls){
17730 Roo.fly(this.elNode).removeClass(cls);
17734 remove : function(){
17736 this.holder = document.createElement("div");
17737 this.holder.appendChild(this.wrap);
17741 fireEvent : function(){
17742 return this.node.fireEvent.apply(this.node, arguments);
17745 initEvents : function(){
17746 this.node.on("move", this.onMove, this);
17747 var E = Roo.EventManager;
17748 var a = this.anchor;
17750 var el = Roo.fly(a, '_treeui');
17752 if(Roo.isOpera){ // opera render bug ignores the CSS
17753 el.setStyle("text-decoration", "none");
17756 el.on("click", this.onClick, this);
17757 el.on("dblclick", this.onDblClick, this);
17760 Roo.EventManager.on(this.checkbox,
17761 Roo.isIE ? 'click' : 'change', this.onCheckChange, this);
17764 el.on("contextmenu", this.onContextMenu, this);
17766 var icon = Roo.fly(this.iconNode);
17767 icon.on("click", this.onClick, this);
17768 icon.on("dblclick", this.onDblClick, this);
17769 icon.on("contextmenu", this.onContextMenu, this);
17770 E.on(this.ecNode, "click", this.ecClick, this, true);
17772 if(this.node.disabled){
17773 this.addClass("x-tree-node-disabled");
17775 if(this.node.hidden){
17776 this.addClass("x-tree-node-disabled");
17778 var ot = this.node.getOwnerTree();
17779 var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
17780 if(dd && (!this.node.isRoot || ot.rootVisible)){
17781 Roo.dd.Registry.register(this.elNode, {
17783 handles: this.getDDHandles(),
17789 getDDHandles : function(){
17790 return [this.iconNode, this.textNode];
17795 this.wrap.style.display = "none";
17801 this.wrap.style.display = "";
17805 onContextMenu : function(e){
17806 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
17807 e.preventDefault();
17809 this.fireEvent("contextmenu", this.node, e);
17813 onClick : function(e){
17818 if(this.fireEvent("beforeclick", this.node, e) !== false){
17819 if(!this.disabled && this.node.attributes.href){
17820 this.fireEvent("click", this.node, e);
17823 e.preventDefault();
17828 if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){
17829 this.node.toggle();
17832 this.fireEvent("click", this.node, e);
17838 onDblClick : function(e){
17839 e.preventDefault();
17844 this.toggleCheck();
17846 if(!this.animating && this.node.hasChildNodes()){
17847 this.node.toggle();
17849 this.fireEvent("dblclick", this.node, e);
17852 onCheckChange : function(){
17853 var checked = this.checkbox.checked;
17854 this.node.attributes.checked = checked;
17855 this.fireEvent('checkchange', this.node, checked);
17858 ecClick : function(e){
17859 if(!this.animating && this.node.hasChildNodes()){
17860 this.node.toggle();
17864 startDrop : function(){
17865 this.dropping = true;
17868 // delayed drop so the click event doesn't get fired on a drop
17869 endDrop : function(){
17870 setTimeout(function(){
17871 this.dropping = false;
17872 }.createDelegate(this), 50);
17875 expand : function(){
17876 this.updateExpandIcon();
17877 this.ctNode.style.display = "";
17880 focus : function(){
17881 if(!this.node.preventHScroll){
17882 try{this.anchor.focus();
17884 }else if(!Roo.isIE){
17886 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
17887 var l = noscroll.scrollLeft;
17888 this.anchor.focus();
17889 noscroll.scrollLeft = l;
17894 toggleCheck : function(value){
17895 var cb = this.checkbox;
17897 cb.checked = (value === undefined ? !cb.checked : value);
17903 this.anchor.blur();
17907 animExpand : function(callback){
17908 var ct = Roo.get(this.ctNode);
17910 if(!this.node.hasChildNodes()){
17911 this.updateExpandIcon();
17912 this.ctNode.style.display = "";
17913 Roo.callback(callback);
17916 this.animating = true;
17917 this.updateExpandIcon();
17920 callback : function(){
17921 this.animating = false;
17922 Roo.callback(callback);
17925 duration: this.node.ownerTree.duration || .25
17929 highlight : function(){
17930 var tree = this.node.getOwnerTree();
17931 Roo.fly(this.wrap).highlight(
17932 tree.hlColor || "C3DAF9",
17933 {endColor: tree.hlBaseColor}
17937 collapse : function(){
17938 this.updateExpandIcon();
17939 this.ctNode.style.display = "none";
17942 animCollapse : function(callback){
17943 var ct = Roo.get(this.ctNode);
17944 ct.enableDisplayMode('block');
17947 this.animating = true;
17948 this.updateExpandIcon();
17951 callback : function(){
17952 this.animating = false;
17953 Roo.callback(callback);
17956 duration: this.node.ownerTree.duration || .25
17960 getContainer : function(){
17961 return this.ctNode;
17964 getEl : function(){
17968 appendDDGhost : function(ghostNode){
17969 ghostNode.appendChild(this.elNode.cloneNode(true));
17972 getDDRepairXY : function(){
17973 return Roo.lib.Dom.getXY(this.iconNode);
17976 onRender : function(){
17980 render : function(bulkRender){
17981 var n = this.node, a = n.attributes;
17982 var targetNode = n.parentNode ?
17983 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
17985 if(!this.rendered){
17986 this.rendered = true;
17988 this.renderElements(n, a, targetNode, bulkRender);
17991 if(this.textNode.setAttributeNS){
17992 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
17994 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
17997 this.textNode.setAttribute("ext:qtip", a.qtip);
17999 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
18002 }else if(a.qtipCfg){
18003 a.qtipCfg.target = Roo.id(this.textNode);
18004 Roo.QuickTips.register(a.qtipCfg);
18007 if(!this.node.expanded){
18008 this.updateExpandIcon();
18011 if(bulkRender === true) {
18012 targetNode.appendChild(this.wrap);
18017 renderElements : function(n, a, targetNode, bulkRender){
18018 // add some indent caching, this helps performance when rendering a large tree
18019 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
18020 var t = n.getOwnerTree();
18021 var txt = t.renderer ? t.renderer(n.attributes) : Roo.util.Format.htmlEncode(n.text);
18022 var tip = t.rendererTip ? t.rendererTip(n.attributes) : txt;
18023 var cb = typeof a.checked == 'boolean';
18024 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
18025 var buf = ['<li class="x-tree-node"><div class="x-tree-node-el ', a.cls,'">',
18026 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
18027 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon" />',
18028 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
18029 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : ' />')) : '',
18030 '<a hidefocus="on" href="',href,'" tabIndex="1" ',
18031 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "",
18032 '><span unselectable="on" qtip="' , tip ,'">',txt,"</span></a></div>",
18033 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
18036 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
18037 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
18038 n.nextSibling.ui.getEl(), buf.join(""));
18040 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
18043 this.elNode = this.wrap.childNodes[0];
18044 this.ctNode = this.wrap.childNodes[1];
18045 var cs = this.elNode.childNodes;
18046 this.indentNode = cs[0];
18047 this.ecNode = cs[1];
18048 this.iconNode = cs[2];
18051 this.checkbox = cs[3];
18054 this.anchor = cs[index];
18055 this.textNode = cs[index].firstChild;
18058 getAnchor : function(){
18059 return this.anchor;
18062 getTextEl : function(){
18063 return this.textNode;
18066 getIconEl : function(){
18067 return this.iconNode;
18070 isChecked : function(){
18071 return this.checkbox ? this.checkbox.checked : false;
18074 updateExpandIcon : function(){
18076 var n = this.node, c1, c2;
18077 var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
18078 var hasChild = n.hasChildNodes();
18082 c1 = "x-tree-node-collapsed";
18083 c2 = "x-tree-node-expanded";
18086 c1 = "x-tree-node-expanded";
18087 c2 = "x-tree-node-collapsed";
18090 this.removeClass("x-tree-node-leaf");
18091 this.wasLeaf = false;
18093 if(this.c1 != c1 || this.c2 != c2){
18094 Roo.fly(this.elNode).replaceClass(c1, c2);
18095 this.c1 = c1; this.c2 = c2;
18099 Roo.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
18102 this.wasLeaf = true;
18105 var ecc = "x-tree-ec-icon "+cls;
18106 if(this.ecc != ecc){
18107 this.ecNode.className = ecc;
18113 getChildIndent : function(){
18114 if(!this.childIndent){
18118 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
18120 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
18122 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
18127 this.childIndent = buf.join("");
18129 return this.childIndent;
18132 renderIndent : function(){
18135 var p = this.node.parentNode;
18137 indent = p.ui.getChildIndent();
18139 if(this.indentMarkup != indent){ // don't rerender if not required
18140 this.indentNode.innerHTML = indent;
18141 this.indentMarkup = indent;
18143 this.updateExpandIcon();
18148 Roo.tree.RootTreeNodeUI = function(){
18149 Roo.tree.RootTreeNodeUI.superclass.constructor.apply(this, arguments);
18151 Roo.extend(Roo.tree.RootTreeNodeUI, Roo.tree.TreeNodeUI, {
18152 render : function(){
18153 if(!this.rendered){
18154 var targetNode = this.node.ownerTree.innerCt.dom;
18155 this.node.expanded = true;
18156 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
18157 this.wrap = this.ctNode = targetNode.firstChild;
18160 collapse : function(){
18162 expand : function(){
18166 * Ext JS Library 1.1.1
18167 * Copyright(c) 2006-2007, Ext JS, LLC.
18169 * Originally Released Under LGPL - original licence link has changed is not relivant.
18172 * <script type="text/javascript">
18175 * @class Roo.tree.TreeLoader
18176 * @extends Roo.util.Observable
18177 * A TreeLoader provides for lazy loading of an {@link Roo.tree.TreeNode}'s child
18178 * nodes from a specified URL. The response must be a javascript Array definition
18179 * who's elements are node definition objects. eg:
18181 [{ 'id': 1, 'text': 'A folder Node', 'leaf': false },
18182 { 'id': 2, 'text': 'A leaf Node', 'leaf': true }]
18185 * A server request is sent, and child nodes are loaded only when a node is expanded.
18186 * The loading node's id is passed to the server under the parameter name "node" to
18187 * enable the server to produce the correct child nodes.
18189 * To pass extra parameters, an event handler may be attached to the "beforeload"
18190 * event, and the parameters specified in the TreeLoader's baseParams property:
18192 myTreeLoader.on("beforeload", function(treeLoader, node) {
18193 this.baseParams.category = node.attributes.category;
18196 * This would pass an HTTP parameter called "category" to the server containing
18197 * the value of the Node's "category" attribute.
18199 * Creates a new Treeloader.
18200 * @param {Object} config A config object containing config properties.
18202 Roo.tree.TreeLoader = function(config){
18203 this.baseParams = {};
18204 this.requestMethod = "POST";
18205 Roo.apply(this, config);
18210 * @event beforeload
18211 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
18212 * @param {Object} This TreeLoader object.
18213 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18214 * @param {Object} callback The callback function specified in the {@link #load} call.
18219 * Fires when the node has been successfuly loaded.
18220 * @param {Object} This TreeLoader object.
18221 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18222 * @param {Object} response The response object containing the data from the server.
18226 * @event loadexception
18227 * Fires if the network request failed.
18228 * @param {Object} This TreeLoader object.
18229 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18230 * @param {Object} response The response object containing the data from the server.
18232 loadexception : true,
18235 * Fires before a node is created, enabling you to return custom Node types
18236 * @param {Object} This TreeLoader object.
18237 * @param {Object} attr - the data returned from the AJAX call (modify it to suit)
18242 Roo.tree.TreeLoader.superclass.constructor.call(this);
18245 Roo.extend(Roo.tree.TreeLoader, Roo.util.Observable, {
18247 * @cfg {String} dataUrl The URL from which to request a Json string which
18248 * specifies an array of node definition object representing the child nodes
18252 * @cfg {Object} baseParams (optional) An object containing properties which
18253 * specify HTTP parameters to be passed to each request for child nodes.
18256 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
18257 * created by this loader. If the attributes sent by the server have an attribute in this object,
18258 * they take priority.
18261 * @cfg {Object} uiProviders (optional) An object containing properties which
18263 * DEPRECIATED - use 'create' event handler to modify attributes - which affect creation.
18264 * specify custom {@link Roo.tree.TreeNodeUI} implementations. If the optional
18265 * <i>uiProvider</i> attribute of a returned child node is a string rather
18266 * than a reference to a TreeNodeUI implementation, this that string value
18267 * is used as a property name in the uiProviders object. You can define the provider named
18268 * 'default' , and this will be used for all nodes (if no uiProvider is delivered by the node data)
18273 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
18274 * child nodes before loading.
18276 clearOnLoad : true,
18279 * @cfg {String} root (optional) Default to false. Use this to read data from an object
18280 * property on loading, rather than expecting an array. (eg. more compatible to a standard
18281 * Grid query { data : [ .....] }
18286 * @cfg {String} queryParam (optional)
18287 * Name of the query as it will be passed on the querystring (defaults to 'node')
18288 * eg. the request will be ?node=[id]
18295 * Load an {@link Roo.tree.TreeNode} from the URL specified in the constructor.
18296 * This is called automatically when a node is expanded, but may be used to reload
18297 * a node (or append new children if the {@link #clearOnLoad} option is false.)
18298 * @param {Roo.tree.TreeNode} node
18299 * @param {Function} callback
18301 load : function(node, callback){
18302 if(this.clearOnLoad){
18303 while(node.firstChild){
18304 node.removeChild(node.firstChild);
18307 if(node.attributes.children){ // preloaded json children
18308 var cs = node.attributes.children;
18309 for(var i = 0, len = cs.length; i < len; i++){
18310 node.appendChild(this.createNode(cs[i]));
18312 if(typeof callback == "function"){
18315 }else if(this.dataUrl){
18316 this.requestData(node, callback);
18320 getParams: function(node){
18321 var buf = [], bp = this.baseParams;
18322 for(var key in bp){
18323 if(typeof bp[key] != "function"){
18324 buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
18327 var n = this.queryParam === false ? 'node' : this.queryParam;
18328 buf.push(n + "=", encodeURIComponent(node.id));
18329 return buf.join("");
18332 requestData : function(node, callback){
18333 if(this.fireEvent("beforeload", this, node, callback) !== false){
18334 this.transId = Roo.Ajax.request({
18335 method:this.requestMethod,
18336 url: this.dataUrl||this.url,
18337 success: this.handleResponse,
18338 failure: this.handleFailure,
18340 argument: {callback: callback, node: node},
18341 params: this.getParams(node)
18344 // if the load is cancelled, make sure we notify
18345 // the node that we are done
18346 if(typeof callback == "function"){
18352 isLoading : function(){
18353 return this.transId ? true : false;
18356 abort : function(){
18357 if(this.isLoading()){
18358 Roo.Ajax.abort(this.transId);
18363 createNode : function(attr){
18364 // apply baseAttrs, nice idea Corey!
18365 if(this.baseAttrs){
18366 Roo.applyIf(attr, this.baseAttrs);
18368 if(this.applyLoader !== false){
18369 attr.loader = this;
18371 // uiProvider = depreciated..
18373 if(typeof(attr.uiProvider) == 'string'){
18374 attr.uiProvider = this.uiProviders[attr.uiProvider] ||
18375 /** eval:var:attr */ eval(attr.uiProvider);
18377 if(typeof(this.uiProviders['default']) != 'undefined') {
18378 attr.uiProvider = this.uiProviders['default'];
18381 this.fireEvent('create', this, attr);
18383 attr.leaf = typeof(attr.leaf) == 'string' ? attr.leaf * 1 : attr.leaf;
18385 new Roo.tree.TreeNode(attr) :
18386 new Roo.tree.AsyncTreeNode(attr));
18389 processResponse : function(response, node, callback){
18390 var json = response.responseText;
18393 var o = /** eval:var:zzzzzzzzzz */ eval("("+json+")");
18394 if (this.root !== false) {
18398 for(var i = 0, len = o.length; i < len; i++){
18399 var n = this.createNode(o[i]);
18401 node.appendChild(n);
18404 if(typeof callback == "function"){
18405 callback(this, node);
18408 this.handleFailure(response);
18412 handleResponse : function(response){
18413 this.transId = false;
18414 var a = response.argument;
18415 this.processResponse(response, a.node, a.callback);
18416 this.fireEvent("load", this, a.node, response);
18419 handleFailure : function(response){
18420 this.transId = false;
18421 var a = response.argument;
18422 this.fireEvent("loadexception", this, a.node, response);
18423 if(typeof a.callback == "function"){
18424 a.callback(this, a.node);
18429 * Ext JS Library 1.1.1
18430 * Copyright(c) 2006-2007, Ext JS, LLC.
18432 * Originally Released Under LGPL - original licence link has changed is not relivant.
18435 * <script type="text/javascript">
18439 * @class Roo.tree.TreeFilter
18440 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
18441 * @param {TreePanel} tree
18442 * @param {Object} config (optional)
18444 Roo.tree.TreeFilter = function(tree, config){
18446 this.filtered = {};
18447 Roo.apply(this, config);
18450 Roo.tree.TreeFilter.prototype = {
18457 * Filter the data by a specific attribute.
18458 * @param {String/RegExp} value Either string that the attribute value
18459 * should start with or a RegExp to test against the attribute
18460 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
18461 * @param {TreeNode} startNode (optional) The node to start the filter at.
18463 filter : function(value, attr, startNode){
18464 attr = attr || "text";
18466 if(typeof value == "string"){
18467 var vlen = value.length;
18468 // auto clear empty filter
18469 if(vlen == 0 && this.clearBlank){
18473 value = value.toLowerCase();
18475 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
18477 }else if(value.exec){ // regex?
18479 return value.test(n.attributes[attr]);
18482 throw 'Illegal filter type, must be string or regex';
18484 this.filterBy(f, null, startNode);
18488 * Filter by a function. The passed function will be called with each
18489 * node in the tree (or from the startNode). If the function returns true, the node is kept
18490 * otherwise it is filtered. If a node is filtered, its children are also filtered.
18491 * @param {Function} fn The filter function
18492 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
18494 filterBy : function(fn, scope, startNode){
18495 startNode = startNode || this.tree.root;
18496 if(this.autoClear){
18499 var af = this.filtered, rv = this.reverse;
18500 var f = function(n){
18501 if(n == startNode){
18507 var m = fn.call(scope || n, n);
18515 startNode.cascade(f);
18518 if(typeof id != "function"){
18520 if(n && n.parentNode){
18521 n.parentNode.removeChild(n);
18529 * Clears the current filter. Note: with the "remove" option
18530 * set a filter cannot be cleared.
18532 clear : function(){
18534 var af = this.filtered;
18536 if(typeof id != "function"){
18543 this.filtered = {};
18548 * Ext JS Library 1.1.1
18549 * Copyright(c) 2006-2007, Ext JS, LLC.
18551 * Originally Released Under LGPL - original licence link has changed is not relivant.
18554 * <script type="text/javascript">
18559 * @class Roo.tree.TreeSorter
18560 * Provides sorting of nodes in a TreePanel
18562 * @cfg {Boolean} folderSort True to sort leaf nodes under non leaf nodes
18563 * @cfg {String} property The named attribute on the node to sort by (defaults to text)
18564 * @cfg {String} dir The direction to sort (asc or desc) (defaults to asc)
18565 * @cfg {String} leafAttr The attribute used to determine leaf nodes in folder sort (defaults to "leaf")
18566 * @cfg {Boolean} caseSensitive true for case sensitive sort (defaults to false)
18567 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting
18569 * @param {TreePanel} tree
18570 * @param {Object} config
18572 Roo.tree.TreeSorter = function(tree, config){
18573 Roo.apply(this, config);
18574 tree.on("beforechildrenrendered", this.doSort, this);
18575 tree.on("append", this.updateSort, this);
18576 tree.on("insert", this.updateSort, this);
18578 var dsc = this.dir && this.dir.toLowerCase() == "desc";
18579 var p = this.property || "text";
18580 var sortType = this.sortType;
18581 var fs = this.folderSort;
18582 var cs = this.caseSensitive === true;
18583 var leafAttr = this.leafAttr || 'leaf';
18585 this.sortFn = function(n1, n2){
18587 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
18590 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
18594 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
18595 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
18597 return dsc ? +1 : -1;
18599 return dsc ? -1 : +1;
18606 Roo.tree.TreeSorter.prototype = {
18607 doSort : function(node){
18608 node.sort(this.sortFn);
18611 compareNodes : function(n1, n2){
18612 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
18615 updateSort : function(tree, node){
18616 if(node.childrenRendered){
18617 this.doSort.defer(1, this, [node]);
18622 * Ext JS Library 1.1.1
18623 * Copyright(c) 2006-2007, Ext JS, LLC.
18625 * Originally Released Under LGPL - original licence link has changed is not relivant.
18628 * <script type="text/javascript">
18631 if(Roo.dd.DropZone){
18633 Roo.tree.TreeDropZone = function(tree, config){
18634 this.allowParentInsert = false;
18635 this.allowContainerDrop = false;
18636 this.appendOnly = false;
18637 Roo.tree.TreeDropZone.superclass.constructor.call(this, tree.innerCt, config);
18639 this.lastInsertClass = "x-tree-no-status";
18640 this.dragOverData = {};
18643 Roo.extend(Roo.tree.TreeDropZone, Roo.dd.DropZone, {
18644 ddGroup : "TreeDD",
18646 expandDelay : 1000,
18648 expandNode : function(node){
18649 if(node.hasChildNodes() && !node.isExpanded()){
18650 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
18654 queueExpand : function(node){
18655 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
18658 cancelExpand : function(){
18659 if(this.expandProcId){
18660 clearTimeout(this.expandProcId);
18661 this.expandProcId = false;
18665 isValidDropPoint : function(n, pt, dd, e, data){
18666 if(!n || !data){ return false; }
18667 var targetNode = n.node;
18668 var dropNode = data.node;
18669 // default drop rules
18670 if(!(targetNode && targetNode.isTarget && pt)){
18673 if(pt == "append" && targetNode.allowChildren === false){
18676 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
18679 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
18682 // reuse the object
18683 var overEvent = this.dragOverData;
18684 overEvent.tree = this.tree;
18685 overEvent.target = targetNode;
18686 overEvent.data = data;
18687 overEvent.point = pt;
18688 overEvent.source = dd;
18689 overEvent.rawEvent = e;
18690 overEvent.dropNode = dropNode;
18691 overEvent.cancel = false;
18692 var result = this.tree.fireEvent("nodedragover", overEvent);
18693 return overEvent.cancel === false && result !== false;
18696 getDropPoint : function(e, n, dd){
18699 return tn.allowChildren !== false ? "append" : false; // always append for root
18701 var dragEl = n.ddel;
18702 var t = Roo.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
18703 var y = Roo.lib.Event.getPageY(e);
18704 //var noAppend = tn.allowChildren === false || tn.isLeaf();
18706 // we may drop nodes anywhere, as long as allowChildren has not been set to false..
18707 var noAppend = tn.allowChildren === false;
18708 if(this.appendOnly || tn.parentNode.allowChildren === false){
18709 return noAppend ? false : "append";
18711 var noBelow = false;
18712 if(!this.allowParentInsert){
18713 noBelow = tn.hasChildNodes() && tn.isExpanded();
18715 var q = (b - t) / (noAppend ? 2 : 3);
18716 if(y >= t && y < (t + q)){
18718 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
18725 onNodeEnter : function(n, dd, e, data){
18726 this.cancelExpand();
18729 onNodeOver : function(n, dd, e, data){
18730 var pt = this.getDropPoint(e, n, dd);
18733 // auto node expand check
18734 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
18735 this.queueExpand(node);
18736 }else if(pt != "append"){
18737 this.cancelExpand();
18740 // set the insert point style on the target node
18741 var returnCls = this.dropNotAllowed;
18742 if(this.isValidDropPoint(n, pt, dd, e, data)){
18747 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
18748 cls = "x-tree-drag-insert-above";
18749 }else if(pt == "below"){
18750 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
18751 cls = "x-tree-drag-insert-below";
18753 returnCls = "x-tree-drop-ok-append";
18754 cls = "x-tree-drag-append";
18756 if(this.lastInsertClass != cls){
18757 Roo.fly(el).replaceClass(this.lastInsertClass, cls);
18758 this.lastInsertClass = cls;
18765 onNodeOut : function(n, dd, e, data){
18766 this.cancelExpand();
18767 this.removeDropIndicators(n);
18770 onNodeDrop : function(n, dd, e, data){
18771 var point = this.getDropPoint(e, n, dd);
18772 var targetNode = n.node;
18773 targetNode.ui.startDrop();
18774 if(!this.isValidDropPoint(n, point, dd, e, data)){
18775 targetNode.ui.endDrop();
18778 // first try to find the drop node
18779 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
18782 target: targetNode,
18787 dropNode: dropNode,
18790 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
18791 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
18792 targetNode.ui.endDrop();
18795 // allow target changing
18796 targetNode = dropEvent.target;
18797 if(point == "append" && !targetNode.isExpanded()){
18798 targetNode.expand(false, null, function(){
18799 this.completeDrop(dropEvent);
18800 }.createDelegate(this));
18802 this.completeDrop(dropEvent);
18807 completeDrop : function(de){
18808 var ns = de.dropNode, p = de.point, t = de.target;
18809 if(!(ns instanceof Array)){
18813 for(var i = 0, len = ns.length; i < len; i++){
18816 t.parentNode.insertBefore(n, t);
18817 }else if(p == "below"){
18818 t.parentNode.insertBefore(n, t.nextSibling);
18824 if(this.tree.hlDrop){
18828 this.tree.fireEvent("nodedrop", de);
18831 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
18832 if(this.tree.hlDrop){
18833 dropNode.ui.focus();
18834 dropNode.ui.highlight();
18836 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
18839 getTree : function(){
18843 removeDropIndicators : function(n){
18846 Roo.fly(el).removeClass([
18847 "x-tree-drag-insert-above",
18848 "x-tree-drag-insert-below",
18849 "x-tree-drag-append"]);
18850 this.lastInsertClass = "_noclass";
18854 beforeDragDrop : function(target, e, id){
18855 this.cancelExpand();
18859 afterRepair : function(data){
18860 if(data && Roo.enableFx){
18861 data.node.ui.highlight();
18870 * Ext JS Library 1.1.1
18871 * Copyright(c) 2006-2007, Ext JS, LLC.
18873 * Originally Released Under LGPL - original licence link has changed is not relivant.
18876 * <script type="text/javascript">
18880 if(Roo.dd.DragZone){
18881 Roo.tree.TreeDragZone = function(tree, config){
18882 Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
18886 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
18887 ddGroup : "TreeDD",
18889 onBeforeDrag : function(data, e){
18891 return n && n.draggable && !n.disabled;
18894 onInitDrag : function(e){
18895 var data = this.dragData;
18896 this.tree.getSelectionModel().select(data.node);
18897 this.proxy.update("");
18898 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
18899 this.tree.fireEvent("startdrag", this.tree, data.node, e);
18902 getRepairXY : function(e, data){
18903 return data.node.ui.getDDRepairXY();
18906 onEndDrag : function(data, e){
18907 this.tree.fireEvent("enddrag", this.tree, data.node, e);
18910 onValidDrop : function(dd, e, id){
18911 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
18915 beforeInvalidDrop : function(e, id){
18916 // this scrolls the original position back into view
18917 var sm = this.tree.getSelectionModel();
18918 sm.clearSelections();
18919 sm.select(this.dragData.node);
18924 * Ext JS Library 1.1.1
18925 * Copyright(c) 2006-2007, Ext JS, LLC.
18927 * Originally Released Under LGPL - original licence link has changed is not relivant.
18930 * <script type="text/javascript">
18933 * @class Roo.tree.TreeEditor
18934 * @extends Roo.Editor
18935 * Provides editor functionality for inline tree node editing. Any valid {@link Roo.form.Field} can be used
18936 * as the editor field.
18938 * @param {TreePanel} tree
18939 * @param {Object} config Either a prebuilt {@link Roo.form.Field} instance or a Field config object
18941 Roo.tree.TreeEditor = function(tree, config){
18942 config = config || {};
18943 var field = config.events ? config : new Roo.form.TextField(config);
18944 Roo.tree.TreeEditor.superclass.constructor.call(this, field);
18948 tree.on('beforeclick', this.beforeNodeClick, this);
18949 tree.getTreeEl().on('mousedown', this.hide, this);
18950 this.on('complete', this.updateNode, this);
18951 this.on('beforestartedit', this.fitToTree, this);
18952 this.on('startedit', this.bindScroll, this, {delay:10});
18953 this.on('specialkey', this.onSpecialKey, this);
18956 Roo.extend(Roo.tree.TreeEditor, Roo.Editor, {
18958 * @cfg {String} alignment
18959 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "l-l").
18965 * @cfg {Boolean} hideEl
18966 * True to hide the bound element while the editor is displayed (defaults to false)
18970 * @cfg {String} cls
18971 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
18973 cls: "x-small-editor x-tree-editor",
18975 * @cfg {Boolean} shim
18976 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
18982 * @cfg {Number} maxWidth
18983 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
18984 * the containing tree element's size, it will be automatically limited for you to the container width, taking
18985 * scroll and client offsets into account prior to each edit.
18992 fitToTree : function(ed, el){
18993 var td = this.tree.getTreeEl().dom, nd = el.dom;
18994 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
18995 td.scrollLeft = nd.offsetLeft;
18999 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
19000 this.setSize(w, '');
19004 triggerEdit : function(node){
19005 this.completeEdit();
19006 this.editNode = node;
19007 this.startEdit(node.ui.textNode, node.text);
19011 bindScroll : function(){
19012 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
19016 beforeNodeClick : function(node, e){
19017 var sinceLast = (this.lastClick ? this.lastClick.getElapsed() : 0);
19018 this.lastClick = new Date();
19019 if(sinceLast > this.editDelay && this.tree.getSelectionModel().isSelected(node)){
19021 this.triggerEdit(node);
19027 updateNode : function(ed, value){
19028 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
19029 this.editNode.setText(value);
19033 onHide : function(){
19034 Roo.tree.TreeEditor.superclass.onHide.call(this);
19036 this.editNode.ui.focus();
19041 onSpecialKey : function(field, e){
19042 var k = e.getKey();
19046 }else if(k == e.ENTER && !e.hasModifier()){
19048 this.completeEdit();
19051 });//<Script type="text/javascript">
19054 * Ext JS Library 1.1.1
19055 * Copyright(c) 2006-2007, Ext JS, LLC.
19057 * Originally Released Under LGPL - original licence link has changed is not relivant.
19060 * <script type="text/javascript">
19064 * Not documented??? - probably should be...
19067 Roo.tree.ColumnNodeUI = Roo.extend(Roo.tree.TreeNodeUI, {
19068 //focus: Roo.emptyFn, // prevent odd scrolling behavior
19070 renderElements : function(n, a, targetNode, bulkRender){
19071 //consel.log("renderElements?");
19072 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
19074 var t = n.getOwnerTree();
19075 var tid = Pman.Tab.Document_TypesTree.tree.el.id;
19077 var cols = t.columns;
19078 var bw = t.borderWidth;
19080 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
19081 var cb = typeof a.checked == "boolean";
19082 var tx = String.format('{0}',n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
19083 var colcls = 'x-t-' + tid + '-c0';
19085 '<li class="x-tree-node">',
19088 '<div class="x-tree-node-el ', a.cls,'">',
19090 '<div class="x-tree-col ', colcls, '" style="width:', c.width-bw, 'px;">',
19093 '<span class="x-tree-node-indent">',this.indentMarkup,'</span>',
19094 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon " />',
19095 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',
19096 (a.icon ? ' x-tree-node-inline-icon' : ''),
19097 (a.iconCls ? ' '+a.iconCls : ''),
19098 '" unselectable="on" />',
19099 (cb ? ('<input class="x-tree-node-cb" type="checkbox" ' +
19100 (a.checked ? 'checked="checked" />' : ' />')) : ''),
19102 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
19103 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
19104 '<span unselectable="on" qtip="' + tx + '">',
19108 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
19109 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>'
19111 for(var i = 1, len = cols.length; i < len; i++){
19113 colcls = 'x-t-' + tid + '-c' +i;
19114 tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
19115 buf.push('<div class="x-tree-col ', colcls, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
19116 '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
19122 '<div class="x-clear"></div></div>',
19123 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
19126 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
19127 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
19128 n.nextSibling.ui.getEl(), buf.join(""));
19130 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
19132 var el = this.wrap.firstChild;
19134 this.elNode = el.firstChild;
19135 this.ranchor = el.childNodes[1];
19136 this.ctNode = this.wrap.childNodes[1];
19137 var cs = el.firstChild.childNodes;
19138 this.indentNode = cs[0];
19139 this.ecNode = cs[1];
19140 this.iconNode = cs[2];
19143 this.checkbox = cs[3];
19146 this.anchor = cs[index];
19148 this.textNode = cs[index].firstChild;
19150 //el.on("click", this.onClick, this);
19151 //el.on("dblclick", this.onDblClick, this);
19154 // console.log(this);
19156 initEvents : function(){
19157 Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
19160 var a = this.ranchor;
19162 var el = Roo.get(a);
19164 if(Roo.isOpera){ // opera render bug ignores the CSS
19165 el.setStyle("text-decoration", "none");
19168 el.on("click", this.onClick, this);
19169 el.on("dblclick", this.onDblClick, this);
19170 el.on("contextmenu", this.onContextMenu, this);
19174 /*onSelectedChange : function(state){
19177 this.addClass("x-tree-selected");
19180 this.removeClass("x-tree-selected");
19183 addClass : function(cls){
19185 Roo.fly(this.elRow).addClass(cls);
19191 removeClass : function(cls){
19193 Roo.fly(this.elRow).removeClass(cls);
19199 });//<Script type="text/javascript">
19203 * Ext JS Library 1.1.1
19204 * Copyright(c) 2006-2007, Ext JS, LLC.
19206 * Originally Released Under LGPL - original licence link has changed is not relivant.
19209 * <script type="text/javascript">
19214 * @class Roo.tree.ColumnTree
19215 * @extends Roo.data.TreePanel
19216 * @cfg {Object} columns Including width, header, renderer, cls, dataIndex
19217 * @cfg {int} borderWidth compined right/left border allowance
19219 * @param {String/HTMLElement/Element} el The container element
19220 * @param {Object} config
19222 Roo.tree.ColumnTree = function(el, config)
19224 Roo.tree.ColumnTree.superclass.constructor.call(this, el , config);
19228 * Fire this event on a container when it resizes
19229 * @param {int} w Width
19230 * @param {int} h Height
19234 this.on('resize', this.onResize, this);
19237 Roo.extend(Roo.tree.ColumnTree, Roo.tree.TreePanel, {
19241 borderWidth: Roo.isBorderBox ? 0 : 2,
19244 render : function(){
19245 // add the header.....
19247 Roo.tree.ColumnTree.superclass.render.apply(this);
19249 this.el.addClass('x-column-tree');
19251 this.headers = this.el.createChild(
19252 {cls:'x-tree-headers'},this.innerCt.dom);
19254 var cols = this.columns, c;
19255 var totalWidth = 0;
19257 var len = cols.length;
19258 for(var i = 0; i < len; i++){
19260 totalWidth += c.width;
19261 this.headEls.push(this.headers.createChild({
19262 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
19264 cls:'x-tree-hd-text',
19267 style:'width:'+(c.width-this.borderWidth)+'px;'
19270 this.headers.createChild({cls:'x-clear'});
19271 // prevent floats from wrapping when clipped
19272 this.headers.setWidth(totalWidth);
19273 //this.innerCt.setWidth(totalWidth);
19274 this.innerCt.setStyle({ overflow: 'auto' });
19275 this.onResize(this.width, this.height);
19279 onResize : function(w,h)
19284 this.innerCt.setWidth(this.width);
19285 this.innerCt.setHeight(this.height-20);
19288 var cols = this.columns, c;
19289 var totalWidth = 0;
19291 var len = cols.length;
19292 for(var i = 0; i < len; i++){
19294 if (this.autoExpandColumn !== false && c.dataIndex == this.autoExpandColumn) {
19295 // it's the expander..
19296 expEl = this.headEls[i];
19299 totalWidth += c.width;
19303 expEl.setWidth( ((w - totalWidth)-this.borderWidth - 20));
19305 this.headers.setWidth(w-20);
19314 * Ext JS Library 1.1.1
19315 * Copyright(c) 2006-2007, Ext JS, LLC.
19317 * Originally Released Under LGPL - original licence link has changed is not relivant.
19320 * <script type="text/javascript">
19324 * @class Roo.menu.Menu
19325 * @extends Roo.util.Observable
19326 * A menu object. This is the container to which you add all other menu items. Menu can also serve a as a base class
19327 * when you want a specialzed menu based off of another component (like {@link Roo.menu.DateMenu} for example).
19329 * Creates a new Menu
19330 * @param {Object} config Configuration options
19332 Roo.menu.Menu = function(config){
19333 Roo.apply(this, config);
19334 this.id = this.id || Roo.id();
19337 * @event beforeshow
19338 * Fires before this menu is displayed
19339 * @param {Roo.menu.Menu} this
19343 * @event beforehide
19344 * Fires before this menu is hidden
19345 * @param {Roo.menu.Menu} this
19350 * Fires after this menu is displayed
19351 * @param {Roo.menu.Menu} this
19356 * Fires after this menu is hidden
19357 * @param {Roo.menu.Menu} this
19362 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
19363 * @param {Roo.menu.Menu} this
19364 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19365 * @param {Roo.EventObject} e
19370 * Fires when the mouse is hovering over this menu
19371 * @param {Roo.menu.Menu} this
19372 * @param {Roo.EventObject} e
19373 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19378 * Fires when the mouse exits this menu
19379 * @param {Roo.menu.Menu} this
19380 * @param {Roo.EventObject} e
19381 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19386 * Fires when a menu item contained in this menu is clicked
19387 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
19388 * @param {Roo.EventObject} e
19392 if (this.registerMenu) {
19393 Roo.menu.MenuMgr.register(this);
19396 var mis = this.items;
19397 this.items = new Roo.util.MixedCollection();
19399 this.add.apply(this, mis);
19403 Roo.extend(Roo.menu.Menu, Roo.util.Observable, {
19405 * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120)
19409 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
19410 * for bottom-right shadow (defaults to "sides")
19414 * @cfg {String} subMenuAlign The {@link Roo.Element#alignTo} anchor position value to use for submenus of
19415 * this menu (defaults to "tl-tr?")
19417 subMenuAlign : "tl-tr?",
19419 * @cfg {String} defaultAlign The default {@link Roo.Element#alignTo) anchor position value for this menu
19420 * relative to its element of origin (defaults to "tl-bl?")
19422 defaultAlign : "tl-bl?",
19424 * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false)
19426 allowOtherMenus : false,
19428 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
19430 registerMenu : true,
19435 render : function(){
19439 var el = this.el = new Roo.Layer({
19441 shadow:this.shadow,
19443 parentEl: this.parentEl || document.body,
19447 this.keyNav = new Roo.menu.MenuNav(this);
19450 el.addClass("x-menu-plain");
19453 el.addClass(this.cls);
19455 // generic focus element
19456 this.focusEl = el.createChild({
19457 tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1"
19459 var ul = el.createChild({tag: "ul", cls: "x-menu-list"});
19460 ul.on("click", this.onClick, this);
19461 ul.on("mouseover", this.onMouseOver, this);
19462 ul.on("mouseout", this.onMouseOut, this);
19463 this.items.each(function(item){
19464 var li = document.createElement("li");
19465 li.className = "x-menu-list-item";
19466 ul.dom.appendChild(li);
19467 item.render(li, this);
19474 autoWidth : function(){
19475 var el = this.el, ul = this.ul;
19479 var w = this.width;
19482 }else if(Roo.isIE){
19483 el.setWidth(this.minWidth);
19484 var t = el.dom.offsetWidth; // force recalc
19485 el.setWidth(ul.getWidth()+el.getFrameWidth("lr"));
19490 delayAutoWidth : function(){
19493 this.awTask = new Roo.util.DelayedTask(this.autoWidth, this);
19495 this.awTask.delay(20);
19500 findTargetItem : function(e){
19501 var t = e.getTarget(".x-menu-list-item", this.ul, true);
19502 if(t && t.menuItemId){
19503 return this.items.get(t.menuItemId);
19508 onClick : function(e){
19510 if(t = this.findTargetItem(e)){
19512 this.fireEvent("click", this, t, e);
19517 setActiveItem : function(item, autoExpand){
19518 if(item != this.activeItem){
19519 if(this.activeItem){
19520 this.activeItem.deactivate();
19522 this.activeItem = item;
19523 item.activate(autoExpand);
19524 }else if(autoExpand){
19530 tryActivate : function(start, step){
19531 var items = this.items;
19532 for(var i = start, len = items.length; i >= 0 && i < len; i+= step){
19533 var item = items.get(i);
19534 if(!item.disabled && item.canActivate){
19535 this.setActiveItem(item, false);
19543 onMouseOver : function(e){
19545 if(t = this.findTargetItem(e)){
19546 if(t.canActivate && !t.disabled){
19547 this.setActiveItem(t, true);
19550 this.fireEvent("mouseover", this, e, t);
19554 onMouseOut : function(e){
19556 if(t = this.findTargetItem(e)){
19557 if(t == this.activeItem && t.shouldDeactivate(e)){
19558 this.activeItem.deactivate();
19559 delete this.activeItem;
19562 this.fireEvent("mouseout", this, e, t);
19566 * Read-only. Returns true if the menu is currently displayed, else false.
19569 isVisible : function(){
19570 return this.el && !this.hidden;
19574 * Displays this menu relative to another element
19575 * @param {String/HTMLElement/Roo.Element} element The element to align to
19576 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
19577 * the element (defaults to this.defaultAlign)
19578 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
19580 show : function(el, pos, parentMenu){
19581 this.parentMenu = parentMenu;
19585 this.fireEvent("beforeshow", this);
19586 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
19590 * Displays this menu at a specific xy position
19591 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
19592 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
19594 showAt : function(xy, parentMenu, /* private: */_e){
19595 this.parentMenu = parentMenu;
19600 this.fireEvent("beforeshow", this);
19601 xy = this.el.adjustForConstraints(xy);
19605 this.hidden = false;
19607 this.fireEvent("show", this);
19610 focus : function(){
19612 this.doFocus.defer(50, this);
19616 doFocus : function(){
19618 this.focusEl.focus();
19623 * Hides this menu and optionally all parent menus
19624 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
19626 hide : function(deep){
19627 if(this.el && this.isVisible()){
19628 this.fireEvent("beforehide", this);
19629 if(this.activeItem){
19630 this.activeItem.deactivate();
19631 this.activeItem = null;
19634 this.hidden = true;
19635 this.fireEvent("hide", this);
19637 if(deep === true && this.parentMenu){
19638 this.parentMenu.hide(true);
19643 * Addds one or more items of any type supported by the Menu class, or that can be converted into menu items.
19644 * Any of the following are valid:
19646 * <li>Any menu item object based on {@link Roo.menu.Item}</li>
19647 * <li>An HTMLElement object which will be converted to a menu item</li>
19648 * <li>A menu item config object that will be created as a new menu item</li>
19649 * <li>A string, which can either be '-' or 'separator' to add a menu separator, otherwise
19650 * it will be converted into a {@link Roo.menu.TextItem} and added</li>
19655 var menu = new Roo.menu.Menu();
19657 // Create a menu item to add by reference
19658 var menuItem = new Roo.menu.Item({ text: 'New Item!' });
19660 // Add a bunch of items at once using different methods.
19661 // Only the last item added will be returned.
19662 var item = menu.add(
19663 menuItem, // add existing item by ref
19664 'Dynamic Item', // new TextItem
19665 '-', // new separator
19666 { text: 'Config Item' } // new item by config
19669 * @param {Mixed} args One or more menu items, menu item configs or other objects that can be converted to menu items
19670 * @return {Roo.menu.Item} The menu item that was added, or the last one if multiple items were added
19673 var a = arguments, l = a.length, item;
19674 for(var i = 0; i < l; i++){
19676 if ((typeof(el) == "object") && el.xtype && el.xns) {
19677 el = Roo.factory(el, Roo.menu);
19680 if(el.render){ // some kind of Item
19681 item = this.addItem(el);
19682 }else if(typeof el == "string"){ // string
19683 if(el == "separator" || el == "-"){
19684 item = this.addSeparator();
19686 item = this.addText(el);
19688 }else if(el.tagName || el.el){ // element
19689 item = this.addElement(el);
19690 }else if(typeof el == "object"){ // must be menu item config?
19691 item = this.addMenuItem(el);
19698 * Returns this menu's underlying {@link Roo.Element} object
19699 * @return {Roo.Element} The element
19701 getEl : function(){
19709 * Adds a separator bar to the menu
19710 * @return {Roo.menu.Item} The menu item that was added
19712 addSeparator : function(){
19713 return this.addItem(new Roo.menu.Separator());
19717 * Adds an {@link Roo.Element} object to the menu
19718 * @param {String/HTMLElement/Roo.Element} el The element or DOM node to add, or its id
19719 * @return {Roo.menu.Item} The menu item that was added
19721 addElement : function(el){
19722 return this.addItem(new Roo.menu.BaseItem(el));
19726 * Adds an existing object based on {@link Roo.menu.Item} to the menu
19727 * @param {Roo.menu.Item} item The menu item to add
19728 * @return {Roo.menu.Item} The menu item that was added
19730 addItem : function(item){
19731 this.items.add(item);
19733 var li = document.createElement("li");
19734 li.className = "x-menu-list-item";
19735 this.ul.dom.appendChild(li);
19736 item.render(li, this);
19737 this.delayAutoWidth();
19743 * Creates a new {@link Roo.menu.Item} based an the supplied config object and adds it to the menu
19744 * @param {Object} config A MenuItem config object
19745 * @return {Roo.menu.Item} The menu item that was added
19747 addMenuItem : function(config){
19748 if(!(config instanceof Roo.menu.Item)){
19749 if(typeof config.checked == "boolean"){ // must be check menu item config?
19750 config = new Roo.menu.CheckItem(config);
19752 config = new Roo.menu.Item(config);
19755 return this.addItem(config);
19759 * Creates a new {@link Roo.menu.TextItem} with the supplied text and adds it to the menu
19760 * @param {String} text The text to display in the menu item
19761 * @return {Roo.menu.Item} The menu item that was added
19763 addText : function(text){
19764 return this.addItem(new Roo.menu.TextItem({ text : text }));
19768 * Inserts an existing object based on {@link Roo.menu.Item} to the menu at a specified index
19769 * @param {Number} index The index in the menu's list of current items where the new item should be inserted
19770 * @param {Roo.menu.Item} item The menu item to add
19771 * @return {Roo.menu.Item} The menu item that was added
19773 insert : function(index, item){
19774 this.items.insert(index, item);
19776 var li = document.createElement("li");
19777 li.className = "x-menu-list-item";
19778 this.ul.dom.insertBefore(li, this.ul.dom.childNodes[index]);
19779 item.render(li, this);
19780 this.delayAutoWidth();
19786 * Removes an {@link Roo.menu.Item} from the menu and destroys the object
19787 * @param {Roo.menu.Item} item The menu item to remove
19789 remove : function(item){
19790 this.items.removeKey(item.id);
19795 * Removes and destroys all items in the menu
19797 removeAll : function(){
19799 while(f = this.items.first()){
19805 // MenuNav is a private utility class used internally by the Menu
19806 Roo.menu.MenuNav = function(menu){
19807 Roo.menu.MenuNav.superclass.constructor.call(this, menu.el);
19808 this.scope = this.menu = menu;
19811 Roo.extend(Roo.menu.MenuNav, Roo.KeyNav, {
19812 doRelay : function(e, h){
19813 var k = e.getKey();
19814 if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){
19815 this.menu.tryActivate(0, 1);
19818 return h.call(this.scope || this, e, this.menu);
19821 up : function(e, m){
19822 if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
19823 m.tryActivate(m.items.length-1, -1);
19827 down : function(e, m){
19828 if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
19829 m.tryActivate(0, 1);
19833 right : function(e, m){
19835 m.activeItem.expandMenu(true);
19839 left : function(e, m){
19841 if(m.parentMenu && m.parentMenu.activeItem){
19842 m.parentMenu.activeItem.activate();
19846 enter : function(e, m){
19848 e.stopPropagation();
19849 m.activeItem.onClick(e);
19850 m.fireEvent("click", this, m.activeItem);