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);
77 Roo.dd.DragDrop.prototype = {
80 * The id of the element associated with this object. This is what we
81 * refer to as the "linked element" because the size and position of
82 * this element is used to determine when the drag and drop objects have
90 * Configuration attributes passed into the constructor
97 * The id of the element that will be dragged. By default this is same
98 * as the linked element , but could be changed to another element. Ex:
107 * the id of the element that initiates the drag operation. By default
108 * this is the linked element, but could be changed to be a child of this
109 * element. This lets us do things like only starting the drag when the
110 * header element within the linked html element is clicked.
111 * @property handleElId
118 * An associative array of HTML tags that will be ignored if clicked.
119 * @property invalidHandleTypes
120 * @type {string: string}
122 invalidHandleTypes: null,
125 * An associative array of ids for elements that will be ignored if clicked
126 * @property invalidHandleIds
127 * @type {string: string}
129 invalidHandleIds: null,
132 * An indexted array of css class names for elements that will be ignored
134 * @property invalidHandleClasses
137 invalidHandleClasses: null,
140 * The linked element's absolute X position at the time the drag was
142 * @property startPageX
149 * The linked element's absolute X position at the time the drag was
151 * @property startPageY
158 * The group defines a logical collection of DragDrop objects that are
159 * related. Instances only get events when interacting with other
160 * DragDrop object in the same group. This lets us define multiple
161 * groups using a single DragDrop subclass if we want.
163 * @type {string: string}
168 * Individual drag/drop instances can be locked. This will prevent
169 * onmousedown start drag.
180 lock: function() { this.locked = true; },
183 * Unlock this instace
186 unlock: function() { this.locked = false; },
189 * By default, all insances can be a drop target. This can be disabled by
190 * setting isTarget to false.
197 * The padding configured for this drag and drop object for calculating
198 * the drop zone intersection with this object.
205 * Cached reference to the linked element
212 * Internal typeof flag
213 * @property __ygDragDrop
219 * Set to true when horizontal contraints are applied
220 * @property constrainX
227 * Set to true when vertical contraints are applied
228 * @property constrainY
235 * The left constraint
243 * The right constraint
260 * The down constraint
268 * Maintain offsets when we resetconstraints. Set to true when you want
269 * the position of the element relative to its parent to stay the same
270 * when the page changes
272 * @property maintainOffset
275 maintainOffset: false,
278 * Array of pixel locations the element will snap to if we specified a
279 * horizontal graduation/interval. This array is generated automatically
280 * when you define a tick interval.
287 * Array of pixel locations the element will snap to if we specified a
288 * vertical graduation/interval. This array is generated automatically
289 * when you define a tick interval.
296 * By default the drag and drop instance will only respond to the primary
297 * button click (left button for a right-handed mouse). Set to true to
298 * allow drag and drop to start with any mouse click that is propogated
300 * @property primaryButtonOnly
303 primaryButtonOnly: true,
306 * The availabe property is false until the linked dom element is accessible.
307 * @property available
313 * By default, drags can only be initiated if the mousedown occurs in the
314 * region the linked element is. This is done in part to work around a
315 * bug in some browsers that mis-report the mousedown if the previous
316 * mouseup happened outside of the window. This property is set to true
317 * if outer handles are defined.
319 * @property hasOuterHandles
323 hasOuterHandles: false,
326 * Code that executes immediately before the startDrag event
327 * @method b4StartDrag
330 b4StartDrag: function(x, y) { },
333 * Abstract method called after a drag/drop object is clicked
334 * and the drag or mousedown time thresholds have beeen met.
336 * @param {int} X click location
337 * @param {int} Y click location
339 startDrag: function(x, y) { /* override this */ },
342 * Code that executes immediately before the onDrag event
346 b4Drag: function(e) { },
349 * Abstract method called during the onMouseMove event while dragging an
352 * @param {Event} e the mousemove event
354 onDrag: function(e) { /* override this */ },
357 * Abstract method called when this element fist begins hovering over
358 * another DragDrop obj
359 * @method onDragEnter
360 * @param {Event} e the mousemove event
361 * @param {String|DragDrop[]} id In POINT mode, the element
362 * id this is hovering over. In INTERSECT mode, an array of one or more
363 * dragdrop items being hovered over.
365 onDragEnter: function(e, id) { /* override this */ },
368 * Code that executes immediately before the onDragOver event
372 b4DragOver: function(e) { },
375 * Abstract method called when this element is hovering over another
378 * @param {Event} e the mousemove event
379 * @param {String|DragDrop[]} id In POINT mode, the element
380 * id this is hovering over. In INTERSECT mode, an array of dd items
381 * being hovered over.
383 onDragOver: function(e, id) { /* override this */ },
386 * Code that executes immediately before the onDragOut event
390 b4DragOut: function(e) { },
393 * Abstract method called when we are no longer hovering over an element
395 * @param {Event} e the mousemove event
396 * @param {String|DragDrop[]} id In POINT mode, the element
397 * id this was hovering over. In INTERSECT mode, an array of dd items
398 * that the mouse is no longer over.
400 onDragOut: function(e, id) { /* override this */ },
403 * Code that executes immediately before the onDragDrop event
407 b4DragDrop: function(e) { },
410 * Abstract method called when this item is dropped on another DragDrop
413 * @param {Event} e the mouseup event
414 * @param {String|DragDrop[]} id In POINT mode, the element
415 * id this was dropped on. In INTERSECT mode, an array of dd items this
418 onDragDrop: function(e, id) { /* override this */ },
421 * Abstract method called when this item is dropped on an area with no
423 * @method onInvalidDrop
424 * @param {Event} e the mouseup event
426 onInvalidDrop: function(e) { /* override this */ },
429 * Code that executes immediately before the endDrag event
433 b4EndDrag: function(e) { },
436 * Fired when we are done dragging the object
438 * @param {Event} e the mouseup event
440 endDrag: function(e) { /* override this */ },
443 * Code executed immediately before the onMouseDown event
444 * @method b4MouseDown
445 * @param {Event} e the mousedown event
448 b4MouseDown: function(e) { },
451 * Event handler that fires when a drag/drop obj gets a mousedown
452 * @method onMouseDown
453 * @param {Event} e the mousedown event
455 onMouseDown: function(e) { /* override this */ },
458 * Event handler that fires when a drag/drop obj gets a mouseup
460 * @param {Event} e the mouseup event
462 onMouseUp: function(e) { /* override this */ },
465 * Override the onAvailable method to do what is needed after the initial
466 * position was determined.
467 * @method onAvailable
469 onAvailable: function () {
473 * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
476 defaultPadding : {left:0, right:0, top:0, bottom:0},
479 * Initializes the drag drop object's constraints to restrict movement to a certain element.
483 var dd = new Roo.dd.DDProxy("dragDiv1", "proxytest",
484 { dragElId: "existingProxyDiv" });
485 dd.startDrag = function(){
486 this.constrainTo("parent-id");
489 * Or you can initalize it using the {@link Roo.Element} object:
491 Roo.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
492 startDrag : function(){
493 this.constrainTo("parent-id");
497 * @param {String/HTMLElement/Element} constrainTo The element to constrain to.
498 * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
499 * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
500 * an object containing the sides to pad. For example: {right:10, bottom:10}
501 * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
503 constrainTo : function(constrainTo, pad, inContent){
504 if(typeof pad == "number"){
505 pad = {left: pad, right:pad, top:pad, bottom:pad};
507 pad = pad || this.defaultPadding;
508 var b = Roo.get(this.getEl()).getBox();
509 var ce = Roo.get(constrainTo);
510 var s = ce.getScroll();
512 if(cd == document.body){
513 c = { x: s.left, y: s.top, width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
516 c = {x : xy[0]+s.left, y: xy[1]+s.top, width: cd.clientWidth, height: cd.clientHeight};
520 var topSpace = b.y - c.y;
521 var leftSpace = b.x - c.x;
523 this.resetConstraints();
524 this.setXConstraint(leftSpace - (pad.left||0), // left
525 c.width - leftSpace - b.width - (pad.right||0) //right
527 this.setYConstraint(topSpace - (pad.top||0), //top
528 c.height - topSpace - b.height - (pad.bottom||0) //bottom
533 * Returns a reference to the linked element
535 * @return {HTMLElement} the html element
539 this._domRef = Roo.getDom(this.id);
546 * Returns a reference to the actual element to drag. By default this is
547 * the same as the html element, but it can be assigned to another
548 * element. An example of this can be found in Roo.dd.DDProxy
550 * @return {HTMLElement} the html element
552 getDragEl: function() {
553 return Roo.getDom(this.dragElId);
557 * Sets up the DragDrop object. Must be called in the constructor of any
558 * Roo.dd.DragDrop subclass
560 * @param id the id of the linked element
561 * @param {String} sGroup the group of related items
562 * @param {object} config configuration attributes
564 init: function(id, sGroup, config) {
565 this.initTarget(id, sGroup, config);
566 Event.on(this.id, "mousedown", this.handleMouseDown, this);
567 // Event.on(this.id, "selectstart", Event.preventDefault);
571 * Initializes Targeting functionality only... the object does not
572 * get a mousedown handler.
574 * @param id the id of the linked element
575 * @param {String} sGroup the group of related items
576 * @param {object} config configuration attributes
578 initTarget: function(id, sGroup, config) {
580 // configuration attributes
581 this.config = config || {};
583 // create a local reference to the drag and drop manager
584 this.DDM = Roo.dd.DDM;
585 // initialize the groups array
588 // assume that we have an element reference instead of an id if the
589 // parameter is not a string
590 if (typeof id !== "string") {
597 // add to an interaction group
598 this.addToGroup((sGroup) ? sGroup : "default");
600 // We don't want to register this as the handle with the manager
601 // so we just set the id rather than calling the setter.
602 this.handleElId = id;
604 // the linked element is the element that gets dragged by default
605 this.setDragElId(id);
607 // by default, clicked anchors will not start drag operations.
608 this.invalidHandleTypes = { A: "A" };
609 this.invalidHandleIds = {};
610 this.invalidHandleClasses = [];
614 this.handleOnAvailable();
618 * Applies the configuration parameters that were passed into the constructor.
619 * This is supposed to happen at each level through the inheritance chain. So
620 * a DDProxy implentation will execute apply config on DDProxy, DD, and
621 * DragDrop in order to get all of the parameters that are available in
623 * @method applyConfig
625 applyConfig: function() {
627 // configurable properties:
628 // padding, isTarget, maintainOffset, primaryButtonOnly
629 this.padding = this.config.padding || [0, 0, 0, 0];
630 this.isTarget = (this.config.isTarget !== false);
631 this.maintainOffset = (this.config.maintainOffset);
632 this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
637 * Executed when the linked element is available
638 * @method handleOnAvailable
641 handleOnAvailable: function() {
642 this.available = true;
643 this.resetConstraints();
648 * Configures the padding for the target zone in px. Effectively expands
649 * (or reduces) the virtual object size for targeting calculations.
650 * Supports css-style shorthand; if only one parameter is passed, all sides
651 * will have that padding, and if only two are passed, the top and bottom
652 * will have the first param, the left and right the second.
654 * @param {int} iTop Top pad
655 * @param {int} iRight Right pad
656 * @param {int} iBot Bot pad
657 * @param {int} iLeft Left pad
659 setPadding: function(iTop, iRight, iBot, iLeft) {
660 // this.padding = [iLeft, iRight, iTop, iBot];
661 if (!iRight && 0 !== iRight) {
662 this.padding = [iTop, iTop, iTop, iTop];
663 } else if (!iBot && 0 !== iBot) {
664 this.padding = [iTop, iRight, iTop, iRight];
666 this.padding = [iTop, iRight, iBot, iLeft];
671 * Stores the initial placement of the linked element.
672 * @method setInitialPosition
673 * @param {int} diffX the X offset, default 0
674 * @param {int} diffY the Y offset, default 0
676 setInitPosition: function(diffX, diffY) {
677 var el = this.getEl();
679 if (!this.DDM.verifyEl(el)) {
686 var p = Dom.getXY( el );
688 this.initPageX = p[0] - dx;
689 this.initPageY = p[1] - dy;
691 this.lastPageX = p[0];
692 this.lastPageY = p[1];
695 this.setStartPosition(p);
699 * Sets the start position of the element. This is set when the obj
700 * is initialized, the reset when a drag is started.
701 * @method setStartPosition
702 * @param pos current position (from previous lookup)
705 setStartPosition: function(pos) {
706 var p = pos || Dom.getXY( this.getEl() );
707 this.deltaSetXY = null;
709 this.startPageX = p[0];
710 this.startPageY = p[1];
714 * Add this instance to a group of related drag/drop objects. All
715 * instances belong to at least one group, and can belong to as many
718 * @param sGroup {string} the name of the group
720 addToGroup: function(sGroup) {
721 this.groups[sGroup] = true;
722 this.DDM.regDragDrop(this, sGroup);
726 * Remove's this instance from the supplied interaction group
727 * @method removeFromGroup
728 * @param {string} sGroup The group to drop
730 removeFromGroup: function(sGroup) {
731 if (this.groups[sGroup]) {
732 delete this.groups[sGroup];
735 this.DDM.removeDDFromGroup(this, sGroup);
739 * Allows you to specify that an element other than the linked element
740 * will be moved with the cursor during a drag
741 * @method setDragElId
742 * @param id {string} the id of the element that will be used to initiate the drag
744 setDragElId: function(id) {
749 * Allows you to specify a child of the linked element that should be
750 * used to initiate the drag operation. An example of this would be if
751 * you have a content div with text and links. Clicking anywhere in the
752 * content area would normally start the drag operation. Use this method
753 * to specify that an element inside of the content div is the element
754 * that starts the drag operation.
755 * @method setHandleElId
756 * @param id {string} the id of the element that will be used to
759 setHandleElId: function(id) {
760 if (typeof id !== "string") {
763 this.handleElId = id;
764 this.DDM.regHandle(this.id, id);
768 * Allows you to set an element outside of the linked element as a drag
770 * @method setOuterHandleElId
771 * @param id the id of the element that will be used to initiate the drag
773 setOuterHandleElId: function(id) {
774 if (typeof id !== "string") {
777 Event.on(id, "mousedown",
778 this.handleMouseDown, this);
779 this.setHandleElId(id);
781 this.hasOuterHandles = true;
785 * Remove all drag and drop hooks for this element
789 Event.un(this.id, "mousedown",
790 this.handleMouseDown);
792 this.DDM._remove(this);
795 destroy : function(){
800 * Returns true if this instance is locked, or the drag drop mgr is locked
801 * (meaning that all drag/drop is disabled on the page.)
803 * @return {boolean} true if this obj or all drag/drop is locked, else
806 isLocked: function() {
807 return (this.DDM.isLocked() || this.locked);
811 * Fired when this object is clicked
812 * @method handleMouseDown
814 * @param {Roo.dd.DragDrop} oDD the clicked dd object (this dd obj)
817 handleMouseDown: function(e, oDD){
818 if (this.primaryButtonOnly && e.button != 0) {
822 if (this.isLocked()) {
826 this.DDM.refreshCache(this.groups);
828 var pt = new Roo.lib.Point(Roo.lib.Event.getPageX(e), Roo.lib.Event.getPageY(e));
829 if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) {
831 if (this.clickValidator(e)) {
833 // set the initial element position
834 this.setStartPosition();
840 this.DDM.handleMouseDown(e, this);
842 this.DDM.stopEvent(e);
850 clickValidator: function(e) {
851 var target = e.getTarget();
852 return ( this.isValidHandleChild(target) &&
853 (this.id == this.handleElId ||
854 this.DDM.handleWasClicked(target, this.id)) );
858 * Allows you to specify a tag name that should not start a drag operation
859 * when clicked. This is designed to facilitate embedding links within a
860 * drag handle that do something other than start the drag.
861 * @method addInvalidHandleType
862 * @param {string} tagName the type of element to exclude
864 addInvalidHandleType: function(tagName) {
865 var type = tagName.toUpperCase();
866 this.invalidHandleTypes[type] = type;
870 * Lets you to specify an element id for a child of a drag handle
871 * that should not initiate a drag
872 * @method addInvalidHandleId
873 * @param {string} id the element id of the element you wish to ignore
875 addInvalidHandleId: function(id) {
876 if (typeof id !== "string") {
879 this.invalidHandleIds[id] = id;
883 * Lets you specify a css class of elements that will not initiate a drag
884 * @method addInvalidHandleClass
885 * @param {string} cssClass the class of the elements you wish to ignore
887 addInvalidHandleClass: function(cssClass) {
888 this.invalidHandleClasses.push(cssClass);
892 * Unsets an excluded tag name set by addInvalidHandleType
893 * @method removeInvalidHandleType
894 * @param {string} tagName the type of element to unexclude
896 removeInvalidHandleType: function(tagName) {
897 var type = tagName.toUpperCase();
898 // this.invalidHandleTypes[type] = null;
899 delete this.invalidHandleTypes[type];
903 * Unsets an invalid handle id
904 * @method removeInvalidHandleId
905 * @param {string} id the id of the element to re-enable
907 removeInvalidHandleId: function(id) {
908 if (typeof id !== "string") {
911 delete this.invalidHandleIds[id];
915 * Unsets an invalid css class
916 * @method removeInvalidHandleClass
917 * @param {string} cssClass the class of the element(s) you wish to
920 removeInvalidHandleClass: function(cssClass) {
921 for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
922 if (this.invalidHandleClasses[i] == cssClass) {
923 delete this.invalidHandleClasses[i];
929 * Checks the tag exclusion list to see if this click should be ignored
930 * @method isValidHandleChild
931 * @param {HTMLElement} node the HTMLElement to evaluate
932 * @return {boolean} true if this is a valid tag type, false if not
934 isValidHandleChild: function(node) {
937 // var n = (node.nodeName == "#text") ? node.parentNode : node;
940 nodeName = node.nodeName.toUpperCase();
942 nodeName = node.nodeName;
944 valid = valid && !this.invalidHandleTypes[nodeName];
945 valid = valid && !this.invalidHandleIds[node.id];
947 for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
948 valid = !Dom.hasClass(node, this.invalidHandleClasses[i]);
957 * Create the array of horizontal tick marks if an interval was specified
958 * in setXConstraint().
962 setXTicks: function(iStartX, iTickSize) {
964 this.xTickSize = iTickSize;
968 for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
970 this.xTicks[this.xTicks.length] = i;
975 for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
977 this.xTicks[this.xTicks.length] = i;
982 this.xTicks.sort(this.DDM.numericSort) ;
986 * Create the array of vertical tick marks if an interval was specified in
991 setYTicks: function(iStartY, iTickSize) {
993 this.yTickSize = iTickSize;
997 for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
999 this.yTicks[this.yTicks.length] = i;
1004 for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
1006 this.yTicks[this.yTicks.length] = i;
1011 this.yTicks.sort(this.DDM.numericSort) ;
1015 * By default, the element can be dragged any place on the screen. Use
1016 * this method to limit the horizontal travel of the element. Pass in
1017 * 0,0 for the parameters if you want to lock the drag to the y axis.
1018 * @method setXConstraint
1019 * @param {int} iLeft the number of pixels the element can move to the left
1020 * @param {int} iRight the number of pixels the element can move to the
1022 * @param {int} iTickSize optional parameter for specifying that the
1024 * should move iTickSize pixels at a time.
1026 setXConstraint: function(iLeft, iRight, iTickSize) {
1027 this.leftConstraint = iLeft;
1028 this.rightConstraint = iRight;
1030 this.minX = this.initPageX - iLeft;
1031 this.maxX = this.initPageX + iRight;
1032 if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
1034 this.constrainX = true;
1038 * Clears any constraints applied to this instance. Also clears ticks
1039 * since they can't exist independent of a constraint at this time.
1040 * @method clearConstraints
1042 clearConstraints: function() {
1043 this.constrainX = false;
1044 this.constrainY = false;
1049 * Clears any tick interval defined for this instance
1050 * @method clearTicks
1052 clearTicks: function() {
1060 * By default, the element can be dragged any place on the screen. Set
1061 * this to limit the vertical travel of the element. Pass in 0,0 for the
1062 * parameters if you want to lock the drag to the x axis.
1063 * @method setYConstraint
1064 * @param {int} iUp the number of pixels the element can move up
1065 * @param {int} iDown the number of pixels the element can move down
1066 * @param {int} iTickSize optional parameter for specifying that the
1067 * element should move iTickSize pixels at a time.
1069 setYConstraint: function(iUp, iDown, iTickSize) {
1070 this.topConstraint = iUp;
1071 this.bottomConstraint = iDown;
1073 this.minY = this.initPageY - iUp;
1074 this.maxY = this.initPageY + iDown;
1075 if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
1077 this.constrainY = true;
1082 * resetConstraints must be called if you manually reposition a dd element.
1083 * @method resetConstraints
1084 * @param {boolean} maintainOffset
1086 resetConstraints: function() {
1089 // Maintain offsets if necessary
1090 if (this.initPageX || this.initPageX === 0) {
1091 // figure out how much this thing has moved
1092 var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0;
1093 var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0;
1095 this.setInitPosition(dx, dy);
1097 // This is the first time we have detected the element's position
1099 this.setInitPosition();
1102 if (this.constrainX) {
1103 this.setXConstraint( this.leftConstraint,
1104 this.rightConstraint,
1108 if (this.constrainY) {
1109 this.setYConstraint( this.topConstraint,
1110 this.bottomConstraint,
1116 * Normally the drag element is moved pixel by pixel, but we can specify
1117 * that it move a number of pixels at a time. This method resolves the
1118 * location when we have it set up like this.
1120 * @param {int} val where we want to place the object
1121 * @param {int[]} tickArray sorted array of valid points
1122 * @return {int} the closest tick
1125 getTick: function(val, tickArray) {
1128 // If tick interval is not defined, it is effectively 1 pixel,
1129 // so we return the value passed to us.
1131 } else if (tickArray[0] >= val) {
1132 // The value is lower than the first tick, so we return the first
1134 return tickArray[0];
1136 for (var i=0, len=tickArray.length; i<len; ++i) {
1138 if (tickArray[next] && tickArray[next] >= val) {
1139 var diff1 = val - tickArray[i];
1140 var diff2 = tickArray[next] - val;
1141 return (diff2 > diff1) ? tickArray[i] : tickArray[next];
1145 // The value is larger than the last tick, so we return the last
1147 return tickArray[tickArray.length - 1];
1154 * @return {string} string representation of the dd obj
1156 toString: function() {
1157 return ("DragDrop " + this.id);
1165 * Ext JS Library 1.1.1
1166 * Copyright(c) 2006-2007, Ext JS, LLC.
1168 * Originally Released Under LGPL - original licence link has changed is not relivant.
1171 * <script type="text/javascript">
1176 * The drag and drop utility provides a framework for building drag and drop
1177 * applications. In addition to enabling drag and drop for specific elements,
1178 * the drag and drop elements are tracked by the manager class, and the
1179 * interactions between the various elements are tracked during the drag and
1180 * the implementing code is notified about these important moments.
1183 // Only load the library once. Rewriting the manager class would orphan
1184 // existing drag and drop instances.
1185 if (!Roo.dd.DragDropMgr) {
1188 * @class Roo.dd.DragDropMgr
1189 * DragDropMgr is a singleton that tracks the element interaction for
1190 * all DragDrop items in the window. Generally, you will not call
1191 * this class directly, but it does have helper methods that could
1192 * be useful in your DragDrop implementations.
1195 Roo.dd.DragDropMgr = function() {
1197 var Event = Roo.EventManager;
1202 * Two dimensional Array of registered DragDrop objects. The first
1203 * dimension is the DragDrop item group, the second the DragDrop
1206 * @type {string: string}
1213 * Array of element ids defined as drag handles. Used to determine
1214 * if the element that generated the mousedown event is actually the
1215 * handle and not the html element itself.
1216 * @property handleIds
1217 * @type {string: string}
1224 * the DragDrop object that is currently being dragged
1225 * @property dragCurrent
1233 * the DragDrop object(s) that are being hovered over
1234 * @property dragOvers
1242 * the X distance between the cursor and the object being dragged
1251 * the Y distance between the cursor and the object being dragged
1260 * Flag to determine if we should prevent the default behavior of the
1261 * events we define. By default this is true, but this can be set to
1262 * false if you need the default behavior (not recommended)
1263 * @property preventDefault
1267 preventDefault: true,
1270 * Flag to determine if we should stop the propagation of the events
1271 * we generate. This is true by default but you may want to set it to
1272 * false if the html element contains other features that require the
1274 * @property stopPropagation
1278 stopPropagation: true,
1281 * Internal flag that is set to true when drag and drop has been
1283 * @property initialized
1290 * All drag and drop can be disabled.
1298 * Called the first time an element is registered.
1304 this.initialized = true;
1308 * In point mode, drag and drop interaction is defined by the
1309 * location of the cursor during the drag/drop
1317 * In intersect mode, drag and drop interactio nis defined by the
1318 * overlap of two or more drag and drop objects.
1319 * @property INTERSECT
1326 * The current drag and drop mode. Default: POINT
1334 * Runs method on all drag and drop objects
1335 * @method _execOnAll
1339 _execOnAll: function(sMethod, args) {
1340 for (var i in this.ids) {
1341 for (var j in this.ids[i]) {
1342 var oDD = this.ids[i][j];
1343 if (! this.isTypeOfDD(oDD)) {
1346 oDD[sMethod].apply(oDD, args);
1352 * Drag and drop initialization. Sets up the global event handlers
1357 _onLoad: function() {
1362 Event.on(document, "mouseup", this.handleMouseUp, this, true);
1363 Event.on(document, "mousemove", this.handleMouseMove, this, true);
1364 Event.on(window, "unload", this._onUnload, this, true);
1365 Event.on(window, "resize", this._onResize, this, true);
1366 // Event.on(window, "mouseout", this._test);
1371 * Reset constraints on all drag and drop objs
1376 _onResize: function(e) {
1377 this._execOnAll("resetConstraints", []);
1381 * Lock all drag and drop functionality
1385 lock: function() { this.locked = true; },
1388 * Unlock all drag and drop functionality
1392 unlock: function() { this.locked = false; },
1395 * Is drag and drop locked?
1397 * @return {boolean} True if drag and drop is locked, false otherwise.
1400 isLocked: function() { return this.locked; },
1403 * Location cache that is set for all drag drop objects when a drag is
1404 * initiated, cleared when the drag is finished.
1405 * @property locationCache
1412 * Set useCache to false if you want to force object the lookup of each
1413 * drag and drop linked element constantly during a drag.
1414 * @property useCache
1421 * The number of pixels that the mouse needs to move after the
1422 * mousedown before the drag is initiated. Default=3;
1423 * @property clickPixelThresh
1427 clickPixelThresh: 3,
1430 * The number of milliseconds after the mousedown event to initiate the
1431 * drag if we don't get a mouseup event. Default=1000
1432 * @property clickTimeThresh
1436 clickTimeThresh: 350,
1439 * Flag that indicates that either the drag pixel threshold or the
1440 * mousdown time threshold has been met
1441 * @property dragThreshMet
1446 dragThreshMet: false,
1449 * Timeout used for the click time threshold
1450 * @property clickTimeout
1458 * The X position of the mousedown event stored for later use when a
1459 * drag threshold is met.
1468 * The Y position of the mousedown event stored for later use when a
1469 * drag threshold is met.
1478 * Each DragDrop instance must be registered with the DragDropMgr.
1479 * This is executed in DragDrop.init()
1480 * @method regDragDrop
1481 * @param {DragDrop} oDD the DragDrop object to register
1482 * @param {String} sGroup the name of the group this element belongs to
1485 regDragDrop: function(oDD, sGroup) {
1486 if (!this.initialized) { this.init(); }
1488 if (!this.ids[sGroup]) {
1489 this.ids[sGroup] = {};
1491 this.ids[sGroup][oDD.id] = oDD;
1495 * Removes the supplied dd instance from the supplied group. Executed
1496 * by DragDrop.removeFromGroup, so don't call this function directly.
1497 * @method removeDDFromGroup
1501 removeDDFromGroup: function(oDD, sGroup) {
1502 if (!this.ids[sGroup]) {
1503 this.ids[sGroup] = {};
1506 var obj = this.ids[sGroup];
1507 if (obj && obj[oDD.id]) {
1513 * Unregisters a drag and drop item. This is executed in
1514 * DragDrop.unreg, use that method instead of calling this directly.
1519 _remove: function(oDD) {
1520 for (var g in oDD.groups) {
1521 if (g && this.ids[g][oDD.id]) {
1522 delete this.ids[g][oDD.id];
1525 delete this.handleIds[oDD.id];
1529 * Each DragDrop handle element must be registered. This is done
1530 * automatically when executing DragDrop.setHandleElId()
1532 * @param {String} sDDId the DragDrop id this element is a handle for
1533 * @param {String} sHandleId the id of the element that is the drag
1537 regHandle: function(sDDId, sHandleId) {
1538 if (!this.handleIds[sDDId]) {
1539 this.handleIds[sDDId] = {};
1541 this.handleIds[sDDId][sHandleId] = sHandleId;
1545 * Utility function to determine if a given element has been
1546 * registered as a drag drop item.
1547 * @method isDragDrop
1548 * @param {String} id the element id to check
1549 * @return {boolean} true if this element is a DragDrop item,
1553 isDragDrop: function(id) {
1554 return ( this.getDDById(id) ) ? true : false;
1558 * Returns the drag and drop instances that are in all groups the
1559 * passed in instance belongs to.
1560 * @method getRelated
1561 * @param {DragDrop} p_oDD the obj to get related data for
1562 * @param {boolean} bTargetsOnly if true, only return targetable objs
1563 * @return {DragDrop[]} the related instances
1566 getRelated: function(p_oDD, bTargetsOnly) {
1568 for (var i in p_oDD.groups) {
1569 for (j in this.ids[i]) {
1570 var dd = this.ids[i][j];
1571 if (! this.isTypeOfDD(dd)) {
1574 if (!bTargetsOnly || dd.isTarget) {
1575 oDDs[oDDs.length] = dd;
1584 * Returns true if the specified dd target is a legal target for
1585 * the specifice drag obj
1586 * @method isLegalTarget
1587 * @param {DragDrop} the drag obj
1588 * @param {DragDrop} the target
1589 * @return {boolean} true if the target is a legal target for the
1593 isLegalTarget: function (oDD, oTargetDD) {
1594 var targets = this.getRelated(oDD, true);
1595 for (var i=0, len=targets.length;i<len;++i) {
1596 if (targets[i].id == oTargetDD.id) {
1605 * My goal is to be able to transparently determine if an object is
1606 * typeof DragDrop, and the exact subclass of DragDrop. typeof
1607 * returns "object", oDD.constructor.toString() always returns
1608 * "DragDrop" and not the name of the subclass. So for now it just
1609 * evaluates a well-known variable in DragDrop.
1610 * @method isTypeOfDD
1611 * @param {Object} the object to evaluate
1612 * @return {boolean} true if typeof oDD = DragDrop
1615 isTypeOfDD: function (oDD) {
1616 return (oDD && oDD.__ygDragDrop);
1620 * Utility function to determine if a given element has been
1621 * registered as a drag drop handle for the given Drag Drop object.
1623 * @param {String} id the element id to check
1624 * @return {boolean} true if this element is a DragDrop handle, false
1628 isHandle: function(sDDId, sHandleId) {
1629 return ( this.handleIds[sDDId] &&
1630 this.handleIds[sDDId][sHandleId] );
1634 * Returns the DragDrop instance for a given id
1636 * @param {String} id the id of the DragDrop object
1637 * @return {DragDrop} the drag drop object, null if it is not found
1640 getDDById: function(id) {
1641 for (var i in this.ids) {
1642 if (this.ids[i][id]) {
1643 return this.ids[i][id];
1650 * Fired after a registered DragDrop object gets the mousedown event.
1651 * Sets up the events required to track the object being dragged
1652 * @method handleMouseDown
1653 * @param {Event} e the event
1654 * @param oDD the DragDrop object being dragged
1658 handleMouseDown: function(e, oDD) {
1660 Roo.QuickTips.disable();
1662 this.currentTarget = e.getTarget();
1664 this.dragCurrent = oDD;
1666 var el = oDD.getEl();
1668 // track start position
1669 this.startX = e.getPageX();
1670 this.startY = e.getPageY();
1672 this.deltaX = this.startX - el.offsetLeft;
1673 this.deltaY = this.startY - el.offsetTop;
1675 this.dragThreshMet = false;
1677 this.clickTimeout = setTimeout(
1679 var DDM = Roo.dd.DDM;
1680 DDM.startDrag(DDM.startX, DDM.startY);
1682 this.clickTimeThresh );
1686 * Fired when either the drag pixel threshol or the mousedown hold
1687 * time threshold has been met.
1689 * @param x {int} the X position of the original mousedown
1690 * @param y {int} the Y position of the original mousedown
1693 startDrag: function(x, y) {
1694 clearTimeout(this.clickTimeout);
1695 if (this.dragCurrent) {
1696 this.dragCurrent.b4StartDrag(x, y);
1697 this.dragCurrent.startDrag(x, y);
1699 this.dragThreshMet = true;
1703 * Internal function to handle the mouseup event. Will be invoked
1704 * from the context of the document.
1705 * @method handleMouseUp
1706 * @param {Event} e the event
1710 handleMouseUp: function(e) {
1713 Roo.QuickTips.enable();
1715 if (! this.dragCurrent) {
1719 clearTimeout(this.clickTimeout);
1721 if (this.dragThreshMet) {
1722 this.fireEvents(e, true);
1732 * Utility to stop event propagation and event default, if these
1733 * features are turned on.
1735 * @param {Event} e the event as returned by this.getEvent()
1738 stopEvent: function(e){
1739 if(this.stopPropagation) {
1740 e.stopPropagation();
1743 if (this.preventDefault) {
1749 * Internal function to clean up event handlers after the drag
1750 * operation is complete
1752 * @param {Event} e the event
1756 stopDrag: function(e) {
1757 // Fire the drag end event for the item that was dragged
1758 if (this.dragCurrent) {
1759 if (this.dragThreshMet) {
1760 this.dragCurrent.b4EndDrag(e);
1761 this.dragCurrent.endDrag(e);
1764 this.dragCurrent.onMouseUp(e);
1767 this.dragCurrent = null;
1768 this.dragOvers = {};
1772 * Internal function to handle the mousemove event. Will be invoked
1773 * from the context of the html element.
1775 * @TODO figure out what we can do about mouse events lost when the
1776 * user drags objects beyond the window boundary. Currently we can
1777 * detect this in internet explorer by verifying that the mouse is
1778 * down during the mousemove event. Firefox doesn't give us the
1779 * button state on the mousemove event.
1780 * @method handleMouseMove
1781 * @param {Event} e the event
1785 handleMouseMove: function(e) {
1786 if (! this.dragCurrent) {
1790 // var button = e.which || e.button;
1792 // check for IE mouseup outside of page boundary
1793 if (Roo.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
1795 return this.handleMouseUp(e);
1798 if (!this.dragThreshMet) {
1799 var diffX = Math.abs(this.startX - e.getPageX());
1800 var diffY = Math.abs(this.startY - e.getPageY());
1801 if (diffX > this.clickPixelThresh ||
1802 diffY > this.clickPixelThresh) {
1803 this.startDrag(this.startX, this.startY);
1807 if (this.dragThreshMet) {
1808 this.dragCurrent.b4Drag(e);
1809 this.dragCurrent.onDrag(e);
1810 if(!this.dragCurrent.moveOnly){
1811 this.fireEvents(e, false);
1821 * Iterates over all of the DragDrop elements to find ones we are
1822 * hovering over or dropping on
1823 * @method fireEvents
1824 * @param {Event} e the event
1825 * @param {boolean} isDrop is this a drop op or a mouseover op?
1829 fireEvents: function(e, isDrop) {
1830 var dc = this.dragCurrent;
1832 // If the user did the mouse up outside of the window, we could
1833 // get here even though we have ended the drag.
1834 if (!dc || dc.isLocked()) {
1838 var pt = e.getPoint();
1840 // cache the previous dragOver array
1848 // Check to see if the object(s) we were hovering over is no longer
1849 // being hovered over so we can fire the onDragOut event
1850 for (var i in this.dragOvers) {
1852 var ddo = this.dragOvers[i];
1854 if (! this.isTypeOfDD(ddo)) {
1858 if (! this.isOverTarget(pt, ddo, this.mode)) {
1859 outEvts.push( ddo );
1863 delete this.dragOvers[i];
1866 for (var sGroup in dc.groups) {
1868 if ("string" != typeof sGroup) {
1872 for (i in this.ids[sGroup]) {
1873 var oDD = this.ids[sGroup][i];
1874 if (! this.isTypeOfDD(oDD)) {
1878 if (oDD.isTarget && !oDD.isLocked() && oDD != dc) {
1879 if (this.isOverTarget(pt, oDD, this.mode)) {
1880 // look for drop interactions
1882 dropEvts.push( oDD );
1883 // look for drag enter and drag over interactions
1886 // initial drag over: dragEnter fires
1887 if (!oldOvers[oDD.id]) {
1888 enterEvts.push( oDD );
1889 // subsequent drag overs: dragOver fires
1891 overEvts.push( oDD );
1894 this.dragOvers[oDD.id] = oDD;
1902 if (outEvts.length) {
1903 dc.b4DragOut(e, outEvts);
1904 dc.onDragOut(e, outEvts);
1907 if (enterEvts.length) {
1908 dc.onDragEnter(e, enterEvts);
1911 if (overEvts.length) {
1912 dc.b4DragOver(e, overEvts);
1913 dc.onDragOver(e, overEvts);
1916 if (dropEvts.length) {
1917 dc.b4DragDrop(e, dropEvts);
1918 dc.onDragDrop(e, dropEvts);
1922 // fire dragout events
1924 for (i=0, len=outEvts.length; i<len; ++i) {
1925 dc.b4DragOut(e, outEvts[i].id);
1926 dc.onDragOut(e, outEvts[i].id);
1929 // fire enter events
1930 for (i=0,len=enterEvts.length; i<len; ++i) {
1931 // dc.b4DragEnter(e, oDD.id);
1932 dc.onDragEnter(e, enterEvts[i].id);
1936 for (i=0,len=overEvts.length; i<len; ++i) {
1937 dc.b4DragOver(e, overEvts[i].id);
1938 dc.onDragOver(e, overEvts[i].id);
1942 for (i=0, len=dropEvts.length; i<len; ++i) {
1943 dc.b4DragDrop(e, dropEvts[i].id);
1944 dc.onDragDrop(e, dropEvts[i].id);
1949 // notify about a drop that did not find a target
1950 if (isDrop && !dropEvts.length) {
1951 dc.onInvalidDrop(e);
1957 * Helper function for getting the best match from the list of drag
1958 * and drop objects returned by the drag and drop events when we are
1959 * in INTERSECT mode. It returns either the first object that the
1960 * cursor is over, or the object that has the greatest overlap with
1961 * the dragged element.
1962 * @method getBestMatch
1963 * @param {DragDrop[]} dds The array of drag and drop objects
1965 * @return {DragDrop} The best single match
1968 getBestMatch: function(dds) {
1970 // Return null if the input is not what we expect
1971 //if (!dds || !dds.length || dds.length == 0) {
1973 // If there is only one item, it wins
1974 //} else if (dds.length == 1) {
1976 var len = dds.length;
1981 // Loop through the targeted items
1982 for (var i=0; i<len; ++i) {
1984 // If the cursor is over the object, it wins. If the
1985 // cursor is over multiple matches, the first one we come
1987 if (dd.cursorIsOver) {
1990 // Otherwise the object with the most overlap wins
1993 winner.overlap.getArea() < dd.overlap.getArea()) {
2004 * Refreshes the cache of the top-left and bottom-right points of the
2005 * drag and drop objects in the specified group(s). This is in the
2006 * format that is stored in the drag and drop instance, so typical
2009 * Roo.dd.DragDropMgr.refreshCache(ddinstance.groups);
2013 * Roo.dd.DragDropMgr.refreshCache({group1:true, group2:true});
2015 * @TODO this really should be an indexed array. Alternatively this
2016 * method could accept both.
2017 * @method refreshCache
2018 * @param {Object} groups an associative array of groups to refresh
2021 refreshCache: function(groups) {
2022 for (var sGroup in groups) {
2023 if ("string" != typeof sGroup) {
2026 for (var i in this.ids[sGroup]) {
2027 var oDD = this.ids[sGroup][i];
2029 if (this.isTypeOfDD(oDD)) {
2030 // if (this.isTypeOfDD(oDD) && oDD.isTarget) {
2031 var loc = this.getLocation(oDD);
2033 this.locationCache[oDD.id] = loc;
2035 delete this.locationCache[oDD.id];
2036 // this will unregister the drag and drop object if
2037 // the element is not in a usable state
2046 * This checks to make sure an element exists and is in the DOM. The
2047 * main purpose is to handle cases where innerHTML is used to remove
2048 * drag and drop objects from the DOM. IE provides an 'unspecified
2049 * error' when trying to access the offsetParent of such an element
2051 * @param {HTMLElement} el the element to check
2052 * @return {boolean} true if the element looks usable
2055 verifyEl: function(el) {
2060 parent = el.offsetParent;
2063 parent = el.offsetParent;
2074 * Returns a Region object containing the drag and drop element's position
2075 * and size, including the padding configured for it
2076 * @method getLocation
2077 * @param {DragDrop} oDD the drag and drop object to get the
2079 * @return {Roo.lib.Region} a Region object representing the total area
2080 * the element occupies, including any padding
2081 * the instance is configured for.
2084 getLocation: function(oDD) {
2085 if (! this.isTypeOfDD(oDD)) {
2089 var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l;
2092 pos= Roo.lib.Dom.getXY(el);
2100 x2 = x1 + el.offsetWidth;
2102 y2 = y1 + el.offsetHeight;
2104 t = y1 - oDD.padding[0];
2105 r = x2 + oDD.padding[1];
2106 b = y2 + oDD.padding[2];
2107 l = x1 - oDD.padding[3];
2109 return new Roo.lib.Region( t, r, b, l );
2113 * Checks the cursor location to see if it over the target
2114 * @method isOverTarget
2115 * @param {Roo.lib.Point} pt The point to evaluate
2116 * @param {DragDrop} oTarget the DragDrop object we are inspecting
2117 * @return {boolean} true if the mouse is over the target
2121 isOverTarget: function(pt, oTarget, intersect) {
2122 // use cache if available
2123 var loc = this.locationCache[oTarget.id];
2124 if (!loc || !this.useCache) {
2125 loc = this.getLocation(oTarget);
2126 this.locationCache[oTarget.id] = loc;
2134 oTarget.cursorIsOver = loc.contains( pt );
2136 // DragDrop is using this as a sanity check for the initial mousedown
2137 // in this case we are done. In POINT mode, if the drag obj has no
2138 // contraints, we are also done. Otherwise we need to evaluate the
2139 // location of the target as related to the actual location of the
2141 var dc = this.dragCurrent;
2142 if (!dc || !dc.getTargetCoord ||
2143 (!intersect && !dc.constrainX && !dc.constrainY)) {
2144 return oTarget.cursorIsOver;
2147 oTarget.overlap = null;
2149 // Get the current location of the drag element, this is the
2150 // location of the mouse event less the delta that represents
2151 // where the original mousedown happened on the element. We
2152 // need to consider constraints and ticks as well.
2153 var pos = dc.getTargetCoord(pt.x, pt.y);
2155 var el = dc.getDragEl();
2156 var curRegion = new Roo.lib.Region( pos.y,
2157 pos.x + el.offsetWidth,
2158 pos.y + el.offsetHeight,
2161 var overlap = curRegion.intersect(loc);
2164 oTarget.overlap = overlap;
2165 return (intersect) ? true : oTarget.cursorIsOver;
2172 * unload event handler
2177 _onUnload: function(e, me) {
2178 Roo.dd.DragDropMgr.unregAll();
2182 * Cleans up the drag and drop events and objects.
2187 unregAll: function() {
2189 if (this.dragCurrent) {
2191 this.dragCurrent = null;
2194 this._execOnAll("unreg", []);
2196 for (i in this.elementCache) {
2197 delete this.elementCache[i];
2200 this.elementCache = {};
2205 * A cache of DOM elements
2206 * @property elementCache
2213 * Get the wrapper for the DOM element specified
2214 * @method getElWrapper
2215 * @param {String} id the id of the element to get
2216 * @return {Roo.dd.DDM.ElementWrapper} the wrapped element
2218 * @deprecated This wrapper isn't that useful
2221 getElWrapper: function(id) {
2222 var oWrapper = this.elementCache[id];
2223 if (!oWrapper || !oWrapper.el) {
2224 oWrapper = this.elementCache[id] =
2225 new this.ElementWrapper(Roo.getDom(id));
2231 * Returns the actual DOM element
2232 * @method getElement
2233 * @param {String} id the id of the elment to get
2234 * @return {Object} The element
2235 * @deprecated use Roo.getDom instead
2238 getElement: function(id) {
2239 return Roo.getDom(id);
2243 * Returns the style property for the DOM element (i.e.,
2244 * document.getElById(id).style)
2246 * @param {String} id the id of the elment to get
2247 * @return {Object} The style property of the element
2248 * @deprecated use Roo.getDom instead
2251 getCss: function(id) {
2252 var el = Roo.getDom(id);
2253 return (el) ? el.style : null;
2257 * Inner class for cached elements
2258 * @class DragDropMgr.ElementWrapper
2263 ElementWrapper: function(el) {
2268 this.el = el || null;
2273 this.id = this.el && el.id;
2275 * A reference to the style property
2278 this.css = this.el && el.style;
2282 * Returns the X position of an html element
2284 * @param el the element for which to get the position
2285 * @return {int} the X coordinate
2287 * @deprecated use Roo.lib.Dom.getX instead
2290 getPosX: function(el) {
2291 return Roo.lib.Dom.getX(el);
2295 * Returns the Y position of an html element
2297 * @param el the element for which to get the position
2298 * @return {int} the Y coordinate
2299 * @deprecated use Roo.lib.Dom.getY instead
2302 getPosY: function(el) {
2303 return Roo.lib.Dom.getY(el);
2307 * Swap two nodes. In IE, we use the native method, for others we
2308 * emulate the IE behavior
2310 * @param n1 the first node to swap
2311 * @param n2 the other node to swap
2314 swapNode: function(n1, n2) {
2318 var p = n2.parentNode;
2319 var s = n2.nextSibling;
2322 p.insertBefore(n1, n2);
2323 } else if (n2 == n1.nextSibling) {
2324 p.insertBefore(n2, n1);
2326 n1.parentNode.replaceChild(n2, n1);
2327 p.insertBefore(n1, s);
2333 * Returns the current scroll position
2338 getScroll: function () {
2339 var t, l, dde=document.documentElement, db=document.body;
2340 if (dde && (dde.scrollTop || dde.scrollLeft)) {
2349 return { top: t, left: l };
2353 * Returns the specified element style property
2355 * @param {HTMLElement} el the element
2356 * @param {string} styleProp the style property
2357 * @return {string} The value of the style property
2358 * @deprecated use Roo.lib.Dom.getStyle
2361 getStyle: function(el, styleProp) {
2362 return Roo.fly(el).getStyle(styleProp);
2366 * Gets the scrollTop
2367 * @method getScrollTop
2368 * @return {int} the document's scrollTop
2371 getScrollTop: function () { return this.getScroll().top; },
2374 * Gets the scrollLeft
2375 * @method getScrollLeft
2376 * @return {int} the document's scrollTop
2379 getScrollLeft: function () { return this.getScroll().left; },
2382 * Sets the x/y position of an element to the location of the
2385 * @param {HTMLElement} moveEl The element to move
2386 * @param {HTMLElement} targetEl The position reference element
2389 moveToEl: function (moveEl, targetEl) {
2390 var aCoord = Roo.lib.Dom.getXY(targetEl);
2391 Roo.lib.Dom.setXY(moveEl, aCoord);
2395 * Numeric array sort function
2396 * @method numericSort
2399 numericSort: function(a, b) { return (a - b); },
2403 * @property _timeoutCount
2410 * Trying to make the load order less important. Without this we get
2411 * an error if this file is loaded before the Event Utility.
2412 * @method _addListeners
2416 _addListeners: function() {
2417 var DDM = Roo.dd.DDM;
2418 if ( Roo.lib.Event && document ) {
2421 if (DDM._timeoutCount > 2000) {
2423 setTimeout(DDM._addListeners, 10);
2424 if (document && document.body) {
2425 DDM._timeoutCount += 1;
2432 * Recursively searches the immediate parent and all child nodes for
2433 * the handle element in order to determine wheter or not it was
2435 * @method handleWasClicked
2436 * @param node the html element to inspect
2439 handleWasClicked: function(node, id) {
2440 if (this.isHandle(id, node.id)) {
2443 // check to see if this is a text node child of the one we want
2444 var p = node.parentNode;
2447 if (this.isHandle(id, p.id)) {
2462 // shorter alias, save a few bytes
2463 Roo.dd.DDM = Roo.dd.DragDropMgr;
2464 Roo.dd.DDM._addListeners();
2468 * Ext JS Library 1.1.1
2469 * Copyright(c) 2006-2007, Ext JS, LLC.
2471 * Originally Released Under LGPL - original licence link has changed is not relivant.
2474 * <script type="text/javascript">
2479 * A DragDrop implementation where the linked element follows the
2480 * mouse cursor during a drag.
2481 * @extends Roo.dd.DragDrop
2483 * @param {String} id the id of the linked element
2484 * @param {String} sGroup the group of related DragDrop items
2485 * @param {object} config an object containing configurable attributes
2486 * Valid properties for DD:
2489 Roo.dd.DD = function(id, sGroup, config) {
2491 this.init(id, sGroup, config);
2495 Roo.extend(Roo.dd.DD, Roo.dd.DragDrop, {
2498 * When set to true, the utility automatically tries to scroll the browser
2499 * window wehn a drag and drop element is dragged near the viewport boundary.
2507 * Sets the pointer offset to the distance between the linked element's top
2508 * left corner and the location the element was clicked
2509 * @method autoOffset
2510 * @param {int} iPageX the X coordinate of the click
2511 * @param {int} iPageY the Y coordinate of the click
2513 autoOffset: function(iPageX, iPageY) {
2514 var x = iPageX - this.startPageX;
2515 var y = iPageY - this.startPageY;
2516 this.setDelta(x, y);
2520 * Sets the pointer offset. You can call this directly to force the
2521 * offset to be in a particular location (e.g., pass in 0,0 to set it
2522 * to the center of the object)
2524 * @param {int} iDeltaX the distance from the left
2525 * @param {int} iDeltaY the distance from the top
2527 setDelta: function(iDeltaX, iDeltaY) {
2528 this.deltaX = iDeltaX;
2529 this.deltaY = iDeltaY;
2533 * Sets the drag element to the location of the mousedown or click event,
2534 * maintaining the cursor location relative to the location on the element
2535 * that was clicked. Override this if you want to place the element in a
2536 * location other than where the cursor is.
2537 * @method setDragElPos
2538 * @param {int} iPageX the X coordinate of the mousedown or drag event
2539 * @param {int} iPageY the Y coordinate of the mousedown or drag event
2541 setDragElPos: function(iPageX, iPageY) {
2542 // the first time we do this, we are going to check to make sure
2543 // the element has css positioning
2545 var el = this.getDragEl();
2546 this.alignElWithMouse(el, iPageX, iPageY);
2550 * Sets the element to the location of the mousedown or click event,
2551 * maintaining the cursor location relative to the location on the element
2552 * that was clicked. Override this if you want to place the element in a
2553 * location other than where the cursor is.
2554 * @method alignElWithMouse
2555 * @param {HTMLElement} el the element to move
2556 * @param {int} iPageX the X coordinate of the mousedown or drag event
2557 * @param {int} iPageY the Y coordinate of the mousedown or drag event
2559 alignElWithMouse: function(el, iPageX, iPageY) {
2560 var oCoord = this.getTargetCoord(iPageX, iPageY);
2561 var fly = el.dom ? el : Roo.fly(el);
2562 if (!this.deltaSetXY) {
2563 var aCoord = [oCoord.x, oCoord.y];
2565 var newLeft = fly.getLeft(true);
2566 var newTop = fly.getTop(true);
2567 this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
2569 fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]);
2572 this.cachePosition(oCoord.x, oCoord.y);
2573 this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
2578 * Saves the most recent position so that we can reset the constraints and
2579 * tick marks on-demand. We need to know this so that we can calculate the
2580 * number of pixels the element is offset from its original position.
2581 * @method cachePosition
2582 * @param iPageX the current x position (optional, this just makes it so we
2583 * don't have to look it up again)
2584 * @param iPageY the current y position (optional, this just makes it so we
2585 * don't have to look it up again)
2587 cachePosition: function(iPageX, iPageY) {
2589 this.lastPageX = iPageX;
2590 this.lastPageY = iPageY;
2592 var aCoord = Roo.lib.Dom.getXY(this.getEl());
2593 this.lastPageX = aCoord[0];
2594 this.lastPageY = aCoord[1];
2599 * Auto-scroll the window if the dragged object has been moved beyond the
2600 * visible window boundary.
2601 * @method autoScroll
2602 * @param {int} x the drag element's x position
2603 * @param {int} y the drag element's y position
2604 * @param {int} h the height of the drag element
2605 * @param {int} w the width of the drag element
2608 autoScroll: function(x, y, h, w) {
2611 // The client height
2612 var clientH = Roo.lib.Dom.getViewWidth();
2615 var clientW = Roo.lib.Dom.getViewHeight();
2617 // The amt scrolled down
2618 var st = this.DDM.getScrollTop();
2620 // The amt scrolled right
2621 var sl = this.DDM.getScrollLeft();
2623 // Location of the bottom of the element
2626 // Location of the right of the element
2629 // The distance from the cursor to the bottom of the visible area,
2630 // adjusted so that we don't scroll if the cursor is beyond the
2631 // element drag constraints
2632 var toBot = (clientH + st - y - this.deltaY);
2634 // The distance from the cursor to the right of the visible area
2635 var toRight = (clientW + sl - x - this.deltaX);
2638 // How close to the edge the cursor must be before we scroll
2639 // var thresh = (document.all) ? 100 : 40;
2642 // How many pixels to scroll per autoscroll op. This helps to reduce
2643 // clunky scrolling. IE is more sensitive about this ... it needs this
2644 // value to be higher.
2645 var scrAmt = (document.all) ? 80 : 30;
2647 // Scroll down if we are near the bottom of the visible page and the
2648 // obj extends below the crease
2649 if ( bot > clientH && toBot < thresh ) {
2650 window.scrollTo(sl, st + scrAmt);
2653 // Scroll up if the window is scrolled down and the top of the object
2654 // goes above the top border
2655 if ( y < st && st > 0 && y - st < thresh ) {
2656 window.scrollTo(sl, st - scrAmt);
2659 // Scroll right if the obj is beyond the right border and the cursor is
2661 if ( right > clientW && toRight < thresh ) {
2662 window.scrollTo(sl + scrAmt, st);
2665 // Scroll left if the window has been scrolled to the right and the obj
2666 // extends past the left border
2667 if ( x < sl && sl > 0 && x - sl < thresh ) {
2668 window.scrollTo(sl - scrAmt, st);
2674 * Finds the location the element should be placed if we want to move
2675 * it to where the mouse location less the click offset would place us.
2676 * @method getTargetCoord
2677 * @param {int} iPageX the X coordinate of the click
2678 * @param {int} iPageY the Y coordinate of the click
2679 * @return an object that contains the coordinates (Object.x and Object.y)
2682 getTargetCoord: function(iPageX, iPageY) {
2685 var x = iPageX - this.deltaX;
2686 var y = iPageY - this.deltaY;
2688 if (this.constrainX) {
2689 if (x < this.minX) { x = this.minX; }
2690 if (x > this.maxX) { x = this.maxX; }
2693 if (this.constrainY) {
2694 if (y < this.minY) { y = this.minY; }
2695 if (y > this.maxY) { y = this.maxY; }
2698 x = this.getTick(x, this.xTicks);
2699 y = this.getTick(y, this.yTicks);
2706 * Sets up config options specific to this class. Overrides
2707 * Roo.dd.DragDrop, but all versions of this method through the
2708 * inheritance chain are called
2710 applyConfig: function() {
2711 Roo.dd.DD.superclass.applyConfig.call(this);
2712 this.scroll = (this.config.scroll !== false);
2716 * Event that fires prior to the onMouseDown event. Overrides
2719 b4MouseDown: function(e) {
2720 // this.resetConstraints();
2721 this.autoOffset(e.getPageX(),
2726 * Event that fires prior to the onDrag event. Overrides
2729 b4Drag: function(e) {
2730 this.setDragElPos(e.getPageX(),
2734 toString: function() {
2735 return ("DD " + this.id);
2738 //////////////////////////////////////////////////////////////////////////
2739 // Debugging ygDragDrop events that can be overridden
2740 //////////////////////////////////////////////////////////////////////////
2742 startDrag: function(x, y) {
2745 onDrag: function(e) {
2748 onDragEnter: function(e, id) {
2751 onDragOver: function(e, id) {
2754 onDragOut: function(e, id) {
2757 onDragDrop: function(e, id) {
2760 endDrag: function(e) {
2767 * Ext JS Library 1.1.1
2768 * Copyright(c) 2006-2007, Ext JS, LLC.
2770 * Originally Released Under LGPL - original licence link has changed is not relivant.
2773 * <script type="text/javascript">
2777 * @class Roo.dd.DDProxy
2778 * A DragDrop implementation that inserts an empty, bordered div into
2779 * the document that follows the cursor during drag operations. At the time of
2780 * the click, the frame div is resized to the dimensions of the linked html
2781 * element, and moved to the exact location of the linked element.
2783 * References to the "frame" element refer to the single proxy element that
2784 * was created to be dragged in place of all DDProxy elements on the
2787 * @extends Roo.dd.DD
2789 * @param {String} id the id of the linked html element
2790 * @param {String} sGroup the group of related DragDrop objects
2791 * @param {object} config an object containing configurable attributes
2792 * Valid properties for DDProxy in addition to those in DragDrop:
2793 * resizeFrame, centerFrame, dragElId
2795 Roo.dd.DDProxy = function(id, sGroup, config) {
2797 this.init(id, sGroup, config);
2803 * The default drag frame div id
2804 * @property Roo.dd.DDProxy.dragElId
2808 Roo.dd.DDProxy.dragElId = "ygddfdiv";
2810 Roo.extend(Roo.dd.DDProxy, Roo.dd.DD, {
2813 * By default we resize the drag frame to be the same size as the element
2814 * we want to drag (this is to get the frame effect). We can turn it off
2815 * if we want a different behavior.
2816 * @property resizeFrame
2822 * By default the frame is positioned exactly where the drag element is, so
2823 * we use the cursor offset provided by Roo.dd.DD. Another option that works only if
2824 * you do not have constraints on the obj is to have the drag frame centered
2825 * around the cursor. Set centerFrame to true for this effect.
2826 * @property centerFrame
2832 * Creates the proxy element if it does not yet exist
2833 * @method createFrame
2835 createFrame: function() {
2837 var body = document.body;
2839 if (!body || !body.firstChild) {
2840 setTimeout( function() { self.createFrame(); }, 50 );
2844 var div = this.getDragEl();
2847 div = document.createElement("div");
2848 div.id = this.dragElId;
2851 s.position = "absolute";
2852 s.visibility = "hidden";
2854 s.border = "2px solid #aaa";
2857 // appendChild can blow up IE if invoked prior to the window load event
2858 // while rendering a table. It is possible there are other scenarios
2859 // that would cause this to happen as well.
2860 body.insertBefore(div, body.firstChild);
2865 * Initialization for the drag frame element. Must be called in the
2866 * constructor of all subclasses
2869 initFrame: function() {
2873 applyConfig: function() {
2874 Roo.dd.DDProxy.superclass.applyConfig.call(this);
2876 this.resizeFrame = (this.config.resizeFrame !== false);
2877 this.centerFrame = (this.config.centerFrame);
2878 this.setDragElId(this.config.dragElId || Roo.dd.DDProxy.dragElId);
2882 * Resizes the drag frame to the dimensions of the clicked object, positions
2883 * it over the object, and finally displays it
2885 * @param {int} iPageX X click position
2886 * @param {int} iPageY Y click position
2889 showFrame: function(iPageX, iPageY) {
2890 var el = this.getEl();
2891 var dragEl = this.getDragEl();
2892 var s = dragEl.style;
2894 this._resizeProxy();
2896 if (this.centerFrame) {
2897 this.setDelta( Math.round(parseInt(s.width, 10)/2),
2898 Math.round(parseInt(s.height, 10)/2) );
2901 this.setDragElPos(iPageX, iPageY);
2903 Roo.fly(dragEl).show();
2907 * The proxy is automatically resized to the dimensions of the linked
2908 * element when a drag is initiated, unless resizeFrame is set to false
2909 * @method _resizeProxy
2912 _resizeProxy: function() {
2913 if (this.resizeFrame) {
2914 var el = this.getEl();
2915 Roo.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
2919 // overrides Roo.dd.DragDrop
2920 b4MouseDown: function(e) {
2921 var x = e.getPageX();
2922 var y = e.getPageY();
2923 this.autoOffset(x, y);
2924 this.setDragElPos(x, y);
2927 // overrides Roo.dd.DragDrop
2928 b4StartDrag: function(x, y) {
2929 // show the drag frame
2930 this.showFrame(x, y);
2933 // overrides Roo.dd.DragDrop
2934 b4EndDrag: function(e) {
2935 Roo.fly(this.getDragEl()).hide();
2938 // overrides Roo.dd.DragDrop
2939 // By default we try to move the element to the last location of the frame.
2940 // This is so that the default behavior mirrors that of Roo.dd.DD.
2941 endDrag: function(e) {
2943 var lel = this.getEl();
2944 var del = this.getDragEl();
2946 // Show the drag frame briefly so we can get its position
2947 del.style.visibility = "";
2950 // Hide the linked element before the move to get around a Safari
2952 lel.style.visibility = "hidden";
2953 Roo.dd.DDM.moveToEl(lel, del);
2954 del.style.visibility = "hidden";
2955 lel.style.visibility = "";
2960 beforeMove : function(){
2964 afterDrag : function(){
2968 toString: function() {
2969 return ("DDProxy " + this.id);
2975 * Ext JS Library 1.1.1
2976 * Copyright(c) 2006-2007, Ext JS, LLC.
2978 * Originally Released Under LGPL - original licence link has changed is not relivant.
2981 * <script type="text/javascript">
2985 * @class Roo.dd.DDTarget
2986 * A DragDrop implementation that does not move, but can be a drop
2987 * target. You would get the same result by simply omitting implementation
2988 * for the event callbacks, but this way we reduce the processing cost of the
2989 * event listener and the callbacks.
2990 * @extends Roo.dd.DragDrop
2992 * @param {String} id the id of the element that is a drop target
2993 * @param {String} sGroup the group of related DragDrop objects
2994 * @param {object} config an object containing configurable attributes
2995 * Valid properties for DDTarget in addition to those in
2999 Roo.dd.DDTarget = function(id, sGroup, config) {
3001 this.initTarget(id, sGroup, config);
3005 // Roo.dd.DDTarget.prototype = new Roo.dd.DragDrop();
3006 Roo.extend(Roo.dd.DDTarget, Roo.dd.DragDrop, {
3007 toString: function() {
3008 return ("DDTarget " + this.id);
3013 * Ext JS Library 1.1.1
3014 * Copyright(c) 2006-2007, Ext JS, LLC.
3016 * Originally Released Under LGPL - original licence link has changed is not relivant.
3019 * <script type="text/javascript">
3024 * @class Roo.dd.ScrollManager
3025 * Provides automatic scrolling of overflow regions in the page during drag operations.<br><br>
3026 * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
3029 Roo.dd.ScrollManager = function(){
3030 var ddm = Roo.dd.DragDropMgr;
3035 var onStop = function(e){
3040 var triggerRefresh = function(){
3041 if(ddm.dragCurrent){
3042 ddm.refreshCache(ddm.dragCurrent.groups);
3046 var doScroll = function(){
3047 if(ddm.dragCurrent){
3048 var dds = Roo.dd.ScrollManager;
3050 if(proc.el.scroll(proc.dir, dds.increment)){
3054 proc.el.scroll(proc.dir, dds.increment, true, dds.animDuration, triggerRefresh);
3059 var clearProc = function(){
3061 clearInterval(proc.id);
3068 var startProc = function(el, dir){
3072 proc.id = setInterval(doScroll, Roo.dd.ScrollManager.frequency);
3075 var onFire = function(e, isDrop){
3076 if(isDrop || !ddm.dragCurrent){ return; }
3077 var dds = Roo.dd.ScrollManager;
3078 if(!dragEl || dragEl != ddm.dragCurrent){
3079 dragEl = ddm.dragCurrent;
3080 // refresh regions on drag start
3084 var xy = Roo.lib.Event.getXY(e);
3085 var pt = new Roo.lib.Point(xy[0], xy[1]);
3087 var el = els[id], r = el._region;
3088 if(r && r.contains(pt) && el.isScrollable()){
3089 if(r.bottom - pt.y <= dds.thresh){
3091 startProc(el, "down");
3094 }else if(r.right - pt.x <= dds.thresh){
3096 startProc(el, "left");
3099 }else if(pt.y - r.top <= dds.thresh){
3101 startProc(el, "up");
3104 }else if(pt.x - r.left <= dds.thresh){
3106 startProc(el, "right");
3115 ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
3116 ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
3120 * Registers new overflow element(s) to auto scroll
3121 * @param {String/HTMLElement/Element/Array} el The id of or the element to be scrolled or an array of either
3123 register : function(el){
3124 if(el instanceof Array){
3125 for(var i = 0, len = el.length; i < len; i++) {
3126 this.register(el[i]);
3135 * Unregisters overflow element(s) so they are no longer scrolled
3136 * @param {String/HTMLElement/Element/Array} el The id of or the element to be removed or an array of either
3138 unregister : function(el){
3139 if(el instanceof Array){
3140 for(var i = 0, len = el.length; i < len; i++) {
3141 this.unregister(el[i]);
3150 * The number of pixels from the edge of a container the pointer needs to be to
3151 * trigger scrolling (defaults to 25)
3157 * The number of pixels to scroll in each scroll increment (defaults to 50)
3163 * The frequency of scrolls in milliseconds (defaults to 500)
3169 * True to animate the scroll (defaults to true)
3175 * The animation duration in seconds -
3176 * MUST BE less than Roo.dd.ScrollManager.frequency! (defaults to .4)
3182 * Manually trigger a cache refresh.
3184 refreshCache : function(){
3186 if(typeof els[id] == 'object'){ // for people extending the object prototype
3187 els[id]._region = els[id].getRegion();
3194 * Ext JS Library 1.1.1
3195 * Copyright(c) 2006-2007, Ext JS, LLC.
3197 * Originally Released Under LGPL - original licence link has changed is not relivant.
3200 * <script type="text/javascript">
3205 * @class Roo.dd.Registry
3206 * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
3207 * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
3210 Roo.dd.Registry = function(){
3215 var getId = function(el, autogen){
3216 if(typeof el == "string"){
3220 if(!id && autogen !== false){
3221 id = "roodd-" + (++autoIdSeed);
3229 * Register a drag drop element
3230 * @param {String|HTMLElement} element The id or DOM node to register
3231 * @param {Object} data (optional) A custom data object that will be passed between the elements that are involved
3232 * in drag drop operations. You can populate this object with any arbitrary properties that your own code
3233 * knows how to interpret, plus there are some specific properties known to the Registry that should be
3234 * populated in the data object (if applicable):
3236 Value Description<br />
3237 --------- ------------------------------------------<br />
3238 handles Array of DOM nodes that trigger dragging<br />
3239 for the element being registered<br />
3240 isHandle True if the element passed in triggers<br />
3241 dragging itself, else false
3244 register : function(el, data){
3246 if(typeof el == "string"){
3247 el = document.getElementById(el);
3250 elements[getId(el)] = data;
3251 if(data.isHandle !== false){
3252 handles[data.ddel.id] = data;
3255 var hs = data.handles;
3256 for(var i = 0, len = hs.length; i < len; i++){
3257 handles[getId(hs[i])] = data;
3263 * Unregister a drag drop element
3264 * @param {String|HTMLElement} element The id or DOM node to unregister
3266 unregister : function(el){
3267 var id = getId(el, false);
3268 var data = elements[id];
3270 delete elements[id];
3272 var hs = data.handles;
3273 for(var i = 0, len = hs.length; i < len; i++){
3274 delete handles[getId(hs[i], false)];
3281 * Returns the handle registered for a DOM Node by id
3282 * @param {String|HTMLElement} id The DOM node or id to look up
3283 * @return {Object} handle The custom handle data
3285 getHandle : function(id){
3286 if(typeof id != "string"){ // must be element?
3293 * Returns the handle that is registered for the DOM node that is the target of the event
3294 * @param {Event} e The event
3295 * @return {Object} handle The custom handle data
3297 getHandleFromEvent : function(e){
3298 var t = Roo.lib.Event.getTarget(e);
3299 return t ? handles[t.id] : null;
3303 * Returns a custom data object that is registered for a DOM node by id
3304 * @param {String|HTMLElement} id The DOM node or id to look up
3305 * @return {Object} data The custom data
3307 getTarget : function(id){
3308 if(typeof id != "string"){ // must be element?
3311 return elements[id];
3315 * Returns a custom data object that is registered for the DOM node that is the target of the event
3316 * @param {Event} e The event
3317 * @return {Object} data The custom data
3319 getTargetFromEvent : function(e){
3320 var t = Roo.lib.Event.getTarget(e);
3321 return t ? elements[t.id] || handles[t.id] : null;
3326 * Ext JS Library 1.1.1
3327 * Copyright(c) 2006-2007, Ext JS, LLC.
3329 * Originally Released Under LGPL - original licence link has changed is not relivant.
3332 * <script type="text/javascript">
3337 * @class Roo.dd.StatusProxy
3338 * A specialized drag proxy that supports a drop status icon, {@link Roo.Layer} styles and auto-repair. This is the
3339 * default drag proxy used by all Roo.dd components.
3341 * @param {Object} config
3343 Roo.dd.StatusProxy = function(config){
3344 Roo.apply(this, config);
3345 this.id = this.id || Roo.id();
3346 this.el = new Roo.Layer({
3348 id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
3349 {tag: "div", cls: "x-dd-drop-icon"},
3350 {tag: "div", cls: "x-dd-drag-ghost"}
3353 shadow: !config || config.shadow !== false
3355 this.ghost = Roo.get(this.el.dom.childNodes[1]);
3356 this.dropStatus = this.dropNotAllowed;
3359 Roo.dd.StatusProxy.prototype = {
3361 * @cfg {String} dropAllowed
3362 * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").
3364 dropAllowed : "x-dd-drop-ok",
3366 * @cfg {String} dropNotAllowed
3367 * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").
3369 dropNotAllowed : "x-dd-drop-nodrop",
3372 * Updates the proxy's visual element to indicate the status of whether or not drop is allowed
3373 * over the current target element.
3374 * @param {String} cssClass The css class for the new drop status indicator image
3376 setStatus : function(cssClass){
3377 cssClass = cssClass || this.dropNotAllowed;
3378 if(this.dropStatus != cssClass){
3379 this.el.replaceClass(this.dropStatus, cssClass);
3380 this.dropStatus = cssClass;
3385 * Resets the status indicator to the default dropNotAllowed value
3386 * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
3388 reset : function(clearGhost){
3389 this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
3390 this.dropStatus = this.dropNotAllowed;
3392 this.ghost.update("");
3397 * Updates the contents of the ghost element
3398 * @param {String} html The html that will replace the current innerHTML of the ghost element
3400 update : function(html){
3401 if(typeof html == "string"){
3402 this.ghost.update(html);
3404 this.ghost.update("");
3405 html.style.margin = "0";
3406 this.ghost.dom.appendChild(html);
3408 // ensure float = none set?? cant remember why though.
3409 var el = this.ghost.dom.firstChild;
3411 Roo.fly(el).setStyle('float', 'none');
3416 * Returns the underlying proxy {@link Roo.Layer}
3417 * @return {Roo.Layer} el
3424 * Returns the ghost element
3425 * @return {Roo.Element} el
3427 getGhost : function(){
3433 * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them
3435 hide : function(clear){
3443 * Stops the repair animation if it's currently running
3446 if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){
3452 * Displays this proxy
3459 * Force the Layer to sync its shadow and shim positions to the element
3466 * Causes the proxy to return to its position of origin via an animation. Should be called after an
3467 * invalid drop operation by the item being dragged.
3468 * @param {Array} xy The XY position of the element ([x, y])
3469 * @param {Function} callback The function to call after the repair is complete
3470 * @param {Object} scope The scope in which to execute the callback
3472 repair : function(xy, callback, scope){
3473 this.callback = callback;
3475 if(xy && this.animRepair !== false){
3476 this.el.addClass("x-dd-drag-repair");
3477 this.el.hideUnders(true);
3478 this.anim = this.el.shift({
3479 duration: this.repairDuration || .5,
3483 callback: this.afterRepair,
3492 afterRepair : function(){
3494 if(typeof this.callback == "function"){
3495 this.callback.call(this.scope || this);
3497 this.callback = null;
3502 * Ext JS Library 1.1.1
3503 * Copyright(c) 2006-2007, Ext JS, LLC.
3505 * Originally Released Under LGPL - original licence link has changed is not relivant.
3508 * <script type="text/javascript">
3512 * @class Roo.dd.DragSource
3513 * @extends Roo.dd.DDProxy
3514 * A simple class that provides the basic implementation needed to make any element draggable.
3516 * @param {String/HTMLElement/Element} el The container element
3517 * @param {Object} config
3519 Roo.dd.DragSource = function(el, config){
3520 this.el = Roo.get(el);
3523 Roo.apply(this, config);
3526 this.proxy = new Roo.dd.StatusProxy();
3529 Roo.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
3530 {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
3532 this.dragging = false;
3535 Roo.extend(Roo.dd.DragSource, Roo.dd.DDProxy, {
3537 * @cfg {String} dropAllowed
3538 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
3540 dropAllowed : "x-dd-drop-ok",
3542 * @cfg {String} dropNotAllowed
3543 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
3545 dropNotAllowed : "x-dd-drop-nodrop",
3548 * Returns the data object associated with this drag source
3549 * @return {Object} data An object containing arbitrary data
3551 getDragData : function(e){
3552 return this.dragData;
3556 onDragEnter : function(e, id){
3557 var target = Roo.dd.DragDropMgr.getDDById(id);
3558 this.cachedTarget = target;
3559 if(this.beforeDragEnter(target, e, id) !== false){
3560 if(target.isNotifyTarget){
3561 var status = target.notifyEnter(this, e, this.dragData);
3562 this.proxy.setStatus(status);
3564 this.proxy.setStatus(this.dropAllowed);
3567 if(this.afterDragEnter){
3569 * An empty function by default, but provided so that you can perform a custom action
3570 * when the dragged item enters the drop target by providing an implementation.
3571 * @param {Roo.dd.DragDrop} target The drop target
3572 * @param {Event} e The event object
3573 * @param {String} id The id of the dragged element
3574 * @method afterDragEnter
3576 this.afterDragEnter(target, e, id);
3582 * An empty function by default, but provided so that you can perform a custom action
3583 * before the dragged item enters the drop target and optionally cancel the onDragEnter.
3584 * @param {Roo.dd.DragDrop} target The drop target
3585 * @param {Event} e The event object
3586 * @param {String} id The id of the dragged element
3587 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3589 beforeDragEnter : function(target, e, id){
3594 alignElWithMouse: function() {
3595 Roo.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
3600 onDragOver : function(e, id){
3601 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
3602 if(this.beforeDragOver(target, e, id) !== false){
3603 if(target.isNotifyTarget){
3604 var status = target.notifyOver(this, e, this.dragData);
3605 this.proxy.setStatus(status);
3608 if(this.afterDragOver){
3610 * An empty function by default, but provided so that you can perform a custom action
3611 * while the dragged item is over the drop target by providing an implementation.
3612 * @param {Roo.dd.DragDrop} target The drop target
3613 * @param {Event} e The event object
3614 * @param {String} id The id of the dragged element
3615 * @method afterDragOver
3617 this.afterDragOver(target, e, id);
3623 * An empty function by default, but provided so that you can perform a custom action
3624 * while the dragged item is over the drop target and optionally cancel the onDragOver.
3625 * @param {Roo.dd.DragDrop} target The drop target
3626 * @param {Event} e The event object
3627 * @param {String} id The id of the dragged element
3628 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3630 beforeDragOver : function(target, e, id){
3635 onDragOut : function(e, id){
3636 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
3637 if(this.beforeDragOut(target, e, id) !== false){
3638 if(target.isNotifyTarget){
3639 target.notifyOut(this, e, this.dragData);
3642 if(this.afterDragOut){
3644 * An empty function by default, but provided so that you can perform a custom action
3645 * after the dragged item is dragged out of the target without dropping.
3646 * @param {Roo.dd.DragDrop} target The drop target
3647 * @param {Event} e The event object
3648 * @param {String} id The id of the dragged element
3649 * @method afterDragOut
3651 this.afterDragOut(target, e, id);
3654 this.cachedTarget = null;
3658 * An empty function by default, but provided so that you can perform a custom action before the dragged
3659 * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
3660 * @param {Roo.dd.DragDrop} target The drop target
3661 * @param {Event} e The event object
3662 * @param {String} id The id of the dragged element
3663 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3665 beforeDragOut : function(target, e, id){
3670 onDragDrop : function(e, id){
3671 var target = this.cachedTarget || Roo.dd.DragDropMgr.getDDById(id);
3672 if(this.beforeDragDrop(target, e, id) !== false){
3673 if(target.isNotifyTarget){
3674 if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
3675 this.onValidDrop(target, e, id);
3677 this.onInvalidDrop(target, e, id);
3680 this.onValidDrop(target, e, id);
3683 if(this.afterDragDrop){
3685 * An empty function by default, but provided so that you can perform a custom action
3686 * after a valid drag drop has occurred by providing an implementation.
3687 * @param {Roo.dd.DragDrop} target The drop target
3688 * @param {Event} e The event object
3689 * @param {String} id The id of the dropped element
3690 * @method afterDragDrop
3692 this.afterDragDrop(target, e, id);
3695 delete this.cachedTarget;
3699 * An empty function by default, but provided so that you can perform a custom action before the dragged
3700 * item is dropped onto the target and optionally cancel the onDragDrop.
3701 * @param {Roo.dd.DragDrop} target The drop target
3702 * @param {Event} e The event object
3703 * @param {String} id The id of the dragged element
3704 * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
3706 beforeDragDrop : function(target, e, id){
3711 onValidDrop : function(target, e, id){
3713 if(this.afterValidDrop){
3715 * An empty function by default, but provided so that you can perform a custom action
3716 * after a valid drop has occurred by providing an implementation.
3717 * @param {Object} target The target DD
3718 * @param {Event} e The event object
3719 * @param {String} id The id of the dropped element
3720 * @method afterInvalidDrop
3722 this.afterValidDrop(target, e, id);
3727 getRepairXY : function(e, data){
3728 return this.el.getXY();
3732 onInvalidDrop : function(target, e, id){
3733 this.beforeInvalidDrop(target, e, id);
3734 if(this.cachedTarget){
3735 if(this.cachedTarget.isNotifyTarget){
3736 this.cachedTarget.notifyOut(this, e, this.dragData);
3738 this.cacheTarget = null;
3740 this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
3742 if(this.afterInvalidDrop){
3744 * An empty function by default, but provided so that you can perform a custom action
3745 * after an invalid drop has occurred by providing an implementation.
3746 * @param {Event} e The event object
3747 * @param {String} id The id of the dropped element
3748 * @method afterInvalidDrop
3750 this.afterInvalidDrop(e, id);
3755 afterRepair : function(){
3757 this.el.highlight(this.hlColor || "c3daf9");
3759 this.dragging = false;
3763 * An empty function by default, but provided so that you can perform a custom action after an invalid
3764 * drop has occurred.
3765 * @param {Roo.dd.DragDrop} target The drop target
3766 * @param {Event} e The event object
3767 * @param {String} id The id of the dragged element
3768 * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
3770 beforeInvalidDrop : function(target, e, id){
3775 handleMouseDown : function(e){
3779 var data = this.getDragData(e);
3780 if(data && this.onBeforeDrag(data, e) !== false){
3781 this.dragData = data;
3783 Roo.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
3788 * An empty function by default, but provided so that you can perform a custom action before the initial
3789 * drag event begins and optionally cancel it.
3790 * @param {Object} data An object containing arbitrary data to be shared with drop targets
3791 * @param {Event} e The event object
3792 * @return {Boolean} isValid True if the drag event is valid, else false to cancel
3794 onBeforeDrag : function(data, e){
3799 * An empty function by default, but provided so that you can perform a custom action once the initial
3800 * drag event has begun. The drag cannot be canceled from this function.
3801 * @param {Number} x The x position of the click on the dragged object
3802 * @param {Number} y The y position of the click on the dragged object
3804 onStartDrag : Roo.emptyFn,
3806 // private - YUI override
3807 startDrag : function(x, y){
3809 this.dragging = true;
3810 this.proxy.update("");
3811 this.onInitDrag(x, y);
3816 onInitDrag : function(x, y){
3817 var clone = this.el.dom.cloneNode(true);
3818 clone.id = Roo.id(); // prevent duplicate ids
3819 this.proxy.update(clone);
3820 this.onStartDrag(x, y);
3825 * Returns the drag source's underlying {@link Roo.dd.StatusProxy}
3826 * @return {Roo.dd.StatusProxy} proxy The StatusProxy
3828 getProxy : function(){
3833 * Hides the drag source's {@link Roo.dd.StatusProxy}
3835 hideProxy : function(){
3837 this.proxy.reset(true);
3838 this.dragging = false;
3842 triggerCacheRefresh : function(){
3843 Roo.dd.DDM.refreshCache(this.groups);
3846 // private - override to prevent hiding
3847 b4EndDrag: function(e) {
3850 // private - override to prevent moving
3851 endDrag : function(e){
3852 this.onEndDrag(this.dragData, e);
3856 onEndDrag : function(data, e){
3859 // private - pin to cursor
3860 autoOffset : function(x, y) {
3861 this.setDelta(-12, -20);
3865 * Ext JS Library 1.1.1
3866 * Copyright(c) 2006-2007, Ext JS, LLC.
3868 * Originally Released Under LGPL - original licence link has changed is not relivant.
3871 * <script type="text/javascript">
3876 * @class Roo.dd.DropTarget
3877 * @extends Roo.dd.DDTarget
3878 * A simple class that provides the basic implementation needed to make any element a drop target that can have
3879 * draggable items dropped onto it. The drop has no effect until an implementation of notifyDrop is provided.
3881 * @param {String/HTMLElement/Element} el The container element
3882 * @param {Object} config
3884 Roo.dd.DropTarget = function(el, config){
3885 this.el = Roo.get(el);
3887 Roo.apply(this, config);
3889 if(this.containerScroll){
3890 Roo.dd.ScrollManager.register(this.el);
3893 Roo.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
3898 Roo.extend(Roo.dd.DropTarget, Roo.dd.DDTarget, {
3900 * @cfg {String} overClass
3901 * The CSS class applied to the drop target element while the drag source is over it (defaults to "").
3904 * @cfg {String} dropAllowed
3905 * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
3907 dropAllowed : "x-dd-drop-ok",
3909 * @cfg {String} dropNotAllowed
3910 * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
3912 dropNotAllowed : "x-dd-drop-nodrop",
3918 isNotifyTarget : true,
3921 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source is now over the
3922 * target. This default implementation adds the CSS class specified by overClass (if any) to the drop element
3923 * and returns the dropAllowed config value. This method should be overridden if drop validation is required.
3924 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3925 * @param {Event} e The event
3926 * @param {Object} data An object containing arbitrary data supplied by the drag source
3927 * @return {String} status The CSS class that communicates the drop status back to the source so that the
3928 * underlying {@link Roo.dd.StatusProxy} can be updated
3930 notifyEnter : function(dd, e, data){
3932 this.el.addClass(this.overClass);
3934 return this.dropAllowed;
3938 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the target.
3939 * This method will be called on every mouse movement while the drag source is over the drop target.
3940 * This default implementation simply returns the dropAllowed config value.
3941 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3942 * @param {Event} e The event
3943 * @param {Object} data An object containing arbitrary data supplied by the drag source
3944 * @return {String} status The CSS class that communicates the drop status back to the source so that the
3945 * underlying {@link Roo.dd.StatusProxy} can be updated
3947 notifyOver : function(dd, e, data){
3948 return this.dropAllowed;
3952 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the source has been dragged
3953 * out of the target without dropping. This default implementation simply removes the CSS class specified by
3954 * overClass (if any) from the drop element.
3955 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3956 * @param {Event} e The event
3957 * @param {Object} data An object containing arbitrary data supplied by the drag source
3959 notifyOut : function(dd, e, data){
3961 this.el.removeClass(this.overClass);
3966 * The function a {@link Roo.dd.DragSource} calls once to notify this drop target that the dragged item has
3967 * been dropped on it. This method has no default implementation and returns false, so you must provide an
3968 * implementation that does something to process the drop event and returns true so that the drag source's
3969 * repair action does not run.
3970 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
3971 * @param {Event} e The event
3972 * @param {Object} data An object containing arbitrary data supplied by the drag source
3973 * @return {Boolean} True if the drop was valid, else false
3975 notifyDrop : function(dd, e, data){
3980 * Ext JS Library 1.1.1
3981 * Copyright(c) 2006-2007, Ext JS, LLC.
3983 * Originally Released Under LGPL - original licence link has changed is not relivant.
3986 * <script type="text/javascript">
3991 * @class Roo.dd.DragZone
3992 * @extends Roo.dd.DragSource
3993 * This class provides a container DD instance that proxies for multiple child node sources.<br />
3994 * By default, this class requires that draggable child nodes are registered with {@link Roo.dd.Registry}.
3996 * @param {String/HTMLElement/Element} el The container element
3997 * @param {Object} config
3999 Roo.dd.DragZone = function(el, config){
4000 Roo.dd.DragZone.superclass.constructor.call(this, el, config);
4001 if(this.containerScroll){
4002 Roo.dd.ScrollManager.register(this.el);
4006 Roo.extend(Roo.dd.DragZone, Roo.dd.DragSource, {
4008 * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
4009 * for auto scrolling during drag operations.
4012 * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
4013 * method after a failed drop (defaults to "c3daf9" - light blue)
4017 * Called when a mousedown occurs in this container. Looks in {@link Roo.dd.Registry}
4018 * for a valid target to drag based on the mouse down. Override this method
4019 * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
4020 * object has a "ddel" attribute (with an HTML Element) for other functions to work.
4021 * @param {EventObject} e The mouse down event
4022 * @return {Object} The dragData
4024 getDragData : function(e){
4025 return Roo.dd.Registry.getHandleFromEvent(e);
4029 * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
4030 * this.dragData.ddel
4031 * @param {Number} x The x position of the click on the dragged object
4032 * @param {Number} y The y position of the click on the dragged object
4033 * @return {Boolean} true to continue the drag, false to cancel
4035 onInitDrag : function(x, y){
4036 this.proxy.update(this.dragData.ddel.cloneNode(true));
4037 this.onStartDrag(x, y);
4042 * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
4044 afterRepair : function(){
4046 Roo.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
4048 this.dragging = false;
4052 * Called before a repair of an invalid drop to get the XY to animate to. By default returns
4053 * the XY of this.dragData.ddel
4054 * @param {EventObject} e The mouse up event
4055 * @return {Array} The xy location (e.g. [100, 200])
4057 getRepairXY : function(e){
4058 return Roo.Element.fly(this.dragData.ddel).getXY();
4062 * Ext JS Library 1.1.1
4063 * Copyright(c) 2006-2007, Ext JS, LLC.
4065 * Originally Released Under LGPL - original licence link has changed is not relivant.
4068 * <script type="text/javascript">
4071 * @class Roo.dd.DropZone
4072 * @extends Roo.dd.DropTarget
4073 * This class provides a container DD instance that proxies for multiple child node targets.<br />
4074 * By default, this class requires that child nodes accepting drop are registered with {@link Roo.dd.Registry}.
4076 * @param {String/HTMLElement/Element} el The container element
4077 * @param {Object} config
4079 Roo.dd.DropZone = function(el, config){
4080 Roo.dd.DropZone.superclass.constructor.call(this, el, config);
4083 Roo.extend(Roo.dd.DropZone, Roo.dd.DropTarget, {
4085 * Returns a custom data object associated with the DOM node that is the target of the event. By default
4086 * this looks up the event target in the {@link Roo.dd.Registry}, although you can override this method to
4087 * provide your own custom lookup.
4088 * @param {Event} e The event
4089 * @return {Object} data The custom data
4091 getTargetFromEvent : function(e){
4092 return Roo.dd.Registry.getTargetFromEvent(e);
4096 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has entered a drop node
4097 * that it has registered. This method has no default implementation and should be overridden to provide
4098 * node-specific processing if necessary.
4099 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4100 * {@link #getTargetFromEvent} for this node)
4101 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4102 * @param {Event} e The event
4103 * @param {Object} data An object containing arbitrary data supplied by the drag source
4105 onNodeEnter : function(n, dd, e, data){
4110 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is over a drop node
4111 * that it has registered. The default implementation returns this.dropNotAllowed, so it should be
4112 * overridden to provide the proper feedback.
4113 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4114 * {@link #getTargetFromEvent} for this node)
4115 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4116 * @param {Event} e The event
4117 * @param {Object} data An object containing arbitrary data supplied by the drag source
4118 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4119 * underlying {@link Roo.dd.StatusProxy} can be updated
4121 onNodeOver : function(n, dd, e, data){
4122 return this.dropAllowed;
4126 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dragged out of
4127 * the drop node without dropping. This method has no default implementation and should be overridden to provide
4128 * node-specific processing if necessary.
4129 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4130 * {@link #getTargetFromEvent} for this node)
4131 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4132 * @param {Event} e The event
4133 * @param {Object} data An object containing arbitrary data supplied by the drag source
4135 onNodeOut : function(n, dd, e, data){
4140 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped onto
4141 * the drop node. The default implementation returns false, so it should be overridden to provide the
4142 * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
4143 * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
4144 * {@link #getTargetFromEvent} for this node)
4145 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4146 * @param {Event} e The event
4147 * @param {Object} data An object containing arbitrary data supplied by the drag source
4148 * @return {Boolean} True if the drop was valid, else false
4150 onNodeDrop : function(n, dd, e, data){
4155 * Called internally while the DropZone determines that a {@link Roo.dd.DragSource} is being dragged over it,
4156 * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
4157 * it should be overridden to provide the proper feedback if necessary.
4158 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4159 * @param {Event} e The event
4160 * @param {Object} data An object containing arbitrary data supplied by the drag source
4161 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4162 * underlying {@link Roo.dd.StatusProxy} can be updated
4164 onContainerOver : function(dd, e, data){
4165 return this.dropNotAllowed;
4169 * Called internally when the DropZone determines that a {@link Roo.dd.DragSource} has been dropped on it,
4170 * but not on any of its registered drop nodes. The default implementation returns false, so it should be
4171 * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
4172 * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
4173 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4174 * @param {Event} e The event
4175 * @param {Object} data An object containing arbitrary data supplied by the drag source
4176 * @return {Boolean} True if the drop was valid, else false
4178 onContainerDrop : function(dd, e, data){
4183 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source is now over
4184 * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
4185 * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
4186 * you should override this method and provide a custom implementation.
4187 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4188 * @param {Event} e The event
4189 * @param {Object} data An object containing arbitrary data supplied by the drag source
4190 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4191 * underlying {@link Roo.dd.StatusProxy} can be updated
4193 notifyEnter : function(dd, e, data){
4194 return this.dropNotAllowed;
4198 * The function a {@link Roo.dd.DragSource} calls continuously while it is being dragged over the drop zone.
4199 * This method will be called on every mouse movement while the drag source is over the drop zone.
4200 * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
4201 * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
4202 * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
4203 * registered node, it will call {@link #onContainerOver}.
4204 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4205 * @param {Event} e The event
4206 * @param {Object} data An object containing arbitrary data supplied by the drag source
4207 * @return {String} status The CSS class that communicates the drop status back to the source so that the
4208 * underlying {@link Roo.dd.StatusProxy} can be updated
4210 notifyOver : function(dd, e, data){
4211 var n = this.getTargetFromEvent(e);
4212 if(!n){ // not over valid drop target
4213 if(this.lastOverNode){
4214 this.onNodeOut(this.lastOverNode, dd, e, data);
4215 this.lastOverNode = null;
4217 return this.onContainerOver(dd, e, data);
4219 if(this.lastOverNode != n){
4220 if(this.lastOverNode){
4221 this.onNodeOut(this.lastOverNode, dd, e, data);
4223 this.onNodeEnter(n, dd, e, data);
4224 this.lastOverNode = n;
4226 return this.onNodeOver(n, dd, e, data);
4230 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the source has been dragged
4231 * out of the zone without dropping. If the drag source is currently over a registered node, the notification
4232 * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
4233 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop target
4234 * @param {Event} e The event
4235 * @param {Object} data An object containing arbitrary data supplied by the drag zone
4237 notifyOut : function(dd, e, data){
4238 if(this.lastOverNode){
4239 this.onNodeOut(this.lastOverNode, dd, e, data);
4240 this.lastOverNode = null;
4245 * The function a {@link Roo.dd.DragSource} calls once to notify this drop zone that the dragged item has
4246 * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
4247 * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
4248 * otherwise it will call {@link #onContainerDrop}.
4249 * @param {Roo.dd.DragSource} source The drag source that was dragged over this drop zone
4250 * @param {Event} e The event
4251 * @param {Object} data An object containing arbitrary data supplied by the drag source
4252 * @return {Boolean} True if the drop was valid, else false
4254 notifyDrop : function(dd, e, data){
4255 if(this.lastOverNode){
4256 this.onNodeOut(this.lastOverNode, dd, e, data);
4257 this.lastOverNode = null;
4259 var n = this.getTargetFromEvent(e);
4261 this.onNodeDrop(n, dd, e, data) :
4262 this.onContainerDrop(dd, e, data);
4266 triggerCacheRefresh : function(){
4267 Roo.dd.DDM.refreshCache(this.groups);
4271 * Ext JS Library 1.1.1
4272 * Copyright(c) 2006-2007, Ext JS, LLC.
4274 * Originally Released Under LGPL - original licence link has changed is not relivant.
4277 * <script type="text/javascript">
4282 * @class Roo.data.SortTypes
4284 * Defines the default sorting (casting?) comparison functions used when sorting data.
4286 Roo.data.SortTypes = {
4288 * Default sort that does nothing
4289 * @param {Mixed} s The value being converted
4290 * @return {Mixed} The comparison value
4297 * The regular expression used to strip tags
4301 stripTagsRE : /<\/?[^>]+>/gi,
4304 * Strips all HTML tags to sort on text only
4305 * @param {Mixed} s The value being converted
4306 * @return {String} The comparison value
4308 asText : function(s){
4309 return String(s).replace(this.stripTagsRE, "");
4313 * Strips all HTML tags to sort on text only - Case insensitive
4314 * @param {Mixed} s The value being converted
4315 * @return {String} The comparison value
4317 asUCText : function(s){
4318 return String(s).toUpperCase().replace(this.stripTagsRE, "");
4322 * Case insensitive string
4323 * @param {Mixed} s The value being converted
4324 * @return {String} The comparison value
4326 asUCString : function(s) {
4327 return String(s).toUpperCase();
4332 * @param {Mixed} s The value being converted
4333 * @return {Number} The comparison value
4335 asDate : function(s) {
4339 if(s instanceof Date){
4342 return Date.parse(String(s));
4347 * @param {Mixed} s The value being converted
4348 * @return {Float} The comparison value
4350 asFloat : function(s) {
4351 var val = parseFloat(String(s).replace(/,/g, ""));
4352 if(isNaN(val)) val = 0;
4358 * @param {Mixed} s The value being converted
4359 * @return {Number} The comparison value
4361 asInt : function(s) {
4362 var val = parseInt(String(s).replace(/,/g, ""));
4363 if(isNaN(val)) val = 0;
4368 * Ext JS Library 1.1.1
4369 * Copyright(c) 2006-2007, Ext JS, LLC.
4371 * Originally Released Under LGPL - original licence link has changed is not relivant.
4374 * <script type="text/javascript">
4378 * @class Roo.data.Record
4379 * Instances of this class encapsulate both record <em>definition</em> information, and record
4380 * <em>value</em> information for use in {@link Roo.data.Store} objects, or any code which needs
4381 * to access Records cached in an {@link Roo.data.Store} object.<br>
4383 * Constructors for this class are generated by passing an Array of field definition objects to {@link #create}.
4384 * Instances are usually only created by {@link Roo.data.Reader} implementations when processing unformatted data
4387 * Record objects generated by this constructor inherit all the methods of Roo.data.Record listed below.
4389 * This constructor should not be used to create Record objects. Instead, use the constructor generated by
4390 * {@link #create}. The parameters are the same.
4391 * @param {Array} data An associative Array of data values keyed by the field name.
4392 * @param {Object} id (Optional) The id of the record. This id should be unique, and is used by the
4393 * {@link Roo.data.Store} object which owns the Record to index its collection of Records. If
4394 * not specified an integer id is generated.
4396 Roo.data.Record = function(data, id){
4397 this.id = (id || id === 0) ? id : ++Roo.data.Record.AUTO_ID;
4402 * Generate a constructor for a specific record layout.
4403 * @param {Array} o An Array of field definition objects which specify field names, and optionally,
4404 * data types, and a mapping for an {@link Roo.data.Reader} to extract the field's value from a data object.
4405 * Each field definition object may contain the following properties: <ul>
4406 * <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,
4407 * for example the <em>dataIndex</em> property in column definition objects passed to {@link Roo.grid.ColumnModel}</p></li>
4408 * <li><b>mapping</b> : String<p style="margin-left:1em">(Optional) A path specification for use by the {@link Roo.data.Reader} implementation
4409 * that is creating the Record to access the data value from the data object. If an {@link Roo.data.JsonReader}
4410 * is being used, then this is a string containing the javascript expression to reference the data relative to
4411 * the record item's root. If an {@link Roo.data.XmlReader} is being used, this is an {@link Roo.DomQuery} path
4412 * to the data item relative to the record element. If the mapping expression is the same as the field name,
4413 * this may be omitted.</p></li>
4414 * <li><b>type</b> : String<p style="margin-left:1em">(Optional) The data type for conversion to displayable value. Possible values are
4415 * <ul><li>auto (Default, implies no conversion)</li>
4420 * <li>date</li></ul></p></li>
4421 * <li><b>sortType</b> : Mixed<p style="margin-left:1em">(Optional) A member of {@link Roo.data.SortTypes}.</p></li>
4422 * <li><b>sortDir</b> : String<p style="margin-left:1em">(Optional) Initial direction to sort. "ASC" or "DESC"</p></li>
4423 * <li><b>convert</b> : Function<p style="margin-left:1em">(Optional) A function which converts the value provided
4424 * by the Reader into an object that will be stored in the Record. It is passed the
4425 * following parameters:<ul>
4426 * <li><b>v</b> : Mixed<p style="margin-left:1em">The data value as read by the Reader.</p></li>
4428 * <li><b>dateFormat</b> : String<p style="margin-left:1em">(Optional) A format String for the Date.parseDate function.</p></li>
4430 * <br>usage:<br><pre><code>
4431 var TopicRecord = Roo.data.Record.create(
4432 {name: 'title', mapping: 'topic_title'},
4433 {name: 'author', mapping: 'username'},
4434 {name: 'totalPosts', mapping: 'topic_replies', type: 'int'},
4435 {name: 'lastPost', mapping: 'post_time', type: 'date'},
4436 {name: 'lastPoster', mapping: 'user2'},
4437 {name: 'excerpt', mapping: 'post_text'}
4440 var myNewRecord = new TopicRecord({
4441 title: 'Do my job please',
4444 lastPost: new Date(),
4445 lastPoster: 'Animal',
4446 excerpt: 'No way dude!'
4448 myStore.add(myNewRecord);
4453 Roo.data.Record.create = function(o){
4455 f.superclass.constructor.apply(this, arguments);
4457 Roo.extend(f, Roo.data.Record);
4458 var p = f.prototype;
4459 p.fields = new Roo.util.MixedCollection(false, function(field){
4462 for(var i = 0, len = o.length; i < len; i++){
4463 p.fields.add(new Roo.data.Field(o[i]));
4465 f.getField = function(name){
4466 return p.fields.get(name);
4471 Roo.data.Record.AUTO_ID = 1000;
4472 Roo.data.Record.EDIT = 'edit';
4473 Roo.data.Record.REJECT = 'reject';
4474 Roo.data.Record.COMMIT = 'commit';
4476 Roo.data.Record.prototype = {
4478 * Readonly flag - true if this record has been modified.
4487 join : function(store){
4492 * Set the named field to the specified value.
4493 * @param {String} name The name of the field to set.
4494 * @param {Object} value The value to set the field to.
4496 set : function(name, value){
4497 if(this.data[name] == value){
4504 if(typeof this.modified[name] == 'undefined'){
4505 this.modified[name] = this.data[name];
4507 this.data[name] = value;
4509 this.store.afterEdit(this);
4514 * Get the value of the named field.
4515 * @param {String} name The name of the field to get the value of.
4516 * @return {Object} The value of the field.
4518 get : function(name){
4519 return this.data[name];
4523 beginEdit : function(){
4524 this.editing = true;
4529 cancelEdit : function(){
4530 this.editing = false;
4531 delete this.modified;
4535 endEdit : function(){
4536 this.editing = false;
4537 if(this.dirty && this.store){
4538 this.store.afterEdit(this);
4543 * Usually called by the {@link Roo.data.Store} which owns the Record.
4544 * Rejects all changes made to the Record since either creation, or the last commit operation.
4545 * Modified fields are reverted to their original values.
4547 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
4548 * of reject operations.
4550 reject : function(){
4551 var m = this.modified;
4553 if(typeof m[n] != "function"){
4554 this.data[n] = m[n];
4558 delete this.modified;
4559 this.editing = false;
4561 this.store.afterReject(this);
4566 * Usually called by the {@link Roo.data.Store} which owns the Record.
4567 * Commits all changes made to the Record since either creation, or the last commit operation.
4569 * Developers should subscribe to the {@link Roo.data.Store#update} event to have their code notified
4570 * of commit operations.
4572 commit : function(){
4574 delete this.modified;
4575 this.editing = false;
4577 this.store.afterCommit(this);
4582 hasError : function(){
4583 return this.error != null;
4587 clearError : function(){
4592 * Creates a copy of this record.
4593 * @param {String} id (optional) A new record id if you don't want to use this record's id
4596 copy : function(newId) {
4597 return new this.constructor(Roo.apply({}, this.data), newId || this.id);
4601 * Ext JS Library 1.1.1
4602 * Copyright(c) 2006-2007, Ext JS, LLC.
4604 * Originally Released Under LGPL - original licence link has changed is not relivant.
4607 * <script type="text/javascript">
4613 * @class Roo.data.Store
4614 * @extends Roo.util.Observable
4615 * The Store class encapsulates a client side cache of {@link Roo.data.Record} objects which provide input data
4616 * for widgets such as the Roo.grid.Grid, or the Roo.form.ComboBox.<br>
4618 * 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
4619 * has no knowledge of the format of the data returned by the Proxy.<br>
4621 * A Store object uses its configured implementation of {@link Roo.data.DataReader} to create {@link Roo.data.Record}
4622 * instances from the data object. These records are cached and made available through accessor functions.
4624 * Creates a new Store.
4625 * @param {Object} config A config object containing the objects needed for the Store to access data,
4626 * and read the data into Records.
4628 Roo.data.Store = function(config){
4629 this.data = new Roo.util.MixedCollection(false);
4630 this.data.getKey = function(o){
4633 this.baseParams = {};
4642 if(config && config.data){
4643 this.inlineData = config.data;
4647 Roo.apply(this, config);
4649 if(this.reader){ // reader passed
4650 this.reader = Roo.factory(this.reader, Roo.data);
4651 this.reader.xmodule = this.xmodule || false;
4652 if(!this.recordType){
4653 this.recordType = this.reader.recordType;
4655 if(this.reader.onMetaChange){
4656 this.reader.onMetaChange = this.onMetaChange.createDelegate(this);
4660 if(this.recordType){
4661 this.fields = this.recordType.prototype.fields;
4667 * @event datachanged
4668 * Fires when the data cache has changed, and a widget which is using this Store
4669 * as a Record cache should refresh its view.
4670 * @param {Store} this
4675 * Fires when this store's reader provides new metadata (fields). This is currently only support for JsonReaders.
4676 * @param {Store} this
4677 * @param {Object} meta The JSON metadata
4682 * Fires when Records have been added to the Store
4683 * @param {Store} this
4684 * @param {Roo.data.Record[]} records The array of Records added
4685 * @param {Number} index The index at which the record(s) were added
4690 * Fires when a Record has been removed from the Store
4691 * @param {Store} this
4692 * @param {Roo.data.Record} record The Record that was removed
4693 * @param {Number} index The index at which the record was removed
4698 * Fires when a Record has been updated
4699 * @param {Store} this
4700 * @param {Roo.data.Record} record The Record that was updated
4701 * @param {String} operation The update operation being performed. Value may be one of:
4703 Roo.data.Record.EDIT
4704 Roo.data.Record.REJECT
4705 Roo.data.Record.COMMIT
4711 * Fires when the data cache has been cleared.
4712 * @param {Store} this
4717 * Fires before a request is made for a new data object. If the beforeload handler returns false
4718 * the load action will be canceled.
4719 * @param {Store} this
4720 * @param {Object} options The loading options that were specified (see {@link #load} for details)
4725 * Fires after a new set of Records has been loaded.
4726 * @param {Store} this
4727 * @param {Roo.data.Record[]} records The Records that were loaded
4728 * @param {Object} options The loading options that were specified (see {@link #load} for details)
4732 * @event loadexception
4733 * Fires if an exception occurs in the Proxy during loading.
4734 * Called with the signature of the Proxy's "loadexception" event.
4735 * If you return Json { data: [] , success: false, .... } then this will be thrown with the following args
4738 * @param {Object} return from JsonData.reader() - success, totalRecords, records
4739 * @param {Object} load options
4740 * @param {Object} jsonData from your request (normally this contains the Exception)
4742 loadexception : true
4746 this.proxy = Roo.factory(this.proxy, Roo.data);
4747 this.proxy.xmodule = this.xmodule || false;
4748 this.relayEvents(this.proxy, ["loadexception"]);
4750 this.sortToggle = {};
4752 Roo.data.Store.superclass.constructor.call(this);
4754 if(this.inlineData){
4755 this.loadData(this.inlineData);
4756 delete this.inlineData;
4759 Roo.extend(Roo.data.Store, Roo.util.Observable, {
4761 * @cfg {boolean} isLocal flag if data is locally available (and can be always looked up
4762 * without a remote query - used by combo/forms at present.
4766 * @cfg {Roo.data.DataProxy} proxy The Proxy object which provides access to a data object.
4769 * @cfg {Array} data Inline data to be loaded when the store is initialized.
4772 * @cfg {Roo.data.Reader} reader The Reader object which processes the data object and returns
4773 * an Array of Roo.data.record objects which are cached keyed by their <em>id</em> property.
4776 * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
4777 * on any HTTP request
4780 * @cfg {Object} sortInfo A config object in the format: {field: "fieldName", direction: "ASC|DESC"}
4783 * @cfg {boolean} remoteSort True if sorting is to be handled by requesting the Proxy to provide a refreshed
4784 * version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
4789 * @cfg {boolean} pruneModifiedRecords True to clear all modified record information each time the store is
4790 * loaded or when a record is removed. (defaults to false).
4792 pruneModifiedRecords : false,
4798 * Add Records to the Store and fires the add event.
4799 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
4801 add : function(records){
4802 records = [].concat(records);
4803 for(var i = 0, len = records.length; i < len; i++){
4804 records[i].join(this);
4806 var index = this.data.length;
4807 this.data.addAll(records);
4808 this.fireEvent("add", this, records, index);
4812 * Remove a Record from the Store and fires the remove event.
4813 * @param {Ext.data.Record} record The Roo.data.Record object to remove from the cache.
4815 remove : function(record){
4816 var index = this.data.indexOf(record);
4817 this.data.removeAt(index);
4818 if(this.pruneModifiedRecords){
4819 this.modified.remove(record);
4821 this.fireEvent("remove", this, record, index);
4825 * Remove all Records from the Store and fires the clear event.
4827 removeAll : function(){
4829 if(this.pruneModifiedRecords){
4832 this.fireEvent("clear", this);
4836 * Inserts Records to the Store at the given index and fires the add event.
4837 * @param {Number} index The start index at which to insert the passed Records.
4838 * @param {Roo.data.Record[]} records An Array of Roo.data.Record objects to add to the cache.
4840 insert : function(index, records){
4841 records = [].concat(records);
4842 for(var i = 0, len = records.length; i < len; i++){
4843 this.data.insert(index, records[i]);
4844 records[i].join(this);
4846 this.fireEvent("add", this, records, index);
4850 * Get the index within the cache of the passed Record.
4851 * @param {Roo.data.Record} record The Roo.data.Record object to to find.
4852 * @return {Number} The index of the passed Record. Returns -1 if not found.
4854 indexOf : function(record){
4855 return this.data.indexOf(record);
4859 * Get the index within the cache of the Record with the passed id.
4860 * @param {String} id The id of the Record to find.
4861 * @return {Number} The index of the Record. Returns -1 if not found.
4863 indexOfId : function(id){
4864 return this.data.indexOfKey(id);
4868 * Get the Record with the specified id.
4869 * @param {String} id The id of the Record to find.
4870 * @return {Roo.data.Record} The Record with the passed id. Returns undefined if not found.
4872 getById : function(id){
4873 return this.data.key(id);
4877 * Get the Record at the specified index.
4878 * @param {Number} index The index of the Record to find.
4879 * @return {Roo.data.Record} The Record at the passed index. Returns undefined if not found.
4881 getAt : function(index){
4882 return this.data.itemAt(index);
4886 * Returns a range of Records between specified indices.
4887 * @param {Number} startIndex (optional) The starting index (defaults to 0)
4888 * @param {Number} endIndex (optional) The ending index (defaults to the last Record in the Store)
4889 * @return {Roo.data.Record[]} An array of Records
4891 getRange : function(start, end){
4892 return this.data.getRange(start, end);
4896 storeOptions : function(o){
4897 o = Roo.apply({}, o);
4900 this.lastOptions = o;
4904 * Loads the Record cache from the configured Proxy using the configured Reader.
4906 * If using remote paging, then the first load call must specify the <em>start</em>
4907 * and <em>limit</em> properties in the options.params property to establish the initial
4908 * position within the dataset, and the number of Records to cache on each read from the Proxy.
4910 * <strong>It is important to note that for remote data sources, loading is asynchronous,
4911 * and this call will return before the new data has been loaded. Perform any post-processing
4912 * in a callback function, or in a "load" event handler.</strong>
4914 * @param {Object} options An object containing properties which control loading options:<ul>
4915 * <li>params {Object} An object containing properties to pass as HTTP parameters to a remote data source.</li>
4916 * <li>callback {Function} A function to be called after the Records have been loaded. The callback is
4917 * passed the following arguments:<ul>
4918 * <li>r : Roo.data.Record[]</li>
4919 * <li>options: Options object from the load call</li>
4920 * <li>success: Boolean success indicator</li></ul></li>
4921 * <li>scope {Object} Scope with which to call the callback (defaults to the Store object)</li>
4922 * <li>add {Boolean} indicator to append loaded records rather than replace the current cache.</li>
4925 load : function(options){
4926 options = options || {};
4927 if(this.fireEvent("beforeload", this, options) !== false){
4928 this.storeOptions(options);
4929 var p = Roo.apply(options.params || {}, this.baseParams);
4930 // if meta was not loaded from remote source.. try requesting it.
4931 if (!this.reader.metaFromRemote) {
4934 if(this.sortInfo && this.remoteSort){
4935 var pn = this.paramNames;
4936 p[pn["sort"]] = this.sortInfo.field;
4937 p[pn["dir"]] = this.sortInfo.direction;
4939 this.proxy.load(p, this.reader, this.loadRecords, this, options);
4944 * Reloads the Record cache from the configured Proxy using the configured Reader and
4945 * the options from the last load operation performed.
4946 * @param {Object} options (optional) An object containing properties which may override the options
4947 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
4948 * the most recently used options are reused).
4950 reload : function(options){
4951 this.load(Roo.applyIf(options||{}, this.lastOptions));
4955 // Called as a callback by the Reader during a load operation.
4956 loadRecords : function(o, options, success){
4957 if(!o || success === false){
4958 if(success !== false){
4959 this.fireEvent("load", this, [], options);
4961 if(options.callback){
4962 options.callback.call(options.scope || this, [], options, false);
4966 // if data returned failure - throw an exception.
4967 if (o.success === false) {
4968 this.fireEvent("loadexception", this, o, options, this.reader.jsonData);
4971 var r = o.records, t = o.totalRecords || r.length;
4972 if(!options || options.add !== true){
4973 if(this.pruneModifiedRecords){
4976 for(var i = 0, len = r.length; i < len; i++){
4980 this.data = this.snapshot;
4981 delete this.snapshot;
4984 this.data.addAll(r);
4985 this.totalLength = t;
4987 this.fireEvent("datachanged", this);
4989 this.totalLength = Math.max(t, this.data.length+r.length);
4992 this.fireEvent("load", this, r, options);
4993 if(options.callback){
4994 options.callback.call(options.scope || this, r, options, true);
4999 * Loads data from a passed data block. A Reader which understands the format of the data
5000 * must have been configured in the constructor.
5001 * @param {Object} data The data block from which to read the Records. The format of the data expected
5002 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
5003 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
5005 loadData : function(o, append){
5006 var r = this.reader.readRecords(o);
5007 this.loadRecords(r, {add: append}, true);
5011 * Gets the number of cached records.
5013 * <em>If using paging, this may not be the total size of the dataset. If the data object
5014 * used by the Reader contains the dataset size, then the getTotalCount() function returns
5015 * the data set size</em>
5017 getCount : function(){
5018 return this.data.length || 0;
5022 * Gets the total number of records in the dataset as returned by the server.
5024 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
5025 * the dataset size</em>
5027 getTotalCount : function(){
5028 return this.totalLength || 0;
5032 * Returns the sort state of the Store as an object with two properties:
5034 field {String} The name of the field by which the Records are sorted
5035 direction {String} The sort order, "ASC" or "DESC"
5038 getSortState : function(){
5039 return this.sortInfo;
5043 applySort : function(){
5044 if(this.sortInfo && !this.remoteSort){
5045 var s = this.sortInfo, f = s.field;
5046 var st = this.fields.get(f).sortType;
5047 var fn = function(r1, r2){
5048 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
5049 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
5051 this.data.sort(s.direction, fn);
5052 if(this.snapshot && this.snapshot != this.data){
5053 this.snapshot.sort(s.direction, fn);
5059 * Sets the default sort column and order to be used by the next load operation.
5060 * @param {String} fieldName The name of the field to sort by.
5061 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
5063 setDefaultSort : function(field, dir){
5064 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
5069 * If remote sorting is used, the sort is performed on the server, and the cache is
5070 * reloaded. If local sorting is used, the cache is sorted internally.
5071 * @param {String} fieldName The name of the field to sort by.
5072 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
5074 sort : function(fieldName, dir){
5075 var f = this.fields.get(fieldName);
5077 if(this.sortInfo && this.sortInfo.field == f.name){ // toggle sort dir
5078 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
5083 this.sortToggle[f.name] = dir;
5084 this.sortInfo = {field: f.name, direction: dir};
5085 if(!this.remoteSort){
5087 this.fireEvent("datachanged", this);
5089 this.load(this.lastOptions);
5094 * Calls the specified function for each of the Records in the cache.
5095 * @param {Function} fn The function to call. The Record is passed as the first parameter.
5096 * Returning <em>false</em> aborts and exits the iteration.
5097 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
5099 each : function(fn, scope){
5100 this.data.each(fn, scope);
5104 * Gets all records modified since the last commit. Modified records are persisted across load operations
5105 * (e.g., during paging).
5106 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
5108 getModifiedRecords : function(){
5109 return this.modified;
5113 createFilterFn : function(property, value, anyMatch){
5114 if(!value.exec){ // not a regex
5115 value = String(value);
5116 if(value.length == 0){
5119 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
5122 return value.test(r.data[property]);
5127 * Sums the value of <i>property</i> for each record between start and end and returns the result.
5128 * @param {String} property A field on your records
5129 * @param {Number} start The record index to start at (defaults to 0)
5130 * @param {Number} end The last record index to include (defaults to length - 1)
5131 * @return {Number} The sum
5133 sum : function(property, start, end){
5134 var rs = this.data.items, v = 0;
5136 end = (end || end === 0) ? end : rs.length-1;
5138 for(var i = start; i <= end; i++){
5139 v += (rs[i].data[property] || 0);
5145 * Filter the records by a specified property.
5146 * @param {String} field A field on your records
5147 * @param {String/RegExp} value Either a string that the field
5148 * should start with or a RegExp to test against the field
5149 * @param {Boolean} anyMatch True to match any part not just the beginning
5151 filter : function(property, value, anyMatch){
5152 var fn = this.createFilterFn(property, value, anyMatch);
5153 return fn ? this.filterBy(fn) : this.clearFilter();
5157 * Filter by a function. The specified function will be called with each
5158 * record in this data source. If the function returns true the record is included,
5159 * otherwise it is filtered.
5160 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
5161 * @param {Object} scope (optional) The scope of the function (defaults to this)
5163 filterBy : function(fn, scope){
5164 this.snapshot = this.snapshot || this.data;
5165 this.data = this.queryBy(fn, scope||this);
5166 this.fireEvent("datachanged", this);
5170 * Query the records by a specified property.
5171 * @param {String} field A field on your records
5172 * @param {String/RegExp} value Either a string that the field
5173 * should start with or a RegExp to test against the field
5174 * @param {Boolean} anyMatch True to match any part not just the beginning
5175 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
5177 query : function(property, value, anyMatch){
5178 var fn = this.createFilterFn(property, value, anyMatch);
5179 return fn ? this.queryBy(fn) : this.data.clone();
5183 * Query by a function. The specified function will be called with each
5184 * record in this data source. If the function returns true the record is included
5186 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
5187 * @param {Object} scope (optional) The scope of the function (defaults to this)
5188 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
5190 queryBy : function(fn, scope){
5191 var data = this.snapshot || this.data;
5192 return data.filterBy(fn, scope||this);
5196 * Collects unique values for a particular dataIndex from this store.
5197 * @param {String} dataIndex The property to collect
5198 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
5199 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
5200 * @return {Array} An array of the unique values
5202 collect : function(dataIndex, allowNull, bypassFilter){
5203 var d = (bypassFilter === true && this.snapshot) ?
5204 this.snapshot.items : this.data.items;
5205 var v, sv, r = [], l = {};
5206 for(var i = 0, len = d.length; i < len; i++){
5207 v = d[i].data[dataIndex];
5209 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
5218 * Revert to a view of the Record cache with no filtering applied.
5219 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
5221 clearFilter : function(suppressEvent){
5222 if(this.snapshot && this.snapshot != this.data){
5223 this.data = this.snapshot;
5224 delete this.snapshot;
5225 if(suppressEvent !== true){
5226 this.fireEvent("datachanged", this);
5232 afterEdit : function(record){
5233 if(this.modified.indexOf(record) == -1){
5234 this.modified.push(record);
5236 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
5240 afterReject : function(record){
5241 this.modified.remove(record);
5242 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
5246 afterCommit : function(record){
5247 this.modified.remove(record);
5248 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
5252 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
5253 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
5255 commitChanges : function(){
5256 var m = this.modified.slice(0);
5258 for(var i = 0, len = m.length; i < len; i++){
5264 * Cancel outstanding changes on all changed records.
5266 rejectChanges : function(){
5267 var m = this.modified.slice(0);
5269 for(var i = 0, len = m.length; i < len; i++){
5274 onMetaChange : function(meta, rtype, o){
5275 this.recordType = rtype;
5276 this.fields = rtype.prototype.fields;
5277 delete this.snapshot;
5278 this.sortInfo = meta.sortInfo || this.sortInfo;
5280 this.fireEvent('metachange', this, this.reader.meta);
5284 * Ext JS Library 1.1.1
5285 * Copyright(c) 2006-2007, Ext JS, LLC.
5287 * Originally Released Under LGPL - original licence link has changed is not relivant.
5290 * <script type="text/javascript">
5294 * @class Roo.data.SimpleStore
5295 * @extends Roo.data.Store
5296 * Small helper class to make creating Stores from Array data easier.
5297 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
5298 * @cfg {Array} fields An array of field definition objects, or field name strings.
5299 * @cfg {Array} data The multi-dimensional array of data
5301 * @param {Object} config
5303 Roo.data.SimpleStore = function(config){
5304 Roo.data.SimpleStore.superclass.constructor.call(this, {
5306 reader: new Roo.data.ArrayReader({
5309 Roo.data.Record.create(config.fields)
5311 proxy : new Roo.data.MemoryProxy(config.data)
5315 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
5317 * Ext JS Library 1.1.1
5318 * Copyright(c) 2006-2007, Ext JS, LLC.
5320 * Originally Released Under LGPL - original licence link has changed is not relivant.
5323 * <script type="text/javascript">
5328 * @extends Roo.data.Store
5329 * @class Roo.data.JsonStore
5330 * Small helper class to make creating Stores for JSON data easier. <br/>
5332 var store = new Roo.data.JsonStore({
5333 url: 'get-images.php',
5335 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
5338 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
5339 * JsonReader and HttpProxy (unless inline data is provided).</b>
5340 * @cfg {Array} fields An array of field definition objects, or field name strings.
5342 * @param {Object} config
5344 Roo.data.JsonStore = function(c){
5345 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
5346 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
5347 reader: new Roo.data.JsonReader(c, c.fields)
5350 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
5352 * Ext JS Library 1.1.1
5353 * Copyright(c) 2006-2007, Ext JS, LLC.
5355 * Originally Released Under LGPL - original licence link has changed is not relivant.
5358 * <script type="text/javascript">
5362 Roo.data.Field = function(config){
5363 if(typeof config == "string"){
5364 config = {name: config};
5366 Roo.apply(this, config);
5372 var st = Roo.data.SortTypes;
5373 // named sortTypes are supported, here we look them up
5374 if(typeof this.sortType == "string"){
5375 this.sortType = st[this.sortType];
5378 // set default sortType for strings and dates
5382 this.sortType = st.asUCString;
5385 this.sortType = st.asDate;
5388 this.sortType = st.none;
5393 var stripRe = /[\$,%]/g;
5395 // prebuilt conversion function for this field, instead of
5396 // switching every time we're reading a value
5398 var cv, dateFormat = this.dateFormat;
5403 cv = function(v){ return v; };
5406 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
5410 return v !== undefined && v !== null && v !== '' ?
5411 parseInt(String(v).replace(stripRe, ""), 10) : '';
5416 return v !== undefined && v !== null && v !== '' ?
5417 parseFloat(String(v).replace(stripRe, ""), 10) : '';
5422 cv = function(v){ return v === true || v === "true" || v == 1; };
5429 if(v instanceof Date){
5433 if(dateFormat == "timestamp"){
5434 return new Date(v*1000);
5436 return Date.parseDate(v, dateFormat);
5438 var parsed = Date.parse(v);
5439 return parsed ? new Date(parsed) : null;
5448 Roo.data.Field.prototype = {
5456 * Ext JS Library 1.1.1
5457 * Copyright(c) 2006-2007, Ext JS, LLC.
5459 * Originally Released Under LGPL - original licence link has changed is not relivant.
5462 * <script type="text/javascript">
5465 // Base class for reading structured data from a data source. This class is intended to be
5466 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
5469 * @class Roo.data.DataReader
5470 * Base class for reading structured data from a data source. This class is intended to be
5471 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
5474 Roo.data.DataReader = function(meta, recordType){
5478 this.recordType = recordType instanceof Array ?
5479 Roo.data.Record.create(recordType) : recordType;
5482 Roo.data.DataReader.prototype = {
5484 * Create an empty record
5485 * @param {Object} data (optional) - overlay some values
5486 * @return {Roo.data.Record} record created.
5488 newRow : function(d) {
5490 this.recordType.prototype.fields.each(function(c) {
5492 case 'int' : da[c.name] = 0; break;
5493 case 'date' : da[c.name] = new Date(); break;
5494 case 'float' : da[c.name] = 0.0; break;
5495 case 'boolean' : da[c.name] = false; break;
5496 default : da[c.name] = ""; break;
5500 return new this.recordType(Roo.apply(da, d));
5505 * Ext JS Library 1.1.1
5506 * Copyright(c) 2006-2007, Ext JS, LLC.
5508 * Originally Released Under LGPL - original licence link has changed is not relivant.
5511 * <script type="text/javascript">
5515 * @class Roo.data.DataProxy
5516 * @extends Roo.data.Observable
5517 * This class is an abstract base class for implementations which provide retrieval of
5518 * unformatted data objects.<br>
5520 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
5521 * (of the appropriate type which knows how to parse the data object) to provide a block of
5522 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
5524 * Custom implementations must implement the load method as described in
5525 * {@link Roo.data.HttpProxy#load}.
5527 Roo.data.DataProxy = function(){
5531 * Fires before a network request is made to retrieve a data object.
5532 * @param {Object} This DataProxy object.
5533 * @param {Object} params The params parameter to the load function.
5538 * Fires before the load method's callback is called.
5539 * @param {Object} This DataProxy object.
5540 * @param {Object} o The data object.
5541 * @param {Object} arg The callback argument object passed to the load function.
5545 * @event loadexception
5546 * Fires if an Exception occurs during data retrieval.
5547 * @param {Object} This DataProxy object.
5548 * @param {Object} o The data object.
5549 * @param {Object} arg The callback argument object passed to the load function.
5550 * @param {Object} e The Exception.
5552 loadexception : true
5554 Roo.data.DataProxy.superclass.constructor.call(this);
5557 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
5560 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
5564 * Ext JS Library 1.1.1
5565 * Copyright(c) 2006-2007, Ext JS, LLC.
5567 * Originally Released Under LGPL - original licence link has changed is not relivant.
5570 * <script type="text/javascript">
5573 * @class Roo.data.MemoryProxy
5574 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
5575 * to the Reader when its load method is called.
5577 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
5579 Roo.data.MemoryProxy = function(data){
5583 Roo.data.MemoryProxy.superclass.constructor.call(this);
5587 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
5589 * Load data from the requested source (in this case an in-memory
5590 * data object passed to the constructor), read the data object into
5591 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
5592 * process that block using the passed callback.
5593 * @param {Object} params This parameter is not used by the MemoryProxy class.
5594 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5595 * object into a block of Roo.data.Records.
5596 * @param {Function} callback The function into which to pass the block of Roo.data.records.
5597 * The function must be passed <ul>
5598 * <li>The Record block object</li>
5599 * <li>The "arg" argument from the load function</li>
5600 * <li>A boolean success indicator</li>
5602 * @param {Object} scope The scope in which to call the callback
5603 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5605 load : function(params, reader, callback, scope, arg){
5606 params = params || {};
5609 result = reader.readRecords(this.data);
5611 this.fireEvent("loadexception", this, arg, null, e);
5612 callback.call(scope, null, arg, false);
5615 callback.call(scope, result, arg, true);
5619 update : function(params, records){
5624 * Ext JS Library 1.1.1
5625 * Copyright(c) 2006-2007, Ext JS, LLC.
5627 * Originally Released Under LGPL - original licence link has changed is not relivant.
5630 * <script type="text/javascript">
5633 * @class Roo.data.HttpProxy
5634 * @extends Roo.data.DataProxy
5635 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
5636 * configured to reference a certain URL.<br><br>
5638 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
5639 * from which the running page was served.<br><br>
5641 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
5643 * Be aware that to enable the browser to parse an XML document, the server must set
5644 * the Content-Type header in the HTTP response to "text/xml".
5646 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
5647 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
5648 * will be used to make the request.
5650 Roo.data.HttpProxy = function(conn){
5651 Roo.data.HttpProxy.superclass.constructor.call(this);
5652 // is conn a conn config or a real conn?
5654 this.useAjax = !conn || !conn.events;
5658 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
5659 // thse are take from connection...
5662 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
5665 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
5666 * extra parameters to each request made by this object. (defaults to undefined)
5669 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
5670 * to each request made by this object. (defaults to undefined)
5673 * @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)
5676 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
5679 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
5685 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
5689 * Return the {@link Roo.data.Connection} object being used by this Proxy.
5690 * @return {Connection} The Connection object. This object may be used to subscribe to events on
5691 * a finer-grained basis than the DataProxy events.
5693 getConnection : function(){
5694 return this.useAjax ? Roo.Ajax : this.conn;
5698 * Load data from the configured {@link Roo.data.Connection}, read the data object into
5699 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
5700 * process that block using the passed callback.
5701 * @param {Object} params An object containing properties which are to be used as HTTP parameters
5702 * for the request to the remote server.
5703 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5704 * object into a block of Roo.data.Records.
5705 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
5706 * The function must be passed <ul>
5707 * <li>The Record block object</li>
5708 * <li>The "arg" argument from the load function</li>
5709 * <li>A boolean success indicator</li>
5711 * @param {Object} scope The scope in which to call the callback
5712 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5714 load : function(params, reader, callback, scope, arg){
5715 if(this.fireEvent("beforeload", this, params) !== false){
5717 params : params || {},
5719 callback : callback,
5724 callback : this.loadResponse,
5728 Roo.applyIf(o, this.conn);
5729 if(this.activeRequest){
5730 Roo.Ajax.abort(this.activeRequest);
5732 this.activeRequest = Roo.Ajax.request(o);
5734 this.conn.request(o);
5737 callback.call(scope||this, null, arg, false);
5742 loadResponse : function(o, success, response){
5743 delete this.activeRequest;
5745 this.fireEvent("loadexception", this, o, response);
5746 o.request.callback.call(o.request.scope, null, o.request.arg, false);
5751 result = o.reader.read(response);
5753 this.fireEvent("loadexception", this, o, response, e);
5754 o.request.callback.call(o.request.scope, null, o.request.arg, false);
5758 this.fireEvent("load", this, o, o.request.arg);
5759 o.request.callback.call(o.request.scope, result, o.request.arg, true);
5763 update : function(dataSet){
5768 updateResponse : function(dataSet){
5773 * Ext JS Library 1.1.1
5774 * Copyright(c) 2006-2007, Ext JS, LLC.
5776 * Originally Released Under LGPL - original licence link has changed is not relivant.
5779 * <script type="text/javascript">
5783 * @class Roo.data.ScriptTagProxy
5784 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
5785 * other than the originating domain of the running page.<br><br>
5787 * <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
5788 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
5790 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
5791 * source code that is used as the source inside a <script> tag.<br><br>
5793 * In order for the browser to process the returned data, the server must wrap the data object
5794 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
5795 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
5796 * depending on whether the callback name was passed:
5799 boolean scriptTag = false;
5800 String cb = request.getParameter("callback");
5803 response.setContentType("text/javascript");
5805 response.setContentType("application/x-json");
5807 Writer out = response.getWriter();
5809 out.write(cb + "(");
5811 out.print(dataBlock.toJsonString());
5818 * @param {Object} config A configuration object.
5820 Roo.data.ScriptTagProxy = function(config){
5821 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
5822 Roo.apply(this, config);
5823 this.head = document.getElementsByTagName("head")[0];
5826 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
5828 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
5830 * @cfg {String} url The URL from which to request the data object.
5833 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
5837 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
5838 * the server the name of the callback function set up by the load call to process the returned data object.
5839 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
5840 * javascript output which calls this named function passing the data object as its only parameter.
5842 callbackParam : "callback",
5844 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
5845 * name to the request.
5850 * Load data from the configured URL, read the data object into
5851 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
5852 * process that block using the passed callback.
5853 * @param {Object} params An object containing properties which are to be used as HTTP parameters
5854 * for the request to the remote server.
5855 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5856 * object into a block of Roo.data.Records.
5857 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
5858 * The function must be passed <ul>
5859 * <li>The Record block object</li>
5860 * <li>The "arg" argument from the load function</li>
5861 * <li>A boolean success indicator</li>
5863 * @param {Object} scope The scope in which to call the callback
5864 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5866 load : function(params, reader, callback, scope, arg){
5867 if(this.fireEvent("beforeload", this, params) !== false){
5869 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
5872 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
5874 url += "&_dc=" + (new Date().getTime());
5876 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
5879 cb : "stcCallback"+transId,
5880 scriptId : "stcScript"+transId,
5884 callback : callback,
5890 window[trans.cb] = function(o){
5891 conn.handleResponse(o, trans);
5894 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
5896 if(this.autoAbort !== false){
5900 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
5902 var script = document.createElement("script");
5903 script.setAttribute("src", url);
5904 script.setAttribute("type", "text/javascript");
5905 script.setAttribute("id", trans.scriptId);
5906 this.head.appendChild(script);
5910 callback.call(scope||this, null, arg, false);
5915 isLoading : function(){
5916 return this.trans ? true : false;
5920 * Abort the current server request.
5923 if(this.isLoading()){
5924 this.destroyTrans(this.trans);
5929 destroyTrans : function(trans, isLoaded){
5930 this.head.removeChild(document.getElementById(trans.scriptId));
5931 clearTimeout(trans.timeoutId);
5933 window[trans.cb] = undefined;
5935 delete window[trans.cb];
5938 // if hasn't been loaded, wait for load to remove it to prevent script error
5939 window[trans.cb] = function(){
5940 window[trans.cb] = undefined;
5942 delete window[trans.cb];
5949 handleResponse : function(o, trans){
5951 this.destroyTrans(trans, true);
5954 result = trans.reader.readRecords(o);
5956 this.fireEvent("loadexception", this, o, trans.arg, e);
5957 trans.callback.call(trans.scope||window, null, trans.arg, false);
5960 this.fireEvent("load", this, o, trans.arg);
5961 trans.callback.call(trans.scope||window, result, trans.arg, true);
5965 handleFailure : function(trans){
5967 this.destroyTrans(trans, false);
5968 this.fireEvent("loadexception", this, null, trans.arg);
5969 trans.callback.call(trans.scope||window, null, trans.arg, false);
5973 * Ext JS Library 1.1.1
5974 * Copyright(c) 2006-2007, Ext JS, LLC.
5976 * Originally Released Under LGPL - original licence link has changed is not relivant.
5979 * <script type="text/javascript">
5983 * @class Roo.data.JsonReader
5984 * @extends Roo.data.DataReader
5985 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
5986 * based on mappings in a provided Roo.data.Record constructor.
5988 * The default behaviour of a store is to send ?_requestMeta=1, unless the class has recieved 'metaData' property
5989 * in the reply previously.
5994 var RecordDef = Roo.data.Record.create([
5995 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
5996 {name: 'occupation'} // This field will use "occupation" as the mapping.
5998 var myReader = new Roo.data.JsonReader({
5999 totalProperty: "results", // The property which contains the total dataset size (optional)
6000 root: "rows", // The property which contains an Array of row objects
6001 id: "id" // The property within each row object that provides an ID for the record (optional)
6005 * This would consume a JSON file like this:
6007 { 'results': 2, 'rows': [
6008 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
6009 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
6012 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
6013 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
6014 * paged from the remote server.
6015 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
6016 * @cfg {String} root name of the property which contains the Array of row objects.
6017 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
6019 * Create a new JsonReader
6020 * @param {Object} meta Metadata configuration options
6021 * @param {Object} recordType Either an Array of field definition objects,
6022 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
6024 Roo.data.JsonReader = function(meta, recordType){
6027 // set some defaults:
6029 totalProperty: 'total',
6030 successProperty : 'success',
6035 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
6037 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
6040 * @prop {Boolean} metaFromRemote - if the meta data was loaded from the remote source.
6041 * Used by Store query builder to append _requestMeta to params.
6044 metaFromRemote : false,
6046 * This method is only used by a DataProxy which has retrieved data from a remote server.
6047 * @param {Object} response The XHR object which contains the JSON data in its responseText.
6048 * @return {Object} data A data block which is used by an Roo.data.Store object as
6049 * a cache of Roo.data.Records.
6051 read : function(response){
6052 var json = response.responseText;
6054 var o = /* eval:var:o */ eval("("+json+")");
6056 throw {message: "JsonReader.read: Json object not found"};
6062 this.metaFromRemote = true;
6063 this.meta = o.metaData;
6064 this.recordType = Roo.data.Record.create(o.metaData.fields);
6065 this.onMetaChange(this.meta, this.recordType, o);
6067 return this.readRecords(o);
6070 // private function a store will implement
6071 onMetaChange : function(meta, recordType, o){
6078 simpleAccess: function(obj, subsc) {
6085 getJsonAccessor: function(){
6087 return function(expr) {
6089 return(re.test(expr))
6090 ? new Function("obj", "return obj." + expr)
6100 * Create a data block containing Roo.data.Records from an XML document.
6101 * @param {Object} o An object which contains an Array of row objects in the property specified
6102 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
6103 * which contains the total size of the dataset.
6104 * @return {Object} data A data block which is used by an Roo.data.Store object as
6105 * a cache of Roo.data.Records.
6107 readRecords : function(o){
6109 * After any data loads, the raw JSON data is available for further custom processing.
6113 var s = this.meta, Record = this.recordType,
6114 f = Record.prototype.fields, fi = f.items, fl = f.length;
6116 // Generate extraction functions for the totalProperty, the root, the id, and for each field
6118 if(s.totalProperty) {
6119 this.getTotal = this.getJsonAccessor(s.totalProperty);
6121 if(s.successProperty) {
6122 this.getSuccess = this.getJsonAccessor(s.successProperty);
6124 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
6126 var g = this.getJsonAccessor(s.id);
6127 this.getId = function(rec) {
6129 return (r === undefined || r === "") ? null : r;
6132 this.getId = function(){return null;};
6135 for(var jj = 0; jj < fl; jj++){
6137 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
6138 this.ef[jj] = this.getJsonAccessor(map);
6142 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
6143 if(s.totalProperty){
6144 var vt = parseInt(this.getTotal(o), 10);
6149 if(s.successProperty){
6150 var vs = this.getSuccess(o);
6151 if(vs === false || vs === 'false'){
6156 for(var i = 0; i < c; i++){
6159 var id = this.getId(n);
6160 for(var j = 0; j < fl; j++){
6162 var v = this.ef[j](n);
6164 Roo.log('missing convert for ' + f.name);
6168 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
6170 var record = new Record(values, id);
6172 records[i] = record;
6177 totalRecords : totalRecords
6182 * Ext JS Library 1.1.1
6183 * Copyright(c) 2006-2007, Ext JS, LLC.
6185 * Originally Released Under LGPL - original licence link has changed is not relivant.
6188 * <script type="text/javascript">
6192 * @class Roo.data.XmlReader
6193 * @extends Roo.data.DataReader
6194 * Data reader class to create an Array of {@link Roo.data.Record} objects from an XML document
6195 * based on mappings in a provided Roo.data.Record constructor.<br><br>
6197 * <em>Note that in order for the browser to parse a returned XML document, the Content-Type
6198 * header in the HTTP response must be set to "text/xml".</em>
6202 var RecordDef = Roo.data.Record.create([
6203 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
6204 {name: 'occupation'} // This field will use "occupation" as the mapping.
6206 var myReader = new Roo.data.XmlReader({
6207 totalRecords: "results", // The element which contains the total dataset size (optional)
6208 record: "row", // The repeated element which contains row information
6209 id: "id" // The element within the row that provides an ID for the record (optional)
6213 * This would consume an XML file like this:
6217 <results>2</results>
6220 <name>Bill</name>
6221 <occupation>Gardener</occupation>
6225 <name>Ben</name>
6226 <occupation>Horticulturalist</occupation>
6230 * @cfg {String} totalRecords The DomQuery path from which to retrieve the total number of records
6231 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
6232 * paged from the remote server.
6233 * @cfg {String} record The DomQuery path to the repeated element which contains record information.
6234 * @cfg {String} success The DomQuery path to the success attribute used by forms.
6235 * @cfg {String} id The DomQuery path relative from the record element to the element that contains
6236 * a record identifier value.
6238 * Create a new XmlReader
6239 * @param {Object} meta Metadata configuration options
6240 * @param {Mixed} recordType The definition of the data record type to produce. This can be either a valid
6241 * Record subclass created with {@link Roo.data.Record#create}, or an array of objects with which to call
6242 * Roo.data.Record.create. See the {@link Roo.data.Record} class for more details.
6244 Roo.data.XmlReader = function(meta, recordType){
6246 Roo.data.XmlReader.superclass.constructor.call(this, meta, recordType||meta.fields);
6248 Roo.extend(Roo.data.XmlReader, Roo.data.DataReader, {
6250 * This method is only used by a DataProxy which has retrieved data from a remote server.
6251 * @param {Object} response The XHR object which contains the parsed XML document. The response is expected
6252 * to contain a method called 'responseXML' that returns an XML document object.
6253 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
6254 * a cache of Roo.data.Records.
6256 read : function(response){
6257 var doc = response.responseXML;
6259 throw {message: "XmlReader.read: XML Document not available"};
6261 return this.readRecords(doc);
6265 * Create a data block containing Roo.data.Records from an XML document.
6266 * @param {Object} doc A parsed XML document.
6267 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
6268 * a cache of Roo.data.Records.
6270 readRecords : function(doc){
6272 * After any data loads/reads, the raw XML Document is available for further custom processing.
6276 var root = doc.documentElement || doc;
6277 var q = Roo.DomQuery;
6278 var recordType = this.recordType, fields = recordType.prototype.fields;
6279 var sid = this.meta.id;
6280 var totalRecords = 0, success = true;
6281 if(this.meta.totalRecords){
6282 totalRecords = q.selectNumber(this.meta.totalRecords, root, 0);
6285 if(this.meta.success){
6286 var sv = q.selectValue(this.meta.success, root, true);
6287 success = sv !== false && sv !== 'false';
6290 var ns = q.select(this.meta.record, root);
6291 for(var i = 0, len = ns.length; i < len; i++) {
6294 var id = sid ? q.selectValue(sid, n) : undefined;
6295 for(var j = 0, jlen = fields.length; j < jlen; j++){
6296 var f = fields.items[j];
6297 var v = q.selectValue(f.mapping || f.name, n, f.defaultValue);
6301 var record = new recordType(values, id);
6303 records[records.length] = record;
6309 totalRecords : totalRecords || records.length
6314 * Ext JS Library 1.1.1
6315 * Copyright(c) 2006-2007, Ext JS, LLC.
6317 * Originally Released Under LGPL - original licence link has changed is not relivant.
6320 * <script type="text/javascript">
6324 * @class Roo.data.ArrayReader
6325 * @extends Roo.data.DataReader
6326 * Data reader class to create an Array of Roo.data.Record objects from an Array.
6327 * Each element of that Array represents a row of data fields. The
6328 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
6329 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
6333 var RecordDef = Roo.data.Record.create([
6334 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
6335 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
6337 var myReader = new Roo.data.ArrayReader({
6338 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
6342 * This would consume an Array like this:
6344 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
6346 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
6348 * Create a new JsonReader
6349 * @param {Object} meta Metadata configuration options.
6350 * @param {Object} recordType Either an Array of field definition objects
6351 * as specified to {@link Roo.data.Record#create},
6352 * or an {@link Roo.data.Record} object
6353 * created using {@link Roo.data.Record#create}.
6355 Roo.data.ArrayReader = function(meta, recordType){
6356 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
6359 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
6361 * Create a data block containing Roo.data.Records from an XML document.
6362 * @param {Object} o An Array of row objects which represents the dataset.
6363 * @return {Object} data A data block which is used by an Roo.data.Store object as
6364 * a cache of Roo.data.Records.
6366 readRecords : function(o){
6367 var sid = this.meta ? this.meta.id : null;
6368 var recordType = this.recordType, fields = recordType.prototype.fields;
6371 for(var i = 0; i < root.length; i++){
6374 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
6375 for(var j = 0, jlen = fields.length; j < jlen; j++){
6376 var f = fields.items[j];
6377 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
6378 var v = n[k] !== undefined ? n[k] : f.defaultValue;
6382 var record = new recordType(values, id);
6384 records[records.length] = record;
6388 totalRecords : records.length
6393 * Ext JS Library 1.1.1
6394 * Copyright(c) 2006-2007, Ext JS, LLC.
6396 * Originally Released Under LGPL - original licence link has changed is not relivant.
6399 * <script type="text/javascript">
6404 * @class Roo.data.Tree
6405 * @extends Roo.util.Observable
6406 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
6407 * in the tree have most standard DOM functionality.
6409 * @param {Node} root (optional) The root node
6411 Roo.data.Tree = function(root){
6414 * The root node for this tree
6419 this.setRootNode(root);
6424 * Fires when a new child node is appended to a node in this tree.
6425 * @param {Tree} tree The owner tree
6426 * @param {Node} parent The parent node
6427 * @param {Node} node The newly appended node
6428 * @param {Number} index The index of the newly appended node
6433 * Fires when a child node is removed from a node in this tree.
6434 * @param {Tree} tree The owner tree
6435 * @param {Node} parent The parent node
6436 * @param {Node} node The child node removed
6441 * Fires when a node is moved to a new location in the tree
6442 * @param {Tree} tree The owner tree
6443 * @param {Node} node The node moved
6444 * @param {Node} oldParent The old parent of this node
6445 * @param {Node} newParent The new parent of this node
6446 * @param {Number} index The index it was moved to
6451 * Fires when a new child node is inserted in a node in this tree.
6452 * @param {Tree} tree The owner tree
6453 * @param {Node} parent The parent node
6454 * @param {Node} node The child node inserted
6455 * @param {Node} refNode The child node the node was inserted before
6459 * @event beforeappend
6460 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
6461 * @param {Tree} tree The owner tree
6462 * @param {Node} parent The parent node
6463 * @param {Node} node The child node to be appended
6465 "beforeappend" : true,
6467 * @event beforeremove
6468 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
6469 * @param {Tree} tree The owner tree
6470 * @param {Node} parent The parent node
6471 * @param {Node} node The child node to be removed
6473 "beforeremove" : true,
6476 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
6477 * @param {Tree} tree The owner tree
6478 * @param {Node} node The node being moved
6479 * @param {Node} oldParent The parent of the node
6480 * @param {Node} newParent The new parent the node is moving to
6481 * @param {Number} index The index it is being moved to
6483 "beforemove" : true,
6485 * @event beforeinsert
6486 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
6487 * @param {Tree} tree The owner tree
6488 * @param {Node} parent The parent node
6489 * @param {Node} node The child node to be inserted
6490 * @param {Node} refNode The child node the node is being inserted before
6492 "beforeinsert" : true
6495 Roo.data.Tree.superclass.constructor.call(this);
6498 Roo.extend(Roo.data.Tree, Roo.util.Observable, {
6501 proxyNodeEvent : function(){
6502 return this.fireEvent.apply(this, arguments);
6506 * Returns the root node for this tree.
6509 getRootNode : function(){
6514 * Sets the root node for this tree.
6515 * @param {Node} node
6518 setRootNode : function(node){
6520 node.ownerTree = this;
6522 this.registerNode(node);
6527 * Gets a node in this tree by its id.
6528 * @param {String} id
6531 getNodeById : function(id){
6532 return this.nodeHash[id];
6535 registerNode : function(node){
6536 this.nodeHash[node.id] = node;
6539 unregisterNode : function(node){
6540 delete this.nodeHash[node.id];
6543 toString : function(){
6544 return "[Tree"+(this.id?" "+this.id:"")+"]";
6549 * @class Roo.data.Node
6550 * @extends Roo.util.Observable
6551 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
6552 * @cfg {String} id The id for this node. If one is not specified, one is generated.
6554 * @param {Object} attributes The attributes/config for the node
6556 Roo.data.Node = function(attributes){
6558 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
6561 this.attributes = attributes || {};
6562 this.leaf = this.attributes.leaf;
6564 * The node id. @type String
6566 this.id = this.attributes.id;
6568 this.id = Roo.id(null, "ynode-");
6569 this.attributes.id = this.id;
6572 * All child nodes of this node. @type Array
6574 this.childNodes = [];
6575 if(!this.childNodes.indexOf){ // indexOf is a must
6576 this.childNodes.indexOf = function(o){
6577 for(var i = 0, len = this.length; i < len; i++){
6586 * The parent node for this node. @type Node
6588 this.parentNode = null;
6590 * The first direct child node of this node, or null if this node has no child nodes. @type Node
6592 this.firstChild = null;
6594 * The last direct child node of this node, or null if this node has no child nodes. @type Node
6596 this.lastChild = null;
6598 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
6600 this.previousSibling = null;
6602 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
6604 this.nextSibling = null;
6609 * Fires when a new child node is appended
6610 * @param {Tree} tree The owner tree
6611 * @param {Node} this This node
6612 * @param {Node} node The newly appended node
6613 * @param {Number} index The index of the newly appended node
6618 * Fires when a child node is removed
6619 * @param {Tree} tree The owner tree
6620 * @param {Node} this This node
6621 * @param {Node} node The removed node
6626 * Fires when this node is moved to a new location in the tree
6627 * @param {Tree} tree The owner tree
6628 * @param {Node} this This node
6629 * @param {Node} oldParent The old parent of this node
6630 * @param {Node} newParent The new parent of this node
6631 * @param {Number} index The index it was moved to
6636 * Fires when a new child node is inserted.
6637 * @param {Tree} tree The owner tree
6638 * @param {Node} this This node
6639 * @param {Node} node The child node inserted
6640 * @param {Node} refNode The child node the node was inserted before
6644 * @event beforeappend
6645 * Fires before a new child is appended, return false to cancel the append.
6646 * @param {Tree} tree The owner tree
6647 * @param {Node} this This node
6648 * @param {Node} node The child node to be appended
6650 "beforeappend" : true,
6652 * @event beforeremove
6653 * Fires before a child is removed, return false to cancel the remove.
6654 * @param {Tree} tree The owner tree
6655 * @param {Node} this This node
6656 * @param {Node} node The child node to be removed
6658 "beforeremove" : true,
6661 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
6662 * @param {Tree} tree The owner tree
6663 * @param {Node} this This node
6664 * @param {Node} oldParent The parent of this node
6665 * @param {Node} newParent The new parent this node is moving to
6666 * @param {Number} index The index it is being moved to
6668 "beforemove" : true,
6670 * @event beforeinsert
6671 * Fires before a new child is inserted, return false to cancel the insert.
6672 * @param {Tree} tree The owner tree
6673 * @param {Node} this This node
6674 * @param {Node} node The child node to be inserted
6675 * @param {Node} refNode The child node the node is being inserted before
6677 "beforeinsert" : true
6679 this.listeners = this.attributes.listeners;
6680 Roo.data.Node.superclass.constructor.call(this);
6683 Roo.extend(Roo.data.Node, Roo.util.Observable, {
6684 fireEvent : function(evtName){
6685 // first do standard event for this node
6686 if(Roo.data.Node.superclass.fireEvent.apply(this, arguments) === false){
6689 // then bubble it up to the tree if the event wasn't cancelled
6690 var ot = this.getOwnerTree();
6692 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
6700 * Returns true if this node is a leaf
6703 isLeaf : function(){
6704 return this.leaf === true;
6708 setFirstChild : function(node){
6709 this.firstChild = node;
6713 setLastChild : function(node){
6714 this.lastChild = node;
6719 * Returns true if this node is the last child of its parent
6722 isLast : function(){
6723 return (!this.parentNode ? true : this.parentNode.lastChild == this);
6727 * Returns true if this node is the first child of its parent
6730 isFirst : function(){
6731 return (!this.parentNode ? true : this.parentNode.firstChild == this);
6734 hasChildNodes : function(){
6735 return !this.isLeaf() && this.childNodes.length > 0;
6739 * Insert node(s) as the last child node of this node.
6740 * @param {Node/Array} node The node or Array of nodes to append
6741 * @return {Node} The appended node if single append, or null if an array was passed
6743 appendChild : function(node){
6745 if(node instanceof Array){
6747 }else if(arguments.length > 1){
6750 // if passed an array or multiple args do them one by one
6752 for(var i = 0, len = multi.length; i < len; i++) {
6753 this.appendChild(multi[i]);
6756 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
6759 var index = this.childNodes.length;
6760 var oldParent = node.parentNode;
6761 // it's a move, make sure we move it cleanly
6763 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
6766 oldParent.removeChild(node);
6768 index = this.childNodes.length;
6770 this.setFirstChild(node);
6772 this.childNodes.push(node);
6773 node.parentNode = this;
6774 var ps = this.childNodes[index-1];
6776 node.previousSibling = ps;
6777 ps.nextSibling = node;
6779 node.previousSibling = null;
6781 node.nextSibling = null;
6782 this.setLastChild(node);
6783 node.setOwnerTree(this.getOwnerTree());
6784 this.fireEvent("append", this.ownerTree, this, node, index);
6786 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
6793 * Removes a child node from this node.
6794 * @param {Node} node The node to remove
6795 * @return {Node} The removed node
6797 removeChild : function(node){
6798 var index = this.childNodes.indexOf(node);
6802 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
6806 // remove it from childNodes collection
6807 this.childNodes.splice(index, 1);
6810 if(node.previousSibling){
6811 node.previousSibling.nextSibling = node.nextSibling;
6813 if(node.nextSibling){
6814 node.nextSibling.previousSibling = node.previousSibling;
6817 // update child refs
6818 if(this.firstChild == node){
6819 this.setFirstChild(node.nextSibling);
6821 if(this.lastChild == node){
6822 this.setLastChild(node.previousSibling);
6825 node.setOwnerTree(null);
6826 // clear any references from the node
6827 node.parentNode = null;
6828 node.previousSibling = null;
6829 node.nextSibling = null;
6830 this.fireEvent("remove", this.ownerTree, this, node);
6835 * Inserts the first node before the second node in this nodes childNodes collection.
6836 * @param {Node} node The node to insert
6837 * @param {Node} refNode The node to insert before (if null the node is appended)
6838 * @return {Node} The inserted node
6840 insertBefore : function(node, refNode){
6841 if(!refNode){ // like standard Dom, refNode can be null for append
6842 return this.appendChild(node);
6845 if(node == refNode){
6849 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
6852 var index = this.childNodes.indexOf(refNode);
6853 var oldParent = node.parentNode;
6854 var refIndex = index;
6856 // when moving internally, indexes will change after remove
6857 if(oldParent == this && this.childNodes.indexOf(node) < index){
6861 // it's a move, make sure we move it cleanly
6863 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
6866 oldParent.removeChild(node);
6869 this.setFirstChild(node);
6871 this.childNodes.splice(refIndex, 0, node);
6872 node.parentNode = this;
6873 var ps = this.childNodes[refIndex-1];
6875 node.previousSibling = ps;
6876 ps.nextSibling = node;
6878 node.previousSibling = null;
6880 node.nextSibling = refNode;
6881 refNode.previousSibling = node;
6882 node.setOwnerTree(this.getOwnerTree());
6883 this.fireEvent("insert", this.ownerTree, this, node, refNode);
6885 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
6891 * Returns the child node at the specified index.
6892 * @param {Number} index
6895 item : function(index){
6896 return this.childNodes[index];
6900 * Replaces one child node in this node with another.
6901 * @param {Node} newChild The replacement node
6902 * @param {Node} oldChild The node to replace
6903 * @return {Node} The replaced node
6905 replaceChild : function(newChild, oldChild){
6906 this.insertBefore(newChild, oldChild);
6907 this.removeChild(oldChild);
6912 * Returns the index of a child node
6913 * @param {Node} node
6914 * @return {Number} The index of the node or -1 if it was not found
6916 indexOf : function(child){
6917 return this.childNodes.indexOf(child);
6921 * Returns the tree this node is in.
6924 getOwnerTree : function(){
6925 // if it doesn't have one, look for one
6926 if(!this.ownerTree){
6930 this.ownerTree = p.ownerTree;
6936 return this.ownerTree;
6940 * Returns depth of this node (the root node has a depth of 0)
6943 getDepth : function(){
6946 while(p.parentNode){
6954 setOwnerTree : function(tree){
6955 // if it's move, we need to update everyone
6956 if(tree != this.ownerTree){
6958 this.ownerTree.unregisterNode(this);
6960 this.ownerTree = tree;
6961 var cs = this.childNodes;
6962 for(var i = 0, len = cs.length; i < len; i++) {
6963 cs[i].setOwnerTree(tree);
6966 tree.registerNode(this);
6972 * Returns the path for this node. The path can be used to expand or select this node programmatically.
6973 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
6974 * @return {String} The path
6976 getPath : function(attr){
6977 attr = attr || "id";
6978 var p = this.parentNode;
6979 var b = [this.attributes[attr]];
6981 b.unshift(p.attributes[attr]);
6984 var sep = this.getOwnerTree().pathSeparator;
6985 return sep + b.join(sep);
6989 * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
6990 * function call will be the scope provided or the current node. The arguments to the function
6991 * will be the args provided or the current node. If the function returns false at any point,
6992 * the bubble is stopped.
6993 * @param {Function} fn The function to call
6994 * @param {Object} scope (optional) The scope of the function (defaults to current node)
6995 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
6997 bubble : function(fn, scope, args){
7000 if(fn.call(scope || p, args || p) === false){
7008 * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
7009 * function call will be the scope provided or the current node. The arguments to the function
7010 * will be the args provided or the current node. If the function returns false at any point,
7011 * the cascade is stopped on that branch.
7012 * @param {Function} fn The function to call
7013 * @param {Object} scope (optional) The scope of the function (defaults to current node)
7014 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
7016 cascade : function(fn, scope, args){
7017 if(fn.call(scope || this, args || this) !== false){
7018 var cs = this.childNodes;
7019 for(var i = 0, len = cs.length; i < len; i++) {
7020 cs[i].cascade(fn, scope, args);
7026 * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
7027 * function call will be the scope provided or the current node. The arguments to the function
7028 * will be the args provided or the current node. If the function returns false at any point,
7029 * the iteration stops.
7030 * @param {Function} fn The function to call
7031 * @param {Object} scope (optional) The scope of the function (defaults to current node)
7032 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
7034 eachChild : function(fn, scope, args){
7035 var cs = this.childNodes;
7036 for(var i = 0, len = cs.length; i < len; i++) {
7037 if(fn.call(scope || this, args || cs[i]) === false){
7044 * Finds the first child that has the attribute with the specified value.
7045 * @param {String} attribute The attribute name
7046 * @param {Mixed} value The value to search for
7047 * @return {Node} The found child or null if none was found
7049 findChild : function(attribute, value){
7050 var cs = this.childNodes;
7051 for(var i = 0, len = cs.length; i < len; i++) {
7052 if(cs[i].attributes[attribute] == value){
7060 * Finds the first child by a custom function. The child matches if the function passed
7062 * @param {Function} fn
7063 * @param {Object} scope (optional)
7064 * @return {Node} The found child or null if none was found
7066 findChildBy : function(fn, scope){
7067 var cs = this.childNodes;
7068 for(var i = 0, len = cs.length; i < len; i++) {
7069 if(fn.call(scope||cs[i], cs[i]) === true){
7077 * Sorts this nodes children using the supplied sort function
7078 * @param {Function} fn
7079 * @param {Object} scope (optional)
7081 sort : function(fn, scope){
7082 var cs = this.childNodes;
7083 var len = cs.length;
7085 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
7087 for(var i = 0; i < len; i++){
7089 n.previousSibling = cs[i-1];
7090 n.nextSibling = cs[i+1];
7092 this.setFirstChild(n);
7095 this.setLastChild(n);
7102 * Returns true if this node is an ancestor (at any point) of the passed node.
7103 * @param {Node} node
7106 contains : function(node){
7107 return node.isAncestor(this);
7111 * Returns true if the passed node is an ancestor (at any point) of this node.
7112 * @param {Node} node
7115 isAncestor : function(node){
7116 var p = this.parentNode;
7126 toString : function(){
7127 return "[Node"+(this.id?" "+this.id:"")+"]";
7131 * Ext JS Library 1.1.1
7132 * Copyright(c) 2006-2007, Ext JS, LLC.
7134 * Originally Released Under LGPL - original licence link has changed is not relivant.
7137 * <script type="text/javascript">
7142 * @class Roo.ComponentMgr
7143 * Provides a common registry of all components on a page so that they can be easily accessed by component id (see {@link Roo.getCmp}).
7146 Roo.ComponentMgr = function(){
7147 var all = new Roo.util.MixedCollection();
7151 * Registers a component.
7152 * @param {Roo.Component} c The component
7154 register : function(c){
7159 * Unregisters a component.
7160 * @param {Roo.Component} c The component
7162 unregister : function(c){
7167 * Returns a component by id
7168 * @param {String} id The component id
7175 * Registers a function that will be called when a specified component is added to ComponentMgr
7176 * @param {String} id The component id
7177 * @param {Funtction} fn The callback function
7178 * @param {Object} scope The scope of the callback
7180 onAvailable : function(id, fn, scope){
7181 all.on("add", function(index, o){
7183 fn.call(scope || o, o);
7184 all.un("add", fn, scope);
7191 * Ext JS Library 1.1.1
7192 * Copyright(c) 2006-2007, Ext JS, LLC.
7194 * Originally Released Under LGPL - original licence link has changed is not relivant.
7197 * <script type="text/javascript">
7201 * @class Roo.Component
7202 * @extends Roo.util.Observable
7203 * Base class for all major Roo components. All subclasses of Component can automatically participate in the standard
7204 * Roo component lifecycle of creation, rendering and destruction. They also have automatic support for basic hide/show
7205 * and enable/disable behavior. Component allows any subclass to be lazy-rendered into any {@link Roo.Container} and
7206 * to be automatically registered with the {@link Roo.ComponentMgr} so that it can be referenced at any time via {@link Roo.getCmp}.
7207 * All visual components (widgets) that require rendering into a layout should subclass Component.
7209 * @param {Roo.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal
7210 * 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
7211 * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component.
7213 Roo.Component = function(config){
7214 config = config || {};
7215 if(config.tagName || config.dom || typeof config == "string"){ // element object
7216 config = {el: config, id: config.id || config};
7218 this.initialConfig = config;
7220 Roo.apply(this, config);
7224 * Fires after the component is disabled.
7225 * @param {Roo.Component} this
7230 * Fires after the component is enabled.
7231 * @param {Roo.Component} this
7236 * Fires before the component is shown. Return false to stop the show.
7237 * @param {Roo.Component} this
7242 * Fires after the component is shown.
7243 * @param {Roo.Component} this
7248 * Fires before the component is hidden. Return false to stop the hide.
7249 * @param {Roo.Component} this
7254 * Fires after the component is hidden.
7255 * @param {Roo.Component} this
7259 * @event beforerender
7260 * Fires before the component is rendered. Return false to stop the render.
7261 * @param {Roo.Component} this
7263 beforerender : true,
7266 * Fires after the component is rendered.
7267 * @param {Roo.Component} this
7271 * @event beforedestroy
7272 * Fires before the component is destroyed. Return false to stop the destroy.
7273 * @param {Roo.Component} this
7275 beforedestroy : true,
7278 * Fires after the component is destroyed.
7279 * @param {Roo.Component} this
7284 this.id = "ext-comp-" + (++Roo.Component.AUTO_ID);
7286 Roo.ComponentMgr.register(this);
7287 Roo.Component.superclass.constructor.call(this);
7288 this.initComponent();
7289 if(this.renderTo){ // not supported by all components yet. use at your own risk!
7290 this.render(this.renderTo);
7291 delete this.renderTo;
7296 Roo.Component.AUTO_ID = 1000;
7298 Roo.extend(Roo.Component, Roo.util.Observable, {
7300 * @property {Boolean} hidden
7301 * true if this component is hidden. Read-only.
7305 * true if this component is disabled. Read-only.
7309 * true if this component has been rendered. Read-only.
7313 /** @cfg {String} disableClass
7314 * CSS class added to the component when it is disabled (defaults to "x-item-disabled").
7316 disabledClass : "x-item-disabled",
7317 /** @cfg {Boolean} allowDomMove
7318 * Whether the component can move the Dom node when rendering (defaults to true).
7320 allowDomMove : true,
7321 /** @cfg {String} hideMode
7322 * How this component should hidden. Supported values are
7323 * "visibility" (css visibility), "offsets" (negative offset position) and
7324 * "display" (css display) - defaults to "display".
7326 hideMode: 'display',
7329 ctype : "Roo.Component",
7331 /** @cfg {String} actionMode
7332 * which property holds the element that used for hide() / show() / disable() / enable()
7338 getActionEl : function(){
7339 return this[this.actionMode];
7342 initComponent : Roo.emptyFn,
7344 * If this is a lazy rendering component, render it to its container element.
7345 * @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.
7347 render : function(container, position){
7348 if(!this.rendered && this.fireEvent("beforerender", this) !== false){
7349 if(!container && this.el){
7350 this.el = Roo.get(this.el);
7351 container = this.el.dom.parentNode;
7352 this.allowDomMove = false;
7354 this.container = Roo.get(container);
7355 this.rendered = true;
7356 if(position !== undefined){
7357 if(typeof position == 'number'){
7358 position = this.container.dom.childNodes[position];
7360 position = Roo.getDom(position);
7363 this.onRender(this.container, position || null);
7365 this.el.addClass(this.cls);
7369 this.el.applyStyles(this.style);
7372 this.fireEvent("render", this);
7373 this.afterRender(this.container);
7385 // default function is not really useful
7386 onRender : function(ct, position){
7388 this.el = Roo.get(this.el);
7389 if(this.allowDomMove !== false){
7390 ct.dom.insertBefore(this.el.dom, position);
7396 getAutoCreate : function(){
7397 var cfg = typeof this.autoCreate == "object" ?
7398 this.autoCreate : Roo.apply({}, this.defaultAutoCreate);
7399 if(this.id && !cfg.id){
7406 afterRender : Roo.emptyFn,
7409 * Destroys this component by purging any event listeners, removing the component's element from the DOM,
7410 * removing the component from its {@link Roo.Container} (if applicable) and unregistering it from {@link Roo.ComponentMgr}.
7412 destroy : function(){
7413 if(this.fireEvent("beforedestroy", this) !== false){
7414 this.purgeListeners();
7415 this.beforeDestroy();
7417 this.el.removeAllListeners();
7419 if(this.actionMode == "container"){
7420 this.container.remove();
7424 Roo.ComponentMgr.unregister(this);
7425 this.fireEvent("destroy", this);
7430 beforeDestroy : function(){
7435 onDestroy : function(){
7440 * Returns the underlying {@link Roo.Element}.
7441 * @return {Roo.Element} The element
7448 * Returns the id of this component.
7456 * Try to focus this component.
7457 * @param {Boolean} selectText True to also select the text in this component (if applicable)
7458 * @return {Roo.Component} this
7460 focus : function(selectText){
7463 if(selectText === true){
7464 this.el.dom.select();
7479 * Disable this component.
7480 * @return {Roo.Component} this
7482 disable : function(){
7486 this.disabled = true;
7487 this.fireEvent("disable", this);
7492 onDisable : function(){
7493 this.getActionEl().addClass(this.disabledClass);
7494 this.el.dom.disabled = true;
7498 * Enable this component.
7499 * @return {Roo.Component} this
7501 enable : function(){
7505 this.disabled = false;
7506 this.fireEvent("enable", this);
7511 onEnable : function(){
7512 this.getActionEl().removeClass(this.disabledClass);
7513 this.el.dom.disabled = false;
7517 * Convenience function for setting disabled/enabled by boolean.
7518 * @param {Boolean} disabled
7520 setDisabled : function(disabled){
7521 this[disabled ? "disable" : "enable"]();
7525 * Show this component.
7526 * @return {Roo.Component} this
7529 if(this.fireEvent("beforeshow", this) !== false){
7530 this.hidden = false;
7534 this.fireEvent("show", this);
7540 onShow : function(){
7541 var ae = this.getActionEl();
7542 if(this.hideMode == 'visibility'){
7543 ae.dom.style.visibility = "visible";
7544 }else if(this.hideMode == 'offsets'){
7545 ae.removeClass('x-hidden');
7547 ae.dom.style.display = "";
7552 * Hide this component.
7553 * @return {Roo.Component} this
7556 if(this.fireEvent("beforehide", this) !== false){
7561 this.fireEvent("hide", this);
7567 onHide : function(){
7568 var ae = this.getActionEl();
7569 if(this.hideMode == 'visibility'){
7570 ae.dom.style.visibility = "hidden";
7571 }else if(this.hideMode == 'offsets'){
7572 ae.addClass('x-hidden');
7574 ae.dom.style.display = "none";
7579 * Convenience function to hide or show this component by boolean.
7580 * @param {Boolean} visible True to show, false to hide
7581 * @return {Roo.Component} this
7583 setVisible: function(visible){
7593 * Returns true if this component is visible.
7595 isVisible : function(){
7596 return this.getActionEl().isVisible();
7599 cloneConfig : function(overrides){
7600 overrides = overrides || {};
7601 var id = overrides.id || Roo.id();
7602 var cfg = Roo.applyIf(overrides, this.initialConfig);
7603 cfg.id = id; // prevent dup id
7604 return new this.constructor(cfg);
7608 * Ext JS Library 1.1.1
7609 * Copyright(c) 2006-2007, Ext JS, LLC.
7611 * Originally Released Under LGPL - original licence link has changed is not relivant.
7614 * <script type="text/javascript">
7619 * @extends Roo.Element
7620 * An extended {@link Roo.Element} object that supports a shadow and shim, constrain to viewport and
7621 * automatic maintaining of shadow/shim positions.
7622 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
7623 * @cfg {String/Boolean} shadow True to create a shadow element with default class "x-layer-shadow", or
7624 * you can pass a string with a CSS class name. False turns off the shadow.
7625 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: "div", cls: "x-layer"}).
7626 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
7627 * @cfg {String} cls CSS class to add to the element
7628 * @cfg {Number} zindex Starting z-index (defaults to 11000)
7629 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 3)
7631 * @param {Object} config An object with config options.
7632 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
7635 Roo.Layer = function(config, existingEl){
7636 config = config || {};
7637 var dh = Roo.DomHelper;
7638 var cp = config.parentEl, pel = cp ? Roo.getDom(cp) : document.body;
7640 this.dom = Roo.getDom(existingEl);
7643 var o = config.dh || {tag: "div", cls: "x-layer"};
7644 this.dom = dh.append(pel, o);
7647 this.addClass(config.cls);
7649 this.constrain = config.constrain !== false;
7650 this.visibilityMode = Roo.Element.VISIBILITY;
7652 this.id = this.dom.id = config.id;
7654 this.id = Roo.id(this.dom);
7656 this.zindex = config.zindex || this.getZIndex();
7657 this.position("absolute", this.zindex);
7659 this.shadowOffset = config.shadowOffset || 4;
7660 this.shadow = new Roo.Shadow({
7661 offset : this.shadowOffset,
7662 mode : config.shadow
7665 this.shadowOffset = 0;
7667 this.useShim = config.shim !== false && Roo.useShims;
7668 this.useDisplay = config.useDisplay;
7672 var supr = Roo.Element.prototype;
7674 // shims are shared among layer to keep from having 100 iframes
7677 Roo.extend(Roo.Layer, Roo.Element, {
7679 getZIndex : function(){
7680 return this.zindex || parseInt(this.getStyle("z-index"), 10) || 11000;
7683 getShim : function(){
7690 var shim = shims.shift();
7692 shim = this.createShim();
7693 shim.enableDisplayMode('block');
7694 shim.dom.style.display = 'none';
7695 shim.dom.style.visibility = 'visible';
7697 var pn = this.dom.parentNode;
7698 if(shim.dom.parentNode != pn){
7699 pn.insertBefore(shim.dom, this.dom);
7701 shim.setStyle('z-index', this.getZIndex()-2);
7706 hideShim : function(){
7708 this.shim.setDisplayed(false);
7709 shims.push(this.shim);
7714 disableShadow : function(){
7716 this.shadowDisabled = true;
7718 this.lastShadowOffset = this.shadowOffset;
7719 this.shadowOffset = 0;
7723 enableShadow : function(show){
7725 this.shadowDisabled = false;
7726 this.shadowOffset = this.lastShadowOffset;
7727 delete this.lastShadowOffset;
7735 // this code can execute repeatedly in milliseconds (i.e. during a drag) so
7736 // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
7737 sync : function(doShow){
7738 var sw = this.shadow;
7739 if(!this.updating && this.isVisible() && (sw || this.useShim)){
7740 var sh = this.getShim();
7742 var w = this.getWidth(),
7743 h = this.getHeight();
7745 var l = this.getLeft(true),
7746 t = this.getTop(true);
7748 if(sw && !this.shadowDisabled){
7749 if(doShow && !sw.isVisible()){
7752 sw.realign(l, t, w, h);
7758 // fit the shim behind the shadow, so it is shimmed too
7759 var a = sw.adjusts, s = sh.dom.style;
7760 s.left = (Math.min(l, l+a.l))+"px";
7761 s.top = (Math.min(t, t+a.t))+"px";
7762 s.width = (w+a.w)+"px";
7763 s.height = (h+a.h)+"px";
7770 sh.setLeftTop(l, t);
7777 destroy : function(){
7782 this.removeAllListeners();
7783 var pn = this.dom.parentNode;
7785 pn.removeChild(this.dom);
7787 Roo.Element.uncache(this.id);
7790 remove : function(){
7795 beginUpdate : function(){
7796 this.updating = true;
7800 endUpdate : function(){
7801 this.updating = false;
7806 hideUnders : function(negOffset){
7814 constrainXY : function(){
7816 var vw = Roo.lib.Dom.getViewWidth(),
7817 vh = Roo.lib.Dom.getViewHeight();
7818 var s = Roo.get(document).getScroll();
7820 var xy = this.getXY();
7821 var x = xy[0], y = xy[1];
7822 var w = this.dom.offsetWidth+this.shadowOffset, h = this.dom.offsetHeight+this.shadowOffset;
7823 // only move it if it needs it
7825 // first validate right/bottom
7826 if((x + w) > vw+s.left){
7827 x = vw - w - this.shadowOffset;
7830 if((y + h) > vh+s.top){
7831 y = vh - h - this.shadowOffset;
7834 // then make sure top/left isn't negative
7845 var ay = this.avoidY;
7846 if(y <= ay && (y+h) >= ay){
7852 supr.setXY.call(this, xy);
7858 isVisible : function(){
7859 return this.visible;
7863 showAction : function(){
7864 this.visible = true; // track visibility to prevent getStyle calls
7865 if(this.useDisplay === true){
7866 this.setDisplayed("");
7867 }else if(this.lastXY){
7868 supr.setXY.call(this, this.lastXY);
7869 }else if(this.lastLT){
7870 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
7875 hideAction : function(){
7876 this.visible = false;
7877 if(this.useDisplay === true){
7878 this.setDisplayed(false);
7880 this.setLeftTop(-10000,-10000);
7884 // overridden Element method
7885 setVisible : function(v, a, d, c, e){
7890 var cb = function(){
7895 }.createDelegate(this);
7896 supr.setVisible.call(this, true, true, d, cb, e);
7899 this.hideUnders(true);
7908 }.createDelegate(this);
7910 supr.setVisible.call(this, v, a, d, cb, e);
7919 storeXY : function(xy){
7924 storeLeftTop : function(left, top){
7926 this.lastLT = [left, top];
7930 beforeFx : function(){
7931 this.beforeAction();
7932 return Roo.Layer.superclass.beforeFx.apply(this, arguments);
7936 afterFx : function(){
7937 Roo.Layer.superclass.afterFx.apply(this, arguments);
7938 this.sync(this.isVisible());
7942 beforeAction : function(){
7943 if(!this.updating && this.shadow){
7948 // overridden Element method
7949 setLeft : function(left){
7950 this.storeLeftTop(left, this.getTop(true));
7951 supr.setLeft.apply(this, arguments);
7955 setTop : function(top){
7956 this.storeLeftTop(this.getLeft(true), top);
7957 supr.setTop.apply(this, arguments);
7961 setLeftTop : function(left, top){
7962 this.storeLeftTop(left, top);
7963 supr.setLeftTop.apply(this, arguments);
7967 setXY : function(xy, a, d, c, e){
7969 this.beforeAction();
7971 var cb = this.createCB(c);
7972 supr.setXY.call(this, xy, a, d, cb, e);
7979 createCB : function(c){
7990 // overridden Element method
7991 setX : function(x, a, d, c, e){
7992 this.setXY([x, this.getY()], a, d, c, e);
7995 // overridden Element method
7996 setY : function(y, a, d, c, e){
7997 this.setXY([this.getX(), y], a, d, c, e);
8000 // overridden Element method
8001 setSize : function(w, h, a, d, c, e){
8002 this.beforeAction();
8003 var cb = this.createCB(c);
8004 supr.setSize.call(this, w, h, a, d, cb, e);
8010 // overridden Element method
8011 setWidth : function(w, a, d, c, e){
8012 this.beforeAction();
8013 var cb = this.createCB(c);
8014 supr.setWidth.call(this, w, a, d, cb, e);
8020 // overridden Element method
8021 setHeight : function(h, a, d, c, e){
8022 this.beforeAction();
8023 var cb = this.createCB(c);
8024 supr.setHeight.call(this, h, a, d, cb, e);
8030 // overridden Element method
8031 setBounds : function(x, y, w, h, a, d, c, e){
8032 this.beforeAction();
8033 var cb = this.createCB(c);
8035 this.storeXY([x, y]);
8036 supr.setXY.call(this, [x, y]);
8037 supr.setSize.call(this, w, h, a, d, cb, e);
8040 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
8046 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
8047 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
8048 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
8049 * @param {Number} zindex The new z-index to set
8050 * @return {this} The Layer
8052 setZIndex : function(zindex){
8053 this.zindex = zindex;
8054 this.setStyle("z-index", zindex + 2);
8056 this.shadow.setZIndex(zindex + 1);
8059 this.shim.setStyle("z-index", zindex);
8065 * Ext JS Library 1.1.1
8066 * Copyright(c) 2006-2007, Ext JS, LLC.
8068 * Originally Released Under LGPL - original licence link has changed is not relivant.
8071 * <script type="text/javascript">
8077 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
8078 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
8079 * functionality that can also provide the same shadow effect, see the {@link Roo.Layer} class.
8081 * Create a new Shadow
8082 * @param {Object} config The config object
8084 Roo.Shadow = function(config){
8085 Roo.apply(this, config);
8086 if(typeof this.mode != "string"){
8087 this.mode = this.defaultMode;
8089 var o = this.offset, a = {h: 0};
8090 var rad = Math.floor(this.offset/2);
8091 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
8097 a.l -= this.offset + rad;
8098 a.t -= this.offset + rad;
8109 a.l -= (this.offset - rad);
8110 a.t -= this.offset + rad;
8112 a.w -= (this.offset - rad)*2;
8123 a.l -= (this.offset - rad);
8124 a.t -= (this.offset - rad);
8126 a.w -= (this.offset + rad + 1);
8127 a.h -= (this.offset + rad);
8136 Roo.Shadow.prototype = {
8138 * @cfg {String} mode
8139 * The shadow display mode. Supports the following options:<br />
8140 * sides: Shadow displays on both sides and bottom only<br />
8141 * frame: Shadow displays equally on all four sides<br />
8142 * drop: Traditional bottom-right drop shadow (default)
8145 * @cfg {String} offset
8146 * The number of pixels to offset the shadow from the element (defaults to 4)
8151 defaultMode: "drop",
8154 * Displays the shadow under the target element
8155 * @param {String/HTMLElement/Element} targetEl The id or element under which the shadow should display
8157 show : function(target){
8158 target = Roo.get(target);
8160 this.el = Roo.Shadow.Pool.pull();
8161 if(this.el.dom.nextSibling != target.dom){
8162 this.el.insertBefore(target);
8165 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
8167 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
8170 target.getLeft(true),
8171 target.getTop(true),
8175 this.el.dom.style.display = "block";
8179 * Returns true if the shadow is visible, else false
8181 isVisible : function(){
8182 return this.el ? true : false;
8186 * Direct alignment when values are already available. Show must be called at least once before
8187 * calling this method to ensure it is initialized.
8188 * @param {Number} left The target element left position
8189 * @param {Number} top The target element top position
8190 * @param {Number} width The target element width
8191 * @param {Number} height The target element height
8193 realign : function(l, t, w, h){
8197 var a = this.adjusts, d = this.el.dom, s = d.style;
8199 s.left = (l+a.l)+"px";
8200 s.top = (t+a.t)+"px";
8201 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
8203 if(s.width != sws || s.height != shs){
8207 var cn = d.childNodes;
8208 var sww = Math.max(0, (sw-12))+"px";
8209 cn[0].childNodes[1].style.width = sww;
8210 cn[1].childNodes[1].style.width = sww;
8211 cn[2].childNodes[1].style.width = sww;
8212 cn[1].style.height = Math.max(0, (sh-12))+"px";
8222 this.el.dom.style.display = "none";
8223 Roo.Shadow.Pool.push(this.el);
8229 * Adjust the z-index of this shadow
8230 * @param {Number} zindex The new z-index
8232 setZIndex : function(z){
8235 this.el.setStyle("z-index", z);
8240 // Private utility class that manages the internal Shadow cache
8241 Roo.Shadow.Pool = function(){
8243 var markup = Roo.isIE ?
8244 '<div class="x-ie-shadow"></div>' :
8245 '<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>';
8250 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
8251 sh.autoBoxAdjust = false;
8256 push : function(sh){
8262 * Ext JS Library 1.1.1
8263 * Copyright(c) 2006-2007, Ext JS, LLC.
8265 * Originally Released Under LGPL - original licence link has changed is not relivant.
8268 * <script type="text/javascript">
8272 * @class Roo.BoxComponent
8273 * @extends Roo.Component
8274 * Base class for any visual {@link Roo.Component} that uses a box container. BoxComponent provides automatic box
8275 * model adjustments for sizing and positioning and will work correctly withnin the Component rendering model. All
8276 * container classes should subclass BoxComponent so that they will work consistently when nested within other Ext
8277 * layout containers.
8279 * @param {Roo.Element/String/Object} config The configuration options.
8281 Roo.BoxComponent = function(config){
8282 Roo.Component.call(this, config);
8286 * Fires after the component is resized.
8287 * @param {Roo.Component} this
8288 * @param {Number} adjWidth The box-adjusted width that was set
8289 * @param {Number} adjHeight The box-adjusted height that was set
8290 * @param {Number} rawWidth The width that was originally specified
8291 * @param {Number} rawHeight The height that was originally specified
8296 * Fires after the component is moved.
8297 * @param {Roo.Component} this
8298 * @param {Number} x The new x position
8299 * @param {Number} y The new y position
8305 Roo.extend(Roo.BoxComponent, Roo.Component, {
8306 // private, set in afterRender to signify that the component has been rendered
8308 // private, used to defer height settings to subclasses
8310 /** @cfg {Number} width
8311 * width (optional) size of component
8313 /** @cfg {Number} height
8314 * height (optional) size of component
8318 * Sets the width and height of the component. This method fires the resize event. This method can accept
8319 * either width and height as separate numeric arguments, or you can pass a size object like {width:10, height:20}.
8320 * @param {Number/Object} width The new width to set, or a size object in the format {width, height}
8321 * @param {Number} height The new height to set (not required if a size object is passed as the first arg)
8322 * @return {Roo.BoxComponent} this
8324 setSize : function(w, h){
8325 // support for standard size objects
8326 if(typeof w == 'object'){
8337 // prevent recalcs when not needed
8338 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
8341 this.lastSize = {width: w, height: h};
8343 var adj = this.adjustSize(w, h);
8344 var aw = adj.width, ah = adj.height;
8345 if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
8346 var rz = this.getResizeEl();
8347 if(!this.deferHeight && aw !== undefined && ah !== undefined){
8349 }else if(!this.deferHeight && ah !== undefined){
8351 }else if(aw !== undefined){
8354 this.onResize(aw, ah, w, h);
8355 this.fireEvent('resize', this, aw, ah, w, h);
8361 * Gets the current size of the component's underlying element.
8362 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
8364 getSize : function(){
8365 return this.el.getSize();
8369 * Gets the current XY position of the component's underlying element.
8370 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
8371 * @return {Array} The XY position of the element (e.g., [100, 200])
8373 getPosition : function(local){
8375 return [this.el.getLeft(true), this.el.getTop(true)];
8377 return this.xy || this.el.getXY();
8381 * Gets the current box measurements of the component's underlying element.
8382 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
8383 * @returns {Object} box An object in the format {x, y, width, height}
8385 getBox : function(local){
8386 var s = this.el.getSize();
8388 s.x = this.el.getLeft(true);
8389 s.y = this.el.getTop(true);
8391 var xy = this.xy || this.el.getXY();
8399 * Sets the current box measurements of the component's underlying element.
8400 * @param {Object} box An object in the format {x, y, width, height}
8401 * @returns {Roo.BoxComponent} this
8403 updateBox : function(box){
8404 this.setSize(box.width, box.height);
8405 this.setPagePosition(box.x, box.y);
8410 getResizeEl : function(){
8411 return this.resizeEl || this.el;
8415 getPositionEl : function(){
8416 return this.positionEl || this.el;
8420 * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
8421 * This method fires the move event.
8422 * @param {Number} left The new left
8423 * @param {Number} top The new top
8424 * @returns {Roo.BoxComponent} this
8426 setPosition : function(x, y){
8432 var adj = this.adjustPosition(x, y);
8433 var ax = adj.x, ay = adj.y;
8435 var el = this.getPositionEl();
8436 if(ax !== undefined || ay !== undefined){
8437 if(ax !== undefined && ay !== undefined){
8438 el.setLeftTop(ax, ay);
8439 }else if(ax !== undefined){
8441 }else if(ay !== undefined){
8444 this.onPosition(ax, ay);
8445 this.fireEvent('move', this, ax, ay);
8451 * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
8452 * This method fires the move event.
8453 * @param {Number} x The new x position
8454 * @param {Number} y The new y position
8455 * @returns {Roo.BoxComponent} this
8457 setPagePosition : function(x, y){
8463 if(x === undefined || y === undefined){ // cannot translate undefined points
8466 var p = this.el.translatePoints(x, y);
8467 this.setPosition(p.left, p.top);
8472 onRender : function(ct, position){
8473 Roo.BoxComponent.superclass.onRender.call(this, ct, position);
8475 this.resizeEl = Roo.get(this.resizeEl);
8477 if(this.positionEl){
8478 this.positionEl = Roo.get(this.positionEl);
8483 afterRender : function(){
8484 Roo.BoxComponent.superclass.afterRender.call(this);
8485 this.boxReady = true;
8486 this.setSize(this.width, this.height);
8487 if(this.x || this.y){
8488 this.setPosition(this.x, this.y);
8490 if(this.pageX || this.pageY){
8491 this.setPagePosition(this.pageX, this.pageY);
8496 * Force the component's size to recalculate based on the underlying element's current height and width.
8497 * @returns {Roo.BoxComponent} this
8499 syncSize : function(){
8500 delete this.lastSize;
8501 this.setSize(this.el.getWidth(), this.el.getHeight());
8506 * Called after the component is resized, this method is empty by default but can be implemented by any
8507 * subclass that needs to perform custom logic after a resize occurs.
8508 * @param {Number} adjWidth The box-adjusted width that was set
8509 * @param {Number} adjHeight The box-adjusted height that was set
8510 * @param {Number} rawWidth The width that was originally specified
8511 * @param {Number} rawHeight The height that was originally specified
8513 onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
8518 * Called after the component is moved, this method is empty by default but can be implemented by any
8519 * subclass that needs to perform custom logic after a move occurs.
8520 * @param {Number} x The new x position
8521 * @param {Number} y The new y position
8523 onPosition : function(x, y){
8528 adjustSize : function(w, h){
8532 if(this.autoHeight){
8535 return {width : w, height: h};
8539 adjustPosition : function(x, y){
8540 return {x : x, y: y};
8544 * Ext JS Library 1.1.1
8545 * Copyright(c) 2006-2007, Ext JS, LLC.
8547 * Originally Released Under LGPL - original licence link has changed is not relivant.
8550 * <script type="text/javascript">
8555 * @class Roo.SplitBar
8556 * @extends Roo.util.Observable
8557 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
8561 var split = new Roo.SplitBar("elementToDrag", "elementToSize",
8562 Roo.SplitBar.HORIZONTAL, Roo.SplitBar.LEFT);
8563 split.setAdapter(new Roo.SplitBar.AbsoluteLayoutAdapter("container"));
8564 split.minSize = 100;
8565 split.maxSize = 600;
8566 split.animate = true;
8567 split.on('moved', splitterMoved);
8570 * Create a new SplitBar
8571 * @param {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
8572 * @param {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
8573 * @param {Number} orientation (optional) Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
8574 * @param {Number} placement (optional) Either Roo.SplitBar.LEFT or Roo.SplitBar.RIGHT for horizontal or
8575 Roo.SplitBar.TOP or Roo.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
8576 position of the SplitBar).
8578 Roo.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
8581 this.el = Roo.get(dragElement, true);
8582 this.el.dom.unselectable = "on";
8584 this.resizingEl = Roo.get(resizingElement, true);
8588 * The orientation of the split. Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
8589 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
8592 this.orientation = orientation || Roo.SplitBar.HORIZONTAL;
8595 * The minimum size of the resizing element. (Defaults to 0)
8601 * The maximum size of the resizing element. (Defaults to 2000)
8604 this.maxSize = 2000;
8607 * Whether to animate the transition to the new size
8610 this.animate = false;
8613 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
8616 this.useShim = false;
8623 this.proxy = Roo.SplitBar.createProxy(this.orientation);
8625 this.proxy = Roo.get(existingProxy).dom;
8628 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
8631 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
8634 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
8637 this.dragSpecs = {};
8640 * @private The adapter to use to positon and resize elements
8642 this.adapter = new Roo.SplitBar.BasicLayoutAdapter();
8643 this.adapter.init(this);
8645 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8647 this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Roo.SplitBar.LEFT : Roo.SplitBar.RIGHT);
8648 this.el.addClass("x-splitbar-h");
8651 this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Roo.SplitBar.TOP : Roo.SplitBar.BOTTOM);
8652 this.el.addClass("x-splitbar-v");
8658 * Fires when the splitter is moved (alias for {@link #event-moved})
8659 * @param {Roo.SplitBar} this
8660 * @param {Number} newSize the new width or height
8665 * Fires when the splitter is moved
8666 * @param {Roo.SplitBar} this
8667 * @param {Number} newSize the new width or height
8671 * @event beforeresize
8672 * Fires before the splitter is dragged
8673 * @param {Roo.SplitBar} this
8675 "beforeresize" : true,
8677 "beforeapply" : true
8680 Roo.util.Observable.call(this);
8683 Roo.extend(Roo.SplitBar, Roo.util.Observable, {
8684 onStartProxyDrag : function(x, y){
8685 this.fireEvent("beforeresize", this);
8687 var o = Roo.DomHelper.insertFirst(document.body, {cls: "x-drag-overlay", html: " "}, true);
8689 o.enableDisplayMode("block");
8690 // all splitbars share the same overlay
8691 Roo.SplitBar.prototype.overlay = o;
8693 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
8694 this.overlay.show();
8695 Roo.get(this.proxy).setDisplayed("block");
8696 var size = this.adapter.getElementSize(this);
8697 this.activeMinSize = this.getMinimumSize();;
8698 this.activeMaxSize = this.getMaximumSize();;
8699 var c1 = size - this.activeMinSize;
8700 var c2 = Math.max(this.activeMaxSize - size, 0);
8701 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8702 this.dd.resetConstraints();
8703 this.dd.setXConstraint(
8704 this.placement == Roo.SplitBar.LEFT ? c1 : c2,
8705 this.placement == Roo.SplitBar.LEFT ? c2 : c1
8707 this.dd.setYConstraint(0, 0);
8709 this.dd.resetConstraints();
8710 this.dd.setXConstraint(0, 0);
8711 this.dd.setYConstraint(
8712 this.placement == Roo.SplitBar.TOP ? c1 : c2,
8713 this.placement == Roo.SplitBar.TOP ? c2 : c1
8716 this.dragSpecs.startSize = size;
8717 this.dragSpecs.startPoint = [x, y];
8718 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
8722 * @private Called after the drag operation by the DDProxy
8724 onEndProxyDrag : function(e){
8725 Roo.get(this.proxy).setDisplayed(false);
8726 var endPoint = Roo.lib.Event.getXY(e);
8728 this.overlay.hide();
8731 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8732 newSize = this.dragSpecs.startSize +
8733 (this.placement == Roo.SplitBar.LEFT ?
8734 endPoint[0] - this.dragSpecs.startPoint[0] :
8735 this.dragSpecs.startPoint[0] - endPoint[0]
8738 newSize = this.dragSpecs.startSize +
8739 (this.placement == Roo.SplitBar.TOP ?
8740 endPoint[1] - this.dragSpecs.startPoint[1] :
8741 this.dragSpecs.startPoint[1] - endPoint[1]
8744 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
8745 if(newSize != this.dragSpecs.startSize){
8746 if(this.fireEvent('beforeapply', this, newSize) !== false){
8747 this.adapter.setElementSize(this, newSize);
8748 this.fireEvent("moved", this, newSize);
8749 this.fireEvent("resize", this, newSize);
8755 * Get the adapter this SplitBar uses
8756 * @return The adapter object
8758 getAdapter : function(){
8759 return this.adapter;
8763 * Set the adapter this SplitBar uses
8764 * @param {Object} adapter A SplitBar adapter object
8766 setAdapter : function(adapter){
8767 this.adapter = adapter;
8768 this.adapter.init(this);
8772 * Gets the minimum size for the resizing element
8773 * @return {Number} The minimum size
8775 getMinimumSize : function(){
8776 return this.minSize;
8780 * Sets the minimum size for the resizing element
8781 * @param {Number} minSize The minimum size
8783 setMinimumSize : function(minSize){
8784 this.minSize = minSize;
8788 * Gets the maximum size for the resizing element
8789 * @return {Number} The maximum size
8791 getMaximumSize : function(){
8792 return this.maxSize;
8796 * Sets the maximum size for the resizing element
8797 * @param {Number} maxSize The maximum size
8799 setMaximumSize : function(maxSize){
8800 this.maxSize = maxSize;
8804 * Sets the initialize size for the resizing element
8805 * @param {Number} size The initial size
8807 setCurrentSize : function(size){
8808 var oldAnimate = this.animate;
8809 this.animate = false;
8810 this.adapter.setElementSize(this, size);
8811 this.animate = oldAnimate;
8815 * Destroy this splitbar.
8816 * @param {Boolean} removeEl True to remove the element
8818 destroy : function(removeEl){
8823 this.proxy.parentNode.removeChild(this.proxy);
8831 * @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.
8833 Roo.SplitBar.createProxy = function(dir){
8834 var proxy = new Roo.Element(document.createElement("div"));
8835 proxy.unselectable();
8836 var cls = 'x-splitbar-proxy';
8837 proxy.addClass(cls + ' ' + (dir == Roo.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
8838 document.body.appendChild(proxy.dom);
8843 * @class Roo.SplitBar.BasicLayoutAdapter
8844 * Default Adapter. It assumes the splitter and resizing element are not positioned
8845 * elements and only gets/sets the width of the element. Generally used for table based layouts.
8847 Roo.SplitBar.BasicLayoutAdapter = function(){
8850 Roo.SplitBar.BasicLayoutAdapter.prototype = {
8851 // do nothing for now
8856 * Called before drag operations to get the current size of the resizing element.
8857 * @param {Roo.SplitBar} s The SplitBar using this adapter
8859 getElementSize : function(s){
8860 if(s.orientation == Roo.SplitBar.HORIZONTAL){
8861 return s.resizingEl.getWidth();
8863 return s.resizingEl.getHeight();
8868 * Called after drag operations to set the size of the resizing element.
8869 * @param {Roo.SplitBar} s The SplitBar using this adapter
8870 * @param {Number} newSize The new size to set
8871 * @param {Function} onComplete A function to be invoked when resizing is complete
8873 setElementSize : function(s, newSize, onComplete){
8874 if(s.orientation == Roo.SplitBar.HORIZONTAL){
8876 s.resizingEl.setWidth(newSize);
8878 onComplete(s, newSize);
8881 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
8886 s.resizingEl.setHeight(newSize);
8888 onComplete(s, newSize);
8891 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
8898 *@class Roo.SplitBar.AbsoluteLayoutAdapter
8899 * @extends Roo.SplitBar.BasicLayoutAdapter
8900 * Adapter that moves the splitter element to align with the resized sizing element.
8901 * Used with an absolute positioned SplitBar.
8902 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
8903 * document.body, make sure you assign an id to the body element.
8905 Roo.SplitBar.AbsoluteLayoutAdapter = function(container){
8906 this.basic = new Roo.SplitBar.BasicLayoutAdapter();
8907 this.container = Roo.get(container);
8910 Roo.SplitBar.AbsoluteLayoutAdapter.prototype = {
8915 getElementSize : function(s){
8916 return this.basic.getElementSize(s);
8919 setElementSize : function(s, newSize, onComplete){
8920 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
8923 moveSplitter : function(s){
8924 var yes = Roo.SplitBar;
8925 switch(s.placement){
8927 s.el.setX(s.resizingEl.getRight());
8930 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
8933 s.el.setY(s.resizingEl.getBottom());
8936 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
8943 * Orientation constant - Create a vertical SplitBar
8947 Roo.SplitBar.VERTICAL = 1;
8950 * Orientation constant - Create a horizontal SplitBar
8954 Roo.SplitBar.HORIZONTAL = 2;
8957 * Placement constant - The resizing element is to the left of the splitter element
8961 Roo.SplitBar.LEFT = 1;
8964 * Placement constant - The resizing element is to the right of the splitter element
8968 Roo.SplitBar.RIGHT = 2;
8971 * Placement constant - The resizing element is positioned above the splitter element
8975 Roo.SplitBar.TOP = 3;
8978 * Placement constant - The resizing element is positioned under splitter element
8982 Roo.SplitBar.BOTTOM = 4;
8985 * Ext JS Library 1.1.1
8986 * Copyright(c) 2006-2007, Ext JS, LLC.
8988 * Originally Released Under LGPL - original licence link has changed is not relivant.
8991 * <script type="text/javascript">
8996 * @extends Roo.util.Observable
8997 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
8998 * This class also supports single and multi selection modes. <br>
8999 * Create a data model bound view:
9001 var store = new Roo.data.Store(...);
9003 var view = new Roo.View({
9005 tpl : '<div id="{0}">{2} - {1}</div>', // auto create template
9008 selectedClass: "ydataview-selected",
9012 // listen for node click?
9013 view.on("click", function(vw, index, node, e){
9014 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
9018 dataModel.load("foobar.xml");
9020 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
9022 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
9023 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
9025 * Note: old style constructor is still suported (container, template, config)
9029 * @param {Object} config The config object
9032 Roo.View = function(config, depreciated_tpl, depreciated_config){
9034 if (typeof(depreciated_tpl) == 'undefined') {
9035 // new way.. - universal constructor.
9036 Roo.apply(this, config);
9037 this.el = Roo.get(this.el);
9040 this.el = Roo.get(config);
9041 this.tpl = depreciated_tpl;
9042 Roo.apply(this, depreciated_config);
9046 if(typeof(this.tpl) == "string"){
9047 this.tpl = new Roo.Template(this.tpl);
9049 // support xtype ctors..
9050 this.tpl = new Roo.factory(this.tpl, Roo);
9061 * @event beforeclick
9062 * Fires before a click is processed. Returns false to cancel the default action.
9063 * @param {Roo.View} this
9064 * @param {Number} index The index of the target node
9065 * @param {HTMLElement} node The target node
9066 * @param {Roo.EventObject} e The raw event object
9068 "beforeclick" : true,
9071 * Fires when a template node is clicked.
9072 * @param {Roo.View} this
9073 * @param {Number} index The index of the target node
9074 * @param {HTMLElement} node The target node
9075 * @param {Roo.EventObject} e The raw event object
9080 * Fires when a template node is double clicked.
9081 * @param {Roo.View} this
9082 * @param {Number} index The index of the target node
9083 * @param {HTMLElement} node The target node
9084 * @param {Roo.EventObject} e The raw event object
9088 * @event contextmenu
9089 * Fires when a template node is right clicked.
9090 * @param {Roo.View} this
9091 * @param {Number} index The index of the target node
9092 * @param {HTMLElement} node The target node
9093 * @param {Roo.EventObject} e The raw event object
9095 "contextmenu" : true,
9097 * @event selectionchange
9098 * Fires when the selected nodes change.
9099 * @param {Roo.View} this
9100 * @param {Array} selections Array of the selected nodes
9102 "selectionchange" : true,
9105 * @event beforeselect
9106 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
9107 * @param {Roo.View} this
9108 * @param {HTMLElement} node The node to be selected
9109 * @param {Array} selections Array of currently selected nodes
9111 "beforeselect" : true
9115 "click": this.onClick,
9116 "dblclick": this.onDblClick,
9117 "contextmenu": this.onContextMenu,
9121 this.selections = [];
9123 this.cmp = new Roo.CompositeElementLite([]);
9125 this.store = Roo.factory(this.store, Roo.data);
9126 this.setStore(this.store, true);
9128 Roo.View.superclass.constructor.call(this);
9131 Roo.extend(Roo.View, Roo.util.Observable, {
9134 * @cfg {Roo.data.Store} store Data store to load data from.
9139 * @cfg {String|Roo.Element} el The container element.
9144 * @cfg {String|Roo.Template} tpl The template used by this View
9149 * @cfg {String} selectedClass The css class to add to selected nodes
9151 selectedClass : "x-view-selected",
9153 * @cfg {String} emptyText The empty text to show when nothing is loaded.
9157 * @cfg {Boolean} multiSelect Allow multiple selection
9160 multiSelect : false,
9162 * @cfg {Boolean} singleSelect Allow single selection
9164 singleSelect: false,
9167 * Returns the element this view is bound to.
9168 * @return {Roo.Element}
9175 * Refreshes the view.
9177 refresh : function(){
9179 this.clearSelections();
9182 var records = this.store.getRange();
9183 if(records.length < 1){
9184 this.el.update(this.emptyText);
9187 for(var i = 0, len = records.length; i < len; i++){
9188 var data = this.prepareData(records[i].data, i, records[i]);
9189 html[html.length] = t.apply(data);
9191 this.el.update(html.join(""));
9192 this.nodes = this.el.dom.childNodes;
9193 this.updateIndexes(0);
9197 * Function to override to reformat the data that is sent to
9198 * the template for each node.
9199 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
9200 * a JSON object for an UpdateManager bound view).
9202 prepareData : function(data){
9206 onUpdate : function(ds, record){
9207 this.clearSelections();
9208 var index = this.store.indexOf(record);
9209 var n = this.nodes[index];
9210 this.tpl.insertBefore(n, this.prepareData(record.data));
9211 n.parentNode.removeChild(n);
9212 this.updateIndexes(index, index);
9215 onAdd : function(ds, records, index){
9216 this.clearSelections();
9217 if(this.nodes.length == 0){
9221 var n = this.nodes[index];
9222 for(var i = 0, len = records.length; i < len; i++){
9223 var d = this.prepareData(records[i].data);
9225 this.tpl.insertBefore(n, d);
9227 this.tpl.append(this.el, d);
9230 this.updateIndexes(index);
9233 onRemove : function(ds, record, index){
9234 this.clearSelections();
9235 this.el.dom.removeChild(this.nodes[index]);
9236 this.updateIndexes(index);
9240 * Refresh an individual node.
9241 * @param {Number} index
9243 refreshNode : function(index){
9244 this.onUpdate(this.store, this.store.getAt(index));
9247 updateIndexes : function(startIndex, endIndex){
9248 var ns = this.nodes;
9249 startIndex = startIndex || 0;
9250 endIndex = endIndex || ns.length - 1;
9251 for(var i = startIndex; i <= endIndex; i++){
9252 ns[i].nodeIndex = i;
9257 * Changes the data store this view uses and refresh the view.
9258 * @param {Store} store
9260 setStore : function(store, initial){
9261 if(!initial && this.store){
9262 this.store.un("datachanged", this.refresh);
9263 this.store.un("add", this.onAdd);
9264 this.store.un("remove", this.onRemove);
9265 this.store.un("update", this.onUpdate);
9266 this.store.un("clear", this.refresh);
9270 store.on("datachanged", this.refresh, this);
9271 store.on("add", this.onAdd, this);
9272 store.on("remove", this.onRemove, this);
9273 store.on("update", this.onUpdate, this);
9274 store.on("clear", this.refresh, this);
9283 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
9284 * @param {HTMLElement} node
9285 * @return {HTMLElement} The template node
9287 findItemFromChild : function(node){
9288 var el = this.el.dom;
9289 if(!node || node.parentNode == el){
9292 var p = node.parentNode;
9293 while(p && p != el){
9294 if(p.parentNode == el){
9303 onClick : function(e){
9304 var item = this.findItemFromChild(e.getTarget());
9306 var index = this.indexOf(item);
9307 if(this.onItemClick(item, index, e) !== false){
9308 this.fireEvent("click", this, index, item, e);
9311 this.clearSelections();
9316 onContextMenu : function(e){
9317 var item = this.findItemFromChild(e.getTarget());
9319 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
9324 onDblClick : function(e){
9325 var item = this.findItemFromChild(e.getTarget());
9327 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
9331 onItemClick : function(item, index, e){
9332 if(this.fireEvent("beforeclick", this, index, item, e) === false){
9335 if(this.multiSelect || this.singleSelect){
9336 if(this.multiSelect && e.shiftKey && this.lastSelection){
9337 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
9339 this.select(item, this.multiSelect && e.ctrlKey);
9340 this.lastSelection = item;
9348 * Get the number of selected nodes.
9351 getSelectionCount : function(){
9352 return this.selections.length;
9356 * Get the currently selected nodes.
9357 * @return {Array} An array of HTMLElements
9359 getSelectedNodes : function(){
9360 return this.selections;
9364 * Get the indexes of the selected nodes.
9367 getSelectedIndexes : function(){
9368 var indexes = [], s = this.selections;
9369 for(var i = 0, len = s.length; i < len; i++){
9370 indexes.push(s[i].nodeIndex);
9376 * Clear all selections
9377 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
9379 clearSelections : function(suppressEvent){
9380 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
9381 this.cmp.elements = this.selections;
9382 this.cmp.removeClass(this.selectedClass);
9383 this.selections = [];
9385 this.fireEvent("selectionchange", this, this.selections);
9391 * Returns true if the passed node is selected
9392 * @param {HTMLElement/Number} node The node or node index
9395 isSelected : function(node){
9396 var s = this.selections;
9400 node = this.getNode(node);
9401 return s.indexOf(node) !== -1;
9406 * @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
9407 * @param {Boolean} keepExisting (optional) true to keep existing selections
9408 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
9410 select : function(nodeInfo, keepExisting, suppressEvent){
9411 if(nodeInfo instanceof Array){
9413 this.clearSelections(true);
9415 for(var i = 0, len = nodeInfo.length; i < len; i++){
9416 this.select(nodeInfo[i], true, true);
9419 var node = this.getNode(nodeInfo);
9420 if(node && !this.isSelected(node)){
9422 this.clearSelections(true);
9424 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
9425 Roo.fly(node).addClass(this.selectedClass);
9426 this.selections.push(node);
9428 this.fireEvent("selectionchange", this, this.selections);
9436 * Gets a template node.
9437 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
9438 * @return {HTMLElement} The node or null if it wasn't found
9440 getNode : function(nodeInfo){
9441 if(typeof nodeInfo == "string"){
9442 return document.getElementById(nodeInfo);
9443 }else if(typeof nodeInfo == "number"){
9444 return this.nodes[nodeInfo];
9450 * Gets a range template nodes.
9451 * @param {Number} startIndex
9452 * @param {Number} endIndex
9453 * @return {Array} An array of nodes
9455 getNodes : function(start, end){
9456 var ns = this.nodes;
9458 end = typeof end == "undefined" ? ns.length - 1 : end;
9461 for(var i = start; i <= end; i++){
9465 for(var i = start; i >= end; i--){
9473 * Finds the index of the passed node
9474 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
9475 * @return {Number} The index of the node or -1
9477 indexOf : function(node){
9478 node = this.getNode(node);
9479 if(typeof node.nodeIndex == "number"){
9480 return node.nodeIndex;
9482 var ns = this.nodes;
9483 for(var i = 0, len = ns.length; i < len; i++){
9493 * Ext JS Library 1.1.1
9494 * Copyright(c) 2006-2007, Ext JS, LLC.
9496 * Originally Released Under LGPL - original licence link has changed is not relivant.
9499 * <script type="text/javascript">
9503 * @class Roo.JsonView
9505 * Shortcut class to create a JSON + {@link Roo.UpdateManager} template view. Usage:
9507 var view = new Roo.JsonView({
9508 container: "my-element",
9509 tpl: '<div id="{id}">{foo} - {bar}</div>', // auto create template
9514 // listen for node click?
9515 view.on("click", function(vw, index, node, e){
9516 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
9519 // direct load of JSON data
9520 view.load("foobar.php");
9522 // Example from my blog list
9523 var tpl = new Roo.Template(
9524 '<div class="entry">' +
9525 '<a class="entry-title" href="{link}">{title}</a>' +
9526 "<h4>{date} by {author} | {comments} Comments</h4>{description}" +
9527 "</div><hr />"
9530 var moreView = new Roo.JsonView({
9531 container : "entry-list",
9535 moreView.on("beforerender", this.sortEntries, this);
9537 url: "/blog/get-posts.php",
9538 params: "allposts=true",
9539 text: "Loading Blog Entries..."
9543 * Note: old code is supported with arguments : (container, template, config)
9547 * Create a new JsonView
9549 * @param {Object} config The config object
9552 Roo.JsonView = function(config, depreciated_tpl, depreciated_config){
9555 Roo.JsonView.superclass.constructor.call(this, config, depreciated_tpl, depreciated_config);
9557 var um = this.el.getUpdateManager();
9558 um.setRenderer(this);
9559 um.on("update", this.onLoad, this);
9560 um.on("failure", this.onLoadException, this);
9563 * @event beforerender
9564 * Fires before rendering of the downloaded JSON data.
9565 * @param {Roo.JsonView} this
9566 * @param {Object} data The JSON data loaded
9570 * Fires when data is loaded.
9571 * @param {Roo.JsonView} this
9572 * @param {Object} data The JSON data loaded
9573 * @param {Object} response The raw Connect response object
9576 * @event loadexception
9577 * Fires when loading fails.
9578 * @param {Roo.JsonView} this
9579 * @param {Object} response The raw Connect response object
9582 'beforerender' : true,
9584 'loadexception' : true
9587 Roo.extend(Roo.JsonView, Roo.View, {
9589 * @type {String} The root property in the loaded JSON object that contains the data
9594 * Refreshes the view.
9596 refresh : function(){
9597 this.clearSelections();
9600 var o = this.jsonData;
9601 if(o && o.length > 0){
9602 for(var i = 0, len = o.length; i < len; i++){
9603 var data = this.prepareData(o[i], i, o);
9604 html[html.length] = this.tpl.apply(data);
9607 html.push(this.emptyText);
9609 this.el.update(html.join(""));
9610 this.nodes = this.el.dom.childNodes;
9611 this.updateIndexes(0);
9615 * 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.
9616 * @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:
9619 url: "your-url.php",
9620 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
9621 callback: yourFunction,
9622 scope: yourObject, //(optional scope)
9630 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
9631 * 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.
9632 * @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}
9633 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
9634 * @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.
9637 var um = this.el.getUpdateManager();
9638 um.update.apply(um, arguments);
9641 render : function(el, response){
9642 this.clearSelections();
9646 o = Roo.util.JSON.decode(response.responseText);
9649 o = o[this.jsonRoot];
9654 * The current JSON data or null
9657 this.beforeRender();
9662 * Get the number of records in the current JSON dataset
9665 getCount : function(){
9666 return this.jsonData ? this.jsonData.length : 0;
9670 * Returns the JSON object for the specified node(s)
9671 * @param {HTMLElement/Array} node The node or an array of nodes
9672 * @return {Object/Array} If you pass in an array, you get an array back, otherwise
9673 * you get the JSON object for the node
9675 getNodeData : function(node){
9676 if(node instanceof Array){
9678 for(var i = 0, len = node.length; i < len; i++){
9679 data.push(this.getNodeData(node[i]));
9683 return this.jsonData[this.indexOf(node)] || null;
9686 beforeRender : function(){
9687 this.snapshot = this.jsonData;
9689 this.sort.apply(this, this.sortInfo);
9691 this.fireEvent("beforerender", this, this.jsonData);
9694 onLoad : function(el, o){
9695 this.fireEvent("load", this, this.jsonData, o);
9698 onLoadException : function(el, o){
9699 this.fireEvent("loadexception", this, o);
9703 * Filter the data by a specific property.
9704 * @param {String} property A property on your JSON objects
9705 * @param {String/RegExp} value Either string that the property values
9706 * should start with, or a RegExp to test against the property
9708 filter : function(property, value){
9711 var ss = this.snapshot;
9712 if(typeof value == "string"){
9713 var vlen = value.length;
9718 value = value.toLowerCase();
9719 for(var i = 0, len = ss.length; i < len; i++){
9721 if(o[property].substr(0, vlen).toLowerCase() == value){
9725 } else if(value.exec){ // regex?
9726 for(var i = 0, len = ss.length; i < len; i++){
9728 if(value.test(o[property])){
9735 this.jsonData = data;
9741 * Filter by a function. The passed function will be called with each
9742 * object in the current dataset. If the function returns true the value is kept,
9743 * otherwise it is filtered.
9744 * @param {Function} fn
9745 * @param {Object} scope (optional) The scope of the function (defaults to this JsonView)
9747 filterBy : function(fn, scope){
9750 var ss = this.snapshot;
9751 for(var i = 0, len = ss.length; i < len; i++){
9753 if(fn.call(scope || this, o)){
9757 this.jsonData = data;
9763 * Clears the current filter.
9765 clearFilter : function(){
9766 if(this.snapshot && this.jsonData != this.snapshot){
9767 this.jsonData = this.snapshot;
9774 * Sorts the data for this view and refreshes it.
9775 * @param {String} property A property on your JSON objects to sort on
9776 * @param {String} direction (optional) "desc" or "asc" (defaults to "asc")
9777 * @param {Function} sortType (optional) A function to call to convert the data to a sortable value.
9779 sort : function(property, dir, sortType){
9780 this.sortInfo = Array.prototype.slice.call(arguments, 0);
9783 var dsc = dir && dir.toLowerCase() == "desc";
9784 var f = function(o1, o2){
9785 var v1 = sortType ? sortType(o1[p]) : o1[p];
9786 var v2 = sortType ? sortType(o2[p]) : o2[p];
9789 return dsc ? +1 : -1;
9791 return dsc ? -1 : +1;
9796 this.jsonData.sort(f);
9798 if(this.jsonData != this.snapshot){
9799 this.snapshot.sort(f);
9805 * Ext JS Library 1.1.1
9806 * Copyright(c) 2006-2007, Ext JS, LLC.
9808 * Originally Released Under LGPL - original licence link has changed is not relivant.
9811 * <script type="text/javascript">
9816 * @class Roo.ColorPalette
9817 * @extends Roo.Component
9818 * Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
9819 * Here's an example of typical usage:
9821 var cp = new Roo.ColorPalette({value:'993300'}); // initial selected color
9822 cp.render('my-div');
9824 cp.on('select', function(palette, selColor){
9825 // do something with selColor
9829 * Create a new ColorPalette
9830 * @param {Object} config The config object
9832 Roo.ColorPalette = function(config){
9833 Roo.ColorPalette.superclass.constructor.call(this, config);
9837 * Fires when a color is selected
9838 * @param {ColorPalette} this
9839 * @param {String} color The 6-digit color hex code (without the # symbol)
9845 this.on("select", this.handler, this.scope, true);
9848 Roo.extend(Roo.ColorPalette, Roo.Component, {
9850 * @cfg {String} itemCls
9851 * The CSS class to apply to the containing element (defaults to "x-color-palette")
9853 itemCls : "x-color-palette",
9855 * @cfg {String} value
9856 * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
9857 * the hex codes are case-sensitive.
9862 ctype: "Roo.ColorPalette",
9865 * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the selection event
9867 allowReselect : false,
9870 * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
9871 * of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
9872 * the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
9873 * of colors with the width setting until the box is symmetrical.</p>
9874 * <p>You can override individual colors if needed:</p>
9876 var cp = new Roo.ColorPalette();
9877 cp.colors[0] = "FF0000"; // change the first box to red
9880 Or you can provide a custom array of your own for complete control:
9882 var cp = new Roo.ColorPalette();
9883 cp.colors = ["000000", "993300", "333300"];
9888 "000000", "993300", "333300", "003300", "003366", "000080", "333399", "333333",
9889 "800000", "FF6600", "808000", "008000", "008080", "0000FF", "666699", "808080",
9890 "FF0000", "FF9900", "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696",
9891 "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF", "993366", "C0C0C0",
9892 "FF99CC", "FFCC99", "FFFF99", "CCFFCC", "CCFFFF", "99CCFF", "CC99FF", "FFFFFF"
9896 onRender : function(container, position){
9897 var t = new Roo.MasterTemplate(
9898 '<tpl><a href="#" class="color-{0}" hidefocus="on"><em><span style="background:#{0}" unselectable="on"> </span></em></a></tpl>'
9900 var c = this.colors;
9901 for(var i = 0, len = c.length; i < len; i++){
9904 var el = document.createElement("div");
9905 el.className = this.itemCls;
9907 container.dom.insertBefore(el, position);
9908 this.el = Roo.get(el);
9909 this.el.on(this.clickEvent, this.handleClick, this, {delegate: "a"});
9910 if(this.clickEvent != 'click'){
9911 this.el.on('click', Roo.emptyFn, this, {delegate: "a", preventDefault:true});
9916 afterRender : function(){
9917 Roo.ColorPalette.superclass.afterRender.call(this);
9926 handleClick : function(e, t){
9929 var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
9930 this.select(c.toUpperCase());
9935 * Selects the specified color in the palette (fires the select event)
9936 * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
9938 select : function(color){
9939 color = color.replace("#", "");
9940 if(color != this.value || this.allowReselect){
9943 el.child("a.color-"+this.value).removeClass("x-color-palette-sel");
9945 el.child("a.color-"+color).addClass("x-color-palette-sel");
9947 this.fireEvent("select", this, color);
9952 * Ext JS Library 1.1.1
9953 * Copyright(c) 2006-2007, Ext JS, LLC.
9955 * Originally Released Under LGPL - original licence link has changed is not relivant.
9958 * <script type="text/javascript">
9962 * @class Roo.DatePicker
9963 * @extends Roo.Component
9964 * Simple date picker class.
9966 * Create a new DatePicker
9967 * @param {Object} config The config object
9969 Roo.DatePicker = function(config){
9970 Roo.DatePicker.superclass.constructor.call(this, config);
9972 this.value = config && config.value ?
9973 config.value.clearTime() : new Date().clearTime();
9978 * Fires when a date is selected
9979 * @param {DatePicker} this
9980 * @param {Date} date The selected date
9986 this.on("select", this.handler, this.scope || this);
9988 // build the disabledDatesRE
9989 if(!this.disabledDatesRE && this.disabledDates){
9990 var dd = this.disabledDates;
9992 for(var i = 0; i < dd.length; i++){
9994 if(i != dd.length-1) re += "|";
9996 this.disabledDatesRE = new RegExp(re + ")");
10000 Roo.extend(Roo.DatePicker, Roo.Component, {
10002 * @cfg {String} todayText
10003 * The text to display on the button that selects the current date (defaults to "Today")
10005 todayText : "Today",
10007 * @cfg {String} okText
10008 * The text to display on the ok button
10010 okText : " OK ", //   to give the user extra clicking room
10012 * @cfg {String} cancelText
10013 * The text to display on the cancel button
10015 cancelText : "Cancel",
10017 * @cfg {String} todayTip
10018 * The tooltip to display for the button that selects the current date (defaults to "{current date} (Spacebar)")
10020 todayTip : "{0} (Spacebar)",
10022 * @cfg {Date} minDate
10023 * Minimum allowable date (JavaScript date object, defaults to null)
10027 * @cfg {Date} maxDate
10028 * Maximum allowable date (JavaScript date object, defaults to null)
10032 * @cfg {String} minText
10033 * The error text to display if the minDate validation fails (defaults to "This date is before the minimum date")
10035 minText : "This date is before the minimum date",
10037 * @cfg {String} maxText
10038 * The error text to display if the maxDate validation fails (defaults to "This date is after the maximum date")
10040 maxText : "This date is after the maximum date",
10042 * @cfg {String} format
10043 * The default date format string which can be overriden for localization support. The format must be
10044 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
10048 * @cfg {Array} disabledDays
10049 * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
10051 disabledDays : null,
10053 * @cfg {String} disabledDaysText
10054 * The tooltip to display when the date falls on a disabled day (defaults to "")
10056 disabledDaysText : "",
10058 * @cfg {RegExp} disabledDatesRE
10059 * JavaScript regular expression used to disable a pattern of dates (defaults to null)
10061 disabledDatesRE : null,
10063 * @cfg {String} disabledDatesText
10064 * The tooltip text to display when the date falls on a disabled date (defaults to "")
10066 disabledDatesText : "",
10068 * @cfg {Boolean} constrainToViewport
10069 * True to constrain the date picker to the viewport (defaults to true)
10071 constrainToViewport : true,
10073 * @cfg {Array} monthNames
10074 * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
10076 monthNames : Date.monthNames,
10078 * @cfg {Array} dayNames
10079 * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
10081 dayNames : Date.dayNames,
10083 * @cfg {String} nextText
10084 * The next month navigation button tooltip (defaults to 'Next Month (Control+Right)')
10086 nextText: 'Next Month (Control+Right)',
10088 * @cfg {String} prevText
10089 * The previous month navigation button tooltip (defaults to 'Previous Month (Control+Left)')
10091 prevText: 'Previous Month (Control+Left)',
10093 * @cfg {String} monthYearText
10094 * The header month selector tooltip (defaults to 'Choose a month (Control+Up/Down to move years)')
10096 monthYearText: 'Choose a month (Control+Up/Down to move years)',
10098 * @cfg {Number} startDay
10099 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
10103 * @cfg {Bool} showClear
10104 * Show a clear button (usefull for date form elements that can be blank.)
10110 * Sets the value of the date field
10111 * @param {Date} value The date to set
10113 setValue : function(value){
10114 var old = this.value;
10115 this.value = value.clearTime(true);
10117 this.update(this.value);
10122 * Gets the current selected value of the date field
10123 * @return {Date} The selected date
10125 getValue : function(){
10130 focus : function(){
10132 this.update(this.activeDate);
10137 onRender : function(container, position){
10139 '<table cellspacing="0">',
10140 '<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>',
10141 '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'];
10142 var dn = this.dayNames;
10143 for(var i = 0; i < 7; i++){
10144 var d = this.startDay+i;
10148 m.push("<th><span>", dn[d].substr(0,1), "</span></th>");
10150 m[m.length] = "</tr></thead><tbody><tr>";
10151 for(var i = 0; i < 42; i++) {
10152 if(i % 7 == 0 && i != 0){
10153 m[m.length] = "</tr><tr>";
10155 m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
10157 m[m.length] = '</tr></tbody></table></td></tr><tr>'+
10158 '<td colspan="3" class="x-date-bottom" align="center"></td></tr></table><div class="x-date-mp"></div>';
10160 var el = document.createElement("div");
10161 el.className = "x-date-picker";
10162 el.innerHTML = m.join("");
10164 container.dom.insertBefore(el, position);
10166 this.el = Roo.get(el);
10167 this.eventEl = Roo.get(el.firstChild);
10169 new Roo.util.ClickRepeater(this.el.child("td.x-date-left a"), {
10170 handler: this.showPrevMonth,
10172 preventDefault:true,
10176 new Roo.util.ClickRepeater(this.el.child("td.x-date-right a"), {
10177 handler: this.showNextMonth,
10179 preventDefault:true,
10183 this.eventEl.on("mousewheel", this.handleMouseWheel, this);
10185 this.monthPicker = this.el.down('div.x-date-mp');
10186 this.monthPicker.enableDisplayMode('block');
10188 var kn = new Roo.KeyNav(this.eventEl, {
10189 "left" : function(e){
10191 this.showPrevMonth() :
10192 this.update(this.activeDate.add("d", -1));
10195 "right" : function(e){
10197 this.showNextMonth() :
10198 this.update(this.activeDate.add("d", 1));
10201 "up" : function(e){
10203 this.showNextYear() :
10204 this.update(this.activeDate.add("d", -7));
10207 "down" : function(e){
10209 this.showPrevYear() :
10210 this.update(this.activeDate.add("d", 7));
10213 "pageUp" : function(e){
10214 this.showNextMonth();
10217 "pageDown" : function(e){
10218 this.showPrevMonth();
10221 "enter" : function(e){
10222 e.stopPropagation();
10229 this.eventEl.on("click", this.handleDateClick, this, {delegate: "a.x-date-date"});
10231 this.eventEl.addKeyListener(Roo.EventObject.SPACE, this.selectToday, this);
10233 this.el.unselectable();
10235 this.cells = this.el.select("table.x-date-inner tbody td");
10236 this.textNodes = this.el.query("table.x-date-inner tbody span");
10238 this.mbtn = new Roo.Button(this.el.child("td.x-date-middle", true), {
10240 tooltip: this.monthYearText
10243 this.mbtn.on('click', this.showMonthPicker, this);
10244 this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu");
10247 var today = (new Date()).dateFormat(this.format);
10249 var baseTb = new Roo.Toolbar(this.el.child("td.x-date-bottom", true));
10250 if (this.showClear) {
10251 baseTb.add( new Roo.Toolbar.Fill());
10254 text: String.format(this.todayText, today),
10255 tooltip: String.format(this.todayTip, today),
10256 handler: this.selectToday,
10260 //var todayBtn = new Roo.Button(this.el.child("td.x-date-bottom", true), {
10263 if (this.showClear) {
10265 baseTb.add( new Roo.Toolbar.Fill());
10268 cls: 'x-btn-icon x-btn-clear',
10269 handler: function() {
10271 this.fireEvent("select", this, '');
10281 this.update(this.value);
10284 createMonthPicker : function(){
10285 if(!this.monthPicker.dom.firstChild){
10286 var buf = ['<table border="0" cellspacing="0">'];
10287 for(var i = 0; i < 6; i++){
10289 '<tr><td class="x-date-mp-month"><a href="#">', this.monthNames[i].substr(0, 3), '</a></td>',
10290 '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', this.monthNames[i+6].substr(0, 3), '</a></td>',
10292 '<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>' :
10293 '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
10297 '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
10299 '</button><button type="button" class="x-date-mp-cancel">',
10301 '</button></td></tr>',
10304 this.monthPicker.update(buf.join(''));
10305 this.monthPicker.on('click', this.onMonthClick, this);
10306 this.monthPicker.on('dblclick', this.onMonthDblClick, this);
10308 this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
10309 this.mpYears = this.monthPicker.select('td.x-date-mp-year');
10311 this.mpMonths.each(function(m, a, i){
10314 m.dom.xmonth = 5 + Math.round(i * .5);
10316 m.dom.xmonth = Math.round((i-1) * .5);
10322 showMonthPicker : function(){
10323 this.createMonthPicker();
10324 var size = this.el.getSize();
10325 this.monthPicker.setSize(size);
10326 this.monthPicker.child('table').setSize(size);
10328 this.mpSelMonth = (this.activeDate || this.value).getMonth();
10329 this.updateMPMonth(this.mpSelMonth);
10330 this.mpSelYear = (this.activeDate || this.value).getFullYear();
10331 this.updateMPYear(this.mpSelYear);
10333 this.monthPicker.slideIn('t', {duration:.2});
10336 updateMPYear : function(y){
10338 var ys = this.mpYears.elements;
10339 for(var i = 1; i <= 10; i++){
10340 var td = ys[i-1], y2;
10342 y2 = y + Math.round(i * .5);
10343 td.firstChild.innerHTML = y2;
10346 y2 = y - (5-Math.round(i * .5));
10347 td.firstChild.innerHTML = y2;
10350 this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
10354 updateMPMonth : function(sm){
10355 this.mpMonths.each(function(m, a, i){
10356 m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
10360 selectMPMonth: function(m){
10364 onMonthClick : function(e, t){
10366 var el = new Roo.Element(t), pn;
10367 if(el.is('button.x-date-mp-cancel')){
10368 this.hideMonthPicker();
10370 else if(el.is('button.x-date-mp-ok')){
10371 this.update(new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
10372 this.hideMonthPicker();
10374 else if(pn = el.up('td.x-date-mp-month', 2)){
10375 this.mpMonths.removeClass('x-date-mp-sel');
10376 pn.addClass('x-date-mp-sel');
10377 this.mpSelMonth = pn.dom.xmonth;
10379 else if(pn = el.up('td.x-date-mp-year', 2)){
10380 this.mpYears.removeClass('x-date-mp-sel');
10381 pn.addClass('x-date-mp-sel');
10382 this.mpSelYear = pn.dom.xyear;
10384 else if(el.is('a.x-date-mp-prev')){
10385 this.updateMPYear(this.mpyear-10);
10387 else if(el.is('a.x-date-mp-next')){
10388 this.updateMPYear(this.mpyear+10);
10392 onMonthDblClick : function(e, t){
10394 var el = new Roo.Element(t), pn;
10395 if(pn = el.up('td.x-date-mp-month', 2)){
10396 this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
10397 this.hideMonthPicker();
10399 else if(pn = el.up('td.x-date-mp-year', 2)){
10400 this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
10401 this.hideMonthPicker();
10405 hideMonthPicker : function(disableAnim){
10406 if(this.monthPicker){
10407 if(disableAnim === true){
10408 this.monthPicker.hide();
10410 this.monthPicker.slideOut('t', {duration:.2});
10416 showPrevMonth : function(e){
10417 this.update(this.activeDate.add("mo", -1));
10421 showNextMonth : function(e){
10422 this.update(this.activeDate.add("mo", 1));
10426 showPrevYear : function(){
10427 this.update(this.activeDate.add("y", -1));
10431 showNextYear : function(){
10432 this.update(this.activeDate.add("y", 1));
10436 handleMouseWheel : function(e){
10437 var delta = e.getWheelDelta();
10439 this.showPrevMonth();
10441 } else if(delta < 0){
10442 this.showNextMonth();
10448 handleDateClick : function(e, t){
10450 if(t.dateValue && !Roo.fly(t.parentNode).hasClass("x-date-disabled")){
10451 this.setValue(new Date(t.dateValue));
10452 this.fireEvent("select", this, this.value);
10457 selectToday : function(){
10458 this.setValue(new Date().clearTime());
10459 this.fireEvent("select", this, this.value);
10463 update : function(date){
10464 var vd = this.activeDate;
10465 this.activeDate = date;
10467 var t = date.getTime();
10468 if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
10469 this.cells.removeClass("x-date-selected");
10470 this.cells.each(function(c){
10471 if(c.dom.firstChild.dateValue == t){
10472 c.addClass("x-date-selected");
10473 setTimeout(function(){
10474 try{c.dom.firstChild.focus();}catch(e){}
10482 var days = date.getDaysInMonth();
10483 var firstOfMonth = date.getFirstDateOfMonth();
10484 var startingPos = firstOfMonth.getDay()-this.startDay;
10486 if(startingPos <= this.startDay){
10490 var pm = date.add("mo", -1);
10491 var prevStart = pm.getDaysInMonth()-startingPos;
10493 var cells = this.cells.elements;
10494 var textEls = this.textNodes;
10495 days += startingPos;
10497 // convert everything to numbers so it's fast
10498 var day = 86400000;
10499 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
10500 var today = new Date().clearTime().getTime();
10501 var sel = date.clearTime().getTime();
10502 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
10503 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
10504 var ddMatch = this.disabledDatesRE;
10505 var ddText = this.disabledDatesText;
10506 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
10507 var ddaysText = this.disabledDaysText;
10508 var format = this.format;
10510 var setCellClass = function(cal, cell){
10512 var t = d.getTime();
10513 cell.firstChild.dateValue = t;
10515 cell.className += " x-date-today";
10516 cell.title = cal.todayText;
10519 cell.className += " x-date-selected";
10520 setTimeout(function(){
10521 try{cell.firstChild.focus();}catch(e){}
10526 cell.className = " x-date-disabled";
10527 cell.title = cal.minText;
10531 cell.className = " x-date-disabled";
10532 cell.title = cal.maxText;
10536 if(ddays.indexOf(d.getDay()) != -1){
10537 cell.title = ddaysText;
10538 cell.className = " x-date-disabled";
10541 if(ddMatch && format){
10542 var fvalue = d.dateFormat(format);
10543 if(ddMatch.test(fvalue)){
10544 cell.title = ddText.replace("%0", fvalue);
10545 cell.className = " x-date-disabled";
10551 for(; i < startingPos; i++) {
10552 textEls[i].innerHTML = (++prevStart);
10553 d.setDate(d.getDate()+1);
10554 cells[i].className = "x-date-prevday";
10555 setCellClass(this, cells[i]);
10557 for(; i < days; i++){
10558 intDay = i - startingPos + 1;
10559 textEls[i].innerHTML = (intDay);
10560 d.setDate(d.getDate()+1);
10561 cells[i].className = "x-date-active";
10562 setCellClass(this, cells[i]);
10565 for(; i < 42; i++) {
10566 textEls[i].innerHTML = (++extraDays);
10567 d.setDate(d.getDate()+1);
10568 cells[i].className = "x-date-nextday";
10569 setCellClass(this, cells[i]);
10572 this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear());
10574 if(!this.internalRender){
10575 var main = this.el.dom.firstChild;
10576 var w = main.offsetWidth;
10577 this.el.setWidth(w + this.el.getBorderWidth("lr"));
10578 Roo.fly(main).setWidth(w);
10579 this.internalRender = true;
10580 // opera does not respect the auto grow header center column
10581 // then, after it gets a width opera refuses to recalculate
10582 // without a second pass
10583 if(Roo.isOpera && !this.secondPass){
10584 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
10585 this.secondPass = true;
10586 this.update.defer(10, this, [date]);
10592 * Ext JS Library 1.1.1
10593 * Copyright(c) 2006-2007, Ext JS, LLC.
10595 * Originally Released Under LGPL - original licence link has changed is not relivant.
10598 * <script type="text/javascript">
10601 * @class Roo.TabPanel
10602 * @extends Roo.util.Observable
10603 * A lightweight tab container.
10607 // basic tabs 1, built from existing content
10608 var tabs = new Roo.TabPanel("tabs1");
10609 tabs.addTab("script", "View Script");
10610 tabs.addTab("markup", "View Markup");
10611 tabs.activate("script");
10613 // more advanced tabs, built from javascript
10614 var jtabs = new Roo.TabPanel("jtabs");
10615 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
10617 // set up the UpdateManager
10618 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
10619 var updater = tab2.getUpdateManager();
10620 updater.setDefaultUrl("ajax1.htm");
10621 tab2.on('activate', updater.refresh, updater, true);
10623 // Use setUrl for Ajax loading
10624 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
10625 tab3.setUrl("ajax2.htm", null, true);
10628 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
10631 jtabs.activate("jtabs-1");
10634 * Create a new TabPanel.
10635 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
10636 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
10638 Roo.TabPanel = function(container, config){
10640 * The container element for this TabPanel.
10641 * @type Roo.Element
10643 this.el = Roo.get(container, true);
10645 if(typeof config == "boolean"){
10646 this.tabPosition = config ? "bottom" : "top";
10648 Roo.apply(this, config);
10651 if(this.tabPosition == "bottom"){
10652 this.bodyEl = Roo.get(this.createBody(this.el.dom));
10653 this.el.addClass("x-tabs-bottom");
10655 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
10656 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
10657 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
10659 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
10661 if(this.tabPosition != "bottom"){
10662 /** The body element that contains {@link Roo.TabPanelItem} bodies.
10663 * @type Roo.Element
10665 this.bodyEl = Roo.get(this.createBody(this.el.dom));
10666 this.el.addClass("x-tabs-top");
10670 this.bodyEl.setStyle("position", "relative");
10672 this.active = null;
10673 this.activateDelegate = this.activate.createDelegate(this);
10678 * Fires when the active tab changes
10679 * @param {Roo.TabPanel} this
10680 * @param {Roo.TabPanelItem} activePanel The new active tab
10684 * @event beforetabchange
10685 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
10686 * @param {Roo.TabPanel} this
10687 * @param {Object} e Set cancel to true on this object to cancel the tab change
10688 * @param {Roo.TabPanelItem} tab The tab being changed to
10690 "beforetabchange" : true
10693 Roo.EventManager.onWindowResize(this.onResize, this);
10694 this.cpad = this.el.getPadding("lr");
10695 this.hiddenCount = 0;
10697 Roo.TabPanel.superclass.constructor.call(this);
10700 Roo.extend(Roo.TabPanel, Roo.util.Observable, {
10702 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
10704 tabPosition : "top",
10706 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
10708 currentTabWidth : 0,
10710 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
10714 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
10718 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
10720 preferredTabWidth : 175,
10722 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
10724 resizeTabs : false,
10726 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
10728 monitorResize : true,
10731 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
10732 * @param {String} id The id of the div to use <b>or create</b>
10733 * @param {String} text The text for the tab
10734 * @param {String} content (optional) Content to put in the TabPanelItem body
10735 * @param {Boolean} closable (optional) True to create a close icon on the tab
10736 * @return {Roo.TabPanelItem} The created TabPanelItem
10738 addTab : function(id, text, content, closable){
10739 var item = new Roo.TabPanelItem(this, id, text, closable);
10740 this.addTabItem(item);
10742 item.setContent(content);
10748 * Returns the {@link Roo.TabPanelItem} with the specified id/index
10749 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
10750 * @return {Roo.TabPanelItem}
10752 getTab : function(id){
10753 return this.items[id];
10757 * Hides the {@link Roo.TabPanelItem} with the specified id/index
10758 * @param {String/Number} id The id or index of the TabPanelItem to hide.
10760 hideTab : function(id){
10761 var t = this.items[id];
10764 this.hiddenCount++;
10765 this.autoSizeTabs();
10770 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
10771 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
10773 unhideTab : function(id){
10774 var t = this.items[id];
10776 t.setHidden(false);
10777 this.hiddenCount--;
10778 this.autoSizeTabs();
10783 * Adds an existing {@link Roo.TabPanelItem}.
10784 * @param {Roo.TabPanelItem} item The TabPanelItem to add
10786 addTabItem : function(item){
10787 this.items[item.id] = item;
10788 this.items.push(item);
10789 if(this.resizeTabs){
10790 item.setWidth(this.currentTabWidth || this.preferredTabWidth);
10791 this.autoSizeTabs();
10798 * Removes a {@link Roo.TabPanelItem}.
10799 * @param {String/Number} id The id or index of the TabPanelItem to remove.
10801 removeTab : function(id){
10802 var items = this.items;
10803 var tab = items[id];
10804 if(!tab) { return; }
10805 var index = items.indexOf(tab);
10806 if(this.active == tab && items.length > 1){
10807 var newTab = this.getNextAvailable(index);
10812 this.stripEl.dom.removeChild(tab.pnode.dom);
10813 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
10814 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
10816 items.splice(index, 1);
10817 delete this.items[tab.id];
10818 tab.fireEvent("close", tab);
10819 tab.purgeListeners();
10820 this.autoSizeTabs();
10823 getNextAvailable : function(start){
10824 var items = this.items;
10826 // look for a next tab that will slide over to
10827 // replace the one being removed
10828 while(index < items.length){
10829 var item = items[++index];
10830 if(item && !item.isHidden()){
10834 // if one isn't found select the previous tab (on the left)
10837 var item = items[--index];
10838 if(item && !item.isHidden()){
10846 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
10847 * @param {String/Number} id The id or index of the TabPanelItem to disable.
10849 disableTab : function(id){
10850 var tab = this.items[id];
10851 if(tab && this.active != tab){
10857 * Enables a {@link Roo.TabPanelItem} that is disabled.
10858 * @param {String/Number} id The id or index of the TabPanelItem to enable.
10860 enableTab : function(id){
10861 var tab = this.items[id];
10866 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
10867 * @param {String/Number} id The id or index of the TabPanelItem to activate.
10868 * @return {Roo.TabPanelItem} The TabPanelItem.
10870 activate : function(id){
10871 var tab = this.items[id];
10875 if(tab == this.active || tab.disabled){
10879 this.fireEvent("beforetabchange", this, e, tab);
10880 if(e.cancel !== true && !tab.disabled){
10882 this.active.hide();
10884 this.active = this.items[id];
10885 this.active.show();
10886 this.fireEvent("tabchange", this, this.active);
10892 * Gets the active {@link Roo.TabPanelItem}.
10893 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
10895 getActiveTab : function(){
10896 return this.active;
10900 * Updates the tab body element to fit the height of the container element
10901 * for overflow scrolling
10902 * @param {Number} targetHeight (optional) Override the starting height from the elements height
10904 syncHeight : function(targetHeight){
10905 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
10906 var bm = this.bodyEl.getMargins();
10907 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
10908 this.bodyEl.setHeight(newHeight);
10912 onResize : function(){
10913 if(this.monitorResize){
10914 this.autoSizeTabs();
10919 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
10921 beginUpdate : function(){
10922 this.updating = true;
10926 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
10928 endUpdate : function(){
10929 this.updating = false;
10930 this.autoSizeTabs();
10934 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
10936 autoSizeTabs : function(){
10937 var count = this.items.length;
10938 var vcount = count - this.hiddenCount;
10939 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) return;
10940 var w = Math.max(this.el.getWidth() - this.cpad, 10);
10941 var availWidth = Math.floor(w / vcount);
10942 var b = this.stripBody;
10943 if(b.getWidth() > w){
10944 var tabs = this.items;
10945 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
10946 if(availWidth < this.minTabWidth){
10947 /*if(!this.sleft){ // incomplete scrolling code
10948 this.createScrollButtons();
10951 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
10954 if(this.currentTabWidth < this.preferredTabWidth){
10955 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
10961 * Returns the number of tabs in this TabPanel.
10964 getCount : function(){
10965 return this.items.length;
10969 * Resizes all the tabs to the passed width
10970 * @param {Number} The new width
10972 setTabWidth : function(width){
10973 this.currentTabWidth = width;
10974 for(var i = 0, len = this.items.length; i < len; i++) {
10975 if(!this.items[i].isHidden())this.items[i].setWidth(width);
10980 * Destroys this TabPanel
10981 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
10983 destroy : function(removeEl){
10984 Roo.EventManager.removeResizeListener(this.onResize, this);
10985 for(var i = 0, len = this.items.length; i < len; i++){
10986 this.items[i].purgeListeners();
10988 if(removeEl === true){
10989 this.el.update("");
10996 * @class Roo.TabPanelItem
10997 * @extends Roo.util.Observable
10998 * Represents an individual item (tab plus body) in a TabPanel.
10999 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
11000 * @param {String} id The id of this TabPanelItem
11001 * @param {String} text The text for the tab of this TabPanelItem
11002 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
11004 Roo.TabPanelItem = function(tabPanel, id, text, closable){
11006 * The {@link Roo.TabPanel} this TabPanelItem belongs to
11007 * @type Roo.TabPanel
11009 this.tabPanel = tabPanel;
11011 * The id for this TabPanelItem
11016 this.disabled = false;
11020 this.loaded = false;
11021 this.closable = closable;
11024 * The body element for this TabPanelItem.
11025 * @type Roo.Element
11027 this.bodyEl = Roo.get(tabPanel.createItemBody(tabPanel.bodyEl.dom, id));
11028 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
11029 this.bodyEl.setStyle("display", "block");
11030 this.bodyEl.setStyle("zoom", "1");
11033 var els = tabPanel.createStripElements(tabPanel.stripEl.dom, text, closable);
11035 this.el = Roo.get(els.el, true);
11036 this.inner = Roo.get(els.inner, true);
11037 this.textEl = Roo.get(this.el.dom.firstChild.firstChild.firstChild, true);
11038 this.pnode = Roo.get(els.el.parentNode, true);
11039 this.el.on("mousedown", this.onTabMouseDown, this);
11040 this.el.on("click", this.onTabClick, this);
11043 var c = Roo.get(els.close, true);
11044 c.dom.title = this.closeText;
11045 c.addClassOnOver("close-over");
11046 c.on("click", this.closeClick, this);
11052 * Fires when this tab becomes the active tab.
11053 * @param {Roo.TabPanel} tabPanel The parent TabPanel
11054 * @param {Roo.TabPanelItem} this
11058 * @event beforeclose
11059 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
11060 * @param {Roo.TabPanelItem} this
11061 * @param {Object} e Set cancel to true on this object to cancel the close.
11063 "beforeclose": true,
11066 * Fires when this tab is closed.
11067 * @param {Roo.TabPanelItem} this
11071 * @event deactivate
11072 * Fires when this tab is no longer the active tab.
11073 * @param {Roo.TabPanel} tabPanel The parent TabPanel
11074 * @param {Roo.TabPanelItem} this
11076 "deactivate" : true
11078 this.hidden = false;
11080 Roo.TabPanelItem.superclass.constructor.call(this);
11083 Roo.extend(Roo.TabPanelItem, Roo.util.Observable, {
11084 purgeListeners : function(){
11085 Roo.util.Observable.prototype.purgeListeners.call(this);
11086 this.el.removeAllListeners();
11089 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
11092 this.pnode.addClass("on");
11095 this.tabPanel.stripWrap.repaint();
11097 this.fireEvent("activate", this.tabPanel, this);
11101 * Returns true if this tab is the active tab.
11102 * @return {Boolean}
11104 isActive : function(){
11105 return this.tabPanel.getActiveTab() == this;
11109 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
11112 this.pnode.removeClass("on");
11114 this.fireEvent("deactivate", this.tabPanel, this);
11117 hideAction : function(){
11118 this.bodyEl.hide();
11119 this.bodyEl.setStyle("position", "absolute");
11120 this.bodyEl.setLeft("-20000px");
11121 this.bodyEl.setTop("-20000px");
11124 showAction : function(){
11125 this.bodyEl.setStyle("position", "relative");
11126 this.bodyEl.setTop("");
11127 this.bodyEl.setLeft("");
11128 this.bodyEl.show();
11132 * Set the tooltip for the tab.
11133 * @param {String} tooltip The tab's tooltip
11135 setTooltip : function(text){
11136 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
11137 this.textEl.dom.qtip = text;
11138 this.textEl.dom.removeAttribute('title');
11140 this.textEl.dom.title = text;
11144 onTabClick : function(e){
11145 e.preventDefault();
11146 this.tabPanel.activate(this.id);
11149 onTabMouseDown : function(e){
11150 e.preventDefault();
11151 this.tabPanel.activate(this.id);
11154 getWidth : function(){
11155 return this.inner.getWidth();
11158 setWidth : function(width){
11159 var iwidth = width - this.pnode.getPadding("lr");
11160 this.inner.setWidth(iwidth);
11161 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
11162 this.pnode.setWidth(width);
11166 * Show or hide the tab
11167 * @param {Boolean} hidden True to hide or false to show.
11169 setHidden : function(hidden){
11170 this.hidden = hidden;
11171 this.pnode.setStyle("display", hidden ? "none" : "");
11175 * Returns true if this tab is "hidden"
11176 * @return {Boolean}
11178 isHidden : function(){
11179 return this.hidden;
11183 * Returns the text for this tab
11186 getText : function(){
11190 autoSize : function(){
11191 //this.el.beginMeasure();
11192 this.textEl.setWidth(1);
11193 this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr"));
11194 //this.el.endMeasure();
11198 * Sets the text for the tab (Note: this also sets the tooltip text)
11199 * @param {String} text The tab's text and tooltip
11201 setText : function(text){
11203 this.textEl.update(text);
11204 this.setTooltip(text);
11205 if(!this.tabPanel.resizeTabs){
11210 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
11212 activate : function(){
11213 this.tabPanel.activate(this.id);
11217 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
11219 disable : function(){
11220 if(this.tabPanel.active != this){
11221 this.disabled = true;
11222 this.pnode.addClass("disabled");
11227 * Enables this TabPanelItem if it was previously disabled.
11229 enable : function(){
11230 this.disabled = false;
11231 this.pnode.removeClass("disabled");
11235 * Sets the content for this TabPanelItem.
11236 * @param {String} content The content
11237 * @param {Boolean} loadScripts true to look for and load scripts
11239 setContent : function(content, loadScripts){
11240 this.bodyEl.update(content, loadScripts);
11244 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
11245 * @return {Roo.UpdateManager} The UpdateManager
11247 getUpdateManager : function(){
11248 return this.bodyEl.getUpdateManager();
11252 * Set a URL to be used to load the content for this TabPanelItem.
11253 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
11254 * @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)
11255 * @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)
11256 * @return {Roo.UpdateManager} The UpdateManager
11258 setUrl : function(url, params, loadOnce){
11259 if(this.refreshDelegate){
11260 this.un('activate', this.refreshDelegate);
11262 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
11263 this.on("activate", this.refreshDelegate);
11264 return this.bodyEl.getUpdateManager();
11268 _handleRefresh : function(url, params, loadOnce){
11269 if(!loadOnce || !this.loaded){
11270 var updater = this.bodyEl.getUpdateManager();
11271 updater.update(url, params, this._setLoaded.createDelegate(this));
11276 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
11277 * Will fail silently if the setUrl method has not been called.
11278 * This does not activate the panel, just updates its content.
11280 refresh : function(){
11281 if(this.refreshDelegate){
11282 this.loaded = false;
11283 this.refreshDelegate();
11288 _setLoaded : function(){
11289 this.loaded = true;
11293 closeClick : function(e){
11296 this.fireEvent("beforeclose", this, o);
11297 if(o.cancel !== true){
11298 this.tabPanel.removeTab(this.id);
11302 * The text displayed in the tooltip for the close icon.
11305 closeText : "Close this tab"
11309 Roo.TabPanel.prototype.createStrip = function(container){
11310 var strip = document.createElement("div");
11311 strip.className = "x-tabs-wrap";
11312 container.appendChild(strip);
11316 Roo.TabPanel.prototype.createStripList = function(strip){
11317 // div wrapper for retard IE
11318 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>';
11319 return strip.firstChild.firstChild.firstChild.firstChild;
11322 Roo.TabPanel.prototype.createBody = function(container){
11323 var body = document.createElement("div");
11324 Roo.id(body, "tab-body");
11325 Roo.fly(body).addClass("x-tabs-body");
11326 container.appendChild(body);
11330 Roo.TabPanel.prototype.createItemBody = function(bodyEl, id){
11331 var body = Roo.getDom(id);
11333 body = document.createElement("div");
11336 Roo.fly(body).addClass("x-tabs-item-body");
11337 bodyEl.insertBefore(body, bodyEl.firstChild);
11341 Roo.TabPanel.prototype.createStripElements = function(stripEl, text, closable){
11342 var td = document.createElement("td");
11343 stripEl.appendChild(td);
11345 td.className = "x-tabs-closable";
11346 if(!this.closeTpl){
11347 this.closeTpl = new Roo.Template(
11348 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
11349 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
11350 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
11353 var el = this.closeTpl.overwrite(td, {"text": text});
11354 var close = el.getElementsByTagName("div")[0];
11355 var inner = el.getElementsByTagName("em")[0];
11356 return {"el": el, "close": close, "inner": inner};
11359 this.tabTpl = new Roo.Template(
11360 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
11361 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
11364 var el = this.tabTpl.overwrite(td, {"text": text});
11365 var inner = el.getElementsByTagName("em")[0];
11366 return {"el": el, "inner": inner};
11370 * Ext JS Library 1.1.1
11371 * Copyright(c) 2006-2007, Ext JS, LLC.
11373 * Originally Released Under LGPL - original licence link has changed is not relivant.
11376 * <script type="text/javascript">
11380 * @class Roo.Button
11381 * @extends Roo.util.Observable
11382 * Simple Button class
11383 * @cfg {String} text The button text
11384 * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
11385 * CSS property of the button by default, so if you want a mixed icon/text button, set cls:"x-btn-text-icon")
11386 * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event)
11387 * @cfg {Object} scope The scope of the handler
11388 * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width)
11389 * @cfg {String/Object} tooltip The tooltip for the button - can be a string or QuickTips config object
11390 * @cfg {Boolean} hidden True to start hidden (defaults to false)
11391 * @cfg {Boolean} disabled True to start disabled (defaults to false)
11392 * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
11393 * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed, only
11394 applies if enableToggle = true)
11395 * @cfg {String/HTMLElement/Element} renderTo The element to append the button to
11396 * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
11397 an {@link Roo.util.ClickRepeater} config object (defaults to false).
11399 * Create a new button
11400 * @param {Object} config The config object
11402 Roo.Button = function(renderTo, config)
11406 renderTo = config.renderTo || false;
11409 Roo.apply(this, config);
11413 * Fires when this button is clicked
11414 * @param {Button} this
11415 * @param {EventObject} e The click event
11420 * Fires when the "pressed" state of this button changes (only if enableToggle = true)
11421 * @param {Button} this
11422 * @param {Boolean} pressed
11427 * Fires when the mouse hovers over the button
11428 * @param {Button} this
11429 * @param {Event} e The event object
11431 'mouseover' : true,
11434 * Fires when the mouse exits the button
11435 * @param {Button} this
11436 * @param {Event} e The event object
11441 * Fires when the button is rendered
11442 * @param {Button} this
11447 this.menu = Roo.menu.MenuMgr.get(this.menu);
11449 // register listeners first!! - so render can be captured..
11450 Roo.util.Observable.call(this);
11452 this.render(renderTo);
11458 Roo.extend(Roo.Button, Roo.util.Observable, {
11464 * Read-only. True if this button is hidden
11469 * Read-only. True if this button is disabled
11474 * Read-only. True if this button is pressed (only if enableToggle = true)
11480 * @cfg {Number} tabIndex
11481 * The DOM tabIndex for this button (defaults to undefined)
11483 tabIndex : undefined,
11486 * @cfg {Boolean} enableToggle
11487 * True to enable pressed/not pressed toggling (defaults to false)
11489 enableToggle: false,
11491 * @cfg {Mixed} menu
11492 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
11496 * @cfg {String} menuAlign
11497 * The position to align the menu to (see {@link Roo.Element#alignTo} for more details, defaults to 'tl-bl?').
11499 menuAlign : "tl-bl?",
11502 * @cfg {String} iconCls
11503 * A css class which sets a background image to be used as the icon for this button (defaults to undefined).
11505 iconCls : undefined,
11507 * @cfg {String} type
11508 * The button's type, corresponding to the DOM input element type attribute. Either "submit," "reset" or "button" (default).
11513 menuClassTarget: 'tr',
11516 * @cfg {String} clickEvent
11517 * The type of event to map to the button's event handler (defaults to 'click')
11519 clickEvent : 'click',
11522 * @cfg {Boolean} handleMouseEvents
11523 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
11525 handleMouseEvents : true,
11528 * @cfg {String} tooltipType
11529 * The type of tooltip to use. Either "qtip" (default) for QuickTips or "title" for title attribute.
11531 tooltipType : 'qtip',
11534 * @cfg {String} cls
11535 * A CSS class to apply to the button's main element.
11539 * @cfg {Roo.Template} template (Optional)
11540 * An {@link Roo.Template} with which to create the Button's main element. This Template must
11541 * contain numeric substitution parameter 0 if it is to display the tRoo property. Changing the template could
11542 * require code modifications if required elements (e.g. a button) aren't present.
11546 render : function(renderTo){
11548 if(this.hideParent){
11549 this.parentEl = Roo.get(renderTo);
11551 if(!this.dhconfig){
11552 if(!this.template){
11553 if(!Roo.Button.buttonTemplate){
11554 // hideous table template
11555 Roo.Button.buttonTemplate = new Roo.Template(
11556 '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
11557 '<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>',
11558 "</tr></tbody></table>");
11560 this.template = Roo.Button.buttonTemplate;
11562 btn = this.template.append(renderTo, [this.text || ' ', this.type], true);
11563 var btnEl = btn.child("button:first");
11564 btnEl.on('focus', this.onFocus, this);
11565 btnEl.on('blur', this.onBlur, this);
11567 btn.addClass(this.cls);
11570 btnEl.setStyle('background-image', 'url(' +this.icon +')');
11573 btnEl.addClass(this.iconCls);
11575 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
11578 if(this.tabIndex !== undefined){
11579 btnEl.dom.tabIndex = this.tabIndex;
11582 if(typeof this.tooltip == 'object'){
11583 Roo.QuickTips.tips(Roo.apply({
11587 btnEl.dom[this.tooltipType] = this.tooltip;
11591 btn = Roo.DomHelper.append(Roo.get(renderTo).dom, this.dhconfig, true);
11595 this.el.dom.id = this.el.id = this.id;
11598 this.el.child(this.menuClassTarget).addClass("x-btn-with-menu");
11599 this.menu.on("show", this.onMenuShow, this);
11600 this.menu.on("hide", this.onMenuHide, this);
11602 btn.addClass("x-btn");
11603 if(Roo.isIE && !Roo.isIE7){
11604 this.autoWidth.defer(1, this);
11608 if(this.handleMouseEvents){
11609 btn.on("mouseover", this.onMouseOver, this);
11610 btn.on("mouseout", this.onMouseOut, this);
11611 btn.on("mousedown", this.onMouseDown, this);
11613 btn.on(this.clickEvent, this.onClick, this);
11614 //btn.on("mouseup", this.onMouseUp, this);
11621 Roo.ButtonToggleMgr.register(this);
11623 this.el.addClass("x-btn-pressed");
11626 var repeater = new Roo.util.ClickRepeater(btn,
11627 typeof this.repeat == "object" ? this.repeat : {}
11629 repeater.on("click", this.onClick, this);
11632 this.fireEvent('render', this);
11636 * Returns the button's underlying element
11637 * @return {Roo.Element} The element
11639 getEl : function(){
11644 * Destroys this Button and removes any listeners.
11646 destroy : function(){
11647 Roo.ButtonToggleMgr.unregister(this);
11648 this.el.removeAllListeners();
11649 this.purgeListeners();
11654 autoWidth : function(){
11656 this.el.setWidth("auto");
11657 if(Roo.isIE7 && Roo.isStrict){
11658 var ib = this.el.child('button');
11659 if(ib && ib.getWidth() > 20){
11661 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
11666 this.el.beginMeasure();
11668 if(this.el.getWidth() < this.minWidth){
11669 this.el.setWidth(this.minWidth);
11672 this.el.endMeasure();
11679 * Assigns this button's click handler
11680 * @param {Function} handler The function to call when the button is clicked
11681 * @param {Object} scope (optional) Scope for the function passed in
11683 setHandler : function(handler, scope){
11684 this.handler = handler;
11685 this.scope = scope;
11689 * Sets this button's text
11690 * @param {String} text The button text
11692 setText : function(text){
11695 this.el.child("td.x-btn-center button.x-btn-text").update(text);
11701 * Gets the text for this button
11702 * @return {String} The button text
11704 getText : function(){
11712 this.hidden = false;
11714 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "");
11722 this.hidden = true;
11724 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "none");
11729 * Convenience function for boolean show/hide
11730 * @param {Boolean} visible True to show, false to hide
11732 setVisible: function(visible){
11741 * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
11742 * @param {Boolean} state (optional) Force a particular state
11744 toggle : function(state){
11745 state = state === undefined ? !this.pressed : state;
11746 if(state != this.pressed){
11748 this.el.addClass("x-btn-pressed");
11749 this.pressed = true;
11750 this.fireEvent("toggle", this, true);
11752 this.el.removeClass("x-btn-pressed");
11753 this.pressed = false;
11754 this.fireEvent("toggle", this, false);
11756 if(this.toggleHandler){
11757 this.toggleHandler.call(this.scope || this, this, state);
11765 focus : function(){
11766 this.el.child('button:first').focus();
11770 * Disable this button
11772 disable : function(){
11774 this.el.addClass("x-btn-disabled");
11776 this.disabled = true;
11780 * Enable this button
11782 enable : function(){
11784 this.el.removeClass("x-btn-disabled");
11786 this.disabled = false;
11790 * Convenience function for boolean enable/disable
11791 * @param {Boolean} enabled True to enable, false to disable
11793 setDisabled : function(v){
11794 this[v !== true ? "enable" : "disable"]();
11798 onClick : function(e){
11800 e.preventDefault();
11805 if(!this.disabled){
11806 if(this.enableToggle){
11809 if(this.menu && !this.menu.isVisible()){
11810 this.menu.show(this.el, this.menuAlign);
11812 this.fireEvent("click", this, e);
11814 this.el.removeClass("x-btn-over");
11815 this.handler.call(this.scope || this, this, e);
11820 onMouseOver : function(e){
11821 if(!this.disabled){
11822 this.el.addClass("x-btn-over");
11823 this.fireEvent('mouseover', this, e);
11827 onMouseOut : function(e){
11828 if(!e.within(this.el, true)){
11829 this.el.removeClass("x-btn-over");
11830 this.fireEvent('mouseout', this, e);
11834 onFocus : function(e){
11835 if(!this.disabled){
11836 this.el.addClass("x-btn-focus");
11840 onBlur : function(e){
11841 this.el.removeClass("x-btn-focus");
11844 onMouseDown : function(e){
11845 if(!this.disabled && e.button == 0){
11846 this.el.addClass("x-btn-click");
11847 Roo.get(document).on('mouseup', this.onMouseUp, this);
11851 onMouseUp : function(e){
11853 this.el.removeClass("x-btn-click");
11854 Roo.get(document).un('mouseup', this.onMouseUp, this);
11858 onMenuShow : function(e){
11859 this.el.addClass("x-btn-menu-active");
11862 onMenuHide : function(e){
11863 this.el.removeClass("x-btn-menu-active");
11867 // Private utility class used by Button
11868 Roo.ButtonToggleMgr = function(){
11871 function toggleGroup(btn, state){
11873 var g = groups[btn.toggleGroup];
11874 for(var i = 0, l = g.length; i < l; i++){
11876 g[i].toggle(false);
11883 register : function(btn){
11884 if(!btn.toggleGroup){
11887 var g = groups[btn.toggleGroup];
11889 g = groups[btn.toggleGroup] = [];
11892 btn.on("toggle", toggleGroup);
11895 unregister : function(btn){
11896 if(!btn.toggleGroup){
11899 var g = groups[btn.toggleGroup];
11902 btn.un("toggle", toggleGroup);
11908 * Ext JS Library 1.1.1
11909 * Copyright(c) 2006-2007, Ext JS, LLC.
11911 * Originally Released Under LGPL - original licence link has changed is not relivant.
11914 * <script type="text/javascript">
11918 * @class Roo.SplitButton
11919 * @extends Roo.Button
11920 * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
11921 * click event of the button. Typically this would be used to display a dropdown menu that provides additional
11922 * options to the primary button action, but any custom handler can provide the arrowclick implementation.
11923 * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
11924 * @cfg {String} arrowTooltip The title attribute of the arrow
11926 * Create a new menu button
11927 * @param {String/HTMLElement/Element} renderTo The element to append the button to
11928 * @param {Object} config The config object
11930 Roo.SplitButton = function(renderTo, config){
11931 Roo.SplitButton.superclass.constructor.call(this, renderTo, config);
11933 * @event arrowclick
11934 * Fires when this button's arrow is clicked
11935 * @param {SplitButton} this
11936 * @param {EventObject} e The click event
11938 this.addEvents({"arrowclick":true});
11941 Roo.extend(Roo.SplitButton, Roo.Button, {
11942 render : function(renderTo){
11943 // this is one sweet looking template!
11944 var tpl = new Roo.Template(
11945 '<table cellspacing="0" class="x-btn-menu-wrap x-btn"><tr><td>',
11946 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-text-wrap"><tbody>',
11947 '<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>',
11948 "</tbody></table></td><td>",
11949 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-arrow-wrap"><tbody>',
11950 '<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>',
11951 "</tbody></table></td></tr></table>"
11953 var btn = tpl.append(renderTo, [this.text, this.type], true);
11954 var btnEl = btn.child("button");
11956 btn.addClass(this.cls);
11959 btnEl.setStyle('background-image', 'url(' +this.icon +')');
11962 btnEl.addClass(this.iconCls);
11964 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
11968 if(this.handleMouseEvents){
11969 btn.on("mouseover", this.onMouseOver, this);
11970 btn.on("mouseout", this.onMouseOut, this);
11971 btn.on("mousedown", this.onMouseDown, this);
11972 btn.on("mouseup", this.onMouseUp, this);
11974 btn.on(this.clickEvent, this.onClick, this);
11976 if(typeof this.tooltip == 'object'){
11977 Roo.QuickTips.tips(Roo.apply({
11981 btnEl.dom[this.tooltipType] = this.tooltip;
11984 if(this.arrowTooltip){
11985 btn.child("button:nth(2)").dom[this.tooltipType] = this.arrowTooltip;
11994 this.el.addClass("x-btn-pressed");
11996 if(Roo.isIE && !Roo.isIE7){
11997 this.autoWidth.defer(1, this);
12002 this.menu.on("show", this.onMenuShow, this);
12003 this.menu.on("hide", this.onMenuHide, this);
12005 this.fireEvent('render', this);
12009 autoWidth : function(){
12011 var tbl = this.el.child("table:first");
12012 var tbl2 = this.el.child("table:last");
12013 this.el.setWidth("auto");
12014 tbl.setWidth("auto");
12015 if(Roo.isIE7 && Roo.isStrict){
12016 var ib = this.el.child('button:first');
12017 if(ib && ib.getWidth() > 20){
12019 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
12024 this.el.beginMeasure();
12026 if((tbl.getWidth()+tbl2.getWidth()) < this.minWidth){
12027 tbl.setWidth(this.minWidth-tbl2.getWidth());
12030 this.el.endMeasure();
12033 this.el.setWidth(tbl.getWidth()+tbl2.getWidth());
12037 * Sets this button's click handler
12038 * @param {Function} handler The function to call when the button is clicked
12039 * @param {Object} scope (optional) Scope for the function passed above
12041 setHandler : function(handler, scope){
12042 this.handler = handler;
12043 this.scope = scope;
12047 * Sets this button's arrow click handler
12048 * @param {Function} handler The function to call when the arrow is clicked
12049 * @param {Object} scope (optional) Scope for the function passed above
12051 setArrowHandler : function(handler, scope){
12052 this.arrowHandler = handler;
12053 this.scope = scope;
12059 focus : function(){
12061 this.el.child("button:first").focus();
12066 onClick : function(e){
12067 e.preventDefault();
12068 if(!this.disabled){
12069 if(e.getTarget(".x-btn-menu-arrow-wrap")){
12070 if(this.menu && !this.menu.isVisible()){
12071 this.menu.show(this.el, this.menuAlign);
12073 this.fireEvent("arrowclick", this, e);
12074 if(this.arrowHandler){
12075 this.arrowHandler.call(this.scope || this, this, e);
12078 this.fireEvent("click", this, e);
12080 this.handler.call(this.scope || this, this, e);
12086 onMouseDown : function(e){
12087 if(!this.disabled){
12088 Roo.fly(e.getTarget("table")).addClass("x-btn-click");
12092 onMouseUp : function(e){
12093 Roo.fly(e.getTarget("table")).removeClass("x-btn-click");
12098 // backwards compat
12099 Roo.MenuButton = Roo.SplitButton;/*
12101 * Ext JS Library 1.1.1
12102 * Copyright(c) 2006-2007, Ext JS, LLC.
12104 * Originally Released Under LGPL - original licence link has changed is not relivant.
12107 * <script type="text/javascript">
12111 * @class Roo.Toolbar
12112 * Basic Toolbar class.
12114 * Creates a new Toolbar
12115 * @param {Object} config The config object
12117 Roo.Toolbar = function(container, buttons, config)
12119 /// old consturctor format still supported..
12120 if(container instanceof Array){ // omit the container for later rendering
12121 buttons = container;
12125 if (typeof(container) == 'object' && container.xtype) {
12126 config = container;
12127 container = config.container;
12128 buttons = config.buttons; // not really - use items!!
12131 if (config && config.items) {
12132 xitems = config.items;
12133 delete config.items;
12135 Roo.apply(this, config);
12136 this.buttons = buttons;
12139 this.render(container);
12141 Roo.each(xitems, function(b) {
12147 Roo.Toolbar.prototype = {
12149 * @cfg {Roo.data.Store} items
12150 * array of button configs or elements to add
12154 * @cfg {String/HTMLElement/Element} container
12155 * The id or element that will contain the toolbar
12158 render : function(ct){
12159 this.el = Roo.get(ct);
12161 this.el.addClass(this.cls);
12163 // using a table allows for vertical alignment
12164 // 100% width is needed by Safari...
12165 this.el.update('<div class="x-toolbar x-small-editor"><table cellspacing="0"><tr></tr></table></div>');
12166 this.tr = this.el.child("tr", true);
12168 this.items = new Roo.util.MixedCollection(false, function(o){
12169 return o.id || ("item" + (++autoId));
12172 this.add.apply(this, this.buttons);
12173 delete this.buttons;
12178 * Adds element(s) to the toolbar -- this function takes a variable number of
12179 * arguments of mixed type and adds them to the toolbar.
12180 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
12182 * <li>{@link Roo.Toolbar.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
12183 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
12184 * <li>Field: Any form field (equivalent to {@link #addField})</li>
12185 * <li>Item: Any subclass of {@link Roo.Toolbar.Item} (equivalent to {@link #addItem})</li>
12186 * <li>String: Any generic string (gets wrapped in a {@link Roo.Toolbar.TextItem}, equivalent to {@link #addText}).
12187 * Note that there are a few special strings that are treated differently as explained nRoo.</li>
12188 * <li>'separator' or '-': Creates a separator element (equivalent to {@link #addSeparator})</li>
12189 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
12190 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
12192 * @param {Mixed} arg2
12193 * @param {Mixed} etc.
12196 var a = arguments, l = a.length;
12197 for(var i = 0; i < l; i++){
12202 _add : function(el) {
12205 el = Roo.factory(el, typeof(Roo.Toolbar[el.xtype]) == 'undefined' ? Roo.form : Roo.Toolbar);
12208 if (el.applyTo){ // some kind of form field
12209 return this.addField(el);
12211 if (el.render){ // some kind of Toolbar.Item
12212 return this.addItem(el);
12214 if (typeof el == "string"){ // string
12215 if(el == "separator" || el == "-"){
12216 return this.addSeparator();
12219 return this.addSpacer();
12222 return this.addFill();
12224 return this.addText(el);
12227 if(el.tagName){ // element
12228 return this.addElement(el);
12230 if(typeof el == "object"){ // must be button config?
12231 return this.addButton(el);
12233 // and now what?!?!
12239 * Add an Xtype element
12240 * @param {Object} xtype Xtype Object
12241 * @return {Object} created Object
12243 addxtype : function(e){
12244 return this.add(e);
12248 * Returns the Element for this toolbar.
12249 * @return {Roo.Element}
12251 getEl : function(){
12257 * @return {Roo.Toolbar.Item} The separator item
12259 addSeparator : function(){
12260 return this.addItem(new Roo.Toolbar.Separator());
12264 * Adds a spacer element
12265 * @return {Roo.Toolbar.Spacer} The spacer item
12267 addSpacer : function(){
12268 return this.addItem(new Roo.Toolbar.Spacer());
12272 * Adds a fill element that forces subsequent additions to the right side of the toolbar
12273 * @return {Roo.Toolbar.Fill} The fill item
12275 addFill : function(){
12276 return this.addItem(new Roo.Toolbar.Fill());
12280 * Adds any standard HTML element to the toolbar
12281 * @param {String/HTMLElement/Element} el The element or id of the element to add
12282 * @return {Roo.Toolbar.Item} The element's item
12284 addElement : function(el){
12285 return this.addItem(new Roo.Toolbar.Item(el));
12288 * Collection of items on the toolbar.. (only Toolbar Items, so use fields to retrieve fields)
12289 * @type Roo.util.MixedCollection
12294 * Adds any Toolbar.Item or subclass
12295 * @param {Roo.Toolbar.Item} item
12296 * @return {Roo.Toolbar.Item} The item
12298 addItem : function(item){
12299 var td = this.nextBlock();
12301 this.items.add(item);
12306 * Adds a button (or buttons). See {@link Roo.Toolbar.Button} for more info on the config.
12307 * @param {Object/Array} config A button config or array of configs
12308 * @return {Roo.Toolbar.Button/Array}
12310 addButton : function(config){
12311 if(config instanceof Array){
12313 for(var i = 0, len = config.length; i < len; i++) {
12314 buttons.push(this.addButton(config[i]));
12319 if(!(config instanceof Roo.Toolbar.Button)){
12321 new Roo.Toolbar.SplitButton(config) :
12322 new Roo.Toolbar.Button(config);
12324 var td = this.nextBlock();
12331 * Adds text to the toolbar
12332 * @param {String} text The text to add
12333 * @return {Roo.Toolbar.Item} The element's item
12335 addText : function(text){
12336 return this.addItem(new Roo.Toolbar.TextItem(text));
12340 * Inserts any {@link Roo.Toolbar.Item}/{@link Roo.Toolbar.Button} at the specified index.
12341 * @param {Number} index The index where the item is to be inserted
12342 * @param {Object/Roo.Toolbar.Item/Roo.Toolbar.Button (may be Array)} item The button, or button config object to be inserted.
12343 * @return {Roo.Toolbar.Button/Item}
12345 insertButton : function(index, item){
12346 if(item instanceof Array){
12348 for(var i = 0, len = item.length; i < len; i++) {
12349 buttons.push(this.insertButton(index + i, item[i]));
12353 if (!(item instanceof Roo.Toolbar.Button)){
12354 item = new Roo.Toolbar.Button(item);
12356 var td = document.createElement("td");
12357 this.tr.insertBefore(td, this.tr.childNodes[index]);
12359 this.items.insert(index, item);
12364 * Adds a new element to the toolbar from the passed {@link Roo.DomHelper} config.
12365 * @param {Object} config
12366 * @return {Roo.Toolbar.Item} The element's item
12368 addDom : function(config, returnEl){
12369 var td = this.nextBlock();
12370 Roo.DomHelper.overwrite(td, config);
12371 var ti = new Roo.Toolbar.Item(td.firstChild);
12373 this.items.add(ti);
12378 * Collection of fields on the toolbar.. usefull for quering (value is false if there are no fields)
12379 * @type Roo.util.MixedCollection
12384 * Adds a dynamically rendered Roo.form field (TextField, ComboBox, etc). Note: the field should not have
12385 * been rendered yet. For a field that has already been rendered, use {@link #addElement}.
12386 * @param {Roo.form.Field} field
12387 * @return {Roo.ToolbarItem}
12391 addField : function(field) {
12392 if (!this.fields) {
12394 this.fields = new Roo.util.MixedCollection(false, function(o){
12395 return o.id || ("item" + (++autoId));
12400 var td = this.nextBlock();
12402 var ti = new Roo.Toolbar.Item(td.firstChild);
12404 this.items.add(ti);
12405 this.fields.add(field);
12416 this.el.child('div').setVisibilityMode(Roo.Element.DISPLAY);
12417 this.el.child('div').hide();
12425 this.el.child('div').show();
12429 nextBlock : function(){
12430 var td = document.createElement("td");
12431 this.tr.appendChild(td);
12436 destroy : function(){
12437 if(this.items){ // rendered?
12438 Roo.destroy.apply(Roo, this.items.items);
12440 if(this.fields){ // rendered?
12441 Roo.destroy.apply(Roo, this.fields.items);
12443 Roo.Element.uncache(this.el, this.tr);
12448 * @class Roo.Toolbar.Item
12449 * The base class that other classes should extend in order to get some basic common toolbar item functionality.
12451 * Creates a new Item
12452 * @param {HTMLElement} el
12454 Roo.Toolbar.Item = function(el){
12455 this.el = Roo.getDom(el);
12456 this.id = Roo.id(this.el);
12457 this.hidden = false;
12460 Roo.Toolbar.Item.prototype = {
12463 * Get this item's HTML Element
12464 * @return {HTMLElement}
12466 getEl : function(){
12471 render : function(td){
12473 td.appendChild(this.el);
12477 * Removes and destroys this item.
12479 destroy : function(){
12480 this.td.parentNode.removeChild(this.td);
12487 this.hidden = false;
12488 this.td.style.display = "";
12495 this.hidden = true;
12496 this.td.style.display = "none";
12500 * Convenience function for boolean show/hide.
12501 * @param {Boolean} visible true to show/false to hide
12503 setVisible: function(visible){
12512 * Try to focus this item.
12514 focus : function(){
12515 Roo.fly(this.el).focus();
12519 * Disables this item.
12521 disable : function(){
12522 Roo.fly(this.td).addClass("x-item-disabled");
12523 this.disabled = true;
12524 this.el.disabled = true;
12528 * Enables this item.
12530 enable : function(){
12531 Roo.fly(this.td).removeClass("x-item-disabled");
12532 this.disabled = false;
12533 this.el.disabled = false;
12539 * @class Roo.Toolbar.Separator
12540 * @extends Roo.Toolbar.Item
12541 * A simple toolbar separator class
12543 * Creates a new Separator
12545 Roo.Toolbar.Separator = function(){
12546 var s = document.createElement("span");
12547 s.className = "ytb-sep";
12548 Roo.Toolbar.Separator.superclass.constructor.call(this, s);
12550 Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, {
12551 enable:Roo.emptyFn,
12552 disable:Roo.emptyFn,
12557 * @class Roo.Toolbar.Spacer
12558 * @extends Roo.Toolbar.Item
12559 * A simple element that adds extra horizontal space to a toolbar.
12561 * Creates a new Spacer
12563 Roo.Toolbar.Spacer = function(){
12564 var s = document.createElement("div");
12565 s.className = "ytb-spacer";
12566 Roo.Toolbar.Spacer.superclass.constructor.call(this, s);
12568 Roo.extend(Roo.Toolbar.Spacer, Roo.Toolbar.Item, {
12569 enable:Roo.emptyFn,
12570 disable:Roo.emptyFn,
12575 * @class Roo.Toolbar.Fill
12576 * @extends Roo.Toolbar.Spacer
12577 * A simple element that adds a greedy (100% width) horizontal space to a toolbar.
12579 * Creates a new Spacer
12581 Roo.Toolbar.Fill = Roo.extend(Roo.Toolbar.Spacer, {
12583 render : function(td){
12584 td.style.width = '100%';
12585 Roo.Toolbar.Fill.superclass.render.call(this, td);
12590 * @class Roo.Toolbar.TextItem
12591 * @extends Roo.Toolbar.Item
12592 * A simple class that renders text directly into a toolbar.
12594 * Creates a new TextItem
12595 * @param {String} text
12597 Roo.Toolbar.TextItem = function(text){
12598 if (typeof(text) == 'object') {
12601 var s = document.createElement("span");
12602 s.className = "ytb-text";
12603 s.innerHTML = text;
12604 Roo.Toolbar.TextItem.superclass.constructor.call(this, s);
12606 Roo.extend(Roo.Toolbar.TextItem, Roo.Toolbar.Item, {
12607 enable:Roo.emptyFn,
12608 disable:Roo.emptyFn,
12613 * @class Roo.Toolbar.Button
12614 * @extends Roo.Button
12615 * A button that renders into a toolbar.
12617 * Creates a new Button
12618 * @param {Object} config A standard {@link Roo.Button} config object
12620 Roo.Toolbar.Button = function(config){
12621 Roo.Toolbar.Button.superclass.constructor.call(this, null, config);
12623 Roo.extend(Roo.Toolbar.Button, Roo.Button, {
12624 render : function(td){
12626 Roo.Toolbar.Button.superclass.render.call(this, td);
12630 * Removes and destroys this button
12632 destroy : function(){
12633 Roo.Toolbar.Button.superclass.destroy.call(this);
12634 this.td.parentNode.removeChild(this.td);
12638 * Shows this button
12641 this.hidden = false;
12642 this.td.style.display = "";
12646 * Hides this button
12649 this.hidden = true;
12650 this.td.style.display = "none";
12654 * Disables this item
12656 disable : function(){
12657 Roo.fly(this.td).addClass("x-item-disabled");
12658 this.disabled = true;
12662 * Enables this item
12664 enable : function(){
12665 Roo.fly(this.td).removeClass("x-item-disabled");
12666 this.disabled = false;
12669 // backwards compat
12670 Roo.ToolbarButton = Roo.Toolbar.Button;
12673 * @class Roo.Toolbar.SplitButton
12674 * @extends Roo.SplitButton
12675 * A menu button that renders into a toolbar.
12677 * Creates a new SplitButton
12678 * @param {Object} config A standard {@link Roo.SplitButton} config object
12680 Roo.Toolbar.SplitButton = function(config){
12681 Roo.Toolbar.SplitButton.superclass.constructor.call(this, null, config);
12683 Roo.extend(Roo.Toolbar.SplitButton, Roo.SplitButton, {
12684 render : function(td){
12686 Roo.Toolbar.SplitButton.superclass.render.call(this, td);
12690 * Removes and destroys this button
12692 destroy : function(){
12693 Roo.Toolbar.SplitButton.superclass.destroy.call(this);
12694 this.td.parentNode.removeChild(this.td);
12698 * Shows this button
12701 this.hidden = false;
12702 this.td.style.display = "";
12706 * Hides this button
12709 this.hidden = true;
12710 this.td.style.display = "none";
12714 // backwards compat
12715 Roo.Toolbar.MenuButton = Roo.Toolbar.SplitButton;/*
12717 * Ext JS Library 1.1.1
12718 * Copyright(c) 2006-2007, Ext JS, LLC.
12720 * Originally Released Under LGPL - original licence link has changed is not relivant.
12723 * <script type="text/javascript">
12727 * @class Roo.PagingToolbar
12728 * @extends Roo.Toolbar
12729 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
12731 * Create a new PagingToolbar
12732 * @param {Object} config The config object
12734 Roo.PagingToolbar = function(el, ds, config)
12736 // old args format still supported... - xtype is prefered..
12737 if (typeof(el) == 'object' && el.xtype) {
12738 // created from xtype...
12740 ds = el.dataSource;
12741 el = config.container;
12744 if (config.items) {
12745 items = this.items;
12749 Roo.PagingToolbar.superclass.constructor.call(this, el, null, config);
12752 this.renderButtons(this.el);
12755 // supprot items array.
12757 Roo.each(items, function(e) {
12758 _this.add(Roo.factory(e));
12763 Roo.extend(Roo.PagingToolbar, Roo.Toolbar, {
12765 * @cfg {Roo.data.Store} dataSource
12766 * The underlying data store providing the paged data
12769 * @cfg {String/HTMLElement/Element} container
12770 * container The id or element that will contain the toolbar
12773 * @cfg {Boolean} displayInfo
12774 * True to display the displayMsg (defaults to false)
12777 * @cfg {Number} pageSize
12778 * The number of records to display per page (defaults to 20)
12782 * @cfg {String} displayMsg
12783 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
12785 displayMsg : 'Displaying {0} - {1} of {2}',
12787 * @cfg {String} emptyMsg
12788 * The message to display when no records are found (defaults to "No data to display")
12790 emptyMsg : 'No data to display',
12792 * Customizable piece of the default paging text (defaults to "Page")
12795 beforePageText : "Page",
12797 * Customizable piece of the default paging text (defaults to "of %0")
12800 afterPageText : "of {0}",
12802 * Customizable piece of the default paging text (defaults to "First Page")
12805 firstText : "First Page",
12807 * Customizable piece of the default paging text (defaults to "Previous Page")
12810 prevText : "Previous Page",
12812 * Customizable piece of the default paging text (defaults to "Next Page")
12815 nextText : "Next Page",
12817 * Customizable piece of the default paging text (defaults to "Last Page")
12820 lastText : "Last Page",
12822 * Customizable piece of the default paging text (defaults to "Refresh")
12825 refreshText : "Refresh",
12828 renderButtons : function(el){
12829 Roo.PagingToolbar.superclass.render.call(this, el);
12830 this.first = this.addButton({
12831 tooltip: this.firstText,
12832 cls: "x-btn-icon x-grid-page-first",
12834 handler: this.onClick.createDelegate(this, ["first"])
12836 this.prev = this.addButton({
12837 tooltip: this.prevText,
12838 cls: "x-btn-icon x-grid-page-prev",
12840 handler: this.onClick.createDelegate(this, ["prev"])
12842 //this.addSeparator();
12843 this.add(this.beforePageText);
12844 this.field = Roo.get(this.addDom({
12849 cls: "x-grid-page-number"
12851 this.field.on("keydown", this.onPagingKeydown, this);
12852 this.field.on("focus", function(){this.dom.select();});
12853 this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
12854 this.field.setHeight(18);
12855 //this.addSeparator();
12856 this.next = this.addButton({
12857 tooltip: this.nextText,
12858 cls: "x-btn-icon x-grid-page-next",
12860 handler: this.onClick.createDelegate(this, ["next"])
12862 this.last = this.addButton({
12863 tooltip: this.lastText,
12864 cls: "x-btn-icon x-grid-page-last",
12866 handler: this.onClick.createDelegate(this, ["last"])
12868 //this.addSeparator();
12869 this.loading = this.addButton({
12870 tooltip: this.refreshText,
12871 cls: "x-btn-icon x-grid-loading",
12872 handler: this.onClick.createDelegate(this, ["refresh"])
12875 if(this.displayInfo){
12876 this.displayEl = Roo.fly(this.el.dom.firstChild).createChild({cls:'x-paging-info'});
12881 updateInfo : function(){
12882 if(this.displayEl){
12883 var count = this.ds.getCount();
12884 var msg = count == 0 ?
12888 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
12890 this.displayEl.update(msg);
12895 onLoad : function(ds, r, o){
12896 this.cursor = o.params ? o.params.start : 0;
12897 var d = this.getPageData(), ap = d.activePage, ps = d.pages;
12899 this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
12900 this.field.dom.value = ap;
12901 this.first.setDisabled(ap == 1);
12902 this.prev.setDisabled(ap == 1);
12903 this.next.setDisabled(ap == ps);
12904 this.last.setDisabled(ap == ps);
12905 this.loading.enable();
12910 getPageData : function(){
12911 var total = this.ds.getTotalCount();
12914 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
12915 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
12920 onLoadError : function(){
12921 this.loading.enable();
12925 onPagingKeydown : function(e){
12926 var k = e.getKey();
12927 var d = this.getPageData();
12929 var v = this.field.dom.value, pageNum;
12930 if(!v || isNaN(pageNum = parseInt(v, 10))){
12931 this.field.dom.value = d.activePage;
12934 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
12935 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
12938 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))
12940 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
12941 this.field.dom.value = pageNum;
12942 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
12945 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
12947 var v = this.field.dom.value, pageNum;
12948 var increment = (e.shiftKey) ? 10 : 1;
12949 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
12951 if(!v || isNaN(pageNum = parseInt(v, 10))) {
12952 this.field.dom.value = d.activePage;
12955 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
12957 this.field.dom.value = parseInt(v, 10) + increment;
12958 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
12959 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
12966 beforeLoad : function(){
12968 this.loading.disable();
12973 onClick : function(which){
12977 ds.load({params:{start: 0, limit: this.pageSize}});
12980 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
12983 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
12986 var total = ds.getTotalCount();
12987 var extra = total % this.pageSize;
12988 var lastStart = extra ? (total - extra) : total-this.pageSize;
12989 ds.load({params:{start: lastStart, limit: this.pageSize}});
12992 ds.load({params:{start: this.cursor, limit: this.pageSize}});
12998 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
12999 * @param {Roo.data.Store} store The data store to unbind
13001 unbind : function(ds){
13002 ds.un("beforeload", this.beforeLoad, this);
13003 ds.un("load", this.onLoad, this);
13004 ds.un("loadexception", this.onLoadError, this);
13005 ds.un("remove", this.updateInfo, this);
13006 ds.un("add", this.updateInfo, this);
13007 this.ds = undefined;
13011 * Binds the paging toolbar to the specified {@link Roo.data.Store}
13012 * @param {Roo.data.Store} store The data store to bind
13014 bind : function(ds){
13015 ds.on("beforeload", this.beforeLoad, this);
13016 ds.on("load", this.onLoad, this);
13017 ds.on("loadexception", this.onLoadError, this);
13018 ds.on("remove", this.updateInfo, this);
13019 ds.on("add", this.updateInfo, this);
13024 * Ext JS Library 1.1.1
13025 * Copyright(c) 2006-2007, Ext JS, LLC.
13027 * Originally Released Under LGPL - original licence link has changed is not relivant.
13030 * <script type="text/javascript">
13034 * @class Roo.Resizable
13035 * @extends Roo.util.Observable
13036 * <p>Applies drag handles to an element to make it resizable. The drag handles are inserted into the element
13037 * and positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you can wrap
13038 * 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
13039 * the element will be wrapped for you automatically.</p>
13040 * <p>Here is the list of valid resize handles:</p>
13043 ------ -------------------
13052 'hd' horizontal drag
13055 * <p>Here's an example showing the creation of a typical Resizable:</p>
13057 var resizer = new Roo.Resizable("element-id", {
13065 resizer.on("resize", myHandler);
13067 * <p>To hide a particular handle, set its display to none in CSS, or through script:<br>
13068 * resizer.east.setDisplayed(false);</p>
13069 * @cfg {Boolean/String/Element} resizeChild True to resize the first child, or id/element to resize (defaults to false)
13070 * @cfg {Array/String} adjustments String "auto" or an array [width, height] with values to be <b>added</b> to the
13071 * resize operation's new size (defaults to [0, 0])
13072 * @cfg {Number} minWidth The minimum width for the element (defaults to 5)
13073 * @cfg {Number} minHeight The minimum height for the element (defaults to 5)
13074 * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)
13075 * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)
13076 * @cfg {Boolean} enabled False to disable resizing (defaults to true)
13077 * @cfg {Boolean} wrap True to wrap an element with a div if needed (required for textareas and images, defaults to false)
13078 * @cfg {Number} width The width of the element in pixels (defaults to null)
13079 * @cfg {Number} height The height of the element in pixels (defaults to null)
13080 * @cfg {Boolean} animate True to animate the resize (not compatible with dynamic sizing, defaults to false)
13081 * @cfg {Number} duration Animation duration if animate = true (defaults to .35)
13082 * @cfg {Boolean} dynamic True to resize the element while dragging instead of using a proxy (defaults to false)
13083 * @cfg {String} handles String consisting of the resize handles to display (defaults to undefined)
13084 * @cfg {Boolean} multiDirectional <b>Deprecated</b>. The old style of adding multi-direction resize handles, deprecated
13085 * in favor of the handles config option (defaults to false)
13086 * @cfg {Boolean} disableTrackOver True to disable mouse tracking. This is only applied at config time. (defaults to false)
13087 * @cfg {String} easing Animation easing if animate = true (defaults to 'easingOutStrong')
13088 * @cfg {Number} widthIncrement The increment to snap the width resize in pixels (dynamic must be true, defaults to 0)
13089 * @cfg {Number} heightIncrement The increment to snap the height resize in pixels (dynamic must be true, defaults to 0)
13090 * @cfg {Boolean} pinned True to ensure that the resize handles are always visible, false to display them only when the
13091 * user mouses over the resizable borders. This is only applied at config time. (defaults to false)
13092 * @cfg {Boolean} preserveRatio True to preserve the original ratio between height and width during resize (defaults to false)
13093 * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)
13094 * @cfg {Number} minX The minimum allowed page X for the element (only used for west resizing, defaults to 0)
13095 * @cfg {Number} minY The minimum allowed page Y for the element (only used for north resizing, defaults to 0)
13096 * @cfg {Boolean} draggable Convenience to initialize drag drop (defaults to false)
13098 * Create a new resizable component
13099 * @param {String/HTMLElement/Roo.Element} el The id or element to resize
13100 * @param {Object} config configuration options
13102 Roo.Resizable = function(el, config)
13104 this.el = Roo.get(el);
13106 if(config && config.wrap){
13107 config.resizeChild = this.el;
13108 this.el = this.el.wrap(typeof config.wrap == "object" ? config.wrap : {cls:"xresizable-wrap"});
13109 this.el.id = this.el.dom.id = config.resizeChild.id + "-rzwrap";
13110 this.el.setStyle("overflow", "hidden");
13111 this.el.setPositioning(config.resizeChild.getPositioning());
13112 config.resizeChild.clearPositioning();
13113 if(!config.width || !config.height){
13114 var csize = config.resizeChild.getSize();
13115 this.el.setSize(csize.width, csize.height);
13117 if(config.pinned && !config.adjustments){
13118 config.adjustments = "auto";
13122 this.proxy = this.el.createProxy({tag: "div", cls: "x-resizable-proxy", id: this.el.id + "-rzproxy"});
13123 this.proxy.unselectable();
13124 this.proxy.enableDisplayMode('block');
13126 Roo.apply(this, config);
13129 this.disableTrackOver = true;
13130 this.el.addClass("x-resizable-pinned");
13132 // if the element isn't positioned, make it relative
13133 var position = this.el.getStyle("position");
13134 if(position != "absolute" && position != "fixed"){
13135 this.el.setStyle("position", "relative");
13137 if(!this.handles){ // no handles passed, must be legacy style
13138 this.handles = 's,e,se';
13139 if(this.multiDirectional){
13140 this.handles += ',n,w';
13143 if(this.handles == "all"){
13144 this.handles = "n s e w ne nw se sw";
13146 var hs = this.handles.split(/\s*?[,;]\s*?| /);
13147 var ps = Roo.Resizable.positions;
13148 for(var i = 0, len = hs.length; i < len; i++){
13149 if(hs[i] && ps[hs[i]]){
13150 var pos = ps[hs[i]];
13151 this[pos] = new Roo.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent);
13155 this.corner = this.southeast;
13157 // updateBox = the box can move..
13158 if(this.handles.indexOf("n") != -1 || this.handles.indexOf("w") != -1 || this.handles.indexOf("hd") != -1) {
13159 this.updateBox = true;
13162 this.activeHandle = null;
13164 if(this.resizeChild){
13165 if(typeof this.resizeChild == "boolean"){
13166 this.resizeChild = Roo.get(this.el.dom.firstChild, true);
13168 this.resizeChild = Roo.get(this.resizeChild, true);
13172 if(this.adjustments == "auto"){
13173 var rc = this.resizeChild;
13174 var hw = this.west, he = this.east, hn = this.north, hs = this.south;
13175 if(rc && (hw || hn)){
13176 rc.position("relative");
13177 rc.setLeft(hw ? hw.el.getWidth() : 0);
13178 rc.setTop(hn ? hn.el.getHeight() : 0);
13180 this.adjustments = [
13181 (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),
13182 (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1
13186 if(this.draggable){
13187 this.dd = this.dynamic ?
13188 this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});
13189 this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);
13195 * @event beforeresize
13196 * Fired before resize is allowed. Set enabled to false to cancel resize.
13197 * @param {Roo.Resizable} this
13198 * @param {Roo.EventObject} e The mousedown event
13200 "beforeresize" : true,
13203 * Fired after a resize.
13204 * @param {Roo.Resizable} this
13205 * @param {Number} width The new width
13206 * @param {Number} height The new height
13207 * @param {Roo.EventObject} e The mouseup event
13212 if(this.width !== null && this.height !== null){
13213 this.resizeTo(this.width, this.height);
13215 this.updateChildSize();
13218 this.el.dom.style.zoom = 1;
13220 Roo.Resizable.superclass.constructor.call(this);
13223 Roo.extend(Roo.Resizable, Roo.util.Observable, {
13224 resizeChild : false,
13225 adjustments : [0, 0],
13235 multiDirectional : false,
13236 disableTrackOver : false,
13237 easing : 'easeOutStrong',
13238 widthIncrement : 0,
13239 heightIncrement : 0,
13243 preserveRatio : false,
13244 transparent: false,
13250 * @cfg {String/HTMLElement/Element} constrainTo Constrain the resize to a particular element
13252 constrainTo: undefined,
13254 * @cfg {Roo.lib.Region} resizeRegion Constrain the resize to a particular region
13256 resizeRegion: undefined,
13260 * Perform a manual resize
13261 * @param {Number} width
13262 * @param {Number} height
13264 resizeTo : function(width, height){
13265 this.el.setSize(width, height);
13266 this.updateChildSize();
13267 this.fireEvent("resize", this, width, height, null);
13271 startSizing : function(e, handle){
13272 this.fireEvent("beforeresize", this, e);
13273 if(this.enabled){ // 2nd enabled check in case disabled before beforeresize handler
13276 this.overlay = this.el.createProxy({tag: "div", cls: "x-resizable-overlay", html: " "});
13277 this.overlay.unselectable();
13278 this.overlay.enableDisplayMode("block");
13279 this.overlay.on("mousemove", this.onMouseMove, this);
13280 this.overlay.on("mouseup", this.onMouseUp, this);
13282 this.overlay.setStyle("cursor", handle.el.getStyle("cursor"));
13284 this.resizing = true;
13285 this.startBox = this.el.getBox();
13286 this.startPoint = e.getXY();
13287 this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],
13288 (this.startBox.y + this.startBox.height) - this.startPoint[1]];
13290 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
13291 this.overlay.show();
13293 if(this.constrainTo) {
13294 var ct = Roo.get(this.constrainTo);
13295 this.resizeRegion = ct.getRegion().adjust(
13296 ct.getFrameWidth('t'),
13297 ct.getFrameWidth('l'),
13298 -ct.getFrameWidth('b'),
13299 -ct.getFrameWidth('r')
13303 this.proxy.setStyle('visibility', 'hidden'); // workaround display none
13305 this.proxy.setBox(this.startBox);
13307 this.proxy.setStyle('visibility', 'visible');
13313 onMouseDown : function(handle, e){
13316 this.activeHandle = handle;
13317 this.startSizing(e, handle);
13322 onMouseUp : function(e){
13323 var size = this.resizeElement();
13324 this.resizing = false;
13326 this.overlay.hide();
13328 this.fireEvent("resize", this, size.width, size.height, e);
13332 updateChildSize : function(){
13333 if(this.resizeChild){
13335 var child = this.resizeChild;
13336 var adj = this.adjustments;
13337 if(el.dom.offsetWidth){
13338 var b = el.getSize(true);
13339 child.setSize(b.width+adj[0], b.height+adj[1]);
13341 // Second call here for IE
13342 // The first call enables instant resizing and
13343 // the second call corrects scroll bars if they
13346 setTimeout(function(){
13347 if(el.dom.offsetWidth){
13348 var b = el.getSize(true);
13349 child.setSize(b.width+adj[0], b.height+adj[1]);
13357 snap : function(value, inc, min){
13358 if(!inc || !value) return value;
13359 var newValue = value;
13360 var m = value % inc;
13363 newValue = value + (inc-m);
13365 newValue = value - m;
13368 return Math.max(min, newValue);
13372 resizeElement : function(){
13373 var box = this.proxy.getBox();
13374 if(this.updateBox){
13375 this.el.setBox(box, false, this.animate, this.duration, null, this.easing);
13377 this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing);
13379 this.updateChildSize();
13387 constrain : function(v, diff, m, mx){
13390 }else if(v - diff > mx){
13397 onMouseMove : function(e){
13399 try{// try catch so if something goes wrong the user doesn't get hung
13401 if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {
13405 //var curXY = this.startPoint;
13406 var curSize = this.curSize || this.startBox;
13407 var x = this.startBox.x, y = this.startBox.y;
13408 var ox = x, oy = y;
13409 var w = curSize.width, h = curSize.height;
13410 var ow = w, oh = h;
13411 var mw = this.minWidth, mh = this.minHeight;
13412 var mxw = this.maxWidth, mxh = this.maxHeight;
13413 var wi = this.widthIncrement;
13414 var hi = this.heightIncrement;
13416 var eventXY = e.getXY();
13417 var diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0]));
13418 var diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1]));
13420 var pos = this.activeHandle.position;
13425 w = Math.min(Math.max(mw, w), mxw);
13430 h = Math.min(Math.max(mh, h), mxh);
13435 w = Math.min(Math.max(mw, w), mxw);
13436 h = Math.min(Math.max(mh, h), mxh);
13439 diffY = this.constrain(h, diffY, mh, mxh);
13446 var adiffX = Math.abs(diffX);
13447 var sub = (adiffX % wi); // how much
13448 if (sub > (wi/2)) { // far enough to snap
13449 diffX = (diffX > 0) ? diffX-sub + wi : diffX+sub - wi;
13451 // remove difference..
13452 diffX = (diffX > 0) ? diffX-sub : diffX+sub;
13456 x = Math.max(this.minX, x);
13459 diffX = this.constrain(w, diffX, mw, mxw);
13465 w = Math.min(Math.max(mw, w), mxw);
13466 diffY = this.constrain(h, diffY, mh, mxh);
13471 diffX = this.constrain(w, diffX, mw, mxw);
13472 diffY = this.constrain(h, diffY, mh, mxh);
13479 diffX = this.constrain(w, diffX, mw, mxw);
13481 h = Math.min(Math.max(mh, h), mxh);
13487 var sw = this.snap(w, wi, mw);
13488 var sh = this.snap(h, hi, mh);
13489 if(sw != w || sh != h){
13512 if(this.preserveRatio){
13517 h = Math.min(Math.max(mh, h), mxh);
13522 w = Math.min(Math.max(mw, w), mxw);
13527 w = Math.min(Math.max(mw, w), mxw);
13533 w = Math.min(Math.max(mw, w), mxw);
13539 h = Math.min(Math.max(mh, h), mxh);
13547 h = Math.min(Math.max(mh, h), mxh);
13557 h = Math.min(Math.max(mh, h), mxh);
13565 if (pos == 'hdrag') {
13568 this.proxy.setBounds(x, y, w, h);
13570 this.resizeElement();
13577 handleOver : function(){
13579 this.el.addClass("x-resizable-over");
13584 handleOut : function(){
13585 if(!this.resizing){
13586 this.el.removeClass("x-resizable-over");
13591 * Returns the element this component is bound to.
13592 * @return {Roo.Element}
13594 getEl : function(){
13599 * Returns the resizeChild element (or null).
13600 * @return {Roo.Element}
13602 getResizeChild : function(){
13603 return this.resizeChild;
13607 * Destroys this resizable. If the element was wrapped and
13608 * removeEl is not true then the element remains.
13609 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
13611 destroy : function(removeEl){
13612 this.proxy.remove();
13614 this.overlay.removeAllListeners();
13615 this.overlay.remove();
13617 var ps = Roo.Resizable.positions;
13619 if(typeof ps[k] != "function" && this[ps[k]]){
13620 var h = this[ps[k]];
13621 h.el.removeAllListeners();
13626 this.el.update("");
13633 // hash to map config positions to true positions
13634 Roo.Resizable.positions = {
13635 n: "north", s: "south", e: "east", w: "west", se: "southeast", sw: "southwest", nw: "northwest", ne: "northeast",
13640 Roo.Resizable.Handle = function(rz, pos, disableTrackOver, transparent){
13642 // only initialize the template if resizable is used
13643 var tpl = Roo.DomHelper.createTemplate(
13644 {tag: "div", cls: "x-resizable-handle x-resizable-handle-{0}"}
13647 Roo.Resizable.Handle.prototype.tpl = tpl;
13649 this.position = pos;
13651 // show north drag fro topdra
13652 var handlepos = pos == 'hdrag' ? 'north' : pos;
13654 this.el = this.tpl.append(rz.el.dom, [handlepos], true);
13655 if (pos == 'hdrag') {
13656 this.el.setStyle('cursor', 'pointer');
13658 this.el.unselectable();
13660 this.el.setOpacity(0);
13662 this.el.on("mousedown", this.onMouseDown, this);
13663 if(!disableTrackOver){
13664 this.el.on("mouseover", this.onMouseOver, this);
13665 this.el.on("mouseout", this.onMouseOut, this);
13670 Roo.Resizable.Handle.prototype = {
13671 afterResize : function(rz){
13675 onMouseDown : function(e){
13676 this.rz.onMouseDown(this, e);
13679 onMouseOver : function(e){
13680 this.rz.handleOver(this, e);
13683 onMouseOut : function(e){
13684 this.rz.handleOut(this, e);
13688 * Ext JS Library 1.1.1
13689 * Copyright(c) 2006-2007, Ext JS, LLC.
13691 * Originally Released Under LGPL - original licence link has changed is not relivant.
13694 * <script type="text/javascript">
13698 * @class Roo.Editor
13699 * @extends Roo.Component
13700 * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
13702 * Create a new Editor
13703 * @param {Roo.form.Field} field The Field object (or descendant)
13704 * @param {Object} config The config object
13706 Roo.Editor = function(field, config){
13707 Roo.Editor.superclass.constructor.call(this, config);
13708 this.field = field;
13711 * @event beforestartedit
13712 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
13713 * false from the handler of this event.
13714 * @param {Editor} this
13715 * @param {Roo.Element} boundEl The underlying element bound to this editor
13716 * @param {Mixed} value The field value being set
13718 "beforestartedit" : true,
13721 * Fires when this editor is displayed
13722 * @param {Roo.Element} boundEl The underlying element bound to this editor
13723 * @param {Mixed} value The starting field value
13725 "startedit" : true,
13727 * @event beforecomplete
13728 * Fires after a change has been made to the field, but before the change is reflected in the underlying
13729 * field. Saving the change to the field can be canceled by returning false from the handler of this event.
13730 * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
13731 * event will not fire since no edit actually occurred.
13732 * @param {Editor} this
13733 * @param {Mixed} value The current field value
13734 * @param {Mixed} startValue The original field value
13736 "beforecomplete" : true,
13739 * Fires after editing is complete and any changed value has been written to the underlying field.
13740 * @param {Editor} this
13741 * @param {Mixed} value The current field value
13742 * @param {Mixed} startValue The original field value
13746 * @event specialkey
13747 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
13748 * {@link Roo.EventObject#getKey} to determine which key was pressed.
13749 * @param {Roo.form.Field} this
13750 * @param {Roo.EventObject} e The event object
13752 "specialkey" : true
13756 Roo.extend(Roo.Editor, Roo.Component, {
13758 * @cfg {Boolean/String} autosize
13759 * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
13760 * or "height" to adopt the height only (defaults to false)
13763 * @cfg {Boolean} revertInvalid
13764 * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
13765 * validation fails (defaults to true)
13768 * @cfg {Boolean} ignoreNoChange
13769 * True to skip the the edit completion process (no save, no events fired) if the user completes an edit and
13770 * the value has not changed (defaults to false). Applies only to string values - edits for other data types
13771 * will never be ignored.
13774 * @cfg {Boolean} hideEl
13775 * False to keep the bound element visible while the editor is displayed (defaults to true)
13778 * @cfg {Mixed} value
13779 * The data value of the underlying field (defaults to "")
13783 * @cfg {String} alignment
13784 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "c-c?").
13788 * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
13789 * for bottom-right shadow (defaults to "frame")
13793 * @cfg {Boolean} constrain True to constrain the editor to the viewport
13797 * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed (defaults to false)
13799 completeOnEnter : false,
13801 * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed (defaults to false)
13803 cancelOnEsc : false,
13805 * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
13810 onRender : function(ct, position){
13811 this.el = new Roo.Layer({
13812 shadow: this.shadow,
13818 constrain: this.constrain
13820 this.el.setStyle("overflow", Roo.isGecko ? "auto" : "hidden");
13821 if(this.field.msgTarget != 'title'){
13822 this.field.msgTarget = 'qtip';
13824 this.field.render(this.el);
13826 this.field.el.dom.setAttribute('autocomplete', 'off');
13828 this.field.on("specialkey", this.onSpecialKey, this);
13829 if(this.swallowKeys){
13830 this.field.el.swallowEvent(['keydown','keypress']);
13833 this.field.on("blur", this.onBlur, this);
13834 if(this.field.grow){
13835 this.field.on("autosize", this.el.sync, this.el, {delay:1});
13839 onSpecialKey : function(field, e){
13840 //Roo.log('editor onSpecialKey');
13841 if(this.completeOnEnter && e.getKey() == e.ENTER){
13843 this.completeEdit();
13844 }else if(this.cancelOnEsc && e.getKey() == e.ESC){
13847 this.fireEvent('specialkey', field, e);
13852 * Starts the editing process and shows the editor.
13853 * @param {String/HTMLElement/Element} el The element to edit
13854 * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
13855 * to the innerHTML of el.
13857 startEdit : function(el, value){
13859 this.completeEdit();
13861 this.boundEl = Roo.get(el);
13862 var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
13863 if(!this.rendered){
13864 this.render(this.parentEl || document.body);
13866 if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
13869 this.startValue = v;
13870 this.field.setValue(v);
13872 var sz = this.boundEl.getSize();
13873 switch(this.autoSize){
13875 this.setSize(sz.width, "");
13878 this.setSize("", sz.height);
13881 this.setSize(sz.width, sz.height);
13884 this.el.alignTo(this.boundEl, this.alignment);
13885 this.editing = true;
13887 Roo.QuickTips.disable();
13893 * Sets the height and width of this editor.
13894 * @param {Number} width The new width
13895 * @param {Number} height The new height
13897 setSize : function(w, h){
13898 this.field.setSize(w, h);
13905 * Realigns the editor to the bound field based on the current alignment config value.
13907 realign : function(){
13908 this.el.alignTo(this.boundEl, this.alignment);
13912 * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
13913 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
13915 completeEdit : function(remainVisible){
13919 var v = this.getValue();
13920 if(this.revertInvalid !== false && !this.field.isValid()){
13921 v = this.startValue;
13922 this.cancelEdit(true);
13924 if(String(v) === String(this.startValue) && this.ignoreNoChange){
13925 this.editing = false;
13929 if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
13930 this.editing = false;
13931 if(this.updateEl && this.boundEl){
13932 this.boundEl.update(v);
13934 if(remainVisible !== true){
13937 this.fireEvent("complete", this, v, this.startValue);
13942 onShow : function(){
13944 if(this.hideEl !== false){
13945 this.boundEl.hide();
13948 if(Roo.isIE && !this.fixIEFocus){ // IE has problems with focusing the first time
13949 this.fixIEFocus = true;
13950 this.deferredFocus.defer(50, this);
13952 this.field.focus();
13954 this.fireEvent("startedit", this.boundEl, this.startValue);
13957 deferredFocus : function(){
13959 this.field.focus();
13964 * Cancels the editing process and hides the editor without persisting any changes. The field value will be
13965 * reverted to the original starting value.
13966 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
13967 * cancel (defaults to false)
13969 cancelEdit : function(remainVisible){
13971 this.setValue(this.startValue);
13972 if(remainVisible !== true){
13979 onBlur : function(){
13980 if(this.allowBlur !== true && this.editing){
13981 this.completeEdit();
13986 onHide : function(){
13988 this.completeEdit();
13992 if(this.field.collapse){
13993 this.field.collapse();
13996 if(this.hideEl !== false){
13997 this.boundEl.show();
14000 Roo.QuickTips.enable();
14005 * Sets the data value of the editor
14006 * @param {Mixed} value Any valid value supported by the underlying field
14008 setValue : function(v){
14009 this.field.setValue(v);
14013 * Gets the data value of the editor
14014 * @return {Mixed} The data value
14016 getValue : function(){
14017 return this.field.getValue();
14021 * Ext JS Library 1.1.1
14022 * Copyright(c) 2006-2007, Ext JS, LLC.
14024 * Originally Released Under LGPL - original licence link has changed is not relivant.
14027 * <script type="text/javascript">
14031 * @class Roo.BasicDialog
14032 * @extends Roo.util.Observable
14033 * Lightweight Dialog Class. The code below shows the creation of a typical dialog using existing HTML markup:
14035 var dlg = new Roo.BasicDialog("my-dlg", {
14044 dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
14045 dlg.addButton('OK', dlg.hide, dlg); // Could call a save function instead of hiding
14046 dlg.addButton('Cancel', dlg.hide, dlg);
14049 <b>A Dialog should always be a direct child of the body element.</b>
14050 * @cfg {Boolean/DomHelper} autoCreate True to auto create from scratch, or using a DomHelper Object (defaults to false)
14051 * @cfg {String} title Default text to display in the title bar (defaults to null)
14052 * @cfg {Number} width Width of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
14053 * @cfg {Number} height Height of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
14054 * @cfg {Number} x The default left page coordinate of the dialog (defaults to center screen)
14055 * @cfg {Number} y The default top page coordinate of the dialog (defaults to center screen)
14056 * @cfg {String/Element} animateTarget Id or element from which the dialog should animate while opening
14057 * (defaults to null with no animation)
14058 * @cfg {Boolean} resizable False to disable manual dialog resizing (defaults to true)
14059 * @cfg {String} resizeHandles Which resize handles to display - see the {@link Roo.Resizable} handles config
14060 * property for valid values (defaults to 'all')
14061 * @cfg {Number} minHeight The minimum allowable height for a resizable dialog (defaults to 80)
14062 * @cfg {Number} minWidth The minimum allowable width for a resizable dialog (defaults to 200)
14063 * @cfg {Boolean} modal True to show the dialog modally, preventing user interaction with the rest of the page (defaults to false)
14064 * @cfg {Boolean} autoScroll True to allow the dialog body contents to overflow and display scrollbars (defaults to false)
14065 * @cfg {Boolean} closable False to remove the built-in top-right corner close button (defaults to true)
14066 * @cfg {Boolean} collapsible False to remove the built-in top-right corner collapse button (defaults to true)
14067 * @cfg {Boolean} constraintoviewport True to keep the dialog constrained within the visible viewport boundaries (defaults to true)
14068 * @cfg {Boolean} syncHeightBeforeShow True to cause the dimensions to be recalculated before the dialog is shown (defaults to false)
14069 * @cfg {Boolean} draggable False to disable dragging of the dialog within the viewport (defaults to true)
14070 * @cfg {Boolean} autoTabs If true, all elements with class 'x-dlg-tab' will get automatically converted to tabs (defaults to false)
14071 * @cfg {String} tabTag The tag name of tab elements, used when autoTabs = true (defaults to 'div')
14072 * @cfg {Boolean} proxyDrag True to drag a lightweight proxy element rather than the dialog itself, used when
14073 * draggable = true (defaults to false)
14074 * @cfg {Boolean} fixedcenter True to ensure that anytime the dialog is shown or resized it gets centered (defaults to false)
14075 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
14076 * shadow (defaults to false)
14077 * @cfg {Number} shadowOffset The number of pixels to offset the shadow if displayed (defaults to 5)
14078 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "right")
14079 * @cfg {Number} minButtonWidth Minimum width of all dialog buttons (defaults to 75)
14080 * @cfg {Array} buttons Array of buttons
14081 * @cfg {Boolean} shim True to create an iframe shim that prevents selects from showing through (defaults to false)
14083 * Create a new BasicDialog.
14084 * @param {String/HTMLElement/Roo.Element} el The container element or DOM node, or its id
14085 * @param {Object} config Configuration options
14087 Roo.BasicDialog = function(el, config){
14088 this.el = Roo.get(el);
14089 var dh = Roo.DomHelper;
14090 if(!this.el && config && config.autoCreate){
14091 if(typeof config.autoCreate == "object"){
14092 if(!config.autoCreate.id){
14093 config.autoCreate.id = el;
14095 this.el = dh.append(document.body,
14096 config.autoCreate, true);
14098 this.el = dh.append(document.body,
14099 {tag: "div", id: el, style:'visibility:hidden;'}, true);
14103 el.setDisplayed(true);
14104 el.hide = this.hideAction;
14106 el.addClass("x-dlg");
14108 Roo.apply(this, config);
14110 this.proxy = el.createProxy("x-dlg-proxy");
14111 this.proxy.hide = this.hideAction;
14112 this.proxy.setOpacity(.5);
14116 el.setWidth(config.width);
14119 el.setHeight(config.height);
14121 this.size = el.getSize();
14122 if(typeof config.x != "undefined" && typeof config.y != "undefined"){
14123 this.xy = [config.x,config.y];
14125 this.xy = el.getCenterXY(true);
14127 /** The header element @type Roo.Element */
14128 this.header = el.child("> .x-dlg-hd");
14129 /** The body element @type Roo.Element */
14130 this.body = el.child("> .x-dlg-bd");
14131 /** The footer element @type Roo.Element */
14132 this.footer = el.child("> .x-dlg-ft");
14135 this.header = el.createChild({tag: "div", cls:"x-dlg-hd", html: " "}, this.body ? this.body.dom : null);
14138 this.body = el.createChild({tag: "div", cls:"x-dlg-bd"});
14141 this.header.unselectable();
14143 this.header.update(this.title);
14145 // this element allows the dialog to be focused for keyboard event
14146 this.focusEl = el.createChild({tag: "a", href:"#", cls:"x-dlg-focus", tabIndex:"-1"});
14147 this.focusEl.swallowEvent("click", true);
14149 this.header.wrap({cls:"x-dlg-hd-right"}).wrap({cls:"x-dlg-hd-left"}, true);
14151 // wrap the body and footer for special rendering
14152 this.bwrap = this.body.wrap({tag: "div", cls:"x-dlg-dlg-body"});
14154 this.bwrap.dom.appendChild(this.footer.dom);
14157 this.bg = this.el.createChild({
14158 tag: "div", cls:"x-dlg-bg",
14159 html: '<div class="x-dlg-bg-left"><div class="x-dlg-bg-right"><div class="x-dlg-bg-center"> </div></div></div>'
14161 this.centerBg = this.bg.child("div.x-dlg-bg-center");
14164 if(this.autoScroll !== false && !this.autoTabs){
14165 this.body.setStyle("overflow", "auto");
14168 this.toolbox = this.el.createChild({cls: "x-dlg-toolbox"});
14170 if(this.closable !== false){
14171 this.el.addClass("x-dlg-closable");
14172 this.close = this.toolbox.createChild({cls:"x-dlg-close"});
14173 this.close.on("click", this.closeClick, this);
14174 this.close.addClassOnOver("x-dlg-close-over");
14176 if(this.collapsible !== false){
14177 this.collapseBtn = this.toolbox.createChild({cls:"x-dlg-collapse"});
14178 this.collapseBtn.on("click", this.collapseClick, this);
14179 this.collapseBtn.addClassOnOver("x-dlg-collapse-over");
14180 this.header.on("dblclick", this.collapseClick, this);
14182 if(this.resizable !== false){
14183 this.el.addClass("x-dlg-resizable");
14184 this.resizer = new Roo.Resizable(el, {
14185 minWidth: this.minWidth || 80,
14186 minHeight:this.minHeight || 80,
14187 handles: this.resizeHandles || "all",
14190 this.resizer.on("beforeresize", this.beforeResize, this);
14191 this.resizer.on("resize", this.onResize, this);
14193 if(this.draggable !== false){
14194 el.addClass("x-dlg-draggable");
14195 if (!this.proxyDrag) {
14196 var dd = new Roo.dd.DD(el.dom.id, "WindowDrag");
14199 var dd = new Roo.dd.DDProxy(el.dom.id, "WindowDrag", {dragElId: this.proxy.id});
14201 dd.setHandleElId(this.header.id);
14202 dd.endDrag = this.endMove.createDelegate(this);
14203 dd.startDrag = this.startMove.createDelegate(this);
14204 dd.onDrag = this.onDrag.createDelegate(this);
14209 this.mask = dh.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
14210 this.mask.enableDisplayMode("block");
14212 this.el.addClass("x-dlg-modal");
14215 this.shadow = new Roo.Shadow({
14216 mode : typeof this.shadow == "string" ? this.shadow : "sides",
14217 offset : this.shadowOffset
14220 this.shadowOffset = 0;
14222 if(Roo.useShims && this.shim !== false){
14223 this.shim = this.el.createShim();
14224 this.shim.hide = this.hideAction;
14232 if (this.buttons) {
14233 var bts= this.buttons;
14235 Roo.each(bts, function(b) {
14244 * Fires when a key is pressed
14245 * @param {Roo.BasicDialog} this
14246 * @param {Roo.EventObject} e
14251 * Fires when this dialog is moved by the user.
14252 * @param {Roo.BasicDialog} this
14253 * @param {Number} x The new page X
14254 * @param {Number} y The new page Y
14259 * Fires when this dialog is resized by the user.
14260 * @param {Roo.BasicDialog} this
14261 * @param {Number} width The new width
14262 * @param {Number} height The new height
14266 * @event beforehide
14267 * Fires before this dialog is hidden.
14268 * @param {Roo.BasicDialog} this
14270 "beforehide" : true,
14273 * Fires when this dialog is hidden.
14274 * @param {Roo.BasicDialog} this
14278 * @event beforeshow
14279 * Fires before this dialog is shown.
14280 * @param {Roo.BasicDialog} this
14282 "beforeshow" : true,
14285 * Fires when this dialog is shown.
14286 * @param {Roo.BasicDialog} this
14290 el.on("keydown", this.onKeyDown, this);
14291 el.on("mousedown", this.toFront, this);
14292 Roo.EventManager.onWindowResize(this.adjustViewport, this, true);
14294 Roo.DialogManager.register(this);
14295 Roo.BasicDialog.superclass.constructor.call(this);
14298 Roo.extend(Roo.BasicDialog, Roo.util.Observable, {
14299 shadowOffset: Roo.isIE ? 6 : 5,
14302 minButtonWidth: 75,
14303 defaultButton: null,
14304 buttonAlign: "right",
14309 * Sets the dialog title text
14310 * @param {String} text The title text to display
14311 * @return {Roo.BasicDialog} this
14313 setTitle : function(text){
14314 this.header.update(text);
14319 closeClick : function(){
14324 collapseClick : function(){
14325 this[this.collapsed ? "expand" : "collapse"]();
14329 * Collapses the dialog to its minimized state (only the title bar is visible).
14330 * Equivalent to the user clicking the collapse dialog button.
14332 collapse : function(){
14333 if(!this.collapsed){
14334 this.collapsed = true;
14335 this.el.addClass("x-dlg-collapsed");
14336 this.restoreHeight = this.el.getHeight();
14337 this.resizeTo(this.el.getWidth(), this.header.getHeight());
14342 * Expands a collapsed dialog back to its normal state. Equivalent to the user
14343 * clicking the expand dialog button.
14345 expand : function(){
14346 if(this.collapsed){
14347 this.collapsed = false;
14348 this.el.removeClass("x-dlg-collapsed");
14349 this.resizeTo(this.el.getWidth(), this.restoreHeight);
14354 * Reinitializes the tabs component, clearing out old tabs and finding new ones.
14355 * @return {Roo.TabPanel} The tabs component
14357 initTabs : function(){
14358 var tabs = this.getTabs();
14359 while(tabs.getTab(0)){
14362 this.el.select(this.tabTag+'.x-dlg-tab').each(function(el){
14364 tabs.addTab(Roo.id(dom), dom.title);
14372 beforeResize : function(){
14373 this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
14377 onResize : function(){
14378 this.refreshSize();
14379 this.syncBodyHeight();
14380 this.adjustAssets();
14382 this.fireEvent("resize", this, this.size.width, this.size.height);
14386 onKeyDown : function(e){
14387 if(this.isVisible()){
14388 this.fireEvent("keydown", this, e);
14393 * Resizes the dialog.
14394 * @param {Number} width
14395 * @param {Number} height
14396 * @return {Roo.BasicDialog} this
14398 resizeTo : function(width, height){
14399 this.el.setSize(width, height);
14400 this.size = {width: width, height: height};
14401 this.syncBodyHeight();
14402 if(this.fixedcenter){
14405 if(this.isVisible()){
14406 this.constrainXY();
14407 this.adjustAssets();
14409 this.fireEvent("resize", this, width, height);
14415 * Resizes the dialog to fit the specified content size.
14416 * @param {Number} width
14417 * @param {Number} height
14418 * @return {Roo.BasicDialog} this
14420 setContentSize : function(w, h){
14421 h += this.getHeaderFooterHeight() + this.body.getMargins("tb");
14422 w += this.body.getMargins("lr") + this.bwrap.getMargins("lr") + this.centerBg.getPadding("lr");
14423 //if(!this.el.isBorderBox()){
14424 h += this.body.getPadding("tb") + this.bwrap.getBorderWidth("tb") + this.body.getBorderWidth("tb") + this.el.getBorderWidth("tb");
14425 w += this.body.getPadding("lr") + this.bwrap.getBorderWidth("lr") + this.body.getBorderWidth("lr") + this.bwrap.getPadding("lr") + this.el.getBorderWidth("lr");
14428 h += this.tabs.stripWrap.getHeight() + this.tabs.bodyEl.getMargins("tb") + this.tabs.bodyEl.getPadding("tb");
14429 w += this.tabs.bodyEl.getMargins("lr") + this.tabs.bodyEl.getPadding("lr");
14431 this.resizeTo(w, h);
14436 * Adds a key listener for when this dialog is displayed. This allows you to hook in a function that will be
14437 * executed in response to a particular key being pressed while the dialog is active.
14438 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the following options:
14439 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
14440 * @param {Function} fn The function to call
14441 * @param {Object} scope (optional) The scope of the function
14442 * @return {Roo.BasicDialog} this
14444 addKeyListener : function(key, fn, scope){
14445 var keyCode, shift, ctrl, alt;
14446 if(typeof key == "object" && !(key instanceof Array)){
14447 keyCode = key["key"];
14448 shift = key["shift"];
14449 ctrl = key["ctrl"];
14454 var handler = function(dlg, e){
14455 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
14456 var k = e.getKey();
14457 if(keyCode instanceof Array){
14458 for(var i = 0, len = keyCode.length; i < len; i++){
14459 if(keyCode[i] == k){
14460 fn.call(scope || window, dlg, k, e);
14466 fn.call(scope || window, dlg, k, e);
14471 this.on("keydown", handler);
14476 * Returns the TabPanel component (creates it if it doesn't exist).
14477 * Note: If you wish to simply check for the existence of tabs without creating them,
14478 * check for a null 'tabs' property.
14479 * @return {Roo.TabPanel} The tabs component
14481 getTabs : function(){
14483 this.el.addClass("x-dlg-auto-tabs");
14484 this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
14485 this.tabs = new Roo.TabPanel(this.body.dom, this.tabPosition == "bottom");
14491 * Adds a button to the footer section of the dialog.
14492 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
14493 * object or a valid Roo.DomHelper element config
14494 * @param {Function} handler The function called when the button is clicked
14495 * @param {Object} scope (optional) The scope of the handler function (accepts position as a property)
14496 * @return {Roo.Button} The new button
14498 addButton : function(config, handler, scope){
14499 var dh = Roo.DomHelper;
14501 this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
14503 if(!this.btnContainer){
14504 var tb = this.footer.createChild({
14506 cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
14507 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
14509 this.btnContainer = tb.firstChild.firstChild.firstChild;
14514 minWidth: this.minButtonWidth,
14517 if(typeof config == "string"){
14518 bconfig.text = config;
14521 bconfig.dhconfig = config;
14523 Roo.apply(bconfig, config);
14527 if ((typeof(bconfig.position) != 'undefined') && bconfig.position < this.btnContainer.childNodes.length-1) {
14528 bconfig.position = Math.max(0, bconfig.position);
14529 fc = this.btnContainer.childNodes[bconfig.position];
14532 var btn = new Roo.Button(
14534 this.btnContainer.insertBefore(document.createElement("td"),fc)
14535 : this.btnContainer.appendChild(document.createElement("td")),
14536 //Roo.get(this.btnContainer).createChild( { tag: 'td'}, fc ),
14539 this.syncBodyHeight();
14542 * Array of all the buttons that have been added to this dialog via addButton
14547 this.buttons.push(btn);
14552 * Sets the default button to be focused when the dialog is displayed.
14553 * @param {Roo.BasicDialog.Button} btn The button object returned by {@link #addButton}
14554 * @return {Roo.BasicDialog} this
14556 setDefaultButton : function(btn){
14557 this.defaultButton = btn;
14562 getHeaderFooterHeight : function(safe){
14565 height += this.header.getHeight();
14568 var fm = this.footer.getMargins();
14569 height += (this.footer.getHeight()+fm.top+fm.bottom);
14571 height += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
14572 height += this.centerBg.getPadding("tb");
14577 syncBodyHeight : function(){
14578 var bd = this.body, cb = this.centerBg, bw = this.bwrap;
14579 var height = this.size.height - this.getHeaderFooterHeight(false);
14580 bd.setHeight(height-bd.getMargins("tb"));
14581 var hh = this.header.getHeight();
14582 var h = this.size.height-hh;
14584 bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
14585 bw.setHeight(h-cb.getPadding("tb"));
14586 bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
14587 bd.setWidth(bw.getWidth(true));
14589 this.tabs.syncHeight();
14591 this.tabs.el.repaint();
14597 * Restores the previous state of the dialog if Roo.state is configured.
14598 * @return {Roo.BasicDialog} this
14600 restoreState : function(){
14601 var box = Roo.state.Manager.get(this.stateId || (this.el.id + "-state"));
14602 if(box && box.width){
14603 this.xy = [box.x, box.y];
14604 this.resizeTo(box.width, box.height);
14610 beforeShow : function(){
14612 if(this.fixedcenter){
14613 this.xy = this.el.getCenterXY(true);
14616 Roo.get(document.body).addClass("x-body-masked");
14617 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
14620 this.constrainXY();
14624 animShow : function(){
14625 var b = Roo.get(this.animateTarget).getBox();
14626 this.proxy.setSize(b.width, b.height);
14627 this.proxy.setLocation(b.x, b.y);
14629 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
14630 true, .35, this.showEl.createDelegate(this));
14634 * Shows the dialog.
14635 * @param {String/HTMLElement/Roo.Element} animateTarget (optional) Reset the animation target
14636 * @return {Roo.BasicDialog} this
14638 show : function(animateTarget){
14639 if (this.fireEvent("beforeshow", this) === false){
14642 if(this.syncHeightBeforeShow){
14643 this.syncBodyHeight();
14644 }else if(this.firstShow){
14645 this.firstShow = false;
14646 this.syncBodyHeight(); // sync the height on the first show instead of in the constructor
14648 this.animateTarget = animateTarget || this.animateTarget;
14649 if(!this.el.isVisible()){
14651 if(this.animateTarget && Roo.get(this.animateTarget)){
14661 showEl : function(){
14663 this.el.setXY(this.xy);
14665 this.adjustAssets(true);
14668 // IE peekaboo bug - fix found by Dave Fenwick
14672 this.fireEvent("show", this);
14676 * Focuses the dialog. If a defaultButton is set, it will receive focus, otherwise the
14677 * dialog itself will receive focus.
14679 focus : function(){
14680 if(this.defaultButton){
14681 this.defaultButton.focus();
14683 this.focusEl.focus();
14688 constrainXY : function(){
14689 if(this.constraintoviewport !== false){
14690 if(!this.viewSize){
14691 if(this.container){
14692 var s = this.container.getSize();
14693 this.viewSize = [s.width, s.height];
14695 this.viewSize = [Roo.lib.Dom.getViewWidth(),Roo.lib.Dom.getViewHeight()];
14698 var s = Roo.get(this.container||document).getScroll();
14700 var x = this.xy[0], y = this.xy[1];
14701 var w = this.size.width, h = this.size.height;
14702 var vw = this.viewSize[0], vh = this.viewSize[1];
14703 // only move it if it needs it
14705 // first validate right/bottom
14706 if(x + w > vw+s.left){
14710 if(y + h > vh+s.top){
14714 // then make sure top/left isn't negative
14726 if(this.isVisible()){
14727 this.el.setLocation(x, y);
14728 this.adjustAssets();
14735 onDrag : function(){
14736 if(!this.proxyDrag){
14737 this.xy = this.el.getXY();
14738 this.adjustAssets();
14743 adjustAssets : function(doShow){
14744 var x = this.xy[0], y = this.xy[1];
14745 var w = this.size.width, h = this.size.height;
14746 if(doShow === true){
14748 this.shadow.show(this.el);
14754 if(this.shadow && this.shadow.isVisible()){
14755 this.shadow.show(this.el);
14757 if(this.shim && this.shim.isVisible()){
14758 this.shim.setBounds(x, y, w, h);
14763 adjustViewport : function(w, h){
14765 w = Roo.lib.Dom.getViewWidth();
14766 h = Roo.lib.Dom.getViewHeight();
14769 this.viewSize = [w, h];
14770 if(this.modal && this.mask.isVisible()){
14771 this.mask.setSize(w, h); // first make sure the mask isn't causing overflow
14772 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
14774 if(this.isVisible()){
14775 this.constrainXY();
14780 * Destroys this dialog and all its supporting elements (including any tabs, shim,
14781 * shadow, proxy, mask, etc.) Also removes all event listeners.
14782 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
14784 destroy : function(removeEl){
14785 if(this.isVisible()){
14786 this.animateTarget = null;
14789 Roo.EventManager.removeResizeListener(this.adjustViewport, this);
14791 this.tabs.destroy(removeEl);
14804 for(var i = 0, len = this.buttons.length; i < len; i++){
14805 this.buttons[i].destroy();
14808 this.el.removeAllListeners();
14809 if(removeEl === true){
14810 this.el.update("");
14813 Roo.DialogManager.unregister(this);
14817 startMove : function(){
14818 if(this.proxyDrag){
14821 if(this.constraintoviewport !== false){
14822 this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
14827 endMove : function(){
14828 if(!this.proxyDrag){
14829 Roo.dd.DD.prototype.endDrag.apply(this.dd, arguments);
14831 Roo.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
14834 this.refreshSize();
14835 this.adjustAssets();
14837 this.fireEvent("move", this, this.xy[0], this.xy[1]);
14841 * Brings this dialog to the front of any other visible dialogs
14842 * @return {Roo.BasicDialog} this
14844 toFront : function(){
14845 Roo.DialogManager.bringToFront(this);
14850 * Sends this dialog to the back (under) of any other visible dialogs
14851 * @return {Roo.BasicDialog} this
14853 toBack : function(){
14854 Roo.DialogManager.sendToBack(this);
14859 * Centers this dialog in the viewport
14860 * @return {Roo.BasicDialog} this
14862 center : function(){
14863 var xy = this.el.getCenterXY(true);
14864 this.moveTo(xy[0], xy[1]);
14869 * Moves the dialog's top-left corner to the specified point
14870 * @param {Number} x
14871 * @param {Number} y
14872 * @return {Roo.BasicDialog} this
14874 moveTo : function(x, y){
14876 if(this.isVisible()){
14877 this.el.setXY(this.xy);
14878 this.adjustAssets();
14884 * Aligns the dialog to the specified element
14885 * @param {String/HTMLElement/Roo.Element} element The element to align to.
14886 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details).
14887 * @param {Array} offsets (optional) Offset the positioning by [x, y]
14888 * @return {Roo.BasicDialog} this
14890 alignTo : function(element, position, offsets){
14891 this.xy = this.el.getAlignToXY(element, position, offsets);
14892 if(this.isVisible()){
14893 this.el.setXY(this.xy);
14894 this.adjustAssets();
14900 * Anchors an element to another element and realigns it when the window is resized.
14901 * @param {String/HTMLElement/Roo.Element} element The element to align to.
14902 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details)
14903 * @param {Array} offsets (optional) Offset the positioning by [x, y]
14904 * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
14905 * is a number, it is used as the buffer delay (defaults to 50ms).
14906 * @return {Roo.BasicDialog} this
14908 anchorTo : function(el, alignment, offsets, monitorScroll){
14909 var action = function(){
14910 this.alignTo(el, alignment, offsets);
14912 Roo.EventManager.onWindowResize(action, this);
14913 var tm = typeof monitorScroll;
14914 if(tm != 'undefined'){
14915 Roo.EventManager.on(window, 'scroll', action, this,
14916 {buffer: tm == 'number' ? monitorScroll : 50});
14923 * Returns true if the dialog is visible
14924 * @return {Boolean}
14926 isVisible : function(){
14927 return this.el.isVisible();
14931 animHide : function(callback){
14932 var b = Roo.get(this.animateTarget).getBox();
14934 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
14936 this.proxy.setBounds(b.x, b.y, b.width, b.height, true, .35,
14937 this.hideEl.createDelegate(this, [callback]));
14941 * Hides the dialog.
14942 * @param {Function} callback (optional) Function to call when the dialog is hidden
14943 * @return {Roo.BasicDialog} this
14945 hide : function(callback){
14946 if (this.fireEvent("beforehide", this) === false){
14950 this.shadow.hide();
14955 // sometimes animateTarget seems to get set.. causing problems...
14956 // this just double checks..
14957 if(this.animateTarget && Roo.get(this.animateTarget)) {
14958 this.animHide(callback);
14961 this.hideEl(callback);
14967 hideEl : function(callback){
14971 Roo.get(document.body).removeClass("x-body-masked");
14973 this.fireEvent("hide", this);
14974 if(typeof callback == "function"){
14980 hideAction : function(){
14981 this.setLeft("-10000px");
14982 this.setTop("-10000px");
14983 this.setStyle("visibility", "hidden");
14987 refreshSize : function(){
14988 this.size = this.el.getSize();
14989 this.xy = this.el.getXY();
14990 Roo.state.Manager.set(this.stateId || this.el.id + "-state", this.el.getBox());
14994 // z-index is managed by the DialogManager and may be overwritten at any time
14995 setZIndex : function(index){
14997 this.mask.setStyle("z-index", index);
15000 this.shim.setStyle("z-index", ++index);
15003 this.shadow.setZIndex(++index);
15005 this.el.setStyle("z-index", ++index);
15007 this.proxy.setStyle("z-index", ++index);
15010 this.resizer.proxy.setStyle("z-index", ++index);
15013 this.lastZIndex = index;
15017 * Returns the element for this dialog
15018 * @return {Roo.Element} The underlying dialog Element
15020 getEl : function(){
15026 * @class Roo.DialogManager
15027 * Provides global access to BasicDialogs that have been created and
15028 * support for z-indexing (layering) multiple open dialogs.
15030 Roo.DialogManager = function(){
15032 var accessList = [];
15036 var sortDialogs = function(d1, d2){
15037 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
15041 var orderDialogs = function(){
15042 accessList.sort(sortDialogs);
15043 var seed = Roo.DialogManager.zseed;
15044 for(var i = 0, len = accessList.length; i < len; i++){
15045 var dlg = accessList[i];
15047 dlg.setZIndex(seed + (i*10));
15054 * The starting z-index for BasicDialogs (defaults to 9000)
15055 * @type Number The z-index value
15060 register : function(dlg){
15061 list[dlg.id] = dlg;
15062 accessList.push(dlg);
15066 unregister : function(dlg){
15067 delete list[dlg.id];
15070 if(!accessList.indexOf){
15071 for( i = 0, len = accessList.length; i < len; i++){
15072 if(accessList[i] == dlg){
15073 accessList.splice(i, 1);
15078 i = accessList.indexOf(dlg);
15080 accessList.splice(i, 1);
15086 * Gets a registered dialog by id
15087 * @param {String/Object} id The id of the dialog or a dialog
15088 * @return {Roo.BasicDialog} this
15090 get : function(id){
15091 return typeof id == "object" ? id : list[id];
15095 * Brings the specified dialog to the front
15096 * @param {String/Object} dlg The id of the dialog or a dialog
15097 * @return {Roo.BasicDialog} this
15099 bringToFront : function(dlg){
15100 dlg = this.get(dlg);
15103 dlg._lastAccess = new Date().getTime();
15110 * Sends the specified dialog to the back
15111 * @param {String/Object} dlg The id of the dialog or a dialog
15112 * @return {Roo.BasicDialog} this
15114 sendToBack : function(dlg){
15115 dlg = this.get(dlg);
15116 dlg._lastAccess = -(new Date().getTime());
15122 * Hides all dialogs
15124 hideAll : function(){
15125 for(var id in list){
15126 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
15135 * @class Roo.LayoutDialog
15136 * @extends Roo.BasicDialog
15137 * Dialog which provides adjustments for working with a layout in a Dialog.
15138 * Add your necessary layout config options to the dialog's config.<br>
15139 * Example usage (including a nested layout):
15142 dialog = new Roo.LayoutDialog("download-dlg", {
15151 // layout config merges with the dialog config
15153 tabPosition: "top",
15154 alwaysShowTabs: true
15157 dialog.addKeyListener(27, dialog.hide, dialog);
15158 dialog.setDefaultButton(dialog.addButton("Close", dialog.hide, dialog));
15159 dialog.addButton("Build It!", this.getDownload, this);
15161 // we can even add nested layouts
15162 var innerLayout = new Roo.BorderLayout("dl-inner", {
15172 innerLayout.beginUpdate();
15173 innerLayout.add("east", new Roo.ContentPanel("dl-details"));
15174 innerLayout.add("center", new Roo.ContentPanel("selection-panel"));
15175 innerLayout.endUpdate(true);
15177 var layout = dialog.getLayout();
15178 layout.beginUpdate();
15179 layout.add("center", new Roo.ContentPanel("standard-panel",
15180 {title: "Download the Source", fitToFrame:true}));
15181 layout.add("center", new Roo.NestedLayoutPanel(innerLayout,
15182 {title: "Build your own roo.js"}));
15183 layout.getRegion("center").showPanel(sp);
15184 layout.endUpdate();
15188 * @param {String/HTMLElement/Roo.Element} el The id of or container element, or config
15189 * @param {Object} config configuration options
15191 Roo.LayoutDialog = function(el, cfg){
15194 if (typeof(cfg) == 'undefined') {
15195 config = Roo.apply({}, el);
15196 // not sure why we use documentElement here.. - it should always be body.
15197 // IE7 borks horribly if we use documentElement.
15198 el = Roo.get( Roo.isIE ? (document.body || document.documentElement) : (document.documentElement || document.body) ).createChild();
15199 //config.autoCreate = true;
15203 config.autoTabs = false;
15204 Roo.LayoutDialog.superclass.constructor.call(this, el, config);
15205 this.body.setStyle({overflow:"hidden", position:"relative"});
15206 this.layout = new Roo.BorderLayout(this.body.dom, config);
15207 this.layout.monitorWindowResize = false;
15208 this.el.addClass("x-dlg-auto-layout");
15209 // fix case when center region overwrites center function
15210 this.center = Roo.BasicDialog.prototype.center;
15211 this.on("show", this.layout.layout, this.layout, true);
15212 if (config.items) {
15213 var xitems = config.items;
15214 delete config.items;
15215 Roo.each(xitems, this.addxtype, this);
15220 Roo.extend(Roo.LayoutDialog, Roo.BasicDialog, {
15222 * Ends update of the layout <strike>and resets display to none</strike>. Use standard beginUpdate/endUpdate on the layout.
15225 endUpdate : function(){
15226 this.layout.endUpdate();
15230 * Begins an update of the layout <strike>and sets display to block and visibility to hidden</strike>. Use standard beginUpdate/endUpdate on the layout.
15233 beginUpdate : function(){
15234 this.layout.beginUpdate();
15238 * Get the BorderLayout for this dialog
15239 * @return {Roo.BorderLayout}
15241 getLayout : function(){
15242 return this.layout;
15245 showEl : function(){
15246 Roo.LayoutDialog.superclass.showEl.apply(this, arguments);
15248 this.layout.layout();
15253 // Use the syncHeightBeforeShow config option to control this automatically
15254 syncBodyHeight : function(){
15255 Roo.LayoutDialog.superclass.syncBodyHeight.call(this);
15256 if(this.layout){this.layout.layout();}
15260 * Add an xtype element (actually adds to the layout.)
15261 * @return {Object} xdata xtype object data.
15264 addxtype : function(c) {
15265 return this.layout.addxtype(c);
15269 * Ext JS Library 1.1.1
15270 * Copyright(c) 2006-2007, Ext JS, LLC.
15272 * Originally Released Under LGPL - original licence link has changed is not relivant.
15275 * <script type="text/javascript">
15279 * @class Roo.MessageBox
15280 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
15284 Roo.Msg.alert('Status', 'Changes saved successfully.');
15286 // Prompt for user data:
15287 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
15289 // process text value...
15293 // Show a dialog using config options:
15295 title:'Save Changes?',
15296 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
15297 buttons: Roo.Msg.YESNOCANCEL,
15304 Roo.MessageBox = function(){
15305 var dlg, opt, mask, waitTimer;
15306 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
15307 var buttons, activeTextEl, bwidth;
15310 var handleButton = function(button){
15312 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
15316 var handleHide = function(){
15317 if(opt && opt.cls){
15318 dlg.el.removeClass(opt.cls);
15321 Roo.TaskMgr.stop(waitTimer);
15327 var updateButtons = function(b){
15330 buttons["ok"].hide();
15331 buttons["cancel"].hide();
15332 buttons["yes"].hide();
15333 buttons["no"].hide();
15334 dlg.footer.dom.style.display = 'none';
15337 dlg.footer.dom.style.display = '';
15338 for(var k in buttons){
15339 if(typeof buttons[k] != "function"){
15342 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.MessageBox.buttonText[k]);
15343 width += buttons[k].el.getWidth()+15;
15353 var handleEsc = function(d, k, e){
15354 if(opt && opt.closable !== false){
15364 * Returns a reference to the underlying {@link Roo.BasicDialog} element
15365 * @return {Roo.BasicDialog} The BasicDialog element
15367 getDialog : function(){
15369 dlg = new Roo.BasicDialog("x-msg-box", {
15374 constraintoviewport:false,
15376 collapsible : false,
15379 width:400, height:100,
15380 buttonAlign:"center",
15381 closeClick : function(){
15382 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
15383 handleButton("no");
15385 handleButton("cancel");
15389 dlg.on("hide", handleHide);
15391 dlg.addKeyListener(27, handleEsc);
15393 var bt = this.buttonText;
15394 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
15395 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
15396 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
15397 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
15398 bodyEl = dlg.body.createChild({
15400 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>'
15402 msgEl = bodyEl.dom.firstChild;
15403 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
15404 textboxEl.enableDisplayMode();
15405 textboxEl.addKeyListener([10,13], function(){
15406 if(dlg.isVisible() && opt && opt.buttons){
15407 if(opt.buttons.ok){
15408 handleButton("ok");
15409 }else if(opt.buttons.yes){
15410 handleButton("yes");
15414 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
15415 textareaEl.enableDisplayMode();
15416 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
15417 progressEl.enableDisplayMode();
15418 var pf = progressEl.dom.firstChild;
15420 pp = Roo.get(pf.firstChild);
15421 pp.setHeight(pf.offsetHeight);
15429 * Updates the message box body text
15430 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
15431 * the XHTML-compliant non-breaking space character '&#160;')
15432 * @return {Roo.MessageBox} This message box
15434 updateText : function(text){
15435 if(!dlg.isVisible() && !opt.width){
15436 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
15438 msgEl.innerHTML = text || ' ';
15439 var w = Math.max(Math.min(opt.width || msgEl.offsetWidth, this.maxWidth),
15440 Math.max(opt.minWidth || this.minWidth, bwidth));
15442 activeTextEl.setWidth(w);
15444 if(dlg.isVisible()){
15445 dlg.fixedcenter = false;
15447 dlg.setContentSize(w, bodyEl.getHeight());
15448 if(dlg.isVisible()){
15449 dlg.fixedcenter = true;
15455 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
15456 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
15457 * @param {Number} value Any number between 0 and 1 (e.g., .5)
15458 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
15459 * @return {Roo.MessageBox} This message box
15461 updateProgress : function(value, text){
15463 this.updateText(text);
15465 if (pp) { // weird bug on my firefox - for some reason this is not defined
15466 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
15472 * Returns true if the message box is currently displayed
15473 * @return {Boolean} True if the message box is visible, else false
15475 isVisible : function(){
15476 return dlg && dlg.isVisible();
15480 * Hides the message box if it is displayed
15483 if(this.isVisible()){
15489 * Displays a new message box, or reinitializes an existing message box, based on the config options
15490 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
15491 * The following config object properties are supported:
15493 Property Type Description
15494 ---------- --------------- ------------------------------------------------------------------------------------
15495 animEl String/Element An id or Element from which the message box should animate as it opens and
15496 closes (defaults to undefined)
15497 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
15498 cancel:'Bar'}), or false to not show any buttons (defaults to false)
15499 closable Boolean False to hide the top-right close button (defaults to true). Note that
15500 progress and wait dialogs will ignore this property and always hide the
15501 close button as they can only be closed programmatically.
15502 cls String A custom CSS class to apply to the message box element
15503 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
15504 displayed (defaults to 75)
15505 fn Function A callback function to execute after closing the dialog. The arguments to the
15506 function will be btn (the name of the button that was clicked, if applicable,
15507 e.g. "ok"), and text (the value of the active text field, if applicable).
15508 Progress and wait dialogs will ignore this option since they do not respond to
15509 user actions and can only be closed programmatically, so any required function
15510 should be called by the same code after it closes the dialog.
15511 icon String A CSS class that provides a background image to be used as an icon for
15512 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
15513 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
15514 minWidth Number The minimum width in pixels of the message box (defaults to 100)
15515 modal Boolean False to allow user interaction with the page while the message box is
15516 displayed (defaults to true)
15517 msg String A string that will replace the existing message box body text (defaults
15518 to the XHTML-compliant non-breaking space character ' ')
15519 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
15520 progress Boolean True to display a progress bar (defaults to false)
15521 progressText String The text to display inside the progress bar if progress = true (defaults to '')
15522 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
15523 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
15524 title String The title text
15525 value String The string value to set into the active textbox element if displayed
15526 wait Boolean True to display a progress bar (defaults to false)
15527 width Number The width of the dialog in pixels
15534 msg: 'Please enter your address:',
15536 buttons: Roo.MessageBox.OKCANCEL,
15539 animEl: 'addAddressBtn'
15542 * @param {Object} config Configuration options
15543 * @return {Roo.MessageBox} This message box
15545 show : function(options){
15546 if(this.isVisible()){
15549 var d = this.getDialog();
15551 d.setTitle(opt.title || " ");
15552 d.close.setDisplayed(opt.closable !== false);
15553 activeTextEl = textboxEl;
15554 opt.prompt = opt.prompt || (opt.multiline ? true : false);
15559 textareaEl.setHeight(typeof opt.multiline == "number" ?
15560 opt.multiline : this.defaultTextHeight);
15561 activeTextEl = textareaEl;
15570 progressEl.setDisplayed(opt.progress === true);
15571 this.updateProgress(0);
15572 activeTextEl.dom.value = opt.value || "";
15574 dlg.setDefaultButton(activeTextEl);
15576 var bs = opt.buttons;
15579 db = buttons["ok"];
15580 }else if(bs && bs.yes){
15581 db = buttons["yes"];
15583 dlg.setDefaultButton(db);
15585 bwidth = updateButtons(opt.buttons);
15586 this.updateText(opt.msg);
15588 d.el.addClass(opt.cls);
15590 d.proxyDrag = opt.proxyDrag === true;
15591 d.modal = opt.modal !== false;
15592 d.mask = opt.modal !== false ? mask : false;
15593 if(!d.isVisible()){
15594 // force it to the end of the z-index stack so it gets a cursor in FF
15595 document.body.appendChild(dlg.el.dom);
15596 d.animateTarget = null;
15597 d.show(options.animEl);
15603 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
15604 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
15605 * and closing the message box when the process is complete.
15606 * @param {String} title The title bar text
15607 * @param {String} msg The message box body text
15608 * @return {Roo.MessageBox} This message box
15610 progress : function(title, msg){
15617 minWidth: this.minProgressWidth,
15624 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
15625 * If a callback function is passed it will be called after the user clicks the button, and the
15626 * id of the button that was clicked will be passed as the only parameter to the callback
15627 * (could also be the top-right close button).
15628 * @param {String} title The title bar text
15629 * @param {String} msg The message box body text
15630 * @param {Function} fn (optional) The callback function invoked after the message box is closed
15631 * @param {Object} scope (optional) The scope of the callback function
15632 * @return {Roo.MessageBox} This message box
15634 alert : function(title, msg, fn, scope){
15647 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
15648 * interaction while waiting for a long-running process to complete that does not have defined intervals.
15649 * You are responsible for closing the message box when the process is complete.
15650 * @param {String} msg The message box body text
15651 * @param {String} title (optional) The title bar text
15652 * @return {Roo.MessageBox} This message box
15654 wait : function(msg, title){
15665 waitTimer = Roo.TaskMgr.start({
15667 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
15675 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
15676 * If a callback function is passed it will be called after the user clicks either button, and the id of the
15677 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
15678 * @param {String} title The title bar text
15679 * @param {String} msg The message box body text
15680 * @param {Function} fn (optional) The callback function invoked after the message box is closed
15681 * @param {Object} scope (optional) The scope of the callback function
15682 * @return {Roo.MessageBox} This message box
15684 confirm : function(title, msg, fn, scope){
15688 buttons: this.YESNO,
15697 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
15698 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
15699 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
15700 * (could also be the top-right close button) and the text that was entered will be passed as the two
15701 * parameters to the callback.
15702 * @param {String} title The title bar text
15703 * @param {String} msg The message box body text
15704 * @param {Function} fn (optional) The callback function invoked after the message box is closed
15705 * @param {Object} scope (optional) The scope of the callback function
15706 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
15707 * property, or the height in pixels to create the textbox (defaults to false / single-line)
15708 * @return {Roo.MessageBox} This message box
15710 prompt : function(title, msg, fn, scope, multiline){
15714 buttons: this.OKCANCEL,
15719 multiline: multiline,
15726 * Button config that displays a single OK button
15731 * Button config that displays Yes and No buttons
15734 YESNO : {yes:true, no:true},
15736 * Button config that displays OK and Cancel buttons
15739 OKCANCEL : {ok:true, cancel:true},
15741 * Button config that displays Yes, No and Cancel buttons
15744 YESNOCANCEL : {yes:true, no:true, cancel:true},
15747 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
15750 defaultTextHeight : 75,
15752 * The maximum width in pixels of the message box (defaults to 600)
15757 * The minimum width in pixels of the message box (defaults to 100)
15762 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
15763 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
15766 minProgressWidth : 250,
15768 * An object containing the default button text strings that can be overriden for localized language support.
15769 * Supported properties are: ok, cancel, yes and no.
15770 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
15783 * Shorthand for {@link Roo.MessageBox}
15785 Roo.Msg = Roo.MessageBox;/*
15787 * Ext JS Library 1.1.1
15788 * Copyright(c) 2006-2007, Ext JS, LLC.
15790 * Originally Released Under LGPL - original licence link has changed is not relivant.
15793 * <script type="text/javascript">
15796 * @class Roo.QuickTips
15797 * Provides attractive and customizable tooltips for any element.
15800 Roo.QuickTips = function(){
15801 var el, tipBody, tipBodyText, tipTitle, tm, cfg, close, tagEls = {}, esc, removeCls = null, bdLeft, bdRight;
15802 var ce, bd, xy, dd;
15803 var visible = false, disabled = true, inited = false;
15804 var showProc = 1, hideProc = 1, dismissProc = 1, locks = [];
15806 var onOver = function(e){
15810 var t = e.getTarget();
15811 if(!t || t.nodeType !== 1 || t == document || t == document.body){
15814 if(ce && t == ce.el){
15815 clearTimeout(hideProc);
15818 if(t && tagEls[t.id]){
15819 tagEls[t.id].el = t;
15820 showProc = show.defer(tm.showDelay, tm, [tagEls[t.id]]);
15823 var ttp, et = Roo.fly(t);
15824 var ns = cfg.namespace;
15825 if(tm.interceptTitles && t.title){
15828 t.removeAttribute("title");
15829 e.preventDefault();
15831 ttp = t.qtip || et.getAttributeNS(ns, cfg.attribute);
15834 showProc = show.defer(tm.showDelay, tm, [{
15837 width: et.getAttributeNS(ns, cfg.width),
15838 autoHide: et.getAttributeNS(ns, cfg.hide) != "user",
15839 title: et.getAttributeNS(ns, cfg.title),
15840 cls: et.getAttributeNS(ns, cfg.cls)
15845 var onOut = function(e){
15846 clearTimeout(showProc);
15847 var t = e.getTarget();
15848 if(t && ce && ce.el == t && (tm.autoHide && ce.autoHide !== false)){
15849 hideProc = setTimeout(hide, tm.hideDelay);
15853 var onMove = function(e){
15859 if(tm.trackMouse && ce){
15864 var onDown = function(e){
15865 clearTimeout(showProc);
15866 clearTimeout(hideProc);
15868 if(tm.hideOnClick){
15871 tm.enable.defer(100, tm);
15876 var getPad = function(){
15877 return 2;//bdLeft.getPadding('l')+bdRight.getPadding('r');
15880 var show = function(o){
15884 clearTimeout(dismissProc);
15886 if(removeCls){ // in case manually hidden
15887 el.removeClass(removeCls);
15891 el.addClass(ce.cls);
15892 removeCls = ce.cls;
15895 tipTitle.update(ce.title);
15898 tipTitle.update('');
15901 el.dom.style.width = tm.maxWidth+'px';
15902 //tipBody.dom.style.width = '';
15903 tipBodyText.update(o.text);
15904 var p = getPad(), w = ce.width;
15906 var td = tipBodyText.dom;
15907 var aw = Math.max(td.offsetWidth, td.clientWidth, td.scrollWidth);
15908 if(aw > tm.maxWidth){
15910 }else if(aw < tm.minWidth){
15916 //tipBody.setWidth(w);
15917 el.setWidth(parseInt(w, 10) + p);
15918 if(ce.autoHide === false){
15919 close.setDisplayed(true);
15924 close.setDisplayed(false);
15930 el.avoidY = xy[1]-18;
15935 el.setStyle("visibility", "visible");
15936 el.fadeIn({callback: afterShow});
15942 var afterShow = function(){
15946 if(tm.autoDismiss && ce.autoHide !== false){
15947 dismissProc = setTimeout(hide, tm.autoDismissDelay);
15952 var hide = function(noanim){
15953 clearTimeout(dismissProc);
15954 clearTimeout(hideProc);
15956 if(el.isVisible()){
15958 if(noanim !== true && tm.animate){
15959 el.fadeOut({callback: afterHide});
15966 var afterHide = function(){
15969 el.removeClass(removeCls);
15976 * @cfg {Number} minWidth
15977 * The minimum width of the quick tip (defaults to 40)
15981 * @cfg {Number} maxWidth
15982 * The maximum width of the quick tip (defaults to 300)
15986 * @cfg {Boolean} interceptTitles
15987 * True to automatically use the element's DOM title value if available (defaults to false)
15989 interceptTitles : false,
15991 * @cfg {Boolean} trackMouse
15992 * True to have the quick tip follow the mouse as it moves over the target element (defaults to false)
15994 trackMouse : false,
15996 * @cfg {Boolean} hideOnClick
15997 * True to hide the quick tip if the user clicks anywhere in the document (defaults to true)
15999 hideOnClick : true,
16001 * @cfg {Number} showDelay
16002 * Delay in milliseconds before the quick tip displays after the mouse enters the target element (defaults to 500)
16006 * @cfg {Number} hideDelay
16007 * Delay in milliseconds before the quick tip hides when autoHide = true (defaults to 200)
16011 * @cfg {Boolean} autoHide
16012 * True to automatically hide the quick tip after the mouse exits the target element (defaults to true).
16013 * Used in conjunction with hideDelay.
16018 * True to automatically hide the quick tip after a set period of time, regardless of the user's actions
16019 * (defaults to true). Used in conjunction with autoDismissDelay.
16021 autoDismiss : true,
16024 * Delay in milliseconds before the quick tip hides when autoDismiss = true (defaults to 5000)
16026 autoDismissDelay : 5000,
16028 * @cfg {Boolean} animate
16029 * True to turn on fade animation. Defaults to false (ClearType/scrollbar flicker issues in IE7).
16034 * @cfg {String} title
16035 * Title text to display (defaults to ''). This can be any valid HTML markup.
16039 * @cfg {String} text
16040 * Body text to display (defaults to ''). This can be any valid HTML markup.
16044 * @cfg {String} cls
16045 * A CSS class to apply to the base quick tip element (defaults to '').
16049 * @cfg {Number} width
16050 * Width in pixels of the quick tip (defaults to auto). Width will be ignored if it exceeds the bounds of
16051 * minWidth or maxWidth.
16056 * Initialize and enable QuickTips for first use. This should be called once before the first attempt to access
16057 * or display QuickTips in a page.
16060 tm = Roo.QuickTips;
16061 cfg = tm.tagConfig;
16063 if(!Roo.isReady){ // allow calling of init() before onReady
16064 Roo.onReady(Roo.QuickTips.init, Roo.QuickTips);
16067 el = new Roo.Layer({cls:"x-tip", shadow:"drop", shim: true, constrain:true, shadowOffset:4});
16068 el.fxDefaults = {stopFx: true};
16069 // maximum custom styling
16070 //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>');
16071 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>');
16072 tipTitle = el.child('h3');
16073 tipTitle.enableDisplayMode("block");
16074 tipBody = el.child('div.x-tip-bd');
16075 tipBodyText = el.child('div.x-tip-bd-inner');
16076 //bdLeft = el.child('div.x-tip-bd-left');
16077 //bdRight = el.child('div.x-tip-bd-right');
16078 close = el.child('div.x-tip-close');
16079 close.enableDisplayMode("block");
16080 close.on("click", hide);
16081 var d = Roo.get(document);
16082 d.on("mousedown", onDown);
16083 d.on("mouseover", onOver);
16084 d.on("mouseout", onOut);
16085 d.on("mousemove", onMove);
16086 esc = d.addKeyListener(27, hide);
16089 dd = el.initDD("default", null, {
16090 onDrag : function(){
16094 dd.setHandleElId(tipTitle.id);
16103 * Configures a new quick tip instance and assigns it to a target element. The following config options
16106 Property Type Description
16107 ---------- --------------------- ------------------------------------------------------------------------
16108 target Element/String/Array An Element, id or array of ids that this quick tip should be tied to
16110 * @param {Object} config The config object
16112 register : function(config){
16113 var cs = config instanceof Array ? config : arguments;
16114 for(var i = 0, len = cs.length; i < len; i++) {
16116 var target = c.target;
16118 if(target instanceof Array){
16119 for(var j = 0, jlen = target.length; j < jlen; j++){
16120 tagEls[target[j]] = c;
16123 tagEls[typeof target == 'string' ? target : Roo.id(target)] = c;
16130 * Removes this quick tip from its element and destroys it.
16131 * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
16133 unregister : function(el){
16134 delete tagEls[Roo.id(el)];
16138 * Enable this quick tip.
16140 enable : function(){
16141 if(inited && disabled){
16143 if(locks.length < 1){
16150 * Disable this quick tip.
16152 disable : function(){
16154 clearTimeout(showProc);
16155 clearTimeout(hideProc);
16156 clearTimeout(dismissProc);
16164 * Returns true if the quick tip is enabled, else false.
16166 isEnabled : function(){
16173 attribute : "qtip",
16183 // backwards compat
16184 Roo.QuickTips.tips = Roo.QuickTips.register;/*
16186 * Ext JS Library 1.1.1
16187 * Copyright(c) 2006-2007, Ext JS, LLC.
16189 * Originally Released Under LGPL - original licence link has changed is not relivant.
16192 * <script type="text/javascript">
16197 * @class Roo.tree.TreePanel
16198 * @extends Roo.data.Tree
16200 * @cfg {Boolean} rootVisible false to hide the root node (defaults to true)
16201 * @cfg {Boolean} lines false to disable tree lines (defaults to true)
16202 * @cfg {Boolean} enableDD true to enable drag and drop
16203 * @cfg {Boolean} enableDrag true to enable just drag
16204 * @cfg {Boolean} enableDrop true to enable just drop
16205 * @cfg {Object} dragConfig Custom config to pass to the {@link Roo.tree.TreeDragZone} instance
16206 * @cfg {Object} dropConfig Custom config to pass to the {@link Roo.tree.TreeDropZone} instance
16207 * @cfg {String} ddGroup The DD group this TreePanel belongs to
16208 * @cfg {String} ddAppendOnly True if the tree should only allow append drops (use for trees which are sorted)
16209 * @cfg {Boolean} ddScroll true to enable YUI body scrolling
16210 * @cfg {Boolean} containerScroll true to register this container with ScrollManager
16211 * @cfg {Boolean} hlDrop false to disable node highlight on drop (defaults to the value of Roo.enableFx)
16212 * @cfg {String} hlColor The color of the node highlight (defaults to C3DAF9)
16213 * @cfg {Boolean} animate true to enable animated expand/collapse (defaults to the value of Roo.enableFx)
16214 * @cfg {Boolean} singleExpand true if only 1 node per branch may be expanded
16215 * @cfg {Boolean} selModel A tree selection model to use with this TreePanel (defaults to a {@link Roo.tree.DefaultSelectionModel})
16216 * @cfg {Boolean} loader A TreeLoader for use with this TreePanel
16217 * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to '/')
16218 * @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>
16219 * @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>
16222 * @param {String/HTMLElement/Element} el The container element
16223 * @param {Object} config
16225 Roo.tree.TreePanel = function(el, config){
16227 var loader = false;
16229 root = config.root;
16230 delete config.root;
16232 if (config.loader) {
16233 loader = config.loader;
16234 delete config.loader;
16237 Roo.apply(this, config);
16238 Roo.tree.TreePanel.superclass.constructor.call(this);
16239 this.el = Roo.get(el);
16240 this.el.addClass('x-tree');
16241 //console.log(root);
16243 this.setRootNode( Roo.factory(root, Roo.tree));
16246 this.loader = Roo.factory(loader, Roo.tree);
16249 * Read-only. The id of the container element becomes this TreePanel's id.
16251 this.id = this.el.id;
16254 * @event beforeload
16255 * Fires before a node is loaded, return false to cancel
16256 * @param {Node} node The node being loaded
16258 "beforeload" : true,
16261 * Fires when a node is loaded
16262 * @param {Node} node The node that was loaded
16266 * @event textchange
16267 * Fires when the text for a node is changed
16268 * @param {Node} node The node
16269 * @param {String} text The new text
16270 * @param {String} oldText The old text
16272 "textchange" : true,
16274 * @event beforeexpand
16275 * Fires before a node is expanded, return false to cancel.
16276 * @param {Node} node The node
16277 * @param {Boolean} deep
16278 * @param {Boolean} anim
16280 "beforeexpand" : true,
16282 * @event beforecollapse
16283 * Fires before a node is collapsed, return false to cancel.
16284 * @param {Node} node The node
16285 * @param {Boolean} deep
16286 * @param {Boolean} anim
16288 "beforecollapse" : true,
16291 * Fires when a node is expanded
16292 * @param {Node} node The node
16296 * @event disabledchange
16297 * Fires when the disabled status of a node changes
16298 * @param {Node} node The node
16299 * @param {Boolean} disabled
16301 "disabledchange" : true,
16304 * Fires when a node is collapsed
16305 * @param {Node} node The node
16309 * @event beforeclick
16310 * Fires before click processing on a node. Return false to cancel the default action.
16311 * @param {Node} node The node
16312 * @param {Roo.EventObject} e The event object
16314 "beforeclick":true,
16316 * @event checkchange
16317 * Fires when a node with a checkbox's checked property changes
16318 * @param {Node} this This node
16319 * @param {Boolean} checked
16321 "checkchange":true,
16324 * Fires when a node is clicked
16325 * @param {Node} node The node
16326 * @param {Roo.EventObject} e The event object
16331 * Fires when a node is double clicked
16332 * @param {Node} node The node
16333 * @param {Roo.EventObject} e The event object
16337 * @event contextmenu
16338 * Fires when a node is right clicked
16339 * @param {Node} node The node
16340 * @param {Roo.EventObject} e The event object
16342 "contextmenu":true,
16344 * @event beforechildrenrendered
16345 * Fires right before the child nodes for a node are rendered
16346 * @param {Node} node The node
16348 "beforechildrenrendered":true,
16351 * Fires when a node starts being dragged
16352 * @param {Roo.tree.TreePanel} this
16353 * @param {Roo.tree.TreeNode} node
16354 * @param {event} e The raw browser event
16356 "startdrag" : true,
16359 * Fires when a drag operation is complete
16360 * @param {Roo.tree.TreePanel} this
16361 * @param {Roo.tree.TreeNode} node
16362 * @param {event} e The raw browser event
16367 * Fires when a dragged node is dropped on a valid DD target
16368 * @param {Roo.tree.TreePanel} this
16369 * @param {Roo.tree.TreeNode} node
16370 * @param {DD} dd The dd it was dropped on
16371 * @param {event} e The raw browser event
16375 * @event beforenodedrop
16376 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
16377 * passed to handlers has the following properties:<br />
16378 * <ul style="padding:5px;padding-left:16px;">
16379 * <li>tree - The TreePanel</li>
16380 * <li>target - The node being targeted for the drop</li>
16381 * <li>data - The drag data from the drag source</li>
16382 * <li>point - The point of the drop - append, above or below</li>
16383 * <li>source - The drag source</li>
16384 * <li>rawEvent - Raw mouse event</li>
16385 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
16386 * to be inserted by setting them on this object.</li>
16387 * <li>cancel - Set this to true to cancel the drop.</li>
16389 * @param {Object} dropEvent
16391 "beforenodedrop" : true,
16394 * Fires after a DD object is dropped on a node in this tree. The dropEvent
16395 * passed to handlers has the following properties:<br />
16396 * <ul style="padding:5px;padding-left:16px;">
16397 * <li>tree - The TreePanel</li>
16398 * <li>target - The node being targeted for the drop</li>
16399 * <li>data - The drag data from the drag source</li>
16400 * <li>point - The point of the drop - append, above or below</li>
16401 * <li>source - The drag source</li>
16402 * <li>rawEvent - Raw mouse event</li>
16403 * <li>dropNode - Dropped node(s).</li>
16405 * @param {Object} dropEvent
16409 * @event nodedragover
16410 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
16411 * passed to handlers has the following properties:<br />
16412 * <ul style="padding:5px;padding-left:16px;">
16413 * <li>tree - The TreePanel</li>
16414 * <li>target - The node being targeted for the drop</li>
16415 * <li>data - The drag data from the drag source</li>
16416 * <li>point - The point of the drop - append, above or below</li>
16417 * <li>source - The drag source</li>
16418 * <li>rawEvent - Raw mouse event</li>
16419 * <li>dropNode - Drop node(s) provided by the source.</li>
16420 * <li>cancel - Set this to true to signal drop not allowed.</li>
16422 * @param {Object} dragOverEvent
16424 "nodedragover" : true
16427 if(this.singleExpand){
16428 this.on("beforeexpand", this.restrictExpand, this);
16431 Roo.extend(Roo.tree.TreePanel, Roo.data.Tree, {
16432 rootVisible : true,
16433 animate: Roo.enableFx,
16436 hlDrop : Roo.enableFx,
16440 rendererTip: false,
16442 restrictExpand : function(node){
16443 var p = node.parentNode;
16445 if(p.expandedChild && p.expandedChild.parentNode == p){
16446 p.expandedChild.collapse();
16448 p.expandedChild = node;
16452 // private override
16453 setRootNode : function(node){
16454 Roo.tree.TreePanel.superclass.setRootNode.call(this, node);
16455 if(!this.rootVisible){
16456 node.ui = new Roo.tree.RootTreeNodeUI(node);
16462 * Returns the container element for this TreePanel
16464 getEl : function(){
16469 * Returns the default TreeLoader for this TreePanel
16471 getLoader : function(){
16472 return this.loader;
16478 expandAll : function(){
16479 this.root.expand(true);
16483 * Collapse all nodes
16485 collapseAll : function(){
16486 this.root.collapse(true);
16490 * Returns the selection model used by this TreePanel
16492 getSelectionModel : function(){
16493 if(!this.selModel){
16494 this.selModel = new Roo.tree.DefaultSelectionModel();
16496 return this.selModel;
16500 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
16501 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
16502 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
16505 getChecked : function(a, startNode){
16506 startNode = startNode || this.root;
16508 var f = function(){
16509 if(this.attributes.checked){
16510 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
16513 startNode.cascade(f);
16518 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
16519 * @param {String} path
16520 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
16521 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
16522 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
16524 expandPath : function(path, attr, callback){
16525 attr = attr || "id";
16526 var keys = path.split(this.pathSeparator);
16527 var curNode = this.root;
16528 if(curNode.attributes[attr] != keys[1]){ // invalid root
16530 callback(false, null);
16535 var f = function(){
16536 if(++index == keys.length){
16538 callback(true, curNode);
16542 var c = curNode.findChild(attr, keys[index]);
16545 callback(false, curNode);
16550 c.expand(false, false, f);
16552 curNode.expand(false, false, f);
16556 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
16557 * @param {String} path
16558 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
16559 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
16560 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
16562 selectPath : function(path, attr, callback){
16563 attr = attr || "id";
16564 var keys = path.split(this.pathSeparator);
16565 var v = keys.pop();
16566 if(keys.length > 0){
16567 var f = function(success, node){
16568 if(success && node){
16569 var n = node.findChild(attr, v);
16575 }else if(callback){
16576 callback(false, n);
16580 callback(false, n);
16584 this.expandPath(keys.join(this.pathSeparator), attr, f);
16586 this.root.select();
16588 callback(true, this.root);
16593 getTreeEl : function(){
16598 * Trigger rendering of this TreePanel
16600 render : function(){
16601 if (this.innerCt) {
16602 return this; // stop it rendering more than once!!
16605 this.innerCt = this.el.createChild({tag:"ul",
16606 cls:"x-tree-root-ct " +
16607 (this.lines ? "x-tree-lines" : "x-tree-no-lines")});
16609 if(this.containerScroll){
16610 Roo.dd.ScrollManager.register(this.el);
16612 if((this.enableDD || this.enableDrop) && !this.dropZone){
16614 * The dropZone used by this tree if drop is enabled
16615 * @type Roo.tree.TreeDropZone
16617 this.dropZone = new Roo.tree.TreeDropZone(this, this.dropConfig || {
16618 ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
16621 if((this.enableDD || this.enableDrag) && !this.dragZone){
16623 * The dragZone used by this tree if drag is enabled
16624 * @type Roo.tree.TreeDragZone
16626 this.dragZone = new Roo.tree.TreeDragZone(this, this.dragConfig || {
16627 ddGroup: this.ddGroup || "TreeDD",
16628 scroll: this.ddScroll
16631 this.getSelectionModel().init(this);
16633 console.log("ROOT not set in tree");
16636 this.root.render();
16637 if(!this.rootVisible){
16638 this.root.renderChildren();
16644 * Ext JS Library 1.1.1
16645 * Copyright(c) 2006-2007, Ext JS, LLC.
16647 * Originally Released Under LGPL - original licence link has changed is not relivant.
16650 * <script type="text/javascript">
16655 * @class Roo.tree.DefaultSelectionModel
16656 * @extends Roo.util.Observable
16657 * The default single selection for a TreePanel.
16659 Roo.tree.DefaultSelectionModel = function(){
16660 this.selNode = null;
16664 * @event selectionchange
16665 * Fires when the selected node changes
16666 * @param {DefaultSelectionModel} this
16667 * @param {TreeNode} node the new selection
16669 "selectionchange" : true,
16672 * @event beforeselect
16673 * Fires before the selected node changes, return false to cancel the change
16674 * @param {DefaultSelectionModel} this
16675 * @param {TreeNode} node the new selection
16676 * @param {TreeNode} node the old selection
16678 "beforeselect" : true
16682 Roo.extend(Roo.tree.DefaultSelectionModel, Roo.util.Observable, {
16683 init : function(tree){
16685 tree.getTreeEl().on("keydown", this.onKeyDown, this);
16686 tree.on("click", this.onNodeClick, this);
16689 onNodeClick : function(node, e){
16690 if (e.ctrlKey && this.selNode == node) {
16691 this.unselect(node);
16699 * @param {TreeNode} node The node to select
16700 * @return {TreeNode} The selected node
16702 select : function(node){
16703 var last = this.selNode;
16704 if(last != node && this.fireEvent('beforeselect', this, node, last) !== false){
16706 last.ui.onSelectedChange(false);
16708 this.selNode = node;
16709 node.ui.onSelectedChange(true);
16710 this.fireEvent("selectionchange", this, node, last);
16717 * @param {TreeNode} node The node to unselect
16719 unselect : function(node){
16720 if(this.selNode == node){
16721 this.clearSelections();
16726 * Clear all selections
16728 clearSelections : function(){
16729 var n = this.selNode;
16731 n.ui.onSelectedChange(false);
16732 this.selNode = null;
16733 this.fireEvent("selectionchange", this, null);
16739 * Get the selected node
16740 * @return {TreeNode} The selected node
16742 getSelectedNode : function(){
16743 return this.selNode;
16747 * Returns true if the node is selected
16748 * @param {TreeNode} node The node to check
16749 * @return {Boolean}
16751 isSelected : function(node){
16752 return this.selNode == node;
16756 * Selects the node above the selected node in the tree, intelligently walking the nodes
16757 * @return TreeNode The new selection
16759 selectPrevious : function(){
16760 var s = this.selNode || this.lastSelNode;
16764 var ps = s.previousSibling;
16766 if(!ps.isExpanded() || ps.childNodes.length < 1){
16767 return this.select(ps);
16769 var lc = ps.lastChild;
16770 while(lc && lc.isExpanded() && lc.childNodes.length > 0){
16773 return this.select(lc);
16775 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
16776 return this.select(s.parentNode);
16782 * Selects the node above the selected node in the tree, intelligently walking the nodes
16783 * @return TreeNode The new selection
16785 selectNext : function(){
16786 var s = this.selNode || this.lastSelNode;
16790 if(s.firstChild && s.isExpanded()){
16791 return this.select(s.firstChild);
16792 }else if(s.nextSibling){
16793 return this.select(s.nextSibling);
16794 }else if(s.parentNode){
16796 s.parentNode.bubble(function(){
16797 if(this.nextSibling){
16798 newS = this.getOwnerTree().selModel.select(this.nextSibling);
16807 onKeyDown : function(e){
16808 var s = this.selNode || this.lastSelNode;
16809 // undesirable, but required
16814 var k = e.getKey();
16822 this.selectPrevious();
16825 e.preventDefault();
16826 if(s.hasChildNodes()){
16827 if(!s.isExpanded()){
16829 }else if(s.firstChild){
16830 this.select(s.firstChild, e);
16835 e.preventDefault();
16836 if(s.hasChildNodes() && s.isExpanded()){
16838 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
16839 this.select(s.parentNode, e);
16847 * @class Roo.tree.MultiSelectionModel
16848 * @extends Roo.util.Observable
16849 * Multi selection for a TreePanel.
16851 Roo.tree.MultiSelectionModel = function(){
16852 this.selNodes = [];
16856 * @event selectionchange
16857 * Fires when the selected nodes change
16858 * @param {MultiSelectionModel} this
16859 * @param {Array} nodes Array of the selected nodes
16861 "selectionchange" : true
16865 Roo.extend(Roo.tree.MultiSelectionModel, Roo.util.Observable, {
16866 init : function(tree){
16868 tree.getTreeEl().on("keydown", this.onKeyDown, this);
16869 tree.on("click", this.onNodeClick, this);
16872 onNodeClick : function(node, e){
16873 this.select(node, e, e.ctrlKey);
16878 * @param {TreeNode} node The node to select
16879 * @param {EventObject} e (optional) An event associated with the selection
16880 * @param {Boolean} keepExisting True to retain existing selections
16881 * @return {TreeNode} The selected node
16883 select : function(node, e, keepExisting){
16884 if(keepExisting !== true){
16885 this.clearSelections(true);
16887 if(this.isSelected(node)){
16888 this.lastSelNode = node;
16891 this.selNodes.push(node);
16892 this.selMap[node.id] = node;
16893 this.lastSelNode = node;
16894 node.ui.onSelectedChange(true);
16895 this.fireEvent("selectionchange", this, this.selNodes);
16901 * @param {TreeNode} node The node to unselect
16903 unselect : function(node){
16904 if(this.selMap[node.id]){
16905 node.ui.onSelectedChange(false);
16906 var sn = this.selNodes;
16909 index = sn.indexOf(node);
16911 for(var i = 0, len = sn.length; i < len; i++){
16919 this.selNodes.splice(index, 1);
16921 delete this.selMap[node.id];
16922 this.fireEvent("selectionchange", this, this.selNodes);
16927 * Clear all selections
16929 clearSelections : function(suppressEvent){
16930 var sn = this.selNodes;
16932 for(var i = 0, len = sn.length; i < len; i++){
16933 sn[i].ui.onSelectedChange(false);
16935 this.selNodes = [];
16937 if(suppressEvent !== true){
16938 this.fireEvent("selectionchange", this, this.selNodes);
16944 * Returns true if the node is selected
16945 * @param {TreeNode} node The node to check
16946 * @return {Boolean}
16948 isSelected : function(node){
16949 return this.selMap[node.id] ? true : false;
16953 * Returns an array of the selected nodes
16956 getSelectedNodes : function(){
16957 return this.selNodes;
16960 onKeyDown : Roo.tree.DefaultSelectionModel.prototype.onKeyDown,
16962 selectNext : Roo.tree.DefaultSelectionModel.prototype.selectNext,
16964 selectPrevious : Roo.tree.DefaultSelectionModel.prototype.selectPrevious
16967 * Ext JS Library 1.1.1
16968 * Copyright(c) 2006-2007, Ext JS, LLC.
16970 * Originally Released Under LGPL - original licence link has changed is not relivant.
16973 * <script type="text/javascript">
16977 * @class Roo.tree.TreeNode
16978 * @extends Roo.data.Node
16979 * @cfg {String} text The text for this node
16980 * @cfg {Boolean} expanded true to start the node expanded
16981 * @cfg {Boolean} allowDrag false to make this node undraggable if DD is on (defaults to true)
16982 * @cfg {Boolean} allowDrop false if this node cannot be drop on
16983 * @cfg {Boolean} disabled true to start the node disabled
16984 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
16985 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
16986 * @cfg {String} cls A css class to be added to the node
16987 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
16988 * @cfg {String} href URL of the link used for the node (defaults to #)
16989 * @cfg {String} hrefTarget target frame for the link
16990 * @cfg {String} qtip An Ext QuickTip for the node
16991 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
16992 * @cfg {Boolean} singleClickExpand True for single click expand on this node
16993 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Roo.tree.TreeNodeUI)
16994 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
16995 * (defaults to undefined with no checkbox rendered)
16997 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
16999 Roo.tree.TreeNode = function(attributes){
17000 attributes = attributes || {};
17001 if(typeof attributes == "string"){
17002 attributes = {text: attributes};
17004 this.childrenRendered = false;
17005 this.rendered = false;
17006 Roo.tree.TreeNode.superclass.constructor.call(this, attributes);
17007 this.expanded = attributes.expanded === true;
17008 this.isTarget = attributes.isTarget !== false;
17009 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
17010 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
17013 * Read-only. The text for this node. To change it use setText().
17016 this.text = attributes.text;
17018 * True if this node is disabled.
17021 this.disabled = attributes.disabled === true;
17025 * @event textchange
17026 * Fires when the text for this node is changed
17027 * @param {Node} this This node
17028 * @param {String} text The new text
17029 * @param {String} oldText The old text
17031 "textchange" : true,
17033 * @event beforeexpand
17034 * Fires before this node is expanded, return false to cancel.
17035 * @param {Node} this This node
17036 * @param {Boolean} deep
17037 * @param {Boolean} anim
17039 "beforeexpand" : true,
17041 * @event beforecollapse
17042 * Fires before this node is collapsed, return false to cancel.
17043 * @param {Node} this This node
17044 * @param {Boolean} deep
17045 * @param {Boolean} anim
17047 "beforecollapse" : true,
17050 * Fires when this node is expanded
17051 * @param {Node} this This node
17055 * @event disabledchange
17056 * Fires when the disabled status of this node changes
17057 * @param {Node} this This node
17058 * @param {Boolean} disabled
17060 "disabledchange" : true,
17063 * Fires when this node is collapsed
17064 * @param {Node} this This node
17068 * @event beforeclick
17069 * Fires before click processing. Return false to cancel the default action.
17070 * @param {Node} this This node
17071 * @param {Roo.EventObject} e The event object
17073 "beforeclick":true,
17075 * @event checkchange
17076 * Fires when a node with a checkbox's checked property changes
17077 * @param {Node} this This node
17078 * @param {Boolean} checked
17080 "checkchange":true,
17083 * Fires when this node is clicked
17084 * @param {Node} this This node
17085 * @param {Roo.EventObject} e The event object
17090 * Fires when this node is double clicked
17091 * @param {Node} this This node
17092 * @param {Roo.EventObject} e The event object
17096 * @event contextmenu
17097 * Fires when this node is right clicked
17098 * @param {Node} this This node
17099 * @param {Roo.EventObject} e The event object
17101 "contextmenu":true,
17103 * @event beforechildrenrendered
17104 * Fires right before the child nodes for this node are rendered
17105 * @param {Node} this This node
17107 "beforechildrenrendered":true
17110 var uiClass = this.attributes.uiProvider || Roo.tree.TreeNodeUI;
17113 * Read-only. The UI for this node
17116 this.ui = new uiClass(this);
17118 Roo.extend(Roo.tree.TreeNode, Roo.data.Node, {
17119 preventHScroll: true,
17121 * Returns true if this node is expanded
17122 * @return {Boolean}
17124 isExpanded : function(){
17125 return this.expanded;
17129 * Returns the UI object for this node
17130 * @return {TreeNodeUI}
17132 getUI : function(){
17136 // private override
17137 setFirstChild : function(node){
17138 var of = this.firstChild;
17139 Roo.tree.TreeNode.superclass.setFirstChild.call(this, node);
17140 if(this.childrenRendered && of && node != of){
17141 of.renderIndent(true, true);
17144 this.renderIndent(true, true);
17148 // private override
17149 setLastChild : function(node){
17150 var ol = this.lastChild;
17151 Roo.tree.TreeNode.superclass.setLastChild.call(this, node);
17152 if(this.childrenRendered && ol && node != ol){
17153 ol.renderIndent(true, true);
17156 this.renderIndent(true, true);
17160 // these methods are overridden to provide lazy rendering support
17161 // private override
17162 appendChild : function(){
17163 var node = Roo.tree.TreeNode.superclass.appendChild.apply(this, arguments);
17164 if(node && this.childrenRendered){
17167 this.ui.updateExpandIcon();
17171 // private override
17172 removeChild : function(node){
17173 this.ownerTree.getSelectionModel().unselect(node);
17174 Roo.tree.TreeNode.superclass.removeChild.apply(this, arguments);
17175 // if it's been rendered remove dom node
17176 if(this.childrenRendered){
17179 if(this.childNodes.length < 1){
17180 this.collapse(false, false);
17182 this.ui.updateExpandIcon();
17184 if(!this.firstChild) {
17185 this.childrenRendered = false;
17190 // private override
17191 insertBefore : function(node, refNode){
17192 var newNode = Roo.tree.TreeNode.superclass.insertBefore.apply(this, arguments);
17193 if(newNode && refNode && this.childrenRendered){
17196 this.ui.updateExpandIcon();
17201 * Sets the text for this node
17202 * @param {String} text
17204 setText : function(text){
17205 var oldText = this.text;
17207 this.attributes.text = text;
17208 if(this.rendered){ // event without subscribing
17209 this.ui.onTextChange(this, text, oldText);
17211 this.fireEvent("textchange", this, text, oldText);
17215 * Triggers selection of this node
17217 select : function(){
17218 this.getOwnerTree().getSelectionModel().select(this);
17222 * Triggers deselection of this node
17224 unselect : function(){
17225 this.getOwnerTree().getSelectionModel().unselect(this);
17229 * Returns true if this node is selected
17230 * @return {Boolean}
17232 isSelected : function(){
17233 return this.getOwnerTree().getSelectionModel().isSelected(this);
17237 * Expand this node.
17238 * @param {Boolean} deep (optional) True to expand all children as well
17239 * @param {Boolean} anim (optional) false to cancel the default animation
17240 * @param {Function} callback (optional) A callback to be called when
17241 * expanding this node completes (does not wait for deep expand to complete).
17242 * Called with 1 parameter, this node.
17244 expand : function(deep, anim, callback){
17245 if(!this.expanded){
17246 if(this.fireEvent("beforeexpand", this, deep, anim) === false){
17249 if(!this.childrenRendered){
17250 this.renderChildren();
17252 this.expanded = true;
17253 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
17254 this.ui.animExpand(function(){
17255 this.fireEvent("expand", this);
17256 if(typeof callback == "function"){
17260 this.expandChildNodes(true);
17262 }.createDelegate(this));
17266 this.fireEvent("expand", this);
17267 if(typeof callback == "function"){
17272 if(typeof callback == "function"){
17277 this.expandChildNodes(true);
17281 isHiddenRoot : function(){
17282 return this.isRoot && !this.getOwnerTree().rootVisible;
17286 * Collapse this node.
17287 * @param {Boolean} deep (optional) True to collapse all children as well
17288 * @param {Boolean} anim (optional) false to cancel the default animation
17290 collapse : function(deep, anim){
17291 if(this.expanded && !this.isHiddenRoot()){
17292 if(this.fireEvent("beforecollapse", this, deep, anim) === false){
17295 this.expanded = false;
17296 if((this.getOwnerTree().animate && anim !== false) || anim){
17297 this.ui.animCollapse(function(){
17298 this.fireEvent("collapse", this);
17300 this.collapseChildNodes(true);
17302 }.createDelegate(this));
17305 this.ui.collapse();
17306 this.fireEvent("collapse", this);
17310 var cs = this.childNodes;
17311 for(var i = 0, len = cs.length; i < len; i++) {
17312 cs[i].collapse(true, false);
17318 delayedExpand : function(delay){
17319 if(!this.expandProcId){
17320 this.expandProcId = this.expand.defer(delay, this);
17325 cancelExpand : function(){
17326 if(this.expandProcId){
17327 clearTimeout(this.expandProcId);
17329 this.expandProcId = false;
17333 * Toggles expanded/collapsed state of the node
17335 toggle : function(){
17344 * Ensures all parent nodes are expanded
17346 ensureVisible : function(callback){
17347 var tree = this.getOwnerTree();
17348 tree.expandPath(this.parentNode.getPath(), false, function(){
17349 tree.getTreeEl().scrollChildIntoView(this.ui.anchor);
17350 Roo.callback(callback);
17351 }.createDelegate(this));
17355 * Expand all child nodes
17356 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
17358 expandChildNodes : function(deep){
17359 var cs = this.childNodes;
17360 for(var i = 0, len = cs.length; i < len; i++) {
17361 cs[i].expand(deep);
17366 * Collapse all child nodes
17367 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
17369 collapseChildNodes : function(deep){
17370 var cs = this.childNodes;
17371 for(var i = 0, len = cs.length; i < len; i++) {
17372 cs[i].collapse(deep);
17377 * Disables this node
17379 disable : function(){
17380 this.disabled = true;
17382 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
17383 this.ui.onDisableChange(this, true);
17385 this.fireEvent("disabledchange", this, true);
17389 * Enables this node
17391 enable : function(){
17392 this.disabled = false;
17393 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
17394 this.ui.onDisableChange(this, false);
17396 this.fireEvent("disabledchange", this, false);
17400 renderChildren : function(suppressEvent){
17401 if(suppressEvent !== false){
17402 this.fireEvent("beforechildrenrendered", this);
17404 var cs = this.childNodes;
17405 for(var i = 0, len = cs.length; i < len; i++){
17406 cs[i].render(true);
17408 this.childrenRendered = true;
17412 sort : function(fn, scope){
17413 Roo.tree.TreeNode.superclass.sort.apply(this, arguments);
17414 if(this.childrenRendered){
17415 var cs = this.childNodes;
17416 for(var i = 0, len = cs.length; i < len; i++){
17417 cs[i].render(true);
17423 render : function(bulkRender){
17424 this.ui.render(bulkRender);
17425 if(!this.rendered){
17426 this.rendered = true;
17428 this.expanded = false;
17429 this.expand(false, false);
17435 renderIndent : function(deep, refresh){
17437 this.ui.childIndent = null;
17439 this.ui.renderIndent();
17440 if(deep === true && this.childrenRendered){
17441 var cs = this.childNodes;
17442 for(var i = 0, len = cs.length; i < len; i++){
17443 cs[i].renderIndent(true, refresh);
17449 * Ext JS Library 1.1.1
17450 * Copyright(c) 2006-2007, Ext JS, LLC.
17452 * Originally Released Under LGPL - original licence link has changed is not relivant.
17455 * <script type="text/javascript">
17459 * @class Roo.tree.AsyncTreeNode
17460 * @extends Roo.tree.TreeNode
17461 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
17463 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
17465 Roo.tree.AsyncTreeNode = function(config){
17466 this.loaded = false;
17467 this.loading = false;
17468 Roo.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
17470 * @event beforeload
17471 * Fires before this node is loaded, return false to cancel
17472 * @param {Node} this This node
17474 this.addEvents({'beforeload':true, 'load': true});
17477 * Fires when this node is loaded
17478 * @param {Node} this This node
17481 * The loader used by this node (defaults to using the tree's defined loader)
17486 Roo.extend(Roo.tree.AsyncTreeNode, Roo.tree.TreeNode, {
17487 expand : function(deep, anim, callback){
17488 if(this.loading){ // if an async load is already running, waiting til it's done
17490 var f = function(){
17491 if(!this.loading){ // done loading
17492 clearInterval(timer);
17493 this.expand(deep, anim, callback);
17495 }.createDelegate(this);
17496 timer = setInterval(f, 200);
17500 if(this.fireEvent("beforeload", this) === false){
17503 this.loading = true;
17504 this.ui.beforeLoad(this);
17505 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
17507 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback]));
17511 Roo.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback);
17515 * Returns true if this node is currently loading
17516 * @return {Boolean}
17518 isLoading : function(){
17519 return this.loading;
17522 loadComplete : function(deep, anim, callback){
17523 this.loading = false;
17524 this.loaded = true;
17525 this.ui.afterLoad(this);
17526 this.fireEvent("load", this);
17527 this.expand(deep, anim, callback);
17531 * Returns true if this node has been loaded
17532 * @return {Boolean}
17534 isLoaded : function(){
17535 return this.loaded;
17538 hasChildNodes : function(){
17539 if(!this.isLeaf() && !this.loaded){
17542 return Roo.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
17547 * Trigger a reload for this node
17548 * @param {Function} callback
17550 reload : function(callback){
17551 this.collapse(false, false);
17552 while(this.firstChild){
17553 this.removeChild(this.firstChild);
17555 this.childrenRendered = false;
17556 this.loaded = false;
17557 if(this.isHiddenRoot()){
17558 this.expanded = false;
17560 this.expand(false, false, callback);
17564 * Ext JS Library 1.1.1
17565 * Copyright(c) 2006-2007, Ext JS, LLC.
17567 * Originally Released Under LGPL - original licence link has changed is not relivant.
17570 * <script type="text/javascript">
17574 * @class Roo.tree.TreeNodeUI
17576 * @param {Object} node The node to render
17577 * The TreeNode UI implementation is separate from the
17578 * tree implementation. Unless you are customizing the tree UI,
17579 * you should never have to use this directly.
17581 Roo.tree.TreeNodeUI = function(node){
17583 this.rendered = false;
17584 this.animating = false;
17585 this.emptyIcon = Roo.BLANK_IMAGE_URL;
17588 Roo.tree.TreeNodeUI.prototype = {
17589 removeChild : function(node){
17591 this.ctNode.removeChild(node.ui.getEl());
17595 beforeLoad : function(){
17596 this.addClass("x-tree-node-loading");
17599 afterLoad : function(){
17600 this.removeClass("x-tree-node-loading");
17603 onTextChange : function(node, text, oldText){
17605 this.textNode.innerHTML = text;
17609 onDisableChange : function(node, state){
17610 this.disabled = state;
17612 this.addClass("x-tree-node-disabled");
17614 this.removeClass("x-tree-node-disabled");
17618 onSelectedChange : function(state){
17621 this.addClass("x-tree-selected");
17624 this.removeClass("x-tree-selected");
17628 onMove : function(tree, node, oldParent, newParent, index, refNode){
17629 this.childIndent = null;
17631 var targetNode = newParent.ui.getContainer();
17632 if(!targetNode){//target not rendered
17633 this.holder = document.createElement("div");
17634 this.holder.appendChild(this.wrap);
17637 var insertBefore = refNode ? refNode.ui.getEl() : null;
17639 targetNode.insertBefore(this.wrap, insertBefore);
17641 targetNode.appendChild(this.wrap);
17643 this.node.renderIndent(true);
17647 addClass : function(cls){
17649 Roo.fly(this.elNode).addClass(cls);
17653 removeClass : function(cls){
17655 Roo.fly(this.elNode).removeClass(cls);
17659 remove : function(){
17661 this.holder = document.createElement("div");
17662 this.holder.appendChild(this.wrap);
17666 fireEvent : function(){
17667 return this.node.fireEvent.apply(this.node, arguments);
17670 initEvents : function(){
17671 this.node.on("move", this.onMove, this);
17672 var E = Roo.EventManager;
17673 var a = this.anchor;
17675 var el = Roo.fly(a, '_treeui');
17677 if(Roo.isOpera){ // opera render bug ignores the CSS
17678 el.setStyle("text-decoration", "none");
17681 el.on("click", this.onClick, this);
17682 el.on("dblclick", this.onDblClick, this);
17685 Roo.EventManager.on(this.checkbox,
17686 Roo.isIE ? 'click' : 'change', this.onCheckChange, this);
17689 el.on("contextmenu", this.onContextMenu, this);
17691 var icon = Roo.fly(this.iconNode);
17692 icon.on("click", this.onClick, this);
17693 icon.on("dblclick", this.onDblClick, this);
17694 icon.on("contextmenu", this.onContextMenu, this);
17695 E.on(this.ecNode, "click", this.ecClick, this, true);
17697 if(this.node.disabled){
17698 this.addClass("x-tree-node-disabled");
17700 if(this.node.hidden){
17701 this.addClass("x-tree-node-disabled");
17703 var ot = this.node.getOwnerTree();
17704 var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
17705 if(dd && (!this.node.isRoot || ot.rootVisible)){
17706 Roo.dd.Registry.register(this.elNode, {
17708 handles: this.getDDHandles(),
17714 getDDHandles : function(){
17715 return [this.iconNode, this.textNode];
17720 this.wrap.style.display = "none";
17726 this.wrap.style.display = "";
17730 onContextMenu : function(e){
17731 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
17732 e.preventDefault();
17734 this.fireEvent("contextmenu", this.node, e);
17738 onClick : function(e){
17743 if(this.fireEvent("beforeclick", this.node, e) !== false){
17744 if(!this.disabled && this.node.attributes.href){
17745 this.fireEvent("click", this.node, e);
17748 e.preventDefault();
17753 if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){
17754 this.node.toggle();
17757 this.fireEvent("click", this.node, e);
17763 onDblClick : function(e){
17764 e.preventDefault();
17769 this.toggleCheck();
17771 if(!this.animating && this.node.hasChildNodes()){
17772 this.node.toggle();
17774 this.fireEvent("dblclick", this.node, e);
17777 onCheckChange : function(){
17778 var checked = this.checkbox.checked;
17779 this.node.attributes.checked = checked;
17780 this.fireEvent('checkchange', this.node, checked);
17783 ecClick : function(e){
17784 if(!this.animating && this.node.hasChildNodes()){
17785 this.node.toggle();
17789 startDrop : function(){
17790 this.dropping = true;
17793 // delayed drop so the click event doesn't get fired on a drop
17794 endDrop : function(){
17795 setTimeout(function(){
17796 this.dropping = false;
17797 }.createDelegate(this), 50);
17800 expand : function(){
17801 this.updateExpandIcon();
17802 this.ctNode.style.display = "";
17805 focus : function(){
17806 if(!this.node.preventHScroll){
17807 try{this.anchor.focus();
17809 }else if(!Roo.isIE){
17811 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
17812 var l = noscroll.scrollLeft;
17813 this.anchor.focus();
17814 noscroll.scrollLeft = l;
17819 toggleCheck : function(value){
17820 var cb = this.checkbox;
17822 cb.checked = (value === undefined ? !cb.checked : value);
17828 this.anchor.blur();
17832 animExpand : function(callback){
17833 var ct = Roo.get(this.ctNode);
17835 if(!this.node.hasChildNodes()){
17836 this.updateExpandIcon();
17837 this.ctNode.style.display = "";
17838 Roo.callback(callback);
17841 this.animating = true;
17842 this.updateExpandIcon();
17845 callback : function(){
17846 this.animating = false;
17847 Roo.callback(callback);
17850 duration: this.node.ownerTree.duration || .25
17854 highlight : function(){
17855 var tree = this.node.getOwnerTree();
17856 Roo.fly(this.wrap).highlight(
17857 tree.hlColor || "C3DAF9",
17858 {endColor: tree.hlBaseColor}
17862 collapse : function(){
17863 this.updateExpandIcon();
17864 this.ctNode.style.display = "none";
17867 animCollapse : function(callback){
17868 var ct = Roo.get(this.ctNode);
17869 ct.enableDisplayMode('block');
17872 this.animating = true;
17873 this.updateExpandIcon();
17876 callback : function(){
17877 this.animating = false;
17878 Roo.callback(callback);
17881 duration: this.node.ownerTree.duration || .25
17885 getContainer : function(){
17886 return this.ctNode;
17889 getEl : function(){
17893 appendDDGhost : function(ghostNode){
17894 ghostNode.appendChild(this.elNode.cloneNode(true));
17897 getDDRepairXY : function(){
17898 return Roo.lib.Dom.getXY(this.iconNode);
17901 onRender : function(){
17905 render : function(bulkRender){
17906 var n = this.node, a = n.attributes;
17907 var targetNode = n.parentNode ?
17908 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
17910 if(!this.rendered){
17911 this.rendered = true;
17913 this.renderElements(n, a, targetNode, bulkRender);
17916 if(this.textNode.setAttributeNS){
17917 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
17919 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
17922 this.textNode.setAttribute("ext:qtip", a.qtip);
17924 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
17927 }else if(a.qtipCfg){
17928 a.qtipCfg.target = Roo.id(this.textNode);
17929 Roo.QuickTips.register(a.qtipCfg);
17932 if(!this.node.expanded){
17933 this.updateExpandIcon();
17936 if(bulkRender === true) {
17937 targetNode.appendChild(this.wrap);
17942 renderElements : function(n, a, targetNode, bulkRender){
17943 // add some indent caching, this helps performance when rendering a large tree
17944 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
17945 var t = n.getOwnerTree();
17946 var txt = t.renderer ? t.renderer(n.attributes) : Roo.util.Format.htmlEncode(n.text);
17947 var tip = t.rendererTip ? t.rendererTip(n.attributes) : txt;
17948 var cb = typeof a.checked == 'boolean';
17949 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
17950 var buf = ['<li class="x-tree-node"><div class="x-tree-node-el ', a.cls,'">',
17951 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
17952 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon" />',
17953 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
17954 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : ' />')) : '',
17955 '<a hidefocus="on" href="',href,'" tabIndex="1" ',
17956 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "",
17957 '><span unselectable="on" qtip="' , tip ,'">',txt,"</span></a></div>",
17958 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
17961 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
17962 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
17963 n.nextSibling.ui.getEl(), buf.join(""));
17965 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
17968 this.elNode = this.wrap.childNodes[0];
17969 this.ctNode = this.wrap.childNodes[1];
17970 var cs = this.elNode.childNodes;
17971 this.indentNode = cs[0];
17972 this.ecNode = cs[1];
17973 this.iconNode = cs[2];
17976 this.checkbox = cs[3];
17979 this.anchor = cs[index];
17980 this.textNode = cs[index].firstChild;
17983 getAnchor : function(){
17984 return this.anchor;
17987 getTextEl : function(){
17988 return this.textNode;
17991 getIconEl : function(){
17992 return this.iconNode;
17995 isChecked : function(){
17996 return this.checkbox ? this.checkbox.checked : false;
17999 updateExpandIcon : function(){
18001 var n = this.node, c1, c2;
18002 var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
18003 var hasChild = n.hasChildNodes();
18007 c1 = "x-tree-node-collapsed";
18008 c2 = "x-tree-node-expanded";
18011 c1 = "x-tree-node-expanded";
18012 c2 = "x-tree-node-collapsed";
18015 this.removeClass("x-tree-node-leaf");
18016 this.wasLeaf = false;
18018 if(this.c1 != c1 || this.c2 != c2){
18019 Roo.fly(this.elNode).replaceClass(c1, c2);
18020 this.c1 = c1; this.c2 = c2;
18024 Roo.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
18027 this.wasLeaf = true;
18030 var ecc = "x-tree-ec-icon "+cls;
18031 if(this.ecc != ecc){
18032 this.ecNode.className = ecc;
18038 getChildIndent : function(){
18039 if(!this.childIndent){
18043 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
18045 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
18047 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
18052 this.childIndent = buf.join("");
18054 return this.childIndent;
18057 renderIndent : function(){
18060 var p = this.node.parentNode;
18062 indent = p.ui.getChildIndent();
18064 if(this.indentMarkup != indent){ // don't rerender if not required
18065 this.indentNode.innerHTML = indent;
18066 this.indentMarkup = indent;
18068 this.updateExpandIcon();
18073 Roo.tree.RootTreeNodeUI = function(){
18074 Roo.tree.RootTreeNodeUI.superclass.constructor.apply(this, arguments);
18076 Roo.extend(Roo.tree.RootTreeNodeUI, Roo.tree.TreeNodeUI, {
18077 render : function(){
18078 if(!this.rendered){
18079 var targetNode = this.node.ownerTree.innerCt.dom;
18080 this.node.expanded = true;
18081 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
18082 this.wrap = this.ctNode = targetNode.firstChild;
18085 collapse : function(){
18087 expand : function(){
18091 * Ext JS Library 1.1.1
18092 * Copyright(c) 2006-2007, Ext JS, LLC.
18094 * Originally Released Under LGPL - original licence link has changed is not relivant.
18097 * <script type="text/javascript">
18100 * @class Roo.tree.TreeLoader
18101 * @extends Roo.util.Observable
18102 * A TreeLoader provides for lazy loading of an {@link Roo.tree.TreeNode}'s child
18103 * nodes from a specified URL. The response must be a javascript Array definition
18104 * who's elements are node definition objects. eg:
18106 [{ 'id': 1, 'text': 'A folder Node', 'leaf': false },
18107 { 'id': 2, 'text': 'A leaf Node', 'leaf': true }]
18110 * A server request is sent, and child nodes are loaded only when a node is expanded.
18111 * The loading node's id is passed to the server under the parameter name "node" to
18112 * enable the server to produce the correct child nodes.
18114 * To pass extra parameters, an event handler may be attached to the "beforeload"
18115 * event, and the parameters specified in the TreeLoader's baseParams property:
18117 myTreeLoader.on("beforeload", function(treeLoader, node) {
18118 this.baseParams.category = node.attributes.category;
18121 * This would pass an HTTP parameter called "category" to the server containing
18122 * the value of the Node's "category" attribute.
18124 * Creates a new Treeloader.
18125 * @param {Object} config A config object containing config properties.
18127 Roo.tree.TreeLoader = function(config){
18128 this.baseParams = {};
18129 this.requestMethod = "POST";
18130 Roo.apply(this, config);
18135 * @event beforeload
18136 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
18137 * @param {Object} This TreeLoader object.
18138 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18139 * @param {Object} callback The callback function specified in the {@link #load} call.
18144 * Fires when the node has been successfuly loaded.
18145 * @param {Object} This TreeLoader object.
18146 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18147 * @param {Object} response The response object containing the data from the server.
18151 * @event loadexception
18152 * Fires if the network request failed.
18153 * @param {Object} This TreeLoader object.
18154 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18155 * @param {Object} response The response object containing the data from the server.
18157 loadexception : true,
18160 * Fires before a node is created, enabling you to return custom Node types
18161 * @param {Object} This TreeLoader object.
18162 * @param {Object} attr - the data returned from the AJAX call (modify it to suit)
18167 Roo.tree.TreeLoader.superclass.constructor.call(this);
18170 Roo.extend(Roo.tree.TreeLoader, Roo.util.Observable, {
18172 * @cfg {String} dataUrl The URL from which to request a Json string which
18173 * specifies an array of node definition object representing the child nodes
18177 * @cfg {Object} baseParams (optional) An object containing properties which
18178 * specify HTTP parameters to be passed to each request for child nodes.
18181 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
18182 * created by this loader. If the attributes sent by the server have an attribute in this object,
18183 * they take priority.
18186 * @cfg {Object} uiProviders (optional) An object containing properties which
18188 * DEPRECIATED - use 'create' event handler to modify attributes - which affect creation.
18189 * specify custom {@link Roo.tree.TreeNodeUI} implementations. If the optional
18190 * <i>uiProvider</i> attribute of a returned child node is a string rather
18191 * than a reference to a TreeNodeUI implementation, this that string value
18192 * is used as a property name in the uiProviders object. You can define the provider named
18193 * 'default' , and this will be used for all nodes (if no uiProvider is delivered by the node data)
18198 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
18199 * child nodes before loading.
18201 clearOnLoad : true,
18204 * @cfg {String} root (optional) Default to false. Use this to read data from an object
18205 * property on loading, rather than expecting an array. (eg. more compatible to a standard
18206 * Grid query { data : [ .....] }
18211 * @cfg {String} queryParam (optional)
18212 * Name of the query as it will be passed on the querystring (defaults to 'node')
18213 * eg. the request will be ?node=[id]
18220 * Load an {@link Roo.tree.TreeNode} from the URL specified in the constructor.
18221 * This is called automatically when a node is expanded, but may be used to reload
18222 * a node (or append new children if the {@link #clearOnLoad} option is false.)
18223 * @param {Roo.tree.TreeNode} node
18224 * @param {Function} callback
18226 load : function(node, callback){
18227 if(this.clearOnLoad){
18228 while(node.firstChild){
18229 node.removeChild(node.firstChild);
18232 if(node.attributes.children){ // preloaded json children
18233 var cs = node.attributes.children;
18234 for(var i = 0, len = cs.length; i < len; i++){
18235 node.appendChild(this.createNode(cs[i]));
18237 if(typeof callback == "function"){
18240 }else if(this.dataUrl){
18241 this.requestData(node, callback);
18245 getParams: function(node){
18246 var buf = [], bp = this.baseParams;
18247 for(var key in bp){
18248 if(typeof bp[key] != "function"){
18249 buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
18252 var n = this.queryParam === false ? 'node' : this.queryParam;
18253 buf.push(n + "=", encodeURIComponent(node.id));
18254 return buf.join("");
18257 requestData : function(node, callback){
18258 if(this.fireEvent("beforeload", this, node, callback) !== false){
18259 this.transId = Roo.Ajax.request({
18260 method:this.requestMethod,
18261 url: this.dataUrl||this.url,
18262 success: this.handleResponse,
18263 failure: this.handleFailure,
18265 argument: {callback: callback, node: node},
18266 params: this.getParams(node)
18269 // if the load is cancelled, make sure we notify
18270 // the node that we are done
18271 if(typeof callback == "function"){
18277 isLoading : function(){
18278 return this.transId ? true : false;
18281 abort : function(){
18282 if(this.isLoading()){
18283 Roo.Ajax.abort(this.transId);
18288 createNode : function(attr){
18289 // apply baseAttrs, nice idea Corey!
18290 if(this.baseAttrs){
18291 Roo.applyIf(attr, this.baseAttrs);
18293 if(this.applyLoader !== false){
18294 attr.loader = this;
18296 // uiProvider = depreciated..
18298 if(typeof(attr.uiProvider) == 'string'){
18299 attr.uiProvider = this.uiProviders[attr.uiProvider] ||
18300 /** eval:var:attr */ eval(attr.uiProvider);
18302 if(typeof(this.uiProviders['default']) != 'undefined') {
18303 attr.uiProvider = this.uiProviders['default'];
18306 this.fireEvent('create', this, attr);
18308 attr.leaf = typeof(attr.leaf) == 'string' ? attr.leaf * 1 : attr.leaf;
18310 new Roo.tree.TreeNode(attr) :
18311 new Roo.tree.AsyncTreeNode(attr));
18314 processResponse : function(response, node, callback){
18315 var json = response.responseText;
18318 var o = /** eval:var:zzzzzzzzzz */ eval("("+json+")");
18319 if (this.root !== false) {
18323 for(var i = 0, len = o.length; i < len; i++){
18324 var n = this.createNode(o[i]);
18326 node.appendChild(n);
18329 if(typeof callback == "function"){
18330 callback(this, node);
18333 this.handleFailure(response);
18337 handleResponse : function(response){
18338 this.transId = false;
18339 var a = response.argument;
18340 this.processResponse(response, a.node, a.callback);
18341 this.fireEvent("load", this, a.node, response);
18344 handleFailure : function(response){
18345 this.transId = false;
18346 var a = response.argument;
18347 this.fireEvent("loadexception", this, a.node, response);
18348 if(typeof a.callback == "function"){
18349 a.callback(this, a.node);
18354 * Ext JS Library 1.1.1
18355 * Copyright(c) 2006-2007, Ext JS, LLC.
18357 * Originally Released Under LGPL - original licence link has changed is not relivant.
18360 * <script type="text/javascript">
18364 * @class Roo.tree.TreeFilter
18365 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
18366 * @param {TreePanel} tree
18367 * @param {Object} config (optional)
18369 Roo.tree.TreeFilter = function(tree, config){
18371 this.filtered = {};
18372 Roo.apply(this, config);
18375 Roo.tree.TreeFilter.prototype = {
18382 * Filter the data by a specific attribute.
18383 * @param {String/RegExp} value Either string that the attribute value
18384 * should start with or a RegExp to test against the attribute
18385 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
18386 * @param {TreeNode} startNode (optional) The node to start the filter at.
18388 filter : function(value, attr, startNode){
18389 attr = attr || "text";
18391 if(typeof value == "string"){
18392 var vlen = value.length;
18393 // auto clear empty filter
18394 if(vlen == 0 && this.clearBlank){
18398 value = value.toLowerCase();
18400 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
18402 }else if(value.exec){ // regex?
18404 return value.test(n.attributes[attr]);
18407 throw 'Illegal filter type, must be string or regex';
18409 this.filterBy(f, null, startNode);
18413 * Filter by a function. The passed function will be called with each
18414 * node in the tree (or from the startNode). If the function returns true, the node is kept
18415 * otherwise it is filtered. If a node is filtered, its children are also filtered.
18416 * @param {Function} fn The filter function
18417 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
18419 filterBy : function(fn, scope, startNode){
18420 startNode = startNode || this.tree.root;
18421 if(this.autoClear){
18424 var af = this.filtered, rv = this.reverse;
18425 var f = function(n){
18426 if(n == startNode){
18432 var m = fn.call(scope || n, n);
18440 startNode.cascade(f);
18443 if(typeof id != "function"){
18445 if(n && n.parentNode){
18446 n.parentNode.removeChild(n);
18454 * Clears the current filter. Note: with the "remove" option
18455 * set a filter cannot be cleared.
18457 clear : function(){
18459 var af = this.filtered;
18461 if(typeof id != "function"){
18468 this.filtered = {};
18473 * Ext JS Library 1.1.1
18474 * Copyright(c) 2006-2007, Ext JS, LLC.
18476 * Originally Released Under LGPL - original licence link has changed is not relivant.
18479 * <script type="text/javascript">
18484 * @class Roo.tree.TreeSorter
18485 * Provides sorting of nodes in a TreePanel
18487 * @cfg {Boolean} folderSort True to sort leaf nodes under non leaf nodes
18488 * @cfg {String} property The named attribute on the node to sort by (defaults to text)
18489 * @cfg {String} dir The direction to sort (asc or desc) (defaults to asc)
18490 * @cfg {String} leafAttr The attribute used to determine leaf nodes in folder sort (defaults to "leaf")
18491 * @cfg {Boolean} caseSensitive true for case sensitive sort (defaults to false)
18492 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting
18494 * @param {TreePanel} tree
18495 * @param {Object} config
18497 Roo.tree.TreeSorter = function(tree, config){
18498 Roo.apply(this, config);
18499 tree.on("beforechildrenrendered", this.doSort, this);
18500 tree.on("append", this.updateSort, this);
18501 tree.on("insert", this.updateSort, this);
18503 var dsc = this.dir && this.dir.toLowerCase() == "desc";
18504 var p = this.property || "text";
18505 var sortType = this.sortType;
18506 var fs = this.folderSort;
18507 var cs = this.caseSensitive === true;
18508 var leafAttr = this.leafAttr || 'leaf';
18510 this.sortFn = function(n1, n2){
18512 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
18515 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
18519 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
18520 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
18522 return dsc ? +1 : -1;
18524 return dsc ? -1 : +1;
18531 Roo.tree.TreeSorter.prototype = {
18532 doSort : function(node){
18533 node.sort(this.sortFn);
18536 compareNodes : function(n1, n2){
18537 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
18540 updateSort : function(tree, node){
18541 if(node.childrenRendered){
18542 this.doSort.defer(1, this, [node]);
18547 * Ext JS Library 1.1.1
18548 * Copyright(c) 2006-2007, Ext JS, LLC.
18550 * Originally Released Under LGPL - original licence link has changed is not relivant.
18553 * <script type="text/javascript">
18556 if(Roo.dd.DropZone){
18558 Roo.tree.TreeDropZone = function(tree, config){
18559 this.allowParentInsert = false;
18560 this.allowContainerDrop = false;
18561 this.appendOnly = false;
18562 Roo.tree.TreeDropZone.superclass.constructor.call(this, tree.innerCt, config);
18564 this.lastInsertClass = "x-tree-no-status";
18565 this.dragOverData = {};
18568 Roo.extend(Roo.tree.TreeDropZone, Roo.dd.DropZone, {
18569 ddGroup : "TreeDD",
18571 expandDelay : 1000,
18573 expandNode : function(node){
18574 if(node.hasChildNodes() && !node.isExpanded()){
18575 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
18579 queueExpand : function(node){
18580 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
18583 cancelExpand : function(){
18584 if(this.expandProcId){
18585 clearTimeout(this.expandProcId);
18586 this.expandProcId = false;
18590 isValidDropPoint : function(n, pt, dd, e, data){
18591 if(!n || !data){ return false; }
18592 var targetNode = n.node;
18593 var dropNode = data.node;
18594 // default drop rules
18595 if(!(targetNode && targetNode.isTarget && pt)){
18598 if(pt == "append" && targetNode.allowChildren === false){
18601 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
18604 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
18607 // reuse the object
18608 var overEvent = this.dragOverData;
18609 overEvent.tree = this.tree;
18610 overEvent.target = targetNode;
18611 overEvent.data = data;
18612 overEvent.point = pt;
18613 overEvent.source = dd;
18614 overEvent.rawEvent = e;
18615 overEvent.dropNode = dropNode;
18616 overEvent.cancel = false;
18617 var result = this.tree.fireEvent("nodedragover", overEvent);
18618 return overEvent.cancel === false && result !== false;
18621 getDropPoint : function(e, n, dd){
18624 return tn.allowChildren !== false ? "append" : false; // always append for root
18626 var dragEl = n.ddel;
18627 var t = Roo.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
18628 var y = Roo.lib.Event.getPageY(e);
18629 //var noAppend = tn.allowChildren === false || tn.isLeaf();
18631 // we may drop nodes anywhere, as long as allowChildren has not been set to false..
18632 var noAppend = tn.allowChildren === false;
18633 if(this.appendOnly || tn.parentNode.allowChildren === false){
18634 return noAppend ? false : "append";
18636 var noBelow = false;
18637 if(!this.allowParentInsert){
18638 noBelow = tn.hasChildNodes() && tn.isExpanded();
18640 var q = (b - t) / (noAppend ? 2 : 3);
18641 if(y >= t && y < (t + q)){
18643 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
18650 onNodeEnter : function(n, dd, e, data){
18651 this.cancelExpand();
18654 onNodeOver : function(n, dd, e, data){
18655 var pt = this.getDropPoint(e, n, dd);
18658 // auto node expand check
18659 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
18660 this.queueExpand(node);
18661 }else if(pt != "append"){
18662 this.cancelExpand();
18665 // set the insert point style on the target node
18666 var returnCls = this.dropNotAllowed;
18667 if(this.isValidDropPoint(n, pt, dd, e, data)){
18672 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
18673 cls = "x-tree-drag-insert-above";
18674 }else if(pt == "below"){
18675 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
18676 cls = "x-tree-drag-insert-below";
18678 returnCls = "x-tree-drop-ok-append";
18679 cls = "x-tree-drag-append";
18681 if(this.lastInsertClass != cls){
18682 Roo.fly(el).replaceClass(this.lastInsertClass, cls);
18683 this.lastInsertClass = cls;
18690 onNodeOut : function(n, dd, e, data){
18691 this.cancelExpand();
18692 this.removeDropIndicators(n);
18695 onNodeDrop : function(n, dd, e, data){
18696 var point = this.getDropPoint(e, n, dd);
18697 var targetNode = n.node;
18698 targetNode.ui.startDrop();
18699 if(!this.isValidDropPoint(n, point, dd, e, data)){
18700 targetNode.ui.endDrop();
18703 // first try to find the drop node
18704 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
18707 target: targetNode,
18712 dropNode: dropNode,
18715 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
18716 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
18717 targetNode.ui.endDrop();
18720 // allow target changing
18721 targetNode = dropEvent.target;
18722 if(point == "append" && !targetNode.isExpanded()){
18723 targetNode.expand(false, null, function(){
18724 this.completeDrop(dropEvent);
18725 }.createDelegate(this));
18727 this.completeDrop(dropEvent);
18732 completeDrop : function(de){
18733 var ns = de.dropNode, p = de.point, t = de.target;
18734 if(!(ns instanceof Array)){
18738 for(var i = 0, len = ns.length; i < len; i++){
18741 t.parentNode.insertBefore(n, t);
18742 }else if(p == "below"){
18743 t.parentNode.insertBefore(n, t.nextSibling);
18749 if(this.tree.hlDrop){
18753 this.tree.fireEvent("nodedrop", de);
18756 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
18757 if(this.tree.hlDrop){
18758 dropNode.ui.focus();
18759 dropNode.ui.highlight();
18761 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
18764 getTree : function(){
18768 removeDropIndicators : function(n){
18771 Roo.fly(el).removeClass([
18772 "x-tree-drag-insert-above",
18773 "x-tree-drag-insert-below",
18774 "x-tree-drag-append"]);
18775 this.lastInsertClass = "_noclass";
18779 beforeDragDrop : function(target, e, id){
18780 this.cancelExpand();
18784 afterRepair : function(data){
18785 if(data && Roo.enableFx){
18786 data.node.ui.highlight();
18795 * Ext JS Library 1.1.1
18796 * Copyright(c) 2006-2007, Ext JS, LLC.
18798 * Originally Released Under LGPL - original licence link has changed is not relivant.
18801 * <script type="text/javascript">
18805 if(Roo.dd.DragZone){
18806 Roo.tree.TreeDragZone = function(tree, config){
18807 Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
18811 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
18812 ddGroup : "TreeDD",
18814 onBeforeDrag : function(data, e){
18816 return n && n.draggable && !n.disabled;
18819 onInitDrag : function(e){
18820 var data = this.dragData;
18821 this.tree.getSelectionModel().select(data.node);
18822 this.proxy.update("");
18823 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
18824 this.tree.fireEvent("startdrag", this.tree, data.node, e);
18827 getRepairXY : function(e, data){
18828 return data.node.ui.getDDRepairXY();
18831 onEndDrag : function(data, e){
18832 this.tree.fireEvent("enddrag", this.tree, data.node, e);
18835 onValidDrop : function(dd, e, id){
18836 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
18840 beforeInvalidDrop : function(e, id){
18841 // this scrolls the original position back into view
18842 var sm = this.tree.getSelectionModel();
18843 sm.clearSelections();
18844 sm.select(this.dragData.node);
18849 * Ext JS Library 1.1.1
18850 * Copyright(c) 2006-2007, Ext JS, LLC.
18852 * Originally Released Under LGPL - original licence link has changed is not relivant.
18855 * <script type="text/javascript">
18858 * @class Roo.tree.TreeEditor
18859 * @extends Roo.Editor
18860 * Provides editor functionality for inline tree node editing. Any valid {@link Roo.form.Field} can be used
18861 * as the editor field.
18863 * @param {TreePanel} tree
18864 * @param {Object} config Either a prebuilt {@link Roo.form.Field} instance or a Field config object
18866 Roo.tree.TreeEditor = function(tree, config){
18867 config = config || {};
18868 var field = config.events ? config : new Roo.form.TextField(config);
18869 Roo.tree.TreeEditor.superclass.constructor.call(this, field);
18873 tree.on('beforeclick', this.beforeNodeClick, this);
18874 tree.getTreeEl().on('mousedown', this.hide, this);
18875 this.on('complete', this.updateNode, this);
18876 this.on('beforestartedit', this.fitToTree, this);
18877 this.on('startedit', this.bindScroll, this, {delay:10});
18878 this.on('specialkey', this.onSpecialKey, this);
18881 Roo.extend(Roo.tree.TreeEditor, Roo.Editor, {
18883 * @cfg {String} alignment
18884 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "l-l").
18890 * @cfg {Boolean} hideEl
18891 * True to hide the bound element while the editor is displayed (defaults to false)
18895 * @cfg {String} cls
18896 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
18898 cls: "x-small-editor x-tree-editor",
18900 * @cfg {Boolean} shim
18901 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
18907 * @cfg {Number} maxWidth
18908 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
18909 * the containing tree element's size, it will be automatically limited for you to the container width, taking
18910 * scroll and client offsets into account prior to each edit.
18917 fitToTree : function(ed, el){
18918 var td = this.tree.getTreeEl().dom, nd = el.dom;
18919 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
18920 td.scrollLeft = nd.offsetLeft;
18924 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
18925 this.setSize(w, '');
18929 triggerEdit : function(node){
18930 this.completeEdit();
18931 this.editNode = node;
18932 this.startEdit(node.ui.textNode, node.text);
18936 bindScroll : function(){
18937 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
18941 beforeNodeClick : function(node, e){
18942 var sinceLast = (this.lastClick ? this.lastClick.getElapsed() : 0);
18943 this.lastClick = new Date();
18944 if(sinceLast > this.editDelay && this.tree.getSelectionModel().isSelected(node)){
18946 this.triggerEdit(node);
18952 updateNode : function(ed, value){
18953 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
18954 this.editNode.setText(value);
18958 onHide : function(){
18959 Roo.tree.TreeEditor.superclass.onHide.call(this);
18961 this.editNode.ui.focus();
18966 onSpecialKey : function(field, e){
18967 var k = e.getKey();
18971 }else if(k == e.ENTER && !e.hasModifier()){
18973 this.completeEdit();
18976 });//<Script type="text/javascript">
18979 * Ext JS Library 1.1.1
18980 * Copyright(c) 2006-2007, Ext JS, LLC.
18982 * Originally Released Under LGPL - original licence link has changed is not relivant.
18985 * <script type="text/javascript">
18989 * Not documented??? - probably should be...
18992 Roo.tree.ColumnNodeUI = Roo.extend(Roo.tree.TreeNodeUI, {
18993 //focus: Roo.emptyFn, // prevent odd scrolling behavior
18995 renderElements : function(n, a, targetNode, bulkRender){
18996 //consel.log("renderElements?");
18997 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
18999 var t = n.getOwnerTree();
19000 var tid = Pman.Tab.Document_TypesTree.tree.el.id;
19002 var cols = t.columns;
19003 var bw = t.borderWidth;
19005 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
19006 var cb = typeof a.checked == "boolean";
19007 var tx = String.format('{0}',n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
19008 var colcls = 'x-t-' + tid + '-c0';
19010 '<li class="x-tree-node">',
19013 '<div class="x-tree-node-el ', a.cls,'">',
19015 '<div class="x-tree-col ', colcls, '" style="width:', c.width-bw, 'px;">',
19018 '<span class="x-tree-node-indent">',this.indentMarkup,'</span>',
19019 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon " />',
19020 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',
19021 (a.icon ? ' x-tree-node-inline-icon' : ''),
19022 (a.iconCls ? ' '+a.iconCls : ''),
19023 '" unselectable="on" />',
19024 (cb ? ('<input class="x-tree-node-cb" type="checkbox" ' +
19025 (a.checked ? 'checked="checked" />' : ' />')) : ''),
19027 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
19028 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
19029 '<span unselectable="on" qtip="' + tx + '">',
19033 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
19034 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>'
19036 for(var i = 1, len = cols.length; i < len; i++){
19038 colcls = 'x-t-' + tid + '-c' +i;
19039 tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
19040 buf.push('<div class="x-tree-col ', colcls, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
19041 '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
19047 '<div class="x-clear"></div></div>',
19048 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
19051 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
19052 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
19053 n.nextSibling.ui.getEl(), buf.join(""));
19055 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
19057 var el = this.wrap.firstChild;
19059 this.elNode = el.firstChild;
19060 this.ranchor = el.childNodes[1];
19061 this.ctNode = this.wrap.childNodes[1];
19062 var cs = el.firstChild.childNodes;
19063 this.indentNode = cs[0];
19064 this.ecNode = cs[1];
19065 this.iconNode = cs[2];
19068 this.checkbox = cs[3];
19071 this.anchor = cs[index];
19073 this.textNode = cs[index].firstChild;
19075 //el.on("click", this.onClick, this);
19076 //el.on("dblclick", this.onDblClick, this);
19079 // console.log(this);
19081 initEvents : function(){
19082 Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
19085 var a = this.ranchor;
19087 var el = Roo.get(a);
19089 if(Roo.isOpera){ // opera render bug ignores the CSS
19090 el.setStyle("text-decoration", "none");
19093 el.on("click", this.onClick, this);
19094 el.on("dblclick", this.onDblClick, this);
19095 el.on("contextmenu", this.onContextMenu, this);
19099 /*onSelectedChange : function(state){
19102 this.addClass("x-tree-selected");
19105 this.removeClass("x-tree-selected");
19108 addClass : function(cls){
19110 Roo.fly(this.elRow).addClass(cls);
19116 removeClass : function(cls){
19118 Roo.fly(this.elRow).removeClass(cls);
19124 });//<Script type="text/javascript">
19128 * Ext JS Library 1.1.1
19129 * Copyright(c) 2006-2007, Ext JS, LLC.
19131 * Originally Released Under LGPL - original licence link has changed is not relivant.
19134 * <script type="text/javascript">
19139 * @class Roo.tree.ColumnTree
19140 * @extends Roo.data.TreePanel
19141 * @cfg {Object} columns Including width, header, renderer, cls, dataIndex
19142 * @cfg {int} borderWidth compined right/left border allowance
19144 * @param {String/HTMLElement/Element} el The container element
19145 * @param {Object} config
19147 Roo.tree.ColumnTree = function(el, config)
19149 Roo.tree.ColumnTree.superclass.constructor.call(this, el , config);
19153 * Fire this event on a container when it resizes
19154 * @param {int} w Width
19155 * @param {int} h Height
19159 this.on('resize', this.onResize, this);
19162 Roo.extend(Roo.tree.ColumnTree, Roo.tree.TreePanel, {
19166 borderWidth: Roo.isBorderBox ? 0 : 2,
19169 render : function(){
19170 // add the header.....
19172 Roo.tree.ColumnTree.superclass.render.apply(this);
19174 this.el.addClass('x-column-tree');
19176 this.headers = this.el.createChild(
19177 {cls:'x-tree-headers'},this.innerCt.dom);
19179 var cols = this.columns, c;
19180 var totalWidth = 0;
19182 var len = cols.length;
19183 for(var i = 0; i < len; i++){
19185 totalWidth += c.width;
19186 this.headEls.push(this.headers.createChild({
19187 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
19189 cls:'x-tree-hd-text',
19192 style:'width:'+(c.width-this.borderWidth)+'px;'
19195 this.headers.createChild({cls:'x-clear'});
19196 // prevent floats from wrapping when clipped
19197 this.headers.setWidth(totalWidth);
19198 //this.innerCt.setWidth(totalWidth);
19199 this.innerCt.setStyle({ overflow: 'auto' });
19200 this.onResize(this.width, this.height);
19204 onResize : function(w,h)
19209 this.innerCt.setWidth(this.width);
19210 this.innerCt.setHeight(this.height-20);
19213 var cols = this.columns, c;
19214 var totalWidth = 0;
19216 var len = cols.length;
19217 for(var i = 0; i < len; i++){
19219 if (this.autoExpandColumn !== false && c.dataIndex == this.autoExpandColumn) {
19220 // it's the expander..
19221 expEl = this.headEls[i];
19224 totalWidth += c.width;
19228 expEl.setWidth( ((w - totalWidth)-this.borderWidth - 20));
19230 this.headers.setWidth(w-20);
19239 * Ext JS Library 1.1.1
19240 * Copyright(c) 2006-2007, Ext JS, LLC.
19242 * Originally Released Under LGPL - original licence link has changed is not relivant.
19245 * <script type="text/javascript">
19249 * @class Roo.menu.Menu
19250 * @extends Roo.util.Observable
19251 * A menu object. This is the container to which you add all other menu items. Menu can also serve a as a base class
19252 * when you want a specialzed menu based off of another component (like {@link Roo.menu.DateMenu} for example).
19254 * Creates a new Menu
19255 * @param {Object} config Configuration options
19257 Roo.menu.Menu = function(config){
19258 Roo.apply(this, config);
19259 this.id = this.id || Roo.id();
19262 * @event beforeshow
19263 * Fires before this menu is displayed
19264 * @param {Roo.menu.Menu} this
19268 * @event beforehide
19269 * Fires before this menu is hidden
19270 * @param {Roo.menu.Menu} this
19275 * Fires after this menu is displayed
19276 * @param {Roo.menu.Menu} this
19281 * Fires after this menu is hidden
19282 * @param {Roo.menu.Menu} this
19287 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
19288 * @param {Roo.menu.Menu} this
19289 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19290 * @param {Roo.EventObject} e
19295 * Fires when the mouse is hovering over this menu
19296 * @param {Roo.menu.Menu} this
19297 * @param {Roo.EventObject} e
19298 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19303 * Fires when the mouse exits this menu
19304 * @param {Roo.menu.Menu} this
19305 * @param {Roo.EventObject} e
19306 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19311 * Fires when a menu item contained in this menu is clicked
19312 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
19313 * @param {Roo.EventObject} e
19317 if (this.registerMenu) {
19318 Roo.menu.MenuMgr.register(this);
19321 var mis = this.items;
19322 this.items = new Roo.util.MixedCollection();
19324 this.add.apply(this, mis);
19328 Roo.extend(Roo.menu.Menu, Roo.util.Observable, {
19330 * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120)
19334 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
19335 * for bottom-right shadow (defaults to "sides")
19339 * @cfg {String} subMenuAlign The {@link Roo.Element#alignTo} anchor position value to use for submenus of
19340 * this menu (defaults to "tl-tr?")
19342 subMenuAlign : "tl-tr?",
19344 * @cfg {String} defaultAlign The default {@link Roo.Element#alignTo) anchor position value for this menu
19345 * relative to its element of origin (defaults to "tl-bl?")
19347 defaultAlign : "tl-bl?",
19349 * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false)
19351 allowOtherMenus : false,
19353 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
19355 registerMenu : true,
19360 render : function(){
19364 var el = this.el = new Roo.Layer({
19366 shadow:this.shadow,
19368 parentEl: this.parentEl || document.body,
19372 this.keyNav = new Roo.menu.MenuNav(this);
19375 el.addClass("x-menu-plain");
19378 el.addClass(this.cls);
19380 // generic focus element
19381 this.focusEl = el.createChild({
19382 tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1"
19384 var ul = el.createChild({tag: "ul", cls: "x-menu-list"});
19385 ul.on("click", this.onClick, this);
19386 ul.on("mouseover", this.onMouseOver, this);
19387 ul.on("mouseout", this.onMouseOut, this);
19388 this.items.each(function(item){
19389 var li = document.createElement("li");
19390 li.className = "x-menu-list-item";
19391 ul.dom.appendChild(li);
19392 item.render(li, this);
19399 autoWidth : function(){
19400 var el = this.el, ul = this.ul;
19404 var w = this.width;
19407 }else if(Roo.isIE){
19408 el.setWidth(this.minWidth);
19409 var t = el.dom.offsetWidth; // force recalc
19410 el.setWidth(ul.getWidth()+el.getFrameWidth("lr"));
19415 delayAutoWidth : function(){
19418 this.awTask = new Roo.util.DelayedTask(this.autoWidth, this);
19420 this.awTask.delay(20);
19425 findTargetItem : function(e){
19426 var t = e.getTarget(".x-menu-list-item", this.ul, true);
19427 if(t && t.menuItemId){
19428 return this.items.get(t.menuItemId);
19433 onClick : function(e){
19435 if(t = this.findTargetItem(e)){
19437 this.fireEvent("click", this, t, e);
19442 setActiveItem : function(item, autoExpand){
19443 if(item != this.activeItem){
19444 if(this.activeItem){
19445 this.activeItem.deactivate();
19447 this.activeItem = item;
19448 item.activate(autoExpand);
19449 }else if(autoExpand){
19455 tryActivate : function(start, step){
19456 var items = this.items;
19457 for(var i = start, len = items.length; i >= 0 && i < len; i+= step){
19458 var item = items.get(i);
19459 if(!item.disabled && item.canActivate){
19460 this.setActiveItem(item, false);
19468 onMouseOver : function(e){
19470 if(t = this.findTargetItem(e)){
19471 if(t.canActivate && !t.disabled){
19472 this.setActiveItem(t, true);
19475 this.fireEvent("mouseover", this, e, t);
19479 onMouseOut : function(e){
19481 if(t = this.findTargetItem(e)){
19482 if(t == this.activeItem && t.shouldDeactivate(e)){
19483 this.activeItem.deactivate();
19484 delete this.activeItem;
19487 this.fireEvent("mouseout", this, e, t);
19491 * Read-only. Returns true if the menu is currently displayed, else false.
19494 isVisible : function(){
19495 return this.el && !this.hidden;
19499 * Displays this menu relative to another element
19500 * @param {String/HTMLElement/Roo.Element} element The element to align to
19501 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
19502 * the element (defaults to this.defaultAlign)
19503 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
19505 show : function(el, pos, parentMenu){
19506 this.parentMenu = parentMenu;
19510 this.fireEvent("beforeshow", this);
19511 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
19515 * Displays this menu at a specific xy position
19516 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
19517 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
19519 showAt : function(xy, parentMenu, /* private: */_e){
19520 this.parentMenu = parentMenu;
19525 this.fireEvent("beforeshow", this);
19526 xy = this.el.adjustForConstraints(xy);
19530 this.hidden = false;
19532 this.fireEvent("show", this);
19535 focus : function(){
19537 this.doFocus.defer(50, this);
19541 doFocus : function(){
19543 this.focusEl.focus();
19548 * Hides this menu and optionally all parent menus
19549 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
19551 hide : function(deep){
19552 if(this.el && this.isVisible()){
19553 this.fireEvent("beforehide", this);
19554 if(this.activeItem){
19555 this.activeItem.deactivate();
19556 this.activeItem = null;
19559 this.hidden = true;
19560 this.fireEvent("hide", this);
19562 if(deep === true && this.parentMenu){
19563 this.parentMenu.hide(true);
19568 * Addds one or more items of any type supported by the Menu class, or that can be converted into menu items.
19569 * Any of the following are valid:
19571 * <li>Any menu item object based on {@link Roo.menu.Item}</li>
19572 * <li>An HTMLElement object which will be converted to a menu item</li>
19573 * <li>A menu item config object that will be created as a new menu item</li>
19574 * <li>A string, which can either be '-' or 'separator' to add a menu separator, otherwise
19575 * it will be converted into a {@link Roo.menu.TextItem} and added</li>
19580 var menu = new Roo.menu.Menu();
19582 // Create a menu item to add by reference
19583 var menuItem = new Roo.menu.Item({ text: 'New Item!' });
19585 // Add a bunch of items at once using different methods.
19586 // Only the last item added will be returned.
19587 var item = menu.add(
19588 menuItem, // add existing item by ref
19589 'Dynamic Item', // new TextItem
19590 '-', // new separator
19591 { text: 'Config Item' } // new item by config
19594 * @param {Mixed} args One or more menu items, menu item configs or other objects that can be converted to menu items
19595 * @return {Roo.menu.Item} The menu item that was added, or the last one if multiple items were added
19598 var a = arguments, l = a.length, item;
19599 for(var i = 0; i < l; i++){
19601 if ((typeof(el) == "object") && el.xtype && el.xns) {
19602 el = Roo.factory(el, Roo.menu);
19605 if(el.render){ // some kind of Item
19606 item = this.addItem(el);
19607 }else if(typeof el == "string"){ // string
19608 if(el == "separator" || el == "-"){
19609 item = this.addSeparator();
19611 item = this.addText(el);
19613 }else if(el.tagName || el.el){ // element
19614 item = this.addElement(el);
19615 }else if(typeof el == "object"){ // must be menu item config?
19616 item = this.addMenuItem(el);
19623 * Returns this menu's underlying {@link Roo.Element} object
19624 * @return {Roo.Element} The element
19626 getEl : function(){
19634 * Adds a separator bar to the menu
19635 * @return {Roo.menu.Item} The menu item that was added
19637 addSeparator : function(){
19638 return this.addItem(new Roo.menu.Separator());
19642 * Adds an {@link Roo.Element} object to the menu
19643 * @param {String/HTMLElement/Roo.Element} el The element or DOM node to add, or its id
19644 * @return {Roo.menu.Item} The menu item that was added
19646 addElement : function(el){
19647 return this.addItem(new Roo.menu.BaseItem(el));
19651 * Adds an existing object based on {@link Roo.menu.Item} to the menu
19652 * @param {Roo.menu.Item} item The menu item to add
19653 * @return {Roo.menu.Item} The menu item that was added
19655 addItem : function(item){
19656 this.items.add(item);
19658 var li = document.createElement("li");
19659 li.className = "x-menu-list-item";
19660 this.ul.dom.appendChild(li);
19661 item.render(li, this);
19662 this.delayAutoWidth();
19668 * Creates a new {@link Roo.menu.Item} based an the supplied config object and adds it to the menu
19669 * @param {Object} config A MenuItem config object
19670 * @return {Roo.menu.Item} The menu item that was added
19672 addMenuItem : function(config){
19673 if(!(config instanceof Roo.menu.Item)){
19674 if(typeof config.checked == "boolean"){ // must be check menu item config?
19675 config = new Roo.menu.CheckItem(config);
19677 config = new Roo.menu.Item(config);
19680 return this.addItem(config);
19684 * Creates a new {@link Roo.menu.TextItem} with the supplied text and adds it to the menu
19685 * @param {String} text The text to display in the menu item
19686 * @return {Roo.menu.Item} The menu item that was added
19688 addText : function(text){
19689 return this.addItem(new Roo.menu.TextItem({ text : text }));
19693 * Inserts an existing object based on {@link Roo.menu.Item} to the menu at a specified index
19694 * @param {Number} index The index in the menu's list of current items where the new item should be inserted
19695 * @param {Roo.menu.Item} item The menu item to add
19696 * @return {Roo.menu.Item} The menu item that was added
19698 insert : function(index, item){
19699 this.items.insert(index, item);
19701 var li = document.createElement("li");
19702 li.className = "x-menu-list-item";
19703 this.ul.dom.insertBefore(li, this.ul.dom.childNodes[index]);
19704 item.render(li, this);
19705 this.delayAutoWidth();
19711 * Removes an {@link Roo.menu.Item} from the menu and destroys the object
19712 * @param {Roo.menu.Item} item The menu item to remove
19714 remove : function(item){
19715 this.items.removeKey(item.id);
19720 * Removes and destroys all items in the menu
19722 removeAll : function(){
19724 while(f = this.items.first()){
19730 // MenuNav is a private utility class used internally by the Menu
19731 Roo.menu.MenuNav = function(menu){
19732 Roo.menu.MenuNav.superclass.constructor.call(this, menu.el);
19733 this.scope = this.menu = menu;
19736 Roo.extend(Roo.menu.MenuNav, Roo.KeyNav, {
19737 doRelay : function(e, h){
19738 var k = e.getKey();
19739 if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){
19740 this.menu.tryActivate(0, 1);
19743 return h.call(this.scope || this, e, this.menu);
19746 up : function(e, m){
19747 if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
19748 m.tryActivate(m.items.length-1, -1);
19752 down : function(e, m){
19753 if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
19754 m.tryActivate(0, 1);
19758 right : function(e, m){
19760 m.activeItem.expandMenu(true);
19764 left : function(e, m){
19766 if(m.parentMenu && m.parentMenu.activeItem){
19767 m.parentMenu.activeItem.activate();
19771 enter : function(e, m){
19773 e.stopPropagation();
19774 m.activeItem.onClick(e);
19775 m.fireEvent("click", this, m.activeItem);
19781 * Ext JS Library 1.1.1
19782 * Copyright(c) 2006-2007, Ext JS, LLC.
19784 * Originally Released Under LGPL - original licence link has changed is not relivant.
19787 * <script type="text/javascript">
19791 * @class Roo.menu.MenuMgr
19792 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
19795 Roo.menu.MenuMgr = function(){
19796 var menus, active, groups = {}, attached = false, lastShow = new Date();
19798 // private - called when first menu is created
19801 active = new Roo.util.MixedCollection();
19802 Roo.get(document).addKeyListener(27, function(){
19803 if(active.length > 0){
19810 function hideAll(){
19811 if(active && active.length > 0){
19812 var c = active.clone();
19813 c.each(function(m){
19820 function onHide(m){
19822 if(active.length < 1){
19823 Roo.get(document).un("mousedown", onMouseDown);
19829 function onShow(m){
19830 var last = active.last();
19831 lastShow = new Date();
19834 Roo.get(document).on("mousedown", onMouseDown);
19838 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
19839 m.parentMenu.activeChild = m;
19840 }else if(last && last.isVisible()){
19841 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
19846 function onBeforeHide(m){
19848 m.activeChild.hide();
19850 if(m.autoHideTimer){
19851 clearTimeout(m.autoHideTimer);
19852 delete m.autoHideTimer;
19857 function onBeforeShow(m){
19858 var pm = m.parentMenu;
19859 if(!pm && !m.allowOtherMenus){
19861 }else if(pm && pm.activeChild && active != m){
19862 pm.activeChild.hide();
19867 function onMouseDown(e){
19868 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
19874 function onBeforeCheck(mi, state){
19876 var g = groups[mi.group];
19877 for(var i = 0, l = g.length; i < l; i++){
19879 g[i].setChecked(false);
19888 * Hides all menus that are currently visible
19890 hideAll : function(){
19895 register : function(menu){
19899 menus[menu.id] = menu;
19900 menu.on("beforehide", onBeforeHide);
19901 menu.on("hide", onHide);
19902 menu.on("beforeshow", onBeforeShow);
19903 menu.on("show", onShow);
19904 var g = menu.group;
19905 if(g && menu.events["checkchange"]){
19909 groups[g].push(menu);
19910 menu.on("checkchange", onCheck);
19915 * Returns a {@link Roo.menu.Menu} object
19916 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
19917 * be used to generate and return a new Menu instance.
19919 get : function(menu){
19920 if(typeof menu == "string"){ // menu id
19921 return menus[menu];
19922 }else if(menu.events){ // menu instance
19924 }else if(typeof menu.length == 'number'){ // array of menu items?
19925 return new Roo.menu.Menu({items:menu});
19926 }else{ // otherwise, must be a config
19927 return new Roo.menu.Menu(menu);
19932 unregister : function(menu){
19933 delete menus[menu.id];
19934 menu.un("beforehide", onBeforeHide);
19935 menu.un("hide", onHide);
19936 menu.un("beforeshow", onBeforeShow);
19937 menu.un("show", onShow);
19938 var g = menu.group;
19939 if(g && menu.events["checkchange"]){
19940 groups[g].remove(menu);
19941 menu.un("checkchange", onCheck);
19946 registerCheckable : function(menuItem){
19947 var g = menuItem.group;
19952 groups[g].push(menuItem);
19953 menuItem.on("beforecheckchange", onBeforeCheck);
19958 unregisterCheckable : function(menuItem){
19959 var g = menuItem.group;
19961 groups[g].remove(menuItem);
19962 menuItem.un("beforecheckchange", onBeforeCheck);
19968 * Ext JS Library 1.1.1
19969 * Copyright(c) 2006-2007, Ext JS, LLC.
19971 * Originally Released Under LGPL - original licence link has changed is not relivant.
19974 * <script type="text/javascript">
19979 * @class Roo.menu.BaseItem
19980 * @extends Roo.Component
19981 * The base class for all items that render into menus. BaseItem provides default rendering, activated state
19982 * management and base configuration options shared by all menu components.
19984 * Creates a new BaseItem
19985 * @param {Object} config Configuration options
19987 Roo.menu.BaseItem = function(config){
19988 Roo.menu.BaseItem.superclass.constructor.call(this, config);
19993 * Fires when this item is clicked
19994 * @param {Roo.menu.BaseItem} this
19995 * @param {Roo.EventObject} e
20000 * Fires when this item is activated
20001 * @param {Roo.menu.BaseItem} this
20005 * @event deactivate
20006 * Fires when this item is deactivated
20007 * @param {Roo.menu.BaseItem} this
20013 this.on("click", this.handler, this.scope, true);
20017 Roo.extend(Roo.menu.BaseItem, Roo.Component, {
20019 * @cfg {Function} handler
20020 * A function that will handle the click event of this menu item (defaults to undefined)
20023 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
20025 canActivate : false,
20027 * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
20029 activeClass : "x-menu-item-active",
20031 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
20033 hideOnClick : true,
20035 * @cfg {Number} hideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
20040 ctype: "Roo.menu.BaseItem",
20043 actionMode : "container",
20046 render : function(container, parentMenu){
20047 this.parentMenu = parentMenu;
20048 Roo.menu.BaseItem.superclass.render.call(this, container);
20049 this.container.menuItemId = this.id;
20053 onRender : function(container, position){
20054 this.el = Roo.get(this.el);
20055 container.dom.appendChild(this.el.dom);
20059 onClick : function(e){
20060 if(!this.disabled && this.fireEvent("click", this, e) !== false
20061 && this.parentMenu.fireEvent("itemclick", this, e) !== false){
20062 this.handleClick(e);
20069 activate : function(){
20073 var li = this.container;
20074 li.addClass(this.activeClass);
20075 this.region = li.getRegion().adjust(2, 2, -2, -2);
20076 this.fireEvent("activate", this);
20081 deactivate : function(){
20082 this.container.removeClass(this.activeClass);
20083 this.fireEvent("deactivate", this);
20087 shouldDeactivate : function(e){
20088 return !this.region || !this.region.contains(e.getPoint());
20092 handleClick : function(e){
20093 if(this.hideOnClick){
20094 this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
20099 expandMenu : function(autoActivate){
20104 hideMenu : function(){
20109 * Ext JS Library 1.1.1
20110 * Copyright(c) 2006-2007, Ext JS, LLC.
20112 * Originally Released Under LGPL - original licence link has changed is not relivant.
20115 * <script type="text/javascript">
20119 * @class Roo.menu.Adapter
20120 * @extends Roo.menu.BaseItem
20121 * A base utility class that adapts a non-menu component so that it can be wrapped by a menu item and added to a menu.
20122 * It provides basic rendering, activation management and enable/disable logic required to work in menus.
20124 * Creates a new Adapter
20125 * @param {Object} config Configuration options
20127 Roo.menu.Adapter = function(component, config){
20128 Roo.menu.Adapter.superclass.constructor.call(this, config);
20129 this.component = component;
20131 Roo.extend(Roo.menu.Adapter, Roo.menu.BaseItem, {
20133 canActivate : true,
20136 onRender : function(container, position){
20137 this.component.render(container);
20138 this.el = this.component.getEl();
20142 activate : function(){
20146 this.component.focus();
20147 this.fireEvent("activate", this);
20152 deactivate : function(){
20153 this.fireEvent("deactivate", this);
20157 disable : function(){
20158 this.component.disable();
20159 Roo.menu.Adapter.superclass.disable.call(this);
20163 enable : function(){
20164 this.component.enable();
20165 Roo.menu.Adapter.superclass.enable.call(this);
20169 * Ext JS Library 1.1.1
20170 * Copyright(c) 2006-2007, Ext JS, LLC.
20172 * Originally Released Under LGPL - original licence link has changed is not relivant.
20175 * <script type="text/javascript">
20179 * @class Roo.menu.TextItem
20180 * @extends Roo.menu.BaseItem
20181 * Adds a static text string to a menu, usually used as either a heading or group separator.
20182 * Note: old style constructor with text is still supported.
20185 * Creates a new TextItem
20186 * @param {Object} cfg Configuration
20188 Roo.menu.TextItem = function(cfg){
20189 if (typeof(cfg) == 'string') {
20192 Roo.apply(this,cfg);
20195 Roo.menu.TextItem.superclass.constructor.call(this);
20198 Roo.extend(Roo.menu.TextItem, Roo.menu.BaseItem, {
20200 * @cfg {Boolean} text Text to show on item.
20205 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
20207 hideOnClick : false,
20209 * @cfg {String} itemCls The default CSS class to use for text items (defaults to "x-menu-text")
20211 itemCls : "x-menu-text",
20214 onRender : function(){
20215 var s = document.createElement("span");
20216 s.className = this.itemCls;
20217 s.innerHTML = this.text;
20219 Roo.menu.TextItem.superclass.onRender.apply(this, arguments);
20223 * Ext JS Library 1.1.1
20224 * Copyright(c) 2006-2007, Ext JS, LLC.
20226 * Originally Released Under LGPL - original licence link has changed is not relivant.
20229 * <script type="text/javascript">
20233 * @class Roo.menu.Separator
20234 * @extends Roo.menu.BaseItem
20235 * Adds a separator bar to a menu, used to divide logical groups of menu items. Generally you will
20236 * add one of these by using "-" in you call to add() or in your items config rather than creating one directly.
20238 * @param {Object} config Configuration options
20240 Roo.menu.Separator = function(config){
20241 Roo.menu.Separator.superclass.constructor.call(this, config);
20244 Roo.extend(Roo.menu.Separator, Roo.menu.BaseItem, {
20246 * @cfg {String} itemCls The default CSS class to use for separators (defaults to "x-menu-sep")
20248 itemCls : "x-menu-sep",
20250 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
20252 hideOnClick : false,
20255 onRender : function(li){
20256 var s = document.createElement("span");
20257 s.className = this.itemCls;
20258 s.innerHTML = " ";
20260 li.addClass("x-menu-sep-li");
20261 Roo.menu.Separator.superclass.onRender.apply(this, arguments);
20265 * Ext JS Library 1.1.1
20266 * Copyright(c) 2006-2007, Ext JS, LLC.
20268 * Originally Released Under LGPL - original licence link has changed is not relivant.
20271 * <script type="text/javascript">
20274 * @class Roo.menu.Item
20275 * @extends Roo.menu.BaseItem
20276 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
20277 * display items. Item extends the base functionality of {@link Roo.menu.BaseItem} by adding menu-specific
20278 * activation and click handling.
20280 * Creates a new Item
20281 * @param {Object} config Configuration options
20283 Roo.menu.Item = function(config){
20284 Roo.menu.Item.superclass.constructor.call(this, config);
20286 this.menu = Roo.menu.MenuMgr.get(this.menu);
20289 Roo.extend(Roo.menu.Item, Roo.menu.BaseItem, {
20292 * @cfg {String} text
20293 * The text to show on the menu item.
20297 * @cfg {String} HTML to render in menu
20298 * The text to show on the menu item (HTML version).
20302 * @cfg {String} icon
20303 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
20307 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
20309 itemCls : "x-menu-item",
20311 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
20313 canActivate : true,
20315 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
20318 // doc'd in BaseItem
20322 ctype: "Roo.menu.Item",
20325 onRender : function(container, position){
20326 var el = document.createElement("a");
20327 el.hideFocus = true;
20328 el.unselectable = "on";
20329 el.href = this.href || "#";
20330 if(this.hrefTarget){
20331 el.target = this.hrefTarget;
20333 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
20335 var html = this.html.length ? this.html : String.format('{0}',this.text);
20337 el.innerHTML = String.format(
20338 '<img src="{0}" class="x-menu-item-icon {1}" />' + html,
20339 this.icon || Roo.BLANK_IMAGE_URL, this.iconCls || '');
20341 Roo.menu.Item.superclass.onRender.call(this, container, position);
20345 * Sets the text to display in this menu item
20346 * @param {String} text The text to display
20347 * @param {Boolean} isHTML true to indicate text is pure html.
20349 setText : function(text, isHTML){
20357 var html = this.html.length ? this.html : String.format('{0}',this.text);
20359 this.el.update(String.format(
20360 '<img src="{0}" class="x-menu-item-icon {2}">' + html,
20361 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
20362 this.parentMenu.autoWidth();
20367 handleClick : function(e){
20368 if(!this.href){ // if no link defined, stop the event automatically
20371 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
20375 activate : function(autoExpand){
20376 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
20386 shouldDeactivate : function(e){
20387 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
20388 if(this.menu && this.menu.isVisible()){
20389 return !this.menu.getEl().getRegion().contains(e.getPoint());
20397 deactivate : function(){
20398 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
20403 expandMenu : function(autoActivate){
20404 if(!this.disabled && this.menu){
20405 clearTimeout(this.hideTimer);
20406 delete this.hideTimer;
20407 if(!this.menu.isVisible() && !this.showTimer){
20408 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
20409 }else if (this.menu.isVisible() && autoActivate){
20410 this.menu.tryActivate(0, 1);
20416 deferExpand : function(autoActivate){
20417 delete this.showTimer;
20418 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
20420 this.menu.tryActivate(0, 1);
20425 hideMenu : function(){
20426 clearTimeout(this.showTimer);
20427 delete this.showTimer;
20428 if(!this.hideTimer && this.menu && this.menu.isVisible()){
20429 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
20434 deferHide : function(){
20435 delete this.hideTimer;
20440 * Ext JS Library 1.1.1
20441 * Copyright(c) 2006-2007, Ext JS, LLC.
20443 * Originally Released Under LGPL - original licence link has changed is not relivant.
20446 * <script type="text/javascript">
20450 * @class Roo.menu.CheckItem
20451 * @extends Roo.menu.Item
20452 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
20454 * Creates a new CheckItem
20455 * @param {Object} config Configuration options
20457 Roo.menu.CheckItem = function(config){
20458 Roo.menu.CheckItem.superclass.constructor.call(this, config);
20461 * @event beforecheckchange
20462 * Fires before the checked value is set, providing an opportunity to cancel if needed
20463 * @param {Roo.menu.CheckItem} this
20464 * @param {Boolean} checked The new checked value that will be set
20466 "beforecheckchange" : true,
20468 * @event checkchange
20469 * Fires after the checked value has been set
20470 * @param {Roo.menu.CheckItem} this
20471 * @param {Boolean} checked The checked value that was set
20473 "checkchange" : true
20475 if(this.checkHandler){
20476 this.on('checkchange', this.checkHandler, this.scope);
20479 Roo.extend(Roo.menu.CheckItem, Roo.menu.Item, {
20481 * @cfg {String} group
20482 * All check items with the same group name will automatically be grouped into a single-select
20483 * radio button group (defaults to '')
20486 * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
20488 itemCls : "x-menu-item x-menu-check-item",
20490 * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
20492 groupClass : "x-menu-group-item",
20495 * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
20496 * if this checkbox is part of a radio group (group = true) only the last item in the group that is
20497 * initialized with checked = true will be rendered as checked.
20502 ctype: "Roo.menu.CheckItem",
20505 onRender : function(c){
20506 Roo.menu.CheckItem.superclass.onRender.apply(this, arguments);
20508 this.el.addClass(this.groupClass);
20510 Roo.menu.MenuMgr.registerCheckable(this);
20512 this.checked = false;
20513 this.setChecked(true, true);
20518 destroy : function(){
20520 Roo.menu.MenuMgr.unregisterCheckable(this);
20522 Roo.menu.CheckItem.superclass.destroy.apply(this, arguments);
20526 * Set the checked state of this item
20527 * @param {Boolean} checked The new checked value
20528 * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
20530 setChecked : function(state, suppressEvent){
20531 if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
20532 if(this.container){
20533 this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
20535 this.checked = state;
20536 if(suppressEvent !== true){
20537 this.fireEvent("checkchange", this, state);
20543 handleClick : function(e){
20544 if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
20545 this.setChecked(!this.checked);
20547 Roo.menu.CheckItem.superclass.handleClick.apply(this, arguments);
20551 * Ext JS Library 1.1.1
20552 * Copyright(c) 2006-2007, Ext JS, LLC.
20554 * Originally Released Under LGPL - original licence link has changed is not relivant.
20557 * <script type="text/javascript">
20561 * @class Roo.menu.DateItem
20562 * @extends Roo.menu.Adapter
20563 * A menu item that wraps the {@link Roo.DatPicker} component.
20565 * Creates a new DateItem
20566 * @param {Object} config Configuration options
20568 Roo.menu.DateItem = function(config){
20569 Roo.menu.DateItem.superclass.constructor.call(this, new Roo.DatePicker(config), config);
20570 /** The Roo.DatePicker object @type Roo.DatePicker */
20571 this.picker = this.component;
20572 this.addEvents({select: true});
20574 this.picker.on("render", function(picker){
20575 picker.getEl().swallowEvent("click");
20576 picker.container.addClass("x-menu-date-item");
20579 this.picker.on("select", this.onSelect, this);
20582 Roo.extend(Roo.menu.DateItem, Roo.menu.Adapter, {
20584 onSelect : function(picker, date){
20585 this.fireEvent("select", this, date, picker);
20586 Roo.menu.DateItem.superclass.handleClick.call(this);
20590 * Ext JS Library 1.1.1
20591 * Copyright(c) 2006-2007, Ext JS, LLC.
20593 * Originally Released Under LGPL - original licence link has changed is not relivant.
20596 * <script type="text/javascript">
20600 * @class Roo.menu.ColorItem
20601 * @extends Roo.menu.Adapter
20602 * A menu item that wraps the {@link Roo.ColorPalette} component.
20604 * Creates a new ColorItem
20605 * @param {Object} config Configuration options
20607 Roo.menu.ColorItem = function(config){
20608 Roo.menu.ColorItem.superclass.constructor.call(this, new Roo.ColorPalette(config), config);
20609 /** The Roo.ColorPalette object @type Roo.ColorPalette */
20610 this.palette = this.component;
20611 this.relayEvents(this.palette, ["select"]);
20612 if(this.selectHandler){
20613 this.on('select', this.selectHandler, this.scope);
20616 Roo.extend(Roo.menu.ColorItem, Roo.menu.Adapter);/*
20618 * Ext JS Library 1.1.1
20619 * Copyright(c) 2006-2007, Ext JS, LLC.
20621 * Originally Released Under LGPL - original licence link has changed is not relivant.
20624 * <script type="text/javascript">
20629 * @class Roo.menu.DateMenu
20630 * @extends Roo.menu.Menu
20631 * A menu containing a {@link Roo.menu.DateItem} component (which provides a date picker).
20633 * Creates a new DateMenu
20634 * @param {Object} config Configuration options
20636 Roo.menu.DateMenu = function(config){
20637 Roo.menu.DateMenu.superclass.constructor.call(this, config);
20639 var di = new Roo.menu.DateItem(config);
20642 * The {@link Roo.DatePicker} instance for this DateMenu
20645 this.picker = di.picker;
20648 * @param {DatePicker} picker
20649 * @param {Date} date
20651 this.relayEvents(di, ["select"]);
20653 this.on('beforeshow', function(){
20655 this.picker.hideMonthPicker(true);
20659 Roo.extend(Roo.menu.DateMenu, Roo.menu.Menu, {
20663 * Ext JS Library 1.1.1
20664 * Copyright(c) 2006-2007, Ext JS, LLC.
20666 * Originally Released Under LGPL - original licence link has changed is not relivant.
20669 * <script type="text/javascript">
20674 * @class Roo.menu.ColorMenu
20675 * @extends Roo.menu.Menu
20676 * A menu containing a {@link Roo.menu.ColorItem} component (which provides a basic color picker).
20678 * Creates a new ColorMenu
20679 * @param {Object} config Configuration options
20681 Roo.menu.ColorMenu = function(config){
20682 Roo.menu.ColorMenu.superclass.constructor.call(this, config);
20684 var ci = new Roo.menu.ColorItem(config);
20687 * The {@link Roo.ColorPalette} instance for this ColorMenu
20688 * @type ColorPalette
20690 this.palette = ci.palette;
20693 * @param {ColorPalette} palette
20694 * @param {String} color
20696 this.relayEvents(ci, ["select"]);
20698 Roo.extend(Roo.menu.ColorMenu, Roo.menu.Menu);/*
20700 * Ext JS Library 1.1.1
20701 * Copyright(c) 2006-2007, Ext JS, LLC.
20703 * Originally Released Under LGPL - original licence link has changed is not relivant.
20706 * <script type="text/javascript">
20710 * @class Roo.form.Field
20711 * @extends Roo.BoxComponent
20712 * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
20714 * Creates a new Field
20715 * @param {Object} config Configuration options
20717 Roo.form.Field = function(config){
20718 Roo.form.Field.superclass.constructor.call(this, config);
20721 Roo.extend(Roo.form.Field, Roo.BoxComponent, {
20723 * @cfg {String} fieldLabel Label to use when rendering a form.
20726 * @cfg {String} qtip Mouse over tip
20730 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
20732 invalidClass : "x-form-invalid",
20734 * @cfg {String} invalidText The error text to use when marking a field invalid and no message is provided (defaults to "The value in this field is invalid")
20736 invalidText : "The value in this field is invalid",
20738 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
20740 focusClass : "x-form-focus",
20742 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
20743 automatic validation (defaults to "keyup").
20745 validationEvent : "keyup",
20747 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
20749 validateOnBlur : true,
20751 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
20753 validationDelay : 250,
20755 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
20756 * {tag: "input", type: "text", size: "20", autocomplete: "off"})
20758 defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "off"},
20760 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field")
20762 fieldClass : "x-form-field",
20764 * @cfg {String} msgTarget The location where error text should display. Should be one of the following values (defaults to 'qtip'):
20767 ----------- ----------------------------------------------------------------------
20768 qtip Display a quick tip when the user hovers over the field
20769 title Display a default browser title attribute popup
20770 under Add a block div beneath the field containing the error text
20771 side Add an error icon to the right of the field with a popup on hover
20772 [element id] Add the error text directly to the innerHTML of the specified element
20775 msgTarget : 'qtip',
20777 * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field (defaults to 'normal').
20782 * @cfg {Boolean} readOnly True to mark the field as readOnly in HTML (defaults to false) -- Note: this only sets the element's readOnly DOM attribute.
20787 * @cfg {Boolean} disabled True to disable the field (defaults to false).
20792 * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password (defaults to "text").
20794 inputType : undefined,
20797 * @cfg {Number} tabIndex The tabIndex for this field. Note this only applies to fields that are rendered, not those which are built via applyTo (defaults to undefined).
20799 tabIndex : undefined,
20802 isFormField : true,
20807 * @property {Roo.Element} fieldEl
20808 * Element Containing the rendered Field (with label etc.)
20811 * @cfg {Mixed} value A value to initialize this field with.
20816 * @cfg {String} name The field's HTML name attribute.
20819 * @cfg {String} cls A CSS class to apply to the field's underlying element.
20823 initComponent : function(){
20824 Roo.form.Field.superclass.initComponent.call(this);
20828 * Fires when this field receives input focus.
20829 * @param {Roo.form.Field} this
20834 * Fires when this field loses input focus.
20835 * @param {Roo.form.Field} this
20839 * @event specialkey
20840 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
20841 * {@link Roo.EventObject#getKey} to determine which key was pressed.
20842 * @param {Roo.form.Field} this
20843 * @param {Roo.EventObject} e The event object
20848 * Fires just before the field blurs if the field value has changed.
20849 * @param {Roo.form.Field} this
20850 * @param {Mixed} newValue The new value
20851 * @param {Mixed} oldValue The original value
20856 * Fires after the field has been marked as invalid.
20857 * @param {Roo.form.Field} this
20858 * @param {String} msg The validation message
20863 * Fires after the field has been validated with no errors.
20864 * @param {Roo.form.Field} this
20869 * Fires after the key up
20870 * @param {Roo.form.Field} this
20871 * @param {Roo.EventObject} e The event Object
20878 * Returns the name attribute of the field if available
20879 * @return {String} name The field name
20881 getName: function(){
20882 return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
20886 onRender : function(ct, position){
20887 Roo.form.Field.superclass.onRender.call(this, ct, position);
20889 var cfg = this.getAutoCreate();
20891 cfg.name = this.name || this.id;
20893 if(this.inputType){
20894 cfg.type = this.inputType;
20896 this.el = ct.createChild(cfg, position);
20898 var type = this.el.dom.type;
20900 if(type == 'password'){
20903 this.el.addClass('x-form-'+type);
20906 this.el.dom.readOnly = true;
20908 if(this.tabIndex !== undefined){
20909 this.el.dom.setAttribute('tabIndex', this.tabIndex);
20912 this.el.addClass([this.fieldClass, this.cls]);
20917 * Apply the behaviors of this component to an existing element. <b>This is used instead of render().</b>
20918 * @param {String/HTMLElement/Element} el The id of the node, a DOM node or an existing Element
20919 * @return {Roo.form.Field} this
20921 applyTo : function(target){
20922 this.allowDomMove = false;
20923 this.el = Roo.get(target);
20924 this.render(this.el.dom.parentNode);
20929 initValue : function(){
20930 if(this.value !== undefined){
20931 this.setValue(this.value);
20932 }else if(this.el.dom.value.length > 0){
20933 this.setValue(this.el.dom.value);
20938 * Returns true if this field has been changed since it was originally loaded and is not disabled.
20940 isDirty : function() {
20941 if(this.disabled) {
20944 return String(this.getValue()) !== String(this.originalValue);
20948 afterRender : function(){
20949 Roo.form.Field.superclass.afterRender.call(this);
20954 fireKey : function(e){
20955 //Roo.log('field ' + e.getKey());
20956 if(e.isNavKeyPress()){
20957 this.fireEvent("specialkey", this, e);
20962 * Resets the current field value to the originally loaded value and clears any validation messages
20964 reset : function(){
20965 this.setValue(this.originalValue);
20966 this.clearInvalid();
20970 initEvents : function(){
20971 // safari killled keypress - so keydown is now used..
20972 this.el.on("keydown" , this.fireKey, this);
20973 this.el.on("focus", this.onFocus, this);
20974 this.el.on("blur", this.onBlur, this);
20975 this.el.relayEvent('keyup', this);
20977 // reference to original value for reset
20978 this.originalValue = this.getValue();
20982 onFocus : function(){
20983 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
20984 this.el.addClass(this.focusClass);
20986 if(!this.hasFocus){
20987 this.hasFocus = true;
20988 this.startValue = this.getValue();
20989 this.fireEvent("focus", this);
20993 beforeBlur : Roo.emptyFn,
20996 onBlur : function(){
20998 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
20999 this.el.removeClass(this.focusClass);
21001 this.hasFocus = false;
21002 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
21005 var v = this.getValue();
21006 if(String(v) !== String(this.startValue)){
21007 this.fireEvent('change', this, v, this.startValue);
21009 this.fireEvent("blur", this);
21013 * Returns whether or not the field value is currently valid
21014 * @param {Boolean} preventMark True to disable marking the field invalid
21015 * @return {Boolean} True if the value is valid, else false
21017 isValid : function(preventMark){
21021 var restore = this.preventMark;
21022 this.preventMark = preventMark === true;
21023 var v = this.validateValue(this.processValue(this.getRawValue()));
21024 this.preventMark = restore;
21029 * Validates the field value
21030 * @return {Boolean} True if the value is valid, else false
21032 validate : function(){
21033 if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
21034 this.clearInvalid();
21040 processValue : function(value){
21045 // Subclasses should provide the validation implementation by overriding this
21046 validateValue : function(value){
21051 * Mark this field as invalid
21052 * @param {String} msg The validation message
21054 markInvalid : function(msg){
21055 if(!this.rendered || this.preventMark){ // not rendered
21058 this.el.addClass(this.invalidClass);
21059 msg = msg || this.invalidText;
21060 switch(this.msgTarget){
21062 this.el.dom.qtip = msg;
21063 this.el.dom.qclass = 'x-form-invalid-tip';
21064 if(Roo.QuickTips){ // fix for floating editors interacting with DND
21065 Roo.QuickTips.enable();
21069 this.el.dom.title = msg;
21073 var elp = this.el.findParent('.x-form-element', 5, true);
21074 this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
21075 this.errorEl.setWidth(elp.getWidth(true)-20);
21077 this.errorEl.update(msg);
21078 Roo.form.Field.msgFx[this.msgFx].show(this.errorEl, this);
21081 if(!this.errorIcon){
21082 var elp = this.el.findParent('.x-form-element', 5, true);
21083 this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
21085 this.alignErrorIcon();
21086 this.errorIcon.dom.qtip = msg;
21087 this.errorIcon.dom.qclass = 'x-form-invalid-tip';
21088 this.errorIcon.show();
21089 this.on('resize', this.alignErrorIcon, this);
21092 var t = Roo.getDom(this.msgTarget);
21094 t.style.display = this.msgDisplay;
21097 this.fireEvent('invalid', this, msg);
21101 alignErrorIcon : function(){
21102 this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
21106 * Clear any invalid styles/messages for this field
21108 clearInvalid : function(){
21109 if(!this.rendered || this.preventMark){ // not rendered
21112 this.el.removeClass(this.invalidClass);
21113 switch(this.msgTarget){
21115 this.el.dom.qtip = '';
21118 this.el.dom.title = '';
21122 Roo.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);
21126 if(this.errorIcon){
21127 this.errorIcon.dom.qtip = '';
21128 this.errorIcon.hide();
21129 this.un('resize', this.alignErrorIcon, this);
21133 var t = Roo.getDom(this.msgTarget);
21135 t.style.display = 'none';
21138 this.fireEvent('valid', this);
21142 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
21143 * @return {Mixed} value The field value
21145 getRawValue : function(){
21146 var v = this.el.getValue();
21147 if(v === this.emptyText){
21154 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
21155 * @return {Mixed} value The field value
21157 getValue : function(){
21158 var v = this.el.getValue();
21159 if(v === this.emptyText || v === undefined){
21166 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
21167 * @param {Mixed} value The value to set
21169 setRawValue : function(v){
21170 return this.el.dom.value = (v === null || v === undefined ? '' : v);
21174 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
21175 * @param {Mixed} value The value to set
21177 setValue : function(v){
21180 this.el.dom.value = (v === null || v === undefined ? '' : v);
21185 adjustSize : function(w, h){
21186 var s = Roo.form.Field.superclass.adjustSize.call(this, w, h);
21187 s.width = this.adjustWidth(this.el.dom.tagName, s.width);
21191 adjustWidth : function(tag, w){
21192 tag = tag.toLowerCase();
21193 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
21194 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
21195 if(tag == 'input'){
21198 if(tag = 'textarea'){
21201 }else if(Roo.isOpera){
21202 if(tag == 'input'){
21205 if(tag = 'textarea'){
21215 // anything other than normal should be considered experimental
21216 Roo.form.Field.msgFx = {
21218 show: function(msgEl, f){
21219 msgEl.setDisplayed('block');
21222 hide : function(msgEl, f){
21223 msgEl.setDisplayed(false).update('');
21228 show: function(msgEl, f){
21229 msgEl.slideIn('t', {stopFx:true});
21232 hide : function(msgEl, f){
21233 msgEl.slideOut('t', {stopFx:true,useDisplay:true});
21238 show: function(msgEl, f){
21239 msgEl.fixDisplay();
21240 msgEl.alignTo(f.el, 'tl-tr');
21241 msgEl.slideIn('l', {stopFx:true});
21244 hide : function(msgEl, f){
21245 msgEl.slideOut('l', {stopFx:true,useDisplay:true});
21250 * Ext JS Library 1.1.1
21251 * Copyright(c) 2006-2007, Ext JS, LLC.
21253 * Originally Released Under LGPL - original licence link has changed is not relivant.
21256 * <script type="text/javascript">
21261 * @class Roo.form.TextField
21262 * @extends Roo.form.Field
21263 * Basic text field. Can be used as a direct replacement for traditional text inputs, or as the base
21264 * class for more sophisticated input controls (like {@link Roo.form.TextArea} and {@link Roo.form.ComboBox}).
21266 * Creates a new TextField
21267 * @param {Object} config Configuration options
21269 Roo.form.TextField = function(config){
21270 Roo.form.TextField.superclass.constructor.call(this, config);
21274 * Fires when the autosize function is triggered. The field may or may not have actually changed size
21275 * according to the default logic, but this event provides a hook for the developer to apply additional
21276 * logic at runtime to resize the field if needed.
21277 * @param {Roo.form.Field} this This text field
21278 * @param {Number} width The new field width
21284 Roo.extend(Roo.form.TextField, Roo.form.Field, {
21286 * @cfg {Boolean} grow True if this field should automatically grow and shrink to its content
21290 * @cfg {Number} growMin The minimum width to allow when grow = true (defaults to 30)
21294 * @cfg {Number} growMax The maximum width to allow when grow = true (defaults to 800)
21298 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
21302 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
21306 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
21308 disableKeyFilter : false,
21310 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
21314 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
21318 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
21320 maxLength : Number.MAX_VALUE,
21322 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
21324 minLengthText : "The minimum length for this field is {0}",
21326 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
21328 maxLengthText : "The maximum length for this field is {0}",
21330 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
21332 selectOnFocus : false,
21334 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
21336 blankText : "This field is required",
21338 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
21339 * If available, this function will be called only after the basic validators all return true, and will be passed the
21340 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
21344 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
21345 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
21346 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
21350 * @cfg {String} regexText The error text to display if {@link #regex} is used and the test fails during validation (defaults to "")
21354 * @cfg {String} emptyText The default text to display in an empty field (defaults to null).
21358 * @cfg {String} emptyClass The CSS class to apply to an empty field to style the {@link #emptyText} (defaults to
21359 * 'x-form-empty-field'). This class is automatically added and removed as needed depending on the current field value.
21361 emptyClass : 'x-form-empty-field',
21364 initEvents : function(){
21365 Roo.form.TextField.superclass.initEvents.call(this);
21366 if(this.validationEvent == 'keyup'){
21367 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
21368 this.el.on('keyup', this.filterValidation, this);
21370 else if(this.validationEvent !== false){
21371 this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
21373 if(this.selectOnFocus || this.emptyText){
21374 this.on("focus", this.preFocus, this);
21375 if(this.emptyText){
21376 this.on('blur', this.postBlur, this);
21377 this.applyEmptyText();
21380 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
21381 this.el.on("keypress", this.filterKeys, this);
21384 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
21385 this.el.on("click", this.autoSize, this);
21389 processValue : function(value){
21390 if(this.stripCharsRe){
21391 var newValue = value.replace(this.stripCharsRe, '');
21392 if(newValue !== value){
21393 this.setRawValue(newValue);
21400 filterValidation : function(e){
21401 if(!e.isNavKeyPress()){
21402 this.validationTask.delay(this.validationDelay);
21407 onKeyUp : function(e){
21408 if(!e.isNavKeyPress()){
21414 * Resets the current field value to the originally-loaded value and clears any validation messages.
21415 * Also adds emptyText and emptyClass if the original value was blank.
21417 reset : function(){
21418 Roo.form.TextField.superclass.reset.call(this);
21419 this.applyEmptyText();
21422 applyEmptyText : function(){
21423 if(this.rendered && this.emptyText && this.getRawValue().length < 1){
21424 this.setRawValue(this.emptyText);
21425 this.el.addClass(this.emptyClass);
21430 preFocus : function(){
21431 if(this.emptyText){
21432 if(this.el.dom.value == this.emptyText){
21433 this.setRawValue('');
21435 this.el.removeClass(this.emptyClass);
21437 if(this.selectOnFocus){
21438 this.el.dom.select();
21443 postBlur : function(){
21444 this.applyEmptyText();
21448 filterKeys : function(e){
21449 var k = e.getKey();
21450 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
21453 var c = e.getCharCode(), cc = String.fromCharCode(c);
21454 if(Roo.isIE && (e.isSpecialKey() || !cc)){
21457 if(!this.maskRe.test(cc)){
21462 setValue : function(v){
21463 if(this.emptyText && this.el && v !== undefined && v !== null && v !== ''){
21464 this.el.removeClass(this.emptyClass);
21466 Roo.form.TextField.superclass.setValue.apply(this, arguments);
21467 this.applyEmptyText();
21472 * Validates a value according to the field's validation rules and marks the field as invalid
21473 * if the validation fails
21474 * @param {Mixed} value The value to validate
21475 * @return {Boolean} True if the value is valid, else false
21477 validateValue : function(value){
21478 if(value.length < 1 || value === this.emptyText){ // if it's blank
21479 if(this.allowBlank){
21480 this.clearInvalid();
21483 this.markInvalid(this.blankText);
21487 if(value.length < this.minLength){
21488 this.markInvalid(String.format(this.minLengthText, this.minLength));
21491 if(value.length > this.maxLength){
21492 this.markInvalid(String.format(this.maxLengthText, this.maxLength));
21496 var vt = Roo.form.VTypes;
21497 if(!vt[this.vtype](value, this)){
21498 this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
21502 if(typeof this.validator == "function"){
21503 var msg = this.validator(value);
21505 this.markInvalid(msg);
21509 if(this.regex && !this.regex.test(value)){
21510 this.markInvalid(this.regexText);
21517 * Selects text in this field
21518 * @param {Number} start (optional) The index where the selection should start (defaults to 0)
21519 * @param {Number} end (optional) The index where the selection should end (defaults to the text length)
21521 selectText : function(start, end){
21522 var v = this.getRawValue();
21524 start = start === undefined ? 0 : start;
21525 end = end === undefined ? v.length : end;
21526 var d = this.el.dom;
21527 if(d.setSelectionRange){
21528 d.setSelectionRange(start, end);
21529 }else if(d.createTextRange){
21530 var range = d.createTextRange();
21531 range.moveStart("character", start);
21532 range.moveEnd("character", v.length-end);
21539 * Automatically grows the field to accomodate the width of the text up to the maximum field width allowed.
21540 * This only takes effect if grow = true, and fires the autosize event.
21542 autoSize : function(){
21543 if(!this.grow || !this.rendered){
21547 this.metrics = Roo.util.TextMetrics.createInstance(this.el);
21550 var v = el.dom.value;
21551 var d = document.createElement('div');
21552 d.appendChild(document.createTextNode(v));
21556 var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + /* add extra padding */ 10, this.growMin));
21557 this.el.setWidth(w);
21558 this.fireEvent("autosize", this, w);
21562 * Ext JS Library 1.1.1
21563 * Copyright(c) 2006-2007, Ext JS, LLC.
21565 * Originally Released Under LGPL - original licence link has changed is not relivant.
21568 * <script type="text/javascript">
21572 * @class Roo.form.Hidden
21573 * @extends Roo.form.TextField
21574 * Simple Hidden element used on forms
21576 * usage: form.add(new Roo.form.HiddenField({ 'name' : 'test1' }));
21579 * Creates a new Hidden form element.
21580 * @param {Object} config Configuration options
21585 // easy hidden field...
21586 Roo.form.Hidden = function(config){
21587 Roo.form.Hidden.superclass.constructor.call(this, config);
21590 Roo.extend(Roo.form.Hidden, Roo.form.TextField, {
21592 inputType: 'hidden',
21595 labelSeparator: '',
21597 itemCls : 'x-form-item-display-none'
21605 * Ext JS Library 1.1.1
21606 * Copyright(c) 2006-2007, Ext JS, LLC.
21608 * Originally Released Under LGPL - original licence link has changed is not relivant.
21611 * <script type="text/javascript">
21615 * @class Roo.form.TriggerField
21616 * @extends Roo.form.TextField
21617 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
21618 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
21619 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
21620 * for which you can provide a custom implementation. For example:
21622 var trigger = new Roo.form.TriggerField();
21623 trigger.onTriggerClick = myTriggerFn;
21624 trigger.applyTo('my-field');
21627 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
21628 * {@link Roo.form.DateField} and {@link Roo.form.ComboBox} are perfect examples of this.
21629 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
21630 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
21632 * Create a new TriggerField.
21633 * @param {Object} config Configuration options (valid {@Roo.form.TextField} config options will also be applied
21634 * to the base TextField)
21636 Roo.form.TriggerField = function(config){
21637 this.mimicing = false;
21638 Roo.form.TriggerField.superclass.constructor.call(this, config);
21641 Roo.extend(Roo.form.TriggerField, Roo.form.TextField, {
21643 * @cfg {String} triggerClass A CSS class to apply to the trigger
21646 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
21647 * {tag: "input", type: "text", size: "16", autocomplete: "off"})
21649 defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
21651 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
21655 /** @cfg {Boolean} grow @hide */
21656 /** @cfg {Number} growMin @hide */
21657 /** @cfg {Number} growMax @hide */
21663 autoSize: Roo.emptyFn,
21667 deferHeight : true,
21670 actionMode : 'wrap',
21672 onResize : function(w, h){
21673 Roo.form.TriggerField.superclass.onResize.apply(this, arguments);
21674 if(typeof w == 'number'){
21675 var x = w - this.trigger.getWidth();
21676 this.el.setWidth(this.adjustWidth('input', x));
21677 this.trigger.setStyle('left', x+'px');
21682 adjustSize : Roo.BoxComponent.prototype.adjustSize,
21685 getResizeEl : function(){
21690 getPositionEl : function(){
21695 alignErrorIcon : function(){
21696 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
21700 onRender : function(ct, position){
21701 Roo.form.TriggerField.superclass.onRender.call(this, ct, position);
21702 this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
21703 this.trigger = this.wrap.createChild(this.triggerConfig ||
21704 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
21705 if(this.hideTrigger){
21706 this.trigger.setDisplayed(false);
21708 this.initTrigger();
21710 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
21715 initTrigger : function(){
21716 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
21717 this.trigger.addClassOnOver('x-form-trigger-over');
21718 this.trigger.addClassOnClick('x-form-trigger-click');
21722 onDestroy : function(){
21724 this.trigger.removeAllListeners();
21725 this.trigger.remove();
21728 this.wrap.remove();
21730 Roo.form.TriggerField.superclass.onDestroy.call(this);
21734 onFocus : function(){
21735 Roo.form.TriggerField.superclass.onFocus.call(this);
21736 if(!this.mimicing){
21737 this.wrap.addClass('x-trigger-wrap-focus');
21738 this.mimicing = true;
21739 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
21740 if(this.monitorTab){
21741 this.el.on("keydown", this.checkTab, this);
21747 checkTab : function(e){
21748 if(e.getKey() == e.TAB){
21749 this.triggerBlur();
21754 onBlur : function(){
21759 mimicBlur : function(e, t){
21760 if(!this.wrap.contains(t) && this.validateBlur()){
21761 this.triggerBlur();
21766 triggerBlur : function(){
21767 this.mimicing = false;
21768 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
21769 if(this.monitorTab){
21770 this.el.un("keydown", this.checkTab, this);
21772 this.wrap.removeClass('x-trigger-wrap-focus');
21773 Roo.form.TriggerField.superclass.onBlur.call(this);
21777 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
21778 validateBlur : function(e, t){
21783 onDisable : function(){
21784 Roo.form.TriggerField.superclass.onDisable.call(this);
21786 this.wrap.addClass('x-item-disabled');
21791 onEnable : function(){
21792 Roo.form.TriggerField.superclass.onEnable.call(this);
21794 this.wrap.removeClass('x-item-disabled');
21799 onShow : function(){
21800 var ae = this.getActionEl();
21803 ae.dom.style.display = '';
21804 ae.dom.style.visibility = 'visible';
21810 onHide : function(){
21811 var ae = this.getActionEl();
21812 ae.dom.style.display = 'none';
21816 * The function that should handle the trigger's click event. This method does nothing by default until overridden
21817 * by an implementing function.
21819 * @param {EventObject} e
21821 onTriggerClick : Roo.emptyFn
21824 // TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
21825 // to be extended by an implementing class. For an example of implementing this class, see the custom
21826 // SearchField implementation here: http://extjs.com/deploy/ext/examples/form/custom.html
21827 Roo.form.TwinTriggerField = Roo.extend(Roo.form.TriggerField, {
21828 initComponent : function(){
21829 Roo.form.TwinTriggerField.superclass.initComponent.call(this);
21831 this.triggerConfig = {
21832 tag:'span', cls:'x-form-twin-triggers', cn:[
21833 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
21834 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
21838 getTrigger : function(index){
21839 return this.triggers[index];
21842 initTrigger : function(){
21843 var ts = this.trigger.select('.x-form-trigger', true);
21844 this.wrap.setStyle('overflow', 'hidden');
21845 var triggerField = this;
21846 ts.each(function(t, all, index){
21847 t.hide = function(){
21848 var w = triggerField.wrap.getWidth();
21849 this.dom.style.display = 'none';
21850 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
21852 t.show = function(){
21853 var w = triggerField.wrap.getWidth();
21854 this.dom.style.display = '';
21855 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
21857 var triggerIndex = 'Trigger'+(index+1);
21859 if(this['hide'+triggerIndex]){
21860 t.dom.style.display = 'none';
21862 t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
21863 t.addClassOnOver('x-form-trigger-over');
21864 t.addClassOnClick('x-form-trigger-click');
21866 this.triggers = ts.elements;
21869 onTrigger1Click : Roo.emptyFn,
21870 onTrigger2Click : Roo.emptyFn
21873 * Ext JS Library 1.1.1
21874 * Copyright(c) 2006-2007, Ext JS, LLC.
21876 * Originally Released Under LGPL - original licence link has changed is not relivant.
21879 * <script type="text/javascript">
21883 * @class Roo.form.TextArea
21884 * @extends Roo.form.TextField
21885 * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds
21886 * support for auto-sizing.
21888 * Creates a new TextArea
21889 * @param {Object} config Configuration options
21891 Roo.form.TextArea = function(config){
21892 Roo.form.TextArea.superclass.constructor.call(this, config);
21893 // these are provided exchanges for backwards compat
21894 // minHeight/maxHeight were replaced by growMin/growMax to be
21895 // compatible with TextField growing config values
21896 if(this.minHeight !== undefined){
21897 this.growMin = this.minHeight;
21899 if(this.maxHeight !== undefined){
21900 this.growMax = this.maxHeight;
21904 Roo.extend(Roo.form.TextArea, Roo.form.TextField, {
21906 * @cfg {Number} growMin The minimum height to allow when grow = true (defaults to 60)
21910 * @cfg {Number} growMax The maximum height to allow when grow = true (defaults to 1000)
21914 * @cfg {Boolean} preventScrollbars True to prevent scrollbars from appearing regardless of how much text is
21915 * in the field (equivalent to setting overflow: hidden, defaults to false)
21917 preventScrollbars: false,
21919 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
21920 * {tag: "textarea", style: "width:300px;height:60px;", autocomplete: "off"})
21924 onRender : function(ct, position){
21926 this.defaultAutoCreate = {
21928 style:"width:300px;height:60px;",
21929 autocomplete: "off"
21932 Roo.form.TextArea.superclass.onRender.call(this, ct, position);
21934 this.textSizeEl = Roo.DomHelper.append(document.body, {
21935 tag: "pre", cls: "x-form-grow-sizer"
21937 if(this.preventScrollbars){
21938 this.el.setStyle("overflow", "hidden");
21940 this.el.setHeight(this.growMin);
21944 onDestroy : function(){
21945 if(this.textSizeEl){
21946 this.textSizeEl.parentNode.removeChild(this.textSizeEl);
21948 Roo.form.TextArea.superclass.onDestroy.call(this);
21952 onKeyUp : function(e){
21953 if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
21959 * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
21960 * This only takes effect if grow = true, and fires the autosize event if the height changes.
21962 autoSize : function(){
21963 if(!this.grow || !this.textSizeEl){
21967 var v = el.dom.value;
21968 var ts = this.textSizeEl;
21971 ts.appendChild(document.createTextNode(v));
21974 Roo.fly(ts).setWidth(this.el.getWidth());
21976 v = "  ";
21979 v = v.replace(/\n/g, '<p> </p>');
21981 v += " \n ";
21984 var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
21985 if(h != this.lastHeight){
21986 this.lastHeight = h;
21987 this.el.setHeight(h);
21988 this.fireEvent("autosize", this, h);
21993 * Ext JS Library 1.1.1
21994 * Copyright(c) 2006-2007, Ext JS, LLC.
21996 * Originally Released Under LGPL - original licence link has changed is not relivant.
21999 * <script type="text/javascript">
22004 * @class Roo.form.NumberField
22005 * @extends Roo.form.TextField
22006 * Numeric text field that provides automatic keystroke filtering and numeric validation.
22008 * Creates a new NumberField
22009 * @param {Object} config Configuration options
22011 Roo.form.NumberField = function(config){
22012 Roo.form.NumberField.superclass.constructor.call(this, config);
22015 Roo.extend(Roo.form.NumberField, Roo.form.TextField, {
22017 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
22019 fieldClass: "x-form-field x-form-num-field",
22021 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
22023 allowDecimals : true,
22025 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
22027 decimalSeparator : ".",
22029 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
22031 decimalPrecision : 2,
22033 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
22035 allowNegative : true,
22037 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
22039 minValue : Number.NEGATIVE_INFINITY,
22041 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
22043 maxValue : Number.MAX_VALUE,
22045 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
22047 minText : "The minimum value for this field is {0}",
22049 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
22051 maxText : "The maximum value for this field is {0}",
22053 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
22054 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
22056 nanText : "{0} is not a valid number",
22059 initEvents : function(){
22060 Roo.form.NumberField.superclass.initEvents.call(this);
22061 var allowed = "0123456789";
22062 if(this.allowDecimals){
22063 allowed += this.decimalSeparator;
22065 if(this.allowNegative){
22068 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
22069 var keyPress = function(e){
22070 var k = e.getKey();
22071 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
22074 var c = e.getCharCode();
22075 if(allowed.indexOf(String.fromCharCode(c)) === -1){
22079 this.el.on("keypress", keyPress, this);
22083 validateValue : function(value){
22084 if(!Roo.form.NumberField.superclass.validateValue.call(this, value)){
22087 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
22090 var num = this.parseValue(value);
22092 this.markInvalid(String.format(this.nanText, value));
22095 if(num < this.minValue){
22096 this.markInvalid(String.format(this.minText, this.minValue));
22099 if(num > this.maxValue){
22100 this.markInvalid(String.format(this.maxText, this.maxValue));
22106 getValue : function(){
22107 return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));
22111 parseValue : function(value){
22112 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
22113 return isNaN(value) ? '' : value;
22117 fixPrecision : function(value){
22118 var nan = isNaN(value);
22119 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
22120 return nan ? '' : value;
22122 return parseFloat(value).toFixed(this.decimalPrecision);
22125 setValue : function(v){
22126 Roo.form.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
22130 decimalPrecisionFcn : function(v){
22131 return Math.floor(v);
22134 beforeBlur : function(){
22135 var v = this.parseValue(this.getRawValue());
22137 this.setValue(this.fixPrecision(v));
22142 * Ext JS Library 1.1.1
22143 * Copyright(c) 2006-2007, Ext JS, LLC.
22145 * Originally Released Under LGPL - original licence link has changed is not relivant.
22148 * <script type="text/javascript">
22152 * @class Roo.form.DateField
22153 * @extends Roo.form.TriggerField
22154 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
22156 * Create a new DateField
22157 * @param {Object} config
22159 Roo.form.DateField = function(config){
22160 Roo.form.DateField.superclass.constructor.call(this, config);
22166 * Fires when a date is selected
22167 * @param {Roo.form.DateField} combo This combo box
22168 * @param {Date} date The date selected
22175 if(typeof this.minValue == "string") this.minValue = this.parseDate(this.minValue);
22176 if(typeof this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue);
22177 this.ddMatch = null;
22178 if(this.disabledDates){
22179 var dd = this.disabledDates;
22181 for(var i = 0; i < dd.length; i++){
22183 if(i != dd.length-1) re += "|";
22185 this.ddMatch = new RegExp(re + ")");
22189 Roo.extend(Roo.form.DateField, Roo.form.TriggerField, {
22191 * @cfg {String} format
22192 * The default date format string which can be overriden for localization support. The format must be
22193 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
22197 * @cfg {String} altFormats
22198 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
22199 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
22201 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
22203 * @cfg {Array} disabledDays
22204 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
22206 disabledDays : null,
22208 * @cfg {String} disabledDaysText
22209 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
22211 disabledDaysText : "Disabled",
22213 * @cfg {Array} disabledDates
22214 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
22215 * expression so they are very powerful. Some examples:
22217 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
22218 * <li>["03/08", "09/16"] would disable those days for every year</li>
22219 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
22220 * <li>["03/../2006"] would disable every day in March 2006</li>
22221 * <li>["^03"] would disable every day in every March</li>
22223 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
22224 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
22226 disabledDates : null,
22228 * @cfg {String} disabledDatesText
22229 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
22231 disabledDatesText : "Disabled",
22233 * @cfg {Date/String} minValue
22234 * The minimum allowed date. Can be either a Javascript date object or a string date in a
22235 * valid format (defaults to null).
22239 * @cfg {Date/String} maxValue
22240 * The maximum allowed date. Can be either a Javascript date object or a string date in a
22241 * valid format (defaults to null).
22245 * @cfg {String} minText
22246 * The error text to display when the date in the cell is before minValue (defaults to
22247 * 'The date in this field must be after {minValue}').
22249 minText : "The date in this field must be equal to or after {0}",
22251 * @cfg {String} maxText
22252 * The error text to display when the date in the cell is after maxValue (defaults to
22253 * 'The date in this field must be before {maxValue}').
22255 maxText : "The date in this field must be equal to or before {0}",
22257 * @cfg {String} invalidText
22258 * The error text to display when the date in the field is invalid (defaults to
22259 * '{value} is not a valid date - it must be in the format {format}').
22261 invalidText : "{0} is not a valid date - it must be in the format {1}",
22263 * @cfg {String} triggerClass
22264 * An additional CSS class used to style the trigger button. The trigger will always get the
22265 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
22266 * which displays a calendar icon).
22268 triggerClass : 'x-form-date-trigger',
22272 * @cfg {bool} useIso
22273 * if enabled, then the date field will use a hidden field to store the
22274 * real value as iso formated date. default (false)
22278 * @cfg {String/Object} autoCreate
22279 * A DomHelper element spec, or true for a default element spec (defaults to
22280 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
22283 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
22286 hiddenField: false,
22288 onRender : function(ct, position)
22290 Roo.form.DateField.superclass.onRender.call(this, ct, position);
22292 this.el.dom.removeAttribute('name');
22293 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
22295 this.hiddenField.value = this.formatDate(this.value, 'Y-m-d');
22296 // prevent input submission
22297 this.hiddenName = this.name;
22304 validateValue : function(value)
22306 value = this.formatDate(value);
22307 if(!Roo.form.DateField.superclass.validateValue.call(this, value)){
22310 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
22313 var svalue = value;
22314 value = this.parseDate(value);
22316 this.markInvalid(String.format(this.invalidText, svalue, this.format));
22319 var time = value.getTime();
22320 if(this.minValue && time < this.minValue.getTime()){
22321 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
22324 if(this.maxValue && time > this.maxValue.getTime()){
22325 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
22328 if(this.disabledDays){
22329 var day = value.getDay();
22330 for(var i = 0; i < this.disabledDays.length; i++) {
22331 if(day === this.disabledDays[i]){
22332 this.markInvalid(this.disabledDaysText);
22337 var fvalue = this.formatDate(value);
22338 if(this.ddMatch && this.ddMatch.test(fvalue)){
22339 this.markInvalid(String.format(this.disabledDatesText, fvalue));
22346 // Provides logic to override the default TriggerField.validateBlur which just returns true
22347 validateBlur : function(){
22348 return !this.menu || !this.menu.isVisible();
22352 * Returns the current date value of the date field.
22353 * @return {Date} The date value
22355 getValue : function(){
22357 return this.hiddenField ? this.hiddenField.value : this.parseDate(Roo.form.DateField.superclass.getValue.call(this)) || "";
22361 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
22362 * date, using DateField.format as the date format, according to the same rules as {@link Date#parseDate}
22363 * (the default format used is "m/d/y").
22366 //All of these calls set the same date value (May 4, 2006)
22368 //Pass a date object:
22369 var dt = new Date('5/4/06');
22370 dateField.setValue(dt);
22372 //Pass a date string (default format):
22373 dateField.setValue('5/4/06');
22375 //Pass a date string (custom format):
22376 dateField.format = 'Y-m-d';
22377 dateField.setValue('2006-5-4');
22379 * @param {String/Date} date The date or valid date string
22381 setValue : function(date){
22382 if (this.hiddenField) {
22383 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
22385 Roo.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
22389 parseDate : function(value){
22390 if(!value || value instanceof Date){
22393 var v = Date.parseDate(value, this.format);
22394 if(!v && this.altFormats){
22395 if(!this.altFormatsArray){
22396 this.altFormatsArray = this.altFormats.split("|");
22398 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
22399 v = Date.parseDate(value, this.altFormatsArray[i]);
22406 formatDate : function(date, fmt){
22407 return (!date || !(date instanceof Date)) ?
22408 date : date.dateFormat(fmt || this.format);
22413 select: function(m, d){
22415 this.fireEvent('select', this, d);
22417 show : function(){ // retain focus styling
22421 this.focus.defer(10, this);
22422 var ml = this.menuListeners;
22423 this.menu.un("select", ml.select, this);
22424 this.menu.un("show", ml.show, this);
22425 this.menu.un("hide", ml.hide, this);
22430 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
22431 onTriggerClick : function(){
22435 if(this.menu == null){
22436 this.menu = new Roo.menu.DateMenu();
22438 Roo.apply(this.menu.picker, {
22439 showClear: this.allowBlank,
22440 minDate : this.minValue,
22441 maxDate : this.maxValue,
22442 disabledDatesRE : this.ddMatch,
22443 disabledDatesText : this.disabledDatesText,
22444 disabledDays : this.disabledDays,
22445 disabledDaysText : this.disabledDaysText,
22446 format : this.format,
22447 minText : String.format(this.minText, this.formatDate(this.minValue)),
22448 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
22450 this.menu.on(Roo.apply({}, this.menuListeners, {
22453 this.menu.picker.setValue(this.getValue() || new Date());
22454 this.menu.show(this.el, "tl-bl?");
22457 beforeBlur : function(){
22458 var v = this.parseDate(this.getRawValue());
22464 /** @cfg {Boolean} grow @hide */
22465 /** @cfg {Number} growMin @hide */
22466 /** @cfg {Number} growMax @hide */
22473 * Ext JS Library 1.1.1
22474 * Copyright(c) 2006-2007, Ext JS, LLC.
22476 * Originally Released Under LGPL - original licence link has changed is not relivant.
22479 * <script type="text/javascript">
22484 * @class Roo.form.ComboBox
22485 * @extends Roo.form.TriggerField
22486 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
22488 * Create a new ComboBox.
22489 * @param {Object} config Configuration options
22491 Roo.form.ComboBox = function(config){
22492 Roo.form.ComboBox.superclass.constructor.call(this, config);
22496 * Fires when the dropdown list is expanded
22497 * @param {Roo.form.ComboBox} combo This combo box
22502 * Fires when the dropdown list is collapsed
22503 * @param {Roo.form.ComboBox} combo This combo box
22507 * @event beforeselect
22508 * Fires before a list item is selected. Return false to cancel the selection.
22509 * @param {Roo.form.ComboBox} combo This combo box
22510 * @param {Roo.data.Record} record The data record returned from the underlying store
22511 * @param {Number} index The index of the selected item in the dropdown list
22513 'beforeselect' : true,
22516 * Fires when a list item is selected
22517 * @param {Roo.form.ComboBox} combo This combo box
22518 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
22519 * @param {Number} index The index of the selected item in the dropdown list
22523 * @event beforequery
22524 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
22525 * The event object passed has these properties:
22526 * @param {Roo.form.ComboBox} combo This combo box
22527 * @param {String} query The query
22528 * @param {Boolean} forceAll true to force "all" query
22529 * @param {Boolean} cancel true to cancel the query
22530 * @param {Object} e The query event object
22532 'beforequery': true,
22535 * Fires when the 'add' icon is pressed (add a listener to enable add button)
22536 * @param {Roo.form.ComboBox} combo This combo box
22541 * Fires when the 'edit' icon is pressed (add a listener to enable add button)
22542 * @param {Roo.form.ComboBox} combo This combo box
22543 * @param {Roo.data.Record|false} record The data record returned from the underlying store (or false on nothing selected)
22549 if(this.transform){
22550 this.allowDomMove = false;
22551 var s = Roo.getDom(this.transform);
22552 if(!this.hiddenName){
22553 this.hiddenName = s.name;
22556 this.mode = 'local';
22557 var d = [], opts = s.options;
22558 for(var i = 0, len = opts.length;i < len; i++){
22560 var value = (Roo.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text;
22562 this.value = value;
22564 d.push([value, o.text]);
22566 this.store = new Roo.data.SimpleStore({
22568 fields: ['value', 'text'],
22571 this.valueField = 'value';
22572 this.displayField = 'text';
22574 s.name = Roo.id(); // wipe out the name in case somewhere else they have a reference
22575 if(!this.lazyRender){
22576 this.target = true;
22577 this.el = Roo.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
22578 s.parentNode.removeChild(s); // remove it
22579 this.render(this.el.parentNode);
22581 s.parentNode.removeChild(s); // remove it
22586 this.store = Roo.factory(this.store, Roo.data);
22589 this.selectedIndex = -1;
22590 if(this.mode == 'local'){
22591 if(config.queryDelay === undefined){
22592 this.queryDelay = 10;
22594 if(config.minChars === undefined){
22600 Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, {
22602 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
22605 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
22606 * rendering into an Roo.Editor, defaults to false)
22609 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
22610 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
22613 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
22616 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
22617 * the dropdown list (defaults to undefined, with no header element)
22621 * @cfg {String/Roo.Template} tpl The template to use to render the output
22625 defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
22627 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
22629 listWidth: undefined,
22631 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
22632 * mode = 'remote' or 'text' if mode = 'local')
22634 displayField: undefined,
22636 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
22637 * mode = 'remote' or 'value' if mode = 'local').
22638 * Note: use of a valueField requires the user make a selection
22639 * in order for a value to be mapped.
22641 valueField: undefined,
22643 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
22644 * field's data value (defaults to the underlying DOM element's name)
22646 hiddenName: undefined,
22648 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
22652 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
22654 selectedClass: 'x-combo-selected',
22656 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
22657 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
22658 * which displays a downward arrow icon).
22660 triggerClass : 'x-form-arrow-trigger',
22662 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
22666 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
22667 * anchor positions (defaults to 'tl-bl')
22669 listAlign: 'tl-bl?',
22671 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
22675 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
22676 * query specified by the allQuery config option (defaults to 'query')
22678 triggerAction: 'query',
22680 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
22681 * (defaults to 4, does not apply if editable = false)
22685 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
22686 * delay (typeAheadDelay) if it matches a known value (defaults to false)
22690 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
22691 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
22695 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
22696 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
22700 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
22701 * when editable = true (defaults to false)
22703 selectOnFocus:false,
22705 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
22707 queryParam: 'query',
22709 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
22710 * when mode = 'remote' (defaults to 'Loading...')
22712 loadingText: 'Loading...',
22714 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
22718 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
22722 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
22723 * traditional select (defaults to true)
22727 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
22731 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
22735 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
22736 * listWidth has a higher value)
22740 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
22741 * allow the user to set arbitrary text into the field (defaults to false)
22743 forceSelection:false,
22745 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
22746 * if typeAhead = true (defaults to 250)
22748 typeAheadDelay : 250,
22750 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
22751 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
22753 valueNotFoundText : undefined,
22755 * @cfg {Boolean} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
22757 blockFocus : false,
22760 * @cfg {Boolean} disableClear Disable showing of clear button.
22762 disableClear : false,
22764 * @cfg {Boolean} alwaysQuery Disable caching of results, and always send query
22766 alwaysQuery : false,
22774 onRender : function(ct, position){
22775 Roo.form.ComboBox.superclass.onRender.call(this, ct, position);
22776 if(this.hiddenName){
22777 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
22779 this.hiddenField.value =
22780 this.hiddenValue !== undefined ? this.hiddenValue :
22781 this.value !== undefined ? this.value : '';
22783 // prevent input submission
22784 this.el.dom.removeAttribute('name');
22787 this.el.dom.setAttribute('autocomplete', 'off');
22790 var cls = 'x-combo-list';
22792 this.list = new Roo.Layer({
22793 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
22796 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
22797 this.list.setWidth(lw);
22798 this.list.swallowEvent('mousewheel');
22799 this.assetHeight = 0;
22802 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
22803 this.assetHeight += this.header.getHeight();
22806 this.innerList = this.list.createChild({cls:cls+'-inner'});
22807 this.innerList.on('mouseover', this.onViewOver, this);
22808 this.innerList.on('mousemove', this.onViewMove, this);
22809 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
22811 if(this.allowBlank && !this.pageSize && !this.disableClear){
22812 this.footer = this.list.createChild({cls:cls+'-ft'});
22813 this.pageTb = new Roo.Toolbar(this.footer);
22817 this.footer = this.list.createChild({cls:cls+'-ft'});
22818 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
22819 {pageSize: this.pageSize});
22823 if (this.pageTb && this.allowBlank && !this.disableClear) {
22825 this.pageTb.add(new Roo.Toolbar.Fill(), {
22826 cls: 'x-btn-icon x-btn-clear',
22828 handler: function()
22831 _this.clearValue();
22832 _this.onSelect(false, -1);
22837 this.assetHeight += this.footer.getHeight();
22842 this.tpl = '<div class="'+cls+'-item">{' + this.displayField + '}</div>';
22845 this.view = new Roo.View(this.innerList, this.tpl, {
22846 singleSelect:true, store: this.store, selectedClass: this.selectedClass
22849 this.view.on('click', this.onViewClick, this);
22851 this.store.on('beforeload', this.onBeforeLoad, this);
22852 this.store.on('load', this.onLoad, this);
22853 this.store.on('loadexception', this.collapse, this);
22855 if(this.resizable){
22856 this.resizer = new Roo.Resizable(this.list, {
22857 pinned:true, handles:'se'
22859 this.resizer.on('resize', function(r, w, h){
22860 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
22861 this.listWidth = w;
22862 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
22863 this.restrictHeight();
22865 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
22867 if(!this.editable){
22868 this.editable = true;
22869 this.setEditable(false);
22873 if (typeof(this.events.add.listeners) != 'undefined') {
22875 this.addicon = this.wrap.createChild(
22876 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-add' });
22878 this.addicon.on('click', function(e) {
22879 this.fireEvent('add', this);
22882 if (typeof(this.events.edit.listeners) != 'undefined') {
22884 this.editicon = this.wrap.createChild(
22885 {tag: 'img', src: Roo.BLANK_IMAGE_URL, cls: 'x-form-combo-edit' });
22886 if (this.addicon) {
22887 this.editicon.setStyle('margin-left', '40px');
22889 this.editicon.on('click', function(e) {
22891 // we fire even if inothing is selected..
22892 this.fireEvent('edit', this, this.lastData );
22902 initEvents : function(){
22903 Roo.form.ComboBox.superclass.initEvents.call(this);
22905 this.keyNav = new Roo.KeyNav(this.el, {
22906 "up" : function(e){
22907 this.inKeyMode = true;
22911 "down" : function(e){
22912 if(!this.isExpanded()){
22913 this.onTriggerClick();
22915 this.inKeyMode = true;
22920 "enter" : function(e){
22921 this.onViewClick();
22925 "esc" : function(e){
22929 "tab" : function(e){
22930 this.onViewClick(false);
22936 doRelay : function(foo, bar, hname){
22937 if(hname == 'down' || this.scope.isExpanded()){
22938 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
22945 this.queryDelay = Math.max(this.queryDelay || 10,
22946 this.mode == 'local' ? 10 : 250);
22947 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
22948 if(this.typeAhead){
22949 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
22951 if(this.editable !== false){
22952 this.el.on("keyup", this.onKeyUp, this);
22954 if(this.forceSelection){
22955 this.on('blur', this.doForce, this);
22959 onDestroy : function(){
22961 this.view.setStore(null);
22962 this.view.el.removeAllListeners();
22963 this.view.el.remove();
22964 this.view.purgeListeners();
22967 this.list.destroy();
22970 this.store.un('beforeload', this.onBeforeLoad, this);
22971 this.store.un('load', this.onLoad, this);
22972 this.store.un('loadexception', this.collapse, this);
22974 Roo.form.ComboBox.superclass.onDestroy.call(this);
22978 fireKey : function(e){
22979 if(e.isNavKeyPress() && !this.list.isVisible()){
22980 this.fireEvent("specialkey", this, e);
22985 onResize: function(w, h){
22986 Roo.form.ComboBox.superclass.onResize.apply(this, arguments);
22988 if(typeof w != 'number'){
22989 // we do not handle it!?!?
22992 var tw = this.trigger.getWidth();
22993 tw += this.addicon ? this.addicon.getWidth() : 0;
22994 tw += this.editicon ? this.editicon.getWidth() : 0;
22996 this.el.setWidth( this.adjustWidth('input', x));
22998 this.trigger.setStyle('left', x+'px');
23000 if(this.list && this.listWidth === undefined){
23001 var lw = Math.max(x + this.trigger.getWidth(), this.minListWidth);
23002 this.list.setWidth(lw);
23003 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
23011 * Allow or prevent the user from directly editing the field text. If false is passed,
23012 * the user will only be able to select from the items defined in the dropdown list. This method
23013 * is the runtime equivalent of setting the 'editable' config option at config time.
23014 * @param {Boolean} value True to allow the user to directly edit the field text
23016 setEditable : function(value){
23017 if(value == this.editable){
23020 this.editable = value;
23022 this.el.dom.setAttribute('readOnly', true);
23023 this.el.on('mousedown', this.onTriggerClick, this);
23024 this.el.addClass('x-combo-noedit');
23026 this.el.dom.setAttribute('readOnly', false);
23027 this.el.un('mousedown', this.onTriggerClick, this);
23028 this.el.removeClass('x-combo-noedit');
23033 onBeforeLoad : function(){
23034 if(!this.hasFocus){
23037 this.innerList.update(this.loadingText ?
23038 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
23039 this.restrictHeight();
23040 this.selectedIndex = -1;
23044 onLoad : function(){
23045 if(!this.hasFocus){
23048 if(this.store.getCount() > 0){
23050 this.restrictHeight();
23051 if(this.lastQuery == this.allQuery){
23053 this.el.dom.select();
23055 if(!this.selectByValue(this.value, true)){
23056 this.select(0, true);
23060 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
23061 this.taTask.delay(this.typeAheadDelay);
23065 this.onEmptyResults();
23071 onTypeAhead : function(){
23072 if(this.store.getCount() > 0){
23073 var r = this.store.getAt(0);
23074 var newValue = r.data[this.displayField];
23075 var len = newValue.length;
23076 var selStart = this.getRawValue().length;
23077 if(selStart != len){
23078 this.setRawValue(newValue);
23079 this.selectText(selStart, newValue.length);
23085 onSelect : function(record, index){
23086 if(this.fireEvent('beforeselect', this, record, index) !== false){
23087 this.setFromData(index > -1 ? record.data : false);
23089 this.fireEvent('select', this, record, index);
23094 * Returns the currently selected field value or empty string if no value is set.
23095 * @return {String} value The selected value
23097 getValue : function(){
23098 if(this.valueField){
23099 return typeof this.value != 'undefined' ? this.value : '';
23101 return Roo.form.ComboBox.superclass.getValue.call(this);
23106 * Clears any text/value currently set in the field
23108 clearValue : function(){
23109 if(this.hiddenField){
23110 this.hiddenField.value = '';
23113 this.setRawValue('');
23114 this.lastSelectionText = '';
23115 this.applyEmptyText();
23119 * Sets the specified value into the field. If the value finds a match, the corresponding record text
23120 * will be displayed in the field. If the value does not match the data value of an existing item,
23121 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
23122 * Otherwise the field will be blank (although the value will still be set).
23123 * @param {String} value The value to match
23125 setValue : function(v){
23127 if(this.valueField){
23128 var r = this.findRecord(this.valueField, v);
23130 text = r.data[this.displayField];
23131 }else if(this.valueNotFoundText !== undefined){
23132 text = this.valueNotFoundText;
23135 this.lastSelectionText = text;
23136 if(this.hiddenField){
23137 this.hiddenField.value = v;
23139 Roo.form.ComboBox.superclass.setValue.call(this, text);
23143 * @property {Object} the last set data for the element
23148 * Sets the value of the field based on a object which is related to the record format for the store.
23149 * @param {Object} value the value to set as. or false on reset?
23151 setFromData : function(o){
23152 var dv = ''; // display value
23153 var vv = ''; // value value..
23155 if (this.displayField) {
23156 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
23158 // this is an error condition!!!
23159 Roo.log('no displayField value set for '+ (this.name ? this.name : this.id));
23162 if(this.valueField){
23163 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
23165 if(this.hiddenField){
23166 this.hiddenField.value = vv;
23168 this.lastSelectionText = dv;
23169 Roo.form.ComboBox.superclass.setValue.call(this, dv);
23173 // no hidden field.. - we store the value in 'value', but still display
23174 // display field!!!!
23175 this.lastSelectionText = dv;
23176 Roo.form.ComboBox.superclass.setValue.call(this, dv);
23182 reset : function(){
23183 // overridden so that last data is reset..
23184 this.setValue(this.originalValue);
23185 this.clearInvalid();
23186 this.lastData = false;
23189 findRecord : function(prop, value){
23191 if(this.store.getCount() > 0){
23192 this.store.each(function(r){
23193 if(r.data[prop] == value){
23203 onViewMove : function(e, t){
23204 this.inKeyMode = false;
23208 onViewOver : function(e, t){
23209 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
23212 var item = this.view.findItemFromChild(t);
23214 var index = this.view.indexOf(item);
23215 this.select(index, false);
23220 onViewClick : function(doFocus){
23221 var index = this.view.getSelectedIndexes()[0];
23222 var r = this.store.getAt(index);
23224 this.onSelect(r, index);
23226 if(doFocus !== false && !this.blockFocus){
23232 restrictHeight : function(){
23233 this.innerList.dom.style.height = '';
23234 var inner = this.innerList.dom;
23235 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
23236 this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
23237 this.list.beginUpdate();
23238 this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
23239 this.list.alignTo(this.el, this.listAlign);
23240 this.list.endUpdate();
23244 onEmptyResults : function(){
23249 * Returns true if the dropdown list is expanded, else false.
23251 isExpanded : function(){
23252 return this.list.isVisible();
23256 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
23257 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
23258 * @param {String} value The data value of the item to select
23259 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
23260 * selected item if it is not currently in view (defaults to true)
23261 * @return {Boolean} True if the value matched an item in the list, else false
23263 selectByValue : function(v, scrollIntoView){
23264 if(v !== undefined && v !== null){
23265 var r = this.findRecord(this.valueField || this.displayField, v);
23267 this.select(this.store.indexOf(r), scrollIntoView);
23275 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
23276 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
23277 * @param {Number} index The zero-based index of the list item to select
23278 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
23279 * selected item if it is not currently in view (defaults to true)
23281 select : function(index, scrollIntoView){
23282 this.selectedIndex = index;
23283 this.view.select(index);
23284 if(scrollIntoView !== false){
23285 var el = this.view.getNode(index);
23287 this.innerList.scrollChildIntoView(el, false);
23293 selectNext : function(){
23294 var ct = this.store.getCount();
23296 if(this.selectedIndex == -1){
23298 }else if(this.selectedIndex < ct-1){
23299 this.select(this.selectedIndex+1);
23305 selectPrev : function(){
23306 var ct = this.store.getCount();
23308 if(this.selectedIndex == -1){
23310 }else if(this.selectedIndex != 0){
23311 this.select(this.selectedIndex-1);
23317 onKeyUp : function(e){
23318 if(this.editable !== false && !e.isSpecialKey()){
23319 this.lastKey = e.getKey();
23320 this.dqTask.delay(this.queryDelay);
23325 validateBlur : function(){
23326 return !this.list || !this.list.isVisible();
23330 initQuery : function(){
23331 this.doQuery(this.getRawValue());
23335 doForce : function(){
23336 if(this.el.dom.value.length > 0){
23337 this.el.dom.value =
23338 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
23339 this.applyEmptyText();
23344 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
23345 * query allowing the query action to be canceled if needed.
23346 * @param {String} query The SQL query to execute
23347 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
23348 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
23349 * saved in the current store (defaults to false)
23351 doQuery : function(q, forceAll){
23352 if(q === undefined || q === null){
23357 forceAll: forceAll,
23361 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
23365 forceAll = qe.forceAll;
23366 if(forceAll === true || (q.length >= this.minChars)){
23367 if(this.lastQuery != q || this.alwaysQuery){
23368 this.lastQuery = q;
23369 if(this.mode == 'local'){
23370 this.selectedIndex = -1;
23372 this.store.clearFilter();
23374 this.store.filter(this.displayField, q);
23378 this.store.baseParams[this.queryParam] = q;
23380 params: this.getParams(q)
23385 this.selectedIndex = -1;
23392 getParams : function(q){
23394 //p[this.queryParam] = q;
23397 p.limit = this.pageSize;
23403 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
23405 collapse : function(){
23406 if(!this.isExpanded()){
23410 Roo.get(document).un('mousedown', this.collapseIf, this);
23411 Roo.get(document).un('mousewheel', this.collapseIf, this);
23412 if (!this.editable) {
23413 Roo.get(document).un('keydown', this.listKeyPress, this);
23415 this.fireEvent('collapse', this);
23419 collapseIf : function(e){
23420 if(!e.within(this.wrap) && !e.within(this.list)){
23426 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
23428 expand : function(){
23429 if(this.isExpanded() || !this.hasFocus){
23432 this.list.alignTo(this.el, this.listAlign);
23434 Roo.get(document).on('mousedown', this.collapseIf, this);
23435 Roo.get(document).on('mousewheel', this.collapseIf, this);
23436 if (!this.editable) {
23437 Roo.get(document).on('keydown', this.listKeyPress, this);
23440 this.fireEvent('expand', this);
23444 // Implements the default empty TriggerField.onTriggerClick function
23445 onTriggerClick : function(){
23449 if(this.isExpanded()){
23451 if (!this.blockFocus) {
23456 this.hasFocus = true;
23457 if(this.triggerAction == 'all') {
23458 this.doQuery(this.allQuery, true);
23460 this.doQuery(this.getRawValue());
23462 if (!this.blockFocus) {
23467 listKeyPress : function(e)
23469 //Roo.log('listkeypress');
23470 // scroll to first matching element based on key pres..
23471 if (e.isSpecialKey()) {
23474 var k = String.fromCharCode(e.getKey()).toUpperCase();
23477 var csel = this.view.getSelectedNodes();
23478 var cselitem = false;
23480 var ix = this.view.indexOf(csel[0]);
23481 cselitem = this.store.getAt(ix);
23482 if (!cselitem.get(this.displayField) || cselitem.get(this.displayField).substring(0,1).toUpperCase() != k) {
23488 this.store.each(function(v) {
23490 // start at existing selection.
23491 if (cselitem.id == v.id) {
23497 if (v.get(this.displayField) && v.get(this.displayField).substring(0,1).toUpperCase() == k) {
23498 match = this.store.indexOf(v);
23503 if (match === false) {
23504 return true; // no more action?
23507 this.view.select(match);
23508 var sn = Roo.get(this.view.getSelectedNodes()[0])
23509 sn.scrollIntoView(sn.dom.parentNode, false);
23513 * @cfg {Boolean} grow
23517 * @cfg {Number} growMin
23521 * @cfg {Number} growMax
23530 * Ext JS Library 1.1.1
23531 * Copyright(c) 2006-2007, Ext JS, LLC.
23533 * Originally Released Under LGPL - original licence link has changed is not relivant.
23536 * <script type="text/javascript">
23539 * @class Roo.form.Checkbox
23540 * @extends Roo.form.Field
23541 * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
23543 * Creates a new Checkbox
23544 * @param {Object} config Configuration options
23546 Roo.form.Checkbox = function(config){
23547 Roo.form.Checkbox.superclass.constructor.call(this, config);
23551 * Fires when the checkbox is checked or unchecked.
23552 * @param {Roo.form.Checkbox} this This checkbox
23553 * @param {Boolean} checked The new checked value
23559 Roo.extend(Roo.form.Checkbox, Roo.form.Field, {
23561 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
23563 focusClass : undefined,
23565 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
23567 fieldClass: "x-form-field",
23569 * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
23573 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
23574 * {tag: "input", type: "checkbox", autocomplete: "off"})
23576 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "off"},
23578 * @cfg {String} boxLabel The text that appears beside the checkbox
23582 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
23586 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
23588 valueOff: '0', // value when not checked..
23590 actionMode : 'viewEl',
23593 itemCls : 'x-menu-check-item x-form-item',
23594 groupClass : 'x-menu-group-item',
23595 inputType : 'hidden',
23598 inSetChecked: false, // check that we are not calling self...
23600 inputElement: false, // real input element?
23601 basedOn: false, // ????
23603 isFormField: true, // not sure where this is needed!!!!
23605 onResize : function(){
23606 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
23607 if(!this.boxLabel){
23608 this.el.alignTo(this.wrap, 'c-c');
23612 initEvents : function(){
23613 Roo.form.Checkbox.superclass.initEvents.call(this);
23614 this.el.on("click", this.onClick, this);
23615 this.el.on("change", this.onClick, this);
23619 getResizeEl : function(){
23623 getPositionEl : function(){
23628 onRender : function(ct, position){
23629 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
23631 if(this.inputValue !== undefined){
23632 this.el.dom.value = this.inputValue;
23635 //this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
23636 this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
23637 var viewEl = this.wrap.createChild({
23638 tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
23639 this.viewEl = viewEl;
23640 this.wrap.on('click', this.onClick, this);
23642 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
23643 this.el.on('propertychange', this.setFromHidden, this); //ie
23648 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
23649 // viewEl.on('click', this.onClick, this);
23651 //if(this.checked){
23652 this.setChecked(this.checked);
23654 //this.checked = this.el.dom;
23660 initValue : Roo.emptyFn,
23663 * Returns the checked state of the checkbox.
23664 * @return {Boolean} True if checked, else false
23666 getValue : function(){
23668 return String(this.el.dom.value) == String(this.inputValue ) ? this.inputValue : this.valueOff;
23670 return this.valueOff;
23675 onClick : function(){
23676 this.setChecked(!this.checked);
23678 //if(this.el.dom.checked != this.checked){
23679 // this.setValue(this.el.dom.checked);
23684 * Sets the checked state of the checkbox.
23685 * On is always based on a string comparison between inputValue and the param.
23686 * @param {Boolean/String} value - the value to set
23687 * @param {Boolean/String} suppressEvent - whether to suppress the checkchange event.
23689 setValue : function(v,suppressEvent){
23692 //this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
23693 //if(this.el && this.el.dom){
23694 // this.el.dom.checked = this.checked;
23695 // this.el.dom.defaultChecked = this.checked;
23697 this.setChecked(String(v) === String(this.inputValue), suppressEvent);
23698 //this.fireEvent("check", this, this.checked);
23701 setChecked : function(state,suppressEvent)
23703 if (this.inSetChecked) {
23704 this.checked = state;
23710 this.wrap[state ? 'addClass' : 'removeClass']('x-menu-item-checked');
23712 this.checked = state;
23713 if(suppressEvent !== true){
23714 this.fireEvent('check', this, state);
23716 this.inSetChecked = true;
23717 this.el.dom.value = state ? this.inputValue : this.valueOff;
23718 this.inSetChecked = false;
23721 // handle setting of hidden value by some other method!!?!?
23722 setFromHidden: function()
23727 //console.log("SET FROM HIDDEN");
23728 //alert('setFrom hidden');
23729 this.setValue(this.el.dom.value);
23732 onDestroy : function()
23735 Roo.get(this.viewEl).remove();
23738 Roo.form.Checkbox.superclass.onDestroy.call(this);
23743 * Ext JS Library 1.1.1
23744 * Copyright(c) 2006-2007, Ext JS, LLC.
23746 * Originally Released Under LGPL - original licence link has changed is not relivant.
23749 * <script type="text/javascript">
23753 * @class Roo.form.Radio
23754 * @extends Roo.form.Checkbox
23755 * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type.
23756 * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
23758 * Creates a new Radio
23759 * @param {Object} config Configuration options
23761 Roo.form.Radio = function(){
23762 Roo.form.Radio.superclass.constructor.apply(this, arguments);
23764 Roo.extend(Roo.form.Radio, Roo.form.Checkbox, {
23765 inputType: 'radio',
23768 * If this radio is part of a group, it will return the selected value
23771 getGroupValue : function(){
23772 return this.el.up('form').child('input[name='+this.el.dom.name+']:checked', true).value;
23774 });//<script type="text/javascript">
23777 * Ext JS Library 1.1.1
23778 * Copyright(c) 2006-2007, Ext JS, LLC.
23779 * licensing@extjs.com
23781 * http://www.extjs.com/license
23787 * Default CSS appears to render it as fixed text by default (should really be Sans-Serif)
23788 * - IE ? - no idea how much works there.
23796 * @class Ext.form.HtmlEditor
23797 * @extends Ext.form.Field
23798 * Provides a lightweight HTML Editor component.
23799 * WARNING - THIS CURRENTlY ONLY WORKS ON FIREFOX - USE FCKeditor for a cross platform version
23801 * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
23802 * supported by this editor.</b><br/><br/>
23803 * An Editor is a sensitive component that can't be used in all spots standard fields can be used. Putting an Editor within
23804 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
23806 Roo.form.HtmlEditor = Roo.extend(Roo.form.Field, {
23808 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
23812 * @cfg {String} createLinkText The default text for the create link prompt
23814 createLinkText : 'Please enter the URL for the link:',
23816 * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
23818 defaultLinkValue : 'http:/'+'/',
23824 // private properties
23825 validationEvent : false,
23827 initialized : false,
23829 sourceEditMode : false,
23830 onFocus : Roo.emptyFn,
23832 hideMode:'offsets',
23833 defaultAutoCreate : {
23835 style:"width:500px;height:300px;",
23836 autocomplete: "off"
23840 initComponent : function(){
23843 * @event initialize
23844 * Fires when the editor is fully initialized (including the iframe)
23845 * @param {HtmlEditor} this
23850 * Fires when the editor is first receives the focus. Any insertion must wait
23851 * until after this event.
23852 * @param {HtmlEditor} this
23856 * @event beforesync
23857 * Fires before the textarea is updated with content from the editor iframe. Return false
23858 * to cancel the sync.
23859 * @param {HtmlEditor} this
23860 * @param {String} html
23864 * @event beforepush
23865 * Fires before the iframe editor is updated with content from the textarea. Return false
23866 * to cancel the push.
23867 * @param {HtmlEditor} this
23868 * @param {String} html
23873 * Fires when the textarea is updated with content from the editor iframe.
23874 * @param {HtmlEditor} this
23875 * @param {String} html
23880 * Fires when the iframe editor is updated with content from the textarea.
23881 * @param {HtmlEditor} this
23882 * @param {String} html
23886 * @event editmodechange
23887 * Fires when the editor switches edit modes
23888 * @param {HtmlEditor} this
23889 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
23891 editmodechange: true,
23893 * @event editorevent
23894 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
23895 * @param {HtmlEditor} this
23902 * Protected method that will not generally be called directly. It
23903 * is called when the editor creates its toolbar. Override this method if you need to
23904 * add custom toolbar buttons.
23905 * @param {HtmlEditor} editor
23907 createToolbar : function(editor){
23908 if (!editor.toolbars || !editor.toolbars.length) {
23909 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
23912 for (var i =0 ; i < editor.toolbars.length;i++) {
23913 editor.toolbars[i] = Roo.factory(editor.toolbars[i], Roo.form.HtmlEditor);
23914 editor.toolbars[i].init(editor);
23921 * Protected method that will not generally be called directly. It
23922 * is called when the editor initializes the iframe with HTML contents. Override this method if you
23923 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
23925 getDocMarkup : function(){
23926 return '<html><head><style type="text/css">body{border:0;margin:0;padding:3px;height:98%;cursor:text;}</style></head><body></body></html>';
23930 onRender : function(ct, position){
23931 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
23932 this.el.dom.style.border = '0 none';
23933 this.el.dom.setAttribute('tabIndex', -1);
23934 this.el.addClass('x-hidden');
23935 if(Roo.isIE){ // fix IE 1px bogus margin
23936 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
23938 this.wrap = this.el.wrap({
23939 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
23942 this.frameId = Roo.id();
23943 this.createToolbar(this);
23950 var iframe = this.wrap.createChild({
23953 name: this.frameId,
23954 frameBorder : 'no',
23955 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
23958 // console.log(iframe);
23959 //this.wrap.dom.appendChild(iframe);
23961 this.iframe = iframe.dom;
23963 this.assignDocWin();
23965 this.doc.designMode = 'on';
23968 this.doc.write(this.getDocMarkup());
23972 var task = { // must defer to wait for browser to be ready
23974 //console.log("run task?" + this.doc.readyState);
23975 this.assignDocWin();
23976 if(this.doc.body || this.doc.readyState == 'complete'){
23978 this.doc.designMode="on";
23982 Roo.TaskMgr.stop(task);
23983 this.initEditor.defer(10, this);
23990 Roo.TaskMgr.start(task);
23993 this.setSize(this.el.getSize());
23998 onResize : function(w, h){
23999 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
24000 if(this.el && this.iframe){
24001 if(typeof w == 'number'){
24002 var aw = w - this.wrap.getFrameWidth('lr');
24003 this.el.setWidth(this.adjustWidth('textarea', aw));
24004 this.iframe.style.width = aw + 'px';
24006 if(typeof h == 'number'){
24008 for (var i =0; i < this.toolbars.length;i++) {
24009 // fixme - ask toolbars for heights?
24010 tbh += this.toolbars[i].tb.el.getHeight();
24016 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
24017 this.el.setHeight(this.adjustWidth('textarea', ah));
24018 this.iframe.style.height = ah + 'px';
24020 (this.doc.body || this.doc.documentElement).style.height = (ah - (this.iframePad*2)) + 'px';
24027 * Toggles the editor between standard and source edit mode.
24028 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
24030 toggleSourceEdit : function(sourceEditMode){
24032 this.sourceEditMode = sourceEditMode === true;
24034 if(this.sourceEditMode){
24037 this.iframe.className = 'x-hidden';
24038 this.el.removeClass('x-hidden');
24039 this.el.dom.removeAttribute('tabIndex');
24044 this.iframe.className = '';
24045 this.el.addClass('x-hidden');
24046 this.el.dom.setAttribute('tabIndex', -1);
24049 this.setSize(this.wrap.getSize());
24050 this.fireEvent('editmodechange', this, this.sourceEditMode);
24053 // private used internally
24054 createLink : function(){
24055 var url = prompt(this.createLinkText, this.defaultLinkValue);
24056 if(url && url != 'http:/'+'/'){
24057 this.relayCmd('createlink', url);
24061 // private (for BoxComponent)
24062 adjustSize : Roo.BoxComponent.prototype.adjustSize,
24064 // private (for BoxComponent)
24065 getResizeEl : function(){
24069 // private (for BoxComponent)
24070 getPositionEl : function(){
24075 initEvents : function(){
24076 this.originalValue = this.getValue();
24080 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
24083 markInvalid : Roo.emptyFn,
24085 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
24088 clearInvalid : Roo.emptyFn,
24090 setValue : function(v){
24091 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
24096 * Protected method that will not generally be called directly. If you need/want
24097 * custom HTML cleanup, this is the method you should override.
24098 * @param {String} html The HTML to be cleaned
24099 * return {String} The cleaned HTML
24101 cleanHtml : function(html){
24102 html = String(html);
24103 if(html.length > 5){
24104 if(Roo.isSafari){ // strip safari nonsense
24105 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
24108 if(html == ' '){
24115 * Protected method that will not generally be called directly. Syncs the contents
24116 * of the editor iframe with the textarea.
24118 syncValue : function(){
24119 if(this.initialized){
24120 var bd = (this.doc.body || this.doc.documentElement);
24121 var html = bd.innerHTML;
24123 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
24124 var m = bs.match(/text-align:(.*?);/i);
24126 html = '<div style="'+m[0]+'">' + html + '</div>';
24129 html = this.cleanHtml(html);
24130 if(this.fireEvent('beforesync', this, html) !== false){
24131 this.el.dom.value = html;
24132 this.fireEvent('sync', this, html);
24138 * Protected method that will not generally be called directly. Pushes the value of the textarea
24139 * into the iframe editor.
24141 pushValue : function(){
24142 if(this.initialized){
24143 var v = this.el.dom.value;
24147 if(this.fireEvent('beforepush', this, v) !== false){
24148 (this.doc.body || this.doc.documentElement).innerHTML = v;
24149 this.fireEvent('push', this, v);
24155 deferFocus : function(){
24156 this.focus.defer(10, this);
24160 focus : function(){
24161 if(this.win && !this.sourceEditMode){
24168 assignDocWin: function()
24170 var iframe = this.iframe;
24173 this.doc = iframe.contentWindow.document;
24174 this.win = iframe.contentWindow;
24176 if (!Roo.get(this.frameId)) {
24179 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
24180 this.win = Roo.get(this.frameId).dom.contentWindow;
24185 initEditor : function(){
24186 //console.log("INIT EDITOR");
24187 this.assignDocWin();
24191 this.doc.designMode="on";
24193 this.doc.write(this.getDocMarkup());
24196 var dbody = (this.doc.body || this.doc.documentElement);
24197 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
24198 // this copies styles from the containing element into thsi one..
24199 // not sure why we need all of this..
24200 var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
24201 ss['background-attachment'] = 'fixed'; // w3c
24202 dbody.bgProperties = 'fixed'; // ie
24203 Roo.DomHelper.applyStyles(dbody, ss);
24204 Roo.EventManager.on(this.doc, {
24205 'mousedown': this.onEditorEvent,
24206 'dblclick': this.onEditorEvent,
24207 'click': this.onEditorEvent,
24208 'keyup': this.onEditorEvent,
24213 Roo.EventManager.on(this.doc, 'keypress', this.mozKeyPress, this);
24215 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
24216 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
24218 this.initialized = true;
24220 this.fireEvent('initialize', this);
24225 onDestroy : function(){
24231 for (var i =0; i < this.toolbars.length;i++) {
24232 // fixme - ask toolbars for heights?
24233 this.toolbars[i].onDestroy();
24236 this.wrap.dom.innerHTML = '';
24237 this.wrap.remove();
24242 onFirstFocus : function(){
24244 this.assignDocWin();
24247 this.activated = true;
24248 for (var i =0; i < this.toolbars.length;i++) {
24249 this.toolbars[i].onFirstFocus();
24252 if(Roo.isGecko){ // prevent silly gecko errors
24254 var s = this.win.getSelection();
24255 if(!s.focusNode || s.focusNode.nodeType != 3){
24256 var r = s.getRangeAt(0);
24257 r.selectNodeContents((this.doc.body || this.doc.documentElement));
24262 this.execCmd('useCSS', true);
24263 this.execCmd('styleWithCSS', false);
24266 this.fireEvent('activate', this);
24270 adjustFont: function(btn){
24271 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
24272 //if(Roo.isSafari){ // safari
24275 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
24276 if(Roo.isSafari){ // safari
24277 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
24278 v = (v < 10) ? 10 : v;
24279 v = (v > 48) ? 48 : v;
24280 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
24285 v = Math.max(1, v+adjust);
24287 this.execCmd('FontSize', v );
24290 onEditorEvent : function(e){
24291 this.fireEvent('editorevent', this, e);
24292 // this.updateToolbar();
24296 insertTag : function(tg)
24298 // could be a bit smarter... -> wrap the current selected tRoo..
24300 this.execCmd("formatblock", tg);
24304 insertText : function(txt)
24308 range = this.createRange();
24309 range.deleteContents();
24310 //alert(Sender.getAttribute('label'));
24312 range.insertNode(this.doc.createTextNode(txt));
24316 relayBtnCmd : function(btn){
24317 this.relayCmd(btn.cmd);
24321 * Executes a Midas editor command on the editor document and performs necessary focus and
24322 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
24323 * @param {String} cmd The Midas command
24324 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
24326 relayCmd : function(cmd, value){
24328 this.execCmd(cmd, value);
24329 this.fireEvent('editorevent', this);
24330 //this.updateToolbar();
24335 * Executes a Midas editor command directly on the editor document.
24336 * For visual commands, you should use {@link #relayCmd} instead.
24337 * <b>This should only be called after the editor is initialized.</b>
24338 * @param {String} cmd The Midas command
24339 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
24341 execCmd : function(cmd, value){
24342 this.doc.execCommand(cmd, false, value === undefined ? null : value);
24348 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
24350 * @param {String} text
24352 insertAtCursor : function(text){
24353 if(!this.activated){
24358 var r = this.doc.selection.createRange();
24365 }else if(Roo.isGecko || Roo.isOpera || Roo.isSafari){
24367 this.execCmd('InsertHTML', text);
24372 mozKeyPress : function(e){
24374 var c = e.getCharCode(), cmd;
24377 c = String.fromCharCode(c).toLowerCase();
24388 this.cleanUpPaste.defer(100, this);
24396 e.preventDefault();
24404 fixKeys : function(){ // load time branching for fastest keydown performance
24406 return function(e){
24407 var k = e.getKey(), r;
24410 r = this.doc.selection.createRange();
24413 r.pasteHTML('    ');
24420 r = this.doc.selection.createRange();
24422 var target = r.parentElement();
24423 if(!target || target.tagName.toLowerCase() != 'li'){
24425 r.pasteHTML('<br />');
24431 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
24432 this.cleanUpPaste.defer(100, this);
24438 }else if(Roo.isOpera){
24439 return function(e){
24440 var k = e.getKey();
24444 this.execCmd('InsertHTML','    ');
24447 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
24448 this.cleanUpPaste.defer(100, this);
24453 }else if(Roo.isSafari){
24454 return function(e){
24455 var k = e.getKey();
24459 this.execCmd('InsertText','\t');
24463 if (String.fromCharCode(k).toLowerCase() == 'v') { // paste
24464 this.cleanUpPaste.defer(100, this);
24472 getAllAncestors: function()
24474 var p = this.getSelectedNode();
24477 a.push(p); // push blank onto stack..
24478 p = this.getParentElement();
24482 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
24486 a.push(this.doc.body);
24490 lastSelNode : false,
24493 getSelection : function()
24495 this.assignDocWin();
24496 return Roo.isIE ? this.doc.selection : this.win.getSelection();
24499 getSelectedNode: function()
24501 // this may only work on Gecko!!!
24503 // should we cache this!!!!
24508 var range = this.createRange(this.getSelection());
24511 var parent = range.parentElement();
24513 var testRange = range.duplicate();
24514 testRange.moveToElementText(parent);
24515 if (testRange.inRange(range)) {
24518 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
24521 parent = parent.parentElement;
24527 var ar = range.endContainer.childNodes;
24529 ar = range.commonAncestorContainer.childNodes;
24530 //alert(ar.length);
24533 var other_nodes = [];
24534 var has_other_nodes = false;
24535 for (var i=0;i<ar.length;i++) {
24536 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
24539 // fullly contained node.
24541 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
24546 // probably selected..
24547 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
24548 other_nodes.push(ar[i]);
24551 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
24556 has_other_nodes = true;
24558 if (!nodes.length && other_nodes.length) {
24559 nodes= other_nodes;
24561 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
24567 createRange: function(sel)
24569 // this has strange effects when using with
24570 // top toolbar - not sure if it's a great idea.
24571 //this.editor.contentWindow.focus();
24572 if (typeof sel != "undefined") {
24574 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
24576 return this.doc.createRange();
24579 return this.doc.createRange();
24582 getParentElement: function()
24585 this.assignDocWin();
24586 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
24588 var range = this.createRange(sel);
24591 var p = range.commonAncestorContainer;
24592 while (p.nodeType == 3) { // text node
24604 // BC Hacks - cause I cant work out what i was trying to do..
24605 rangeIntersectsNode : function(range, node)
24607 var nodeRange = node.ownerDocument.createRange();
24609 nodeRange.selectNode(node);
24612 nodeRange.selectNodeContents(node);
24615 return range.compareBoundaryPoints(Range.END_TO_START, nodeRange) == -1 &&
24616 range.compareBoundaryPoints(Range.START_TO_END, nodeRange) == 1;
24618 rangeCompareNode : function(range, node) {
24619 var nodeRange = node.ownerDocument.createRange();
24621 nodeRange.selectNode(node);
24623 nodeRange.selectNodeContents(node);
24625 var nodeIsBefore = range.compareBoundaryPoints(Range.START_TO_START, nodeRange) == 1;
24626 var nodeIsAfter = range.compareBoundaryPoints(Range.END_TO_END, nodeRange) == -1;
24628 if (nodeIsBefore && !nodeIsAfter)
24630 if (!nodeIsBefore && nodeIsAfter)
24632 if (nodeIsBefore && nodeIsAfter)
24638 // private? - in a new class?
24639 cleanUpPaste : function()
24641 // cleans up the whole document..
24642 // console.log('cleanuppaste');
24643 this.cleanUpChildren(this.doc.body)
24647 cleanUpChildren : function (n)
24649 if (!n.childNodes.length) {
24652 for (var i = n.childNodes.length-1; i > -1 ; i--) {
24653 this.cleanUpChild(n.childNodes[i]);
24660 cleanUpChild : function (node)
24662 //console.log(node);
24663 if (node.nodeName == "#text") {
24664 // clean up silly Windows -- stuff?
24667 if (node.nodeName == "#comment") {
24668 node.parentNode.removeChild(node);
24669 // clean up silly Windows -- stuff?
24673 if (Roo.form.HtmlEditor.black.indexOf(node.tagName.toLowerCase()) > -1) {
24675 node.parentNode.removeChild(node);
24679 if (!node.attributes || !node.attributes.length) {
24680 this.cleanUpChildren(node);
24684 function cleanAttr(n,v)
24687 if (v.match(/^\./) || v.match(/^\//)) {
24690 if (v.match(/^(http|https):\/\//) || v.match(/^mailto:/)) {
24693 Roo.log("(REMOVE)"+ node.tagName +'.' + n + '=' + v);
24694 node.removeAttribute(n);
24698 function cleanStyle(n,v)
24700 if (v.match(/expression/)) { //XSS?? should we even bother..
24701 node.removeAttribute(n);
24706 var parts = v.split(/;/);
24707 Roo.each(parts, function(p) {
24708 p = p.replace(/\s+/g,'');
24712 var l = p.split(':').shift().replace(/\s+/g,'');
24714 if (Roo.form.HtmlEditor.cwhite.indexOf(l) < 0) {
24715 Roo.log('(REMOVE)' + node.tagName +'.' + n + ':'+l + '=' + v);
24716 node.removeAttribute(n);
24725 for (var i = node.attributes.length-1; i > -1 ; i--) {
24726 var a = node.attributes[i];
24728 if (Roo.form.HtmlEditor.ablack.indexOf(a.name.toLowerCase()) > -1) {
24729 node.removeAttribute(a.name);
24732 if (Roo.form.HtmlEditor.aclean.indexOf(a.name.toLowerCase()) > -1) {
24733 cleanAttr(a.name,a.value); // fixme..
24736 if (a.name == 'style') {
24737 cleanStyle(a.name,a.value);
24739 /// clean up MS crap..
24740 if (a.name == 'class') {
24741 if (a.value.match(/^Mso/)) {
24742 node.className = '';
24752 this.cleanUpChildren(node);
24758 // hide stuff that is not compatible
24772 * @event specialkey
24776 * @cfg {String} fieldClass @hide
24779 * @cfg {String} focusClass @hide
24782 * @cfg {String} autoCreate @hide
24785 * @cfg {String} inputType @hide
24788 * @cfg {String} invalidClass @hide
24791 * @cfg {String} invalidText @hide
24794 * @cfg {String} msgFx @hide
24797 * @cfg {String} validateOnBlur @hide
24801 Roo.form.HtmlEditor.white = [
24802 'area', 'br', 'img', 'input', 'hr', 'wbr',
24804 'address', 'blockquote', 'center', 'dd', 'dir', 'div',
24805 'dl', 'dt', 'h1', 'h2', 'h3', 'h4',
24806 'h5', 'h6', 'hr', 'isindex', 'listing', 'marquee',
24807 'menu', 'multicol', 'ol', 'p', 'plaintext', 'pre',
24808 'table', 'ul', 'xmp',
24810 'caption', 'col', 'colgroup', 'tbody', 'td', 'tfoot', 'th',
24813 'dir', 'menu', 'ol', 'ul', 'dl',
24819 Roo.form.HtmlEditor.black = [
24820 // 'embed', 'object', // enable - backend responsiblity to clean thiese
24822 'base', 'basefont', 'bgsound', 'blink', 'body',
24823 'frame', 'frameset', 'head', 'html', 'ilayer',
24824 'iframe', 'layer', 'link', 'meta', 'object',
24825 'script', 'style' ,'title', 'xml' // clean later..
24827 Roo.form.HtmlEditor.clean = [
24828 'script', 'style', 'title', 'xml'
24833 Roo.form.HtmlEditor.ablack = [
24837 Roo.form.HtmlEditor.aclean = [
24838 'action', 'background', 'codebase', 'dynsrc', 'href', 'lowsrc'
24842 Roo.form.HtmlEditor.pwhite= [
24843 'http', 'https', 'mailto'
24846 Roo.form.HtmlEditor.cwhite= [
24851 // <script type="text/javascript">
24854 * Ext JS Library 1.1.1
24855 * Copyright(c) 2006-2007, Ext JS, LLC.
24861 * @class Roo.form.HtmlEditorToolbar1
24866 new Roo.form.HtmlEditor({
24869 new Roo.form.HtmlEditorToolbar1({
24870 disable : { fonts: 1 , format: 1, ..., ... , ...],
24876 * @cfg {Object} disable List of elements to disable..
24877 * @cfg {Array} btns List of additional buttons.
24881 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
24884 Roo.form.HtmlEditor.ToolbarStandard = function(config)
24887 Roo.apply(this, config);
24888 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
24889 // dont call parent... till later.
24892 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype, {
24900 * @cfg {Object} disable List of toolbar elements to disable
24905 * @cfg {Array} fontFamilies An array of available font families
24923 // "á" , ?? a acute?
24928 "°" // , // degrees
24930 // "é" , // e ecute
24931 // "ú" , // u ecute?
24934 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
24935 "input:submit", "input:button", "select", "textarea", "label" ],
24938 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
24940 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"]
24943 * @cfg {String} defaultFont default font to use.
24945 defaultFont: 'tahoma',
24947 fontSelect : false,
24950 formatCombo : false,
24952 init : function(editor)
24954 this.editor = editor;
24957 var fid = editor.frameId;
24959 function btn(id, toggle, handler){
24960 var xid = fid + '-'+ id ;
24964 cls : 'x-btn-icon x-edit-'+id,
24965 enableToggle:toggle !== false,
24966 scope: editor, // was editor...
24967 handler:handler||editor.relayBtnCmd,
24968 clickEvent:'mousedown',
24969 tooltip: etb.buttonTips[id] || undefined, ///tips ???
24976 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
24978 // stop form submits
24979 tb.el.on('click', function(e){
24980 e.preventDefault(); // what does this do?
24983 if(!this.disable.font && !Roo.isSafari){
24984 /* why no safari for fonts
24985 editor.fontSelect = tb.el.createChild({
24988 cls:'x-font-select',
24989 html: editor.createFontOptions()
24991 editor.fontSelect.on('change', function(){
24992 var font = editor.fontSelect.dom.value;
24993 editor.relayCmd('fontname', font);
24994 editor.deferFocus();
24997 editor.fontSelect.dom,
25002 if(!this.disable.formats){
25003 this.formatCombo = new Roo.form.ComboBox({
25004 store: new Roo.data.SimpleStore({
25007 data : this.formats // from states.js
25010 //autoCreate : {tag: "div", size: "20"},
25011 displayField:'tag',
25015 triggerAction: 'all',
25016 emptyText:'Add tag',
25017 selectOnFocus:true,
25020 'select': function(c, r, i) {
25021 editor.insertTag(r.get('tag'));
25027 tb.addField(this.formatCombo);
25031 if(!this.disable.format){
25038 if(!this.disable.fontSize){
25043 btn('increasefontsize', false, editor.adjustFont),
25044 btn('decreasefontsize', false, editor.adjustFont)
25049 if(this.disable.colors){
25052 id:editor.frameId +'-forecolor',
25053 cls:'x-btn-icon x-edit-forecolor',
25054 clickEvent:'mousedown',
25055 tooltip: this.buttonTips['forecolor'] || undefined,
25057 menu : new Roo.menu.ColorMenu({
25058 allowReselect: true,
25059 focus: Roo.emptyFn,
25062 selectHandler: function(cp, color){
25063 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
25064 editor.deferFocus();
25067 clickEvent:'mousedown'
25070 id:editor.frameId +'backcolor',
25071 cls:'x-btn-icon x-edit-backcolor',
25072 clickEvent:'mousedown',
25073 tooltip: this.buttonTips['backcolor'] || undefined,
25075 menu : new Roo.menu.ColorMenu({
25076 focus: Roo.emptyFn,
25079 allowReselect: true,
25080 selectHandler: function(cp, color){
25082 editor.execCmd('useCSS', false);
25083 editor.execCmd('hilitecolor', color);
25084 editor.execCmd('useCSS', true);
25085 editor.deferFocus();
25087 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
25088 Roo.isSafari || Roo.isIE ? '#'+color : color);
25089 editor.deferFocus();
25093 clickEvent:'mousedown'
25098 // now add all the items...
25101 if(!this.disable.alignments){
25104 btn('justifyleft'),
25105 btn('justifycenter'),
25106 btn('justifyright')
25110 //if(!Roo.isSafari){
25111 if(!this.disable.links){
25114 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
25118 if(!this.disable.lists){
25121 btn('insertorderedlist'),
25122 btn('insertunorderedlist')
25125 if(!this.disable.sourceEdit){
25128 btn('sourceedit', true, function(btn){
25129 this.toggleSourceEdit(btn.pressed);
25136 // special menu.. - needs to be tidied up..
25137 if (!this.disable.special) {
25140 cls: 'x-edit-none',
25145 for (var i =0; i < this.specialChars.length; i++) {
25146 smenu.menu.items.push({
25148 html: this.specialChars[i],
25149 handler: function(a,b) {
25150 editor.insertAtCursor(String.fromCharCode(a.html.replace('&#','').replace(';', '')));
25163 for(var i =0; i< this.btns.length;i++) {
25164 var b = this.btns[i];
25165 b.cls = 'x-edit-none';
25174 // disable everything...
25176 this.tb.items.each(function(item){
25177 if(item.id != editor.frameId+ '-sourceedit'){
25181 this.rendered = true;
25183 // the all the btns;
25184 editor.on('editorevent', this.updateToolbar, this);
25185 // other toolbars need to implement this..
25186 //editor.on('editmodechange', this.updateToolbar, this);
25192 * Protected method that will not generally be called directly. It triggers
25193 * a toolbar update by reading the markup state of the current selection in the editor.
25195 updateToolbar: function(){
25197 if(!this.editor.activated){
25198 this.editor.onFirstFocus();
25202 var btns = this.tb.items.map,
25203 doc = this.editor.doc,
25204 frameId = this.editor.frameId;
25206 if(!this.disable.font && !Roo.isSafari){
25208 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
25209 if(name != this.fontSelect.dom.value){
25210 this.fontSelect.dom.value = name;
25214 if(!this.disable.format){
25215 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
25216 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
25217 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
25219 if(!this.disable.alignments){
25220 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
25221 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
25222 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
25224 if(!Roo.isSafari && !this.disable.lists){
25225 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
25226 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
25229 var ans = this.editor.getAllAncestors();
25230 if (this.formatCombo) {
25233 var store = this.formatCombo.store;
25234 this.formatCombo.setValue("");
25235 for (var i =0; i < ans.length;i++) {
25236 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), false).length) {
25238 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
25246 // hides menus... - so this cant be on a menu...
25247 Roo.menu.MenuMgr.hideAll();
25249 //this.editorsyncValue();
25253 createFontOptions : function(){
25254 var buf = [], fs = this.fontFamilies, ff, lc;
25255 for(var i = 0, len = fs.length; i< len; i++){
25257 lc = ff.toLowerCase();
25259 '<option value="',lc,'" style="font-family:',ff,';"',
25260 (this.defaultFont == lc ? ' selected="true">' : '>'),
25265 return buf.join('');
25268 toggleSourceEdit : function(sourceEditMode){
25269 if(sourceEditMode === undefined){
25270 sourceEditMode = !this.sourceEditMode;
25272 this.sourceEditMode = sourceEditMode === true;
25273 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
25274 // just toggle the button?
25275 if(btn.pressed !== this.editor.sourceEditMode){
25276 btn.toggle(this.editor.sourceEditMode);
25280 if(this.sourceEditMode){
25281 this.tb.items.each(function(item){
25282 if(item.cmd != 'sourceedit'){
25288 if(this.initialized){
25289 this.tb.items.each(function(item){
25295 // tell the editor that it's been pressed..
25296 this.editor.toggleSourceEdit(sourceEditMode);
25300 * Object collection of toolbar tooltips for the buttons in the editor. The key
25301 * is the command id associated with that button and the value is a valid QuickTips object.
25306 title: 'Bold (Ctrl+B)',
25307 text: 'Make the selected text bold.',
25308 cls: 'x-html-editor-tip'
25311 title: 'Italic (Ctrl+I)',
25312 text: 'Make the selected text italic.',
25313 cls: 'x-html-editor-tip'
25321 title: 'Bold (Ctrl+B)',
25322 text: 'Make the selected text bold.',
25323 cls: 'x-html-editor-tip'
25326 title: 'Italic (Ctrl+I)',
25327 text: 'Make the selected text italic.',
25328 cls: 'x-html-editor-tip'
25331 title: 'Underline (Ctrl+U)',
25332 text: 'Underline the selected text.',
25333 cls: 'x-html-editor-tip'
25335 increasefontsize : {
25336 title: 'Grow Text',
25337 text: 'Increase the font size.',
25338 cls: 'x-html-editor-tip'
25340 decreasefontsize : {
25341 title: 'Shrink Text',
25342 text: 'Decrease the font size.',
25343 cls: 'x-html-editor-tip'
25346 title: 'Text Highlight Color',
25347 text: 'Change the background color of the selected text.',
25348 cls: 'x-html-editor-tip'
25351 title: 'Font Color',
25352 text: 'Change the color of the selected text.',
25353 cls: 'x-html-editor-tip'
25356 title: 'Align Text Left',
25357 text: 'Align text to the left.',
25358 cls: 'x-html-editor-tip'
25361 title: 'Center Text',
25362 text: 'Center text in the editor.',
25363 cls: 'x-html-editor-tip'
25366 title: 'Align Text Right',
25367 text: 'Align text to the right.',
25368 cls: 'x-html-editor-tip'
25370 insertunorderedlist : {
25371 title: 'Bullet List',
25372 text: 'Start a bulleted list.',
25373 cls: 'x-html-editor-tip'
25375 insertorderedlist : {
25376 title: 'Numbered List',
25377 text: 'Start a numbered list.',
25378 cls: 'x-html-editor-tip'
25381 title: 'Hyperlink',
25382 text: 'Make the selected text a hyperlink.',
25383 cls: 'x-html-editor-tip'
25386 title: 'Source Edit',
25387 text: 'Switch to source editing mode.',
25388 cls: 'x-html-editor-tip'
25392 onDestroy : function(){
25395 this.tb.items.each(function(item){
25397 item.menu.removeAll();
25399 item.menu.el.destroy();
25407 onFirstFocus: function() {
25408 this.tb.items.each(function(item){
25417 // <script type="text/javascript">
25420 * Ext JS Library 1.1.1
25421 * Copyright(c) 2006-2007, Ext JS, LLC.
25428 * @class Roo.form.HtmlEditor.ToolbarContext
25433 new Roo.form.HtmlEditor({
25436 new Roo.form.HtmlEditor.ToolbarStandard(),
25437 new Roo.form.HtmlEditor.ToolbarContext()
25442 * @config : {Object} disable List of elements to disable.. (not done yet.)
25447 Roo.form.HtmlEditor.ToolbarContext = function(config)
25450 Roo.apply(this, config);
25451 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
25452 // dont call parent... till later.
25454 Roo.form.HtmlEditor.ToolbarContext.types = {
25466 opts : [ [""],[ "left"],[ "right"],[ "center"],[ "top"]],
25528 opts : [[""],[ "left"],[ "center"],[ "right"],[ "justify"],[ "char"]],
25533 opts : [[""],[ "top"],[ "middle"],[ "bottom"],[ "baseline"]],
25597 Roo.apply(Roo.form.HtmlEditor.ToolbarContext.prototype, {
25605 * @cfg {Object} disable List of toolbar elements to disable
25614 init : function(editor)
25616 this.editor = editor;
25619 var fid = editor.frameId;
25621 function btn(id, toggle, handler){
25622 var xid = fid + '-'+ id ;
25626 cls : 'x-btn-icon x-edit-'+id,
25627 enableToggle:toggle !== false,
25628 scope: editor, // was editor...
25629 handler:handler||editor.relayBtnCmd,
25630 clickEvent:'mousedown',
25631 tooltip: etb.buttonTips[id] || undefined, ///tips ???
25635 // create a new element.
25636 var wdiv = editor.wrap.createChild({
25638 }, editor.wrap.dom.firstChild.nextSibling, true);
25640 // can we do this more than once??
25642 // stop form submits
25645 // disable everything...
25646 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
25647 this.toolbars = {};
25649 for (var i in ty) {
25651 this.toolbars[i] = this.buildToolbar(ty[i],i);
25653 this.tb = this.toolbars.BODY;
25657 this.rendered = true;
25659 // the all the btns;
25660 editor.on('editorevent', this.updateToolbar, this);
25661 // other toolbars need to implement this..
25662 //editor.on('editmodechange', this.updateToolbar, this);
25668 * Protected method that will not generally be called directly. It triggers
25669 * a toolbar update by reading the markup state of the current selection in the editor.
25671 updateToolbar: function(){
25673 if(!this.editor.activated){
25674 this.editor.onFirstFocus();
25679 var ans = this.editor.getAllAncestors();
25682 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
25683 var sel = ans.length ? (ans[0] ? ans[0] : ans[1]) : this.editor.doc.body;
25684 sel = sel ? sel : this.editor.doc.body;
25685 sel = sel.tagName.length ? sel : this.editor.doc.body;
25686 var tn = sel.tagName.toUpperCase();
25687 sel = typeof(ty[tn]) != 'undefined' ? sel : this.editor.doc.body;
25688 tn = sel.tagName.toUpperCase();
25689 if (this.tb.name == tn) {
25690 return; // no change
25693 ///console.log("show: " + tn);
25694 this.tb = this.toolbars[tn];
25696 this.tb.fields.each(function(e) {
25697 e.setValue(sel.getAttribute(e.name));
25699 this.tb.selectedNode = sel;
25702 Roo.menu.MenuMgr.hideAll();
25704 //this.editorsyncValue();
25709 onDestroy : function(){
25712 this.tb.items.each(function(item){
25714 item.menu.removeAll();
25716 item.menu.el.destroy();
25724 onFirstFocus: function() {
25725 // need to do this for all the toolbars..
25726 this.tb.items.each(function(item){
25730 buildToolbar: function(tlist, nm)
25732 var editor = this.editor;
25733 // create a new element.
25734 var wdiv = editor.wrap.createChild({
25736 }, editor.wrap.dom.firstChild.nextSibling, true);
25739 var tb = new Roo.Toolbar(wdiv);
25740 tb.add(nm+ ": ");
25741 for (var i in tlist) {
25742 var item = tlist[i];
25743 tb.add(item.title + ": ");
25748 tb.addField( new Roo.form.ComboBox({
25749 store: new Roo.data.SimpleStore({
25752 data : item.opts // from states.js
25755 displayField:'val',
25759 triggerAction: 'all',
25760 emptyText:'Select',
25761 selectOnFocus:true,
25762 width: item.width ? item.width : 130,
25764 'select': function(c, r, i) {
25765 tb.selectedNode.setAttribute(c.name, r.get('val'));
25776 tb.addField( new Roo.form.TextField({
25779 //allowBlank:false,
25784 tb.addField( new Roo.form.TextField({
25790 'change' : function(f, nv, ov) {
25791 tb.selectedNode.setAttribute(f.name, nv);
25797 tb.el.on('click', function(e){
25798 e.preventDefault(); // what does this do?
25800 tb.el.setVisibilityMode( Roo.Element.DISPLAY);
25803 // dont need to disable them... as they will get hidden
25820 * Ext JS Library 1.1.1
25821 * Copyright(c) 2006-2007, Ext JS, LLC.
25823 * Originally Released Under LGPL - original licence link has changed is not relivant.
25826 * <script type="text/javascript">
25830 * @class Roo.form.BasicForm
25831 * @extends Roo.util.Observable
25832 * Supplies the functionality to do "actions" on forms and initialize Roo.form.Field types on existing markup.
25834 * @param {String/HTMLElement/Roo.Element} el The form element or its id
25835 * @param {Object} config Configuration options
25837 Roo.form.BasicForm = function(el, config){
25838 this.allItems = [];
25839 this.childForms = [];
25840 Roo.apply(this, config);
25842 * The Roo.form.Field items in this form.
25843 * @type MixedCollection
25847 this.items = new Roo.util.MixedCollection(false, function(o){
25848 return o.id || (o.id = Roo.id());
25852 * @event beforeaction
25853 * Fires before any action is performed. Return false to cancel the action.
25854 * @param {Form} this
25855 * @param {Action} action The action to be performed
25857 beforeaction: true,
25859 * @event actionfailed
25860 * Fires when an action fails.
25861 * @param {Form} this
25862 * @param {Action} action The action that failed
25864 actionfailed : true,
25866 * @event actioncomplete
25867 * Fires when an action is completed.
25868 * @param {Form} this
25869 * @param {Action} action The action that completed
25871 actioncomplete : true
25876 Roo.form.BasicForm.superclass.constructor.call(this);
25879 Roo.extend(Roo.form.BasicForm, Roo.util.Observable, {
25881 * @cfg {String} method
25882 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
25885 * @cfg {DataReader} reader
25886 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when executing "load" actions.
25887 * This is optional as there is built-in support for processing JSON.
25890 * @cfg {DataReader} errorReader
25891 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when reading validation errors on "submit" actions.
25892 * This is completely optional as there is built-in support for processing JSON.
25895 * @cfg {String} url
25896 * The URL to use for form actions if one isn't supplied in the action options.
25899 * @cfg {Boolean} fileUpload
25900 * Set to true if this form is a file upload.
25903 * @cfg {Object} baseParams
25904 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
25907 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
25912 activeAction : null,
25915 * @cfg {Boolean} trackResetOnLoad If set to true, form.reset() resets to the last loaded
25916 * or setValues() data instead of when the form was first created.
25918 trackResetOnLoad : false,
25922 * childForms - used for multi-tab forms
25925 childForms : false,
25928 * allItems - full list of fields.
25934 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
25935 * element by passing it or its id or mask the form itself by passing in true.
25938 waitMsgTarget : undefined,
25941 initEl : function(el){
25942 this.el = Roo.get(el);
25943 this.id = this.el.id || Roo.id();
25944 this.el.on('submit', this.onSubmit, this);
25945 this.el.addClass('x-form');
25949 onSubmit : function(e){
25954 * Returns true if client-side validation on the form is successful.
25957 isValid : function(){
25959 this.items.each(function(f){
25968 * Returns true if any fields in this form have changed since their original load.
25971 isDirty : function(){
25973 this.items.each(function(f){
25983 * Performs a predefined action (submit or load) or custom actions you define on this form.
25984 * @param {String} actionName The name of the action type
25985 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
25986 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
25987 * accept other config options):
25989 Property Type Description
25990 ---------------- --------------- ----------------------------------------------------------------------------------
25991 url String The url for the action (defaults to the form's url)
25992 method String The form method to use (defaults to the form's method, or POST if not defined)
25993 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
25994 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
25995 validate the form on the client (defaults to false)
25997 * @return {BasicForm} this
25999 doAction : function(action, options){
26000 if(typeof action == 'string'){
26001 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
26003 if(this.fireEvent('beforeaction', this, action) !== false){
26004 this.beforeAction(action);
26005 action.run.defer(100, action);
26011 * Shortcut to do a submit action.
26012 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
26013 * @return {BasicForm} this
26015 submit : function(options){
26016 this.doAction('submit', options);
26021 * Shortcut to do a load action.
26022 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
26023 * @return {BasicForm} this
26025 load : function(options){
26026 this.doAction('load', options);
26031 * Persists the values in this form into the passed Roo.data.Record object in a beginEdit/endEdit block.
26032 * @param {Record} record The record to edit
26033 * @return {BasicForm} this
26035 updateRecord : function(record){
26036 record.beginEdit();
26037 var fs = record.fields;
26038 fs.each(function(f){
26039 var field = this.findField(f.name);
26041 record.set(f.name, field.getValue());
26049 * Loads an Roo.data.Record into this form.
26050 * @param {Record} record The record to load
26051 * @return {BasicForm} this
26053 loadRecord : function(record){
26054 this.setValues(record.data);
26059 beforeAction : function(action){
26060 var o = action.options;
26062 if(this.waitMsgTarget === true){
26063 this.el.mask(o.waitMsg, 'x-mask-loading');
26064 }else if(this.waitMsgTarget){
26065 this.waitMsgTarget = Roo.get(this.waitMsgTarget);
26066 this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');
26068 Roo.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle || 'Please Wait...');
26074 afterAction : function(action, success){
26075 this.activeAction = null;
26076 var o = action.options;
26078 if(this.waitMsgTarget === true){
26080 }else if(this.waitMsgTarget){
26081 this.waitMsgTarget.unmask();
26083 Roo.MessageBox.updateProgress(1);
26084 Roo.MessageBox.hide();
26091 Roo.callback(o.success, o.scope, [this, action]);
26092 this.fireEvent('actioncomplete', this, action);
26094 Roo.callback(o.failure, o.scope, [this, action]);
26095 this.fireEvent('actionfailed', this, action);
26100 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
26101 * @param {String} id The value to search for
26104 findField : function(id){
26105 var field = this.items.get(id);
26107 this.items.each(function(f){
26108 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
26114 return field || null;
26118 * Add a secondary form to this one,
26119 * Used to provide tabbed forms. One form is primary, with hidden values
26120 * which mirror the elements from the other forms.
26122 * @param {Roo.form.Form} form to add.
26125 addForm : function(form)
26128 if (this.childForms.indexOf(form) > -1) {
26132 this.childForms.push(form);
26134 Roo.each(form.allItems, function (fe) {
26136 n = typeof(fe.getName) == 'undefined' ? fe.name : fe.getName();
26137 if (this.findField(n)) { // already added..
26140 var add = new Roo.form.Hidden({
26143 add.render(this.el);
26150 * Mark fields in this form invalid in bulk.
26151 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
26152 * @return {BasicForm} this
26154 markInvalid : function(errors){
26155 if(errors instanceof Array){
26156 for(var i = 0, len = errors.length; i < len; i++){
26157 var fieldError = errors[i];
26158 var f = this.findField(fieldError.id);
26160 f.markInvalid(fieldError.msg);
26166 if(typeof errors[id] != 'function' && (field = this.findField(id))){
26167 field.markInvalid(errors[id]);
26171 Roo.each(this.childForms || [], function (f) {
26172 f.markInvalid(errors);
26179 * Set values for fields in this form in bulk.
26180 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
26181 * @return {BasicForm} this
26183 setValues : function(values){
26184 if(values instanceof Array){ // array of objects
26185 for(var i = 0, len = values.length; i < len; i++){
26187 var f = this.findField(v.id);
26189 f.setValue(v.value);
26190 if(this.trackResetOnLoad){
26191 f.originalValue = f.getValue();
26195 }else{ // object hash
26198 if(typeof values[id] != 'function' && (field = this.findField(id))){
26200 if (field.setFromData &&
26201 field.valueField &&
26202 field.displayField &&
26203 // combos' with local stores can
26204 // be queried via setValue()
26205 // to set their value..
26206 (field.store && !field.store.isLocal)
26210 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
26211 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
26212 field.setFromData(sd);
26215 field.setValue(values[id]);
26219 if(this.trackResetOnLoad){
26220 field.originalValue = field.getValue();
26226 Roo.each(this.childForms || [], function (f) {
26227 f.setValues(values);
26234 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
26235 * they are returned as an array.
26236 * @param {Boolean} asString
26239 getValues : function(asString){
26240 if (this.childForms) {
26241 // copy values from the child forms
26242 Roo.each(this.childForms, function (f) {
26243 this.setValues(f.getValues());
26249 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
26250 if(asString === true){
26253 return Roo.urlDecode(fs);
26257 * Returns the fields in this form as an object with key/value pairs.
26258 * This differs from getValues as it calls getValue on each child item, rather than using dom data.
26261 getFieldValues : function()
26263 if (this.childForms) {
26264 // copy values from the child forms
26265 Roo.each(this.childForms, function (f) {
26266 this.setValues(f.getValues());
26271 this.items.each(function(f){
26272 if (!f.getName()) {
26275 var v = f.getValue();
26276 if ((typeof(v) == 'object') && f.getRawValue) {
26277 v = f.getRawValue() ; // dates..
26279 ret[f.getName()] = v;
26286 * Clears all invalid messages in this form.
26287 * @return {BasicForm} this
26289 clearInvalid : function(){
26290 this.items.each(function(f){
26294 Roo.each(this.childForms || [], function (f) {
26303 * Resets this form.
26304 * @return {BasicForm} this
26306 reset : function(){
26307 this.items.each(function(f){
26311 Roo.each(this.childForms || [], function (f) {
26320 * Add Roo.form components to this form.
26321 * @param {Field} field1
26322 * @param {Field} field2 (optional)
26323 * @param {Field} etc (optional)
26324 * @return {BasicForm} this
26327 this.items.addAll(Array.prototype.slice.call(arguments, 0));
26333 * Removes a field from the items collection (does NOT remove its markup).
26334 * @param {Field} field
26335 * @return {BasicForm} this
26337 remove : function(field){
26338 this.items.remove(field);
26343 * Looks at the fields in this form, checks them for an id attribute,
26344 * and calls applyTo on the existing dom element with that id.
26345 * @return {BasicForm} this
26347 render : function(){
26348 this.items.each(function(f){
26349 if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
26357 * Calls {@link Ext#apply} for all fields in this form with the passed object.
26358 * @param {Object} values
26359 * @return {BasicForm} this
26361 applyToFields : function(o){
26362 this.items.each(function(f){
26369 * Calls {@link Ext#applyIf} for all field in this form with the passed object.
26370 * @param {Object} values
26371 * @return {BasicForm} this
26373 applyIfToFields : function(o){
26374 this.items.each(function(f){
26382 Roo.BasicForm = Roo.form.BasicForm;/*
26384 * Ext JS Library 1.1.1
26385 * Copyright(c) 2006-2007, Ext JS, LLC.
26387 * Originally Released Under LGPL - original licence link has changed is not relivant.
26390 * <script type="text/javascript">
26394 * @class Roo.form.Form
26395 * @extends Roo.form.BasicForm
26396 * Adds the ability to dynamically render forms with JavaScript to {@link Roo.form.BasicForm}.
26398 * @param {Object} config Configuration options
26400 Roo.form.Form = function(config){
26402 if (config.items) {
26403 xitems = config.items;
26404 delete config.items;
26408 Roo.form.Form.superclass.constructor.call(this, null, config);
26409 this.url = this.url || this.action;
26411 this.root = new Roo.form.Layout(Roo.applyIf({
26415 this.active = this.root;
26417 * Array of all the buttons that have been added to this form via {@link addButton}
26421 this.allItems = [];
26424 * @event clientvalidation
26425 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
26426 * @param {Form} this
26427 * @param {Boolean} valid true if the form has passed client-side validation
26429 clientvalidation: true,
26432 * Fires when the form is rendered
26433 * @param {Roo.form.Form} form
26438 if (this.progressUrl) {
26439 // push a hidden field onto the list of fields..
26443 name : 'UPLOAD_IDENTIFIER'
26448 Roo.each(xitems, this.addxtype, this);
26454 Roo.extend(Roo.form.Form, Roo.form.BasicForm, {
26456 * @cfg {Number} labelWidth The width of labels. This property cascades to child containers.
26459 * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
26462 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "center")
26464 buttonAlign:'center',
26467 * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to 75)
26472 * @cfg {String} labelAlign Valid values are "left," "top" and "right" (defaults to "left").
26473 * This property cascades to child containers if not set.
26478 * @cfg {Boolean} monitorValid If true the form monitors its valid state <b>client-side</b> and
26479 * fires a looping event with that state. This is required to bind buttons to the valid
26480 * state using the config value formBind:true on the button.
26482 monitorValid : false,
26485 * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
26490 * @cfg {String} progressUrl - Url to return progress data
26493 progressUrl : false,
26496 * Opens a new {@link Roo.form.Column} container in the layout stack. If fields are passed after the config, the
26497 * fields are added and the column is closed. If no fields are passed the column remains open
26498 * until end() is called.
26499 * @param {Object} config The config to pass to the column
26500 * @param {Field} field1 (optional)
26501 * @param {Field} field2 (optional)
26502 * @param {Field} etc (optional)
26503 * @return Column The column container object
26505 column : function(c){
26506 var col = new Roo.form.Column(c);
26508 if(arguments.length > 1){ // duplicate code required because of Opera
26509 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
26516 * Opens a new {@link Roo.form.FieldSet} container in the layout stack. If fields are passed after the config, the
26517 * fields are added and the fieldset is closed. If no fields are passed the fieldset remains open
26518 * until end() is called.
26519 * @param {Object} config The config to pass to the fieldset
26520 * @param {Field} field1 (optional)
26521 * @param {Field} field2 (optional)
26522 * @param {Field} etc (optional)
26523 * @return FieldSet The fieldset container object
26525 fieldset : function(c){
26526 var fs = new Roo.form.FieldSet(c);
26528 if(arguments.length > 1){ // duplicate code required because of Opera
26529 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
26536 * Opens a new {@link Roo.form.Layout} container in the layout stack. If fields are passed after the config, the
26537 * fields are added and the container is closed. If no fields are passed the container remains open
26538 * until end() is called.
26539 * @param {Object} config The config to pass to the Layout
26540 * @param {Field} field1 (optional)
26541 * @param {Field} field2 (optional)
26542 * @param {Field} etc (optional)
26543 * @return Layout The container object
26545 container : function(c){
26546 var l = new Roo.form.Layout(c);
26548 if(arguments.length > 1){ // duplicate code required because of Opera
26549 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
26556 * Opens the passed container in the layout stack. The container can be any {@link Roo.form.Layout} or subclass.
26557 * @param {Object} container A Roo.form.Layout or subclass of Layout
26558 * @return {Form} this
26560 start : function(c){
26561 // cascade label info
26562 Roo.applyIf(c, {'labelAlign': this.active.labelAlign, 'labelWidth': this.active.labelWidth, 'itemCls': this.active.itemCls});
26563 this.active.stack.push(c);
26564 c.ownerCt = this.active;
26570 * Closes the current open container
26571 * @return {Form} this
26574 if(this.active == this.root){
26577 this.active = this.active.ownerCt;
26582 * Add Roo.form components to the current open container (e.g. column, fieldset, etc.). Fields added via this method
26583 * can also be passed with an additional property of fieldLabel, which if supplied, will provide the text to display
26584 * as the label of the field.
26585 * @param {Field} field1
26586 * @param {Field} field2 (optional)
26587 * @param {Field} etc. (optional)
26588 * @return {Form} this
26591 this.active.stack.push.apply(this.active.stack, arguments);
26592 this.allItems.push.apply(this.allItems,arguments);
26594 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
26595 if(a[i].isFormField){
26600 Roo.form.Form.superclass.add.apply(this, r);
26610 * Find any element that has been added to a form, using it's ID or name
26611 * This can include framesets, columns etc. along with regular fields..
26612 * @param {String} id - id or name to find.
26614 * @return {Element} e - or false if nothing found.
26616 findbyId : function(id)
26622 Ext.each(this.allItems, function(f){
26623 if (f.id == id || f.name == id ){
26634 * Render this form into the passed container. This should only be called once!
26635 * @param {String/HTMLElement/Element} container The element this component should be rendered into
26636 * @return {Form} this
26638 render : function(ct)
26644 var o = this.autoCreate || {
26646 method : this.method || 'POST',
26647 id : this.id || Roo.id()
26649 this.initEl(ct.createChild(o));
26651 this.root.render(this.el);
26655 this.items.each(function(f){
26656 f.render('x-form-el-'+f.id);
26659 if(this.buttons.length > 0){
26660 // tables are required to maintain order and for correct IE layout
26661 var tb = this.el.createChild({cls:'x-form-btns-ct', cn: {
26662 cls:"x-form-btns x-form-btns-"+this.buttonAlign,
26663 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
26665 var tr = tb.getElementsByTagName('tr')[0];
26666 for(var i = 0, len = this.buttons.length; i < len; i++) {
26667 var b = this.buttons[i];
26668 var td = document.createElement('td');
26669 td.className = 'x-form-btn-td';
26670 b.render(tr.appendChild(td));
26673 if(this.monitorValid){ // initialize after render
26674 this.startMonitoring();
26676 this.fireEvent('rendered', this);
26681 * Adds a button to the footer of the form - this <b>must</b> be called before the form is rendered.
26682 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
26683 * object or a valid Roo.DomHelper element config
26684 * @param {Function} handler The function called when the button is clicked
26685 * @param {Object} scope (optional) The scope of the handler function
26686 * @return {Roo.Button}
26688 addButton : function(config, handler, scope){
26692 minWidth: this.minButtonWidth,
26695 if(typeof config == "string"){
26698 Roo.apply(bc, config);
26700 var btn = new Roo.Button(null, bc);
26701 this.buttons.push(btn);
26706 * Adds a series of form elements (using the xtype property as the factory method.
26707 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column, (and 'end' to close a block)
26708 * @param {Object} config
26711 addxtype : function()
26713 var ar = Array.prototype.slice.call(arguments, 0);
26715 for(var i = 0; i < ar.length; i++) {
26717 continue; // skip -- if this happends something invalid got sent, we
26718 // should ignore it, as basically that interface element will not show up
26719 // and that should be pretty obvious!!
26722 if (Roo.form[ar[i].xtype]) {
26724 var fe = Roo.factory(ar[i], Roo.form);
26730 fe.store.form = this;
26735 this.allItems.push(fe);
26736 if (fe.items && fe.addxtype) {
26737 fe.addxtype.apply(fe, fe.items);
26747 // console.log('adding ' + ar[i].xtype);
26749 if (ar[i].xtype == 'Button') {
26750 //console.log('adding button');
26751 //console.log(ar[i]);
26752 this.addButton(ar[i]);
26753 this.allItems.push(fe);
26757 if (ar[i].xtype == 'end') { // so we can add fieldsets... / layout etc.
26758 alert('end is not supported on xtype any more, use items');
26760 // //console.log('adding end');
26768 * Starts monitoring of the valid state of this form. Usually this is done by passing the config
26769 * option "monitorValid"
26771 startMonitoring : function(){
26774 Roo.TaskMgr.start({
26775 run : this.bindHandler,
26776 interval : this.monitorPoll || 200,
26783 * Stops monitoring of the valid state of this form
26785 stopMonitoring : function(){
26786 this.bound = false;
26790 bindHandler : function(){
26792 return false; // stops binding
26795 this.items.each(function(f){
26796 if(!f.isValid(true)){
26801 for(var i = 0, len = this.buttons.length; i < len; i++){
26802 var btn = this.buttons[i];
26803 if(btn.formBind === true && btn.disabled === valid){
26804 btn.setDisabled(!valid);
26807 this.fireEvent('clientvalidation', this, valid);
26821 Roo.Form = Roo.form.Form;
26824 * Ext JS Library 1.1.1
26825 * Copyright(c) 2006-2007, Ext JS, LLC.
26827 * Originally Released Under LGPL - original licence link has changed is not relivant.
26830 * <script type="text/javascript">
26834 * @class Roo.form.Action
26835 * Internal Class used to handle form actions
26837 * @param {Roo.form.BasicForm} el The form element or its id
26838 * @param {Object} config Configuration options
26842 // define the action interface
26843 Roo.form.Action = function(form, options){
26845 this.options = options || {};
26848 * Client Validation Failed
26851 Roo.form.Action.CLIENT_INVALID = 'client';
26853 * Server Validation Failed
26856 Roo.form.Action.SERVER_INVALID = 'server';
26858 * Connect to Server Failed
26861 Roo.form.Action.CONNECT_FAILURE = 'connect';
26863 * Reading Data from Server Failed
26866 Roo.form.Action.LOAD_FAILURE = 'load';
26868 Roo.form.Action.prototype = {
26870 failureType : undefined,
26871 response : undefined,
26872 result : undefined,
26874 // interface method
26875 run : function(options){
26879 // interface method
26880 success : function(response){
26884 // interface method
26885 handleResponse : function(response){
26889 // default connection failure
26890 failure : function(response){
26891 this.response = response;
26892 this.failureType = Roo.form.Action.CONNECT_FAILURE;
26893 this.form.afterAction(this, false);
26896 processResponse : function(response){
26897 this.response = response;
26898 if(!response.responseText){
26901 this.result = this.handleResponse(response);
26902 return this.result;
26905 // utility functions used internally
26906 getUrl : function(appendParams){
26907 var url = this.options.url || this.form.url || this.form.el.dom.action;
26909 var p = this.getParams();
26911 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
26917 getMethod : function(){
26918 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
26921 getParams : function(){
26922 var bp = this.form.baseParams;
26923 var p = this.options.params;
26925 if(typeof p == "object"){
26926 p = Roo.urlEncode(Roo.applyIf(p, bp));
26927 }else if(typeof p == 'string' && bp){
26928 p += '&' + Roo.urlEncode(bp);
26931 p = Roo.urlEncode(bp);
26936 createCallback : function(){
26938 success: this.success,
26939 failure: this.failure,
26941 timeout: (this.form.timeout*1000),
26942 upload: this.form.fileUpload ? this.success : undefined
26947 Roo.form.Action.Submit = function(form, options){
26948 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
26951 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
26954 haveProgress : false,
26955 uploadComplete : false,
26957 // uploadProgress indicator.
26958 uploadProgress : function()
26960 if (!this.form.progressUrl) {
26964 if (!this.haveProgress) {
26965 Roo.MessageBox.progress("Uploading", "Uploading");
26967 if (this.uploadComplete) {
26968 Roo.MessageBox.hide();
26972 this.haveProgress = true;
26974 var uid = this.form.findField('UPLOAD_IDENTIFIER').getValue();
26976 var c = new Roo.data.Connection();
26978 url : this.form.progressUrl,
26983 success : function(req){
26984 //console.log(data);
26988 rdata = Roo.decode(req.responseText)
26990 Roo.log("Invalid data from server..");
26994 if (!rdata || !rdata.success) {
26998 var data = rdata.data;
27000 if (this.uploadComplete) {
27001 Roo.MessageBox.hide();
27006 Roo.MessageBox.updateProgress(data.bytes_uploaded/data.bytes_total,
27007 Math.floor((data.bytes_total - data.bytes_uploaded)/1000) + 'k remaining'
27010 this.uploadProgress.defer(2000,this);
27013 failure: function(data) {
27014 Roo.log('progress url failed ');
27025 // run get Values on the form, so it syncs any secondary forms.
27026 this.form.getValues();
27028 var o = this.options;
27029 var method = this.getMethod();
27030 var isPost = method == 'POST';
27031 if(o.clientValidation === false || this.form.isValid()){
27033 if (this.form.progressUrl) {
27034 this.form.findField('UPLOAD_IDENTIFIER').setValue(
27035 (new Date() * 1) + '' + Math.random());
27039 Roo.Ajax.request(Roo.apply(this.createCallback(), {
27040 form:this.form.el.dom,
27041 url:this.getUrl(!isPost),
27043 params:isPost ? this.getParams() : null,
27044 isUpload: this.form.fileUpload
27047 this.uploadProgress();
27049 }else if (o.clientValidation !== false){ // client validation failed
27050 this.failureType = Roo.form.Action.CLIENT_INVALID;
27051 this.form.afterAction(this, false);
27055 success : function(response)
27057 this.uploadComplete= true;
27058 if (this.haveProgress) {
27059 Roo.MessageBox.hide();
27062 var result = this.processResponse(response);
27063 if(result === true || result.success){
27064 this.form.afterAction(this, true);
27068 this.form.markInvalid(result.errors);
27069 this.failureType = Roo.form.Action.SERVER_INVALID;
27071 this.form.afterAction(this, false);
27073 failure : function(response)
27075 this.uploadComplete= true;
27076 if (this.haveProgress) {
27077 Roo.MessageBox.hide();
27080 this.response = response;
27081 this.failureType = Roo.form.Action.CONNECT_FAILURE;
27082 this.form.afterAction(this, false);
27085 handleResponse : function(response){
27086 if(this.form.errorReader){
27087 var rs = this.form.errorReader.read(response);
27090 for(var i = 0, len = rs.records.length; i < len; i++) {
27091 var r = rs.records[i];
27092 errors[i] = r.data;
27095 if(errors.length < 1){
27099 success : rs.success,
27105 ret = Roo.decode(response.responseText);
27109 errorMsg: "Failed to read server message: " + (response ? response.responseText : ' - no message'),
27119 Roo.form.Action.Load = function(form, options){
27120 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
27121 this.reader = this.form.reader;
27124 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
27128 Roo.Ajax.request(Roo.apply(
27129 this.createCallback(), {
27130 method:this.getMethod(),
27131 url:this.getUrl(false),
27132 params:this.getParams()
27136 success : function(response){
27137 var result = this.processResponse(response);
27138 if(result === true || !result.success || !result.data){
27139 this.failureType = Roo.form.Action.LOAD_FAILURE;
27140 this.form.afterAction(this, false);
27143 this.form.clearInvalid();
27144 this.form.setValues(result.data);
27145 this.form.afterAction(this, true);
27148 handleResponse : function(response){
27149 if(this.form.reader){
27150 var rs = this.form.reader.read(response);
27151 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
27153 success : rs.success,
27157 return Roo.decode(response.responseText);
27161 Roo.form.Action.ACTION_TYPES = {
27162 'load' : Roo.form.Action.Load,
27163 'submit' : Roo.form.Action.Submit
27166 * Ext JS Library 1.1.1
27167 * Copyright(c) 2006-2007, Ext JS, LLC.
27169 * Originally Released Under LGPL - original licence link has changed is not relivant.
27172 * <script type="text/javascript">
27176 * @class Roo.form.Layout
27177 * @extends Roo.Component
27178 * Creates a container for layout and rendering of fields in an {@link Roo.form.Form}.
27180 * @param {Object} config Configuration options
27182 Roo.form.Layout = function(config){
27184 if (config.items) {
27185 xitems = config.items;
27186 delete config.items;
27188 Roo.form.Layout.superclass.constructor.call(this, config);
27190 Roo.each(xitems, this.addxtype, this);
27194 Roo.extend(Roo.form.Layout, Roo.Component, {
27196 * @cfg {String/Object} autoCreate
27197 * A DomHelper element spec used to autocreate the layout (defaults to {tag: 'div', cls: 'x-form-ct'})
27200 * @cfg {String/Object/Function} style
27201 * A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
27202 * a function which returns such a specification.
27205 * @cfg {String} labelAlign
27206 * Valid values are "left," "top" and "right" (defaults to "left")
27209 * @cfg {Number} labelWidth
27210 * Fixed width in pixels of all field labels (defaults to undefined)
27213 * @cfg {Boolean} clear
27214 * True to add a clearing element at the end of this layout, equivalent to CSS clear: both (defaults to true)
27218 * @cfg {String} labelSeparator
27219 * The separator to use after field labels (defaults to ':')
27221 labelSeparator : ':',
27223 * @cfg {Boolean} hideLabels
27224 * True to suppress the display of field labels in this layout (defaults to false)
27226 hideLabels : false,
27229 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct'},
27234 onRender : function(ct, position){
27235 if(this.el){ // from markup
27236 this.el = Roo.get(this.el);
27237 }else { // generate
27238 var cfg = this.getAutoCreate();
27239 this.el = ct.createChild(cfg, position);
27242 this.el.applyStyles(this.style);
27244 if(this.labelAlign){
27245 this.el.addClass('x-form-label-'+this.labelAlign);
27247 if(this.hideLabels){
27248 this.labelStyle = "display:none";
27249 this.elementStyle = "padding-left:0;";
27251 if(typeof this.labelWidth == 'number'){
27252 this.labelStyle = "width:"+this.labelWidth+"px;";
27253 this.elementStyle = "padding-left:"+((this.labelWidth+(typeof this.labelPad == 'number' ? this.labelPad : 5))+'px')+";";
27255 if(this.labelAlign == 'top'){
27256 this.labelStyle = "width:auto;";
27257 this.elementStyle = "padding-left:0;";
27260 var stack = this.stack;
27261 var slen = stack.length;
27263 if(!this.fieldTpl){
27264 var t = new Roo.Template(
27265 '<div class="x-form-item {5}">',
27266 '<label for="{0}" style="{2}">{1}{4}</label>',
27267 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
27269 '</div><div class="x-form-clear-left"></div>'
27271 t.disableFormats = true;
27273 Roo.form.Layout.prototype.fieldTpl = t;
27275 for(var i = 0; i < slen; i++) {
27276 if(stack[i].isFormField){
27277 this.renderField(stack[i]);
27279 this.renderComponent(stack[i]);
27284 this.el.createChild({cls:'x-form-clear'});
27289 renderField : function(f){
27290 f.fieldEl = Roo.get(this.fieldTpl.append(this.el, [
27293 f.labelStyle||this.labelStyle||'', //2
27294 this.elementStyle||'', //3
27295 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator, //4
27296 f.itemCls||this.itemCls||'' //5
27297 ], true).getPrevSibling());
27301 renderComponent : function(c){
27302 c.render(c.isLayout ? this.el : this.el.createChild());
27305 * Adds a object form elements (using the xtype property as the factory method.)
27306 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column
27307 * @param {Object} config
27309 addxtype : function(o)
27311 // create the lement.
27312 o.form = this.form;
27313 var fe = Roo.factory(o, Roo.form);
27314 this.form.allItems.push(fe);
27315 this.stack.push(fe);
27317 if (fe.isFormField) {
27318 this.form.items.add(fe);
27326 * @class Roo.form.Column
27327 * @extends Roo.form.Layout
27328 * Creates a column container for layout and rendering of fields in an {@link Roo.form.Form}.
27330 * @param {Object} config Configuration options
27332 Roo.form.Column = function(config){
27333 Roo.form.Column.superclass.constructor.call(this, config);
27336 Roo.extend(Roo.form.Column, Roo.form.Layout, {
27338 * @cfg {Number/String} width
27339 * The fixed width of the column in pixels or CSS value (defaults to "auto")
27342 * @cfg {String/Object} autoCreate
27343 * A DomHelper element spec used to autocreate the column (defaults to {tag: 'div', cls: 'x-form-ct x-form-column'})
27347 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-column'},
27350 onRender : function(ct, position){
27351 Roo.form.Column.superclass.onRender.call(this, ct, position);
27353 this.el.setWidth(this.width);
27360 * @class Roo.form.Row
27361 * @extends Roo.form.Layout
27362 * Creates a row container for layout and rendering of fields in an {@link Roo.form.Form}.
27364 * @param {Object} config Configuration options
27368 Roo.form.Row = function(config){
27369 Roo.form.Row.superclass.constructor.call(this, config);
27372 Roo.extend(Roo.form.Row, Roo.form.Layout, {
27374 * @cfg {Number/String} width
27375 * The fixed width of the column in pixels or CSS value (defaults to "auto")
27378 * @cfg {Number/String} height
27379 * The fixed height of the column in pixels or CSS value (defaults to "auto")
27381 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-row'},
27385 onRender : function(ct, position){
27386 //console.log('row render');
27388 var t = new Roo.Template(
27389 '<div class="x-form-item {5}" style="float:left;width:{6}px">',
27390 '<label for="{0}" style="{2}">{1}{4}</label>',
27391 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
27395 t.disableFormats = true;
27397 Roo.form.Layout.prototype.rowTpl = t;
27399 this.fieldTpl = this.rowTpl;
27401 //console.log('lw' + this.labelWidth +', la:' + this.labelAlign);
27402 var labelWidth = 100;
27404 if ((this.labelAlign != 'top')) {
27405 if (typeof this.labelWidth == 'number') {
27406 labelWidth = this.labelWidth
27408 this.padWidth = 20 + labelWidth;
27412 Roo.form.Column.superclass.onRender.call(this, ct, position);
27414 this.el.setWidth(this.width);
27417 this.el.setHeight(this.height);
27422 renderField : function(f){
27423 f.fieldEl = this.fieldTpl.append(this.el, [
27424 f.id, f.fieldLabel,
27425 f.labelStyle||this.labelStyle||'',
27426 this.elementStyle||'',
27427 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator,
27428 f.itemCls||this.itemCls||'',
27429 f.width ? f.width + this.padWidth : 160 + this.padWidth
27436 * @class Roo.form.FieldSet
27437 * @extends Roo.form.Layout
27438 * Creates a fieldset container for layout and rendering of fields in an {@link Roo.form.Form}.
27440 * @param {Object} config Configuration options
27442 Roo.form.FieldSet = function(config){
27443 Roo.form.FieldSet.superclass.constructor.call(this, config);
27446 Roo.extend(Roo.form.FieldSet, Roo.form.Layout, {
27448 * @cfg {String} legend
27449 * The text to display as the legend for the FieldSet (defaults to '')
27452 * @cfg {String/Object} autoCreate
27453 * A DomHelper element spec used to autocreate the fieldset (defaults to {tag: 'fieldset', cn: {tag:'legend'}})
27457 defaultAutoCreate : {tag: 'fieldset', cn: {tag:'legend'}},
27460 onRender : function(ct, position){
27461 Roo.form.FieldSet.superclass.onRender.call(this, ct, position);
27463 this.setLegend(this.legend);
27468 setLegend : function(text){
27470 this.el.child('legend').update(text);
27475 * Ext JS Library 1.1.1
27476 * Copyright(c) 2006-2007, Ext JS, LLC.
27478 * Originally Released Under LGPL - original licence link has changed is not relivant.
27481 * <script type="text/javascript">
27484 * @class Roo.form.VTypes
27485 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
27488 Roo.form.VTypes = function(){
27489 // closure these in so they are only created once.
27490 var alpha = /^[a-zA-Z_]+$/;
27491 var alphanum = /^[a-zA-Z0-9_]+$/;
27492 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/;
27493 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
27495 // All these messages and functions are configurable
27498 * The function used to validate email addresses
27499 * @param {String} value The email address
27501 'email' : function(v){
27502 return email.test(v);
27505 * The error text to display when the email validation function returns false
27508 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
27510 * The keystroke filter mask to be applied on email input
27513 'emailMask' : /[a-z0-9_\.\-@]/i,
27516 * The function used to validate URLs
27517 * @param {String} value The URL
27519 'url' : function(v){
27520 return url.test(v);
27523 * The error text to display when the url validation function returns false
27526 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
27529 * The function used to validate alpha values
27530 * @param {String} value The value
27532 'alpha' : function(v){
27533 return alpha.test(v);
27536 * The error text to display when the alpha validation function returns false
27539 'alphaText' : 'This field should only contain letters and _',
27541 * The keystroke filter mask to be applied on alpha input
27544 'alphaMask' : /[a-z_]/i,
27547 * The function used to validate alphanumeric values
27548 * @param {String} value The value
27550 'alphanum' : function(v){
27551 return alphanum.test(v);
27554 * The error text to display when the alphanumeric validation function returns false
27557 'alphanumText' : 'This field should only contain letters, numbers and _',
27559 * The keystroke filter mask to be applied on alphanumeric input
27562 'alphanumMask' : /[a-z0-9_]/i
27564 }();//<script type="text/javascript">
27567 * @class Roo.form.FCKeditor
27568 * @extends Roo.form.TextArea
27569 * Wrapper around the FCKEditor http://www.fckeditor.net
27571 * Creates a new FCKeditor
27572 * @param {Object} config Configuration options
27574 Roo.form.FCKeditor = function(config){
27575 Roo.form.FCKeditor.superclass.constructor.call(this, config);
27578 * @event editorinit
27579 * Fired when the editor is initialized - you can add extra handlers here..
27580 * @param {FCKeditor} this
27581 * @param {Object} the FCK object.
27588 Roo.form.FCKeditor.editors = { };
27589 Roo.extend(Roo.form.FCKeditor, Roo.form.TextArea,
27591 //defaultAutoCreate : {
27592 // tag : "textarea",style : "width:100px;height:60px;" ,autocomplete : "off"
27596 * @cfg {Object} fck options - see fck manual for details.
27601 * @cfg {Object} fck toolbar set (Basic or Default)
27603 toolbarSet : 'Basic',
27605 * @cfg {Object} fck BasePath
27607 basePath : '/fckeditor/',
27615 onRender : function(ct, position)
27618 this.defaultAutoCreate = {
27620 style:"width:300px;height:60px;",
27621 autocomplete: "off"
27624 Roo.form.FCKeditor.superclass.onRender.call(this, ct, position);
27627 this.textSizeEl = Roo.DomHelper.append(document.body, {tag: "pre", cls: "x-form-grow-sizer"});
27628 if(this.preventScrollbars){
27629 this.el.setStyle("overflow", "hidden");
27631 this.el.setHeight(this.growMin);
27634 //console.log('onrender' + this.getId() );
27635 Roo.form.FCKeditor.editors[this.getId()] = this;
27638 this.replaceTextarea() ;
27642 getEditor : function() {
27643 return this.fckEditor;
27646 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
27647 * @param {Mixed} value The value to set
27651 setValue : function(value)
27653 //console.log('setValue: ' + value);
27655 if(typeof(value) == 'undefined') { // not sure why this is happending...
27658 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
27660 //if(!this.el || !this.getEditor()) {
27661 // this.value = value;
27662 //this.setValue.defer(100,this,[value]);
27666 if(!this.getEditor()) {
27670 this.getEditor().SetData(value);
27677 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
27678 * @return {Mixed} value The field value
27680 getValue : function()
27683 if (this.frame && this.frame.dom.style.display == 'none') {
27684 return Roo.form.FCKeditor.superclass.getValue.call(this);
27687 if(!this.el || !this.getEditor()) {
27689 // this.getValue.defer(100,this);
27694 var value=this.getEditor().GetData();
27695 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
27696 return Roo.form.FCKeditor.superclass.getValue.call(this);
27702 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
27703 * @return {Mixed} value The field value
27705 getRawValue : function()
27707 if (this.frame && this.frame.dom.style.display == 'none') {
27708 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
27711 if(!this.el || !this.getEditor()) {
27712 //this.getRawValue.defer(100,this);
27719 var value=this.getEditor().GetData();
27720 Roo.form.FCKeditor.superclass.setRawValue.apply(this,[value]);
27721 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
27725 setSize : function(w,h) {
27729 //if (this.frame && this.frame.dom.style.display == 'none') {
27730 // Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
27733 //if(!this.el || !this.getEditor()) {
27734 // this.setSize.defer(100,this, [w,h]);
27740 Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
27742 this.frame.dom.setAttribute('width', w);
27743 this.frame.dom.setAttribute('height', h);
27744 this.frame.setSize(w,h);
27748 toggleSourceEdit : function(value) {
27752 this.el.dom.style.display = value ? '' : 'none';
27753 this.frame.dom.style.display = value ? 'none' : '';
27758 focus: function(tag)
27760 if (this.frame.dom.style.display == 'none') {
27761 return Roo.form.FCKeditor.superclass.focus.call(this);
27763 if(!this.el || !this.getEditor()) {
27764 this.focus.defer(100,this, [tag]);
27771 var tgs = this.getEditor().EditorDocument.getElementsByTagName(tag);
27772 this.getEditor().Focus();
27774 if (!this.getEditor().Selection.GetSelection()) {
27775 this.focus.defer(100,this, [tag]);
27780 var r = this.getEditor().EditorDocument.createRange();
27781 r.setStart(tgs[0],0);
27782 r.setEnd(tgs[0],0);
27783 this.getEditor().Selection.GetSelection().removeAllRanges();
27784 this.getEditor().Selection.GetSelection().addRange(r);
27785 this.getEditor().Focus();
27792 replaceTextarea : function()
27794 if ( document.getElementById( this.getId() + '___Frame' ) )
27796 //if ( !this.checkBrowser || this._isCompatibleBrowser() )
27798 // We must check the elements firstly using the Id and then the name.
27799 var oTextarea = document.getElementById( this.getId() );
27801 var colElementsByName = document.getElementsByName( this.getId() ) ;
27803 oTextarea.style.display = 'none' ;
27805 if ( oTextarea.tabIndex ) {
27806 this.TabIndex = oTextarea.tabIndex ;
27809 this._insertHtmlBefore( this._getConfigHtml(), oTextarea ) ;
27810 this._insertHtmlBefore( this._getIFrameHtml(), oTextarea ) ;
27811 this.frame = Roo.get(this.getId() + '___Frame')
27814 _getConfigHtml : function()
27818 for ( var o in this.fckconfig ) {
27819 sConfig += sConfig.length > 0 ? '&' : '';
27820 sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.fckconfig[o] ) ;
27823 return '<input type="hidden" id="' + this.getId() + '___Config" value="' + sConfig + '" style="display:none" />' ;
27827 _getIFrameHtml : function()
27829 var sFile = 'fckeditor.html' ;
27830 /* no idea what this is about..
27833 if ( (/fcksource=true/i).test( window.top.location.search ) )
27834 sFile = 'fckeditor.original.html' ;
27839 var sLink = this.basePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.getId() ) ;
27840 sLink += this.toolbarSet ? ( '&Toolbar=' + this.toolbarSet) : '';
27843 var html = '<iframe id="' + this.getId() +
27844 '___Frame" src="' + sLink +
27845 '" width="' + this.width +
27846 '" height="' + this.height + '"' +
27847 (this.tabIndex ? ' tabindex="' + this.tabIndex + '"' :'' ) +
27848 ' frameborder="0" scrolling="no"></iframe>' ;
27853 _insertHtmlBefore : function( html, element )
27855 if ( element.insertAdjacentHTML ) {
27857 element.insertAdjacentHTML( 'beforeBegin', html ) ;
27859 var oRange = document.createRange() ;
27860 oRange.setStartBefore( element ) ;
27861 var oFragment = oRange.createContextualFragment( html );
27862 element.parentNode.insertBefore( oFragment, element ) ;
27875 //Roo.reg('fckeditor', Roo.form.FCKeditor);
27877 function FCKeditor_OnComplete(editorInstance){
27878 var f = Roo.form.FCKeditor.editors[editorInstance.Name];
27879 f.fckEditor = editorInstance;
27880 //console.log("loaded");
27881 f.fireEvent('editorinit', f, editorInstance);
27901 //<script type="text/javascript">
27903 * @class Roo.form.GridField
27904 * @extends Roo.form.Field
27905 * Embed a grid (or editable grid into a form)
27908 * This embeds a grid in a form, the value of the field should be the json encoded array of rows
27910 * xgrid.store = Roo.data.Store
27911 * xgrid.store.proxy = Roo.data.MemoryProxy (data = [] )
27912 * xgrid.store.reader = Roo.data.JsonReader
27916 * Creates a new GridField
27917 * @param {Object} config Configuration options
27919 Roo.form.GridField = function(config){
27920 Roo.form.GridField.superclass.constructor.call(this, config);
27924 Roo.extend(Roo.form.GridField, Roo.form.Field, {
27926 * @cfg {Number} width - used to restrict width of grid..
27930 * @cfg {Number} height - used to restrict height of grid..
27934 * @cfg {Object} xgrid (xtype'd description of grid) { xtype : 'Grid', dataSource: .... }
27940 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
27941 * {tag: "input", type: "checkbox", autocomplete: "off"})
27943 // defaultAutoCreate : { tag: 'div' },
27944 defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
27946 * @cfg {String} addTitle Text to include for adding a title.
27950 onResize : function(){
27951 Roo.form.Field.superclass.onResize.apply(this, arguments);
27954 initEvents : function(){
27955 // Roo.form.Checkbox.superclass.initEvents.call(this);
27956 // has no events...
27961 getResizeEl : function(){
27965 getPositionEl : function(){
27970 onRender : function(ct, position){
27972 this.style = this.style || 'overflow: hidden; border:1px solid #c3daf9;';
27973 var style = this.style;
27976 Roo.form.GridField.superclass.onRender.call(this, ct, position);
27977 this.wrap = this.el.wrap({cls: ''}); // not sure why ive done thsi...
27978 this.viewEl = this.wrap.createChild({ tag: 'div' });
27980 this.viewEl.applyStyles(style);
27983 this.viewEl.setWidth(this.width);
27986 this.viewEl.setHeight(this.height);
27988 //if(this.inputValue !== undefined){
27989 //this.setValue(this.value);
27992 this.grid = new Roo.grid[this.xgrid.xtype](this.viewEl, this.xgrid);
27995 this.grid.render();
27996 this.grid.getDataSource().on('remove', this.refreshValue, this);
27997 this.grid.getDataSource().on('update', this.refreshValue, this);
27998 this.grid.on('afteredit', this.refreshValue, this);
28004 * Sets the value of the item.
28005 * @param {String} either an object or a string..
28007 setValue : function(v){
28009 v = v || []; // empty set..
28010 // this does not seem smart - it really only affects memoryproxy grids..
28011 if (this.grid && this.grid.getDataSource() && typeof(v) != 'undefined') {
28012 var ds = this.grid.getDataSource();
28013 // assumes a json reader..
28015 data[ds.reader.meta.root ] = typeof(v) == 'string' ? Roo.decode(v) : v;
28016 ds.loadData( data);
28018 Roo.form.GridField.superclass.setValue.call(this, v);
28019 this.refreshValue();
28020 // should load data in the grid really....
28024 refreshValue: function() {
28026 this.grid.getDataSource().each(function(r) {
28029 this.el.dom.value = Roo.encode(val);
28037 * Ext JS Library 1.1.1
28038 * Copyright(c) 2006-2007, Ext JS, LLC.
28040 * Originally Released Under LGPL - original licence link has changed is not relivant.
28043 * <script type="text/javascript">
28046 * @class Roo.form.DisplayField
28047 * @extends Roo.form.Field
28048 * A generic Field to display non-editable data.
28050 * Creates a new Display Field item.
28051 * @param {Object} config Configuration options
28053 Roo.form.DisplayField = function(config){
28054 Roo.form.DisplayField.superclass.constructor.call(this, config);
28058 Roo.extend(Roo.form.DisplayField, Roo.form.TextField, {
28059 inputType: 'hidden',
28065 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
28067 focusClass : undefined,
28069 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
28071 fieldClass: 'x-form-field',
28074 * @cfg {Function} valueRenderer The renderer for the field (so you can reformat output). should return raw HTML
28076 valueRenderer: undefined,
28080 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
28081 * {tag: "input", type: "checkbox", autocomplete: "off"})
28084 // defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
28086 onResize : function(){
28087 Roo.form.DisplayField.superclass.onResize.apply(this, arguments);
28091 initEvents : function(){
28092 // Roo.form.Checkbox.superclass.initEvents.call(this);
28093 // has no events...
28098 getResizeEl : function(){
28102 getPositionEl : function(){
28107 onRender : function(ct, position){
28109 Roo.form.DisplayField.superclass.onRender.call(this, ct, position);
28110 //if(this.inputValue !== undefined){
28111 this.wrap = this.el.wrap();
28113 this.viewEl = this.wrap.createChild({ tag: 'div'});
28115 if (this.bodyStyle) {
28116 this.viewEl.applyStyles(this.bodyStyle);
28118 //this.viewEl.setStyle('padding', '2px');
28120 this.setValue(this.value);
28125 initValue : Roo.emptyFn,
28130 onClick : function(){
28135 * Sets the checked state of the checkbox.
28136 * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
28138 setValue : function(v){
28140 var html = this.valueRenderer ? this.valueRenderer(v) : String.format('{0}', v);
28141 // this might be called before we have a dom element..
28142 if (!this.viewEl) {
28145 this.viewEl.dom.innerHTML = html;
28146 Roo.form.DisplayField.superclass.setValue.call(this, v);
28149 });//<script type="text/javasscript">
28153 * @class Roo.DDView
28154 * A DnD enabled version of Roo.View.
28155 * @param {Element/String} container The Element in which to create the View.
28156 * @param {String} tpl The template string used to create the markup for each element of the View
28157 * @param {Object} config The configuration properties. These include all the config options of
28158 * {@link Roo.View} plus some specific to this class.<br>
28160 * Drag/drop is implemented by adding {@link Roo.data.Record}s to the target DDView. If copying is
28161 * not being performed, the original {@link Roo.data.Record} is removed from the source DDView.<br>
28163 * The following extra CSS rules are needed to provide insertion point highlighting:<pre><code>
28164 .x-view-drag-insert-above {
28165 border-top:1px dotted #3366cc;
28167 .x-view-drag-insert-below {
28168 border-bottom:1px dotted #3366cc;
28174 Roo.DDView = function(container, tpl, config) {
28175 Roo.DDView.superclass.constructor.apply(this, arguments);
28176 this.getEl().setStyle("outline", "0px none");
28177 this.getEl().unselectable();
28178 if (this.dragGroup) {
28179 this.setDraggable(this.dragGroup.split(","));
28181 if (this.dropGroup) {
28182 this.setDroppable(this.dropGroup.split(","));
28184 if (this.deletable) {
28185 this.setDeletable();
28187 this.isDirtyFlag = false;
28193 Roo.extend(Roo.DDView, Roo.View, {
28194 /** @cfg {String/Array} dragGroup The ddgroup name(s) for the View's DragZone. */
28195 /** @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone. */
28196 /** @cfg {Boolean} copy Causes drag operations to copy nodes rather than move. */
28197 /** @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move. */
28201 reset: Roo.emptyFn,
28203 clearInvalid: Roo.form.Field.prototype.clearInvalid,
28205 validate: function() {
28209 destroy: function() {
28210 this.purgeListeners();
28211 this.getEl.removeAllListeners();
28212 this.getEl().remove();
28213 if (this.dragZone) {
28214 if (this.dragZone.destroy) {
28215 this.dragZone.destroy();
28218 if (this.dropZone) {
28219 if (this.dropZone.destroy) {
28220 this.dropZone.destroy();
28225 /** Allows this class to be an Roo.form.Field so it can be found using {@link Roo.form.BasicForm#findField}. */
28226 getName: function() {
28230 /** Loads the View from a JSON string representing the Records to put into the Store. */
28231 setValue: function(v) {
28233 throw "DDView.setValue(). DDView must be constructed with a valid Store";
28236 data[this.store.reader.meta.root] = v ? [].concat(v) : [];
28237 this.store.proxy = new Roo.data.MemoryProxy(data);
28241 /** @return {String} a parenthesised list of the ids of the Records in the View. */
28242 getValue: function() {
28244 this.store.each(function(rec) {
28245 result += rec.id + ',';
28247 return result.substr(0, result.length - 1) + ')';
28250 getIds: function() {
28251 var i = 0, result = new Array(this.store.getCount());
28252 this.store.each(function(rec) {
28253 result[i++] = rec.id;
28258 isDirty: function() {
28259 return this.isDirtyFlag;
28263 * Part of the Roo.dd.DropZone interface. If no target node is found, the
28264 * whole Element becomes the target, and this causes the drop gesture to append.
28266 getTargetFromEvent : function(e) {
28267 var target = e.getTarget();
28268 while ((target !== null) && (target.parentNode != this.el.dom)) {
28269 target = target.parentNode;
28272 target = this.el.dom.lastChild || this.el.dom;
28278 * Create the drag data which consists of an object which has the property "ddel" as
28279 * the drag proxy element.
28281 getDragData : function(e) {
28282 var target = this.findItemFromChild(e.getTarget());
28284 this.handleSelection(e);
28285 var selNodes = this.getSelectedNodes();
28288 copy: this.copy || (this.allowCopy && e.ctrlKey),
28292 var selectedIndices = this.getSelectedIndexes();
28293 for (var i = 0; i < selectedIndices.length; i++) {
28294 dragData.records.push(this.store.getAt(selectedIndices[i]));
28296 if (selNodes.length == 1) {
28297 dragData.ddel = target.cloneNode(true); // the div element
28299 var div = document.createElement('div'); // create the multi element drag "ghost"
28300 div.className = 'multi-proxy';
28301 for (var i = 0, len = selNodes.length; i < len; i++) {
28302 div.appendChild(selNodes[i].cloneNode(true));
28304 dragData.ddel = div;
28306 //console.log(dragData)
28307 //console.log(dragData.ddel.innerHTML)
28310 //console.log('nodragData')
28314 /** Specify to which ddGroup items in this DDView may be dragged. */
28315 setDraggable: function(ddGroup) {
28316 if (ddGroup instanceof Array) {
28317 Roo.each(ddGroup, this.setDraggable, this);
28320 if (this.dragZone) {
28321 this.dragZone.addToGroup(ddGroup);
28323 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
28324 containerScroll: true,
28328 // Draggability implies selection. DragZone's mousedown selects the element.
28329 if (!this.multiSelect) { this.singleSelect = true; }
28331 // Wire the DragZone's handlers up to methods in *this*
28332 this.dragZone.getDragData = this.getDragData.createDelegate(this);
28336 /** Specify from which ddGroup this DDView accepts drops. */
28337 setDroppable: function(ddGroup) {
28338 if (ddGroup instanceof Array) {
28339 Roo.each(ddGroup, this.setDroppable, this);
28342 if (this.dropZone) {
28343 this.dropZone.addToGroup(ddGroup);
28345 this.dropZone = new Roo.dd.DropZone(this.getEl(), {
28346 containerScroll: true,
28350 // Wire the DropZone's handlers up to methods in *this*
28351 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
28352 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
28353 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
28354 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
28355 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
28359 /** Decide whether to drop above or below a View node. */
28360 getDropPoint : function(e, n, dd){
28361 if (n == this.el.dom) { return "above"; }
28362 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
28363 var c = t + (b - t) / 2;
28364 var y = Roo.lib.Event.getPageY(e);
28372 onNodeEnter : function(n, dd, e, data){
28376 onNodeOver : function(n, dd, e, data){
28377 var pt = this.getDropPoint(e, n, dd);
28378 // set the insert point style on the target node
28379 var dragElClass = this.dropNotAllowed;
28382 if (pt == "above"){
28383 dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
28384 targetElClass = "x-view-drag-insert-above";
28386 dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
28387 targetElClass = "x-view-drag-insert-below";
28389 if (this.lastInsertClass != targetElClass){
28390 Roo.fly(n).replaceClass(this.lastInsertClass, targetElClass);
28391 this.lastInsertClass = targetElClass;
28394 return dragElClass;
28397 onNodeOut : function(n, dd, e, data){
28398 this.removeDropIndicators(n);
28401 onNodeDrop : function(n, dd, e, data){
28402 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
28405 var pt = this.getDropPoint(e, n, dd);
28406 var insertAt = (n == this.el.dom) ? this.nodes.length : n.nodeIndex;
28407 if (pt == "below") { insertAt++; }
28408 for (var i = 0; i < data.records.length; i++) {
28409 var r = data.records[i];
28410 var dup = this.store.getById(r.id);
28411 if (dup && (dd != this.dragZone)) {
28412 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
28415 this.store.insert(insertAt++, r.copy());
28417 data.source.isDirtyFlag = true;
28419 this.store.insert(insertAt++, r);
28421 this.isDirtyFlag = true;
28424 this.dragZone.cachedTarget = null;
28428 removeDropIndicators : function(n){
28430 Roo.fly(n).removeClass([
28431 "x-view-drag-insert-above",
28432 "x-view-drag-insert-below"]);
28433 this.lastInsertClass = "_noclass";
28438 * Utility method. Add a delete option to the DDView's context menu.
28439 * @param {String} imageUrl The URL of the "delete" icon image.
28441 setDeletable: function(imageUrl) {
28442 if (!this.singleSelect && !this.multiSelect) {
28443 this.singleSelect = true;
28445 var c = this.getContextMenu();
28446 this.contextMenu.on("itemclick", function(item) {
28449 this.remove(this.getSelectedIndexes());
28453 this.contextMenu.add({
28460 /** Return the context menu for this DDView. */
28461 getContextMenu: function() {
28462 if (!this.contextMenu) {
28463 // Create the View's context menu
28464 this.contextMenu = new Roo.menu.Menu({
28465 id: this.id + "-contextmenu"
28467 this.el.on("contextmenu", this.showContextMenu, this);
28469 return this.contextMenu;
28472 disableContextMenu: function() {
28473 if (this.contextMenu) {
28474 this.el.un("contextmenu", this.showContextMenu, this);
28478 showContextMenu: function(e, item) {
28479 item = this.findItemFromChild(e.getTarget());
28482 this.select(this.getNode(item), this.multiSelect && e.ctrlKey, true);
28483 this.contextMenu.showAt(e.getXY());
28488 * Remove {@link Roo.data.Record}s at the specified indices.
28489 * @param {Array/Number} selectedIndices The index (or Array of indices) of Records to remove.
28491 remove: function(selectedIndices) {
28492 selectedIndices = [].concat(selectedIndices);
28493 for (var i = 0; i < selectedIndices.length; i++) {
28494 var rec = this.store.getAt(selectedIndices[i]);
28495 this.store.remove(rec);
28500 * Double click fires the event, but also, if this is draggable, and there is only one other
28501 * related DropZone, it transfers the selected node.
28503 onDblClick : function(e){
28504 var item = this.findItemFromChild(e.getTarget());
28506 if (this.fireEvent("dblclick", this, this.indexOf(item), item, e) === false) {
28509 if (this.dragGroup) {
28510 var targets = Roo.dd.DragDropMgr.getRelated(this.dragZone, true);
28511 while (targets.indexOf(this.dropZone) > -1) {
28512 targets.remove(this.dropZone);
28514 if (targets.length == 1) {
28515 this.dragZone.cachedTarget = null;
28516 var el = Roo.get(targets[0].getEl());
28517 var box = el.getBox(true);
28518 targets[0].onNodeDrop(el.dom, {
28520 xy: [box.x, box.y + box.height - 1]
28521 }, null, this.getDragData(e));
28527 handleSelection: function(e) {
28528 this.dragZone.cachedTarget = null;
28529 var item = this.findItemFromChild(e.getTarget());
28531 this.clearSelections(true);
28534 if (item && (this.multiSelect || this.singleSelect)){
28535 if(this.multiSelect && e.shiftKey && (!e.ctrlKey) && this.lastSelection){
28536 this.select(this.getNodes(this.indexOf(this.lastSelection), item.nodeIndex), false);
28537 }else if (this.isSelected(this.getNode(item)) && e.ctrlKey){
28538 this.unselect(item);
28540 this.select(item, this.multiSelect && e.ctrlKey);
28541 this.lastSelection = item;
28546 onItemClick : function(item, index, e){
28547 if(this.fireEvent("beforeclick", this, index, item, e) === false){
28553 unselect : function(nodeInfo, suppressEvent){
28554 var node = this.getNode(nodeInfo);
28555 if(node && this.isSelected(node)){
28556 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
28557 Roo.fly(node).removeClass(this.selectedClass);
28558 this.selections.remove(node);
28559 if(!suppressEvent){
28560 this.fireEvent("selectionchange", this, this.selections);
28568 * Ext JS Library 1.1.1
28569 * Copyright(c) 2006-2007, Ext JS, LLC.
28571 * Originally Released Under LGPL - original licence link has changed is not relivant.
28574 * <script type="text/javascript">
28578 * @class Roo.LayoutManager
28579 * @extends Roo.util.Observable
28580 * Base class for layout managers.
28582 Roo.LayoutManager = function(container, config){
28583 Roo.LayoutManager.superclass.constructor.call(this);
28584 this.el = Roo.get(container);
28585 // ie scrollbar fix
28586 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
28587 document.body.scroll = "no";
28588 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
28589 this.el.position('relative');
28591 this.id = this.el.id;
28592 this.el.addClass("x-layout-container");
28593 /** false to disable window resize monitoring @type Boolean */
28594 this.monitorWindowResize = true;
28599 * Fires when a layout is performed.
28600 * @param {Roo.LayoutManager} this
28604 * @event regionresized
28605 * Fires when the user resizes a region.
28606 * @param {Roo.LayoutRegion} region The resized region
28607 * @param {Number} newSize The new size (width for east/west, height for north/south)
28609 "regionresized" : true,
28611 * @event regioncollapsed
28612 * Fires when a region is collapsed.
28613 * @param {Roo.LayoutRegion} region The collapsed region
28615 "regioncollapsed" : true,
28617 * @event regionexpanded
28618 * Fires when a region is expanded.
28619 * @param {Roo.LayoutRegion} region The expanded region
28621 "regionexpanded" : true
28623 this.updating = false;
28624 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
28627 Roo.extend(Roo.LayoutManager, Roo.util.Observable, {
28629 * Returns true if this layout is currently being updated
28630 * @return {Boolean}
28632 isUpdating : function(){
28633 return this.updating;
28637 * Suspend the LayoutManager from doing auto-layouts while
28638 * making multiple add or remove calls
28640 beginUpdate : function(){
28641 this.updating = true;
28645 * Restore auto-layouts and optionally disable the manager from performing a layout
28646 * @param {Boolean} noLayout true to disable a layout update
28648 endUpdate : function(noLayout){
28649 this.updating = false;
28655 layout: function(){
28659 onRegionResized : function(region, newSize){
28660 this.fireEvent("regionresized", region, newSize);
28664 onRegionCollapsed : function(region){
28665 this.fireEvent("regioncollapsed", region);
28668 onRegionExpanded : function(region){
28669 this.fireEvent("regionexpanded", region);
28673 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
28674 * performs box-model adjustments.
28675 * @return {Object} The size as an object {width: (the width), height: (the height)}
28677 getViewSize : function(){
28679 if(this.el.dom != document.body){
28680 size = this.el.getSize();
28682 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
28684 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
28685 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
28690 * Returns the Element this layout is bound to.
28691 * @return {Roo.Element}
28693 getEl : function(){
28698 * Returns the specified region.
28699 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
28700 * @return {Roo.LayoutRegion}
28702 getRegion : function(target){
28703 return this.regions[target.toLowerCase()];
28706 onWindowResize : function(){
28707 if(this.monitorWindowResize){
28713 * Ext JS Library 1.1.1
28714 * Copyright(c) 2006-2007, Ext JS, LLC.
28716 * Originally Released Under LGPL - original licence link has changed is not relivant.
28719 * <script type="text/javascript">
28722 * @class Roo.BorderLayout
28723 * @extends Roo.LayoutManager
28724 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
28725 * please see: <br><br>
28726 * <a href="http://www.jackslocum.com/yui/2006/10/19/cross-browser-web-20-layouts-with-yahoo-ui/">Cross Browser Layouts - Part 1</a><br>
28727 * <a href="http://www.jackslocum.com/yui/2006/10/28/cross-browser-web-20-layouts-part-2-ajax-feed-viewer-20/">Cross Browser Layouts - Part 2</a><br><br>
28730 var layout = new Roo.BorderLayout(document.body, {
28764 preferredTabWidth: 150
28769 var CP = Roo.ContentPanel;
28771 layout.beginUpdate();
28772 layout.add("north", new CP("north", "North"));
28773 layout.add("south", new CP("south", {title: "South", closable: true}));
28774 layout.add("west", new CP("west", {title: "West"}));
28775 layout.add("east", new CP("autoTabs", {title: "Auto Tabs", closable: true}));
28776 layout.add("center", new CP("center1", {title: "Close Me", closable: true}));
28777 layout.add("center", new CP("center2", {title: "Center Panel", closable: false}));
28778 layout.getRegion("center").showPanel("center1");
28779 layout.endUpdate();
28782 <b>The container the layout is rendered into can be either the body element or any other element.
28783 If it is not the body element, the container needs to either be an absolute positioned element,
28784 or you will need to add "position:relative" to the css of the container. You will also need to specify
28785 the container size if it is not the body element.</b>
28788 * Create a new BorderLayout
28789 * @param {String/HTMLElement/Element} container The container this layout is bound to
28790 * @param {Object} config Configuration options
28792 Roo.BorderLayout = function(container, config){
28793 config = config || {};
28794 Roo.BorderLayout.superclass.constructor.call(this, container, config);
28795 this.factory = config.factory || Roo.BorderLayout.RegionFactory;
28796 for(var i = 0, len = this.factory.validRegions.length; i < len; i++) {
28797 var target = this.factory.validRegions[i];
28798 if(config[target]){
28799 this.addRegion(target, config[target]);
28804 Roo.extend(Roo.BorderLayout, Roo.LayoutManager, {
28806 * Creates and adds a new region if it doesn't already exist.
28807 * @param {String} target The target region key (north, south, east, west or center).
28808 * @param {Object} config The regions config object
28809 * @return {BorderLayoutRegion} The new region
28811 addRegion : function(target, config){
28812 if(!this.regions[target]){
28813 var r = this.factory.create(target, this, config);
28814 this.bindRegion(target, r);
28816 return this.regions[target];
28820 bindRegion : function(name, r){
28821 this.regions[name] = r;
28822 r.on("visibilitychange", this.layout, this);
28823 r.on("paneladded", this.layout, this);
28824 r.on("panelremoved", this.layout, this);
28825 r.on("invalidated", this.layout, this);
28826 r.on("resized", this.onRegionResized, this);
28827 r.on("collapsed", this.onRegionCollapsed, this);
28828 r.on("expanded", this.onRegionExpanded, this);
28832 * Performs a layout update.
28834 layout : function(){
28835 if(this.updating) return;
28836 var size = this.getViewSize();
28837 var w = size.width;
28838 var h = size.height;
28843 //var x = 0, y = 0;
28845 var rs = this.regions;
28846 var north = rs["north"];
28847 var south = rs["south"];
28848 var west = rs["west"];
28849 var east = rs["east"];
28850 var center = rs["center"];
28851 //if(this.hideOnLayout){ // not supported anymore
28852 //c.el.setStyle("display", "none");
28854 if(north && north.isVisible()){
28855 var b = north.getBox();
28856 var m = north.getMargins();
28857 b.width = w - (m.left+m.right);
28860 centerY = b.height + b.y + m.bottom;
28861 centerH -= centerY;
28862 north.updateBox(this.safeBox(b));
28864 if(south && south.isVisible()){
28865 var b = south.getBox();
28866 var m = south.getMargins();
28867 b.width = w - (m.left+m.right);
28869 var totalHeight = (b.height + m.top + m.bottom);
28870 b.y = h - totalHeight + m.top;
28871 centerH -= totalHeight;
28872 south.updateBox(this.safeBox(b));
28874 if(west && west.isVisible()){
28875 var b = west.getBox();
28876 var m = west.getMargins();
28877 b.height = centerH - (m.top+m.bottom);
28879 b.y = centerY + m.top;
28880 var totalWidth = (b.width + m.left + m.right);
28881 centerX += totalWidth;
28882 centerW -= totalWidth;
28883 west.updateBox(this.safeBox(b));
28885 if(east && east.isVisible()){
28886 var b = east.getBox();
28887 var m = east.getMargins();
28888 b.height = centerH - (m.top+m.bottom);
28889 var totalWidth = (b.width + m.left + m.right);
28890 b.x = w - totalWidth + m.left;
28891 b.y = centerY + m.top;
28892 centerW -= totalWidth;
28893 east.updateBox(this.safeBox(b));
28896 var m = center.getMargins();
28898 x: centerX + m.left,
28899 y: centerY + m.top,
28900 width: centerW - (m.left+m.right),
28901 height: centerH - (m.top+m.bottom)
28903 //if(this.hideOnLayout){
28904 //center.el.setStyle("display", "block");
28906 center.updateBox(this.safeBox(centerBox));
28909 this.fireEvent("layout", this);
28913 safeBox : function(box){
28914 box.width = Math.max(0, box.width);
28915 box.height = Math.max(0, box.height);
28920 * Adds a ContentPanel (or subclass) to this layout.
28921 * @param {String} target The target region key (north, south, east, west or center).
28922 * @param {Roo.ContentPanel} panel The panel to add
28923 * @return {Roo.ContentPanel} The added panel
28925 add : function(target, panel){
28927 target = target.toLowerCase();
28928 return this.regions[target].add(panel);
28932 * Remove a ContentPanel (or subclass) to this layout.
28933 * @param {String} target The target region key (north, south, east, west or center).
28934 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
28935 * @return {Roo.ContentPanel} The removed panel
28937 remove : function(target, panel){
28938 target = target.toLowerCase();
28939 return this.regions[target].remove(panel);
28943 * Searches all regions for a panel with the specified id
28944 * @param {String} panelId
28945 * @return {Roo.ContentPanel} The panel or null if it wasn't found
28947 findPanel : function(panelId){
28948 var rs = this.regions;
28949 for(var target in rs){
28950 if(typeof rs[target] != "function"){
28951 var p = rs[target].getPanel(panelId);
28961 * Searches all regions for a panel with the specified id and activates (shows) it.
28962 * @param {String/ContentPanel} panelId The panels id or the panel itself
28963 * @return {Roo.ContentPanel} The shown panel or null
28965 showPanel : function(panelId) {
28966 var rs = this.regions;
28967 for(var target in rs){
28968 var r = rs[target];
28969 if(typeof r != "function"){
28970 if(r.hasPanel(panelId)){
28971 return r.showPanel(panelId);
28979 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
28980 * @param {Roo.state.Provider} provider (optional) An alternate state provider
28982 restoreState : function(provider){
28984 provider = Roo.state.Manager;
28986 var sm = new Roo.LayoutStateManager();
28987 sm.init(this, provider);
28991 * Adds a batch of multiple ContentPanels dynamically by passing a special regions config object. This config
28992 * object should contain properties for each region to add ContentPanels to, and each property's value should be
28993 * a valid ContentPanel config object. Example:
28995 // Create the main layout
28996 var layout = new Roo.BorderLayout('main-ct', {
29007 // Create and add multiple ContentPanels at once via configs
29010 id: 'source-files',
29012 title:'Ext Source Files',
29025 * @param {Object} regions An object containing ContentPanel configs by region name
29027 batchAdd : function(regions){
29028 this.beginUpdate();
29029 for(var rname in regions){
29030 var lr = this.regions[rname];
29032 this.addTypedPanels(lr, regions[rname]);
29039 addTypedPanels : function(lr, ps){
29040 if(typeof ps == 'string'){
29041 lr.add(new Roo.ContentPanel(ps));
29043 else if(ps instanceof Array){
29044 for(var i =0, len = ps.length; i < len; i++){
29045 this.addTypedPanels(lr, ps[i]);
29048 else if(!ps.events){ // raw config?
29050 delete ps.el; // prevent conflict
29051 lr.add(new Roo.ContentPanel(el || Roo.id(), ps));
29053 else { // panel object assumed!
29058 * Adds a xtype elements to the layout.
29062 xtype : 'ContentPanel',
29069 xtype : 'NestedLayoutPanel',
29075 items : [ ... list of content panels or nested layout panels.. ]
29079 * @param {Object} cfg Xtype definition of item to add.
29081 addxtype : function(cfg)
29083 // basically accepts a pannel...
29084 // can accept a layout region..!?!?
29085 // console.log('BorderLayout add ' + cfg.xtype)
29087 if (!cfg.xtype.match(/Panel$/)) {
29091 var region = cfg.region;
29097 xitems = cfg.items;
29104 case 'ContentPanel': // ContentPanel (el, cfg)
29105 case 'ScrollPanel': // ContentPanel (el, cfg)
29106 if(cfg.autoCreate) {
29107 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
29109 var el = this.el.createChild();
29110 ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
29113 this.add(region, ret);
29117 case 'TreePanel': // our new panel!
29118 cfg.el = this.el.createChild();
29119 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
29120 this.add(region, ret);
29123 case 'NestedLayoutPanel':
29124 // create a new Layout (which is a Border Layout...
29125 var el = this.el.createChild();
29126 var clayout = cfg.layout;
29128 clayout.items = clayout.items || [];
29129 // replace this exitems with the clayout ones..
29130 xitems = clayout.items;
29133 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
29134 cfg.background = false;
29136 var layout = new Roo.BorderLayout(el, clayout);
29138 ret = new Roo[cfg.xtype](layout, cfg); // new panel!!!!!
29139 //console.log('adding nested layout panel ' + cfg.toSource());
29140 this.add(region, ret);
29146 // needs grid and region
29148 //var el = this.getRegion(region).el.createChild();
29149 var el = this.el.createChild();
29150 // create the grid first...
29152 var grid = new Roo.grid[cfg.grid.xtype](el, cfg.grid);
29154 if (region == 'center' && this.active ) {
29155 cfg.background = false;
29157 ret = new Roo[cfg.xtype](grid, cfg); // new panel!!!!!
29159 this.add(region, ret);
29160 if (cfg.background) {
29161 ret.on('activate', function(gp) {
29162 if (!gp.grid.rendered) {
29175 alert("Can not add '" + cfg.xtype + "' to BorderLayout");
29177 // GridPanel (grid, cfg)
29180 this.beginUpdate();
29182 Roo.each(xitems, function(i) {
29192 * Shortcut for creating a new BorderLayout object and adding one or more ContentPanels to it in a single step, handling
29193 * the beginUpdate and endUpdate calls internally. The key to this method is the <b>panels</b> property that can be
29194 * provided with each region config, which allows you to add ContentPanel configs in addition to the region configs
29195 * during creation. The following code is equivalent to the constructor-based example at the beginning of this class:
29198 var CP = Roo.ContentPanel;
29200 var layout = Roo.BorderLayout.create({
29204 panels: [new CP("north", "North")]
29213 panels: [new CP("west", {title: "West"})]
29222 panels: [new CP("autoTabs", {title: "Auto Tabs", closable: true})]
29231 panels: [new CP("south", {title: "South", closable: true})]
29238 preferredTabWidth: 150,
29240 new CP("center1", {title: "Close Me", closable: true}),
29241 new CP("center2", {title: "Center Panel", closable: false})
29246 layout.getRegion("center").showPanel("center1");
29251 Roo.BorderLayout.create = function(config, targetEl){
29252 var layout = new Roo.BorderLayout(targetEl || document.body, config);
29253 layout.beginUpdate();
29254 var regions = Roo.BorderLayout.RegionFactory.validRegions;
29255 for(var j = 0, jlen = regions.length; j < jlen; j++){
29256 var lr = regions[j];
29257 if(layout.regions[lr] && config[lr].panels){
29258 var r = layout.regions[lr];
29259 var ps = config[lr].panels;
29260 layout.addTypedPanels(r, ps);
29263 layout.endUpdate();
29268 Roo.BorderLayout.RegionFactory = {
29270 validRegions : ["north","south","east","west","center"],
29273 create : function(target, mgr, config){
29274 target = target.toLowerCase();
29275 if(config.lightweight || config.basic){
29276 return new Roo.BasicLayoutRegion(mgr, config, target);
29280 return new Roo.NorthLayoutRegion(mgr, config);
29282 return new Roo.SouthLayoutRegion(mgr, config);
29284 return new Roo.EastLayoutRegion(mgr, config);
29286 return new Roo.WestLayoutRegion(mgr, config);
29288 return new Roo.CenterLayoutRegion(mgr, config);
29290 throw 'Layout region "'+target+'" not supported.';
29294 * Ext JS Library 1.1.1
29295 * Copyright(c) 2006-2007, Ext JS, LLC.
29297 * Originally Released Under LGPL - original licence link has changed is not relivant.
29300 * <script type="text/javascript">
29304 * @class Roo.BasicLayoutRegion
29305 * @extends Roo.util.Observable
29306 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
29307 * and does not have a titlebar, tabs or any other features. All it does is size and position
29308 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
29310 Roo.BasicLayoutRegion = function(mgr, config, pos, skipConfig){
29312 this.position = pos;
29315 * @scope Roo.BasicLayoutRegion
29319 * @event beforeremove
29320 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
29321 * @param {Roo.LayoutRegion} this
29322 * @param {Roo.ContentPanel} panel The panel
29323 * @param {Object} e The cancel event object
29325 "beforeremove" : true,
29327 * @event invalidated
29328 * Fires when the layout for this region is changed.
29329 * @param {Roo.LayoutRegion} this
29331 "invalidated" : true,
29333 * @event visibilitychange
29334 * Fires when this region is shown or hidden
29335 * @param {Roo.LayoutRegion} this
29336 * @param {Boolean} visibility true or false
29338 "visibilitychange" : true,
29340 * @event paneladded
29341 * Fires when a panel is added.
29342 * @param {Roo.LayoutRegion} this
29343 * @param {Roo.ContentPanel} panel The panel
29345 "paneladded" : true,
29347 * @event panelremoved
29348 * Fires when a panel is removed.
29349 * @param {Roo.LayoutRegion} this
29350 * @param {Roo.ContentPanel} panel The panel
29352 "panelremoved" : true,
29355 * Fires when this region is collapsed.
29356 * @param {Roo.LayoutRegion} this
29358 "collapsed" : true,
29361 * Fires when this region is expanded.
29362 * @param {Roo.LayoutRegion} this
29367 * Fires when this region is slid into view.
29368 * @param {Roo.LayoutRegion} this
29370 "slideshow" : true,
29373 * Fires when this region slides out of view.
29374 * @param {Roo.LayoutRegion} this
29376 "slidehide" : true,
29378 * @event panelactivated
29379 * Fires when a panel is activated.
29380 * @param {Roo.LayoutRegion} this
29381 * @param {Roo.ContentPanel} panel The activated panel
29383 "panelactivated" : true,
29386 * Fires when the user resizes this region.
29387 * @param {Roo.LayoutRegion} this
29388 * @param {Number} newSize The new size (width for east/west, height for north/south)
29392 /** A collection of panels in this region. @type Roo.util.MixedCollection */
29393 this.panels = new Roo.util.MixedCollection();
29394 this.panels.getKey = this.getPanelId.createDelegate(this);
29396 this.activePanel = null;
29397 // ensure listeners are added...
29399 if (config.listeners || config.events) {
29400 Roo.BasicLayoutRegion.superclass.constructor.call(this, {
29401 listeners : config.listeners || {},
29402 events : config.events || {}
29406 if(skipConfig !== true){
29407 this.applyConfig(config);
29411 Roo.extend(Roo.BasicLayoutRegion, Roo.util.Observable, {
29412 getPanelId : function(p){
29416 applyConfig : function(config){
29417 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
29418 this.config = config;
29423 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
29424 * the width, for horizontal (north, south) the height.
29425 * @param {Number} newSize The new width or height
29427 resizeTo : function(newSize){
29428 var el = this.el ? this.el :
29429 (this.activePanel ? this.activePanel.getEl() : null);
29431 switch(this.position){
29434 el.setWidth(newSize);
29435 this.fireEvent("resized", this, newSize);
29439 el.setHeight(newSize);
29440 this.fireEvent("resized", this, newSize);
29446 getBox : function(){
29447 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
29450 getMargins : function(){
29451 return this.margins;
29454 updateBox : function(box){
29456 var el = this.activePanel.getEl();
29457 el.dom.style.left = box.x + "px";
29458 el.dom.style.top = box.y + "px";
29459 this.activePanel.setSize(box.width, box.height);
29463 * Returns the container element for this region.
29464 * @return {Roo.Element}
29466 getEl : function(){
29467 return this.activePanel;
29471 * Returns true if this region is currently visible.
29472 * @return {Boolean}
29474 isVisible : function(){
29475 return this.activePanel ? true : false;
29478 setActivePanel : function(panel){
29479 panel = this.getPanel(panel);
29480 if(this.activePanel && this.activePanel != panel){
29481 this.activePanel.setActiveState(false);
29482 this.activePanel.getEl().setLeftTop(-10000,-10000);
29484 this.activePanel = panel;
29485 panel.setActiveState(true);
29487 panel.setSize(this.box.width, this.box.height);
29489 this.fireEvent("panelactivated", this, panel);
29490 this.fireEvent("invalidated");
29494 * Show the specified panel.
29495 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
29496 * @return {Roo.ContentPanel} The shown panel or null
29498 showPanel : function(panel){
29499 if(panel = this.getPanel(panel)){
29500 this.setActivePanel(panel);
29506 * Get the active panel for this region.
29507 * @return {Roo.ContentPanel} The active panel or null
29509 getActivePanel : function(){
29510 return this.activePanel;
29514 * Add the passed ContentPanel(s)
29515 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
29516 * @return {Roo.ContentPanel} The panel added (if only one was added)
29518 add : function(panel){
29519 if(arguments.length > 1){
29520 for(var i = 0, len = arguments.length; i < len; i++) {
29521 this.add(arguments[i]);
29525 if(this.hasPanel(panel)){
29526 this.showPanel(panel);
29529 var el = panel.getEl();
29530 if(el.dom.parentNode != this.mgr.el.dom){
29531 this.mgr.el.dom.appendChild(el.dom);
29533 if(panel.setRegion){
29534 panel.setRegion(this);
29536 this.panels.add(panel);
29537 el.setStyle("position", "absolute");
29538 if(!panel.background){
29539 this.setActivePanel(panel);
29540 if(this.config.initialSize && this.panels.getCount()==1){
29541 this.resizeTo(this.config.initialSize);
29544 this.fireEvent("paneladded", this, panel);
29549 * Returns true if the panel is in this region.
29550 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
29551 * @return {Boolean}
29553 hasPanel : function(panel){
29554 if(typeof panel == "object"){ // must be panel obj
29555 panel = panel.getId();
29557 return this.getPanel(panel) ? true : false;
29561 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
29562 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
29563 * @param {Boolean} preservePanel Overrides the config preservePanel option
29564 * @return {Roo.ContentPanel} The panel that was removed
29566 remove : function(panel, preservePanel){
29567 panel = this.getPanel(panel);
29572 this.fireEvent("beforeremove", this, panel, e);
29573 if(e.cancel === true){
29576 var panelId = panel.getId();
29577 this.panels.removeKey(panelId);
29582 * Returns the panel specified or null if it's not in this region.
29583 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
29584 * @return {Roo.ContentPanel}
29586 getPanel : function(id){
29587 if(typeof id == "object"){ // must be panel obj
29590 return this.panels.get(id);
29594 * Returns this regions position (north/south/east/west/center).
29597 getPosition: function(){
29598 return this.position;
29602 * Ext JS Library 1.1.1
29603 * Copyright(c) 2006-2007, Ext JS, LLC.
29605 * Originally Released Under LGPL - original licence link has changed is not relivant.
29608 * <script type="text/javascript">
29612 * @class Roo.LayoutRegion
29613 * @extends Roo.BasicLayoutRegion
29614 * This class represents a region in a layout manager.
29615 * @cfg {Boolean} collapsible False to disable collapsing (defaults to true)
29616 * @cfg {Boolean} collapsed True to set the initial display to collapsed (defaults to false)
29617 * @cfg {Boolean} floatable False to disable floating (defaults to true)
29618 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
29619 * @cfg {Object} cmargins Margins for the element when collapsed (defaults to: north/south {top: 2, left: 0, right:0, bottom: 2} or east/west {top: 0, left: 2, right:2, bottom: 0})
29620 * @cfg {String} tabPosition "top" or "bottom" (defaults to "bottom")
29621 * @cfg {String} collapsedTitle Optional string message to display in the collapsed block of a north or south region
29622 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
29623 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
29624 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
29625 * @cfg {String} title The title for the region (overrides panel titles)
29626 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
29627 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
29628 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
29629 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
29630 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
29631 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
29632 * the space available, similar to FireFox 1.5 tabs (defaults to false)
29633 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
29634 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
29635 * @cfg {Boolean} showPin True to show a pin button
29636 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
29637 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
29638 * @cfg {Boolean} disableTabTips True to disable tab tooltips
29639 * @cfg {Number} width For East/West panels
29640 * @cfg {Number} height For North/South panels
29641 * @cfg {Boolean} split To show the splitter
29643 Roo.LayoutRegion = function(mgr, config, pos){
29644 Roo.LayoutRegion.superclass.constructor.call(this, mgr, config, pos, true);
29645 var dh = Roo.DomHelper;
29646 /** This region's container element
29647 * @type Roo.Element */
29648 this.el = dh.append(mgr.el.dom, {tag: "div", cls: "x-layout-panel x-layout-panel-" + this.position}, true);
29649 /** This region's title element
29650 * @type Roo.Element */
29652 this.titleEl = dh.append(this.el.dom, {tag: "div", unselectable: "on", cls: "x-unselectable x-layout-panel-hd x-layout-title-"+this.position, children:[
29653 {tag: "span", cls: "x-unselectable x-layout-panel-hd-text", unselectable: "on", html: " "},
29654 {tag: "div", cls: "x-unselectable x-layout-panel-hd-tools", unselectable: "on"}
29656 this.titleEl.enableDisplayMode();
29657 /** This region's title text element
29658 * @type HTMLElement */
29659 this.titleTextEl = this.titleEl.dom.firstChild;
29660 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
29661 this.closeBtn = this.createTool(this.tools.dom, "x-layout-close");
29662 this.closeBtn.enableDisplayMode();
29663 this.closeBtn.on("click", this.closeClicked, this);
29664 this.closeBtn.hide();
29666 this.createBody(config);
29667 this.visible = true;
29668 this.collapsed = false;
29670 if(config.hideWhenEmpty){
29672 this.on("paneladded", this.validateVisibility, this);
29673 this.on("panelremoved", this.validateVisibility, this);
29675 this.applyConfig(config);
29678 Roo.extend(Roo.LayoutRegion, Roo.BasicLayoutRegion, {
29680 createBody : function(){
29681 /** This region's body element
29682 * @type Roo.Element */
29683 this.bodyEl = this.el.createChild({tag: "div", cls: "x-layout-panel-body"});
29686 applyConfig : function(c){
29687 if(c.collapsible && this.position != "center" && !this.collapsedEl){
29688 var dh = Roo.DomHelper;
29689 if(c.titlebar !== false){
29690 this.collapseBtn = this.createTool(this.tools.dom, "x-layout-collapse-"+this.position);
29691 this.collapseBtn.on("click", this.collapse, this);
29692 this.collapseBtn.enableDisplayMode();
29694 if(c.showPin === true || this.showPin){
29695 this.stickBtn = this.createTool(this.tools.dom, "x-layout-stick");
29696 this.stickBtn.enableDisplayMode();
29697 this.stickBtn.on("click", this.expand, this);
29698 this.stickBtn.hide();
29701 /** This region's collapsed element
29702 * @type Roo.Element */
29703 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
29704 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
29706 if(c.floatable !== false){
29707 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
29708 this.collapsedEl.on("click", this.collapseClick, this);
29711 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
29712 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
29713 id: "message", unselectable: "on", style:{"float":"left"}});
29714 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
29716 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
29717 this.expandBtn.on("click", this.expand, this);
29719 if(this.collapseBtn){
29720 this.collapseBtn.setVisible(c.collapsible == true);
29722 this.cmargins = c.cmargins || this.cmargins ||
29723 (this.position == "west" || this.position == "east" ?
29724 {top: 0, left: 2, right:2, bottom: 0} :
29725 {top: 2, left: 0, right:0, bottom: 2});
29726 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
29727 this.bottomTabs = c.tabPosition != "top";
29728 this.autoScroll = c.autoScroll || false;
29729 if(this.autoScroll){
29730 this.bodyEl.setStyle("overflow", "auto");
29732 this.bodyEl.setStyle("overflow", "hidden");
29734 //if(c.titlebar !== false){
29735 if((!c.titlebar && !c.title) || c.titlebar === false){
29736 this.titleEl.hide();
29738 this.titleEl.show();
29740 this.titleTextEl.innerHTML = c.title;
29744 this.duration = c.duration || .30;
29745 this.slideDuration = c.slideDuration || .45;
29748 this.collapse(true);
29755 * Returns true if this region is currently visible.
29756 * @return {Boolean}
29758 isVisible : function(){
29759 return this.visible;
29763 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
29764 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
29766 setCollapsedTitle : function(title){
29767 title = title || " ";
29768 if(this.collapsedTitleTextEl){
29769 this.collapsedTitleTextEl.innerHTML = title;
29773 getBox : function(){
29775 if(!this.collapsed){
29776 b = this.el.getBox(false, true);
29778 b = this.collapsedEl.getBox(false, true);
29783 getMargins : function(){
29784 return this.collapsed ? this.cmargins : this.margins;
29787 highlight : function(){
29788 this.el.addClass("x-layout-panel-dragover");
29791 unhighlight : function(){
29792 this.el.removeClass("x-layout-panel-dragover");
29795 updateBox : function(box){
29797 if(!this.collapsed){
29798 this.el.dom.style.left = box.x + "px";
29799 this.el.dom.style.top = box.y + "px";
29800 this.updateBody(box.width, box.height);
29802 this.collapsedEl.dom.style.left = box.x + "px";
29803 this.collapsedEl.dom.style.top = box.y + "px";
29804 this.collapsedEl.setSize(box.width, box.height);
29807 this.tabs.autoSizeTabs();
29811 updateBody : function(w, h){
29813 this.el.setWidth(w);
29814 w -= this.el.getBorderWidth("rl");
29815 if(this.config.adjustments){
29816 w += this.config.adjustments[0];
29820 this.el.setHeight(h);
29821 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
29822 h -= this.el.getBorderWidth("tb");
29823 if(this.config.adjustments){
29824 h += this.config.adjustments[1];
29826 this.bodyEl.setHeight(h);
29828 h = this.tabs.syncHeight(h);
29831 if(this.panelSize){
29832 w = w !== null ? w : this.panelSize.width;
29833 h = h !== null ? h : this.panelSize.height;
29835 if(this.activePanel){
29836 var el = this.activePanel.getEl();
29837 w = w !== null ? w : el.getWidth();
29838 h = h !== null ? h : el.getHeight();
29839 this.panelSize = {width: w, height: h};
29840 this.activePanel.setSize(w, h);
29842 if(Roo.isIE && this.tabs){
29843 this.tabs.el.repaint();
29848 * Returns the container element for this region.
29849 * @return {Roo.Element}
29851 getEl : function(){
29856 * Hides this region.
29859 if(!this.collapsed){
29860 this.el.dom.style.left = "-2000px";
29863 this.collapsedEl.dom.style.left = "-2000px";
29864 this.collapsedEl.hide();
29866 this.visible = false;
29867 this.fireEvent("visibilitychange", this, false);
29871 * Shows this region if it was previously hidden.
29874 if(!this.collapsed){
29877 this.collapsedEl.show();
29879 this.visible = true;
29880 this.fireEvent("visibilitychange", this, true);
29883 closeClicked : function(){
29884 if(this.activePanel){
29885 this.remove(this.activePanel);
29889 collapseClick : function(e){
29891 e.stopPropagation();
29894 e.stopPropagation();
29900 * Collapses this region.
29901 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
29903 collapse : function(skipAnim){
29904 if(this.collapsed) return;
29905 this.collapsed = true;
29907 this.split.el.hide();
29909 if(this.config.animate && skipAnim !== true){
29910 this.fireEvent("invalidated", this);
29911 this.animateCollapse();
29913 this.el.setLocation(-20000,-20000);
29915 this.collapsedEl.show();
29916 this.fireEvent("collapsed", this);
29917 this.fireEvent("invalidated", this);
29921 animateCollapse : function(){
29926 * Expands this region if it was previously collapsed.
29927 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
29928 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
29930 expand : function(e, skipAnim){
29931 if(e) e.stopPropagation();
29932 if(!this.collapsed || this.el.hasActiveFx()) return;
29934 this.afterSlideIn();
29937 this.collapsed = false;
29938 if(this.config.animate && skipAnim !== true){
29939 this.animateExpand();
29943 this.split.el.show();
29945 this.collapsedEl.setLocation(-2000,-2000);
29946 this.collapsedEl.hide();
29947 this.fireEvent("invalidated", this);
29948 this.fireEvent("expanded", this);
29952 animateExpand : function(){
29956 initTabs : function(){
29957 this.bodyEl.setStyle("overflow", "hidden");
29958 var ts = new Roo.TabPanel(this.bodyEl.dom, {
29959 tabPosition: this.bottomTabs ? 'bottom' : 'top',
29960 disableTooltips: this.config.disableTabTips
29962 if(this.config.hideTabs){
29963 ts.stripWrap.setDisplayed(false);
29966 ts.resizeTabs = this.config.resizeTabs === true;
29967 ts.minTabWidth = this.config.minTabWidth || 40;
29968 ts.maxTabWidth = this.config.maxTabWidth || 250;
29969 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
29970 ts.monitorResize = false;
29971 ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
29972 ts.bodyEl.addClass('x-layout-tabs-body');
29973 this.panels.each(this.initPanelAsTab, this);
29976 initPanelAsTab : function(panel){
29977 var ti = this.tabs.addTab(panel.getEl().id, panel.getTitle(), null,
29978 this.config.closeOnTab && panel.isClosable());
29979 if(panel.tabTip !== undefined){
29980 ti.setTooltip(panel.tabTip);
29982 ti.on("activate", function(){
29983 this.setActivePanel(panel);
29985 if(this.config.closeOnTab){
29986 ti.on("beforeclose", function(t, e){
29988 this.remove(panel);
29994 updatePanelTitle : function(panel, title){
29995 if(this.activePanel == panel){
29996 this.updateTitle(title);
29999 var ti = this.tabs.getTab(panel.getEl().id);
30001 if(panel.tabTip !== undefined){
30002 ti.setTooltip(panel.tabTip);
30007 updateTitle : function(title){
30008 if(this.titleTextEl && !this.config.title){
30009 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
30013 setActivePanel : function(panel){
30014 panel = this.getPanel(panel);
30015 if(this.activePanel && this.activePanel != panel){
30016 this.activePanel.setActiveState(false);
30018 this.activePanel = panel;
30019 panel.setActiveState(true);
30020 if(this.panelSize){
30021 panel.setSize(this.panelSize.width, this.panelSize.height);
30024 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
30026 this.updateTitle(panel.getTitle());
30028 this.fireEvent("invalidated", this);
30030 this.fireEvent("panelactivated", this, panel);
30034 * Shows the specified panel.
30035 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
30036 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
30038 showPanel : function(panel){
30039 if(panel = this.getPanel(panel)){
30041 var tab = this.tabs.getTab(panel.getEl().id);
30042 if(tab.isHidden()){
30043 this.tabs.unhideTab(tab.id);
30047 this.setActivePanel(panel);
30054 * Get the active panel for this region.
30055 * @return {Roo.ContentPanel} The active panel or null
30057 getActivePanel : function(){
30058 return this.activePanel;
30061 validateVisibility : function(){
30062 if(this.panels.getCount() < 1){
30063 this.updateTitle(" ");
30064 this.closeBtn.hide();
30067 if(!this.isVisible()){
30074 * Adds the passed ContentPanel(s) to this region.
30075 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
30076 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
30078 add : function(panel){
30079 if(arguments.length > 1){
30080 for(var i = 0, len = arguments.length; i < len; i++) {
30081 this.add(arguments[i]);
30085 if(this.hasPanel(panel)){
30086 this.showPanel(panel);
30089 panel.setRegion(this);
30090 this.panels.add(panel);
30091 if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
30092 this.bodyEl.dom.appendChild(panel.getEl().dom);
30093 if(panel.background !== true){
30094 this.setActivePanel(panel);
30096 this.fireEvent("paneladded", this, panel);
30102 this.initPanelAsTab(panel);
30104 if(panel.background !== true){
30105 this.tabs.activate(panel.getEl().id);
30107 this.fireEvent("paneladded", this, panel);
30112 * Hides the tab for the specified panel.
30113 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30115 hidePanel : function(panel){
30116 if(this.tabs && (panel = this.getPanel(panel))){
30117 this.tabs.hideTab(panel.getEl().id);
30122 * Unhides the tab for a previously hidden panel.
30123 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30125 unhidePanel : function(panel){
30126 if(this.tabs && (panel = this.getPanel(panel))){
30127 this.tabs.unhideTab(panel.getEl().id);
30131 clearPanels : function(){
30132 while(this.panels.getCount() > 0){
30133 this.remove(this.panels.first());
30138 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
30139 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
30140 * @param {Boolean} preservePanel Overrides the config preservePanel option
30141 * @return {Roo.ContentPanel} The panel that was removed
30143 remove : function(panel, preservePanel){
30144 panel = this.getPanel(panel);
30149 this.fireEvent("beforeremove", this, panel, e);
30150 if(e.cancel === true){
30153 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
30154 var panelId = panel.getId();
30155 this.panels.removeKey(panelId);
30157 document.body.appendChild(panel.getEl().dom);
30160 this.tabs.removeTab(panel.getEl().id);
30161 }else if (!preservePanel){
30162 this.bodyEl.dom.removeChild(panel.getEl().dom);
30164 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
30165 var p = this.panels.first();
30166 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
30167 tempEl.appendChild(p.getEl().dom);
30168 this.bodyEl.update("");
30169 this.bodyEl.dom.appendChild(p.getEl().dom);
30171 this.updateTitle(p.getTitle());
30173 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
30174 this.setActivePanel(p);
30176 panel.setRegion(null);
30177 if(this.activePanel == panel){
30178 this.activePanel = null;
30180 if(this.config.autoDestroy !== false && preservePanel !== true){
30181 try{panel.destroy();}catch(e){}
30183 this.fireEvent("panelremoved", this, panel);
30188 * Returns the TabPanel component used by this region
30189 * @return {Roo.TabPanel}
30191 getTabs : function(){
30195 createTool : function(parentEl, className){
30196 var btn = Roo.DomHelper.append(parentEl, {tag: "div", cls: "x-layout-tools-button",
30197 children: [{tag: "div", cls: "x-layout-tools-button-inner " + className, html: " "}]}, true);
30198 btn.addClassOnOver("x-layout-tools-button-over");
30203 * Ext JS Library 1.1.1
30204 * Copyright(c) 2006-2007, Ext JS, LLC.
30206 * Originally Released Under LGPL - original licence link has changed is not relivant.
30209 * <script type="text/javascript">
30215 * @class Roo.SplitLayoutRegion
30216 * @extends Roo.LayoutRegion
30217 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
30219 Roo.SplitLayoutRegion = function(mgr, config, pos, cursor){
30220 this.cursor = cursor;
30221 Roo.SplitLayoutRegion.superclass.constructor.call(this, mgr, config, pos);
30224 Roo.extend(Roo.SplitLayoutRegion, Roo.LayoutRegion, {
30225 splitTip : "Drag to resize.",
30226 collapsibleSplitTip : "Drag to resize. Double click to hide.",
30227 useSplitTips : false,
30229 applyConfig : function(config){
30230 Roo.SplitLayoutRegion.superclass.applyConfig.call(this, config);
30233 var splitEl = Roo.DomHelper.append(this.mgr.el.dom,
30234 {tag: "div", id: this.el.id + "-split", cls: "x-layout-split x-layout-split-"+this.position, html: " "});
30235 /** The SplitBar for this region
30236 * @type Roo.SplitBar */
30237 this.split = new Roo.SplitBar(splitEl, this.el, this.orientation);
30238 this.split.on("moved", this.onSplitMove, this);
30239 this.split.useShim = config.useShim === true;
30240 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
30241 if(this.useSplitTips){
30242 this.split.el.dom.title = config.collapsible ? this.collapsibleSplitTip : this.splitTip;
30244 if(config.collapsible){
30245 this.split.el.on("dblclick", this.collapse, this);
30248 if(typeof config.minSize != "undefined"){
30249 this.split.minSize = config.minSize;
30251 if(typeof config.maxSize != "undefined"){
30252 this.split.maxSize = config.maxSize;
30254 if(config.hideWhenEmpty || config.hidden || config.collapsed){
30255 this.hideSplitter();
30260 getHMaxSize : function(){
30261 var cmax = this.config.maxSize || 10000;
30262 var center = this.mgr.getRegion("center");
30263 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
30266 getVMaxSize : function(){
30267 var cmax = this.config.maxSize || 10000;
30268 var center = this.mgr.getRegion("center");
30269 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
30272 onSplitMove : function(split, newSize){
30273 this.fireEvent("resized", this, newSize);
30277 * Returns the {@link Roo.SplitBar} for this region.
30278 * @return {Roo.SplitBar}
30280 getSplitBar : function(){
30285 this.hideSplitter();
30286 Roo.SplitLayoutRegion.superclass.hide.call(this);
30289 hideSplitter : function(){
30291 this.split.el.setLocation(-2000,-2000);
30292 this.split.el.hide();
30298 this.split.el.show();
30300 Roo.SplitLayoutRegion.superclass.show.call(this);
30303 beforeSlide: function(){
30304 if(Roo.isGecko){// firefox overflow auto bug workaround
30305 this.bodyEl.clip();
30306 if(this.tabs) this.tabs.bodyEl.clip();
30307 if(this.activePanel){
30308 this.activePanel.getEl().clip();
30310 if(this.activePanel.beforeSlide){
30311 this.activePanel.beforeSlide();
30317 afterSlide : function(){
30318 if(Roo.isGecko){// firefox overflow auto bug workaround
30319 this.bodyEl.unclip();
30320 if(this.tabs) this.tabs.bodyEl.unclip();
30321 if(this.activePanel){
30322 this.activePanel.getEl().unclip();
30323 if(this.activePanel.afterSlide){
30324 this.activePanel.afterSlide();
30330 initAutoHide : function(){
30331 if(this.autoHide !== false){
30332 if(!this.autoHideHd){
30333 var st = new Roo.util.DelayedTask(this.slideIn, this);
30334 this.autoHideHd = {
30335 "mouseout": function(e){
30336 if(!e.within(this.el, true)){
30340 "mouseover" : function(e){
30346 this.el.on(this.autoHideHd);
30350 clearAutoHide : function(){
30351 if(this.autoHide !== false){
30352 this.el.un("mouseout", this.autoHideHd.mouseout);
30353 this.el.un("mouseover", this.autoHideHd.mouseover);
30357 clearMonitor : function(){
30358 Roo.get(document).un("click", this.slideInIf, this);
30361 // these names are backwards but not changed for compat
30362 slideOut : function(){
30363 if(this.isSlid || this.el.hasActiveFx()){
30366 this.isSlid = true;
30367 if(this.collapseBtn){
30368 this.collapseBtn.hide();
30370 this.closeBtnState = this.closeBtn.getStyle('display');
30371 this.closeBtn.hide();
30373 this.stickBtn.show();
30376 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
30377 this.beforeSlide();
30378 this.el.setStyle("z-index", 10001);
30379 this.el.slideIn(this.getSlideAnchor(), {
30380 callback: function(){
30382 this.initAutoHide();
30383 Roo.get(document).on("click", this.slideInIf, this);
30384 this.fireEvent("slideshow", this);
30391 afterSlideIn : function(){
30392 this.clearAutoHide();
30393 this.isSlid = false;
30394 this.clearMonitor();
30395 this.el.setStyle("z-index", "");
30396 if(this.collapseBtn){
30397 this.collapseBtn.show();
30399 this.closeBtn.setStyle('display', this.closeBtnState);
30401 this.stickBtn.hide();
30403 this.fireEvent("slidehide", this);
30406 slideIn : function(cb){
30407 if(!this.isSlid || this.el.hasActiveFx()){
30411 this.isSlid = false;
30412 this.beforeSlide();
30413 this.el.slideOut(this.getSlideAnchor(), {
30414 callback: function(){
30415 this.el.setLeftTop(-10000, -10000);
30417 this.afterSlideIn();
30425 slideInIf : function(e){
30426 if(!e.within(this.el)){
30431 animateCollapse : function(){
30432 this.beforeSlide();
30433 this.el.setStyle("z-index", 20000);
30434 var anchor = this.getSlideAnchor();
30435 this.el.slideOut(anchor, {
30436 callback : function(){
30437 this.el.setStyle("z-index", "");
30438 this.collapsedEl.slideIn(anchor, {duration:.3});
30440 this.el.setLocation(-10000,-10000);
30442 this.fireEvent("collapsed", this);
30449 animateExpand : function(){
30450 this.beforeSlide();
30451 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
30452 this.el.setStyle("z-index", 20000);
30453 this.collapsedEl.hide({
30456 this.el.slideIn(this.getSlideAnchor(), {
30457 callback : function(){
30458 this.el.setStyle("z-index", "");
30461 this.split.el.show();
30463 this.fireEvent("invalidated", this);
30464 this.fireEvent("expanded", this);
30492 getAnchor : function(){
30493 return this.anchors[this.position];
30496 getCollapseAnchor : function(){
30497 return this.canchors[this.position];
30500 getSlideAnchor : function(){
30501 return this.sanchors[this.position];
30504 getAlignAdj : function(){
30505 var cm = this.cmargins;
30506 switch(this.position){
30522 getExpandAdj : function(){
30523 var c = this.collapsedEl, cm = this.cmargins;
30524 switch(this.position){
30526 return [-(cm.right+c.getWidth()+cm.left), 0];
30529 return [cm.right+c.getWidth()+cm.left, 0];
30532 return [0, -(cm.top+cm.bottom+c.getHeight())];
30535 return [0, cm.top+cm.bottom+c.getHeight()];