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(this.sortInfo && this.remoteSort){
4931 var pn = this.paramNames;
4932 p[pn["sort"]] = this.sortInfo.field;
4933 p[pn["dir"]] = this.sortInfo.direction;
4935 this.proxy.load(p, this.reader, this.loadRecords, this, options);
4940 * Reloads the Record cache from the configured Proxy using the configured Reader and
4941 * the options from the last load operation performed.
4942 * @param {Object} options (optional) An object containing properties which may override the options
4943 * used in the last load operation. See {@link #load} for details (defaults to null, in which case
4944 * the most recently used options are reused).
4946 reload : function(options){
4947 this.load(Roo.applyIf(options||{}, this.lastOptions));
4951 // Called as a callback by the Reader during a load operation.
4952 loadRecords : function(o, options, success){
4953 if(!o || success === false){
4954 if(success !== false){
4955 this.fireEvent("load", this, [], options);
4957 if(options.callback){
4958 options.callback.call(options.scope || this, [], options, false);
4962 // if data returned failure - throw an exception.
4963 if (o.success === false) {
4964 this.fireEvent("loadexception", this, o, options, this.reader.jsonData);
4967 var r = o.records, t = o.totalRecords || r.length;
4968 if(!options || options.add !== true){
4969 if(this.pruneModifiedRecords){
4972 for(var i = 0, len = r.length; i < len; i++){
4976 this.data = this.snapshot;
4977 delete this.snapshot;
4980 this.data.addAll(r);
4981 this.totalLength = t;
4983 this.fireEvent("datachanged", this);
4985 this.totalLength = Math.max(t, this.data.length+r.length);
4988 this.fireEvent("load", this, r, options);
4989 if(options.callback){
4990 options.callback.call(options.scope || this, r, options, true);
4995 * Loads data from a passed data block. A Reader which understands the format of the data
4996 * must have been configured in the constructor.
4997 * @param {Object} data The data block from which to read the Records. The format of the data expected
4998 * is dependent on the type of Reader that is configured and should correspond to that Reader's readRecords parameter.
4999 * @param {Boolean} append (Optional) True to append the new Records rather than replace the existing cache.
5001 loadData : function(o, append){
5002 var r = this.reader.readRecords(o);
5003 this.loadRecords(r, {add: append}, true);
5007 * Gets the number of cached records.
5009 * <em>If using paging, this may not be the total size of the dataset. If the data object
5010 * used by the Reader contains the dataset size, then the getTotalCount() function returns
5011 * the data set size</em>
5013 getCount : function(){
5014 return this.data.length || 0;
5018 * Gets the total number of records in the dataset as returned by the server.
5020 * <em>If using paging, for this to be accurate, the data object used by the Reader must contain
5021 * the dataset size</em>
5023 getTotalCount : function(){
5024 return this.totalLength || 0;
5028 * Returns the sort state of the Store as an object with two properties:
5030 field {String} The name of the field by which the Records are sorted
5031 direction {String} The sort order, "ASC" or "DESC"
5034 getSortState : function(){
5035 return this.sortInfo;
5039 applySort : function(){
5040 if(this.sortInfo && !this.remoteSort){
5041 var s = this.sortInfo, f = s.field;
5042 var st = this.fields.get(f).sortType;
5043 var fn = function(r1, r2){
5044 var v1 = st(r1.data[f]), v2 = st(r2.data[f]);
5045 return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
5047 this.data.sort(s.direction, fn);
5048 if(this.snapshot && this.snapshot != this.data){
5049 this.snapshot.sort(s.direction, fn);
5055 * Sets the default sort column and order to be used by the next load operation.
5056 * @param {String} fieldName The name of the field to sort by.
5057 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
5059 setDefaultSort : function(field, dir){
5060 this.sortInfo = {field: field, direction: dir ? dir.toUpperCase() : "ASC"};
5065 * If remote sorting is used, the sort is performed on the server, and the cache is
5066 * reloaded. If local sorting is used, the cache is sorted internally.
5067 * @param {String} fieldName The name of the field to sort by.
5068 * @param {String} dir (optional) The sort order, "ASC" or "DESC" (defaults to "ASC")
5070 sort : function(fieldName, dir){
5071 var f = this.fields.get(fieldName);
5073 if(this.sortInfo && this.sortInfo.field == f.name){ // toggle sort dir
5074 dir = (this.sortToggle[f.name] || "ASC").toggle("ASC", "DESC");
5079 this.sortToggle[f.name] = dir;
5080 this.sortInfo = {field: f.name, direction: dir};
5081 if(!this.remoteSort){
5083 this.fireEvent("datachanged", this);
5085 this.load(this.lastOptions);
5090 * Calls the specified function for each of the Records in the cache.
5091 * @param {Function} fn The function to call. The Record is passed as the first parameter.
5092 * Returning <em>false</em> aborts and exits the iteration.
5093 * @param {Object} scope (optional) The scope in which to call the function (defaults to the Record).
5095 each : function(fn, scope){
5096 this.data.each(fn, scope);
5100 * Gets all records modified since the last commit. Modified records are persisted across load operations
5101 * (e.g., during paging).
5102 * @return {Roo.data.Record[]} An array of Records containing outstanding modifications.
5104 getModifiedRecords : function(){
5105 return this.modified;
5109 createFilterFn : function(property, value, anyMatch){
5110 if(!value.exec){ // not a regex
5111 value = String(value);
5112 if(value.length == 0){
5115 value = new RegExp((anyMatch === true ? '' : '^') + Roo.escapeRe(value), "i");
5118 return value.test(r.data[property]);
5123 * Sums the value of <i>property</i> for each record between start and end and returns the result.
5124 * @param {String} property A field on your records
5125 * @param {Number} start The record index to start at (defaults to 0)
5126 * @param {Number} end The last record index to include (defaults to length - 1)
5127 * @return {Number} The sum
5129 sum : function(property, start, end){
5130 var rs = this.data.items, v = 0;
5132 end = (end || end === 0) ? end : rs.length-1;
5134 for(var i = start; i <= end; i++){
5135 v += (rs[i].data[property] || 0);
5141 * Filter the records by a specified property.
5142 * @param {String} field A field on your records
5143 * @param {String/RegExp} value Either a string that the field
5144 * should start with or a RegExp to test against the field
5145 * @param {Boolean} anyMatch True to match any part not just the beginning
5147 filter : function(property, value, anyMatch){
5148 var fn = this.createFilterFn(property, value, anyMatch);
5149 return fn ? this.filterBy(fn) : this.clearFilter();
5153 * Filter by a function. The specified function will be called with each
5154 * record in this data source. If the function returns true the record is included,
5155 * otherwise it is filtered.
5156 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
5157 * @param {Object} scope (optional) The scope of the function (defaults to this)
5159 filterBy : function(fn, scope){
5160 this.snapshot = this.snapshot || this.data;
5161 this.data = this.queryBy(fn, scope||this);
5162 this.fireEvent("datachanged", this);
5166 * Query the records by a specified property.
5167 * @param {String} field A field on your records
5168 * @param {String/RegExp} value Either a string that the field
5169 * should start with or a RegExp to test against the field
5170 * @param {Boolean} anyMatch True to match any part not just the beginning
5171 * @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
5173 query : function(property, value, anyMatch){
5174 var fn = this.createFilterFn(property, value, anyMatch);
5175 return fn ? this.queryBy(fn) : this.data.clone();
5179 * Query by a function. The specified function will be called with each
5180 * record in this data source. If the function returns true the record is included
5182 * @param {Function} fn The function to be called, it will receive 2 args (record, id)
5183 * @param {Object} scope (optional) The scope of the function (defaults to this)
5184 @return {MixedCollection} Returns an Roo.util.MixedCollection of the matched records
5186 queryBy : function(fn, scope){
5187 var data = this.snapshot || this.data;
5188 return data.filterBy(fn, scope||this);
5192 * Collects unique values for a particular dataIndex from this store.
5193 * @param {String} dataIndex The property to collect
5194 * @param {Boolean} allowNull (optional) Pass true to allow null, undefined or empty string values
5195 * @param {Boolean} bypassFilter (optional) Pass true to collect from all records, even ones which are filtered
5196 * @return {Array} An array of the unique values
5198 collect : function(dataIndex, allowNull, bypassFilter){
5199 var d = (bypassFilter === true && this.snapshot) ?
5200 this.snapshot.items : this.data.items;
5201 var v, sv, r = [], l = {};
5202 for(var i = 0, len = d.length; i < len; i++){
5203 v = d[i].data[dataIndex];
5205 if((allowNull || !Roo.isEmpty(v)) && !l[sv]){
5214 * Revert to a view of the Record cache with no filtering applied.
5215 * @param {Boolean} suppressEvent If true the filter is cleared silently without notifying listeners
5217 clearFilter : function(suppressEvent){
5218 if(this.snapshot && this.snapshot != this.data){
5219 this.data = this.snapshot;
5220 delete this.snapshot;
5221 if(suppressEvent !== true){
5222 this.fireEvent("datachanged", this);
5228 afterEdit : function(record){
5229 if(this.modified.indexOf(record) == -1){
5230 this.modified.push(record);
5232 this.fireEvent("update", this, record, Roo.data.Record.EDIT);
5236 afterReject : function(record){
5237 this.modified.remove(record);
5238 this.fireEvent("update", this, record, Roo.data.Record.REJECT);
5242 afterCommit : function(record){
5243 this.modified.remove(record);
5244 this.fireEvent("update", this, record, Roo.data.Record.COMMIT);
5248 * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the
5249 * Store's "update" event, and perform updating when the third parameter is Roo.data.Record.COMMIT.
5251 commitChanges : function(){
5252 var m = this.modified.slice(0);
5254 for(var i = 0, len = m.length; i < len; i++){
5260 * Cancel outstanding changes on all changed records.
5262 rejectChanges : function(){
5263 var m = this.modified.slice(0);
5265 for(var i = 0, len = m.length; i < len; i++){
5270 onMetaChange : function(meta, rtype, o){
5271 this.recordType = rtype;
5272 this.fields = rtype.prototype.fields;
5273 delete this.snapshot;
5274 this.sortInfo = meta.sortInfo;
5276 this.fireEvent('metachange', this, this.reader.meta);
5280 * Ext JS Library 1.1.1
5281 * Copyright(c) 2006-2007, Ext JS, LLC.
5283 * Originally Released Under LGPL - original licence link has changed is not relivant.
5286 * <script type="text/javascript">
5290 * @class Roo.data.SimpleStore
5291 * @extends Roo.data.Store
5292 * Small helper class to make creating Stores from Array data easier.
5293 * @cfg {Number} id The array index of the record id. Leave blank to auto generate ids.
5294 * @cfg {Array} fields An array of field definition objects, or field name strings.
5295 * @cfg {Array} data The multi-dimensional array of data
5297 * @param {Object} config
5299 Roo.data.SimpleStore = function(config){
5300 Roo.data.SimpleStore.superclass.constructor.call(this, {
5302 reader: new Roo.data.ArrayReader({
5305 Roo.data.Record.create(config.fields)
5307 proxy : new Roo.data.MemoryProxy(config.data)
5311 Roo.extend(Roo.data.SimpleStore, Roo.data.Store);/*
5313 * Ext JS Library 1.1.1
5314 * Copyright(c) 2006-2007, Ext JS, LLC.
5316 * Originally Released Under LGPL - original licence link has changed is not relivant.
5319 * <script type="text/javascript">
5324 * @extends Roo.data.Store
5325 * @class Roo.data.JsonStore
5326 * Small helper class to make creating Stores for JSON data easier. <br/>
5328 var store = new Roo.data.JsonStore({
5329 url: 'get-images.php',
5331 fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}]
5334 * <b>Note: Although they are not listed, this class inherits all of the config options of Store,
5335 * JsonReader and HttpProxy (unless inline data is provided).</b>
5336 * @cfg {Array} fields An array of field definition objects, or field name strings.
5338 * @param {Object} config
5340 Roo.data.JsonStore = function(c){
5341 Roo.data.JsonStore.superclass.constructor.call(this, Roo.apply(c, {
5342 proxy: !c.data ? new Roo.data.HttpProxy({url: c.url}) : undefined,
5343 reader: new Roo.data.JsonReader(c, c.fields)
5346 Roo.extend(Roo.data.JsonStore, Roo.data.Store);/*
5348 * Ext JS Library 1.1.1
5349 * Copyright(c) 2006-2007, Ext JS, LLC.
5351 * Originally Released Under LGPL - original licence link has changed is not relivant.
5354 * <script type="text/javascript">
5358 Roo.data.Field = function(config){
5359 if(typeof config == "string"){
5360 config = {name: config};
5362 Roo.apply(this, config);
5368 var st = Roo.data.SortTypes;
5369 // named sortTypes are supported, here we look them up
5370 if(typeof this.sortType == "string"){
5371 this.sortType = st[this.sortType];
5374 // set default sortType for strings and dates
5378 this.sortType = st.asUCString;
5381 this.sortType = st.asDate;
5384 this.sortType = st.none;
5389 var stripRe = /[\$,%]/g;
5391 // prebuilt conversion function for this field, instead of
5392 // switching every time we're reading a value
5394 var cv, dateFormat = this.dateFormat;
5399 cv = function(v){ return v; };
5402 cv = function(v){ return (v === undefined || v === null) ? '' : String(v); };
5406 return v !== undefined && v !== null && v !== '' ?
5407 parseInt(String(v).replace(stripRe, ""), 10) : '';
5412 return v !== undefined && v !== null && v !== '' ?
5413 parseFloat(String(v).replace(stripRe, ""), 10) : '';
5418 cv = function(v){ return v === true || v === "true" || v == 1; };
5425 if(v instanceof Date){
5429 if(dateFormat == "timestamp"){
5430 return new Date(v*1000);
5432 return Date.parseDate(v, dateFormat);
5434 var parsed = Date.parse(v);
5435 return parsed ? new Date(parsed) : null;
5444 Roo.data.Field.prototype = {
5452 * Ext JS Library 1.1.1
5453 * Copyright(c) 2006-2007, Ext JS, LLC.
5455 * Originally Released Under LGPL - original licence link has changed is not relivant.
5458 * <script type="text/javascript">
5461 // Base class for reading structured data from a data source. This class is intended to be
5462 // extended (see ArrayReader, JsonReader and XmlReader) and should not be created directly.
5465 * @class Roo.data.DataReader
5466 * Base class for reading structured data from a data source. This class is intended to be
5467 * extended (see {Roo.data.ArrayReader}, {Roo.data.JsonReader} and {Roo.data.XmlReader}) and should not be created directly.
5470 Roo.data.DataReader = function(meta, recordType){
5474 this.recordType = recordType instanceof Array ?
5475 Roo.data.Record.create(recordType) : recordType;
5478 Roo.data.DataReader.prototype = {
5480 * Create an empty record
5481 * @param {Object} data (optional) - overlay some values
5482 * @return {Roo.data.Record} record created.
5484 newRow : function(d) {
5486 this.recordType.prototype.fields.each(function(c) {
5488 case 'int' : da[c.name] = 0; break;
5489 case 'date' : da[c.name] = new Date(); break;
5490 case 'float' : da[c.name] = 0.0; break;
5491 case 'boolean' : da[c.name] = false; break;
5492 default : da[c.name] = ""; break;
5496 return new this.recordType(Roo.apply(da, d));
5501 * Ext JS Library 1.1.1
5502 * Copyright(c) 2006-2007, Ext JS, LLC.
5504 * Originally Released Under LGPL - original licence link has changed is not relivant.
5507 * <script type="text/javascript">
5511 * @class Roo.data.DataProxy
5512 * @extends Roo.data.Observable
5513 * This class is an abstract base class for implementations which provide retrieval of
5514 * unformatted data objects.<br>
5516 * DataProxy implementations are usually used in conjunction with an implementation of Roo.data.DataReader
5517 * (of the appropriate type which knows how to parse the data object) to provide a block of
5518 * {@link Roo.data.Records} to an {@link Roo.data.Store}.<br>
5520 * Custom implementations must implement the load method as described in
5521 * {@link Roo.data.HttpProxy#load}.
5523 Roo.data.DataProxy = function(){
5527 * Fires before a network request is made to retrieve a data object.
5528 * @param {Object} This DataProxy object.
5529 * @param {Object} params The params parameter to the load function.
5534 * Fires before the load method's callback is called.
5535 * @param {Object} This DataProxy object.
5536 * @param {Object} o The data object.
5537 * @param {Object} arg The callback argument object passed to the load function.
5541 * @event loadexception
5542 * Fires if an Exception occurs during data retrieval.
5543 * @param {Object} This DataProxy object.
5544 * @param {Object} o The data object.
5545 * @param {Object} arg The callback argument object passed to the load function.
5546 * @param {Object} e The Exception.
5548 loadexception : true
5550 Roo.data.DataProxy.superclass.constructor.call(this);
5553 Roo.extend(Roo.data.DataProxy, Roo.util.Observable);
5556 * @cfg {void} listeners (Not available) Constructor blocks listeners from being set
5560 * Ext JS Library 1.1.1
5561 * Copyright(c) 2006-2007, Ext JS, LLC.
5563 * Originally Released Under LGPL - original licence link has changed is not relivant.
5566 * <script type="text/javascript">
5569 * @class Roo.data.MemoryProxy
5570 * An implementation of Roo.data.DataProxy that simply passes the data specified in its constructor
5571 * to the Reader when its load method is called.
5573 * @param {Object} data The data object which the Reader uses to construct a block of Roo.data.Records.
5575 Roo.data.MemoryProxy = function(data){
5579 Roo.data.MemoryProxy.superclass.constructor.call(this);
5583 Roo.extend(Roo.data.MemoryProxy, Roo.data.DataProxy, {
5585 * Load data from the requested source (in this case an in-memory
5586 * data object passed to the constructor), read the data object into
5587 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
5588 * process that block using the passed callback.
5589 * @param {Object} params This parameter is not used by the MemoryProxy class.
5590 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5591 * object into a block of Roo.data.Records.
5592 * @param {Function} callback The function into which to pass the block of Roo.data.records.
5593 * The function must be passed <ul>
5594 * <li>The Record block object</li>
5595 * <li>The "arg" argument from the load function</li>
5596 * <li>A boolean success indicator</li>
5598 * @param {Object} scope The scope in which to call the callback
5599 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5601 load : function(params, reader, callback, scope, arg){
5602 params = params || {};
5605 result = reader.readRecords(this.data);
5607 this.fireEvent("loadexception", this, arg, null, e);
5608 callback.call(scope, null, arg, false);
5611 callback.call(scope, result, arg, true);
5615 update : function(params, records){
5620 * Ext JS Library 1.1.1
5621 * Copyright(c) 2006-2007, Ext JS, LLC.
5623 * Originally Released Under LGPL - original licence link has changed is not relivant.
5626 * <script type="text/javascript">
5629 * @class Roo.data.HttpProxy
5630 * @extends Roo.data.DataProxy
5631 * An implementation of {@link Roo.data.DataProxy} that reads a data object from an {@link Roo.data.Connection} object
5632 * configured to reference a certain URL.<br><br>
5634 * <em>Note that this class cannot be used to retrieve data from a domain other than the domain
5635 * from which the running page was served.<br><br>
5637 * For cross-domain access to remote data, use an {@link Roo.data.ScriptTagProxy}.</em><br><br>
5639 * Be aware that to enable the browser to parse an XML document, the server must set
5640 * the Content-Type header in the HTTP response to "text/xml".
5642 * @param {Object} conn Connection config options to add to each request (e.g. {url: 'foo.php'} or
5643 * an {@link Roo.data.Connection} object. If a Connection config is passed, the singleton {@link Roo.Ajax} object
5644 * will be used to make the request.
5646 Roo.data.HttpProxy = function(conn){
5647 Roo.data.HttpProxy.superclass.constructor.call(this);
5648 // is conn a conn config or a real conn?
5650 this.useAjax = !conn || !conn.events;
5654 Roo.extend(Roo.data.HttpProxy, Roo.data.DataProxy, {
5655 // thse are take from connection...
5658 * @cfg {String} url (Optional) The default URL to be used for requests to the server. (defaults to undefined)
5661 * @cfg {Object} extraParams (Optional) An object containing properties which are used as
5662 * extra parameters to each request made by this object. (defaults to undefined)
5665 * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
5666 * to each request made by this object. (defaults to undefined)
5669 * @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)
5672 * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
5675 * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
5681 * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
5685 * Return the {@link Roo.data.Connection} object being used by this Proxy.
5686 * @return {Connection} The Connection object. This object may be used to subscribe to events on
5687 * a finer-grained basis than the DataProxy events.
5689 getConnection : function(){
5690 return this.useAjax ? Roo.Ajax : this.conn;
5694 * Load data from the configured {@link Roo.data.Connection}, read the data object into
5695 * a block of Roo.data.Records using the passed {@link Roo.data.DataReader} implementation, and
5696 * process that block using the passed callback.
5697 * @param {Object} params An object containing properties which are to be used as HTTP parameters
5698 * for the request to the remote server.
5699 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5700 * object into a block of Roo.data.Records.
5701 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
5702 * The function must be passed <ul>
5703 * <li>The Record block object</li>
5704 * <li>The "arg" argument from the load function</li>
5705 * <li>A boolean success indicator</li>
5707 * @param {Object} scope The scope in which to call the callback
5708 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5710 load : function(params, reader, callback, scope, arg){
5711 if(this.fireEvent("beforeload", this, params) !== false){
5713 params : params || {},
5715 callback : callback,
5720 callback : this.loadResponse,
5724 Roo.applyIf(o, this.conn);
5725 if(this.activeRequest){
5726 Roo.Ajax.abort(this.activeRequest);
5728 this.activeRequest = Roo.Ajax.request(o);
5730 this.conn.request(o);
5733 callback.call(scope||this, null, arg, false);
5738 loadResponse : function(o, success, response){
5739 delete this.activeRequest;
5741 this.fireEvent("loadexception", this, o, response);
5742 o.request.callback.call(o.request.scope, null, o.request.arg, false);
5747 result = o.reader.read(response);
5749 this.fireEvent("loadexception", this, o, response, e);
5750 o.request.callback.call(o.request.scope, null, o.request.arg, false);
5754 this.fireEvent("load", this, o, o.request.arg);
5755 o.request.callback.call(o.request.scope, result, o.request.arg, true);
5759 update : function(dataSet){
5764 updateResponse : function(dataSet){
5769 * Ext JS Library 1.1.1
5770 * Copyright(c) 2006-2007, Ext JS, LLC.
5772 * Originally Released Under LGPL - original licence link has changed is not relivant.
5775 * <script type="text/javascript">
5779 * @class Roo.data.ScriptTagProxy
5780 * An implementation of Roo.data.DataProxy that reads a data object from a URL which may be in a domain
5781 * other than the originating domain of the running page.<br><br>
5783 * <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
5784 * of the running page, you must use this class, rather than DataProxy.</em><br><br>
5786 * The content passed back from a server resource requested by a ScriptTagProxy is executable JavaScript
5787 * source code that is used as the source inside a <script> tag.<br><br>
5789 * In order for the browser to process the returned data, the server must wrap the data object
5790 * with a call to a callback function, the name of which is passed as a parameter by the ScriptTagProxy.
5791 * Below is a Java example for a servlet which returns data for either a ScriptTagProxy, or an HttpProxy
5792 * depending on whether the callback name was passed:
5795 boolean scriptTag = false;
5796 String cb = request.getParameter("callback");
5799 response.setContentType("text/javascript");
5801 response.setContentType("application/x-json");
5803 Writer out = response.getWriter();
5805 out.write(cb + "(");
5807 out.print(dataBlock.toJsonString());
5814 * @param {Object} config A configuration object.
5816 Roo.data.ScriptTagProxy = function(config){
5817 Roo.data.ScriptTagProxy.superclass.constructor.call(this);
5818 Roo.apply(this, config);
5819 this.head = document.getElementsByTagName("head")[0];
5822 Roo.data.ScriptTagProxy.TRANS_ID = 1000;
5824 Roo.extend(Roo.data.ScriptTagProxy, Roo.data.DataProxy, {
5826 * @cfg {String} url The URL from which to request the data object.
5829 * @cfg {Number} timeout (Optional) The number of milliseconds to wait for a response. Defaults to 30 seconds.
5833 * @cfg {String} callbackParam (Optional) The name of the parameter to pass to the server which tells
5834 * the server the name of the callback function set up by the load call to process the returned data object.
5835 * Defaults to "callback".<p>The server-side processing must read this parameter value, and generate
5836 * javascript output which calls this named function passing the data object as its only parameter.
5838 callbackParam : "callback",
5840 * @cfg {Boolean} nocache (Optional) Defaults to true. Disable cacheing by adding a unique parameter
5841 * name to the request.
5846 * Load data from the configured URL, read the data object into
5847 * a block of Roo.data.Records using the passed Roo.data.DataReader implementation, and
5848 * process that block using the passed callback.
5849 * @param {Object} params An object containing properties which are to be used as HTTP parameters
5850 * for the request to the remote server.
5851 * @param {Roo.data.DataReader} reader The Reader object which converts the data
5852 * object into a block of Roo.data.Records.
5853 * @param {Function} callback The function into which to pass the block of Roo.data.Records.
5854 * The function must be passed <ul>
5855 * <li>The Record block object</li>
5856 * <li>The "arg" argument from the load function</li>
5857 * <li>A boolean success indicator</li>
5859 * @param {Object} scope The scope in which to call the callback
5860 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
5862 load : function(params, reader, callback, scope, arg){
5863 if(this.fireEvent("beforeload", this, params) !== false){
5865 var p = Roo.urlEncode(Roo.apply(params, this.extraParams));
5868 url += (url.indexOf("?") != -1 ? "&" : "?") + p;
5870 url += "&_dc=" + (new Date().getTime());
5872 var transId = ++Roo.data.ScriptTagProxy.TRANS_ID;
5875 cb : "stcCallback"+transId,
5876 scriptId : "stcScript"+transId,
5880 callback : callback,
5886 window[trans.cb] = function(o){
5887 conn.handleResponse(o, trans);
5890 url += String.format("&{0}={1}", this.callbackParam, trans.cb);
5892 if(this.autoAbort !== false){
5896 trans.timeoutId = this.handleFailure.defer(this.timeout, this, [trans]);
5898 var script = document.createElement("script");
5899 script.setAttribute("src", url);
5900 script.setAttribute("type", "text/javascript");
5901 script.setAttribute("id", trans.scriptId);
5902 this.head.appendChild(script);
5906 callback.call(scope||this, null, arg, false);
5911 isLoading : function(){
5912 return this.trans ? true : false;
5916 * Abort the current server request.
5919 if(this.isLoading()){
5920 this.destroyTrans(this.trans);
5925 destroyTrans : function(trans, isLoaded){
5926 this.head.removeChild(document.getElementById(trans.scriptId));
5927 clearTimeout(trans.timeoutId);
5929 window[trans.cb] = undefined;
5931 delete window[trans.cb];
5934 // if hasn't been loaded, wait for load to remove it to prevent script error
5935 window[trans.cb] = function(){
5936 window[trans.cb] = undefined;
5938 delete window[trans.cb];
5945 handleResponse : function(o, trans){
5947 this.destroyTrans(trans, true);
5950 result = trans.reader.readRecords(o);
5952 this.fireEvent("loadexception", this, o, trans.arg, e);
5953 trans.callback.call(trans.scope||window, null, trans.arg, false);
5956 this.fireEvent("load", this, o, trans.arg);
5957 trans.callback.call(trans.scope||window, result, trans.arg, true);
5961 handleFailure : function(trans){
5963 this.destroyTrans(trans, false);
5964 this.fireEvent("loadexception", this, null, trans.arg);
5965 trans.callback.call(trans.scope||window, null, trans.arg, false);
5969 * Ext JS Library 1.1.1
5970 * Copyright(c) 2006-2007, Ext JS, LLC.
5972 * Originally Released Under LGPL - original licence link has changed is not relivant.
5975 * <script type="text/javascript">
5979 * @class Roo.data.JsonReader
5980 * @extends Roo.data.DataReader
5981 * Data reader class to create an Array of Roo.data.Record objects from a JSON response
5982 * based on mappings in a provided Roo.data.Record constructor.
5986 var RecordDef = Roo.data.Record.create([
5987 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
5988 {name: 'occupation'} // This field will use "occupation" as the mapping.
5990 var myReader = new Roo.data.JsonReader({
5991 totalProperty: "results", // The property which contains the total dataset size (optional)
5992 root: "rows", // The property which contains an Array of row objects
5993 id: "id" // The property within each row object that provides an ID for the record (optional)
5997 * This would consume a JSON file like this:
5999 { 'results': 2, 'rows': [
6000 { 'id': 1, 'name': 'Bill', occupation: 'Gardener' },
6001 { 'id': 2, 'name': 'Ben', occupation: 'Horticulturalist' } ]
6004 * @cfg {String} totalProperty Name of the property from which to retrieve the total number of records
6005 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
6006 * paged from the remote server.
6007 * @cfg {String} successProperty Name of the property from which to retrieve the success attribute used by forms.
6008 * @cfg {String} root name of the property which contains the Array of row objects.
6009 * @cfg {String} id Name of the property within a row object that contains a record identifier value.
6011 * Create a new JsonReader
6012 * @param {Object} meta Metadata configuration options
6013 * @param {Object} recordType Either an Array of field definition objects,
6014 * or an {@link Roo.data.Record} object created using {@link Roo.data.Record#create}.
6016 Roo.data.JsonReader = function(meta, recordType){
6019 // set some defaults:
6021 totalProperty: 'total',
6022 successProperty : 'success',
6027 Roo.data.JsonReader.superclass.constructor.call(this, meta, recordType||meta.fields);
6029 Roo.extend(Roo.data.JsonReader, Roo.data.DataReader, {
6031 * This method is only used by a DataProxy which has retrieved data from a remote server.
6032 * @param {Object} response The XHR object which contains the JSON data in its responseText.
6033 * @return {Object} data A data block which is used by an Roo.data.Store object as
6034 * a cache of Roo.data.Records.
6036 read : function(response){
6037 var json = response.responseText;
6039 var o = eval("("+json+")");
6041 throw {message: "JsonReader.read: Json object not found"};
6046 this.meta = o.metaData;
6047 this.recordType = Roo.data.Record.create(o.metaData.fields);
6048 this.onMetaChange(this.meta, this.recordType, o);
6050 return this.readRecords(o);
6053 // private function a store will implement
6054 onMetaChange : function(meta, recordType, o){
6061 simpleAccess: function(obj, subsc) {
6068 getJsonAccessor: function(){
6070 return function(expr) {
6072 return(re.test(expr))
6073 ? new Function("obj", "return obj." + expr)
6083 * Create a data block containing Roo.data.Records from an XML document.
6084 * @param {Object} o An object which contains an Array of row objects in the property specified
6085 * in the config as 'root, and optionally a property, specified in the config as 'totalProperty'
6086 * which contains the total size of the dataset.
6087 * @return {Object} data A data block which is used by an Roo.data.Store object as
6088 * a cache of Roo.data.Records.
6090 readRecords : function(o){
6092 * After any data loads, the raw JSON data is available for further custom processing.
6096 var s = this.meta, Record = this.recordType,
6097 f = Record.prototype.fields, fi = f.items, fl = f.length;
6099 // Generate extraction functions for the totalProperty, the root, the id, and for each field
6101 if(s.totalProperty) {
6102 this.getTotal = this.getJsonAccessor(s.totalProperty);
6104 if(s.successProperty) {
6105 this.getSuccess = this.getJsonAccessor(s.successProperty);
6107 this.getRoot = s.root ? this.getJsonAccessor(s.root) : function(p){return p;};
6109 var g = this.getJsonAccessor(s.id);
6110 this.getId = function(rec) {
6112 return (r === undefined || r === "") ? null : r;
6115 this.getId = function(){return null;};
6118 for(var i = 0; i < fl; i++){
6120 var map = (f.mapping !== undefined && f.mapping !== null) ? f.mapping : f.name;
6121 this.ef[i] = this.getJsonAccessor(map);
6125 var root = this.getRoot(o), c = root.length, totalRecords = c, success = true;
6126 if(s.totalProperty){
6127 var v = parseInt(this.getTotal(o), 10);
6132 if(s.successProperty){
6133 var v = this.getSuccess(o);
6134 if(v === false || v === 'false'){
6139 for(var i = 0; i < c; i++){
6142 var id = this.getId(n);
6143 for(var j = 0; j < fl; j++){
6145 var v = this.ef[j](n);
6146 values[f.name] = f.convert((v !== undefined) ? v : f.defaultValue);
6148 var record = new Record(values, id);
6150 records[i] = record;
6155 totalRecords : totalRecords
6160 * Ext JS Library 1.1.1
6161 * Copyright(c) 2006-2007, Ext JS, LLC.
6163 * Originally Released Under LGPL - original licence link has changed is not relivant.
6166 * <script type="text/javascript">
6170 * @class Roo.data.XmlReader
6171 * @extends Roo.data.DataReader
6172 * Data reader class to create an Array of {@link Roo.data.Record} objects from an XML document
6173 * based on mappings in a provided Roo.data.Record constructor.<br><br>
6175 * <em>Note that in order for the browser to parse a returned XML document, the Content-Type
6176 * header in the HTTP response must be set to "text/xml".</em>
6180 var RecordDef = Roo.data.Record.create([
6181 {name: 'name', mapping: 'name'}, // "mapping" property not needed if it's the same as "name"
6182 {name: 'occupation'} // This field will use "occupation" as the mapping.
6184 var myReader = new Roo.data.XmlReader({
6185 totalRecords: "results", // The element which contains the total dataset size (optional)
6186 record: "row", // The repeated element which contains row information
6187 id: "id" // The element within the row that provides an ID for the record (optional)
6191 * This would consume an XML file like this:
6195 <results>2</results>
6198 <name>Bill</name>
6199 <occupation>Gardener</occupation>
6203 <name>Ben</name>
6204 <occupation>Horticulturalist</occupation>
6208 * @cfg {String} totalRecords The DomQuery path from which to retrieve the total number of records
6209 * in the dataset. This is only needed if the whole dataset is not passed in one go, but is being
6210 * paged from the remote server.
6211 * @cfg {String} record The DomQuery path to the repeated element which contains record information.
6212 * @cfg {String} success The DomQuery path to the success attribute used by forms.
6213 * @cfg {String} id The DomQuery path relative from the record element to the element that contains
6214 * a record identifier value.
6216 * Create a new XmlReader
6217 * @param {Object} meta Metadata configuration options
6218 * @param {Mixed} recordType The definition of the data record type to produce. This can be either a valid
6219 * Record subclass created with {@link Roo.data.Record#create}, or an array of objects with which to call
6220 * Roo.data.Record.create. See the {@link Roo.data.Record} class for more details.
6222 Roo.data.XmlReader = function(meta, recordType){
6224 Roo.data.XmlReader.superclass.constructor.call(this, meta, recordType||meta.fields);
6226 Roo.extend(Roo.data.XmlReader, Roo.data.DataReader, {
6228 * This method is only used by a DataProxy which has retrieved data from a remote server.
6229 * @param {Object} response The XHR object which contains the parsed XML document. The response is expected
6230 * to contain a method called 'responseXML' that returns an XML document object.
6231 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
6232 * a cache of Roo.data.Records.
6234 read : function(response){
6235 var doc = response.responseXML;
6237 throw {message: "XmlReader.read: XML Document not available"};
6239 return this.readRecords(doc);
6243 * Create a data block containing Roo.data.Records from an XML document.
6244 * @param {Object} doc A parsed XML document.
6245 * @return {Object} records A data block which is used by an {@link Roo.data.Store} as
6246 * a cache of Roo.data.Records.
6248 readRecords : function(doc){
6250 * After any data loads/reads, the raw XML Document is available for further custom processing.
6254 var root = doc.documentElement || doc;
6255 var q = Roo.DomQuery;
6256 var recordType = this.recordType, fields = recordType.prototype.fields;
6257 var sid = this.meta.id;
6258 var totalRecords = 0, success = true;
6259 if(this.meta.totalRecords){
6260 totalRecords = q.selectNumber(this.meta.totalRecords, root, 0);
6263 if(this.meta.success){
6264 var sv = q.selectValue(this.meta.success, root, true);
6265 success = sv !== false && sv !== 'false';
6268 var ns = q.select(this.meta.record, root);
6269 for(var i = 0, len = ns.length; i < len; i++) {
6272 var id = sid ? q.selectValue(sid, n) : undefined;
6273 for(var j = 0, jlen = fields.length; j < jlen; j++){
6274 var f = fields.items[j];
6275 var v = q.selectValue(f.mapping || f.name, n, f.defaultValue);
6279 var record = new recordType(values, id);
6281 records[records.length] = record;
6287 totalRecords : totalRecords || records.length
6292 * Ext JS Library 1.1.1
6293 * Copyright(c) 2006-2007, Ext JS, LLC.
6295 * Originally Released Under LGPL - original licence link has changed is not relivant.
6298 * <script type="text/javascript">
6302 * @class Roo.data.ArrayReader
6303 * @extends Roo.data.DataReader
6304 * Data reader class to create an Array of Roo.data.Record objects from an Array.
6305 * Each element of that Array represents a row of data fields. The
6306 * fields are pulled into a Record object using as a subscript, the <em>mapping</em> property
6307 * of the field definition if it exists, or the field's ordinal position in the definition.<br>
6311 var RecordDef = Roo.data.Record.create([
6312 {name: 'name', mapping: 1}, // "mapping" only needed if an "id" field is present which
6313 {name: 'occupation', mapping: 2} // precludes using the ordinal position as the index.
6315 var myReader = new Roo.data.ArrayReader({
6316 id: 0 // The subscript within row Array that provides an ID for the Record (optional)
6320 * This would consume an Array like this:
6322 [ [1, 'Bill', 'Gardener'], [2, 'Ben', 'Horticulturalist'] ]
6324 * @cfg {String} id (optional) The subscript within row Array that provides an ID for the Record
6326 * Create a new JsonReader
6327 * @param {Object} meta Metadata configuration options.
6328 * @param {Object} recordType Either an Array of field definition objects
6329 * as specified to {@link Roo.data.Record#create},
6330 * or an {@link Roo.data.Record} object
6331 * created using {@link Roo.data.Record#create}.
6333 Roo.data.ArrayReader = function(meta, recordType){
6334 Roo.data.ArrayReader.superclass.constructor.call(this, meta, recordType);
6337 Roo.extend(Roo.data.ArrayReader, Roo.data.JsonReader, {
6339 * Create a data block containing Roo.data.Records from an XML document.
6340 * @param {Object} o An Array of row objects which represents the dataset.
6341 * @return {Object} data A data block which is used by an Roo.data.Store object as
6342 * a cache of Roo.data.Records.
6344 readRecords : function(o){
6345 var sid = this.meta ? this.meta.id : null;
6346 var recordType = this.recordType, fields = recordType.prototype.fields;
6349 for(var i = 0; i < root.length; i++){
6352 var id = ((sid || sid === 0) && n[sid] !== undefined && n[sid] !== "" ? n[sid] : null);
6353 for(var j = 0, jlen = fields.length; j < jlen; j++){
6354 var f = fields.items[j];
6355 var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : j;
6356 var v = n[k] !== undefined ? n[k] : f.defaultValue;
6360 var record = new recordType(values, id);
6362 records[records.length] = record;
6366 totalRecords : records.length
6371 * Ext JS Library 1.1.1
6372 * Copyright(c) 2006-2007, Ext JS, LLC.
6374 * Originally Released Under LGPL - original licence link has changed is not relivant.
6377 * <script type="text/javascript">
6382 * @class Roo.data.Tree
6383 * @extends Roo.util.Observable
6384 * Represents a tree data structure and bubbles all the events for its nodes. The nodes
6385 * in the tree have most standard DOM functionality.
6387 * @param {Node} root (optional) The root node
6389 Roo.data.Tree = function(root){
6392 * The root node for this tree
6397 this.setRootNode(root);
6402 * Fires when a new child node is appended to a node in this tree.
6403 * @param {Tree} tree The owner tree
6404 * @param {Node} parent The parent node
6405 * @param {Node} node The newly appended node
6406 * @param {Number} index The index of the newly appended node
6411 * Fires when a child node is removed from a node in this tree.
6412 * @param {Tree} tree The owner tree
6413 * @param {Node} parent The parent node
6414 * @param {Node} node The child node removed
6419 * Fires when a node is moved to a new location in the tree
6420 * @param {Tree} tree The owner tree
6421 * @param {Node} node The node moved
6422 * @param {Node} oldParent The old parent of this node
6423 * @param {Node} newParent The new parent of this node
6424 * @param {Number} index The index it was moved to
6429 * Fires when a new child node is inserted in a node in this tree.
6430 * @param {Tree} tree The owner tree
6431 * @param {Node} parent The parent node
6432 * @param {Node} node The child node inserted
6433 * @param {Node} refNode The child node the node was inserted before
6437 * @event beforeappend
6438 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
6439 * @param {Tree} tree The owner tree
6440 * @param {Node} parent The parent node
6441 * @param {Node} node The child node to be appended
6443 "beforeappend" : true,
6445 * @event beforeremove
6446 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
6447 * @param {Tree} tree The owner tree
6448 * @param {Node} parent The parent node
6449 * @param {Node} node The child node to be removed
6451 "beforeremove" : true,
6454 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
6455 * @param {Tree} tree The owner tree
6456 * @param {Node} node The node being moved
6457 * @param {Node} oldParent The parent of the node
6458 * @param {Node} newParent The new parent the node is moving to
6459 * @param {Number} index The index it is being moved to
6461 "beforemove" : true,
6463 * @event beforeinsert
6464 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
6465 * @param {Tree} tree The owner tree
6466 * @param {Node} parent The parent node
6467 * @param {Node} node The child node to be inserted
6468 * @param {Node} refNode The child node the node is being inserted before
6470 "beforeinsert" : true
6473 Roo.data.Tree.superclass.constructor.call(this);
6476 Roo.extend(Roo.data.Tree, Roo.util.Observable, {
6479 proxyNodeEvent : function(){
6480 return this.fireEvent.apply(this, arguments);
6484 * Returns the root node for this tree.
6487 getRootNode : function(){
6492 * Sets the root node for this tree.
6493 * @param {Node} node
6496 setRootNode : function(node){
6498 node.ownerTree = this;
6500 this.registerNode(node);
6505 * Gets a node in this tree by its id.
6506 * @param {String} id
6509 getNodeById : function(id){
6510 return this.nodeHash[id];
6513 registerNode : function(node){
6514 this.nodeHash[node.id] = node;
6517 unregisterNode : function(node){
6518 delete this.nodeHash[node.id];
6521 toString : function(){
6522 return "[Tree"+(this.id?" "+this.id:"")+"]";
6527 * @class Roo.data.Node
6528 * @extends Roo.util.Observable
6529 * @cfg {Boolean} leaf true if this node is a leaf and does not have children
6530 * @cfg {String} id The id for this node. If one is not specified, one is generated.
6532 * @param {Object} attributes The attributes/config for the node
6534 Roo.data.Node = function(attributes){
6536 * The attributes supplied for the node. You can use this property to access any custom attributes you supplied.
6539 this.attributes = attributes || {};
6540 this.leaf = this.attributes.leaf;
6542 * The node id. @type String
6544 this.id = this.attributes.id;
6546 this.id = Roo.id(null, "ynode-");
6547 this.attributes.id = this.id;
6550 * All child nodes of this node. @type Array
6552 this.childNodes = [];
6553 if(!this.childNodes.indexOf){ // indexOf is a must
6554 this.childNodes.indexOf = function(o){
6555 for(var i = 0, len = this.length; i < len; i++){
6556 if(this[i] == o) return i;
6562 * The parent node for this node. @type Node
6564 this.parentNode = null;
6566 * The first direct child node of this node, or null if this node has no child nodes. @type Node
6568 this.firstChild = null;
6570 * The last direct child node of this node, or null if this node has no child nodes. @type Node
6572 this.lastChild = null;
6574 * The node immediately preceding this node in the tree, or null if there is no sibling node. @type Node
6576 this.previousSibling = null;
6578 * The node immediately following this node in the tree, or null if there is no sibling node. @type Node
6580 this.nextSibling = null;
6585 * Fires when a new child node is appended
6586 * @param {Tree} tree The owner tree
6587 * @param {Node} this This node
6588 * @param {Node} node The newly appended node
6589 * @param {Number} index The index of the newly appended node
6594 * Fires when a child node is removed
6595 * @param {Tree} tree The owner tree
6596 * @param {Node} this This node
6597 * @param {Node} node The removed node
6602 * Fires when this node is moved to a new location in the tree
6603 * @param {Tree} tree The owner tree
6604 * @param {Node} this This node
6605 * @param {Node} oldParent The old parent of this node
6606 * @param {Node} newParent The new parent of this node
6607 * @param {Number} index The index it was moved to
6612 * Fires when a new child node is inserted.
6613 * @param {Tree} tree The owner tree
6614 * @param {Node} this This node
6615 * @param {Node} node The child node inserted
6616 * @param {Node} refNode The child node the node was inserted before
6620 * @event beforeappend
6621 * Fires before a new child is appended, return false to cancel the append.
6622 * @param {Tree} tree The owner tree
6623 * @param {Node} this This node
6624 * @param {Node} node The child node to be appended
6626 "beforeappend" : true,
6628 * @event beforeremove
6629 * Fires before a child is removed, return false to cancel the remove.
6630 * @param {Tree} tree The owner tree
6631 * @param {Node} this This node
6632 * @param {Node} node The child node to be removed
6634 "beforeremove" : true,
6637 * Fires before this node is moved to a new location in the tree. Return false to cancel the move.
6638 * @param {Tree} tree The owner tree
6639 * @param {Node} this This node
6640 * @param {Node} oldParent The parent of this node
6641 * @param {Node} newParent The new parent this node is moving to
6642 * @param {Number} index The index it is being moved to
6644 "beforemove" : true,
6646 * @event beforeinsert
6647 * Fires before a new child is inserted, return false to cancel the insert.
6648 * @param {Tree} tree The owner tree
6649 * @param {Node} this This node
6650 * @param {Node} node The child node to be inserted
6651 * @param {Node} refNode The child node the node is being inserted before
6653 "beforeinsert" : true
6655 this.listeners = this.attributes.listeners;
6656 Roo.data.Node.superclass.constructor.call(this);
6659 Roo.extend(Roo.data.Node, Roo.util.Observable, {
6660 fireEvent : function(evtName){
6661 // first do standard event for this node
6662 if(Roo.data.Node.superclass.fireEvent.apply(this, arguments) === false){
6665 // then bubble it up to the tree if the event wasn't cancelled
6666 var ot = this.getOwnerTree();
6668 if(ot.proxyNodeEvent.apply(ot, arguments) === false){
6676 * Returns true if this node is a leaf
6679 isLeaf : function(){
6680 return this.leaf === true;
6684 setFirstChild : function(node){
6685 this.firstChild = node;
6689 setLastChild : function(node){
6690 this.lastChild = node;
6695 * Returns true if this node is the last child of its parent
6698 isLast : function(){
6699 return (!this.parentNode ? true : this.parentNode.lastChild == this);
6703 * Returns true if this node is the first child of its parent
6706 isFirst : function(){
6707 return (!this.parentNode ? true : this.parentNode.firstChild == this);
6710 hasChildNodes : function(){
6711 return !this.isLeaf() && this.childNodes.length > 0;
6715 * Insert node(s) as the last child node of this node.
6716 * @param {Node/Array} node The node or Array of nodes to append
6717 * @return {Node} The appended node if single append, or null if an array was passed
6719 appendChild : function(node){
6721 if(node instanceof Array){
6723 }else if(arguments.length > 1){
6726 // if passed an array or multiple args do them one by one
6728 for(var i = 0, len = multi.length; i < len; i++) {
6729 this.appendChild(multi[i]);
6732 if(this.fireEvent("beforeappend", this.ownerTree, this, node) === false){
6735 var index = this.childNodes.length;
6736 var oldParent = node.parentNode;
6737 // it's a move, make sure we move it cleanly
6739 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index) === false){
6742 oldParent.removeChild(node);
6744 index = this.childNodes.length;
6746 this.setFirstChild(node);
6748 this.childNodes.push(node);
6749 node.parentNode = this;
6750 var ps = this.childNodes[index-1];
6752 node.previousSibling = ps;
6753 ps.nextSibling = node;
6755 node.previousSibling = null;
6757 node.nextSibling = null;
6758 this.setLastChild(node);
6759 node.setOwnerTree(this.getOwnerTree());
6760 this.fireEvent("append", this.ownerTree, this, node, index);
6762 node.fireEvent("move", this.ownerTree, node, oldParent, this, index);
6769 * Removes a child node from this node.
6770 * @param {Node} node The node to remove
6771 * @return {Node} The removed node
6773 removeChild : function(node){
6774 var index = this.childNodes.indexOf(node);
6778 if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false){
6782 // remove it from childNodes collection
6783 this.childNodes.splice(index, 1);
6786 if(node.previousSibling){
6787 node.previousSibling.nextSibling = node.nextSibling;
6789 if(node.nextSibling){
6790 node.nextSibling.previousSibling = node.previousSibling;
6793 // update child refs
6794 if(this.firstChild == node){
6795 this.setFirstChild(node.nextSibling);
6797 if(this.lastChild == node){
6798 this.setLastChild(node.previousSibling);
6801 node.setOwnerTree(null);
6802 // clear any references from the node
6803 node.parentNode = null;
6804 node.previousSibling = null;
6805 node.nextSibling = null;
6806 this.fireEvent("remove", this.ownerTree, this, node);
6811 * Inserts the first node before the second node in this nodes childNodes collection.
6812 * @param {Node} node The node to insert
6813 * @param {Node} refNode The node to insert before (if null the node is appended)
6814 * @return {Node} The inserted node
6816 insertBefore : function(node, refNode){
6817 if(!refNode){ // like standard Dom, refNode can be null for append
6818 return this.appendChild(node);
6821 if(node == refNode){
6825 if(this.fireEvent("beforeinsert", this.ownerTree, this, node, refNode) === false){
6828 var index = this.childNodes.indexOf(refNode);
6829 var oldParent = node.parentNode;
6830 var refIndex = index;
6832 // when moving internally, indexes will change after remove
6833 if(oldParent == this && this.childNodes.indexOf(node) < index){
6837 // it's a move, make sure we move it cleanly
6839 if(node.fireEvent("beforemove", node.getOwnerTree(), node, oldParent, this, index, refNode) === false){
6842 oldParent.removeChild(node);
6845 this.setFirstChild(node);
6847 this.childNodes.splice(refIndex, 0, node);
6848 node.parentNode = this;
6849 var ps = this.childNodes[refIndex-1];
6851 node.previousSibling = ps;
6852 ps.nextSibling = node;
6854 node.previousSibling = null;
6856 node.nextSibling = refNode;
6857 refNode.previousSibling = node;
6858 node.setOwnerTree(this.getOwnerTree());
6859 this.fireEvent("insert", this.ownerTree, this, node, refNode);
6861 node.fireEvent("move", this.ownerTree, node, oldParent, this, refIndex, refNode);
6867 * Returns the child node at the specified index.
6868 * @param {Number} index
6871 item : function(index){
6872 return this.childNodes[index];
6876 * Replaces one child node in this node with another.
6877 * @param {Node} newChild The replacement node
6878 * @param {Node} oldChild The node to replace
6879 * @return {Node} The replaced node
6881 replaceChild : function(newChild, oldChild){
6882 this.insertBefore(newChild, oldChild);
6883 this.removeChild(oldChild);
6888 * Returns the index of a child node
6889 * @param {Node} node
6890 * @return {Number} The index of the node or -1 if it was not found
6892 indexOf : function(child){
6893 return this.childNodes.indexOf(child);
6897 * Returns the tree this node is in.
6900 getOwnerTree : function(){
6901 // if it doesn't have one, look for one
6902 if(!this.ownerTree){
6906 this.ownerTree = p.ownerTree;
6912 return this.ownerTree;
6916 * Returns depth of this node (the root node has a depth of 0)
6919 getDepth : function(){
6922 while(p.parentNode){
6930 setOwnerTree : function(tree){
6931 // if it's move, we need to update everyone
6932 if(tree != this.ownerTree){
6934 this.ownerTree.unregisterNode(this);
6936 this.ownerTree = tree;
6937 var cs = this.childNodes;
6938 for(var i = 0, len = cs.length; i < len; i++) {
6939 cs[i].setOwnerTree(tree);
6942 tree.registerNode(this);
6948 * Returns the path for this node. The path can be used to expand or select this node programmatically.
6949 * @param {String} attr (optional) The attr to use for the path (defaults to the node's id)
6950 * @return {String} The path
6952 getPath : function(attr){
6953 attr = attr || "id";
6954 var p = this.parentNode;
6955 var b = [this.attributes[attr]];
6957 b.unshift(p.attributes[attr]);
6960 var sep = this.getOwnerTree().pathSeparator;
6961 return sep + b.join(sep);
6965 * Bubbles up the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
6966 * function call will be the scope provided or the current node. The arguments to the function
6967 * will be the args provided or the current node. If the function returns false at any point,
6968 * the bubble is stopped.
6969 * @param {Function} fn The function to call
6970 * @param {Object} scope (optional) The scope of the function (defaults to current node)
6971 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
6973 bubble : function(fn, scope, args){
6976 if(fn.call(scope || p, args || p) === false){
6984 * Cascades down the tree from this node, calling the specified function with each node. The scope (<i>this</i>) of
6985 * function call will be the scope provided or the current node. The arguments to the function
6986 * will be the args provided or the current node. If the function returns false at any point,
6987 * the cascade is stopped on that branch.
6988 * @param {Function} fn The function to call
6989 * @param {Object} scope (optional) The scope of the function (defaults to current node)
6990 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
6992 cascade : function(fn, scope, args){
6993 if(fn.call(scope || this, args || this) !== false){
6994 var cs = this.childNodes;
6995 for(var i = 0, len = cs.length; i < len; i++) {
6996 cs[i].cascade(fn, scope, args);
7002 * Interates the child nodes of this node, calling the specified function with each node. The scope (<i>this</i>) of
7003 * function call will be the scope provided or the current node. The arguments to the function
7004 * will be the args provided or the current node. If the function returns false at any point,
7005 * the iteration stops.
7006 * @param {Function} fn The function to call
7007 * @param {Object} scope (optional) The scope of the function (defaults to current node)
7008 * @param {Array} args (optional) The args to call the function with (default to passing the current node)
7010 eachChild : function(fn, scope, args){
7011 var cs = this.childNodes;
7012 for(var i = 0, len = cs.length; i < len; i++) {
7013 if(fn.call(scope || this, args || cs[i]) === false){
7020 * Finds the first child that has the attribute with the specified value.
7021 * @param {String} attribute The attribute name
7022 * @param {Mixed} value The value to search for
7023 * @return {Node} The found child or null if none was found
7025 findChild : function(attribute, value){
7026 var cs = this.childNodes;
7027 for(var i = 0, len = cs.length; i < len; i++) {
7028 if(cs[i].attributes[attribute] == value){
7036 * Finds the first child by a custom function. The child matches if the function passed
7038 * @param {Function} fn
7039 * @param {Object} scope (optional)
7040 * @return {Node} The found child or null if none was found
7042 findChildBy : function(fn, scope){
7043 var cs = this.childNodes;
7044 for(var i = 0, len = cs.length; i < len; i++) {
7045 if(fn.call(scope||cs[i], cs[i]) === true){
7053 * Sorts this nodes children using the supplied sort function
7054 * @param {Function} fn
7055 * @param {Object} scope (optional)
7057 sort : function(fn, scope){
7058 var cs = this.childNodes;
7059 var len = cs.length;
7061 var sortFn = scope ? function(){fn.apply(scope, arguments);} : fn;
7063 for(var i = 0; i < len; i++){
7065 n.previousSibling = cs[i-1];
7066 n.nextSibling = cs[i+1];
7068 this.setFirstChild(n);
7071 this.setLastChild(n);
7078 * Returns true if this node is an ancestor (at any point) of the passed node.
7079 * @param {Node} node
7082 contains : function(node){
7083 return node.isAncestor(this);
7087 * Returns true if the passed node is an ancestor (at any point) of this node.
7088 * @param {Node} node
7091 isAncestor : function(node){
7092 var p = this.parentNode;
7102 toString : function(){
7103 return "[Node"+(this.id?" "+this.id:"")+"]";
7107 * Ext JS Library 1.1.1
7108 * Copyright(c) 2006-2007, Ext JS, LLC.
7110 * Originally Released Under LGPL - original licence link has changed is not relivant.
7113 * <script type="text/javascript">
7118 * @class Roo.ComponentMgr
7119 * Provides a common registry of all components on a page so that they can be easily accessed by component id (see {@link Roo.getCmp}).
7122 Roo.ComponentMgr = function(){
7123 var all = new Roo.util.MixedCollection();
7127 * Registers a component.
7128 * @param {Roo.Component} c The component
7130 register : function(c){
7135 * Unregisters a component.
7136 * @param {Roo.Component} c The component
7138 unregister : function(c){
7143 * Returns a component by id
7144 * @param {String} id The component id
7151 * Registers a function that will be called when a specified component is added to ComponentMgr
7152 * @param {String} id The component id
7153 * @param {Funtction} fn The callback function
7154 * @param {Object} scope The scope of the callback
7156 onAvailable : function(id, fn, scope){
7157 all.on("add", function(index, o){
7159 fn.call(scope || o, o);
7160 all.un("add", fn, scope);
7167 * Ext JS Library 1.1.1
7168 * Copyright(c) 2006-2007, Ext JS, LLC.
7170 * Originally Released Under LGPL - original licence link has changed is not relivant.
7173 * <script type="text/javascript">
7177 * @class Roo.Component
7178 * @extends Roo.util.Observable
7179 * Base class for all major Roo components. All subclasses of Component can automatically participate in the standard
7180 * Roo component lifecycle of creation, rendering and destruction. They also have automatic support for basic hide/show
7181 * and enable/disable behavior. Component allows any subclass to be lazy-rendered into any {@link Roo.Container} and
7182 * to be automatically registered with the {@link Roo.ComponentMgr} so that it can be referenced at any time via {@link Roo.getCmp}.
7183 * All visual components (widgets) that require rendering into a layout should subclass Component.
7185 * @param {Roo.Element/String/Object} config The configuration options. If an element is passed, it is set as the internal
7186 * 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
7187 * and is used as the component id. Otherwise, it is assumed to be a standard config object and is applied to the component.
7189 Roo.Component = function(config){
7190 config = config || {};
7191 if(config.tagName || config.dom || typeof config == "string"){ // element object
7192 config = {el: config, id: config.id || config};
7194 this.initialConfig = config;
7196 Roo.apply(this, config);
7200 * Fires after the component is disabled.
7201 * @param {Roo.Component} this
7206 * Fires after the component is enabled.
7207 * @param {Roo.Component} this
7212 * Fires before the component is shown. Return false to stop the show.
7213 * @param {Roo.Component} this
7218 * Fires after the component is shown.
7219 * @param {Roo.Component} this
7224 * Fires before the component is hidden. Return false to stop the hide.
7225 * @param {Roo.Component} this
7230 * Fires after the component is hidden.
7231 * @param {Roo.Component} this
7235 * @event beforerender
7236 * Fires before the component is rendered. Return false to stop the render.
7237 * @param {Roo.Component} this
7239 beforerender : true,
7242 * Fires after the component is rendered.
7243 * @param {Roo.Component} this
7247 * @event beforedestroy
7248 * Fires before the component is destroyed. Return false to stop the destroy.
7249 * @param {Roo.Component} this
7251 beforedestroy : true,
7254 * Fires after the component is destroyed.
7255 * @param {Roo.Component} this
7260 this.id = "ext-comp-" + (++Roo.Component.AUTO_ID);
7262 Roo.ComponentMgr.register(this);
7263 Roo.Component.superclass.constructor.call(this);
7264 this.initComponent();
7265 if(this.renderTo){ // not supported by all components yet. use at your own risk!
7266 this.render(this.renderTo);
7267 delete this.renderTo;
7272 Roo.Component.AUTO_ID = 1000;
7274 Roo.extend(Roo.Component, Roo.util.Observable, {
7276 * @property {Boolean} hidden
7277 * true if this component is hidden. Read-only.
7281 * true if this component is disabled. Read-only.
7285 * true if this component has been rendered. Read-only.
7289 /** @cfg {String} disableClass
7290 * CSS class added to the component when it is disabled (defaults to "x-item-disabled").
7292 disabledClass : "x-item-disabled",
7293 /** @cfg {Boolean} allowDomMove
7294 * Whether the component can move the Dom node when rendering (defaults to true).
7296 allowDomMove : true,
7297 /** @cfg {String} hideMode
7298 * How this component should hidden. Supported values are
7299 * "visibility" (css visibility), "offsets" (negative offset position) and
7300 * "display" (css display) - defaults to "display".
7302 hideMode: 'display',
7305 ctype : "Roo.Component",
7307 /** @cfg {String} actionMode
7308 * which property holds the element that used for hide() / show() / disable() / enable()
7314 getActionEl : function(){
7315 return this[this.actionMode];
7318 initComponent : Roo.emptyFn,
7320 * If this is a lazy rendering component, render it to its container element.
7321 * @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.
7323 render : function(container, position){
7324 if(!this.rendered && this.fireEvent("beforerender", this) !== false){
7325 if(!container && this.el){
7326 this.el = Roo.get(this.el);
7327 container = this.el.dom.parentNode;
7328 this.allowDomMove = false;
7330 this.container = Roo.get(container);
7331 this.rendered = true;
7332 if(position !== undefined){
7333 if(typeof position == 'number'){
7334 position = this.container.dom.childNodes[position];
7336 position = Roo.getDom(position);
7339 this.onRender(this.container, position || null);
7341 this.el.addClass(this.cls);
7345 this.el.applyStyles(this.style);
7348 this.fireEvent("render", this);
7349 this.afterRender(this.container);
7361 // default function is not really useful
7362 onRender : function(ct, position){
7364 this.el = Roo.get(this.el);
7365 if(this.allowDomMove !== false){
7366 ct.dom.insertBefore(this.el.dom, position);
7372 getAutoCreate : function(){
7373 var cfg = typeof this.autoCreate == "object" ?
7374 this.autoCreate : Roo.apply({}, this.defaultAutoCreate);
7375 if(this.id && !cfg.id){
7382 afterRender : Roo.emptyFn,
7385 * Destroys this component by purging any event listeners, removing the component's element from the DOM,
7386 * removing the component from its {@link Roo.Container} (if applicable) and unregistering it from {@link Roo.ComponentMgr}.
7388 destroy : function(){
7389 if(this.fireEvent("beforedestroy", this) !== false){
7390 this.purgeListeners();
7391 this.beforeDestroy();
7393 this.el.removeAllListeners();
7395 if(this.actionMode == "container"){
7396 this.container.remove();
7400 Roo.ComponentMgr.unregister(this);
7401 this.fireEvent("destroy", this);
7406 beforeDestroy : function(){
7411 onDestroy : function(){
7416 * Returns the underlying {@link Roo.Element}.
7417 * @return {Roo.Element} The element
7424 * Returns the id of this component.
7432 * Try to focus this component.
7433 * @param {Boolean} selectText True to also select the text in this component (if applicable)
7434 * @return {Roo.Component} this
7436 focus : function(selectText){
7439 if(selectText === true){
7440 this.el.dom.select();
7455 * Disable this component.
7456 * @return {Roo.Component} this
7458 disable : function(){
7462 this.disabled = true;
7463 this.fireEvent("disable", this);
7468 onDisable : function(){
7469 this.getActionEl().addClass(this.disabledClass);
7470 this.el.dom.disabled = true;
7474 * Enable this component.
7475 * @return {Roo.Component} this
7477 enable : function(){
7481 this.disabled = false;
7482 this.fireEvent("enable", this);
7487 onEnable : function(){
7488 this.getActionEl().removeClass(this.disabledClass);
7489 this.el.dom.disabled = false;
7493 * Convenience function for setting disabled/enabled by boolean.
7494 * @param {Boolean} disabled
7496 setDisabled : function(disabled){
7497 this[disabled ? "disable" : "enable"]();
7501 * Show this component.
7502 * @return {Roo.Component} this
7505 if(this.fireEvent("beforeshow", this) !== false){
7506 this.hidden = false;
7510 this.fireEvent("show", this);
7516 onShow : function(){
7517 var ae = this.getActionEl();
7518 if(this.hideMode == 'visibility'){
7519 ae.dom.style.visibility = "visible";
7520 }else if(this.hideMode == 'offsets'){
7521 ae.removeClass('x-hidden');
7523 ae.dom.style.display = "";
7528 * Hide this component.
7529 * @return {Roo.Component} this
7532 if(this.fireEvent("beforehide", this) !== false){
7537 this.fireEvent("hide", this);
7543 onHide : function(){
7544 var ae = this.getActionEl();
7545 if(this.hideMode == 'visibility'){
7546 ae.dom.style.visibility = "hidden";
7547 }else if(this.hideMode == 'offsets'){
7548 ae.addClass('x-hidden');
7550 ae.dom.style.display = "none";
7555 * Convenience function to hide or show this component by boolean.
7556 * @param {Boolean} visible True to show, false to hide
7557 * @return {Roo.Component} this
7559 setVisible: function(visible){
7569 * Returns true if this component is visible.
7571 isVisible : function(){
7572 return this.getActionEl().isVisible();
7575 cloneConfig : function(overrides){
7576 overrides = overrides || {};
7577 var id = overrides.id || Roo.id();
7578 var cfg = Roo.applyIf(overrides, this.initialConfig);
7579 cfg.id = id; // prevent dup id
7580 return new this.constructor(cfg);
7584 * Ext JS Library 1.1.1
7585 * Copyright(c) 2006-2007, Ext JS, LLC.
7587 * Originally Released Under LGPL - original licence link has changed is not relivant.
7590 * <script type="text/javascript">
7595 * @extends Roo.Element
7596 * An extended {@link Roo.Element} object that supports a shadow and shim, constrain to viewport and
7597 * automatic maintaining of shadow/shim positions.
7598 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
7599 * @cfg {String/Boolean} shadow True to create a shadow element with default class "x-layer-shadow", or
7600 * you can pass a string with a CSS class name. False turns off the shadow.
7601 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: "div", cls: "x-layer"}).
7602 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
7603 * @cfg {String} cls CSS class to add to the element
7604 * @cfg {Number} zindex Starting z-index (defaults to 11000)
7605 * @cfg {Number} shadowOffset Number of pixels to offset the shadow (defaults to 3)
7607 * @param {Object} config An object with config options.
7608 * @param {String/HTMLElement} existingEl (optional) Uses an existing DOM element. If the element is not found it creates it.
7611 Roo.Layer = function(config, existingEl){
7612 config = config || {};
7613 var dh = Roo.DomHelper;
7614 var cp = config.parentEl, pel = cp ? Roo.getDom(cp) : document.body;
7616 this.dom = Roo.getDom(existingEl);
7619 var o = config.dh || {tag: "div", cls: "x-layer"};
7620 this.dom = dh.append(pel, o);
7623 this.addClass(config.cls);
7625 this.constrain = config.constrain !== false;
7626 this.visibilityMode = Roo.Element.VISIBILITY;
7628 this.id = this.dom.id = config.id;
7630 this.id = Roo.id(this.dom);
7632 this.zindex = config.zindex || this.getZIndex();
7633 this.position("absolute", this.zindex);
7635 this.shadowOffset = config.shadowOffset || 4;
7636 this.shadow = new Roo.Shadow({
7637 offset : this.shadowOffset,
7638 mode : config.shadow
7641 this.shadowOffset = 0;
7643 this.useShim = config.shim !== false && Roo.useShims;
7644 this.useDisplay = config.useDisplay;
7648 var supr = Roo.Element.prototype;
7650 // shims are shared among layer to keep from having 100 iframes
7653 Roo.extend(Roo.Layer, Roo.Element, {
7655 getZIndex : function(){
7656 return this.zindex || parseInt(this.getStyle("z-index"), 10) || 11000;
7659 getShim : function(){
7666 var shim = shims.shift();
7668 shim = this.createShim();
7669 shim.enableDisplayMode('block');
7670 shim.dom.style.display = 'none';
7671 shim.dom.style.visibility = 'visible';
7673 var pn = this.dom.parentNode;
7674 if(shim.dom.parentNode != pn){
7675 pn.insertBefore(shim.dom, this.dom);
7677 shim.setStyle('z-index', this.getZIndex()-2);
7682 hideShim : function(){
7684 this.shim.setDisplayed(false);
7685 shims.push(this.shim);
7690 disableShadow : function(){
7692 this.shadowDisabled = true;
7694 this.lastShadowOffset = this.shadowOffset;
7695 this.shadowOffset = 0;
7699 enableShadow : function(show){
7701 this.shadowDisabled = false;
7702 this.shadowOffset = this.lastShadowOffset;
7703 delete this.lastShadowOffset;
7711 // this code can execute repeatedly in milliseconds (i.e. during a drag) so
7712 // code size was sacrificed for effeciency (e.g. no getBox/setBox, no XY calls)
7713 sync : function(doShow){
7714 var sw = this.shadow;
7715 if(!this.updating && this.isVisible() && (sw || this.useShim)){
7716 var sh = this.getShim();
7718 var w = this.getWidth(),
7719 h = this.getHeight();
7721 var l = this.getLeft(true),
7722 t = this.getTop(true);
7724 if(sw && !this.shadowDisabled){
7725 if(doShow && !sw.isVisible()){
7728 sw.realign(l, t, w, h);
7734 // fit the shim behind the shadow, so it is shimmed too
7735 var a = sw.adjusts, s = sh.dom.style;
7736 s.left = (Math.min(l, l+a.l))+"px";
7737 s.top = (Math.min(t, t+a.t))+"px";
7738 s.width = (w+a.w)+"px";
7739 s.height = (h+a.h)+"px";
7746 sh.setLeftTop(l, t);
7753 destroy : function(){
7758 this.removeAllListeners();
7759 var pn = this.dom.parentNode;
7761 pn.removeChild(this.dom);
7763 Roo.Element.uncache(this.id);
7766 remove : function(){
7771 beginUpdate : function(){
7772 this.updating = true;
7776 endUpdate : function(){
7777 this.updating = false;
7782 hideUnders : function(negOffset){
7790 constrainXY : function(){
7792 var vw = Roo.lib.Dom.getViewWidth(),
7793 vh = Roo.lib.Dom.getViewHeight();
7794 var s = Roo.get(document).getScroll();
7796 var xy = this.getXY();
7797 var x = xy[0], y = xy[1];
7798 var w = this.dom.offsetWidth+this.shadowOffset, h = this.dom.offsetHeight+this.shadowOffset;
7799 // only move it if it needs it
7801 // first validate right/bottom
7802 if((x + w) > vw+s.left){
7803 x = vw - w - this.shadowOffset;
7806 if((y + h) > vh+s.top){
7807 y = vh - h - this.shadowOffset;
7810 // then make sure top/left isn't negative
7821 var ay = this.avoidY;
7822 if(y <= ay && (y+h) >= ay){
7828 supr.setXY.call(this, xy);
7834 isVisible : function(){
7835 return this.visible;
7839 showAction : function(){
7840 this.visible = true; // track visibility to prevent getStyle calls
7841 if(this.useDisplay === true){
7842 this.setDisplayed("");
7843 }else if(this.lastXY){
7844 supr.setXY.call(this, this.lastXY);
7845 }else if(this.lastLT){
7846 supr.setLeftTop.call(this, this.lastLT[0], this.lastLT[1]);
7851 hideAction : function(){
7852 this.visible = false;
7853 if(this.useDisplay === true){
7854 this.setDisplayed(false);
7856 this.setLeftTop(-10000,-10000);
7860 // overridden Element method
7861 setVisible : function(v, a, d, c, e){
7866 var cb = function(){
7871 }.createDelegate(this);
7872 supr.setVisible.call(this, true, true, d, cb, e);
7875 this.hideUnders(true);
7884 }.createDelegate(this);
7886 supr.setVisible.call(this, v, a, d, cb, e);
7895 storeXY : function(xy){
7900 storeLeftTop : function(left, top){
7902 this.lastLT = [left, top];
7906 beforeFx : function(){
7907 this.beforeAction();
7908 return Roo.Layer.superclass.beforeFx.apply(this, arguments);
7912 afterFx : function(){
7913 Roo.Layer.superclass.afterFx.apply(this, arguments);
7914 this.sync(this.isVisible());
7918 beforeAction : function(){
7919 if(!this.updating && this.shadow){
7924 // overridden Element method
7925 setLeft : function(left){
7926 this.storeLeftTop(left, this.getTop(true));
7927 supr.setLeft.apply(this, arguments);
7931 setTop : function(top){
7932 this.storeLeftTop(this.getLeft(true), top);
7933 supr.setTop.apply(this, arguments);
7937 setLeftTop : function(left, top){
7938 this.storeLeftTop(left, top);
7939 supr.setLeftTop.apply(this, arguments);
7943 setXY : function(xy, a, d, c, e){
7945 this.beforeAction();
7947 var cb = this.createCB(c);
7948 supr.setXY.call(this, xy, a, d, cb, e);
7955 createCB : function(c){
7966 // overridden Element method
7967 setX : function(x, a, d, c, e){
7968 this.setXY([x, this.getY()], a, d, c, e);
7971 // overridden Element method
7972 setY : function(y, a, d, c, e){
7973 this.setXY([this.getX(), y], a, d, c, e);
7976 // overridden Element method
7977 setSize : function(w, h, a, d, c, e){
7978 this.beforeAction();
7979 var cb = this.createCB(c);
7980 supr.setSize.call(this, w, h, a, d, cb, e);
7986 // overridden Element method
7987 setWidth : function(w, a, d, c, e){
7988 this.beforeAction();
7989 var cb = this.createCB(c);
7990 supr.setWidth.call(this, w, a, d, cb, e);
7996 // overridden Element method
7997 setHeight : function(h, a, d, c, e){
7998 this.beforeAction();
7999 var cb = this.createCB(c);
8000 supr.setHeight.call(this, h, a, d, cb, e);
8006 // overridden Element method
8007 setBounds : function(x, y, w, h, a, d, c, e){
8008 this.beforeAction();
8009 var cb = this.createCB(c);
8011 this.storeXY([x, y]);
8012 supr.setXY.call(this, [x, y]);
8013 supr.setSize.call(this, w, h, a, d, cb, e);
8016 supr.setBounds.call(this, x, y, w, h, a, d, cb, e);
8022 * Sets the z-index of this layer and adjusts any shadow and shim z-indexes. The layer z-index is automatically
8023 * incremented by two more than the value passed in so that it always shows above any shadow or shim (the shadow
8024 * element, if any, will be assigned z-index + 1, and the shim element, if any, will be assigned the unmodified z-index).
8025 * @param {Number} zindex The new z-index to set
8026 * @return {this} The Layer
8028 setZIndex : function(zindex){
8029 this.zindex = zindex;
8030 this.setStyle("z-index", zindex + 2);
8032 this.shadow.setZIndex(zindex + 1);
8035 this.shim.setStyle("z-index", zindex);
8041 * Ext JS Library 1.1.1
8042 * Copyright(c) 2006-2007, Ext JS, LLC.
8044 * Originally Released Under LGPL - original licence link has changed is not relivant.
8047 * <script type="text/javascript">
8053 * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
8054 * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced
8055 * functionality that can also provide the same shadow effect, see the {@link Roo.Layer} class.
8057 * Create a new Shadow
8058 * @param {Object} config The config object
8060 Roo.Shadow = function(config){
8061 Roo.apply(this, config);
8062 if(typeof this.mode != "string"){
8063 this.mode = this.defaultMode;
8065 var o = this.offset, a = {h: 0};
8066 var rad = Math.floor(this.offset/2);
8067 switch(this.mode.toLowerCase()){ // all this hideous nonsense calculates the various offsets for shadows
8073 a.l -= this.offset + rad;
8074 a.t -= this.offset + rad;
8085 a.l -= (this.offset - rad);
8086 a.t -= this.offset + rad;
8088 a.w -= (this.offset - rad)*2;
8099 a.l -= (this.offset - rad);
8100 a.t -= (this.offset - rad);
8102 a.w -= (this.offset + rad + 1);
8103 a.h -= (this.offset + rad);
8112 Roo.Shadow.prototype = {
8114 * @cfg {String} mode
8115 * The shadow display mode. Supports the following options:<br />
8116 * sides: Shadow displays on both sides and bottom only<br />
8117 * frame: Shadow displays equally on all four sides<br />
8118 * drop: Traditional bottom-right drop shadow (default)
8121 * @cfg {String} offset
8122 * The number of pixels to offset the shadow from the element (defaults to 4)
8127 defaultMode: "drop",
8130 * Displays the shadow under the target element
8131 * @param {String/HTMLElement/Element} targetEl The id or element under which the shadow should display
8133 show : function(target){
8134 target = Roo.get(target);
8136 this.el = Roo.Shadow.Pool.pull();
8137 if(this.el.dom.nextSibling != target.dom){
8138 this.el.insertBefore(target);
8141 this.el.setStyle("z-index", this.zIndex || parseInt(target.getStyle("z-index"), 10)-1);
8143 this.el.dom.style.filter="progid:DXImageTransform.Microsoft.alpha(opacity=50) progid:DXImageTransform.Microsoft.Blur(pixelradius="+(this.offset)+")";
8146 target.getLeft(true),
8147 target.getTop(true),
8151 this.el.dom.style.display = "block";
8155 * Returns true if the shadow is visible, else false
8157 isVisible : function(){
8158 return this.el ? true : false;
8162 * Direct alignment when values are already available. Show must be called at least once before
8163 * calling this method to ensure it is initialized.
8164 * @param {Number} left The target element left position
8165 * @param {Number} top The target element top position
8166 * @param {Number} width The target element width
8167 * @param {Number} height The target element height
8169 realign : function(l, t, w, h){
8173 var a = this.adjusts, d = this.el.dom, s = d.style;
8175 s.left = (l+a.l)+"px";
8176 s.top = (t+a.t)+"px";
8177 var sw = (w+a.w), sh = (h+a.h), sws = sw +"px", shs = sh + "px";
8178 if(s.width != sws || s.height != shs){
8182 var cn = d.childNodes;
8183 var sww = Math.max(0, (sw-12))+"px";
8184 cn[0].childNodes[1].style.width = sww;
8185 cn[1].childNodes[1].style.width = sww;
8186 cn[2].childNodes[1].style.width = sww;
8187 cn[1].style.height = Math.max(0, (sh-12))+"px";
8197 this.el.dom.style.display = "none";
8198 Roo.Shadow.Pool.push(this.el);
8204 * Adjust the z-index of this shadow
8205 * @param {Number} zindex The new z-index
8207 setZIndex : function(z){
8210 this.el.setStyle("z-index", z);
8215 // Private utility class that manages the internal Shadow cache
8216 Roo.Shadow.Pool = function(){
8218 var markup = Roo.isIE ?
8219 '<div class="x-ie-shadow"></div>' :
8220 '<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>';
8225 sh = Roo.get(Roo.DomHelper.insertHtml("beforeBegin", document.body.firstChild, markup));
8226 sh.autoBoxAdjust = false;
8231 push : function(sh){
8237 * Ext JS Library 1.1.1
8238 * Copyright(c) 2006-2007, Ext JS, LLC.
8240 * Originally Released Under LGPL - original licence link has changed is not relivant.
8243 * <script type="text/javascript">
8247 * @class Roo.BoxComponent
8248 * @extends Roo.Component
8249 * Base class for any visual {@link Roo.Component} that uses a box container. BoxComponent provides automatic box
8250 * model adjustments for sizing and positioning and will work correctly withnin the Component rendering model. All
8251 * container classes should subclass BoxComponent so that they will work consistently when nested within other Ext
8252 * layout containers.
8254 * @param {Roo.Element/String/Object} config The configuration options.
8256 Roo.BoxComponent = function(config){
8257 Roo.Component.call(this, config);
8261 * Fires after the component is resized.
8262 * @param {Roo.Component} this
8263 * @param {Number} adjWidth The box-adjusted width that was set
8264 * @param {Number} adjHeight The box-adjusted height that was set
8265 * @param {Number} rawWidth The width that was originally specified
8266 * @param {Number} rawHeight The height that was originally specified
8271 * Fires after the component is moved.
8272 * @param {Roo.Component} this
8273 * @param {Number} x The new x position
8274 * @param {Number} y The new y position
8280 Roo.extend(Roo.BoxComponent, Roo.Component, {
8281 // private, set in afterRender to signify that the component has been rendered
8283 // private, used to defer height settings to subclasses
8285 /** @cfg {Number} width
8286 * width (optional) size of component
8288 /** @cfg {Number} height
8289 * height (optional) size of component
8293 * Sets the width and height of the component. This method fires the resize event. This method can accept
8294 * either width and height as separate numeric arguments, or you can pass a size object like {width:10, height:20}.
8295 * @param {Number/Object} width The new width to set, or a size object in the format {width, height}
8296 * @param {Number} height The new height to set (not required if a size object is passed as the first arg)
8297 * @return {Roo.BoxComponent} this
8299 setSize : function(w, h){
8300 // support for standard size objects
8301 if(typeof w == 'object'){
8312 // prevent recalcs when not needed
8313 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
8316 this.lastSize = {width: w, height: h};
8318 var adj = this.adjustSize(w, h);
8319 var aw = adj.width, ah = adj.height;
8320 if(aw !== undefined || ah !== undefined){ // this code is nasty but performs better with floaters
8321 var rz = this.getResizeEl();
8322 if(!this.deferHeight && aw !== undefined && ah !== undefined){
8324 }else if(!this.deferHeight && ah !== undefined){
8326 }else if(aw !== undefined){
8329 this.onResize(aw, ah, w, h);
8330 this.fireEvent('resize', this, aw, ah, w, h);
8336 * Gets the current size of the component's underlying element.
8337 * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
8339 getSize : function(){
8340 return this.el.getSize();
8344 * Gets the current XY position of the component's underlying element.
8345 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
8346 * @return {Array} The XY position of the element (e.g., [100, 200])
8348 getPosition : function(local){
8350 return [this.el.getLeft(true), this.el.getTop(true)];
8352 return this.xy || this.el.getXY();
8356 * Gets the current box measurements of the component's underlying element.
8357 * @param {Boolean} local (optional) If true the element's left and top are returned instead of page XY (defaults to false)
8358 * @returns {Object} box An object in the format {x, y, width, height}
8360 getBox : function(local){
8361 var s = this.el.getSize();
8363 s.x = this.el.getLeft(true);
8364 s.y = this.el.getTop(true);
8366 var xy = this.xy || this.el.getXY();
8374 * Sets the current box measurements of the component's underlying element.
8375 * @param {Object} box An object in the format {x, y, width, height}
8376 * @returns {Roo.BoxComponent} this
8378 updateBox : function(box){
8379 this.setSize(box.width, box.height);
8380 this.setPagePosition(box.x, box.y);
8385 getResizeEl : function(){
8386 return this.resizeEl || this.el;
8390 getPositionEl : function(){
8391 return this.positionEl || this.el;
8395 * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}.
8396 * This method fires the move event.
8397 * @param {Number} left The new left
8398 * @param {Number} top The new top
8399 * @returns {Roo.BoxComponent} this
8401 setPosition : function(x, y){
8407 var adj = this.adjustPosition(x, y);
8408 var ax = adj.x, ay = adj.y;
8410 var el = this.getPositionEl();
8411 if(ax !== undefined || ay !== undefined){
8412 if(ax !== undefined && ay !== undefined){
8413 el.setLeftTop(ax, ay);
8414 }else if(ax !== undefined){
8416 }else if(ay !== undefined){
8419 this.onPosition(ax, ay);
8420 this.fireEvent('move', this, ax, ay);
8426 * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
8427 * This method fires the move event.
8428 * @param {Number} x The new x position
8429 * @param {Number} y The new y position
8430 * @returns {Roo.BoxComponent} this
8432 setPagePosition : function(x, y){
8438 if(x === undefined || y === undefined){ // cannot translate undefined points
8441 var p = this.el.translatePoints(x, y);
8442 this.setPosition(p.left, p.top);
8447 onRender : function(ct, position){
8448 Roo.BoxComponent.superclass.onRender.call(this, ct, position);
8450 this.resizeEl = Roo.get(this.resizeEl);
8452 if(this.positionEl){
8453 this.positionEl = Roo.get(this.positionEl);
8458 afterRender : function(){
8459 Roo.BoxComponent.superclass.afterRender.call(this);
8460 this.boxReady = true;
8461 this.setSize(this.width, this.height);
8462 if(this.x || this.y){
8463 this.setPosition(this.x, this.y);
8465 if(this.pageX || this.pageY){
8466 this.setPagePosition(this.pageX, this.pageY);
8471 * Force the component's size to recalculate based on the underlying element's current height and width.
8472 * @returns {Roo.BoxComponent} this
8474 syncSize : function(){
8475 delete this.lastSize;
8476 this.setSize(this.el.getWidth(), this.el.getHeight());
8481 * Called after the component is resized, this method is empty by default but can be implemented by any
8482 * subclass that needs to perform custom logic after a resize occurs.
8483 * @param {Number} adjWidth The box-adjusted width that was set
8484 * @param {Number} adjHeight The box-adjusted height that was set
8485 * @param {Number} rawWidth The width that was originally specified
8486 * @param {Number} rawHeight The height that was originally specified
8488 onResize : function(adjWidth, adjHeight, rawWidth, rawHeight){
8493 * Called after the component is moved, this method is empty by default but can be implemented by any
8494 * subclass that needs to perform custom logic after a move occurs.
8495 * @param {Number} x The new x position
8496 * @param {Number} y The new y position
8498 onPosition : function(x, y){
8503 adjustSize : function(w, h){
8507 if(this.autoHeight){
8510 return {width : w, height: h};
8514 adjustPosition : function(x, y){
8515 return {x : x, y: y};
8519 * Ext JS Library 1.1.1
8520 * Copyright(c) 2006-2007, Ext JS, LLC.
8522 * Originally Released Under LGPL - original licence link has changed is not relivant.
8525 * <script type="text/javascript">
8530 * @class Roo.SplitBar
8531 * @extends Roo.util.Observable
8532 * Creates draggable splitter bar functionality from two elements (element to be dragged and element to be resized).
8536 var split = new Roo.SplitBar("elementToDrag", "elementToSize",
8537 Roo.SplitBar.HORIZONTAL, Roo.SplitBar.LEFT);
8538 split.setAdapter(new Roo.SplitBar.AbsoluteLayoutAdapter("container"));
8539 split.minSize = 100;
8540 split.maxSize = 600;
8541 split.animate = true;
8542 split.on('moved', splitterMoved);
8545 * Create a new SplitBar
8546 * @param {String/HTMLElement/Roo.Element} dragElement The element to be dragged and act as the SplitBar.
8547 * @param {String/HTMLElement/Roo.Element} resizingElement The element to be resized based on where the SplitBar element is dragged
8548 * @param {Number} orientation (optional) Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
8549 * @param {Number} placement (optional) Either Roo.SplitBar.LEFT or Roo.SplitBar.RIGHT for horizontal or
8550 Roo.SplitBar.TOP or Roo.SplitBar.BOTTOM for vertical. (By default, this is determined automatically by the initial
8551 position of the SplitBar).
8553 Roo.SplitBar = function(dragElement, resizingElement, orientation, placement, existingProxy){
8556 this.el = Roo.get(dragElement, true);
8557 this.el.dom.unselectable = "on";
8559 this.resizingEl = Roo.get(resizingElement, true);
8563 * The orientation of the split. Either Roo.SplitBar.HORIZONTAL or Roo.SplitBar.VERTICAL. (Defaults to HORIZONTAL)
8564 * Note: If this is changed after creating the SplitBar, the placement property must be manually updated
8567 this.orientation = orientation || Roo.SplitBar.HORIZONTAL;
8570 * The minimum size of the resizing element. (Defaults to 0)
8576 * The maximum size of the resizing element. (Defaults to 2000)
8579 this.maxSize = 2000;
8582 * Whether to animate the transition to the new size
8585 this.animate = false;
8588 * Whether to create a transparent shim that overlays the page when dragging, enables dragging across iframes.
8591 this.useShim = false;
8598 this.proxy = Roo.SplitBar.createProxy(this.orientation);
8600 this.proxy = Roo.get(existingProxy).dom;
8603 this.dd = new Roo.dd.DDProxy(this.el.dom.id, "XSplitBars", {dragElId : this.proxy.id});
8606 this.dd.b4StartDrag = this.onStartProxyDrag.createDelegate(this);
8609 this.dd.endDrag = this.onEndProxyDrag.createDelegate(this);
8612 this.dragSpecs = {};
8615 * @private The adapter to use to positon and resize elements
8617 this.adapter = new Roo.SplitBar.BasicLayoutAdapter();
8618 this.adapter.init(this);
8620 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8622 this.placement = placement || (this.el.getX() > this.resizingEl.getX() ? Roo.SplitBar.LEFT : Roo.SplitBar.RIGHT);
8623 this.el.addClass("x-splitbar-h");
8626 this.placement = placement || (this.el.getY() > this.resizingEl.getY() ? Roo.SplitBar.TOP : Roo.SplitBar.BOTTOM);
8627 this.el.addClass("x-splitbar-v");
8633 * Fires when the splitter is moved (alias for {@link #event-moved})
8634 * @param {Roo.SplitBar} this
8635 * @param {Number} newSize the new width or height
8640 * Fires when the splitter is moved
8641 * @param {Roo.SplitBar} this
8642 * @param {Number} newSize the new width or height
8646 * @event beforeresize
8647 * Fires before the splitter is dragged
8648 * @param {Roo.SplitBar} this
8650 "beforeresize" : true,
8652 "beforeapply" : true
8655 Roo.util.Observable.call(this);
8658 Roo.extend(Roo.SplitBar, Roo.util.Observable, {
8659 onStartProxyDrag : function(x, y){
8660 this.fireEvent("beforeresize", this);
8662 var o = Roo.DomHelper.insertFirst(document.body, {cls: "x-drag-overlay", html: " "}, true);
8664 o.enableDisplayMode("block");
8665 // all splitbars share the same overlay
8666 Roo.SplitBar.prototype.overlay = o;
8668 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
8669 this.overlay.show();
8670 Roo.get(this.proxy).setDisplayed("block");
8671 var size = this.adapter.getElementSize(this);
8672 this.activeMinSize = this.getMinimumSize();;
8673 this.activeMaxSize = this.getMaximumSize();;
8674 var c1 = size - this.activeMinSize;
8675 var c2 = Math.max(this.activeMaxSize - size, 0);
8676 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8677 this.dd.resetConstraints();
8678 this.dd.setXConstraint(
8679 this.placement == Roo.SplitBar.LEFT ? c1 : c2,
8680 this.placement == Roo.SplitBar.LEFT ? c2 : c1
8682 this.dd.setYConstraint(0, 0);
8684 this.dd.resetConstraints();
8685 this.dd.setXConstraint(0, 0);
8686 this.dd.setYConstraint(
8687 this.placement == Roo.SplitBar.TOP ? c1 : c2,
8688 this.placement == Roo.SplitBar.TOP ? c2 : c1
8691 this.dragSpecs.startSize = size;
8692 this.dragSpecs.startPoint = [x, y];
8693 Roo.dd.DDProxy.prototype.b4StartDrag.call(this.dd, x, y);
8697 * @private Called after the drag operation by the DDProxy
8699 onEndProxyDrag : function(e){
8700 Roo.get(this.proxy).setDisplayed(false);
8701 var endPoint = Roo.lib.Event.getXY(e);
8703 this.overlay.hide();
8706 if(this.orientation == Roo.SplitBar.HORIZONTAL){
8707 newSize = this.dragSpecs.startSize +
8708 (this.placement == Roo.SplitBar.LEFT ?
8709 endPoint[0] - this.dragSpecs.startPoint[0] :
8710 this.dragSpecs.startPoint[0] - endPoint[0]
8713 newSize = this.dragSpecs.startSize +
8714 (this.placement == Roo.SplitBar.TOP ?
8715 endPoint[1] - this.dragSpecs.startPoint[1] :
8716 this.dragSpecs.startPoint[1] - endPoint[1]
8719 newSize = Math.min(Math.max(newSize, this.activeMinSize), this.activeMaxSize);
8720 if(newSize != this.dragSpecs.startSize){
8721 if(this.fireEvent('beforeapply', this, newSize) !== false){
8722 this.adapter.setElementSize(this, newSize);
8723 this.fireEvent("moved", this, newSize);
8724 this.fireEvent("resize", this, newSize);
8730 * Get the adapter this SplitBar uses
8731 * @return The adapter object
8733 getAdapter : function(){
8734 return this.adapter;
8738 * Set the adapter this SplitBar uses
8739 * @param {Object} adapter A SplitBar adapter object
8741 setAdapter : function(adapter){
8742 this.adapter = adapter;
8743 this.adapter.init(this);
8747 * Gets the minimum size for the resizing element
8748 * @return {Number} The minimum size
8750 getMinimumSize : function(){
8751 return this.minSize;
8755 * Sets the minimum size for the resizing element
8756 * @param {Number} minSize The minimum size
8758 setMinimumSize : function(minSize){
8759 this.minSize = minSize;
8763 * Gets the maximum size for the resizing element
8764 * @return {Number} The maximum size
8766 getMaximumSize : function(){
8767 return this.maxSize;
8771 * Sets the maximum size for the resizing element
8772 * @param {Number} maxSize The maximum size
8774 setMaximumSize : function(maxSize){
8775 this.maxSize = maxSize;
8779 * Sets the initialize size for the resizing element
8780 * @param {Number} size The initial size
8782 setCurrentSize : function(size){
8783 var oldAnimate = this.animate;
8784 this.animate = false;
8785 this.adapter.setElementSize(this, size);
8786 this.animate = oldAnimate;
8790 * Destroy this splitbar.
8791 * @param {Boolean} removeEl True to remove the element
8793 destroy : function(removeEl){
8798 this.proxy.parentNode.removeChild(this.proxy);
8806 * @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.
8808 Roo.SplitBar.createProxy = function(dir){
8809 var proxy = new Roo.Element(document.createElement("div"));
8810 proxy.unselectable();
8811 var cls = 'x-splitbar-proxy';
8812 proxy.addClass(cls + ' ' + (dir == Roo.SplitBar.HORIZONTAL ? cls +'-h' : cls + '-v'));
8813 document.body.appendChild(proxy.dom);
8818 * @class Roo.SplitBar.BasicLayoutAdapter
8819 * Default Adapter. It assumes the splitter and resizing element are not positioned
8820 * elements and only gets/sets the width of the element. Generally used for table based layouts.
8822 Roo.SplitBar.BasicLayoutAdapter = function(){
8825 Roo.SplitBar.BasicLayoutAdapter.prototype = {
8826 // do nothing for now
8831 * Called before drag operations to get the current size of the resizing element.
8832 * @param {Roo.SplitBar} s The SplitBar using this adapter
8834 getElementSize : function(s){
8835 if(s.orientation == Roo.SplitBar.HORIZONTAL){
8836 return s.resizingEl.getWidth();
8838 return s.resizingEl.getHeight();
8843 * Called after drag operations to set the size of the resizing element.
8844 * @param {Roo.SplitBar} s The SplitBar using this adapter
8845 * @param {Number} newSize The new size to set
8846 * @param {Function} onComplete A function to be invoked when resizing is complete
8848 setElementSize : function(s, newSize, onComplete){
8849 if(s.orientation == Roo.SplitBar.HORIZONTAL){
8851 s.resizingEl.setWidth(newSize);
8853 onComplete(s, newSize);
8856 s.resizingEl.setWidth(newSize, true, .1, onComplete, 'easeOut');
8861 s.resizingEl.setHeight(newSize);
8863 onComplete(s, newSize);
8866 s.resizingEl.setHeight(newSize, true, .1, onComplete, 'easeOut');
8873 *@class Roo.SplitBar.AbsoluteLayoutAdapter
8874 * @extends Roo.SplitBar.BasicLayoutAdapter
8875 * Adapter that moves the splitter element to align with the resized sizing element.
8876 * Used with an absolute positioned SplitBar.
8877 * @param {String/HTMLElement/Roo.Element} container The container that wraps around the absolute positioned content. If it's
8878 * document.body, make sure you assign an id to the body element.
8880 Roo.SplitBar.AbsoluteLayoutAdapter = function(container){
8881 this.basic = new Roo.SplitBar.BasicLayoutAdapter();
8882 this.container = Roo.get(container);
8885 Roo.SplitBar.AbsoluteLayoutAdapter.prototype = {
8890 getElementSize : function(s){
8891 return this.basic.getElementSize(s);
8894 setElementSize : function(s, newSize, onComplete){
8895 this.basic.setElementSize(s, newSize, this.moveSplitter.createDelegate(this, [s]));
8898 moveSplitter : function(s){
8899 var yes = Roo.SplitBar;
8900 switch(s.placement){
8902 s.el.setX(s.resizingEl.getRight());
8905 s.el.setStyle("right", (this.container.getWidth() - s.resizingEl.getLeft()) + "px");
8908 s.el.setY(s.resizingEl.getBottom());
8911 s.el.setY(s.resizingEl.getTop() - s.el.getHeight());
8918 * Orientation constant - Create a vertical SplitBar
8922 Roo.SplitBar.VERTICAL = 1;
8925 * Orientation constant - Create a horizontal SplitBar
8929 Roo.SplitBar.HORIZONTAL = 2;
8932 * Placement constant - The resizing element is to the left of the splitter element
8936 Roo.SplitBar.LEFT = 1;
8939 * Placement constant - The resizing element is to the right of the splitter element
8943 Roo.SplitBar.RIGHT = 2;
8946 * Placement constant - The resizing element is positioned above the splitter element
8950 Roo.SplitBar.TOP = 3;
8953 * Placement constant - The resizing element is positioned under splitter element
8957 Roo.SplitBar.BOTTOM = 4;
8960 * Ext JS Library 1.1.1
8961 * Copyright(c) 2006-2007, Ext JS, LLC.
8963 * Originally Released Under LGPL - original licence link has changed is not relivant.
8966 * <script type="text/javascript">
8971 * @extends Roo.util.Observable
8972 * Create a "View" for an element based on a data model or UpdateManager and the supplied DomHelper template.
8973 * This class also supports single and multi selection modes. <br>
8974 * Create a data model bound view:
8976 var store = new Roo.data.Store(...);
8978 var view = new Roo.View({
8980 template : '<div id="{0}">{2} - {1}</div>', // auto create template
8983 selectedClass: "ydataview-selected",
8987 // listen for node click?
8988 view.on("click", function(vw, index, node, e){
8989 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
8993 dataModel.load("foobar.xml");
8995 For an example of creating a JSON/UpdateManager view, see {@link Roo.JsonView}.
8997 * <b>Note: The root of your template must be a single node. Table/row implementations may work but are not supported due to
8998 * IE"s limited insertion support with tables and Opera"s faulty event bubbling.</b>
9000 * Note: old style constructor is still suported (container, template, config)
9004 * @param {Object} config The config object
9007 Roo.View = function(config, depreciated_tpl, depreciated_config){
9009 if (typeof(depreciated_tpl) == 'undefined') {
9010 // new way.. - universal constructor.
9011 Roo.apply(this, config);
9012 this.el = Roo.get(this.el);
9015 this.el = Roo.get(config);
9016 this.tpl = depreciated_tpl;
9017 Roo.apply(this, depreciated_config);
9021 if(typeof(this.tpl) == "string"){
9022 this.tpl = new Roo.Template(this.tpl);
9033 * @event beforeclick
9034 * Fires before a click is processed. Returns false to cancel the default action.
9035 * @param {Roo.View} this
9036 * @param {Number} index The index of the target node
9037 * @param {HTMLElement} node The target node
9038 * @param {Roo.EventObject} e The raw event object
9040 "beforeclick" : true,
9043 * Fires when a template node is clicked.
9044 * @param {Roo.View} this
9045 * @param {Number} index The index of the target node
9046 * @param {HTMLElement} node The target node
9047 * @param {Roo.EventObject} e The raw event object
9052 * Fires when a template node is double clicked.
9053 * @param {Roo.View} this
9054 * @param {Number} index The index of the target node
9055 * @param {HTMLElement} node The target node
9056 * @param {Roo.EventObject} e The raw event object
9060 * @event contextmenu
9061 * Fires when a template node is right clicked.
9062 * @param {Roo.View} this
9063 * @param {Number} index The index of the target node
9064 * @param {HTMLElement} node The target node
9065 * @param {Roo.EventObject} e The raw event object
9067 "contextmenu" : true,
9069 * @event selectionchange
9070 * Fires when the selected nodes change.
9071 * @param {Roo.View} this
9072 * @param {Array} selections Array of the selected nodes
9074 "selectionchange" : true,
9077 * @event beforeselect
9078 * Fires before a selection is made. If any handlers return false, the selection is cancelled.
9079 * @param {Roo.View} this
9080 * @param {HTMLElement} node The node to be selected
9081 * @param {Array} selections Array of currently selected nodes
9083 "beforeselect" : true
9087 "click": this.onClick,
9088 "dblclick": this.onDblClick,
9089 "contextmenu": this.onContextMenu,
9093 this.selections = [];
9095 this.cmp = new Roo.CompositeElementLite([]);
9097 this.store = Roo.factory(this.store, Roo.data);
9098 this.setStore(this.store, true);
9100 Roo.View.superclass.constructor.call(this);
9103 Roo.extend(Roo.View, Roo.util.Observable, {
9106 * @cfg {Roo.data.Store} store Data store to load data from.
9111 * @cfg {String|Roo.Element} el The container element.
9116 * @cfg {String|Roo.Template} tpl The template used by this View
9121 * @cfg {String} selectedClass The css class to add to selected nodes
9123 selectedClass : "x-view-selected",
9125 * @cfg {String} emptyText The empty text to show when nothing is loaded.
9129 * Returns the element this view is bound to.
9130 * @return {Roo.Element}
9137 * Refreshes the view.
9139 refresh : function(){
9141 this.clearSelections();
9144 var records = this.store.getRange();
9145 if(records.length < 1){
9146 this.el.update(this.emptyText);
9149 for(var i = 0, len = records.length; i < len; i++){
9150 var data = this.prepareData(records[i].data, i, records[i]);
9151 html[html.length] = t.apply(data);
9153 this.el.update(html.join(""));
9154 this.nodes = this.el.dom.childNodes;
9155 this.updateIndexes(0);
9159 * Function to override to reformat the data that is sent to
9160 * the template for each node.
9161 * @param {Array/Object} data The raw data (array of colData for a data model bound view or
9162 * a JSON object for an UpdateManager bound view).
9164 prepareData : function(data){
9168 onUpdate : function(ds, record){
9169 this.clearSelections();
9170 var index = this.store.indexOf(record);
9171 var n = this.nodes[index];
9172 this.tpl.insertBefore(n, this.prepareData(record.data));
9173 n.parentNode.removeChild(n);
9174 this.updateIndexes(index, index);
9177 onAdd : function(ds, records, index){
9178 this.clearSelections();
9179 if(this.nodes.length == 0){
9183 var n = this.nodes[index];
9184 for(var i = 0, len = records.length; i < len; i++){
9185 var d = this.prepareData(records[i].data);
9187 this.tpl.insertBefore(n, d);
9189 this.tpl.append(this.el, d);
9192 this.updateIndexes(index);
9195 onRemove : function(ds, record, index){
9196 this.clearSelections();
9197 this.el.dom.removeChild(this.nodes[index]);
9198 this.updateIndexes(index);
9202 * Refresh an individual node.
9203 * @param {Number} index
9205 refreshNode : function(index){
9206 this.onUpdate(this.store, this.store.getAt(index));
9209 updateIndexes : function(startIndex, endIndex){
9210 var ns = this.nodes;
9211 startIndex = startIndex || 0;
9212 endIndex = endIndex || ns.length - 1;
9213 for(var i = startIndex; i <= endIndex; i++){
9214 ns[i].nodeIndex = i;
9219 * Changes the data store this view uses and refresh the view.
9220 * @param {Store} store
9222 setStore : function(store, initial){
9223 if(!initial && this.store){
9224 this.store.un("datachanged", this.refresh);
9225 this.store.un("add", this.onAdd);
9226 this.store.un("remove", this.onRemove);
9227 this.store.un("update", this.onUpdate);
9228 this.store.un("clear", this.refresh);
9232 store.on("datachanged", this.refresh, this);
9233 store.on("add", this.onAdd, this);
9234 store.on("remove", this.onRemove, this);
9235 store.on("update", this.onUpdate, this);
9236 store.on("clear", this.refresh, this);
9245 * Returns the template node the passed child belongs to or null if it doesn't belong to one.
9246 * @param {HTMLElement} node
9247 * @return {HTMLElement} The template node
9249 findItemFromChild : function(node){
9250 var el = this.el.dom;
9251 if(!node || node.parentNode == el){
9254 var p = node.parentNode;
9255 while(p && p != el){
9256 if(p.parentNode == el){
9265 onClick : function(e){
9266 var item = this.findItemFromChild(e.getTarget());
9268 var index = this.indexOf(item);
9269 if(this.onItemClick(item, index, e) !== false){
9270 this.fireEvent("click", this, index, item, e);
9273 this.clearSelections();
9278 onContextMenu : function(e){
9279 var item = this.findItemFromChild(e.getTarget());
9281 this.fireEvent("contextmenu", this, this.indexOf(item), item, e);
9286 onDblClick : function(e){
9287 var item = this.findItemFromChild(e.getTarget());
9289 this.fireEvent("dblclick", this, this.indexOf(item), item, e);
9293 onItemClick : function(item, index, e){
9294 if(this.fireEvent("beforeclick", this, index, item, e) === false){
9297 if(this.multiSelect || this.singleSelect){
9298 if(this.multiSelect && e.shiftKey && this.lastSelection){
9299 this.select(this.getNodes(this.indexOf(this.lastSelection), index), false);
9301 this.select(item, this.multiSelect && e.ctrlKey);
9302 this.lastSelection = item;
9310 * Get the number of selected nodes.
9313 getSelectionCount : function(){
9314 return this.selections.length;
9318 * Get the currently selected nodes.
9319 * @return {Array} An array of HTMLElements
9321 getSelectedNodes : function(){
9322 return this.selections;
9326 * Get the indexes of the selected nodes.
9329 getSelectedIndexes : function(){
9330 var indexes = [], s = this.selections;
9331 for(var i = 0, len = s.length; i < len; i++){
9332 indexes.push(s[i].nodeIndex);
9338 * Clear all selections
9339 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange event
9341 clearSelections : function(suppressEvent){
9342 if(this.nodes && (this.multiSelect || this.singleSelect) && this.selections.length > 0){
9343 this.cmp.elements = this.selections;
9344 this.cmp.removeClass(this.selectedClass);
9345 this.selections = [];
9347 this.fireEvent("selectionchange", this, this.selections);
9353 * Returns true if the passed node is selected
9354 * @param {HTMLElement/Number} node The node or node index
9357 isSelected : function(node){
9358 var s = this.selections;
9362 node = this.getNode(node);
9363 return s.indexOf(node) !== -1;
9368 * @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
9369 * @param {Boolean} keepExisting (optional) true to keep existing selections
9370 * @param {Boolean} suppressEvent (optional) true to skip firing of the selectionchange vent
9372 select : function(nodeInfo, keepExisting, suppressEvent){
9373 if(nodeInfo instanceof Array){
9375 this.clearSelections(true);
9377 for(var i = 0, len = nodeInfo.length; i < len; i++){
9378 this.select(nodeInfo[i], true, true);
9381 var node = this.getNode(nodeInfo);
9382 if(node && !this.isSelected(node)){
9384 this.clearSelections(true);
9386 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
9387 Roo.fly(node).addClass(this.selectedClass);
9388 this.selections.push(node);
9390 this.fireEvent("selectionchange", this, this.selections);
9398 * Gets a template node.
9399 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
9400 * @return {HTMLElement} The node or null if it wasn't found
9402 getNode : function(nodeInfo){
9403 if(typeof nodeInfo == "string"){
9404 return document.getElementById(nodeInfo);
9405 }else if(typeof nodeInfo == "number"){
9406 return this.nodes[nodeInfo];
9412 * Gets a range template nodes.
9413 * @param {Number} startIndex
9414 * @param {Number} endIndex
9415 * @return {Array} An array of nodes
9417 getNodes : function(start, end){
9418 var ns = this.nodes;
9420 end = typeof end == "undefined" ? ns.length - 1 : end;
9423 for(var i = start; i <= end; i++){
9427 for(var i = start; i >= end; i--){
9435 * Finds the index of the passed node
9436 * @param {HTMLElement/String/Number} nodeInfo An HTMLElement template node, index of a template node or the id of a template node
9437 * @return {Number} The index of the node or -1
9439 indexOf : function(node){
9440 node = this.getNode(node);
9441 if(typeof node.nodeIndex == "number"){
9442 return node.nodeIndex;
9444 var ns = this.nodes;
9445 for(var i = 0, len = ns.length; i < len; i++){
9455 * Ext JS Library 1.1.1
9456 * Copyright(c) 2006-2007, Ext JS, LLC.
9458 * Originally Released Under LGPL - original licence link has changed is not relivant.
9461 * <script type="text/javascript">
9465 * @class Roo.JsonView
9467 * Shortcut class to create a JSON + {@link Roo.UpdateManager} template view. Usage:
9469 var view = new Roo.JsonView({
9470 container: "my-element",
9471 template: '<div id="{id}">{foo} - {bar}</div>', // auto create template
9476 // listen for node click?
9477 view.on("click", function(vw, index, node, e){
9478 alert('Node "' + node.id + '" at index: ' + index + " was clicked.");
9481 // direct load of JSON data
9482 view.load("foobar.php");
9484 // Example from my blog list
9485 var tpl = new Roo.Template(
9486 '<div class="entry">' +
9487 '<a class="entry-title" href="{link}">{title}</a>' +
9488 "<h4>{date} by {author} | {comments} Comments</h4>{description}" +
9489 "</div><hr />"
9492 var moreView = new Roo.JsonView({
9493 container : "entry-list",
9497 moreView.on("beforerender", this.sortEntries, this);
9499 url: "/blog/get-posts.php",
9500 params: "allposts=true",
9501 text: "Loading Blog Entries..."
9505 * Note: old code is supported with arguments : (container, template, config)
9509 * Create a new JsonView
9511 * @param {Object} config The config object
9514 Roo.JsonView = function(config, depreciated_tpl, depreciated_config){
9517 Roo.JsonView.superclass.constructor.call(this, config, depreciated_tpl, depreciated_config);
9519 var um = this.el.getUpdateManager();
9520 um.setRenderer(this);
9521 um.on("update", this.onLoad, this);
9522 um.on("failure", this.onLoadException, this);
9525 * @event beforerender
9526 * Fires before rendering of the downloaded JSON data.
9527 * @param {Roo.JsonView} this
9528 * @param {Object} data The JSON data loaded
9532 * Fires when data is loaded.
9533 * @param {Roo.JsonView} this
9534 * @param {Object} data The JSON data loaded
9535 * @param {Object} response The raw Connect response object
9538 * @event loadexception
9539 * Fires when loading fails.
9540 * @param {Roo.JsonView} this
9541 * @param {Object} response The raw Connect response object
9544 'beforerender' : true,
9546 'loadexception' : true
9549 Roo.extend(Roo.JsonView, Roo.View, {
9551 * @type {String} The root property in the loaded JSON object that contains the data
9556 * Refreshes the view.
9558 refresh : function(){
9559 this.clearSelections();
9562 var o = this.jsonData;
9563 if(o && o.length > 0){
9564 for(var i = 0, len = o.length; i < len; i++){
9565 var data = this.prepareData(o[i], i, o);
9566 html[html.length] = this.tpl.apply(data);
9569 html.push(this.emptyText);
9571 this.el.update(html.join(""));
9572 this.nodes = this.el.dom.childNodes;
9573 this.updateIndexes(0);
9577 * 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.
9578 * @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:
9581 url: "your-url.php",
9582 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
9583 callback: yourFunction,
9584 scope: yourObject, //(optional scope)
9592 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
9593 * 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.
9594 * @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}
9595 * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
9596 * @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.
9599 var um = this.el.getUpdateManager();
9600 um.update.apply(um, arguments);
9603 render : function(el, response){
9604 this.clearSelections();
9608 o = Roo.util.JSON.decode(response.responseText);
9611 o = /** eval:var:o */ eval("o." + this.jsonRoot);
9616 * The current JSON data or null
9619 this.beforeRender();
9624 * Get the number of records in the current JSON dataset
9627 getCount : function(){
9628 return this.jsonData ? this.jsonData.length : 0;
9632 * Returns the JSON object for the specified node(s)
9633 * @param {HTMLElement/Array} node The node or an array of nodes
9634 * @return {Object/Array} If you pass in an array, you get an array back, otherwise
9635 * you get the JSON object for the node
9637 getNodeData : function(node){
9638 if(node instanceof Array){
9640 for(var i = 0, len = node.length; i < len; i++){
9641 data.push(this.getNodeData(node[i]));
9645 return this.jsonData[this.indexOf(node)] || null;
9648 beforeRender : function(){
9649 this.snapshot = this.jsonData;
9651 this.sort.apply(this, this.sortInfo);
9653 this.fireEvent("beforerender", this, this.jsonData);
9656 onLoad : function(el, o){
9657 this.fireEvent("load", this, this.jsonData, o);
9660 onLoadException : function(el, o){
9661 this.fireEvent("loadexception", this, o);
9665 * Filter the data by a specific property.
9666 * @param {String} property A property on your JSON objects
9667 * @param {String/RegExp} value Either string that the property values
9668 * should start with, or a RegExp to test against the property
9670 filter : function(property, value){
9673 var ss = this.snapshot;
9674 if(typeof value == "string"){
9675 var vlen = value.length;
9680 value = value.toLowerCase();
9681 for(var i = 0, len = ss.length; i < len; i++){
9683 if(o[property].substr(0, vlen).toLowerCase() == value){
9687 } else if(value.exec){ // regex?
9688 for(var i = 0, len = ss.length; i < len; i++){
9690 if(value.test(o[property])){
9697 this.jsonData = data;
9703 * Filter by a function. The passed function will be called with each
9704 * object in the current dataset. If the function returns true the value is kept,
9705 * otherwise it is filtered.
9706 * @param {Function} fn
9707 * @param {Object} scope (optional) The scope of the function (defaults to this JsonView)
9709 filterBy : function(fn, scope){
9712 var ss = this.snapshot;
9713 for(var i = 0, len = ss.length; i < len; i++){
9715 if(fn.call(scope || this, o)){
9719 this.jsonData = data;
9725 * Clears the current filter.
9727 clearFilter : function(){
9728 if(this.snapshot && this.jsonData != this.snapshot){
9729 this.jsonData = this.snapshot;
9736 * Sorts the data for this view and refreshes it.
9737 * @param {String} property A property on your JSON objects to sort on
9738 * @param {String} direction (optional) "desc" or "asc" (defaults to "asc")
9739 * @param {Function} sortType (optional) A function to call to convert the data to a sortable value.
9741 sort : function(property, dir, sortType){
9742 this.sortInfo = Array.prototype.slice.call(arguments, 0);
9745 var dsc = dir && dir.toLowerCase() == "desc";
9746 var f = function(o1, o2){
9747 var v1 = sortType ? sortType(o1[p]) : o1[p];
9748 var v2 = sortType ? sortType(o2[p]) : o2[p];
9751 return dsc ? +1 : -1;
9753 return dsc ? -1 : +1;
9758 this.jsonData.sort(f);
9760 if(this.jsonData != this.snapshot){
9761 this.snapshot.sort(f);
9767 * Ext JS Library 1.1.1
9768 * Copyright(c) 2006-2007, Ext JS, LLC.
9770 * Originally Released Under LGPL - original licence link has changed is not relivant.
9773 * <script type="text/javascript">
9778 * @class Roo.ColorPalette
9779 * @extends Roo.Component
9780 * Simple color palette class for choosing colors. The palette can be rendered to any container.<br />
9781 * Here's an example of typical usage:
9783 var cp = new Roo.ColorPalette({value:'993300'}); // initial selected color
9784 cp.render('my-div');
9786 cp.on('select', function(palette, selColor){
9787 // do something with selColor
9791 * Create a new ColorPalette
9792 * @param {Object} config The config object
9794 Roo.ColorPalette = function(config){
9795 Roo.ColorPalette.superclass.constructor.call(this, config);
9799 * Fires when a color is selected
9800 * @param {ColorPalette} this
9801 * @param {String} color The 6-digit color hex code (without the # symbol)
9807 this.on("select", this.handler, this.scope, true);
9810 Roo.extend(Roo.ColorPalette, Roo.Component, {
9812 * @cfg {String} itemCls
9813 * The CSS class to apply to the containing element (defaults to "x-color-palette")
9815 itemCls : "x-color-palette",
9817 * @cfg {String} value
9818 * The initial color to highlight (should be a valid 6-digit color hex code without the # symbol). Note that
9819 * the hex codes are case-sensitive.
9824 ctype: "Roo.ColorPalette",
9827 * @cfg {Boolean} allowReselect If set to true then reselecting a color that is already selected fires the selection event
9829 allowReselect : false,
9832 * <p>An array of 6-digit color hex code strings (without the # symbol). This array can contain any number
9833 * of colors, and each hex code should be unique. The width of the palette is controlled via CSS by adjusting
9834 * the width property of the 'x-color-palette' class (or assigning a custom class), so you can balance the number
9835 * of colors with the width setting until the box is symmetrical.</p>
9836 * <p>You can override individual colors if needed:</p>
9838 var cp = new Roo.ColorPalette();
9839 cp.colors[0] = "FF0000"; // change the first box to red
9842 Or you can provide a custom array of your own for complete control:
9844 var cp = new Roo.ColorPalette();
9845 cp.colors = ["000000", "993300", "333300"];
9850 "000000", "993300", "333300", "003300", "003366", "000080", "333399", "333333",
9851 "800000", "FF6600", "808000", "008000", "008080", "0000FF", "666699", "808080",
9852 "FF0000", "FF9900", "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696",
9853 "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF", "993366", "C0C0C0",
9854 "FF99CC", "FFCC99", "FFFF99", "CCFFCC", "CCFFFF", "99CCFF", "CC99FF", "FFFFFF"
9858 onRender : function(container, position){
9859 var t = new Roo.MasterTemplate(
9860 '<tpl><a href="#" class="color-{0}" hidefocus="on"><em><span style="background:#{0}" unselectable="on"> </span></em></a></tpl>'
9862 var c = this.colors;
9863 for(var i = 0, len = c.length; i < len; i++){
9866 var el = document.createElement("div");
9867 el.className = this.itemCls;
9869 container.dom.insertBefore(el, position);
9870 this.el = Roo.get(el);
9871 this.el.on(this.clickEvent, this.handleClick, this, {delegate: "a"});
9872 if(this.clickEvent != 'click'){
9873 this.el.on('click', Roo.emptyFn, this, {delegate: "a", preventDefault:true});
9878 afterRender : function(){
9879 Roo.ColorPalette.superclass.afterRender.call(this);
9888 handleClick : function(e, t){
9891 var c = t.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
9892 this.select(c.toUpperCase());
9897 * Selects the specified color in the palette (fires the select event)
9898 * @param {String} color A valid 6-digit color hex code (# will be stripped if included)
9900 select : function(color){
9901 color = color.replace("#", "");
9902 if(color != this.value || this.allowReselect){
9905 el.child("a.color-"+this.value).removeClass("x-color-palette-sel");
9907 el.child("a.color-"+color).addClass("x-color-palette-sel");
9909 this.fireEvent("select", this, color);
9914 * Ext JS Library 1.1.1
9915 * Copyright(c) 2006-2007, Ext JS, LLC.
9917 * Originally Released Under LGPL - original licence link has changed is not relivant.
9920 * <script type="text/javascript">
9924 * @class Roo.DatePicker
9925 * @extends Roo.Component
9926 * Simple date picker class.
9928 * Create a new DatePicker
9929 * @param {Object} config The config object
9931 Roo.DatePicker = function(config){
9932 Roo.DatePicker.superclass.constructor.call(this, config);
9934 this.value = config && config.value ?
9935 config.value.clearTime() : new Date().clearTime();
9940 * Fires when a date is selected
9941 * @param {DatePicker} this
9942 * @param {Date} date The selected date
9948 this.on("select", this.handler, this.scope || this);
9950 // build the disabledDatesRE
9951 if(!this.disabledDatesRE && this.disabledDates){
9952 var dd = this.disabledDates;
9954 for(var i = 0; i < dd.length; i++){
9956 if(i != dd.length-1) re += "|";
9958 this.disabledDatesRE = new RegExp(re + ")");
9962 Roo.extend(Roo.DatePicker, Roo.Component, {
9964 * @cfg {String} todayText
9965 * The text to display on the button that selects the current date (defaults to "Today")
9967 todayText : "Today",
9969 * @cfg {String} okText
9970 * The text to display on the ok button
9972 okText : " OK ", //   to give the user extra clicking room
9974 * @cfg {String} cancelText
9975 * The text to display on the cancel button
9977 cancelText : "Cancel",
9979 * @cfg {String} todayTip
9980 * The tooltip to display for the button that selects the current date (defaults to "{current date} (Spacebar)")
9982 todayTip : "{0} (Spacebar)",
9984 * @cfg {Date} minDate
9985 * Minimum allowable date (JavaScript date object, defaults to null)
9989 * @cfg {Date} maxDate
9990 * Maximum allowable date (JavaScript date object, defaults to null)
9994 * @cfg {String} minText
9995 * The error text to display if the minDate validation fails (defaults to "This date is before the minimum date")
9997 minText : "This date is before the minimum date",
9999 * @cfg {String} maxText
10000 * The error text to display if the maxDate validation fails (defaults to "This date is after the maximum date")
10002 maxText : "This date is after the maximum date",
10004 * @cfg {String} format
10005 * The default date format string which can be overriden for localization support. The format must be
10006 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
10010 * @cfg {Array} disabledDays
10011 * An array of days to disable, 0-based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
10013 disabledDays : null,
10015 * @cfg {String} disabledDaysText
10016 * The tooltip to display when the date falls on a disabled day (defaults to "")
10018 disabledDaysText : "",
10020 * @cfg {RegExp} disabledDatesRE
10021 * JavaScript regular expression used to disable a pattern of dates (defaults to null)
10023 disabledDatesRE : null,
10025 * @cfg {String} disabledDatesText
10026 * The tooltip text to display when the date falls on a disabled date (defaults to "")
10028 disabledDatesText : "",
10030 * @cfg {Boolean} constrainToViewport
10031 * True to constrain the date picker to the viewport (defaults to true)
10033 constrainToViewport : true,
10035 * @cfg {Array} monthNames
10036 * An array of textual month names which can be overriden for localization support (defaults to Date.monthNames)
10038 monthNames : Date.monthNames,
10040 * @cfg {Array} dayNames
10041 * An array of textual day names which can be overriden for localization support (defaults to Date.dayNames)
10043 dayNames : Date.dayNames,
10045 * @cfg {String} nextText
10046 * The next month navigation button tooltip (defaults to 'Next Month (Control+Right)')
10048 nextText: 'Next Month (Control+Right)',
10050 * @cfg {String} prevText
10051 * The previous month navigation button tooltip (defaults to 'Previous Month (Control+Left)')
10053 prevText: 'Previous Month (Control+Left)',
10055 * @cfg {String} monthYearText
10056 * The header month selector tooltip (defaults to 'Choose a month (Control+Up/Down to move years)')
10058 monthYearText: 'Choose a month (Control+Up/Down to move years)',
10060 * @cfg {Number} startDay
10061 * Day index at which the week should begin, 0-based (defaults to 0, which is Sunday)
10065 * @cfg {Bool} showClear
10066 * Show a clear button (usefull for date form elements that can be blank.)
10072 * Sets the value of the date field
10073 * @param {Date} value The date to set
10075 setValue : function(value){
10076 var old = this.value;
10077 this.value = value.clearTime(true);
10079 this.update(this.value);
10084 * Gets the current selected value of the date field
10085 * @return {Date} The selected date
10087 getValue : function(){
10092 focus : function(){
10094 this.update(this.activeDate);
10099 onRender : function(container, position){
10101 '<table cellspacing="0">',
10102 '<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>',
10103 '<tr><td colspan="3"><table class="x-date-inner" cellspacing="0"><thead><tr>'];
10104 var dn = this.dayNames;
10105 for(var i = 0; i < 7; i++){
10106 var d = this.startDay+i;
10110 m.push("<th><span>", dn[d].substr(0,1), "</span></th>");
10112 m[m.length] = "</tr></thead><tbody><tr>";
10113 for(var i = 0; i < 42; i++) {
10114 if(i % 7 == 0 && i != 0){
10115 m[m.length] = "</tr><tr>";
10117 m[m.length] = '<td><a href="#" hidefocus="on" class="x-date-date" tabIndex="1"><em><span></span></em></a></td>';
10119 m[m.length] = '</tr></tbody></table></td></tr><tr>'+
10120 '<td colspan="3" class="x-date-bottom" align="center"></td></tr></table><div class="x-date-mp"></div>';
10122 var el = document.createElement("div");
10123 el.className = "x-date-picker";
10124 el.innerHTML = m.join("");
10126 container.dom.insertBefore(el, position);
10128 this.el = Roo.get(el);
10129 this.eventEl = Roo.get(el.firstChild);
10131 new Roo.util.ClickRepeater(this.el.child("td.x-date-left a"), {
10132 handler: this.showPrevMonth,
10134 preventDefault:true,
10138 new Roo.util.ClickRepeater(this.el.child("td.x-date-right a"), {
10139 handler: this.showNextMonth,
10141 preventDefault:true,
10145 this.eventEl.on("mousewheel", this.handleMouseWheel, this);
10147 this.monthPicker = this.el.down('div.x-date-mp');
10148 this.monthPicker.enableDisplayMode('block');
10150 var kn = new Roo.KeyNav(this.eventEl, {
10151 "left" : function(e){
10153 this.showPrevMonth() :
10154 this.update(this.activeDate.add("d", -1));
10157 "right" : function(e){
10159 this.showNextMonth() :
10160 this.update(this.activeDate.add("d", 1));
10163 "up" : function(e){
10165 this.showNextYear() :
10166 this.update(this.activeDate.add("d", -7));
10169 "down" : function(e){
10171 this.showPrevYear() :
10172 this.update(this.activeDate.add("d", 7));
10175 "pageUp" : function(e){
10176 this.showNextMonth();
10179 "pageDown" : function(e){
10180 this.showPrevMonth();
10183 "enter" : function(e){
10184 e.stopPropagation();
10191 this.eventEl.on("click", this.handleDateClick, this, {delegate: "a.x-date-date"});
10193 this.eventEl.addKeyListener(Roo.EventObject.SPACE, this.selectToday, this);
10195 this.el.unselectable();
10197 this.cells = this.el.select("table.x-date-inner tbody td");
10198 this.textNodes = this.el.query("table.x-date-inner tbody span");
10200 this.mbtn = new Roo.Button(this.el.child("td.x-date-middle", true), {
10202 tooltip: this.monthYearText
10205 this.mbtn.on('click', this.showMonthPicker, this);
10206 this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu");
10209 var today = (new Date()).dateFormat(this.format);
10211 var baseTb = new Roo.Toolbar(this.el.child("td.x-date-bottom", true));
10213 text: String.format(this.todayText, today),
10214 tooltip: String.format(this.todayTip, today),
10215 handler: this.selectToday,
10219 //var todayBtn = new Roo.Button(this.el.child("td.x-date-bottom", true), {
10222 if (this.showClear) {
10224 baseTb.add( new Roo.Toolbar.Fill());
10227 cls: 'x-btn-icon x-btn-clear',
10228 handler: function() {
10230 this.fireEvent("select", this, '');
10240 this.update(this.value);
10243 createMonthPicker : function(){
10244 if(!this.monthPicker.dom.firstChild){
10245 var buf = ['<table border="0" cellspacing="0">'];
10246 for(var i = 0; i < 6; i++){
10248 '<tr><td class="x-date-mp-month"><a href="#">', this.monthNames[i].substr(0, 3), '</a></td>',
10249 '<td class="x-date-mp-month x-date-mp-sep"><a href="#">', this.monthNames[i+6].substr(0, 3), '</a></td>',
10251 '<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>' :
10252 '<td class="x-date-mp-year"><a href="#"></a></td><td class="x-date-mp-year"><a href="#"></a></td></tr>'
10256 '<tr class="x-date-mp-btns"><td colspan="4"><button type="button" class="x-date-mp-ok">',
10258 '</button><button type="button" class="x-date-mp-cancel">',
10260 '</button></td></tr>',
10263 this.monthPicker.update(buf.join(''));
10264 this.monthPicker.on('click', this.onMonthClick, this);
10265 this.monthPicker.on('dblclick', this.onMonthDblClick, this);
10267 this.mpMonths = this.monthPicker.select('td.x-date-mp-month');
10268 this.mpYears = this.monthPicker.select('td.x-date-mp-year');
10270 this.mpMonths.each(function(m, a, i){
10273 m.dom.xmonth = 5 + Math.round(i * .5);
10275 m.dom.xmonth = Math.round((i-1) * .5);
10281 showMonthPicker : function(){
10282 this.createMonthPicker();
10283 var size = this.el.getSize();
10284 this.monthPicker.setSize(size);
10285 this.monthPicker.child('table').setSize(size);
10287 this.mpSelMonth = (this.activeDate || this.value).getMonth();
10288 this.updateMPMonth(this.mpSelMonth);
10289 this.mpSelYear = (this.activeDate || this.value).getFullYear();
10290 this.updateMPYear(this.mpSelYear);
10292 this.monthPicker.slideIn('t', {duration:.2});
10295 updateMPYear : function(y){
10297 var ys = this.mpYears.elements;
10298 for(var i = 1; i <= 10; i++){
10299 var td = ys[i-1], y2;
10301 y2 = y + Math.round(i * .5);
10302 td.firstChild.innerHTML = y2;
10305 y2 = y - (5-Math.round(i * .5));
10306 td.firstChild.innerHTML = y2;
10309 this.mpYears.item(i-1)[y2 == this.mpSelYear ? 'addClass' : 'removeClass']('x-date-mp-sel');
10313 updateMPMonth : function(sm){
10314 this.mpMonths.each(function(m, a, i){
10315 m[m.dom.xmonth == sm ? 'addClass' : 'removeClass']('x-date-mp-sel');
10319 selectMPMonth: function(m){
10323 onMonthClick : function(e, t){
10325 var el = new Roo.Element(t), pn;
10326 if(el.is('button.x-date-mp-cancel')){
10327 this.hideMonthPicker();
10329 else if(el.is('button.x-date-mp-ok')){
10330 this.update(new Date(this.mpSelYear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
10331 this.hideMonthPicker();
10333 else if(pn = el.up('td.x-date-mp-month', 2)){
10334 this.mpMonths.removeClass('x-date-mp-sel');
10335 pn.addClass('x-date-mp-sel');
10336 this.mpSelMonth = pn.dom.xmonth;
10338 else if(pn = el.up('td.x-date-mp-year', 2)){
10339 this.mpYears.removeClass('x-date-mp-sel');
10340 pn.addClass('x-date-mp-sel');
10341 this.mpSelYear = pn.dom.xyear;
10343 else if(el.is('a.x-date-mp-prev')){
10344 this.updateMPYear(this.mpyear-10);
10346 else if(el.is('a.x-date-mp-next')){
10347 this.updateMPYear(this.mpyear+10);
10351 onMonthDblClick : function(e, t){
10353 var el = new Roo.Element(t), pn;
10354 if(pn = el.up('td.x-date-mp-month', 2)){
10355 this.update(new Date(this.mpSelYear, pn.dom.xmonth, (this.activeDate || this.value).getDate()));
10356 this.hideMonthPicker();
10358 else if(pn = el.up('td.x-date-mp-year', 2)){
10359 this.update(new Date(pn.dom.xyear, this.mpSelMonth, (this.activeDate || this.value).getDate()));
10360 this.hideMonthPicker();
10364 hideMonthPicker : function(disableAnim){
10365 if(this.monthPicker){
10366 if(disableAnim === true){
10367 this.monthPicker.hide();
10369 this.monthPicker.slideOut('t', {duration:.2});
10375 showPrevMonth : function(e){
10376 this.update(this.activeDate.add("mo", -1));
10380 showNextMonth : function(e){
10381 this.update(this.activeDate.add("mo", 1));
10385 showPrevYear : function(){
10386 this.update(this.activeDate.add("y", -1));
10390 showNextYear : function(){
10391 this.update(this.activeDate.add("y", 1));
10395 handleMouseWheel : function(e){
10396 var delta = e.getWheelDelta();
10398 this.showPrevMonth();
10400 } else if(delta < 0){
10401 this.showNextMonth();
10407 handleDateClick : function(e, t){
10409 if(t.dateValue && !Roo.fly(t.parentNode).hasClass("x-date-disabled")){
10410 this.setValue(new Date(t.dateValue));
10411 this.fireEvent("select", this, this.value);
10416 selectToday : function(){
10417 this.setValue(new Date().clearTime());
10418 this.fireEvent("select", this, this.value);
10422 update : function(date){
10423 var vd = this.activeDate;
10424 this.activeDate = date;
10426 var t = date.getTime();
10427 if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
10428 this.cells.removeClass("x-date-selected");
10429 this.cells.each(function(c){
10430 if(c.dom.firstChild.dateValue == t){
10431 c.addClass("x-date-selected");
10432 setTimeout(function(){
10433 try{c.dom.firstChild.focus();}catch(e){}
10441 var days = date.getDaysInMonth();
10442 var firstOfMonth = date.getFirstDateOfMonth();
10443 var startingPos = firstOfMonth.getDay()-this.startDay;
10445 if(startingPos <= this.startDay){
10449 var pm = date.add("mo", -1);
10450 var prevStart = pm.getDaysInMonth()-startingPos;
10452 var cells = this.cells.elements;
10453 var textEls = this.textNodes;
10454 days += startingPos;
10456 // convert everything to numbers so it's fast
10457 var day = 86400000;
10458 var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
10459 var today = new Date().clearTime().getTime();
10460 var sel = date.clearTime().getTime();
10461 var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
10462 var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
10463 var ddMatch = this.disabledDatesRE;
10464 var ddText = this.disabledDatesText;
10465 var ddays = this.disabledDays ? this.disabledDays.join("") : false;
10466 var ddaysText = this.disabledDaysText;
10467 var format = this.format;
10469 var setCellClass = function(cal, cell){
10471 var t = d.getTime();
10472 cell.firstChild.dateValue = t;
10474 cell.className += " x-date-today";
10475 cell.title = cal.todayText;
10478 cell.className += " x-date-selected";
10479 setTimeout(function(){
10480 try{cell.firstChild.focus();}catch(e){}
10485 cell.className = " x-date-disabled";
10486 cell.title = cal.minText;
10490 cell.className = " x-date-disabled";
10491 cell.title = cal.maxText;
10495 if(ddays.indexOf(d.getDay()) != -1){
10496 cell.title = ddaysText;
10497 cell.className = " x-date-disabled";
10500 if(ddMatch && format){
10501 var fvalue = d.dateFormat(format);
10502 if(ddMatch.test(fvalue)){
10503 cell.title = ddText.replace("%0", fvalue);
10504 cell.className = " x-date-disabled";
10510 for(; i < startingPos; i++) {
10511 textEls[i].innerHTML = (++prevStart);
10512 d.setDate(d.getDate()+1);
10513 cells[i].className = "x-date-prevday";
10514 setCellClass(this, cells[i]);
10516 for(; i < days; i++){
10517 intDay = i - startingPos + 1;
10518 textEls[i].innerHTML = (intDay);
10519 d.setDate(d.getDate()+1);
10520 cells[i].className = "x-date-active";
10521 setCellClass(this, cells[i]);
10524 for(; i < 42; i++) {
10525 textEls[i].innerHTML = (++extraDays);
10526 d.setDate(d.getDate()+1);
10527 cells[i].className = "x-date-nextday";
10528 setCellClass(this, cells[i]);
10531 this.mbtn.setText(this.monthNames[date.getMonth()] + " " + date.getFullYear());
10533 if(!this.internalRender){
10534 var main = this.el.dom.firstChild;
10535 var w = main.offsetWidth;
10536 this.el.setWidth(w + this.el.getBorderWidth("lr"));
10537 Roo.fly(main).setWidth(w);
10538 this.internalRender = true;
10539 // opera does not respect the auto grow header center column
10540 // then, after it gets a width opera refuses to recalculate
10541 // without a second pass
10542 if(Roo.isOpera && !this.secondPass){
10543 main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
10544 this.secondPass = true;
10545 this.update.defer(10, this, [date]);
10551 * Ext JS Library 1.1.1
10552 * Copyright(c) 2006-2007, Ext JS, LLC.
10554 * Originally Released Under LGPL - original licence link has changed is not relivant.
10557 * <script type="text/javascript">
10560 * @class Roo.TabPanel
10561 * @extends Roo.util.Observable
10562 * A lightweight tab container.
10566 // basic tabs 1, built from existing content
10567 var tabs = new Roo.TabPanel("tabs1");
10568 tabs.addTab("script", "View Script");
10569 tabs.addTab("markup", "View Markup");
10570 tabs.activate("script");
10572 // more advanced tabs, built from javascript
10573 var jtabs = new Roo.TabPanel("jtabs");
10574 jtabs.addTab("jtabs-1", "Normal Tab", "My content was added during construction.");
10576 // set up the UpdateManager
10577 var tab2 = jtabs.addTab("jtabs-2", "Ajax Tab 1");
10578 var updater = tab2.getUpdateManager();
10579 updater.setDefaultUrl("ajax1.htm");
10580 tab2.on('activate', updater.refresh, updater, true);
10582 // Use setUrl for Ajax loading
10583 var tab3 = jtabs.addTab("jtabs-3", "Ajax Tab 2");
10584 tab3.setUrl("ajax2.htm", null, true);
10587 var tab4 = jtabs.addTab("tabs1-5", "Disabled Tab", "Can't see me cause I'm disabled");
10590 jtabs.activate("jtabs-1");
10593 * Create a new TabPanel.
10594 * @param {String/HTMLElement/Roo.Element} container The id, DOM element or Roo.Element container where this TabPanel is to be rendered.
10595 * @param {Object/Boolean} config Config object to set any properties for this TabPanel, or true to render the tabs on the bottom.
10597 Roo.TabPanel = function(container, config){
10599 * The container element for this TabPanel.
10600 * @type Roo.Element
10602 this.el = Roo.get(container, true);
10604 if(typeof config == "boolean"){
10605 this.tabPosition = config ? "bottom" : "top";
10607 Roo.apply(this, config);
10610 if(this.tabPosition == "bottom"){
10611 this.bodyEl = Roo.get(this.createBody(this.el.dom));
10612 this.el.addClass("x-tabs-bottom");
10614 this.stripWrap = Roo.get(this.createStrip(this.el.dom), true);
10615 this.stripEl = Roo.get(this.createStripList(this.stripWrap.dom), true);
10616 this.stripBody = Roo.get(this.stripWrap.dom.firstChild.firstChild, true);
10618 Roo.fly(this.stripWrap.dom.firstChild).setStyle("overflow-x", "hidden");
10620 if(this.tabPosition != "bottom"){
10621 /** The body element that contains {@link Roo.TabPanelItem} bodies.
10622 * @type Roo.Element
10624 this.bodyEl = Roo.get(this.createBody(this.el.dom));
10625 this.el.addClass("x-tabs-top");
10629 this.bodyEl.setStyle("position", "relative");
10631 this.active = null;
10632 this.activateDelegate = this.activate.createDelegate(this);
10637 * Fires when the active tab changes
10638 * @param {Roo.TabPanel} this
10639 * @param {Roo.TabPanelItem} activePanel The new active tab
10643 * @event beforetabchange
10644 * Fires before the active tab changes, set cancel to true on the "e" parameter to cancel the change
10645 * @param {Roo.TabPanel} this
10646 * @param {Object} e Set cancel to true on this object to cancel the tab change
10647 * @param {Roo.TabPanelItem} tab The tab being changed to
10649 "beforetabchange" : true
10652 Roo.EventManager.onWindowResize(this.onResize, this);
10653 this.cpad = this.el.getPadding("lr");
10654 this.hiddenCount = 0;
10656 Roo.TabPanel.superclass.constructor.call(this);
10659 Roo.extend(Roo.TabPanel, Roo.util.Observable, {
10661 *@cfg {String} tabPosition "top" or "bottom" (defaults to "top")
10663 tabPosition : "top",
10665 *@cfg {Number} currentTabWidth The width of the current tab (defaults to 0)
10667 currentTabWidth : 0,
10669 *@cfg {Number} minTabWidth The minimum width of a tab (defaults to 40) (ignored if {@link #resizeTabs} is not true)
10673 *@cfg {Number} maxTabWidth The maximum width of a tab (defaults to 250) (ignored if {@link #resizeTabs} is not true)
10677 *@cfg {Number} preferredTabWidth The preferred (default) width of a tab (defaults to 175) (ignored if {@link #resizeTabs} is not true)
10679 preferredTabWidth : 175,
10681 *@cfg {Boolean} resizeTabs True to enable dynamic tab resizing (defaults to false)
10683 resizeTabs : false,
10685 *@cfg {Boolean} monitorResize Set this to true to turn on window resize monitoring (ignored if {@link #resizeTabs} is not true) (defaults to true)
10687 monitorResize : true,
10690 * Creates a new {@link Roo.TabPanelItem} by looking for an existing element with the provided id -- if it's not found it creates one.
10691 * @param {String} id The id of the div to use <b>or create</b>
10692 * @param {String} text The text for the tab
10693 * @param {String} content (optional) Content to put in the TabPanelItem body
10694 * @param {Boolean} closable (optional) True to create a close icon on the tab
10695 * @return {Roo.TabPanelItem} The created TabPanelItem
10697 addTab : function(id, text, content, closable){
10698 var item = new Roo.TabPanelItem(this, id, text, closable);
10699 this.addTabItem(item);
10701 item.setContent(content);
10707 * Returns the {@link Roo.TabPanelItem} with the specified id/index
10708 * @param {String/Number} id The id or index of the TabPanelItem to fetch.
10709 * @return {Roo.TabPanelItem}
10711 getTab : function(id){
10712 return this.items[id];
10716 * Hides the {@link Roo.TabPanelItem} with the specified id/index
10717 * @param {String/Number} id The id or index of the TabPanelItem to hide.
10719 hideTab : function(id){
10720 var t = this.items[id];
10723 this.hiddenCount++;
10724 this.autoSizeTabs();
10729 * "Unhides" the {@link Roo.TabPanelItem} with the specified id/index.
10730 * @param {String/Number} id The id or index of the TabPanelItem to unhide.
10732 unhideTab : function(id){
10733 var t = this.items[id];
10735 t.setHidden(false);
10736 this.hiddenCount--;
10737 this.autoSizeTabs();
10742 * Adds an existing {@link Roo.TabPanelItem}.
10743 * @param {Roo.TabPanelItem} item The TabPanelItem to add
10745 addTabItem : function(item){
10746 this.items[item.id] = item;
10747 this.items.push(item);
10748 if(this.resizeTabs){
10749 item.setWidth(this.currentTabWidth || this.preferredTabWidth);
10750 this.autoSizeTabs();
10757 * Removes a {@link Roo.TabPanelItem}.
10758 * @param {String/Number} id The id or index of the TabPanelItem to remove.
10760 removeTab : function(id){
10761 var items = this.items;
10762 var tab = items[id];
10764 var index = items.indexOf(tab);
10765 if(this.active == tab && items.length > 1){
10766 var newTab = this.getNextAvailable(index);
10767 if(newTab)newTab.activate();
10769 this.stripEl.dom.removeChild(tab.pnode.dom);
10770 if(tab.bodyEl.dom.parentNode == this.bodyEl.dom){ // if it was moved already prevent error
10771 this.bodyEl.dom.removeChild(tab.bodyEl.dom);
10773 items.splice(index, 1);
10774 delete this.items[tab.id];
10775 tab.fireEvent("close", tab);
10776 tab.purgeListeners();
10777 this.autoSizeTabs();
10780 getNextAvailable : function(start){
10781 var items = this.items;
10783 // look for a next tab that will slide over to
10784 // replace the one being removed
10785 while(index < items.length){
10786 var item = items[++index];
10787 if(item && !item.isHidden()){
10791 // if one isn't found select the previous tab (on the left)
10794 var item = items[--index];
10795 if(item && !item.isHidden()){
10803 * Disables a {@link Roo.TabPanelItem}. It cannot be the active tab, if it is this call is ignored.
10804 * @param {String/Number} id The id or index of the TabPanelItem to disable.
10806 disableTab : function(id){
10807 var tab = this.items[id];
10808 if(tab && this.active != tab){
10814 * Enables a {@link Roo.TabPanelItem} that is disabled.
10815 * @param {String/Number} id The id or index of the TabPanelItem to enable.
10817 enableTab : function(id){
10818 var tab = this.items[id];
10823 * Activates a {@link Roo.TabPanelItem}. The currently active one will be deactivated.
10824 * @param {String/Number} id The id or index of the TabPanelItem to activate.
10825 * @return {Roo.TabPanelItem} The TabPanelItem.
10827 activate : function(id){
10828 var tab = this.items[id];
10832 if(tab == this.active || tab.disabled){
10836 this.fireEvent("beforetabchange", this, e, tab);
10837 if(e.cancel !== true && !tab.disabled){
10839 this.active.hide();
10841 this.active = this.items[id];
10842 this.active.show();
10843 this.fireEvent("tabchange", this, this.active);
10849 * Gets the active {@link Roo.TabPanelItem}.
10850 * @return {Roo.TabPanelItem} The active TabPanelItem or null if none are active.
10852 getActiveTab : function(){
10853 return this.active;
10857 * Updates the tab body element to fit the height of the container element
10858 * for overflow scrolling
10859 * @param {Number} targetHeight (optional) Override the starting height from the elements height
10861 syncHeight : function(targetHeight){
10862 var height = (targetHeight || this.el.getHeight())-this.el.getBorderWidth("tb")-this.el.getPadding("tb");
10863 var bm = this.bodyEl.getMargins();
10864 var newHeight = height-(this.stripWrap.getHeight()||0)-(bm.top+bm.bottom);
10865 this.bodyEl.setHeight(newHeight);
10869 onResize : function(){
10870 if(this.monitorResize){
10871 this.autoSizeTabs();
10876 * Disables tab resizing while tabs are being added (if {@link #resizeTabs} is false this does nothing)
10878 beginUpdate : function(){
10879 this.updating = true;
10883 * Stops an update and resizes the tabs (if {@link #resizeTabs} is false this does nothing)
10885 endUpdate : function(){
10886 this.updating = false;
10887 this.autoSizeTabs();
10891 * Manual call to resize the tabs (if {@link #resizeTabs} is false this does nothing)
10893 autoSizeTabs : function(){
10894 var count = this.items.length;
10895 var vcount = count - this.hiddenCount;
10896 if(!this.resizeTabs || count < 1 || vcount < 1 || this.updating) return;
10897 var w = Math.max(this.el.getWidth() - this.cpad, 10);
10898 var availWidth = Math.floor(w / vcount);
10899 var b = this.stripBody;
10900 if(b.getWidth() > w){
10901 var tabs = this.items;
10902 this.setTabWidth(Math.max(availWidth, this.minTabWidth)-2);
10903 if(availWidth < this.minTabWidth){
10904 /*if(!this.sleft){ // incomplete scrolling code
10905 this.createScrollButtons();
10908 this.stripClip.setWidth(w - (this.sleft.getWidth()+this.sright.getWidth()));*/
10911 if(this.currentTabWidth < this.preferredTabWidth){
10912 this.setTabWidth(Math.min(availWidth, this.preferredTabWidth)-2);
10918 * Returns the number of tabs in this TabPanel.
10921 getCount : function(){
10922 return this.items.length;
10926 * Resizes all the tabs to the passed width
10927 * @param {Number} The new width
10929 setTabWidth : function(width){
10930 this.currentTabWidth = width;
10931 for(var i = 0, len = this.items.length; i < len; i++) {
10932 if(!this.items[i].isHidden())this.items[i].setWidth(width);
10937 * Destroys this TabPanel
10938 * @param {Boolean} removeEl (optional) True to remove the element from the DOM as well (defaults to undefined)
10940 destroy : function(removeEl){
10941 Roo.EventManager.removeResizeListener(this.onResize, this);
10942 for(var i = 0, len = this.items.length; i < len; i++){
10943 this.items[i].purgeListeners();
10945 if(removeEl === true){
10946 this.el.update("");
10953 * @class Roo.TabPanelItem
10954 * @extends Roo.util.Observable
10955 * Represents an individual item (tab plus body) in a TabPanel.
10956 * @param {Roo.TabPanel} tabPanel The {@link Roo.TabPanel} this TabPanelItem belongs to
10957 * @param {String} id The id of this TabPanelItem
10958 * @param {String} text The text for the tab of this TabPanelItem
10959 * @param {Boolean} closable True to allow this TabPanelItem to be closable (defaults to false)
10961 Roo.TabPanelItem = function(tabPanel, id, text, closable){
10963 * The {@link Roo.TabPanel} this TabPanelItem belongs to
10964 * @type Roo.TabPanel
10966 this.tabPanel = tabPanel;
10968 * The id for this TabPanelItem
10973 this.disabled = false;
10977 this.loaded = false;
10978 this.closable = closable;
10981 * The body element for this TabPanelItem.
10982 * @type Roo.Element
10984 this.bodyEl = Roo.get(tabPanel.createItemBody(tabPanel.bodyEl.dom, id));
10985 this.bodyEl.setVisibilityMode(Roo.Element.VISIBILITY);
10986 this.bodyEl.setStyle("display", "block");
10987 this.bodyEl.setStyle("zoom", "1");
10990 var els = tabPanel.createStripElements(tabPanel.stripEl.dom, text, closable);
10992 this.el = Roo.get(els.el, true);
10993 this.inner = Roo.get(els.inner, true);
10994 this.textEl = Roo.get(this.el.dom.firstChild.firstChild.firstChild, true);
10995 this.pnode = Roo.get(els.el.parentNode, true);
10996 this.el.on("mousedown", this.onTabMouseDown, this);
10997 this.el.on("click", this.onTabClick, this);
11000 var c = Roo.get(els.close, true);
11001 c.dom.title = this.closeText;
11002 c.addClassOnOver("close-over");
11003 c.on("click", this.closeClick, this);
11009 * Fires when this tab becomes the active tab.
11010 * @param {Roo.TabPanel} tabPanel The parent TabPanel
11011 * @param {Roo.TabPanelItem} this
11015 * @event beforeclose
11016 * Fires before this tab is closed. To cancel the close, set cancel to true on e (e.cancel = true).
11017 * @param {Roo.TabPanelItem} this
11018 * @param {Object} e Set cancel to true on this object to cancel the close.
11020 "beforeclose": true,
11023 * Fires when this tab is closed.
11024 * @param {Roo.TabPanelItem} this
11028 * @event deactivate
11029 * Fires when this tab is no longer the active tab.
11030 * @param {Roo.TabPanel} tabPanel The parent TabPanel
11031 * @param {Roo.TabPanelItem} this
11033 "deactivate" : true
11035 this.hidden = false;
11037 Roo.TabPanelItem.superclass.constructor.call(this);
11040 Roo.extend(Roo.TabPanelItem, Roo.util.Observable, {
11041 purgeListeners : function(){
11042 Roo.util.Observable.prototype.purgeListeners.call(this);
11043 this.el.removeAllListeners();
11046 * Shows this TabPanelItem -- this <b>does not</b> deactivate the currently active TabPanelItem.
11049 this.pnode.addClass("on");
11052 this.tabPanel.stripWrap.repaint();
11054 this.fireEvent("activate", this.tabPanel, this);
11058 * Returns true if this tab is the active tab.
11059 * @return {Boolean}
11061 isActive : function(){
11062 return this.tabPanel.getActiveTab() == this;
11066 * Hides this TabPanelItem -- if you don't activate another TabPanelItem this could look odd.
11069 this.pnode.removeClass("on");
11071 this.fireEvent("deactivate", this.tabPanel, this);
11074 hideAction : function(){
11075 this.bodyEl.hide();
11076 this.bodyEl.setStyle("position", "absolute");
11077 this.bodyEl.setLeft("-20000px");
11078 this.bodyEl.setTop("-20000px");
11081 showAction : function(){
11082 this.bodyEl.setStyle("position", "relative");
11083 this.bodyEl.setTop("");
11084 this.bodyEl.setLeft("");
11085 this.bodyEl.show();
11089 * Set the tooltip for the tab.
11090 * @param {String} tooltip The tab's tooltip
11092 setTooltip : function(text){
11093 if(Roo.QuickTips && Roo.QuickTips.isEnabled()){
11094 this.textEl.dom.qtip = text;
11095 this.textEl.dom.removeAttribute('title');
11097 this.textEl.dom.title = text;
11101 onTabClick : function(e){
11102 e.preventDefault();
11103 this.tabPanel.activate(this.id);
11106 onTabMouseDown : function(e){
11107 e.preventDefault();
11108 this.tabPanel.activate(this.id);
11111 getWidth : function(){
11112 return this.inner.getWidth();
11115 setWidth : function(width){
11116 var iwidth = width - this.pnode.getPadding("lr");
11117 this.inner.setWidth(iwidth);
11118 this.textEl.setWidth(iwidth-this.inner.getPadding("lr"));
11119 this.pnode.setWidth(width);
11123 * Show or hide the tab
11124 * @param {Boolean} hidden True to hide or false to show.
11126 setHidden : function(hidden){
11127 this.hidden = hidden;
11128 this.pnode.setStyle("display", hidden ? "none" : "");
11132 * Returns true if this tab is "hidden"
11133 * @return {Boolean}
11135 isHidden : function(){
11136 return this.hidden;
11140 * Returns the text for this tab
11143 getText : function(){
11147 autoSize : function(){
11148 //this.el.beginMeasure();
11149 this.textEl.setWidth(1);
11150 this.setWidth(this.textEl.dom.scrollWidth+this.pnode.getPadding("lr")+this.inner.getPadding("lr"));
11151 //this.el.endMeasure();
11155 * Sets the text for the tab (Note: this also sets the tooltip text)
11156 * @param {String} text The tab's text and tooltip
11158 setText : function(text){
11160 this.textEl.update(text);
11161 this.setTooltip(text);
11162 if(!this.tabPanel.resizeTabs){
11167 * Activates this TabPanelItem -- this <b>does</b> deactivate the currently active TabPanelItem.
11169 activate : function(){
11170 this.tabPanel.activate(this.id);
11174 * Disables this TabPanelItem -- this does nothing if this is the active TabPanelItem.
11176 disable : function(){
11177 if(this.tabPanel.active != this){
11178 this.disabled = true;
11179 this.pnode.addClass("disabled");
11184 * Enables this TabPanelItem if it was previously disabled.
11186 enable : function(){
11187 this.disabled = false;
11188 this.pnode.removeClass("disabled");
11192 * Sets the content for this TabPanelItem.
11193 * @param {String} content The content
11194 * @param {Boolean} loadScripts true to look for and load scripts
11196 setContent : function(content, loadScripts){
11197 this.bodyEl.update(content, loadScripts);
11201 * Gets the {@link Roo.UpdateManager} for the body of this TabPanelItem. Enables you to perform Ajax updates.
11202 * @return {Roo.UpdateManager} The UpdateManager
11204 getUpdateManager : function(){
11205 return this.bodyEl.getUpdateManager();
11209 * Set a URL to be used to load the content for this TabPanelItem.
11210 * @param {String/Function} url The URL to load the content from, or a function to call to get the URL
11211 * @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)
11212 * @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)
11213 * @return {Roo.UpdateManager} The UpdateManager
11215 setUrl : function(url, params, loadOnce){
11216 if(this.refreshDelegate){
11217 this.un('activate', this.refreshDelegate);
11219 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
11220 this.on("activate", this.refreshDelegate);
11221 return this.bodyEl.getUpdateManager();
11225 _handleRefresh : function(url, params, loadOnce){
11226 if(!loadOnce || !this.loaded){
11227 var updater = this.bodyEl.getUpdateManager();
11228 updater.update(url, params, this._setLoaded.createDelegate(this));
11233 * Forces a content refresh from the URL specified in the {@link #setUrl} method.
11234 * Will fail silently if the setUrl method has not been called.
11235 * This does not activate the panel, just updates its content.
11237 refresh : function(){
11238 if(this.refreshDelegate){
11239 this.loaded = false;
11240 this.refreshDelegate();
11245 _setLoaded : function(){
11246 this.loaded = true;
11250 closeClick : function(e){
11253 this.fireEvent("beforeclose", this, o);
11254 if(o.cancel !== true){
11255 this.tabPanel.removeTab(this.id);
11259 * The text displayed in the tooltip for the close icon.
11262 closeText : "Close this tab"
11266 Roo.TabPanel.prototype.createStrip = function(container){
11267 var strip = document.createElement("div");
11268 strip.className = "x-tabs-wrap";
11269 container.appendChild(strip);
11273 Roo.TabPanel.prototype.createStripList = function(strip){
11274 // div wrapper for retard IE
11275 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>';
11276 return strip.firstChild.firstChild.firstChild.firstChild;
11279 Roo.TabPanel.prototype.createBody = function(container){
11280 var body = document.createElement("div");
11281 Roo.id(body, "tab-body");
11282 Roo.fly(body).addClass("x-tabs-body");
11283 container.appendChild(body);
11287 Roo.TabPanel.prototype.createItemBody = function(bodyEl, id){
11288 var body = Roo.getDom(id);
11290 body = document.createElement("div");
11293 Roo.fly(body).addClass("x-tabs-item-body");
11294 bodyEl.insertBefore(body, bodyEl.firstChild);
11298 Roo.TabPanel.prototype.createStripElements = function(stripEl, text, closable){
11299 var td = document.createElement("td");
11300 stripEl.appendChild(td);
11302 td.className = "x-tabs-closable";
11303 if(!this.closeTpl){
11304 this.closeTpl = new Roo.Template(
11305 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
11306 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span>' +
11307 '<div unselectable="on" class="close-icon"> </div></em></span></a>'
11310 var el = this.closeTpl.overwrite(td, {"text": text});
11311 var close = el.getElementsByTagName("div")[0];
11312 var inner = el.getElementsByTagName("em")[0];
11313 return {"el": el, "close": close, "inner": inner};
11316 this.tabTpl = new Roo.Template(
11317 '<a href="#" class="x-tabs-right"><span class="x-tabs-left"><em class="x-tabs-inner">' +
11318 '<span unselectable="on"' + (this.disableTooltips ? '' : ' title="{text}"') +' class="x-tabs-text">{text}</span></em></span></a>'
11321 var el = this.tabTpl.overwrite(td, {"text": text});
11322 var inner = el.getElementsByTagName("em")[0];
11323 return {"el": el, "inner": inner};
11327 * Ext JS Library 1.1.1
11328 * Copyright(c) 2006-2007, Ext JS, LLC.
11330 * Originally Released Under LGPL - original licence link has changed is not relivant.
11333 * <script type="text/javascript">
11337 * @class Roo.Button
11338 * @extends Roo.util.Observable
11339 * Simple Button class
11340 * @cfg {String} text The button text
11341 * @cfg {String} icon The path to an image to display in the button (the image will be set as the background-image
11342 * CSS property of the button by default, so if you want a mixed icon/text button, set cls:"x-btn-text-icon")
11343 * @cfg {Function} handler A function called when the button is clicked (can be used instead of click event)
11344 * @cfg {Object} scope The scope of the handler
11345 * @cfg {Number} minWidth The minimum width for this button (used to give a set of buttons a common width)
11346 * @cfg {String/Object} tooltip The tooltip for the button - can be a string or QuickTips config object
11347 * @cfg {Boolean} hidden True to start hidden (defaults to false)
11348 * @cfg {Boolean} disabled True to start disabled (defaults to false)
11349 * @cfg {Boolean} pressed True to start pressed (only if enableToggle = true)
11350 * @cfg {String} toggleGroup The group this toggle button is a member of (only 1 per group can be pressed, only
11351 applies if enableToggle = true)
11352 * @cfg {String/HTMLElement/Element} renderTo The element to append the button to
11353 * @cfg {Boolean/Object} repeat True to repeat fire the click event while the mouse is down. This can also be
11354 an {@link Roo.util.ClickRepeater} config object (defaults to false).
11356 * Create a new button
11357 * @param {Object} config The config object
11359 Roo.Button = function(renderTo, config)
11363 renderTo = config.renderTo || false;
11366 Roo.apply(this, config);
11370 * Fires when this button is clicked
11371 * @param {Button} this
11372 * @param {EventObject} e The click event
11377 * Fires when the "pressed" state of this button changes (only if enableToggle = true)
11378 * @param {Button} this
11379 * @param {Boolean} pressed
11384 * Fires when the mouse hovers over the button
11385 * @param {Button} this
11386 * @param {Event} e The event object
11388 'mouseover' : true,
11391 * Fires when the mouse exits the button
11392 * @param {Button} this
11393 * @param {Event} e The event object
11398 * Fires when the button is rendered
11399 * @param {Button} this
11404 this.menu = Roo.menu.MenuMgr.get(this.menu);
11407 this.render(renderTo);
11410 Roo.util.Observable.call(this);
11413 Roo.extend(Roo.Button, Roo.util.Observable, {
11419 * Read-only. True if this button is hidden
11424 * Read-only. True if this button is disabled
11429 * Read-only. True if this button is pressed (only if enableToggle = true)
11435 * @cfg {Number} tabIndex
11436 * The DOM tabIndex for this button (defaults to undefined)
11438 tabIndex : undefined,
11441 * @cfg {Boolean} enableToggle
11442 * True to enable pressed/not pressed toggling (defaults to false)
11444 enableToggle: false,
11446 * @cfg {Mixed} menu
11447 * Standard menu attribute consisting of a reference to a menu object, a menu id or a menu config blob (defaults to undefined).
11451 * @cfg {String} menuAlign
11452 * The position to align the menu to (see {@link Roo.Element#alignTo} for more details, defaults to 'tl-bl?').
11454 menuAlign : "tl-bl?",
11457 * @cfg {String} iconCls
11458 * A css class which sets a background image to be used as the icon for this button (defaults to undefined).
11460 iconCls : undefined,
11462 * @cfg {String} type
11463 * The button's type, corresponding to the DOM input element type attribute. Either "submit," "reset" or "button" (default).
11468 menuClassTarget: 'tr',
11471 * @cfg {String} clickEvent
11472 * The type of event to map to the button's event handler (defaults to 'click')
11474 clickEvent : 'click',
11477 * @cfg {Boolean} handleMouseEvents
11478 * False to disable visual cues on mouseover, mouseout and mousedown (defaults to true)
11480 handleMouseEvents : true,
11483 * @cfg {String} tooltipType
11484 * The type of tooltip to use. Either "qtip" (default) for QuickTips or "title" for title attribute.
11486 tooltipType : 'qtip',
11489 * @cfg {String} cls
11490 * A CSS class to apply to the button's main element.
11494 * @cfg {Roo.Template} template (Optional)
11495 * An {@link Roo.Template} with which to create the Button's main element. This Template must
11496 * contain numeric substitution parameter 0 if it is to display the tRoo property. Changing the template could
11497 * require code modifications if required elements (e.g. a button) aren't present.
11501 render : function(renderTo){
11503 if(this.hideParent){
11504 this.parentEl = Roo.get(renderTo);
11506 if(!this.dhconfig){
11507 if(!this.template){
11508 if(!Roo.Button.buttonTemplate){
11509 // hideous table template
11510 Roo.Button.buttonTemplate = new Roo.Template(
11511 '<table border="0" cellpadding="0" cellspacing="0" class="x-btn-wrap"><tbody><tr>',
11512 '<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>',
11513 "</tr></tbody></table>");
11515 this.template = Roo.Button.buttonTemplate;
11517 btn = this.template.append(renderTo, [this.text || ' ', this.type], true);
11518 var btnEl = btn.child("button:first");
11519 btnEl.on('focus', this.onFocus, this);
11520 btnEl.on('blur', this.onBlur, this);
11522 btn.addClass(this.cls);
11525 btnEl.setStyle('background-image', 'url(' +this.icon +')');
11528 btnEl.addClass(this.iconCls);
11530 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
11533 if(this.tabIndex !== undefined){
11534 btnEl.dom.tabIndex = this.tabIndex;
11537 if(typeof this.tooltip == 'object'){
11538 Roo.QuickTips.tips(Roo.apply({
11542 btnEl.dom[this.tooltipType] = this.tooltip;
11546 btn = Roo.DomHelper.append(Roo.get(renderTo).dom, this.dhconfig, true);
11550 this.el.dom.id = this.el.id = this.id;
11553 this.el.child(this.menuClassTarget).addClass("x-btn-with-menu");
11554 this.menu.on("show", this.onMenuShow, this);
11555 this.menu.on("hide", this.onMenuHide, this);
11557 btn.addClass("x-btn");
11558 if(Roo.isIE && !Roo.isIE7){
11559 this.autoWidth.defer(1, this);
11563 if(this.handleMouseEvents){
11564 btn.on("mouseover", this.onMouseOver, this);
11565 btn.on("mouseout", this.onMouseOut, this);
11566 btn.on("mousedown", this.onMouseDown, this);
11568 btn.on(this.clickEvent, this.onClick, this);
11569 //btn.on("mouseup", this.onMouseUp, this);
11576 Roo.ButtonToggleMgr.register(this);
11578 this.el.addClass("x-btn-pressed");
11581 var repeater = new Roo.util.ClickRepeater(btn,
11582 typeof this.repeat == "object" ? this.repeat : {}
11584 repeater.on("click", this.onClick, this);
11586 this.fireEvent('render', this);
11590 * Returns the button's underlying element
11591 * @return {Roo.Element} The element
11593 getEl : function(){
11598 * Destroys this Button and removes any listeners.
11600 destroy : function(){
11601 Roo.ButtonToggleMgr.unregister(this);
11602 this.el.removeAllListeners();
11603 this.purgeListeners();
11608 autoWidth : function(){
11610 this.el.setWidth("auto");
11611 if(Roo.isIE7 && Roo.isStrict){
11612 var ib = this.el.child('button');
11613 if(ib && ib.getWidth() > 20){
11615 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
11620 this.el.beginMeasure();
11622 if(this.el.getWidth() < this.minWidth){
11623 this.el.setWidth(this.minWidth);
11626 this.el.endMeasure();
11633 * Assigns this button's click handler
11634 * @param {Function} handler The function to call when the button is clicked
11635 * @param {Object} scope (optional) Scope for the function passed in
11637 setHandler : function(handler, scope){
11638 this.handler = handler;
11639 this.scope = scope;
11643 * Sets this button's text
11644 * @param {String} text The button text
11646 setText : function(text){
11649 this.el.child("td.x-btn-center button.x-btn-text").update(text);
11655 * Gets the text for this button
11656 * @return {String} The button text
11658 getText : function(){
11666 this.hidden = false;
11668 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "");
11676 this.hidden = true;
11678 this[this.hideParent? 'parentEl' : 'el'].setStyle("display", "none");
11683 * Convenience function for boolean show/hide
11684 * @param {Boolean} visible True to show, false to hide
11686 setVisible: function(visible){
11695 * If a state it passed, it becomes the pressed state otherwise the current state is toggled.
11696 * @param {Boolean} state (optional) Force a particular state
11698 toggle : function(state){
11699 state = state === undefined ? !this.pressed : state;
11700 if(state != this.pressed){
11702 this.el.addClass("x-btn-pressed");
11703 this.pressed = true;
11704 this.fireEvent("toggle", this, true);
11706 this.el.removeClass("x-btn-pressed");
11707 this.pressed = false;
11708 this.fireEvent("toggle", this, false);
11710 if(this.toggleHandler){
11711 this.toggleHandler.call(this.scope || this, this, state);
11719 focus : function(){
11720 this.el.child('button:first').focus();
11724 * Disable this button
11726 disable : function(){
11728 this.el.addClass("x-btn-disabled");
11730 this.disabled = true;
11734 * Enable this button
11736 enable : function(){
11738 this.el.removeClass("x-btn-disabled");
11740 this.disabled = false;
11744 * Convenience function for boolean enable/disable
11745 * @param {Boolean} enabled True to enable, false to disable
11747 setDisabled : function(v){
11748 this[v !== true ? "enable" : "disable"]();
11752 onClick : function(e){
11754 e.preventDefault();
11759 if(!this.disabled){
11760 if(this.enableToggle){
11763 if(this.menu && !this.menu.isVisible()){
11764 this.menu.show(this.el, this.menuAlign);
11766 this.fireEvent("click", this, e);
11768 this.el.removeClass("x-btn-over");
11769 this.handler.call(this.scope || this, this, e);
11774 onMouseOver : function(e){
11775 if(!this.disabled){
11776 this.el.addClass("x-btn-over");
11777 this.fireEvent('mouseover', this, e);
11781 onMouseOut : function(e){
11782 if(!e.within(this.el, true)){
11783 this.el.removeClass("x-btn-over");
11784 this.fireEvent('mouseout', this, e);
11788 onFocus : function(e){
11789 if(!this.disabled){
11790 this.el.addClass("x-btn-focus");
11794 onBlur : function(e){
11795 this.el.removeClass("x-btn-focus");
11798 onMouseDown : function(e){
11799 if(!this.disabled && e.button == 0){
11800 this.el.addClass("x-btn-click");
11801 Roo.get(document).on('mouseup', this.onMouseUp, this);
11805 onMouseUp : function(e){
11807 this.el.removeClass("x-btn-click");
11808 Roo.get(document).un('mouseup', this.onMouseUp, this);
11812 onMenuShow : function(e){
11813 this.el.addClass("x-btn-menu-active");
11816 onMenuHide : function(e){
11817 this.el.removeClass("x-btn-menu-active");
11821 // Private utility class used by Button
11822 Roo.ButtonToggleMgr = function(){
11825 function toggleGroup(btn, state){
11827 var g = groups[btn.toggleGroup];
11828 for(var i = 0, l = g.length; i < l; i++){
11830 g[i].toggle(false);
11837 register : function(btn){
11838 if(!btn.toggleGroup){
11841 var g = groups[btn.toggleGroup];
11843 g = groups[btn.toggleGroup] = [];
11846 btn.on("toggle", toggleGroup);
11849 unregister : function(btn){
11850 if(!btn.toggleGroup){
11853 var g = groups[btn.toggleGroup];
11856 btn.un("toggle", toggleGroup);
11862 * Ext JS Library 1.1.1
11863 * Copyright(c) 2006-2007, Ext JS, LLC.
11865 * Originally Released Under LGPL - original licence link has changed is not relivant.
11868 * <script type="text/javascript">
11872 * @class Roo.SplitButton
11873 * @extends Roo.Button
11874 * A split button that provides a built-in dropdown arrow that can fire an event separately from the default
11875 * click event of the button. Typically this would be used to display a dropdown menu that provides additional
11876 * options to the primary button action, but any custom handler can provide the arrowclick implementation.
11877 * @cfg {Function} arrowHandler A function called when the arrow button is clicked (can be used instead of click event)
11878 * @cfg {String} arrowTooltip The title attribute of the arrow
11880 * Create a new menu button
11881 * @param {String/HTMLElement/Element} renderTo The element to append the button to
11882 * @param {Object} config The config object
11884 Roo.SplitButton = function(renderTo, config){
11885 Roo.SplitButton.superclass.constructor.call(this, renderTo, config);
11887 * @event arrowclick
11888 * Fires when this button's arrow is clicked
11889 * @param {SplitButton} this
11890 * @param {EventObject} e The click event
11892 this.addEvents({"arrowclick":true});
11895 Roo.extend(Roo.SplitButton, Roo.Button, {
11896 render : function(renderTo){
11897 // this is one sweet looking template!
11898 var tpl = new Roo.Template(
11899 '<table cellspacing="0" class="x-btn-menu-wrap x-btn"><tr><td>',
11900 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-text-wrap"><tbody>',
11901 '<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>',
11902 "</tbody></table></td><td>",
11903 '<table cellspacing="0" class="x-btn-wrap x-btn-menu-arrow-wrap"><tbody>',
11904 '<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>',
11905 "</tbody></table></td></tr></table>"
11907 var btn = tpl.append(renderTo, [this.text, this.type], true);
11908 var btnEl = btn.child("button");
11910 btn.addClass(this.cls);
11913 btnEl.setStyle('background-image', 'url(' +this.icon +')');
11916 btnEl.addClass(this.iconCls);
11918 btn.addClass(this.text ? 'x-btn-text-icon' : 'x-btn-icon');
11922 if(this.handleMouseEvents){
11923 btn.on("mouseover", this.onMouseOver, this);
11924 btn.on("mouseout", this.onMouseOut, this);
11925 btn.on("mousedown", this.onMouseDown, this);
11926 btn.on("mouseup", this.onMouseUp, this);
11928 btn.on(this.clickEvent, this.onClick, this);
11930 if(typeof this.tooltip == 'object'){
11931 Roo.QuickTips.tips(Roo.apply({
11935 btnEl.dom[this.tooltipType] = this.tooltip;
11938 if(this.arrowTooltip){
11939 btn.child("button:nth(2)").dom[this.tooltipType] = this.arrowTooltip;
11948 this.el.addClass("x-btn-pressed");
11950 if(Roo.isIE && !Roo.isIE7){
11951 this.autoWidth.defer(1, this);
11956 this.menu.on("show", this.onMenuShow, this);
11957 this.menu.on("hide", this.onMenuHide, this);
11959 this.fireEvent('render', this);
11963 autoWidth : function(){
11965 var tbl = this.el.child("table:first");
11966 var tbl2 = this.el.child("table:last");
11967 this.el.setWidth("auto");
11968 tbl.setWidth("auto");
11969 if(Roo.isIE7 && Roo.isStrict){
11970 var ib = this.el.child('button:first');
11971 if(ib && ib.getWidth() > 20){
11973 ib.setWidth(Roo.util.TextMetrics.measure(ib, this.text).width+ib.getFrameWidth('lr'));
11978 this.el.beginMeasure();
11980 if((tbl.getWidth()+tbl2.getWidth()) < this.minWidth){
11981 tbl.setWidth(this.minWidth-tbl2.getWidth());
11984 this.el.endMeasure();
11987 this.el.setWidth(tbl.getWidth()+tbl2.getWidth());
11991 * Sets this button's click handler
11992 * @param {Function} handler The function to call when the button is clicked
11993 * @param {Object} scope (optional) Scope for the function passed above
11995 setHandler : function(handler, scope){
11996 this.handler = handler;
11997 this.scope = scope;
12001 * Sets this button's arrow click handler
12002 * @param {Function} handler The function to call when the arrow is clicked
12003 * @param {Object} scope (optional) Scope for the function passed above
12005 setArrowHandler : function(handler, scope){
12006 this.arrowHandler = handler;
12007 this.scope = scope;
12013 focus : function(){
12015 this.el.child("button:first").focus();
12020 onClick : function(e){
12021 e.preventDefault();
12022 if(!this.disabled){
12023 if(e.getTarget(".x-btn-menu-arrow-wrap")){
12024 if(this.menu && !this.menu.isVisible()){
12025 this.menu.show(this.el, this.menuAlign);
12027 this.fireEvent("arrowclick", this, e);
12028 if(this.arrowHandler){
12029 this.arrowHandler.call(this.scope || this, this, e);
12032 this.fireEvent("click", this, e);
12034 this.handler.call(this.scope || this, this, e);
12040 onMouseDown : function(e){
12041 if(!this.disabled){
12042 Roo.fly(e.getTarget("table")).addClass("x-btn-click");
12046 onMouseUp : function(e){
12047 Roo.fly(e.getTarget("table")).removeClass("x-btn-click");
12052 // backwards compat
12053 Roo.MenuButton = Roo.SplitButton;/*
12055 * Ext JS Library 1.1.1
12056 * Copyright(c) 2006-2007, Ext JS, LLC.
12058 * Originally Released Under LGPL - original licence link has changed is not relivant.
12061 * <script type="text/javascript">
12065 * @class Roo.Toolbar
12066 * Basic Toolbar class.
12068 * Creates a new Toolbar
12069 * @param {Object} config The config object
12071 Roo.Toolbar = function(container, buttons, config)
12073 /// old consturctor format still supported..
12074 if(container instanceof Array){ // omit the container for later rendering
12075 buttons = container;
12079 if (typeof(container) == 'object' && container.xtype) {
12080 config = container;
12081 container = config.container;
12082 buttons = config.buttons; // not really - use items!!
12085 if (config && config.items) {
12086 xitems = config.items;
12087 delete config.items;
12089 Roo.apply(this, config);
12090 this.buttons = buttons;
12093 this.render(container);
12095 Roo.each(xitems, function(b) {
12101 Roo.Toolbar.prototype = {
12103 * @cfg {Roo.data.Store} items
12104 * array of button configs or elements to add
12108 * @cfg {String/HTMLElement/Element} container
12109 * The id or element that will contain the toolbar
12112 render : function(ct){
12113 this.el = Roo.get(ct);
12115 this.el.addClass(this.cls);
12117 // using a table allows for vertical alignment
12118 // 100% width is needed by Safari...
12119 this.el.update('<div class="x-toolbar x-small-editor"><table cellspacing="0"><tr></tr></table></div>');
12120 this.tr = this.el.child("tr", true);
12122 this.items = new Roo.util.MixedCollection(false, function(o){
12123 return o.id || ("item" + (++autoId));
12126 this.add.apply(this, this.buttons);
12127 delete this.buttons;
12132 * Adds element(s) to the toolbar -- this function takes a variable number of
12133 * arguments of mixed type and adds them to the toolbar.
12134 * @param {Mixed} arg1 The following types of arguments are all valid:<br />
12136 * <li>{@link Roo.Toolbar.Button} config: A valid button config object (equivalent to {@link #addButton})</li>
12137 * <li>HtmlElement: Any standard HTML element (equivalent to {@link #addElement})</li>
12138 * <li>Field: Any form field (equivalent to {@link #addField})</li>
12139 * <li>Item: Any subclass of {@link Roo.Toolbar.Item} (equivalent to {@link #addItem})</li>
12140 * <li>String: Any generic string (gets wrapped in a {@link Roo.Toolbar.TextItem}, equivalent to {@link #addText}).
12141 * Note that there are a few special strings that are treated differently as explained nRoo.</li>
12142 * <li>'separator' or '-': Creates a separator element (equivalent to {@link #addSeparator})</li>
12143 * <li>' ': Creates a spacer element (equivalent to {@link #addSpacer})</li>
12144 * <li>'->': Creates a fill element (equivalent to {@link #addFill})</li>
12146 * @param {Mixed} arg2
12147 * @param {Mixed} etc.
12150 var a = arguments, l = a.length;
12151 for(var i = 0; i < l; i++){
12156 _add : function(el) {
12159 el = Roo.factory(el, typeof(Roo.Toolbar[el.xtype]) == 'undefined' ? Roo.form : Roo.Toolbar);
12162 if (el.applyTo){ // some kind of form field
12163 return this.addField(el);
12165 if (el.render){ // some kind of Toolbar.Item
12166 return this.addItem(el);
12168 if (typeof el == "string"){ // string
12169 if(el == "separator" || el == "-"){
12170 return this.addSeparator();
12173 return this.addSpacer();
12176 return this.addFill();
12178 return this.addText(el);
12181 if(el.tagName){ // element
12182 return this.addElement(el);
12184 if(typeof el == "object"){ // must be button config?
12185 return this.addButton(el);
12187 // and now what?!?!
12193 * Add an Xtype element
12194 * @param {Object} xtype Xtype Object
12195 * @return {Object} created Object
12197 addxtype : function(e){
12198 return this.add(e);
12202 * Returns the Element for this toolbar.
12203 * @return {Roo.Element}
12205 getEl : function(){
12211 * @return {Roo.Toolbar.Item} The separator item
12213 addSeparator : function(){
12214 return this.addItem(new Roo.Toolbar.Separator());
12218 * Adds a spacer element
12219 * @return {Roo.Toolbar.Spacer} The spacer item
12221 addSpacer : function(){
12222 return this.addItem(new Roo.Toolbar.Spacer());
12226 * Adds a fill element that forces subsequent additions to the right side of the toolbar
12227 * @return {Roo.Toolbar.Fill} The fill item
12229 addFill : function(){
12230 return this.addItem(new Roo.Toolbar.Fill());
12234 * Adds any standard HTML element to the toolbar
12235 * @param {String/HTMLElement/Element} el The element or id of the element to add
12236 * @return {Roo.Toolbar.Item} The element's item
12238 addElement : function(el){
12239 return this.addItem(new Roo.Toolbar.Item(el));
12242 * Collection of items on the toolbar.. (only Toolbar Items, so use fields to retrieve fields)
12243 * @type Roo.util.MixedCollection
12248 * Adds any Toolbar.Item or subclass
12249 * @param {Roo.Toolbar.Item} item
12250 * @return {Roo.Toolbar.Item} The item
12252 addItem : function(item){
12253 var td = this.nextBlock();
12255 this.items.add(item);
12260 * Adds a button (or buttons). See {@link Roo.Toolbar.Button} for more info on the config.
12261 * @param {Object/Array} config A button config or array of configs
12262 * @return {Roo.Toolbar.Button/Array}
12264 addButton : function(config){
12265 if(config instanceof Array){
12267 for(var i = 0, len = config.length; i < len; i++) {
12268 buttons.push(this.addButton(config[i]));
12273 if(!(config instanceof Roo.Toolbar.Button)){
12275 new Roo.Toolbar.SplitButton(config) :
12276 new Roo.Toolbar.Button(config);
12278 var td = this.nextBlock();
12285 * Adds text to the toolbar
12286 * @param {String} text The text to add
12287 * @return {Roo.Toolbar.Item} The element's item
12289 addText : function(text){
12290 return this.addItem(new Roo.Toolbar.TextItem(text));
12294 * Inserts any {@link Roo.Toolbar.Item}/{@link Roo.Toolbar.Button} at the specified index.
12295 * @param {Number} index The index where the item is to be inserted
12296 * @param {Object/Roo.Toolbar.Item/Roo.Toolbar.Button (may be Array)} item The button, or button config object to be inserted.
12297 * @return {Roo.Toolbar.Button/Item}
12299 insertButton : function(index, item){
12300 if(item instanceof Array){
12302 for(var i = 0, len = item.length; i < len; i++) {
12303 buttons.push(this.insertButton(index + i, item[i]));
12307 if (!(item instanceof Roo.Toolbar.Button)){
12308 item = new Roo.Toolbar.Button(item);
12310 var td = document.createElement("td");
12311 this.tr.insertBefore(td, this.tr.childNodes[index]);
12313 this.items.insert(index, item);
12318 * Adds a new element to the toolbar from the passed {@link Roo.DomHelper} config.
12319 * @param {Object} config
12320 * @return {Roo.Toolbar.Item} The element's item
12322 addDom : function(config, returnEl){
12323 var td = this.nextBlock();
12324 Roo.DomHelper.overwrite(td, config);
12325 var ti = new Roo.Toolbar.Item(td.firstChild);
12327 this.items.add(ti);
12332 * Collection of fields on the toolbar.. usefull for quering (value is false if there are no fields)
12333 * @type Roo.util.MixedCollection
12338 * Adds a dynamically rendered Roo.form field (TextField, ComboBox, etc). Note: the field should not have
12339 * been rendered yet. For a field that has already been rendered, use {@link #addElement}.
12340 * @param {Roo.form.Field} field
12341 * @return {Roo.ToolbarItem}
12345 addField : function(field) {
12346 if (!this.fields) {
12348 this.fields = new Roo.util.MixedCollection(false, function(o){
12349 return o.id || ("item" + (++autoId));
12354 var td = this.nextBlock();
12356 var ti = new Roo.Toolbar.Item(td.firstChild);
12358 this.items.add(ti);
12359 this.fields.add(field);
12370 this.el.child('div').setVisibilityMode(Roo.Element.DISPLAY);
12371 this.el.child('div').hide();
12379 this.el.child('div').show();
12383 nextBlock : function(){
12384 var td = document.createElement("td");
12385 this.tr.appendChild(td);
12390 destroy : function(){
12391 if(this.items){ // rendered?
12392 Roo.destroy.apply(Roo, this.items.items);
12394 if(this.fields){ // rendered?
12395 Roo.destroy.apply(Roo, this.fields.items);
12397 Roo.Element.uncache(this.el, this.tr);
12402 * @class Roo.Toolbar.Item
12403 * The base class that other classes should extend in order to get some basic common toolbar item functionality.
12405 * Creates a new Item
12406 * @param {HTMLElement} el
12408 Roo.Toolbar.Item = function(el){
12409 this.el = Roo.getDom(el);
12410 this.id = Roo.id(this.el);
12411 this.hidden = false;
12414 Roo.Toolbar.Item.prototype = {
12417 * Get this item's HTML Element
12418 * @return {HTMLElement}
12420 getEl : function(){
12425 render : function(td){
12427 td.appendChild(this.el);
12431 * Removes and destroys this item.
12433 destroy : function(){
12434 this.td.parentNode.removeChild(this.td);
12441 this.hidden = false;
12442 this.td.style.display = "";
12449 this.hidden = true;
12450 this.td.style.display = "none";
12454 * Convenience function for boolean show/hide.
12455 * @param {Boolean} visible true to show/false to hide
12457 setVisible: function(visible){
12466 * Try to focus this item.
12468 focus : function(){
12469 Roo.fly(this.el).focus();
12473 * Disables this item.
12475 disable : function(){
12476 Roo.fly(this.td).addClass("x-item-disabled");
12477 this.disabled = true;
12478 this.el.disabled = true;
12482 * Enables this item.
12484 enable : function(){
12485 Roo.fly(this.td).removeClass("x-item-disabled");
12486 this.disabled = false;
12487 this.el.disabled = false;
12493 * @class Roo.Toolbar.Separator
12494 * @extends Roo.Toolbar.Item
12495 * A simple toolbar separator class
12497 * Creates a new Separator
12499 Roo.Toolbar.Separator = function(){
12500 var s = document.createElement("span");
12501 s.className = "ytb-sep";
12502 Roo.Toolbar.Separator.superclass.constructor.call(this, s);
12504 Roo.extend(Roo.Toolbar.Separator, Roo.Toolbar.Item, {
12505 enable:Roo.emptyFn,
12506 disable:Roo.emptyFn,
12511 * @class Roo.Toolbar.Spacer
12512 * @extends Roo.Toolbar.Item
12513 * A simple element that adds extra horizontal space to a toolbar.
12515 * Creates a new Spacer
12517 Roo.Toolbar.Spacer = function(){
12518 var s = document.createElement("div");
12519 s.className = "ytb-spacer";
12520 Roo.Toolbar.Spacer.superclass.constructor.call(this, s);
12522 Roo.extend(Roo.Toolbar.Spacer, Roo.Toolbar.Item, {
12523 enable:Roo.emptyFn,
12524 disable:Roo.emptyFn,
12529 * @class Roo.Toolbar.Fill
12530 * @extends Roo.Toolbar.Spacer
12531 * A simple element that adds a greedy (100% width) horizontal space to a toolbar.
12533 * Creates a new Spacer
12535 Roo.Toolbar.Fill = Roo.extend(Roo.Toolbar.Spacer, {
12537 render : function(td){
12538 td.style.width = '100%';
12539 Roo.Toolbar.Fill.superclass.render.call(this, td);
12544 * @class Roo.Toolbar.TextItem
12545 * @extends Roo.Toolbar.Item
12546 * A simple class that renders text directly into a toolbar.
12548 * Creates a new TextItem
12549 * @param {String} text
12551 Roo.Toolbar.TextItem = function(text){
12552 if (typeof(text) == 'object') {
12555 var s = document.createElement("span");
12556 s.className = "ytb-text";
12557 s.innerHTML = text;
12558 Roo.Toolbar.TextItem.superclass.constructor.call(this, s);
12560 Roo.extend(Roo.Toolbar.TextItem, Roo.Toolbar.Item, {
12561 enable:Roo.emptyFn,
12562 disable:Roo.emptyFn,
12567 * @class Roo.Toolbar.Button
12568 * @extends Roo.Button
12569 * A button that renders into a toolbar.
12571 * Creates a new Button
12572 * @param {Object} config A standard {@link Roo.Button} config object
12574 Roo.Toolbar.Button = function(config){
12575 Roo.Toolbar.Button.superclass.constructor.call(this, null, config);
12577 Roo.extend(Roo.Toolbar.Button, Roo.Button, {
12578 render : function(td){
12580 Roo.Toolbar.Button.superclass.render.call(this, td);
12584 * Removes and destroys this button
12586 destroy : function(){
12587 Roo.Toolbar.Button.superclass.destroy.call(this);
12588 this.td.parentNode.removeChild(this.td);
12592 * Shows this button
12595 this.hidden = false;
12596 this.td.style.display = "";
12600 * Hides this button
12603 this.hidden = true;
12604 this.td.style.display = "none";
12608 * Disables this item
12610 disable : function(){
12611 Roo.fly(this.td).addClass("x-item-disabled");
12612 this.disabled = true;
12616 * Enables this item
12618 enable : function(){
12619 Roo.fly(this.td).removeClass("x-item-disabled");
12620 this.disabled = false;
12623 // backwards compat
12624 Roo.ToolbarButton = Roo.Toolbar.Button;
12627 * @class Roo.Toolbar.SplitButton
12628 * @extends Roo.SplitButton
12629 * A menu button that renders into a toolbar.
12631 * Creates a new SplitButton
12632 * @param {Object} config A standard {@link Roo.SplitButton} config object
12634 Roo.Toolbar.SplitButton = function(config){
12635 Roo.Toolbar.SplitButton.superclass.constructor.call(this, null, config);
12637 Roo.extend(Roo.Toolbar.SplitButton, Roo.SplitButton, {
12638 render : function(td){
12640 Roo.Toolbar.SplitButton.superclass.render.call(this, td);
12644 * Removes and destroys this button
12646 destroy : function(){
12647 Roo.Toolbar.SplitButton.superclass.destroy.call(this);
12648 this.td.parentNode.removeChild(this.td);
12652 * Shows this button
12655 this.hidden = false;
12656 this.td.style.display = "";
12660 * Hides this button
12663 this.hidden = true;
12664 this.td.style.display = "none";
12668 // backwards compat
12669 Roo.Toolbar.MenuButton = Roo.Toolbar.SplitButton;/*
12671 * Ext JS Library 1.1.1
12672 * Copyright(c) 2006-2007, Ext JS, LLC.
12674 * Originally Released Under LGPL - original licence link has changed is not relivant.
12677 * <script type="text/javascript">
12681 * @class Roo.PagingToolbar
12682 * @extends Roo.Toolbar
12683 * A specialized toolbar that is bound to a {@link Roo.data.Store} and provides automatic paging controls.
12685 * Create a new PagingToolbar
12686 * @param {Object} config The config object
12688 Roo.PagingToolbar = function(el, ds, config)
12690 // old args format still supported... - xtype is prefered..
12691 if (typeof(el) == 'object' && el.xtype) {
12692 // created from xtype...
12694 ds = el.dataSource;
12695 el = config.container;
12699 Roo.PagingToolbar.superclass.constructor.call(this, el, null, config);
12702 this.renderButtons(this.el);
12706 Roo.extend(Roo.PagingToolbar, Roo.Toolbar, {
12708 * @cfg {Roo.data.Store} dataSource
12709 * The underlying data store providing the paged data
12712 * @cfg {String/HTMLElement/Element} container
12713 * container The id or element that will contain the toolbar
12716 * @cfg {Boolean} displayInfo
12717 * True to display the displayMsg (defaults to false)
12720 * @cfg {Number} pageSize
12721 * The number of records to display per page (defaults to 20)
12725 * @cfg {String} displayMsg
12726 * The paging status message to display (defaults to "Displaying {start} - {end} of {total}")
12728 displayMsg : 'Displaying {0} - {1} of {2}',
12730 * @cfg {String} emptyMsg
12731 * The message to display when no records are found (defaults to "No data to display")
12733 emptyMsg : 'No data to display',
12735 * Customizable piece of the default paging text (defaults to "Page")
12738 beforePageText : "Page",
12740 * Customizable piece of the default paging text (defaults to "of %0")
12743 afterPageText : "of {0}",
12745 * Customizable piece of the default paging text (defaults to "First Page")
12748 firstText : "First Page",
12750 * Customizable piece of the default paging text (defaults to "Previous Page")
12753 prevText : "Previous Page",
12755 * Customizable piece of the default paging text (defaults to "Next Page")
12758 nextText : "Next Page",
12760 * Customizable piece of the default paging text (defaults to "Last Page")
12763 lastText : "Last Page",
12765 * Customizable piece of the default paging text (defaults to "Refresh")
12768 refreshText : "Refresh",
12771 renderButtons : function(el){
12772 Roo.PagingToolbar.superclass.render.call(this, el);
12773 this.first = this.addButton({
12774 tooltip: this.firstText,
12775 cls: "x-btn-icon x-grid-page-first",
12777 handler: this.onClick.createDelegate(this, ["first"])
12779 this.prev = this.addButton({
12780 tooltip: this.prevText,
12781 cls: "x-btn-icon x-grid-page-prev",
12783 handler: this.onClick.createDelegate(this, ["prev"])
12785 this.addSeparator();
12786 this.add(this.beforePageText);
12787 this.field = Roo.get(this.addDom({
12792 cls: "x-grid-page-number"
12794 this.field.on("keydown", this.onPagingKeydown, this);
12795 this.field.on("focus", function(){this.dom.select();});
12796 this.afterTextEl = this.addText(String.format(this.afterPageText, 1));
12797 this.field.setHeight(18);
12798 this.addSeparator();
12799 this.next = this.addButton({
12800 tooltip: this.nextText,
12801 cls: "x-btn-icon x-grid-page-next",
12803 handler: this.onClick.createDelegate(this, ["next"])
12805 this.last = this.addButton({
12806 tooltip: this.lastText,
12807 cls: "x-btn-icon x-grid-page-last",
12809 handler: this.onClick.createDelegate(this, ["last"])
12811 this.addSeparator();
12812 this.loading = this.addButton({
12813 tooltip: this.refreshText,
12814 cls: "x-btn-icon x-grid-loading",
12815 handler: this.onClick.createDelegate(this, ["refresh"])
12818 if(this.displayInfo){
12819 this.displayEl = Roo.fly(this.el.dom.firstChild).createChild({cls:'x-paging-info'});
12824 updateInfo : function(){
12825 if(this.displayEl){
12826 var count = this.ds.getCount();
12827 var msg = count == 0 ?
12831 this.cursor+1, this.cursor+count, this.ds.getTotalCount()
12833 this.displayEl.update(msg);
12838 onLoad : function(ds, r, o){
12839 this.cursor = o.params ? o.params.start : 0;
12840 var d = this.getPageData(), ap = d.activePage, ps = d.pages;
12842 this.afterTextEl.el.innerHTML = String.format(this.afterPageText, d.pages);
12843 this.field.dom.value = ap;
12844 this.first.setDisabled(ap == 1);
12845 this.prev.setDisabled(ap == 1);
12846 this.next.setDisabled(ap == ps);
12847 this.last.setDisabled(ap == ps);
12848 this.loading.enable();
12853 getPageData : function(){
12854 var total = this.ds.getTotalCount();
12857 activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
12858 pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
12863 onLoadError : function(){
12864 this.loading.enable();
12868 onPagingKeydown : function(e){
12869 var k = e.getKey();
12870 var d = this.getPageData();
12872 var v = this.field.dom.value, pageNum;
12873 if(!v || isNaN(pageNum = parseInt(v, 10))){
12874 this.field.dom.value = d.activePage;
12877 pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
12878 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
12881 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))
12883 var pageNum = (k == e.HOME || (k == e.DOWN && e.ctrlKey) || (k == e.LEFT && e.ctrlKey) || (k == e.PAGEDOWN && e.ctrlKey)) ? 1 : d.pages;
12884 this.field.dom.value = pageNum;
12885 this.ds.load({params:{start: (pageNum - 1) * this.pageSize, limit: this.pageSize}});
12888 else if(k == e.UP || k == e.RIGHT || k == e.PAGEUP || k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
12890 var v = this.field.dom.value, pageNum;
12891 var increment = (e.shiftKey) ? 10 : 1;
12892 if(k == e.DOWN || k == e.LEFT || k == e.PAGEDOWN)
12894 if(!v || isNaN(pageNum = parseInt(v, 10))) {
12895 this.field.dom.value = d.activePage;
12898 else if(parseInt(v, 10) + increment >= 1 & parseInt(v, 10) + increment <= d.pages)
12900 this.field.dom.value = parseInt(v, 10) + increment;
12901 pageNum = Math.min(Math.max(1, pageNum + increment), d.pages) - 1;
12902 this.ds.load({params:{start: pageNum * this.pageSize, limit: this.pageSize}});
12909 beforeLoad : function(){
12911 this.loading.disable();
12916 onClick : function(which){
12920 ds.load({params:{start: 0, limit: this.pageSize}});
12923 ds.load({params:{start: Math.max(0, this.cursor-this.pageSize), limit: this.pageSize}});
12926 ds.load({params:{start: this.cursor+this.pageSize, limit: this.pageSize}});
12929 var total = ds.getTotalCount();
12930 var extra = total % this.pageSize;
12931 var lastStart = extra ? (total - extra) : total-this.pageSize;
12932 ds.load({params:{start: lastStart, limit: this.pageSize}});
12935 ds.load({params:{start: this.cursor, limit: this.pageSize}});
12941 * Unbinds the paging toolbar from the specified {@link Roo.data.Store}
12942 * @param {Roo.data.Store} store The data store to unbind
12944 unbind : function(ds){
12945 ds.un("beforeload", this.beforeLoad, this);
12946 ds.un("load", this.onLoad, this);
12947 ds.un("loadexception", this.onLoadError, this);
12948 ds.un("remove", this.updateInfo, this);
12949 ds.un("add", this.updateInfo, this);
12950 this.ds = undefined;
12954 * Binds the paging toolbar to the specified {@link Roo.data.Store}
12955 * @param {Roo.data.Store} store The data store to bind
12957 bind : function(ds){
12958 ds.on("beforeload", this.beforeLoad, this);
12959 ds.on("load", this.onLoad, this);
12960 ds.on("loadexception", this.onLoadError, this);
12961 ds.on("remove", this.updateInfo, this);
12962 ds.on("add", this.updateInfo, this);
12967 * Ext JS Library 1.1.1
12968 * Copyright(c) 2006-2007, Ext JS, LLC.
12970 * Originally Released Under LGPL - original licence link has changed is not relivant.
12973 * <script type="text/javascript">
12977 * @class Roo.Resizable
12978 * @extends Roo.util.Observable
12979 * <p>Applies drag handles to an element to make it resizable. The drag handles are inserted into the element
12980 * and positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you can wrap
12981 * 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
12982 * the element will be wrapped for you automatically.</p>
12983 * <p>Here is the list of valid resize handles:</p>
12986 ------ -------------------
12997 * <p>Here's an example showing the creation of a typical Resizable:</p>
12999 var resizer = new Roo.Resizable("element-id", {
13007 resizer.on("resize", myHandler);
13009 * <p>To hide a particular handle, set its display to none in CSS, or through script:<br>
13010 * resizer.east.setDisplayed(false);</p>
13011 * @cfg {Boolean/String/Element} resizeChild True to resize the first child, or id/element to resize (defaults to false)
13012 * @cfg {Array/String} adjustments String "auto" or an array [width, height] with values to be <b>added</b> to the
13013 * resize operation's new size (defaults to [0, 0])
13014 * @cfg {Number} minWidth The minimum width for the element (defaults to 5)
13015 * @cfg {Number} minHeight The minimum height for the element (defaults to 5)
13016 * @cfg {Number} maxWidth The maximum width for the element (defaults to 10000)
13017 * @cfg {Number} maxHeight The maximum height for the element (defaults to 10000)
13018 * @cfg {Boolean} enabled False to disable resizing (defaults to true)
13019 * @cfg {Boolean} wrap True to wrap an element with a div if needed (required for textareas and images, defaults to false)
13020 * @cfg {Number} width The width of the element in pixels (defaults to null)
13021 * @cfg {Number} height The height of the element in pixels (defaults to null)
13022 * @cfg {Boolean} animate True to animate the resize (not compatible with dynamic sizing, defaults to false)
13023 * @cfg {Number} duration Animation duration if animate = true (defaults to .35)
13024 * @cfg {Boolean} dynamic True to resize the element while dragging instead of using a proxy (defaults to false)
13025 * @cfg {String} handles String consisting of the resize handles to display (defaults to undefined)
13026 * @cfg {Boolean} multiDirectional <b>Deprecated</b>. The old style of adding multi-direction resize handles, deprecated
13027 * in favor of the handles config option (defaults to false)
13028 * @cfg {Boolean} disableTrackOver True to disable mouse tracking. This is only applied at config time. (defaults to false)
13029 * @cfg {String} easing Animation easing if animate = true (defaults to 'easingOutStrong')
13030 * @cfg {Number} widthIncrement The increment to snap the width resize in pixels (dynamic must be true, defaults to 0)
13031 * @cfg {Number} heightIncrement The increment to snap the height resize in pixels (dynamic must be true, defaults to 0)
13032 * @cfg {Boolean} pinned True to ensure that the resize handles are always visible, false to display them only when the
13033 * user mouses over the resizable borders. This is only applied at config time. (defaults to false)
13034 * @cfg {Boolean} preserveRatio True to preserve the original ratio between height and width during resize (defaults to false)
13035 * @cfg {Boolean} transparent True for transparent handles. This is only applied at config time. (defaults to false)
13036 * @cfg {Number} minX The minimum allowed page X for the element (only used for west resizing, defaults to 0)
13037 * @cfg {Number} minY The minimum allowed page Y for the element (only used for north resizing, defaults to 0)
13038 * @cfg {Boolean} draggable Convenience to initialize drag drop (defaults to false)
13040 * Create a new resizable component
13041 * @param {String/HTMLElement/Roo.Element} el The id or element to resize
13042 * @param {Object} config configuration options
13044 Roo.Resizable = function(el, config){
13045 this.el = Roo.get(el);
13047 if(config && config.wrap){
13048 config.resizeChild = this.el;
13049 this.el = this.el.wrap(typeof config.wrap == "object" ? config.wrap : {cls:"xresizable-wrap"});
13050 this.el.id = this.el.dom.id = config.resizeChild.id + "-rzwrap";
13051 this.el.setStyle("overflow", "hidden");
13052 this.el.setPositioning(config.resizeChild.getPositioning());
13053 config.resizeChild.clearPositioning();
13054 if(!config.width || !config.height){
13055 var csize = config.resizeChild.getSize();
13056 this.el.setSize(csize.width, csize.height);
13058 if(config.pinned && !config.adjustments){
13059 config.adjustments = "auto";
13063 this.proxy = this.el.createProxy({tag: "div", cls: "x-resizable-proxy", id: this.el.id + "-rzproxy"});
13064 this.proxy.unselectable();
13065 this.proxy.enableDisplayMode('block');
13067 Roo.apply(this, config);
13070 this.disableTrackOver = true;
13071 this.el.addClass("x-resizable-pinned");
13073 // if the element isn't positioned, make it relative
13074 var position = this.el.getStyle("position");
13075 if(position != "absolute" && position != "fixed"){
13076 this.el.setStyle("position", "relative");
13078 if(!this.handles){ // no handles passed, must be legacy style
13079 this.handles = 's,e,se';
13080 if(this.multiDirectional){
13081 this.handles += ',n,w';
13084 if(this.handles == "all"){
13085 this.handles = "n s e w ne nw se sw";
13087 var hs = this.handles.split(/\s*?[,;]\s*?| /);
13088 var ps = Roo.Resizable.positions;
13089 for(var i = 0, len = hs.length; i < len; i++){
13090 if(hs[i] && ps[hs[i]]){
13091 var pos = ps[hs[i]];
13092 this[pos] = new Roo.Resizable.Handle(this, pos, this.disableTrackOver, this.transparent);
13096 this.corner = this.southeast;
13098 if(this.handles.indexOf("n") != -1 || this.handles.indexOf("w") != -1){
13099 this.updateBox = true;
13102 this.activeHandle = null;
13104 if(this.resizeChild){
13105 if(typeof this.resizeChild == "boolean"){
13106 this.resizeChild = Roo.get(this.el.dom.firstChild, true);
13108 this.resizeChild = Roo.get(this.resizeChild, true);
13112 if(this.adjustments == "auto"){
13113 var rc = this.resizeChild;
13114 var hw = this.west, he = this.east, hn = this.north, hs = this.south;
13115 if(rc && (hw || hn)){
13116 rc.position("relative");
13117 rc.setLeft(hw ? hw.el.getWidth() : 0);
13118 rc.setTop(hn ? hn.el.getHeight() : 0);
13120 this.adjustments = [
13121 (he ? -he.el.getWidth() : 0) + (hw ? -hw.el.getWidth() : 0),
13122 (hn ? -hn.el.getHeight() : 0) + (hs ? -hs.el.getHeight() : 0) -1
13126 if(this.draggable){
13127 this.dd = this.dynamic ?
13128 this.el.initDD(null) : this.el.initDDProxy(null, {dragElId: this.proxy.id});
13129 this.dd.setHandleElId(this.resizeChild ? this.resizeChild.id : this.el.id);
13135 * @event beforeresize
13136 * Fired before resize is allowed. Set enabled to false to cancel resize.
13137 * @param {Roo.Resizable} this
13138 * @param {Roo.EventObject} e The mousedown event
13140 "beforeresize" : true,
13143 * Fired after a resize.
13144 * @param {Roo.Resizable} this
13145 * @param {Number} width The new width
13146 * @param {Number} height The new height
13147 * @param {Roo.EventObject} e The mouseup event
13152 if(this.width !== null && this.height !== null){
13153 this.resizeTo(this.width, this.height);
13155 this.updateChildSize();
13158 this.el.dom.style.zoom = 1;
13160 Roo.Resizable.superclass.constructor.call(this);
13163 Roo.extend(Roo.Resizable, Roo.util.Observable, {
13164 resizeChild : false,
13165 adjustments : [0, 0],
13175 multiDirectional : false,
13176 disableTrackOver : false,
13177 easing : 'easeOutStrong',
13178 widthIncrement : 0,
13179 heightIncrement : 0,
13183 preserveRatio : false,
13184 transparent: false,
13190 * @cfg {String/HTMLElement/Element} constrainTo Constrain the resize to a particular element
13192 constrainTo: undefined,
13194 * @cfg {Roo.lib.Region} resizeRegion Constrain the resize to a particular region
13196 resizeRegion: undefined,
13200 * Perform a manual resize
13201 * @param {Number} width
13202 * @param {Number} height
13204 resizeTo : function(width, height){
13205 this.el.setSize(width, height);
13206 this.updateChildSize();
13207 this.fireEvent("resize", this, width, height, null);
13211 startSizing : function(e, handle){
13212 this.fireEvent("beforeresize", this, e);
13213 if(this.enabled){ // 2nd enabled check in case disabled before beforeresize handler
13216 this.overlay = this.el.createProxy({tag: "div", cls: "x-resizable-overlay", html: " "});
13217 this.overlay.unselectable();
13218 this.overlay.enableDisplayMode("block");
13219 this.overlay.on("mousemove", this.onMouseMove, this);
13220 this.overlay.on("mouseup", this.onMouseUp, this);
13222 this.overlay.setStyle("cursor", handle.el.getStyle("cursor"));
13224 this.resizing = true;
13225 this.startBox = this.el.getBox();
13226 this.startPoint = e.getXY();
13227 this.offsets = [(this.startBox.x + this.startBox.width) - this.startPoint[0],
13228 (this.startBox.y + this.startBox.height) - this.startPoint[1]];
13230 this.overlay.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
13231 this.overlay.show();
13233 if(this.constrainTo) {
13234 var ct = Roo.get(this.constrainTo);
13235 this.resizeRegion = ct.getRegion().adjust(
13236 ct.getFrameWidth('t'),
13237 ct.getFrameWidth('l'),
13238 -ct.getFrameWidth('b'),
13239 -ct.getFrameWidth('r')
13243 this.proxy.setStyle('visibility', 'hidden'); // workaround display none
13245 this.proxy.setBox(this.startBox);
13247 this.proxy.setStyle('visibility', 'visible');
13253 onMouseDown : function(handle, e){
13256 this.activeHandle = handle;
13257 this.startSizing(e, handle);
13262 onMouseUp : function(e){
13263 var size = this.resizeElement();
13264 this.resizing = false;
13266 this.overlay.hide();
13268 this.fireEvent("resize", this, size.width, size.height, e);
13272 updateChildSize : function(){
13273 if(this.resizeChild){
13275 var child = this.resizeChild;
13276 var adj = this.adjustments;
13277 if(el.dom.offsetWidth){
13278 var b = el.getSize(true);
13279 child.setSize(b.width+adj[0], b.height+adj[1]);
13281 // Second call here for IE
13282 // The first call enables instant resizing and
13283 // the second call corrects scroll bars if they
13286 setTimeout(function(){
13287 if(el.dom.offsetWidth){
13288 var b = el.getSize(true);
13289 child.setSize(b.width+adj[0], b.height+adj[1]);
13297 snap : function(value, inc, min){
13298 if(!inc || !value) return value;
13299 var newValue = value;
13300 var m = value % inc;
13303 newValue = value + (inc-m);
13305 newValue = value - m;
13308 return Math.max(min, newValue);
13312 resizeElement : function(){
13313 var box = this.proxy.getBox();
13314 if(this.updateBox){
13315 this.el.setBox(box, false, this.animate, this.duration, null, this.easing);
13317 this.el.setSize(box.width, box.height, this.animate, this.duration, null, this.easing);
13319 this.updateChildSize();
13327 constrain : function(v, diff, m, mx){
13330 }else if(v - diff > mx){
13337 onMouseMove : function(e){
13339 try{// try catch so if something goes wrong the user doesn't get hung
13341 if(this.resizeRegion && !this.resizeRegion.contains(e.getPoint())) {
13345 //var curXY = this.startPoint;
13346 var curSize = this.curSize || this.startBox;
13347 var x = this.startBox.x, y = this.startBox.y;
13348 var ox = x, oy = y;
13349 var w = curSize.width, h = curSize.height;
13350 var ow = w, oh = h;
13351 var mw = this.minWidth, mh = this.minHeight;
13352 var mxw = this.maxWidth, mxh = this.maxHeight;
13353 var wi = this.widthIncrement;
13354 var hi = this.heightIncrement;
13356 var eventXY = e.getXY();
13357 var diffX = -(this.startPoint[0] - Math.max(this.minX, eventXY[0]));
13358 var diffY = -(this.startPoint[1] - Math.max(this.minY, eventXY[1]));
13360 var pos = this.activeHandle.position;
13365 w = Math.min(Math.max(mw, w), mxw);
13369 h = Math.min(Math.max(mh, h), mxh);
13374 w = Math.min(Math.max(mw, w), mxw);
13375 h = Math.min(Math.max(mh, h), mxh);
13378 diffY = this.constrain(h, diffY, mh, mxh);
13383 diffX = this.constrain(w, diffX, mw, mxw);
13389 w = Math.min(Math.max(mw, w), mxw);
13390 diffY = this.constrain(h, diffY, mh, mxh);
13395 diffX = this.constrain(w, diffX, mw, mxw);
13396 diffY = this.constrain(h, diffY, mh, mxh);
13403 diffX = this.constrain(w, diffX, mw, mxw);
13405 h = Math.min(Math.max(mh, h), mxh);
13411 var sw = this.snap(w, wi, mw);
13412 var sh = this.snap(h, hi, mh);
13413 if(sw != w || sh != h){
13436 if(this.preserveRatio){
13441 h = Math.min(Math.max(mh, h), mxh);
13446 w = Math.min(Math.max(mw, w), mxw);
13451 w = Math.min(Math.max(mw, w), mxw);
13457 w = Math.min(Math.max(mw, w), mxw);
13463 h = Math.min(Math.max(mh, h), mxh);
13471 h = Math.min(Math.max(mh, h), mxh);
13481 h = Math.min(Math.max(mh, h), mxh);
13489 this.proxy.setBounds(x, y, w, h);
13491 this.resizeElement();
13498 handleOver : function(){
13500 this.el.addClass("x-resizable-over");
13505 handleOut : function(){
13506 if(!this.resizing){
13507 this.el.removeClass("x-resizable-over");
13512 * Returns the element this component is bound to.
13513 * @return {Roo.Element}
13515 getEl : function(){
13520 * Returns the resizeChild element (or null).
13521 * @return {Roo.Element}
13523 getResizeChild : function(){
13524 return this.resizeChild;
13528 * Destroys this resizable. If the element was wrapped and
13529 * removeEl is not true then the element remains.
13530 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
13532 destroy : function(removeEl){
13533 this.proxy.remove();
13535 this.overlay.removeAllListeners();
13536 this.overlay.remove();
13538 var ps = Roo.Resizable.positions;
13540 if(typeof ps[k] != "function" && this[ps[k]]){
13541 var h = this[ps[k]];
13542 h.el.removeAllListeners();
13547 this.el.update("");
13554 // hash to map config positions to true positions
13555 Roo.Resizable.positions = {
13556 n: "north", s: "south", e: "east", w: "west", se: "southeast", sw: "southwest", nw: "northwest", ne: "northeast"
13560 Roo.Resizable.Handle = function(rz, pos, disableTrackOver, transparent){
13562 // only initialize the template if resizable is used
13563 var tpl = Roo.DomHelper.createTemplate(
13564 {tag: "div", cls: "x-resizable-handle x-resizable-handle-{0}"}
13567 Roo.Resizable.Handle.prototype.tpl = tpl;
13569 this.position = pos;
13571 this.el = this.tpl.append(rz.el.dom, [this.position], true);
13572 this.el.unselectable();
13574 this.el.setOpacity(0);
13576 this.el.on("mousedown", this.onMouseDown, this);
13577 if(!disableTrackOver){
13578 this.el.on("mouseover", this.onMouseOver, this);
13579 this.el.on("mouseout", this.onMouseOut, this);
13584 Roo.Resizable.Handle.prototype = {
13585 afterResize : function(rz){
13589 onMouseDown : function(e){
13590 this.rz.onMouseDown(this, e);
13593 onMouseOver : function(e){
13594 this.rz.handleOver(this, e);
13597 onMouseOut : function(e){
13598 this.rz.handleOut(this, e);
13602 * Ext JS Library 1.1.1
13603 * Copyright(c) 2006-2007, Ext JS, LLC.
13605 * Originally Released Under LGPL - original licence link has changed is not relivant.
13608 * <script type="text/javascript">
13612 * @class Roo.Editor
13613 * @extends Roo.Component
13614 * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
13616 * Create a new Editor
13617 * @param {Roo.form.Field} field The Field object (or descendant)
13618 * @param {Object} config The config object
13620 Roo.Editor = function(field, config){
13621 Roo.Editor.superclass.constructor.call(this, config);
13622 this.field = field;
13625 * @event beforestartedit
13626 * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
13627 * false from the handler of this event.
13628 * @param {Editor} this
13629 * @param {Roo.Element} boundEl The underlying element bound to this editor
13630 * @param {Mixed} value The field value being set
13632 "beforestartedit" : true,
13635 * Fires when this editor is displayed
13636 * @param {Roo.Element} boundEl The underlying element bound to this editor
13637 * @param {Mixed} value The starting field value
13639 "startedit" : true,
13641 * @event beforecomplete
13642 * Fires after a change has been made to the field, but before the change is reflected in the underlying
13643 * field. Saving the change to the field can be canceled by returning false from the handler of this event.
13644 * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
13645 * event will not fire since no edit actually occurred.
13646 * @param {Editor} this
13647 * @param {Mixed} value The current field value
13648 * @param {Mixed} startValue The original field value
13650 "beforecomplete" : true,
13653 * Fires after editing is complete and any changed value has been written to the underlying field.
13654 * @param {Editor} this
13655 * @param {Mixed} value The current field value
13656 * @param {Mixed} startValue The original field value
13660 * @event specialkey
13661 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
13662 * {@link Roo.EventObject#getKey} to determine which key was pressed.
13663 * @param {Roo.form.Field} this
13664 * @param {Roo.EventObject} e The event object
13666 "specialkey" : true
13670 Roo.extend(Roo.Editor, Roo.Component, {
13672 * @cfg {Boolean/String} autosize
13673 * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
13674 * or "height" to adopt the height only (defaults to false)
13677 * @cfg {Boolean} revertInvalid
13678 * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
13679 * validation fails (defaults to true)
13682 * @cfg {Boolean} ignoreNoChange
13683 * True to skip the the edit completion process (no save, no events fired) if the user completes an edit and
13684 * the value has not changed (defaults to false). Applies only to string values - edits for other data types
13685 * will never be ignored.
13688 * @cfg {Boolean} hideEl
13689 * False to keep the bound element visible while the editor is displayed (defaults to true)
13692 * @cfg {Mixed} value
13693 * The data value of the underlying field (defaults to "")
13697 * @cfg {String} alignment
13698 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "c-c?").
13702 * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
13703 * for bottom-right shadow (defaults to "frame")
13707 * @cfg {Boolean} constrain True to constrain the editor to the viewport
13711 * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed (defaults to false)
13713 completeOnEnter : false,
13715 * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed (defaults to false)
13717 cancelOnEsc : false,
13719 * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
13724 onRender : function(ct, position){
13725 this.el = new Roo.Layer({
13726 shadow: this.shadow,
13732 constrain: this.constrain
13734 this.el.setStyle("overflow", Roo.isGecko ? "auto" : "hidden");
13735 if(this.field.msgTarget != 'title'){
13736 this.field.msgTarget = 'qtip';
13738 this.field.render(this.el);
13740 this.field.el.dom.setAttribute('autocomplete', 'off');
13742 this.field.on("specialkey", this.onSpecialKey, this);
13743 if(this.swallowKeys){
13744 this.field.el.swallowEvent(['keydown','keypress']);
13747 this.field.on("blur", this.onBlur, this);
13748 if(this.field.grow){
13749 this.field.on("autosize", this.el.sync, this.el, {delay:1});
13753 onSpecialKey : function(field, e){
13754 if(this.completeOnEnter && e.getKey() == e.ENTER){
13756 this.completeEdit();
13757 }else if(this.cancelOnEsc && e.getKey() == e.ESC){
13760 this.fireEvent('specialkey', field, e);
13765 * Starts the editing process and shows the editor.
13766 * @param {String/HTMLElement/Element} el The element to edit
13767 * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
13768 * to the innerHTML of el.
13770 startEdit : function(el, value){
13772 this.completeEdit();
13774 this.boundEl = Roo.get(el);
13775 var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
13776 if(!this.rendered){
13777 this.render(this.parentEl || document.body);
13779 if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
13782 this.startValue = v;
13783 this.field.setValue(v);
13785 var sz = this.boundEl.getSize();
13786 switch(this.autoSize){
13788 this.setSize(sz.width, "");
13791 this.setSize("", sz.height);
13794 this.setSize(sz.width, sz.height);
13797 this.el.alignTo(this.boundEl, this.alignment);
13798 this.editing = true;
13800 Roo.QuickTips.disable();
13806 * Sets the height and width of this editor.
13807 * @param {Number} width The new width
13808 * @param {Number} height The new height
13810 setSize : function(w, h){
13811 this.field.setSize(w, h);
13818 * Realigns the editor to the bound field based on the current alignment config value.
13820 realign : function(){
13821 this.el.alignTo(this.boundEl, this.alignment);
13825 * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
13826 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
13828 completeEdit : function(remainVisible){
13832 var v = this.getValue();
13833 if(this.revertInvalid !== false && !this.field.isValid()){
13834 v = this.startValue;
13835 this.cancelEdit(true);
13837 if(String(v) === String(this.startValue) && this.ignoreNoChange){
13838 this.editing = false;
13842 if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
13843 this.editing = false;
13844 if(this.updateEl && this.boundEl){
13845 this.boundEl.update(v);
13847 if(remainVisible !== true){
13850 this.fireEvent("complete", this, v, this.startValue);
13855 onShow : function(){
13857 if(this.hideEl !== false){
13858 this.boundEl.hide();
13861 if(Roo.isIE && !this.fixIEFocus){ // IE has problems with focusing the first time
13862 this.fixIEFocus = true;
13863 this.deferredFocus.defer(50, this);
13865 this.field.focus();
13867 this.fireEvent("startedit", this.boundEl, this.startValue);
13870 deferredFocus : function(){
13872 this.field.focus();
13877 * Cancels the editing process and hides the editor without persisting any changes. The field value will be
13878 * reverted to the original starting value.
13879 * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
13880 * cancel (defaults to false)
13882 cancelEdit : function(remainVisible){
13884 this.setValue(this.startValue);
13885 if(remainVisible !== true){
13892 onBlur : function(){
13893 if(this.allowBlur !== true && this.editing){
13894 this.completeEdit();
13899 onHide : function(){
13901 this.completeEdit();
13905 if(this.field.collapse){
13906 this.field.collapse();
13909 if(this.hideEl !== false){
13910 this.boundEl.show();
13913 Roo.QuickTips.enable();
13918 * Sets the data value of the editor
13919 * @param {Mixed} value Any valid value supported by the underlying field
13921 setValue : function(v){
13922 this.field.setValue(v);
13926 * Gets the data value of the editor
13927 * @return {Mixed} The data value
13929 getValue : function(){
13930 return this.field.getValue();
13934 * Ext JS Library 1.1.1
13935 * Copyright(c) 2006-2007, Ext JS, LLC.
13937 * Originally Released Under LGPL - original licence link has changed is not relivant.
13940 * <script type="text/javascript">
13944 * @class Roo.BasicDialog
13945 * @extends Roo.util.Observable
13946 * Lightweight Dialog Class. The code below shows the creation of a typical dialog using existing HTML markup:
13948 var dlg = new Roo.BasicDialog("my-dlg", {
13957 dlg.addKeyListener(27, dlg.hide, dlg); // ESC can also close the dialog
13958 dlg.addButton('OK', dlg.hide, dlg); // Could call a save function instead of hiding
13959 dlg.addButton('Cancel', dlg.hide, dlg);
13962 <b>A Dialog should always be a direct child of the body element.</b>
13963 * @cfg {Boolean/DomHelper} autoCreate True to auto create from scratch, or using a DomHelper Object (defaults to false)
13964 * @cfg {String} title Default text to display in the title bar (defaults to null)
13965 * @cfg {Number} width Width of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
13966 * @cfg {Number} height Height of the dialog in pixels (can also be set via CSS). Determined by browser if unspecified.
13967 * @cfg {Number} x The default left page coordinate of the dialog (defaults to center screen)
13968 * @cfg {Number} y The default top page coordinate of the dialog (defaults to center screen)
13969 * @cfg {String/Element} animateTarget Id or element from which the dialog should animate while opening
13970 * (defaults to null with no animation)
13971 * @cfg {Boolean} resizable False to disable manual dialog resizing (defaults to true)
13972 * @cfg {String} resizeHandles Which resize handles to display - see the {@link Roo.Resizable} handles config
13973 * property for valid values (defaults to 'all')
13974 * @cfg {Number} minHeight The minimum allowable height for a resizable dialog (defaults to 80)
13975 * @cfg {Number} minWidth The minimum allowable width for a resizable dialog (defaults to 200)
13976 * @cfg {Boolean} modal True to show the dialog modally, preventing user interaction with the rest of the page (defaults to false)
13977 * @cfg {Boolean} autoScroll True to allow the dialog body contents to overflow and display scrollbars (defaults to false)
13978 * @cfg {Boolean} closable False to remove the built-in top-right corner close button (defaults to true)
13979 * @cfg {Boolean} collapsible False to remove the built-in top-right corner collapse button (defaults to true)
13980 * @cfg {Boolean} constraintoviewport True to keep the dialog constrained within the visible viewport boundaries (defaults to true)
13981 * @cfg {Boolean} syncHeightBeforeShow True to cause the dimensions to be recalculated before the dialog is shown (defaults to false)
13982 * @cfg {Boolean} draggable False to disable dragging of the dialog within the viewport (defaults to true)
13983 * @cfg {Boolean} autoTabs If true, all elements with class 'x-dlg-tab' will get automatically converted to tabs (defaults to false)
13984 * @cfg {String} tabTag The tag name of tab elements, used when autoTabs = true (defaults to 'div')
13985 * @cfg {Boolean} proxyDrag True to drag a lightweight proxy element rather than the dialog itself, used when
13986 * draggable = true (defaults to false)
13987 * @cfg {Boolean} fixedcenter True to ensure that anytime the dialog is shown or resized it gets centered (defaults to false)
13988 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
13989 * shadow (defaults to false)
13990 * @cfg {Number} shadowOffset The number of pixels to offset the shadow if displayed (defaults to 5)
13991 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "right")
13992 * @cfg {Number} minButtonWidth Minimum width of all dialog buttons (defaults to 75)
13993 * @cfg {Array} buttons Array of buttons
13994 * @cfg {Boolean} shim True to create an iframe shim that prevents selects from showing through (defaults to false)
13996 * Create a new BasicDialog.
13997 * @param {String/HTMLElement/Roo.Element} el The container element or DOM node, or its id
13998 * @param {Object} config Configuration options
14000 Roo.BasicDialog = function(el, config){
14001 this.el = Roo.get(el);
14002 var dh = Roo.DomHelper;
14003 if(!this.el && config && config.autoCreate){
14004 if(typeof config.autoCreate == "object"){
14005 if(!config.autoCreate.id){
14006 config.autoCreate.id = el;
14008 this.el = dh.append(document.body,
14009 config.autoCreate, true);
14011 this.el = dh.append(document.body,
14012 {tag: "div", id: el, style:'visibility:hidden;'}, true);
14016 el.setDisplayed(true);
14017 el.hide = this.hideAction;
14019 el.addClass("x-dlg");
14021 Roo.apply(this, config);
14023 this.proxy = el.createProxy("x-dlg-proxy");
14024 this.proxy.hide = this.hideAction;
14025 this.proxy.setOpacity(.5);
14029 el.setWidth(config.width);
14032 el.setHeight(config.height);
14034 this.size = el.getSize();
14035 if(typeof config.x != "undefined" && typeof config.y != "undefined"){
14036 this.xy = [config.x,config.y];
14038 this.xy = el.getCenterXY(true);
14040 /** The header element @type Roo.Element */
14041 this.header = el.child("> .x-dlg-hd");
14042 /** The body element @type Roo.Element */
14043 this.body = el.child("> .x-dlg-bd");
14044 /** The footer element @type Roo.Element */
14045 this.footer = el.child("> .x-dlg-ft");
14048 this.header = el.createChild({tag: "div", cls:"x-dlg-hd", html: " "}, this.body ? this.body.dom : null);
14051 this.body = el.createChild({tag: "div", cls:"x-dlg-bd"});
14054 this.header.unselectable();
14056 this.header.update(this.title);
14058 // this element allows the dialog to be focused for keyboard event
14059 this.focusEl = el.createChild({tag: "a", href:"#", cls:"x-dlg-focus", tabIndex:"-1"});
14060 this.focusEl.swallowEvent("click", true);
14062 this.header.wrap({cls:"x-dlg-hd-right"}).wrap({cls:"x-dlg-hd-left"}, true);
14064 // wrap the body and footer for special rendering
14065 this.bwrap = this.body.wrap({tag: "div", cls:"x-dlg-dlg-body"});
14067 this.bwrap.dom.appendChild(this.footer.dom);
14070 this.bg = this.el.createChild({
14071 tag: "div", cls:"x-dlg-bg",
14072 html: '<div class="x-dlg-bg-left"><div class="x-dlg-bg-right"><div class="x-dlg-bg-center"> </div></div></div>'
14074 this.centerBg = this.bg.child("div.x-dlg-bg-center");
14077 if(this.autoScroll !== false && !this.autoTabs){
14078 this.body.setStyle("overflow", "auto");
14081 this.toolbox = this.el.createChild({cls: "x-dlg-toolbox"});
14083 if(this.closable !== false){
14084 this.el.addClass("x-dlg-closable");
14085 this.close = this.toolbox.createChild({cls:"x-dlg-close"});
14086 this.close.on("click", this.closeClick, this);
14087 this.close.addClassOnOver("x-dlg-close-over");
14089 if(this.collapsible !== false){
14090 this.collapseBtn = this.toolbox.createChild({cls:"x-dlg-collapse"});
14091 this.collapseBtn.on("click", this.collapseClick, this);
14092 this.collapseBtn.addClassOnOver("x-dlg-collapse-over");
14093 this.header.on("dblclick", this.collapseClick, this);
14095 if(this.resizable !== false){
14096 this.el.addClass("x-dlg-resizable");
14097 this.resizer = new Roo.Resizable(el, {
14098 minWidth: this.minWidth || 80,
14099 minHeight:this.minHeight || 80,
14100 handles: this.resizeHandles || "all",
14103 this.resizer.on("beforeresize", this.beforeResize, this);
14104 this.resizer.on("resize", this.onResize, this);
14106 if(this.draggable !== false){
14107 el.addClass("x-dlg-draggable");
14108 if (!this.proxyDrag) {
14109 var dd = new Roo.dd.DD(el.dom.id, "WindowDrag");
14112 var dd = new Roo.dd.DDProxy(el.dom.id, "WindowDrag", {dragElId: this.proxy.id});
14114 dd.setHandleElId(this.header.id);
14115 dd.endDrag = this.endMove.createDelegate(this);
14116 dd.startDrag = this.startMove.createDelegate(this);
14117 dd.onDrag = this.onDrag.createDelegate(this);
14122 this.mask = dh.append(document.body, {tag: "div", cls:"x-dlg-mask"}, true);
14123 this.mask.enableDisplayMode("block");
14125 this.el.addClass("x-dlg-modal");
14128 this.shadow = new Roo.Shadow({
14129 mode : typeof this.shadow == "string" ? this.shadow : "sides",
14130 offset : this.shadowOffset
14133 this.shadowOffset = 0;
14135 if(Roo.useShims && this.shim !== false){
14136 this.shim = this.el.createShim();
14137 this.shim.hide = this.hideAction;
14145 if (this.buttons) {
14146 var bts= this.buttons;
14148 Roo.each(bts, function(b) {
14157 * Fires when a key is pressed
14158 * @param {Roo.BasicDialog} this
14159 * @param {Roo.EventObject} e
14164 * Fires when this dialog is moved by the user.
14165 * @param {Roo.BasicDialog} this
14166 * @param {Number} x The new page X
14167 * @param {Number} y The new page Y
14172 * Fires when this dialog is resized by the user.
14173 * @param {Roo.BasicDialog} this
14174 * @param {Number} width The new width
14175 * @param {Number} height The new height
14179 * @event beforehide
14180 * Fires before this dialog is hidden.
14181 * @param {Roo.BasicDialog} this
14183 "beforehide" : true,
14186 * Fires when this dialog is hidden.
14187 * @param {Roo.BasicDialog} this
14191 * @event beforeshow
14192 * Fires before this dialog is shown.
14193 * @param {Roo.BasicDialog} this
14195 "beforeshow" : true,
14198 * Fires when this dialog is shown.
14199 * @param {Roo.BasicDialog} this
14203 el.on("keydown", this.onKeyDown, this);
14204 el.on("mousedown", this.toFront, this);
14205 Roo.EventManager.onWindowResize(this.adjustViewport, this, true);
14207 Roo.DialogManager.register(this);
14208 Roo.BasicDialog.superclass.constructor.call(this);
14211 Roo.extend(Roo.BasicDialog, Roo.util.Observable, {
14212 shadowOffset: Roo.isIE ? 6 : 5,
14215 minButtonWidth: 75,
14216 defaultButton: null,
14217 buttonAlign: "right",
14222 * Sets the dialog title text
14223 * @param {String} text The title text to display
14224 * @return {Roo.BasicDialog} this
14226 setTitle : function(text){
14227 this.header.update(text);
14232 closeClick : function(){
14237 collapseClick : function(){
14238 this[this.collapsed ? "expand" : "collapse"]();
14242 * Collapses the dialog to its minimized state (only the title bar is visible).
14243 * Equivalent to the user clicking the collapse dialog button.
14245 collapse : function(){
14246 if(!this.collapsed){
14247 this.collapsed = true;
14248 this.el.addClass("x-dlg-collapsed");
14249 this.restoreHeight = this.el.getHeight();
14250 this.resizeTo(this.el.getWidth(), this.header.getHeight());
14255 * Expands a collapsed dialog back to its normal state. Equivalent to the user
14256 * clicking the expand dialog button.
14258 expand : function(){
14259 if(this.collapsed){
14260 this.collapsed = false;
14261 this.el.removeClass("x-dlg-collapsed");
14262 this.resizeTo(this.el.getWidth(), this.restoreHeight);
14267 * Reinitializes the tabs component, clearing out old tabs and finding new ones.
14268 * @return {Roo.TabPanel} The tabs component
14270 initTabs : function(){
14271 var tabs = this.getTabs();
14272 while(tabs.getTab(0)){
14275 this.el.select(this.tabTag+'.x-dlg-tab').each(function(el){
14277 tabs.addTab(Roo.id(dom), dom.title);
14285 beforeResize : function(){
14286 this.resizer.minHeight = Math.max(this.minHeight, this.getHeaderFooterHeight(true)+40);
14290 onResize : function(){
14291 this.refreshSize();
14292 this.syncBodyHeight();
14293 this.adjustAssets();
14295 this.fireEvent("resize", this, this.size.width, this.size.height);
14299 onKeyDown : function(e){
14300 if(this.isVisible()){
14301 this.fireEvent("keydown", this, e);
14306 * Resizes the dialog.
14307 * @param {Number} width
14308 * @param {Number} height
14309 * @return {Roo.BasicDialog} this
14311 resizeTo : function(width, height){
14312 this.el.setSize(width, height);
14313 this.size = {width: width, height: height};
14314 this.syncBodyHeight();
14315 if(this.fixedcenter){
14318 if(this.isVisible()){
14319 this.constrainXY();
14320 this.adjustAssets();
14322 this.fireEvent("resize", this, width, height);
14328 * Resizes the dialog to fit the specified content size.
14329 * @param {Number} width
14330 * @param {Number} height
14331 * @return {Roo.BasicDialog} this
14333 setContentSize : function(w, h){
14334 h += this.getHeaderFooterHeight() + this.body.getMargins("tb");
14335 w += this.body.getMargins("lr") + this.bwrap.getMargins("lr") + this.centerBg.getPadding("lr");
14336 //if(!this.el.isBorderBox()){
14337 h += this.body.getPadding("tb") + this.bwrap.getBorderWidth("tb") + this.body.getBorderWidth("tb") + this.el.getBorderWidth("tb");
14338 w += this.body.getPadding("lr") + this.bwrap.getBorderWidth("lr") + this.body.getBorderWidth("lr") + this.bwrap.getPadding("lr") + this.el.getBorderWidth("lr");
14341 h += this.tabs.stripWrap.getHeight() + this.tabs.bodyEl.getMargins("tb") + this.tabs.bodyEl.getPadding("tb");
14342 w += this.tabs.bodyEl.getMargins("lr") + this.tabs.bodyEl.getPadding("lr");
14344 this.resizeTo(w, h);
14349 * Adds a key listener for when this dialog is displayed. This allows you to hook in a function that will be
14350 * executed in response to a particular key being pressed while the dialog is active.
14351 * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the following options:
14352 * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
14353 * @param {Function} fn The function to call
14354 * @param {Object} scope (optional) The scope of the function
14355 * @return {Roo.BasicDialog} this
14357 addKeyListener : function(key, fn, scope){
14358 var keyCode, shift, ctrl, alt;
14359 if(typeof key == "object" && !(key instanceof Array)){
14360 keyCode = key["key"];
14361 shift = key["shift"];
14362 ctrl = key["ctrl"];
14367 var handler = function(dlg, e){
14368 if((!shift || e.shiftKey) && (!ctrl || e.ctrlKey) && (!alt || e.altKey)){
14369 var k = e.getKey();
14370 if(keyCode instanceof Array){
14371 for(var i = 0, len = keyCode.length; i < len; i++){
14372 if(keyCode[i] == k){
14373 fn.call(scope || window, dlg, k, e);
14379 fn.call(scope || window, dlg, k, e);
14384 this.on("keydown", handler);
14389 * Returns the TabPanel component (creates it if it doesn't exist).
14390 * Note: If you wish to simply check for the existence of tabs without creating them,
14391 * check for a null 'tabs' property.
14392 * @return {Roo.TabPanel} The tabs component
14394 getTabs : function(){
14396 this.el.addClass("x-dlg-auto-tabs");
14397 this.body.addClass(this.tabPosition == "bottom" ? "x-tabs-bottom" : "x-tabs-top");
14398 this.tabs = new Roo.TabPanel(this.body.dom, this.tabPosition == "bottom");
14404 * Adds a button to the footer section of the dialog.
14405 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
14406 * object or a valid Roo.DomHelper element config
14407 * @param {Function} handler The function called when the button is clicked
14408 * @param {Object} scope (optional) The scope of the handler function (accepts position as a property)
14409 * @return {Roo.Button} The new button
14411 addButton : function(config, handler, scope){
14412 var dh = Roo.DomHelper;
14414 this.footer = dh.append(this.bwrap, {tag: "div", cls:"x-dlg-ft"}, true);
14416 if(!this.btnContainer){
14417 var tb = this.footer.createChild({
14419 cls:"x-dlg-btns x-dlg-btns-"+this.buttonAlign,
14420 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
14422 this.btnContainer = tb.firstChild.firstChild.firstChild;
14427 minWidth: this.minButtonWidth,
14430 if(typeof config == "string"){
14431 bconfig.text = config;
14434 bconfig.dhconfig = config;
14436 Roo.apply(bconfig, config);
14440 if ((typeof(bconfig.position) != 'undefined') && bconfig.position < this.btnContainer.childNodes.length-1) {
14441 bconfig.position = Math.max(0, bconfig.position);
14442 fc = this.btnContainer.childNodes[bconfig.position];
14445 var btn = new Roo.Button(
14447 this.btnContainer.insertBefore(document.createElement("td"),fc)
14448 : this.btnContainer.appendChild(document.createElement("td")),
14449 //Roo.get(this.btnContainer).createChild( { tag: 'td'}, fc ),
14452 this.syncBodyHeight();
14455 * Array of all the buttons that have been added to this dialog via addButton
14460 this.buttons.push(btn);
14465 * Sets the default button to be focused when the dialog is displayed.
14466 * @param {Roo.BasicDialog.Button} btn The button object returned by {@link #addButton}
14467 * @return {Roo.BasicDialog} this
14469 setDefaultButton : function(btn){
14470 this.defaultButton = btn;
14475 getHeaderFooterHeight : function(safe){
14478 height += this.header.getHeight();
14481 var fm = this.footer.getMargins();
14482 height += (this.footer.getHeight()+fm.top+fm.bottom);
14484 height += this.bwrap.getPadding("tb")+this.bwrap.getBorderWidth("tb");
14485 height += this.centerBg.getPadding("tb");
14490 syncBodyHeight : function(){
14491 var bd = this.body, cb = this.centerBg, bw = this.bwrap;
14492 var height = this.size.height - this.getHeaderFooterHeight(false);
14493 bd.setHeight(height-bd.getMargins("tb"));
14494 var hh = this.header.getHeight();
14495 var h = this.size.height-hh;
14497 bw.setLeftTop(cb.getPadding("l"), hh+cb.getPadding("t"));
14498 bw.setHeight(h-cb.getPadding("tb"));
14499 bw.setWidth(this.el.getWidth(true)-cb.getPadding("lr"));
14500 bd.setWidth(bw.getWidth(true));
14502 this.tabs.syncHeight();
14504 this.tabs.el.repaint();
14510 * Restores the previous state of the dialog if Roo.state is configured.
14511 * @return {Roo.BasicDialog} this
14513 restoreState : function(){
14514 var box = Roo.state.Manager.get(this.stateId || (this.el.id + "-state"));
14515 if(box && box.width){
14516 this.xy = [box.x, box.y];
14517 this.resizeTo(box.width, box.height);
14523 beforeShow : function(){
14525 if(this.fixedcenter){
14526 this.xy = this.el.getCenterXY(true);
14529 Roo.get(document.body).addClass("x-body-masked");
14530 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
14533 this.constrainXY();
14537 animShow : function(){
14538 var b = Roo.get(this.animateTarget, true).getBox();
14539 this.proxy.setSize(b.width, b.height);
14540 this.proxy.setLocation(b.x, b.y);
14542 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height,
14543 true, .35, this.showEl.createDelegate(this));
14547 * Shows the dialog.
14548 * @param {String/HTMLElement/Roo.Element} animateTarget (optional) Reset the animation target
14549 * @return {Roo.BasicDialog} this
14551 show : function(animateTarget){
14552 if (this.fireEvent("beforeshow", this) === false){
14555 if(this.syncHeightBeforeShow){
14556 this.syncBodyHeight();
14557 }else if(this.firstShow){
14558 this.firstShow = false;
14559 this.syncBodyHeight(); // sync the height on the first show instead of in the constructor
14561 this.animateTarget = animateTarget || this.animateTarget;
14562 if(!this.el.isVisible()){
14564 if(this.animateTarget){
14574 showEl : function(){
14576 this.el.setXY(this.xy);
14578 this.adjustAssets(true);
14581 // IE peekaboo bug - fix found by Dave Fenwick
14585 this.fireEvent("show", this);
14589 * Focuses the dialog. If a defaultButton is set, it will receive focus, otherwise the
14590 * dialog itself will receive focus.
14592 focus : function(){
14593 if(this.defaultButton){
14594 this.defaultButton.focus();
14596 this.focusEl.focus();
14601 constrainXY : function(){
14602 if(this.constraintoviewport !== false){
14603 if(!this.viewSize){
14604 if(this.container){
14605 var s = this.container.getSize();
14606 this.viewSize = [s.width, s.height];
14608 this.viewSize = [Roo.lib.Dom.getViewWidth(),Roo.lib.Dom.getViewHeight()];
14611 var s = Roo.get(this.container||document).getScroll();
14613 var x = this.xy[0], y = this.xy[1];
14614 var w = this.size.width, h = this.size.height;
14615 var vw = this.viewSize[0], vh = this.viewSize[1];
14616 // only move it if it needs it
14618 // first validate right/bottom
14619 if(x + w > vw+s.left){
14623 if(y + h > vh+s.top){
14627 // then make sure top/left isn't negative
14639 if(this.isVisible()){
14640 this.el.setLocation(x, y);
14641 this.adjustAssets();
14648 onDrag : function(){
14649 if(!this.proxyDrag){
14650 this.xy = this.el.getXY();
14651 this.adjustAssets();
14656 adjustAssets : function(doShow){
14657 var x = this.xy[0], y = this.xy[1];
14658 var w = this.size.width, h = this.size.height;
14659 if(doShow === true){
14661 this.shadow.show(this.el);
14667 if(this.shadow && this.shadow.isVisible()){
14668 this.shadow.show(this.el);
14670 if(this.shim && this.shim.isVisible()){
14671 this.shim.setBounds(x, y, w, h);
14676 adjustViewport : function(w, h){
14678 w = Roo.lib.Dom.getViewWidth();
14679 h = Roo.lib.Dom.getViewHeight();
14682 this.viewSize = [w, h];
14683 if(this.modal && this.mask.isVisible()){
14684 this.mask.setSize(w, h); // first make sure the mask isn't causing overflow
14685 this.mask.setSize(Roo.lib.Dom.getViewWidth(true), Roo.lib.Dom.getViewHeight(true));
14687 if(this.isVisible()){
14688 this.constrainXY();
14693 * Destroys this dialog and all its supporting elements (including any tabs, shim,
14694 * shadow, proxy, mask, etc.) Also removes all event listeners.
14695 * @param {Boolean} removeEl (optional) true to remove the element from the DOM
14697 destroy : function(removeEl){
14698 if(this.isVisible()){
14699 this.animateTarget = null;
14702 Roo.EventManager.removeResizeListener(this.adjustViewport, this);
14704 this.tabs.destroy(removeEl);
14717 for(var i = 0, len = this.buttons.length; i < len; i++){
14718 this.buttons[i].destroy();
14721 this.el.removeAllListeners();
14722 if(removeEl === true){
14723 this.el.update("");
14726 Roo.DialogManager.unregister(this);
14730 startMove : function(){
14731 if(this.proxyDrag){
14734 if(this.constraintoviewport !== false){
14735 this.dd.constrainTo(document.body, {right: this.shadowOffset, bottom: this.shadowOffset});
14740 endMove : function(){
14741 if(!this.proxyDrag){
14742 Roo.dd.DD.prototype.endDrag.apply(this.dd, arguments);
14744 Roo.dd.DDProxy.prototype.endDrag.apply(this.dd, arguments);
14747 this.refreshSize();
14748 this.adjustAssets();
14750 this.fireEvent("move", this, this.xy[0], this.xy[1]);
14754 * Brings this dialog to the front of any other visible dialogs
14755 * @return {Roo.BasicDialog} this
14757 toFront : function(){
14758 Roo.DialogManager.bringToFront(this);
14763 * Sends this dialog to the back (under) of any other visible dialogs
14764 * @return {Roo.BasicDialog} this
14766 toBack : function(){
14767 Roo.DialogManager.sendToBack(this);
14772 * Centers this dialog in the viewport
14773 * @return {Roo.BasicDialog} this
14775 center : function(){
14776 var xy = this.el.getCenterXY(true);
14777 this.moveTo(xy[0], xy[1]);
14782 * Moves the dialog's top-left corner to the specified point
14783 * @param {Number} x
14784 * @param {Number} y
14785 * @return {Roo.BasicDialog} this
14787 moveTo : function(x, y){
14789 if(this.isVisible()){
14790 this.el.setXY(this.xy);
14791 this.adjustAssets();
14797 * Aligns the dialog to the specified element
14798 * @param {String/HTMLElement/Roo.Element} element The element to align to.
14799 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details).
14800 * @param {Array} offsets (optional) Offset the positioning by [x, y]
14801 * @return {Roo.BasicDialog} this
14803 alignTo : function(element, position, offsets){
14804 this.xy = this.el.getAlignToXY(element, position, offsets);
14805 if(this.isVisible()){
14806 this.el.setXY(this.xy);
14807 this.adjustAssets();
14813 * Anchors an element to another element and realigns it when the window is resized.
14814 * @param {String/HTMLElement/Roo.Element} element The element to align to.
14815 * @param {String} position The position to align to (see {@link Roo.Element#alignTo} for more details)
14816 * @param {Array} offsets (optional) Offset the positioning by [x, y]
14817 * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
14818 * is a number, it is used as the buffer delay (defaults to 50ms).
14819 * @return {Roo.BasicDialog} this
14821 anchorTo : function(el, alignment, offsets, monitorScroll){
14822 var action = function(){
14823 this.alignTo(el, alignment, offsets);
14825 Roo.EventManager.onWindowResize(action, this);
14826 var tm = typeof monitorScroll;
14827 if(tm != 'undefined'){
14828 Roo.EventManager.on(window, 'scroll', action, this,
14829 {buffer: tm == 'number' ? monitorScroll : 50});
14836 * Returns true if the dialog is visible
14837 * @return {Boolean}
14839 isVisible : function(){
14840 return this.el.isVisible();
14844 animHide : function(callback){
14845 var b = Roo.get(this.animateTarget).getBox();
14847 this.proxy.setBounds(this.xy[0], this.xy[1], this.size.width, this.size.height);
14849 this.proxy.setBounds(b.x, b.y, b.width, b.height, true, .35,
14850 this.hideEl.createDelegate(this, [callback]));
14854 * Hides the dialog.
14855 * @param {Function} callback (optional) Function to call when the dialog is hidden
14856 * @return {Roo.BasicDialog} this
14858 hide : function(callback){
14859 if (this.fireEvent("beforehide", this) === false){
14863 this.shadow.hide();
14868 if(this.animateTarget){
14869 this.animHide(callback);
14872 this.hideEl(callback);
14878 hideEl : function(callback){
14882 Roo.get(document.body).removeClass("x-body-masked");
14884 this.fireEvent("hide", this);
14885 if(typeof callback == "function"){
14891 hideAction : function(){
14892 this.setLeft("-10000px");
14893 this.setTop("-10000px");
14894 this.setStyle("visibility", "hidden");
14898 refreshSize : function(){
14899 this.size = this.el.getSize();
14900 this.xy = this.el.getXY();
14901 Roo.state.Manager.set(this.stateId || this.el.id + "-state", this.el.getBox());
14905 // z-index is managed by the DialogManager and may be overwritten at any time
14906 setZIndex : function(index){
14908 this.mask.setStyle("z-index", index);
14911 this.shim.setStyle("z-index", ++index);
14914 this.shadow.setZIndex(++index);
14916 this.el.setStyle("z-index", ++index);
14918 this.proxy.setStyle("z-index", ++index);
14921 this.resizer.proxy.setStyle("z-index", ++index);
14924 this.lastZIndex = index;
14928 * Returns the element for this dialog
14929 * @return {Roo.Element} The underlying dialog Element
14931 getEl : function(){
14937 * @class Roo.DialogManager
14938 * Provides global access to BasicDialogs that have been created and
14939 * support for z-indexing (layering) multiple open dialogs.
14941 Roo.DialogManager = function(){
14943 var accessList = [];
14947 var sortDialogs = function(d1, d2){
14948 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
14952 var orderDialogs = function(){
14953 accessList.sort(sortDialogs);
14954 var seed = Roo.DialogManager.zseed;
14955 for(var i = 0, len = accessList.length; i < len; i++){
14956 var dlg = accessList[i];
14958 dlg.setZIndex(seed + (i*10));
14965 * The starting z-index for BasicDialogs (defaults to 9000)
14966 * @type Number The z-index value
14971 register : function(dlg){
14972 list[dlg.id] = dlg;
14973 accessList.push(dlg);
14977 unregister : function(dlg){
14978 delete list[dlg.id];
14981 if(!accessList.indexOf){
14982 for( i = 0, len = accessList.length; i < len; i++){
14983 if(accessList[i] == dlg){
14984 accessList.splice(i, 1);
14989 i = accessList.indexOf(dlg);
14991 accessList.splice(i, 1);
14997 * Gets a registered dialog by id
14998 * @param {String/Object} id The id of the dialog or a dialog
14999 * @return {Roo.BasicDialog} this
15001 get : function(id){
15002 return typeof id == "object" ? id : list[id];
15006 * Brings the specified dialog to the front
15007 * @param {String/Object} dlg The id of the dialog or a dialog
15008 * @return {Roo.BasicDialog} this
15010 bringToFront : function(dlg){
15011 dlg = this.get(dlg);
15014 dlg._lastAccess = new Date().getTime();
15021 * Sends the specified dialog to the back
15022 * @param {String/Object} dlg The id of the dialog or a dialog
15023 * @return {Roo.BasicDialog} this
15025 sendToBack : function(dlg){
15026 dlg = this.get(dlg);
15027 dlg._lastAccess = -(new Date().getTime());
15033 * Hides all dialogs
15035 hideAll : function(){
15036 for(var id in list){
15037 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
15046 * @class Roo.LayoutDialog
15047 * @extends Roo.BasicDialog
15048 * Dialog which provides adjustments for working with a layout in a Dialog.
15049 * Add your necessary layout config options to the dialog's config.<br>
15050 * Example usage (including a nested layout):
15053 dialog = new Roo.LayoutDialog("download-dlg", {
15062 // layout config merges with the dialog config
15064 tabPosition: "top",
15065 alwaysShowTabs: true
15068 dialog.addKeyListener(27, dialog.hide, dialog);
15069 dialog.setDefaultButton(dialog.addButton("Close", dialog.hide, dialog));
15070 dialog.addButton("Build It!", this.getDownload, this);
15072 // we can even add nested layouts
15073 var innerLayout = new Roo.BorderLayout("dl-inner", {
15083 innerLayout.beginUpdate();
15084 innerLayout.add("east", new Roo.ContentPanel("dl-details"));
15085 innerLayout.add("center", new Roo.ContentPanel("selection-panel"));
15086 innerLayout.endUpdate(true);
15088 var layout = dialog.getLayout();
15089 layout.beginUpdate();
15090 layout.add("center", new Roo.ContentPanel("standard-panel",
15091 {title: "Download the Source", fitToFrame:true}));
15092 layout.add("center", new Roo.NestedLayoutPanel(innerLayout,
15093 {title: "Build your own roo.js"}));
15094 layout.getRegion("center").showPanel(sp);
15095 layout.endUpdate();
15099 * @param {String/HTMLElement/Roo.Element} el The id of or container element, or config
15100 * @param {Object} config configuration options
15102 Roo.LayoutDialog = function(el, cfg){
15105 if (typeof(cfg) == 'undefined') {
15106 config = Roo.apply({}, el);
15107 el = Roo.get( document.documentElement || document.body).createChild();
15108 //config.autoCreate = true;
15112 config.autoTabs = false;
15113 Roo.LayoutDialog.superclass.constructor.call(this, el, config);
15114 this.body.setStyle({overflow:"hidden", position:"relative"});
15115 this.layout = new Roo.BorderLayout(this.body.dom, config);
15116 this.layout.monitorWindowResize = false;
15117 this.el.addClass("x-dlg-auto-layout");
15118 // fix case when center region overwrites center function
15119 this.center = Roo.BasicDialog.prototype.center;
15120 this.on("show", this.layout.layout, this.layout, true);
15121 if (config.items) {
15122 var xitems = config.items;
15123 delete config.items;
15124 Roo.each(xitems, this.addxtype, this);
15129 Roo.extend(Roo.LayoutDialog, Roo.BasicDialog, {
15131 * Ends update of the layout <strike>and resets display to none</strike>. Use standard beginUpdate/endUpdate on the layout.
15134 endUpdate : function(){
15135 this.layout.endUpdate();
15139 * Begins an update of the layout <strike>and sets display to block and visibility to hidden</strike>. Use standard beginUpdate/endUpdate on the layout.
15142 beginUpdate : function(){
15143 this.layout.beginUpdate();
15147 * Get the BorderLayout for this dialog
15148 * @return {Roo.BorderLayout}
15150 getLayout : function(){
15151 return this.layout;
15154 showEl : function(){
15155 Roo.LayoutDialog.superclass.showEl.apply(this, arguments);
15157 this.layout.layout();
15162 // Use the syncHeightBeforeShow config option to control this automatically
15163 syncBodyHeight : function(){
15164 Roo.LayoutDialog.superclass.syncBodyHeight.call(this);
15165 if(this.layout){this.layout.layout();}
15169 * Add an xtype element (actually adds to the layout.)
15170 * @return {Object} xdata xtype object data.
15173 addxtype : function(c) {
15174 return this.layout.addxtype(c);
15178 * Ext JS Library 1.1.1
15179 * Copyright(c) 2006-2007, Ext JS, LLC.
15181 * Originally Released Under LGPL - original licence link has changed is not relivant.
15184 * <script type="text/javascript">
15188 * @class Roo.MessageBox
15189 * Utility class for generating different styles of message boxes. The alias Roo.Msg can also be used.
15193 Roo.Msg.alert('Status', 'Changes saved successfully.');
15195 // Prompt for user data:
15196 Roo.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
15198 // process text value...
15202 // Show a dialog using config options:
15204 title:'Save Changes?',
15205 msg: 'Your are closing a tab that has unsaved changes. Would you like to save your changes?',
15206 buttons: Roo.Msg.YESNOCANCEL,
15213 Roo.MessageBox = function(){
15214 var dlg, opt, mask, waitTimer;
15215 var bodyEl, msgEl, textboxEl, textareaEl, progressEl, pp;
15216 var buttons, activeTextEl, bwidth;
15219 var handleButton = function(button){
15221 Roo.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value], 1);
15225 var handleHide = function(){
15226 if(opt && opt.cls){
15227 dlg.el.removeClass(opt.cls);
15230 Roo.TaskMgr.stop(waitTimer);
15236 var updateButtons = function(b){
15239 buttons["ok"].hide();
15240 buttons["cancel"].hide();
15241 buttons["yes"].hide();
15242 buttons["no"].hide();
15243 dlg.footer.dom.style.display = 'none';
15246 dlg.footer.dom.style.display = '';
15247 for(var k in buttons){
15248 if(typeof buttons[k] != "function"){
15251 buttons[k].setText(typeof b[k] == "string" ? b[k] : Roo.MessageBox.buttonText[k]);
15252 width += buttons[k].el.getWidth()+15;
15262 var handleEsc = function(d, k, e){
15263 if(opt && opt.closable !== false){
15273 * Returns a reference to the underlying {@link Roo.BasicDialog} element
15274 * @return {Roo.BasicDialog} The BasicDialog element
15276 getDialog : function(){
15278 dlg = new Roo.BasicDialog("x-msg-box", {
15283 constraintoviewport:false,
15285 collapsible : false,
15288 width:400, height:100,
15289 buttonAlign:"center",
15290 closeClick : function(){
15291 if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
15292 handleButton("no");
15294 handleButton("cancel");
15298 dlg.on("hide", handleHide);
15300 dlg.addKeyListener(27, handleEsc);
15302 var bt = this.buttonText;
15303 buttons["ok"] = dlg.addButton(bt["ok"], handleButton.createCallback("ok"));
15304 buttons["yes"] = dlg.addButton(bt["yes"], handleButton.createCallback("yes"));
15305 buttons["no"] = dlg.addButton(bt["no"], handleButton.createCallback("no"));
15306 buttons["cancel"] = dlg.addButton(bt["cancel"], handleButton.createCallback("cancel"));
15307 bodyEl = dlg.body.createChild({
15309 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>'
15311 msgEl = bodyEl.dom.firstChild;
15312 textboxEl = Roo.get(bodyEl.dom.childNodes[2]);
15313 textboxEl.enableDisplayMode();
15314 textboxEl.addKeyListener([10,13], function(){
15315 if(dlg.isVisible() && opt && opt.buttons){
15316 if(opt.buttons.ok){
15317 handleButton("ok");
15318 }else if(opt.buttons.yes){
15319 handleButton("yes");
15323 textareaEl = Roo.get(bodyEl.dom.childNodes[3]);
15324 textareaEl.enableDisplayMode();
15325 progressEl = Roo.get(bodyEl.dom.childNodes[4]);
15326 progressEl.enableDisplayMode();
15327 var pf = progressEl.dom.firstChild;
15329 pp = Roo.get(pf.firstChild);
15330 pp.setHeight(pf.offsetHeight);
15338 * Updates the message box body text
15339 * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
15340 * the XHTML-compliant non-breaking space character '&#160;')
15341 * @return {Roo.MessageBox} This message box
15343 updateText : function(text){
15344 if(!dlg.isVisible() && !opt.width){
15345 dlg.resizeTo(this.maxWidth, 100); // resize first so content is never clipped from previous shows
15347 msgEl.innerHTML = text || ' ';
15348 var w = Math.max(Math.min(opt.width || msgEl.offsetWidth, this.maxWidth),
15349 Math.max(opt.minWidth || this.minWidth, bwidth));
15351 activeTextEl.setWidth(w);
15353 if(dlg.isVisible()){
15354 dlg.fixedcenter = false;
15356 dlg.setContentSize(w, bodyEl.getHeight());
15357 if(dlg.isVisible()){
15358 dlg.fixedcenter = true;
15364 * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
15365 * initiated via {@link Roo.MessageBox#progress} or by calling {@link Roo.MessageBox#show} with progress: true.
15366 * @param {Number} value Any number between 0 and 1 (e.g., .5)
15367 * @param {String} text (optional) If defined, the message box's body text is replaced with the specified string (defaults to undefined)
15368 * @return {Roo.MessageBox} This message box
15370 updateProgress : function(value, text){
15372 this.updateText(text);
15374 if (pp) { // weird bug on my firefox - for some reason this is not defined
15375 pp.setWidth(Math.floor(value*progressEl.dom.firstChild.offsetWidth));
15381 * Returns true if the message box is currently displayed
15382 * @return {Boolean} True if the message box is visible, else false
15384 isVisible : function(){
15385 return dlg && dlg.isVisible();
15389 * Hides the message box if it is displayed
15392 if(this.isVisible()){
15398 * Displays a new message box, or reinitializes an existing message box, based on the config options
15399 * passed in. All functions (e.g. prompt, alert, etc) on MessageBox call this function internally.
15400 * The following config object properties are supported:
15402 Property Type Description
15403 ---------- --------------- ------------------------------------------------------------------------------------
15404 animEl String/Element An id or Element from which the message box should animate as it opens and
15405 closes (defaults to undefined)
15406 buttons Object/Boolean A button config object (e.g., Roo.MessageBox.OKCANCEL or {ok:'Foo',
15407 cancel:'Bar'}), or false to not show any buttons (defaults to false)
15408 closable Boolean False to hide the top-right close button (defaults to true). Note that
15409 progress and wait dialogs will ignore this property and always hide the
15410 close button as they can only be closed programmatically.
15411 cls String A custom CSS class to apply to the message box element
15412 defaultTextHeight Number The default height in pixels of the message box's multiline textarea if
15413 displayed (defaults to 75)
15414 fn Function A callback function to execute after closing the dialog. The arguments to the
15415 function will be btn (the name of the button that was clicked, if applicable,
15416 e.g. "ok"), and text (the value of the active text field, if applicable).
15417 Progress and wait dialogs will ignore this option since they do not respond to
15418 user actions and can only be closed programmatically, so any required function
15419 should be called by the same code after it closes the dialog.
15420 icon String A CSS class that provides a background image to be used as an icon for
15421 the dialog (e.g., Roo.MessageBox.WARNING or 'custom-class', defaults to '')
15422 maxWidth Number The maximum width in pixels of the message box (defaults to 600)
15423 minWidth Number The minimum width in pixels of the message box (defaults to 100)
15424 modal Boolean False to allow user interaction with the page while the message box is
15425 displayed (defaults to true)
15426 msg String A string that will replace the existing message box body text (defaults
15427 to the XHTML-compliant non-breaking space character ' ')
15428 multiline Boolean True to prompt the user to enter multi-line text (defaults to false)
15429 progress Boolean True to display a progress bar (defaults to false)
15430 progressText String The text to display inside the progress bar if progress = true (defaults to '')
15431 prompt Boolean True to prompt the user to enter single-line text (defaults to false)
15432 proxyDrag Boolean True to display a lightweight proxy while dragging (defaults to false)
15433 title String The title text
15434 value String The string value to set into the active textbox element if displayed
15435 wait Boolean True to display a progress bar (defaults to false)
15436 width Number The width of the dialog in pixels
15443 msg: 'Please enter your address:',
15445 buttons: Roo.MessageBox.OKCANCEL,
15448 animEl: 'addAddressBtn'
15451 * @param {Object} config Configuration options
15452 * @return {Roo.MessageBox} This message box
15454 show : function(options){
15455 if(this.isVisible()){
15458 var d = this.getDialog();
15460 d.setTitle(opt.title || " ");
15461 d.close.setDisplayed(opt.closable !== false);
15462 activeTextEl = textboxEl;
15463 opt.prompt = opt.prompt || (opt.multiline ? true : false);
15468 textareaEl.setHeight(typeof opt.multiline == "number" ?
15469 opt.multiline : this.defaultTextHeight);
15470 activeTextEl = textareaEl;
15479 progressEl.setDisplayed(opt.progress === true);
15480 this.updateProgress(0);
15481 activeTextEl.dom.value = opt.value || "";
15483 dlg.setDefaultButton(activeTextEl);
15485 var bs = opt.buttons;
15488 db = buttons["ok"];
15489 }else if(bs && bs.yes){
15490 db = buttons["yes"];
15492 dlg.setDefaultButton(db);
15494 bwidth = updateButtons(opt.buttons);
15495 this.updateText(opt.msg);
15497 d.el.addClass(opt.cls);
15499 d.proxyDrag = opt.proxyDrag === true;
15500 d.modal = opt.modal !== false;
15501 d.mask = opt.modal !== false ? mask : false;
15502 if(!d.isVisible()){
15503 // force it to the end of the z-index stack so it gets a cursor in FF
15504 document.body.appendChild(dlg.el.dom);
15505 d.animateTarget = null;
15506 d.show(options.animEl);
15512 * Displays a message box with a progress bar. This message box has no buttons and is not closeable by
15513 * the user. You are responsible for updating the progress bar as needed via {@link Roo.MessageBox#updateProgress}
15514 * and closing the message box when the process is complete.
15515 * @param {String} title The title bar text
15516 * @param {String} msg The message box body text
15517 * @return {Roo.MessageBox} This message box
15519 progress : function(title, msg){
15526 minWidth: this.minProgressWidth,
15533 * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript Window.alert).
15534 * If a callback function is passed it will be called after the user clicks the button, and the
15535 * id of the button that was clicked will be passed as the only parameter to the callback
15536 * (could also be the top-right close button).
15537 * @param {String} title The title bar text
15538 * @param {String} msg The message box body text
15539 * @param {Function} fn (optional) The callback function invoked after the message box is closed
15540 * @param {Object} scope (optional) The scope of the callback function
15541 * @return {Roo.MessageBox} This message box
15543 alert : function(title, msg, fn, scope){
15556 * Displays a message box with an infinitely auto-updating progress bar. This can be used to block user
15557 * interaction while waiting for a long-running process to complete that does not have defined intervals.
15558 * You are responsible for closing the message box when the process is complete.
15559 * @param {String} msg The message box body text
15560 * @param {String} title (optional) The title bar text
15561 * @return {Roo.MessageBox} This message box
15563 wait : function(msg, title){
15574 waitTimer = Roo.TaskMgr.start({
15576 Roo.MessageBox.updateProgress(((((i+20)%20)+1)*5)*.01);
15584 * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's Window.confirm).
15585 * If a callback function is passed it will be called after the user clicks either button, and the id of the
15586 * button that was clicked will be passed as the only parameter to the callback (could also be the top-right close button).
15587 * @param {String} title The title bar text
15588 * @param {String} msg The message box body text
15589 * @param {Function} fn (optional) The callback function invoked after the message box is closed
15590 * @param {Object} scope (optional) The scope of the callback function
15591 * @return {Roo.MessageBox} This message box
15593 confirm : function(title, msg, fn, scope){
15597 buttons: this.YESNO,
15606 * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to
15607 * JavaScript's Window.prompt). The prompt can be a single-line or multi-line textbox. If a callback function
15608 * is passed it will be called after the user clicks either button, and the id of the button that was clicked
15609 * (could also be the top-right close button) and the text that was entered will be passed as the two
15610 * parameters to the callback.
15611 * @param {String} title The title bar text
15612 * @param {String} msg The message box body text
15613 * @param {Function} fn (optional) The callback function invoked after the message box is closed
15614 * @param {Object} scope (optional) The scope of the callback function
15615 * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
15616 * property, or the height in pixels to create the textbox (defaults to false / single-line)
15617 * @return {Roo.MessageBox} This message box
15619 prompt : function(title, msg, fn, scope, multiline){
15623 buttons: this.OKCANCEL,
15628 multiline: multiline,
15635 * Button config that displays a single OK button
15640 * Button config that displays Yes and No buttons
15643 YESNO : {yes:true, no:true},
15645 * Button config that displays OK and Cancel buttons
15648 OKCANCEL : {ok:true, cancel:true},
15650 * Button config that displays Yes, No and Cancel buttons
15653 YESNOCANCEL : {yes:true, no:true, cancel:true},
15656 * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
15659 defaultTextHeight : 75,
15661 * The maximum width in pixels of the message box (defaults to 600)
15666 * The minimum width in pixels of the message box (defaults to 100)
15671 * The minimum width in pixels of the message box if it is a progress-style dialog. This is useful
15672 * for setting a different minimum width than text-only dialogs may need (defaults to 250)
15675 minProgressWidth : 250,
15677 * An object containing the default button text strings that can be overriden for localized language support.
15678 * Supported properties are: ok, cancel, yes and no.
15679 * Customize the default text like so: Roo.MessageBox.buttonText.yes = "S?";
15692 * Shorthand for {@link Roo.MessageBox}
15694 Roo.Msg = Roo.MessageBox;/*
15696 * Ext JS Library 1.1.1
15697 * Copyright(c) 2006-2007, Ext JS, LLC.
15699 * Originally Released Under LGPL - original licence link has changed is not relivant.
15702 * <script type="text/javascript">
15705 * @class Roo.QuickTips
15706 * Provides attractive and customizable tooltips for any element.
15709 Roo.QuickTips = function(){
15710 var el, tipBody, tipBodyText, tipTitle, tm, cfg, close, tagEls = {}, esc, removeCls = null, bdLeft, bdRight;
15711 var ce, bd, xy, dd;
15712 var visible = false, disabled = true, inited = false;
15713 var showProc = 1, hideProc = 1, dismissProc = 1, locks = [];
15715 var onOver = function(e){
15719 var t = e.getTarget();
15720 if(!t || t.nodeType !== 1 || t == document || t == document.body){
15723 if(ce && t == ce.el){
15724 clearTimeout(hideProc);
15727 if(t && tagEls[t.id]){
15728 tagEls[t.id].el = t;
15729 showProc = show.defer(tm.showDelay, tm, [tagEls[t.id]]);
15732 var ttp, et = Roo.fly(t);
15733 var ns = cfg.namespace;
15734 if(tm.interceptTitles && t.title){
15737 t.removeAttribute("title");
15738 e.preventDefault();
15740 ttp = t.qtip || et.getAttributeNS(ns, cfg.attribute);
15743 showProc = show.defer(tm.showDelay, tm, [{
15746 width: et.getAttributeNS(ns, cfg.width),
15747 autoHide: et.getAttributeNS(ns, cfg.hide) != "user",
15748 title: et.getAttributeNS(ns, cfg.title),
15749 cls: et.getAttributeNS(ns, cfg.cls)
15754 var onOut = function(e){
15755 clearTimeout(showProc);
15756 var t = e.getTarget();
15757 if(t && ce && ce.el == t && (tm.autoHide && ce.autoHide !== false)){
15758 hideProc = setTimeout(hide, tm.hideDelay);
15762 var onMove = function(e){
15768 if(tm.trackMouse && ce){
15773 var onDown = function(e){
15774 clearTimeout(showProc);
15775 clearTimeout(hideProc);
15777 if(tm.hideOnClick){
15780 tm.enable.defer(100, tm);
15785 var getPad = function(){
15786 return 2;//bdLeft.getPadding('l')+bdRight.getPadding('r');
15789 var show = function(o){
15793 clearTimeout(dismissProc);
15795 if(removeCls){ // in case manually hidden
15796 el.removeClass(removeCls);
15800 el.addClass(ce.cls);
15801 removeCls = ce.cls;
15804 tipTitle.update(ce.title);
15807 tipTitle.update('');
15810 el.dom.style.width = tm.maxWidth+'px';
15811 //tipBody.dom.style.width = '';
15812 tipBodyText.update(o.text);
15813 var p = getPad(), w = ce.width;
15815 var td = tipBodyText.dom;
15816 var aw = Math.max(td.offsetWidth, td.clientWidth, td.scrollWidth);
15817 if(aw > tm.maxWidth){
15819 }else if(aw < tm.minWidth){
15825 //tipBody.setWidth(w);
15826 el.setWidth(parseInt(w, 10) + p);
15827 if(ce.autoHide === false){
15828 close.setDisplayed(true);
15833 close.setDisplayed(false);
15839 el.avoidY = xy[1]-18;
15844 el.setStyle("visibility", "visible");
15845 el.fadeIn({callback: afterShow});
15851 var afterShow = function(){
15855 if(tm.autoDismiss && ce.autoHide !== false){
15856 dismissProc = setTimeout(hide, tm.autoDismissDelay);
15861 var hide = function(noanim){
15862 clearTimeout(dismissProc);
15863 clearTimeout(hideProc);
15865 if(el.isVisible()){
15867 if(noanim !== true && tm.animate){
15868 el.fadeOut({callback: afterHide});
15875 var afterHide = function(){
15878 el.removeClass(removeCls);
15885 * @cfg {Number} minWidth
15886 * The minimum width of the quick tip (defaults to 40)
15890 * @cfg {Number} maxWidth
15891 * The maximum width of the quick tip (defaults to 300)
15895 * @cfg {Boolean} interceptTitles
15896 * True to automatically use the element's DOM title value if available (defaults to false)
15898 interceptTitles : false,
15900 * @cfg {Boolean} trackMouse
15901 * True to have the quick tip follow the mouse as it moves over the target element (defaults to false)
15903 trackMouse : false,
15905 * @cfg {Boolean} hideOnClick
15906 * True to hide the quick tip if the user clicks anywhere in the document (defaults to true)
15908 hideOnClick : true,
15910 * @cfg {Number} showDelay
15911 * Delay in milliseconds before the quick tip displays after the mouse enters the target element (defaults to 500)
15915 * @cfg {Number} hideDelay
15916 * Delay in milliseconds before the quick tip hides when autoHide = true (defaults to 200)
15920 * @cfg {Boolean} autoHide
15921 * True to automatically hide the quick tip after the mouse exits the target element (defaults to true).
15922 * Used in conjunction with hideDelay.
15927 * True to automatically hide the quick tip after a set period of time, regardless of the user's actions
15928 * (defaults to true). Used in conjunction with autoDismissDelay.
15930 autoDismiss : true,
15933 * Delay in milliseconds before the quick tip hides when autoDismiss = true (defaults to 5000)
15935 autoDismissDelay : 5000,
15937 * @cfg {Boolean} animate
15938 * True to turn on fade animation. Defaults to false (ClearType/scrollbar flicker issues in IE7).
15943 * @cfg {String} title
15944 * Title text to display (defaults to ''). This can be any valid HTML markup.
15948 * @cfg {String} text
15949 * Body text to display (defaults to ''). This can be any valid HTML markup.
15953 * @cfg {String} cls
15954 * A CSS class to apply to the base quick tip element (defaults to '').
15958 * @cfg {Number} width
15959 * Width in pixels of the quick tip (defaults to auto). Width will be ignored if it exceeds the bounds of
15960 * minWidth or maxWidth.
15965 * Initialize and enable QuickTips for first use. This should be called once before the first attempt to access
15966 * or display QuickTips in a page.
15969 tm = Roo.QuickTips;
15970 cfg = tm.tagConfig;
15972 if(!Roo.isReady){ // allow calling of init() before onReady
15973 Roo.onReady(Roo.QuickTips.init, Roo.QuickTips);
15976 el = new Roo.Layer({cls:"x-tip", shadow:"drop", shim: true, constrain:true, shadowOffset:4});
15977 el.fxDefaults = {stopFx: true};
15978 // maximum custom styling
15979 //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>');
15980 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>');
15981 tipTitle = el.child('h3');
15982 tipTitle.enableDisplayMode("block");
15983 tipBody = el.child('div.x-tip-bd');
15984 tipBodyText = el.child('div.x-tip-bd-inner');
15985 //bdLeft = el.child('div.x-tip-bd-left');
15986 //bdRight = el.child('div.x-tip-bd-right');
15987 close = el.child('div.x-tip-close');
15988 close.enableDisplayMode("block");
15989 close.on("click", hide);
15990 var d = Roo.get(document);
15991 d.on("mousedown", onDown);
15992 d.on("mouseover", onOver);
15993 d.on("mouseout", onOut);
15994 d.on("mousemove", onMove);
15995 esc = d.addKeyListener(27, hide);
15998 dd = el.initDD("default", null, {
15999 onDrag : function(){
16003 dd.setHandleElId(tipTitle.id);
16012 * Configures a new quick tip instance and assigns it to a target element. The following config options
16015 Property Type Description
16016 ---------- --------------------- ------------------------------------------------------------------------
16017 target Element/String/Array An Element, id or array of ids that this quick tip should be tied to
16019 * @param {Object} config The config object
16021 register : function(config){
16022 var cs = config instanceof Array ? config : arguments;
16023 for(var i = 0, len = cs.length; i < len; i++) {
16025 var target = c.target;
16027 if(target instanceof Array){
16028 for(var j = 0, jlen = target.length; j < jlen; j++){
16029 tagEls[target[j]] = c;
16032 tagEls[typeof target == 'string' ? target : Roo.id(target)] = c;
16039 * Removes this quick tip from its element and destroys it.
16040 * @param {String/HTMLElement/Element} el The element from which the quick tip is to be removed.
16042 unregister : function(el){
16043 delete tagEls[Roo.id(el)];
16047 * Enable this quick tip.
16049 enable : function(){
16050 if(inited && disabled){
16052 if(locks.length < 1){
16059 * Disable this quick tip.
16061 disable : function(){
16063 clearTimeout(showProc);
16064 clearTimeout(hideProc);
16065 clearTimeout(dismissProc);
16073 * Returns true if the quick tip is enabled, else false.
16075 isEnabled : function(){
16082 attribute : "qtip",
16092 // backwards compat
16093 Roo.QuickTips.tips = Roo.QuickTips.register;/*
16095 * Ext JS Library 1.1.1
16096 * Copyright(c) 2006-2007, Ext JS, LLC.
16098 * Originally Released Under LGPL - original licence link has changed is not relivant.
16101 * <script type="text/javascript">
16106 * @class Roo.tree.TreePanel
16107 * @extends Roo.data.Tree
16109 * @cfg {Boolean} rootVisible false to hide the root node (defaults to true)
16110 * @cfg {Boolean} lines false to disable tree lines (defaults to true)
16111 * @cfg {Boolean} enableDD true to enable drag and drop
16112 * @cfg {Boolean} enableDrag true to enable just drag
16113 * @cfg {Boolean} enableDrop true to enable just drop
16114 * @cfg {Object} dragConfig Custom config to pass to the {@link Roo.tree.TreeDragZone} instance
16115 * @cfg {Object} dropConfig Custom config to pass to the {@link Roo.tree.TreeDropZone} instance
16116 * @cfg {String} ddGroup The DD group this TreePanel belongs to
16117 * @cfg {String} ddAppendOnly True if the tree should only allow append drops (use for trees which are sorted)
16118 * @cfg {Boolean} ddScroll true to enable YUI body scrolling
16119 * @cfg {Boolean} containerScroll true to register this container with ScrollManager
16120 * @cfg {Boolean} hlDrop false to disable node highlight on drop (defaults to the value of Roo.enableFx)
16121 * @cfg {String} hlColor The color of the node highlight (defaults to C3DAF9)
16122 * @cfg {Boolean} animate true to enable animated expand/collapse (defaults to the value of Roo.enableFx)
16123 * @cfg {Boolean} singleExpand true if only 1 node per branch may be expanded
16124 * @cfg {Boolean} selModel A tree selection model to use with this TreePanel (defaults to a {@link Roo.tree.DefaultSelectionModel})
16125 * @cfg {Boolean} loader A TreeLoader for use with this TreePanel
16126 * @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to '/')
16127 * @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>
16128 * @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>
16131 * @param {String/HTMLElement/Element} el The container element
16132 * @param {Object} config
16134 Roo.tree.TreePanel = function(el, config){
16136 var loader = false;
16138 root = config.root;
16139 delete config.root;
16141 if (config.loader) {
16142 loader = config.loader;
16143 delete config.loader;
16146 Roo.apply(this, config);
16147 Roo.tree.TreePanel.superclass.constructor.call(this);
16148 this.el = Roo.get(el);
16149 this.el.addClass('x-tree');
16150 //console.log(root);
16152 this.setRootNode( Roo.factory(root, Roo.tree));
16155 this.loader = Roo.factory(loader, Roo.tree);
16158 * Read-only. The id of the container element becomes this TreePanel's id.
16160 this.id = this.el.id;
16163 * @event beforeload
16164 * Fires before a node is loaded, return false to cancel
16165 * @param {Node} node The node being loaded
16167 "beforeload" : true,
16170 * Fires when a node is loaded
16171 * @param {Node} node The node that was loaded
16175 * @event textchange
16176 * Fires when the text for a node is changed
16177 * @param {Node} node The node
16178 * @param {String} text The new text
16179 * @param {String} oldText The old text
16181 "textchange" : true,
16183 * @event beforeexpand
16184 * Fires before a node is expanded, return false to cancel.
16185 * @param {Node} node The node
16186 * @param {Boolean} deep
16187 * @param {Boolean} anim
16189 "beforeexpand" : true,
16191 * @event beforecollapse
16192 * Fires before a node is collapsed, return false to cancel.
16193 * @param {Node} node The node
16194 * @param {Boolean} deep
16195 * @param {Boolean} anim
16197 "beforecollapse" : true,
16200 * Fires when a node is expanded
16201 * @param {Node} node The node
16205 * @event disabledchange
16206 * Fires when the disabled status of a node changes
16207 * @param {Node} node The node
16208 * @param {Boolean} disabled
16210 "disabledchange" : true,
16213 * Fires when a node is collapsed
16214 * @param {Node} node The node
16218 * @event beforeclick
16219 * Fires before click processing on a node. Return false to cancel the default action.
16220 * @param {Node} node The node
16221 * @param {Roo.EventObject} e The event object
16223 "beforeclick":true,
16225 * @event checkchange
16226 * Fires when a node with a checkbox's checked property changes
16227 * @param {Node} this This node
16228 * @param {Boolean} checked
16230 "checkchange":true,
16233 * Fires when a node is clicked
16234 * @param {Node} node The node
16235 * @param {Roo.EventObject} e The event object
16240 * Fires when a node is double clicked
16241 * @param {Node} node The node
16242 * @param {Roo.EventObject} e The event object
16246 * @event contextmenu
16247 * Fires when a node is right clicked
16248 * @param {Node} node The node
16249 * @param {Roo.EventObject} e The event object
16251 "contextmenu":true,
16253 * @event beforechildrenrendered
16254 * Fires right before the child nodes for a node are rendered
16255 * @param {Node} node The node
16257 "beforechildrenrendered":true,
16260 * Fires when a node starts being dragged
16261 * @param {Roo.tree.TreePanel} this
16262 * @param {Roo.tree.TreeNode} node
16263 * @param {event} e The raw browser event
16265 "startdrag" : true,
16268 * Fires when a drag operation is complete
16269 * @param {Roo.tree.TreePanel} this
16270 * @param {Roo.tree.TreeNode} node
16271 * @param {event} e The raw browser event
16276 * Fires when a dragged node is dropped on a valid DD target
16277 * @param {Roo.tree.TreePanel} this
16278 * @param {Roo.tree.TreeNode} node
16279 * @param {DD} dd The dd it was dropped on
16280 * @param {event} e The raw browser event
16284 * @event beforenodedrop
16285 * Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
16286 * passed to handlers has the following properties:<br />
16287 * <ul style="padding:5px;padding-left:16px;">
16288 * <li>tree - The TreePanel</li>
16289 * <li>target - The node being targeted for the drop</li>
16290 * <li>data - The drag data from the drag source</li>
16291 * <li>point - The point of the drop - append, above or below</li>
16292 * <li>source - The drag source</li>
16293 * <li>rawEvent - Raw mouse event</li>
16294 * <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
16295 * to be inserted by setting them on this object.</li>
16296 * <li>cancel - Set this to true to cancel the drop.</li>
16298 * @param {Object} dropEvent
16300 "beforenodedrop" : true,
16303 * Fires after a DD object is dropped on a node in this tree. The dropEvent
16304 * passed to handlers has the following properties:<br />
16305 * <ul style="padding:5px;padding-left:16px;">
16306 * <li>tree - The TreePanel</li>
16307 * <li>target - The node being targeted for the drop</li>
16308 * <li>data - The drag data from the drag source</li>
16309 * <li>point - The point of the drop - append, above or below</li>
16310 * <li>source - The drag source</li>
16311 * <li>rawEvent - Raw mouse event</li>
16312 * <li>dropNode - Dropped node(s).</li>
16314 * @param {Object} dropEvent
16318 * @event nodedragover
16319 * Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
16320 * passed to handlers has the following properties:<br />
16321 * <ul style="padding:5px;padding-left:16px;">
16322 * <li>tree - The TreePanel</li>
16323 * <li>target - The node being targeted for the drop</li>
16324 * <li>data - The drag data from the drag source</li>
16325 * <li>point - The point of the drop - append, above or below</li>
16326 * <li>source - The drag source</li>
16327 * <li>rawEvent - Raw mouse event</li>
16328 * <li>dropNode - Drop node(s) provided by the source.</li>
16329 * <li>cancel - Set this to true to signal drop not allowed.</li>
16331 * @param {Object} dragOverEvent
16333 "nodedragover" : true
16336 if(this.singleExpand){
16337 this.on("beforeexpand", this.restrictExpand, this);
16340 Roo.extend(Roo.tree.TreePanel, Roo.data.Tree, {
16341 rootVisible : true,
16342 animate: Roo.enableFx,
16345 hlDrop : Roo.enableFx,
16349 rendererTip: false,
16351 restrictExpand : function(node){
16352 var p = node.parentNode;
16354 if(p.expandedChild && p.expandedChild.parentNode == p){
16355 p.expandedChild.collapse();
16357 p.expandedChild = node;
16361 // private override
16362 setRootNode : function(node){
16363 Roo.tree.TreePanel.superclass.setRootNode.call(this, node);
16364 if(!this.rootVisible){
16365 node.ui = new Roo.tree.RootTreeNodeUI(node);
16371 * Returns the container element for this TreePanel
16373 getEl : function(){
16378 * Returns the default TreeLoader for this TreePanel
16380 getLoader : function(){
16381 return this.loader;
16387 expandAll : function(){
16388 this.root.expand(true);
16392 * Collapse all nodes
16394 collapseAll : function(){
16395 this.root.collapse(true);
16399 * Returns the selection model used by this TreePanel
16401 getSelectionModel : function(){
16402 if(!this.selModel){
16403 this.selModel = new Roo.tree.DefaultSelectionModel();
16405 return this.selModel;
16409 * Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
16410 * @param {String} attribute (optional) Defaults to null (return the actual nodes)
16411 * @param {TreeNode} startNode (optional) The node to start from, defaults to the root
16414 getChecked : function(a, startNode){
16415 startNode = startNode || this.root;
16417 var f = function(){
16418 if(this.attributes.checked){
16419 r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
16422 startNode.cascade(f);
16427 * Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
16428 * @param {String} path
16429 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
16430 * @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
16431 * (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
16433 expandPath : function(path, attr, callback){
16434 attr = attr || "id";
16435 var keys = path.split(this.pathSeparator);
16436 var curNode = this.root;
16437 if(curNode.attributes[attr] != keys[1]){ // invalid root
16439 callback(false, null);
16444 var f = function(){
16445 if(++index == keys.length){
16447 callback(true, curNode);
16451 var c = curNode.findChild(attr, keys[index]);
16454 callback(false, curNode);
16459 c.expand(false, false, f);
16461 curNode.expand(false, false, f);
16465 * Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Roo.data.Node#getPath}
16466 * @param {String} path
16467 * @param {String} attr (optional) The attribute used in the path (see {@link Roo.data.Node#getPath} for more info)
16468 * @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
16469 * (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
16471 selectPath : function(path, attr, callback){
16472 attr = attr || "id";
16473 var keys = path.split(this.pathSeparator);
16474 var v = keys.pop();
16475 if(keys.length > 0){
16476 var f = function(success, node){
16477 if(success && node){
16478 var n = node.findChild(attr, v);
16484 }else if(callback){
16485 callback(false, n);
16489 callback(false, n);
16493 this.expandPath(keys.join(this.pathSeparator), attr, f);
16495 this.root.select();
16497 callback(true, this.root);
16502 getTreeEl : function(){
16507 * Trigger rendering of this TreePanel
16509 render : function(){
16510 if (this.innerCt) {
16511 return this; // stop it rendering more than once!!
16514 this.innerCt = this.el.createChild({tag:"ul",
16515 cls:"x-tree-root-ct " +
16516 (this.lines ? "x-tree-lines" : "x-tree-no-lines")});
16518 if(this.containerScroll){
16519 Roo.dd.ScrollManager.register(this.el);
16521 if((this.enableDD || this.enableDrop) && !this.dropZone){
16523 * The dropZone used by this tree if drop is enabled
16524 * @type Roo.tree.TreeDropZone
16526 this.dropZone = new Roo.tree.TreeDropZone(this, this.dropConfig || {
16527 ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
16530 if((this.enableDD || this.enableDrag) && !this.dragZone){
16532 * The dragZone used by this tree if drag is enabled
16533 * @type Roo.tree.TreeDragZone
16535 this.dragZone = new Roo.tree.TreeDragZone(this, this.dragConfig || {
16536 ddGroup: this.ddGroup || "TreeDD",
16537 scroll: this.ddScroll
16540 this.getSelectionModel().init(this);
16542 console.log("ROOT not set in tree");
16545 this.root.render();
16546 if(!this.rootVisible){
16547 this.root.renderChildren();
16553 * Ext JS Library 1.1.1
16554 * Copyright(c) 2006-2007, Ext JS, LLC.
16556 * Originally Released Under LGPL - original licence link has changed is not relivant.
16559 * <script type="text/javascript">
16564 * @class Roo.tree.DefaultSelectionModel
16565 * @extends Roo.util.Observable
16566 * The default single selection for a TreePanel.
16568 Roo.tree.DefaultSelectionModel = function(){
16569 this.selNode = null;
16573 * @event selectionchange
16574 * Fires when the selected node changes
16575 * @param {DefaultSelectionModel} this
16576 * @param {TreeNode} node the new selection
16578 "selectionchange" : true,
16581 * @event beforeselect
16582 * Fires before the selected node changes, return false to cancel the change
16583 * @param {DefaultSelectionModel} this
16584 * @param {TreeNode} node the new selection
16585 * @param {TreeNode} node the old selection
16587 "beforeselect" : true
16591 Roo.extend(Roo.tree.DefaultSelectionModel, Roo.util.Observable, {
16592 init : function(tree){
16594 tree.getTreeEl().on("keydown", this.onKeyDown, this);
16595 tree.on("click", this.onNodeClick, this);
16598 onNodeClick : function(node, e){
16599 if (e.ctrlKey && this.selNode == node) {
16600 this.unselect(node);
16608 * @param {TreeNode} node The node to select
16609 * @return {TreeNode} The selected node
16611 select : function(node){
16612 var last = this.selNode;
16613 if(last != node && this.fireEvent('beforeselect', this, node, last) !== false){
16615 last.ui.onSelectedChange(false);
16617 this.selNode = node;
16618 node.ui.onSelectedChange(true);
16619 this.fireEvent("selectionchange", this, node, last);
16626 * @param {TreeNode} node The node to unselect
16628 unselect : function(node){
16629 if(this.selNode == node){
16630 this.clearSelections();
16635 * Clear all selections
16637 clearSelections : function(){
16638 var n = this.selNode;
16640 n.ui.onSelectedChange(false);
16641 this.selNode = null;
16642 this.fireEvent("selectionchange", this, null);
16648 * Get the selected node
16649 * @return {TreeNode} The selected node
16651 getSelectedNode : function(){
16652 return this.selNode;
16656 * Returns true if the node is selected
16657 * @param {TreeNode} node The node to check
16658 * @return {Boolean}
16660 isSelected : function(node){
16661 return this.selNode == node;
16665 * Selects the node above the selected node in the tree, intelligently walking the nodes
16666 * @return TreeNode The new selection
16668 selectPrevious : function(){
16669 var s = this.selNode || this.lastSelNode;
16673 var ps = s.previousSibling;
16675 if(!ps.isExpanded() || ps.childNodes.length < 1){
16676 return this.select(ps);
16678 var lc = ps.lastChild;
16679 while(lc && lc.isExpanded() && lc.childNodes.length > 0){
16682 return this.select(lc);
16684 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
16685 return this.select(s.parentNode);
16691 * Selects the node above the selected node in the tree, intelligently walking the nodes
16692 * @return TreeNode The new selection
16694 selectNext : function(){
16695 var s = this.selNode || this.lastSelNode;
16699 if(s.firstChild && s.isExpanded()){
16700 return this.select(s.firstChild);
16701 }else if(s.nextSibling){
16702 return this.select(s.nextSibling);
16703 }else if(s.parentNode){
16705 s.parentNode.bubble(function(){
16706 if(this.nextSibling){
16707 newS = this.getOwnerTree().selModel.select(this.nextSibling);
16716 onKeyDown : function(e){
16717 var s = this.selNode || this.lastSelNode;
16718 // undesirable, but required
16723 var k = e.getKey();
16731 this.selectPrevious();
16734 e.preventDefault();
16735 if(s.hasChildNodes()){
16736 if(!s.isExpanded()){
16738 }else if(s.firstChild){
16739 this.select(s.firstChild, e);
16744 e.preventDefault();
16745 if(s.hasChildNodes() && s.isExpanded()){
16747 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
16748 this.select(s.parentNode, e);
16756 * @class Roo.tree.MultiSelectionModel
16757 * @extends Roo.util.Observable
16758 * Multi selection for a TreePanel.
16760 Roo.tree.MultiSelectionModel = function(){
16761 this.selNodes = [];
16765 * @event selectionchange
16766 * Fires when the selected nodes change
16767 * @param {MultiSelectionModel} this
16768 * @param {Array} nodes Array of the selected nodes
16770 "selectionchange" : true
16774 Roo.extend(Roo.tree.MultiSelectionModel, Roo.util.Observable, {
16775 init : function(tree){
16777 tree.getTreeEl().on("keydown", this.onKeyDown, this);
16778 tree.on("click", this.onNodeClick, this);
16781 onNodeClick : function(node, e){
16782 this.select(node, e, e.ctrlKey);
16787 * @param {TreeNode} node The node to select
16788 * @param {EventObject} e (optional) An event associated with the selection
16789 * @param {Boolean} keepExisting True to retain existing selections
16790 * @return {TreeNode} The selected node
16792 select : function(node, e, keepExisting){
16793 if(keepExisting !== true){
16794 this.clearSelections(true);
16796 if(this.isSelected(node)){
16797 this.lastSelNode = node;
16800 this.selNodes.push(node);
16801 this.selMap[node.id] = node;
16802 this.lastSelNode = node;
16803 node.ui.onSelectedChange(true);
16804 this.fireEvent("selectionchange", this, this.selNodes);
16810 * @param {TreeNode} node The node to unselect
16812 unselect : function(node){
16813 if(this.selMap[node.id]){
16814 node.ui.onSelectedChange(false);
16815 var sn = this.selNodes;
16818 index = sn.indexOf(node);
16820 for(var i = 0, len = sn.length; i < len; i++){
16828 this.selNodes.splice(index, 1);
16830 delete this.selMap[node.id];
16831 this.fireEvent("selectionchange", this, this.selNodes);
16836 * Clear all selections
16838 clearSelections : function(suppressEvent){
16839 var sn = this.selNodes;
16841 for(var i = 0, len = sn.length; i < len; i++){
16842 sn[i].ui.onSelectedChange(false);
16844 this.selNodes = [];
16846 if(suppressEvent !== true){
16847 this.fireEvent("selectionchange", this, this.selNodes);
16853 * Returns true if the node is selected
16854 * @param {TreeNode} node The node to check
16855 * @return {Boolean}
16857 isSelected : function(node){
16858 return this.selMap[node.id] ? true : false;
16862 * Returns an array of the selected nodes
16865 getSelectedNodes : function(){
16866 return this.selNodes;
16869 onKeyDown : Roo.tree.DefaultSelectionModel.prototype.onKeyDown,
16871 selectNext : Roo.tree.DefaultSelectionModel.prototype.selectNext,
16873 selectPrevious : Roo.tree.DefaultSelectionModel.prototype.selectPrevious
16876 * Ext JS Library 1.1.1
16877 * Copyright(c) 2006-2007, Ext JS, LLC.
16879 * Originally Released Under LGPL - original licence link has changed is not relivant.
16882 * <script type="text/javascript">
16886 * @class Roo.tree.TreeNode
16887 * @extends Roo.data.Node
16888 * @cfg {String} text The text for this node
16889 * @cfg {Boolean} expanded true to start the node expanded
16890 * @cfg {Boolean} allowDrag false to make this node undraggable if DD is on (defaults to true)
16891 * @cfg {Boolean} allowDrop false if this node cannot be drop on
16892 * @cfg {Boolean} disabled true to start the node disabled
16893 * @cfg {String} icon The path to an icon for the node. The preferred way to do this
16894 * is to use the cls or iconCls attributes and add the icon via a CSS background image.
16895 * @cfg {String} cls A css class to be added to the node
16896 * @cfg {String} iconCls A css class to be added to the nodes icon element for applying css background images
16897 * @cfg {String} href URL of the link used for the node (defaults to #)
16898 * @cfg {String} hrefTarget target frame for the link
16899 * @cfg {String} qtip An Ext QuickTip for the node
16900 * @cfg {String} qtipCfg An Ext QuickTip config for the node (used instead of qtip)
16901 * @cfg {Boolean} singleClickExpand True for single click expand on this node
16902 * @cfg {Function} uiProvider A UI <b>class</b> to use for this node (defaults to Roo.tree.TreeNodeUI)
16903 * @cfg {Boolean} checked True to render a checked checkbox for this node, false to render an unchecked checkbox
16904 * (defaults to undefined with no checkbox rendered)
16906 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
16908 Roo.tree.TreeNode = function(attributes){
16909 attributes = attributes || {};
16910 if(typeof attributes == "string"){
16911 attributes = {text: attributes};
16913 this.childrenRendered = false;
16914 this.rendered = false;
16915 Roo.tree.TreeNode.superclass.constructor.call(this, attributes);
16916 this.expanded = attributes.expanded === true;
16917 this.isTarget = attributes.isTarget !== false;
16918 this.draggable = attributes.draggable !== false && attributes.allowDrag !== false;
16919 this.allowChildren = attributes.allowChildren !== false && attributes.allowDrop !== false;
16922 * Read-only. The text for this node. To change it use setText().
16925 this.text = attributes.text;
16927 * True if this node is disabled.
16930 this.disabled = attributes.disabled === true;
16934 * @event textchange
16935 * Fires when the text for this node is changed
16936 * @param {Node} this This node
16937 * @param {String} text The new text
16938 * @param {String} oldText The old text
16940 "textchange" : true,
16942 * @event beforeexpand
16943 * Fires before this node is expanded, return false to cancel.
16944 * @param {Node} this This node
16945 * @param {Boolean} deep
16946 * @param {Boolean} anim
16948 "beforeexpand" : true,
16950 * @event beforecollapse
16951 * Fires before this node is collapsed, return false to cancel.
16952 * @param {Node} this This node
16953 * @param {Boolean} deep
16954 * @param {Boolean} anim
16956 "beforecollapse" : true,
16959 * Fires when this node is expanded
16960 * @param {Node} this This node
16964 * @event disabledchange
16965 * Fires when the disabled status of this node changes
16966 * @param {Node} this This node
16967 * @param {Boolean} disabled
16969 "disabledchange" : true,
16972 * Fires when this node is collapsed
16973 * @param {Node} this This node
16977 * @event beforeclick
16978 * Fires before click processing. Return false to cancel the default action.
16979 * @param {Node} this This node
16980 * @param {Roo.EventObject} e The event object
16982 "beforeclick":true,
16984 * @event checkchange
16985 * Fires when a node with a checkbox's checked property changes
16986 * @param {Node} this This node
16987 * @param {Boolean} checked
16989 "checkchange":true,
16992 * Fires when this node is clicked
16993 * @param {Node} this This node
16994 * @param {Roo.EventObject} e The event object
16999 * Fires when this node is double clicked
17000 * @param {Node} this This node
17001 * @param {Roo.EventObject} e The event object
17005 * @event contextmenu
17006 * Fires when this node is right clicked
17007 * @param {Node} this This node
17008 * @param {Roo.EventObject} e The event object
17010 "contextmenu":true,
17012 * @event beforechildrenrendered
17013 * Fires right before the child nodes for this node are rendered
17014 * @param {Node} this This node
17016 "beforechildrenrendered":true
17019 var uiClass = this.attributes.uiProvider || Roo.tree.TreeNodeUI;
17022 * Read-only. The UI for this node
17025 this.ui = new uiClass(this);
17027 Roo.extend(Roo.tree.TreeNode, Roo.data.Node, {
17028 preventHScroll: true,
17030 * Returns true if this node is expanded
17031 * @return {Boolean}
17033 isExpanded : function(){
17034 return this.expanded;
17038 * Returns the UI object for this node
17039 * @return {TreeNodeUI}
17041 getUI : function(){
17045 // private override
17046 setFirstChild : function(node){
17047 var of = this.firstChild;
17048 Roo.tree.TreeNode.superclass.setFirstChild.call(this, node);
17049 if(this.childrenRendered && of && node != of){
17050 of.renderIndent(true, true);
17053 this.renderIndent(true, true);
17057 // private override
17058 setLastChild : function(node){
17059 var ol = this.lastChild;
17060 Roo.tree.TreeNode.superclass.setLastChild.call(this, node);
17061 if(this.childrenRendered && ol && node != ol){
17062 ol.renderIndent(true, true);
17065 this.renderIndent(true, true);
17069 // these methods are overridden to provide lazy rendering support
17070 // private override
17071 appendChild : function(){
17072 var node = Roo.tree.TreeNode.superclass.appendChild.apply(this, arguments);
17073 if(node && this.childrenRendered){
17076 this.ui.updateExpandIcon();
17080 // private override
17081 removeChild : function(node){
17082 this.ownerTree.getSelectionModel().unselect(node);
17083 Roo.tree.TreeNode.superclass.removeChild.apply(this, arguments);
17084 // if it's been rendered remove dom node
17085 if(this.childrenRendered){
17088 if(this.childNodes.length < 1){
17089 this.collapse(false, false);
17091 this.ui.updateExpandIcon();
17093 if(!this.firstChild) {
17094 this.childrenRendered = false;
17099 // private override
17100 insertBefore : function(node, refNode){
17101 var newNode = Roo.tree.TreeNode.superclass.insertBefore.apply(this, arguments);
17102 if(newNode && refNode && this.childrenRendered){
17105 this.ui.updateExpandIcon();
17110 * Sets the text for this node
17111 * @param {String} text
17113 setText : function(text){
17114 var oldText = this.text;
17116 this.attributes.text = text;
17117 if(this.rendered){ // event without subscribing
17118 this.ui.onTextChange(this, text, oldText);
17120 this.fireEvent("textchange", this, text, oldText);
17124 * Triggers selection of this node
17126 select : function(){
17127 this.getOwnerTree().getSelectionModel().select(this);
17131 * Triggers deselection of this node
17133 unselect : function(){
17134 this.getOwnerTree().getSelectionModel().unselect(this);
17138 * Returns true if this node is selected
17139 * @return {Boolean}
17141 isSelected : function(){
17142 return this.getOwnerTree().getSelectionModel().isSelected(this);
17146 * Expand this node.
17147 * @param {Boolean} deep (optional) True to expand all children as well
17148 * @param {Boolean} anim (optional) false to cancel the default animation
17149 * @param {Function} callback (optional) A callback to be called when
17150 * expanding this node completes (does not wait for deep expand to complete).
17151 * Called with 1 parameter, this node.
17153 expand : function(deep, anim, callback){
17154 if(!this.expanded){
17155 if(this.fireEvent("beforeexpand", this, deep, anim) === false){
17158 if(!this.childrenRendered){
17159 this.renderChildren();
17161 this.expanded = true;
17162 if(!this.isHiddenRoot() && (this.getOwnerTree().animate && anim !== false) || anim){
17163 this.ui.animExpand(function(){
17164 this.fireEvent("expand", this);
17165 if(typeof callback == "function"){
17169 this.expandChildNodes(true);
17171 }.createDelegate(this));
17175 this.fireEvent("expand", this);
17176 if(typeof callback == "function"){
17181 if(typeof callback == "function"){
17186 this.expandChildNodes(true);
17190 isHiddenRoot : function(){
17191 return this.isRoot && !this.getOwnerTree().rootVisible;
17195 * Collapse this node.
17196 * @param {Boolean} deep (optional) True to collapse all children as well
17197 * @param {Boolean} anim (optional) false to cancel the default animation
17199 collapse : function(deep, anim){
17200 if(this.expanded && !this.isHiddenRoot()){
17201 if(this.fireEvent("beforecollapse", this, deep, anim) === false){
17204 this.expanded = false;
17205 if((this.getOwnerTree().animate && anim !== false) || anim){
17206 this.ui.animCollapse(function(){
17207 this.fireEvent("collapse", this);
17209 this.collapseChildNodes(true);
17211 }.createDelegate(this));
17214 this.ui.collapse();
17215 this.fireEvent("collapse", this);
17219 var cs = this.childNodes;
17220 for(var i = 0, len = cs.length; i < len; i++) {
17221 cs[i].collapse(true, false);
17227 delayedExpand : function(delay){
17228 if(!this.expandProcId){
17229 this.expandProcId = this.expand.defer(delay, this);
17234 cancelExpand : function(){
17235 if(this.expandProcId){
17236 clearTimeout(this.expandProcId);
17238 this.expandProcId = false;
17242 * Toggles expanded/collapsed state of the node
17244 toggle : function(){
17253 * Ensures all parent nodes are expanded
17255 ensureVisible : function(callback){
17256 var tree = this.getOwnerTree();
17257 tree.expandPath(this.parentNode.getPath(), false, function(){
17258 tree.getTreeEl().scrollChildIntoView(this.ui.anchor);
17259 Roo.callback(callback);
17260 }.createDelegate(this));
17264 * Expand all child nodes
17265 * @param {Boolean} deep (optional) true if the child nodes should also expand their child nodes
17267 expandChildNodes : function(deep){
17268 var cs = this.childNodes;
17269 for(var i = 0, len = cs.length; i < len; i++) {
17270 cs[i].expand(deep);
17275 * Collapse all child nodes
17276 * @param {Boolean} deep (optional) true if the child nodes should also collapse their child nodes
17278 collapseChildNodes : function(deep){
17279 var cs = this.childNodes;
17280 for(var i = 0, len = cs.length; i < len; i++) {
17281 cs[i].collapse(deep);
17286 * Disables this node
17288 disable : function(){
17289 this.disabled = true;
17291 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
17292 this.ui.onDisableChange(this, true);
17294 this.fireEvent("disabledchange", this, true);
17298 * Enables this node
17300 enable : function(){
17301 this.disabled = false;
17302 if(this.rendered && this.ui.onDisableChange){ // event without subscribing
17303 this.ui.onDisableChange(this, false);
17305 this.fireEvent("disabledchange", this, false);
17309 renderChildren : function(suppressEvent){
17310 if(suppressEvent !== false){
17311 this.fireEvent("beforechildrenrendered", this);
17313 var cs = this.childNodes;
17314 for(var i = 0, len = cs.length; i < len; i++){
17315 cs[i].render(true);
17317 this.childrenRendered = true;
17321 sort : function(fn, scope){
17322 Roo.tree.TreeNode.superclass.sort.apply(this, arguments);
17323 if(this.childrenRendered){
17324 var cs = this.childNodes;
17325 for(var i = 0, len = cs.length; i < len; i++){
17326 cs[i].render(true);
17332 render : function(bulkRender){
17333 this.ui.render(bulkRender);
17334 if(!this.rendered){
17335 this.rendered = true;
17337 this.expanded = false;
17338 this.expand(false, false);
17344 renderIndent : function(deep, refresh){
17346 this.ui.childIndent = null;
17348 this.ui.renderIndent();
17349 if(deep === true && this.childrenRendered){
17350 var cs = this.childNodes;
17351 for(var i = 0, len = cs.length; i < len; i++){
17352 cs[i].renderIndent(true, refresh);
17358 * Ext JS Library 1.1.1
17359 * Copyright(c) 2006-2007, Ext JS, LLC.
17361 * Originally Released Under LGPL - original licence link has changed is not relivant.
17364 * <script type="text/javascript">
17368 * @class Roo.tree.AsyncTreeNode
17369 * @extends Roo.tree.TreeNode
17370 * @cfg {TreeLoader} loader A TreeLoader to be used by this node (defaults to the loader defined on the tree)
17372 * @param {Object/String} attributes The attributes/config for the node or just a string with the text for the node
17374 Roo.tree.AsyncTreeNode = function(config){
17375 this.loaded = false;
17376 this.loading = false;
17377 Roo.tree.AsyncTreeNode.superclass.constructor.apply(this, arguments);
17379 * @event beforeload
17380 * Fires before this node is loaded, return false to cancel
17381 * @param {Node} this This node
17383 this.addEvents({'beforeload':true, 'load': true});
17386 * Fires when this node is loaded
17387 * @param {Node} this This node
17390 * The loader used by this node (defaults to using the tree's defined loader)
17395 Roo.extend(Roo.tree.AsyncTreeNode, Roo.tree.TreeNode, {
17396 expand : function(deep, anim, callback){
17397 if(this.loading){ // if an async load is already running, waiting til it's done
17399 var f = function(){
17400 if(!this.loading){ // done loading
17401 clearInterval(timer);
17402 this.expand(deep, anim, callback);
17404 }.createDelegate(this);
17405 timer = setInterval(f, 200);
17409 if(this.fireEvent("beforeload", this) === false){
17412 this.loading = true;
17413 this.ui.beforeLoad(this);
17414 var loader = this.loader || this.attributes.loader || this.getOwnerTree().getLoader();
17416 loader.load(this, this.loadComplete.createDelegate(this, [deep, anim, callback]));
17420 Roo.tree.AsyncTreeNode.superclass.expand.call(this, deep, anim, callback);
17424 * Returns true if this node is currently loading
17425 * @return {Boolean}
17427 isLoading : function(){
17428 return this.loading;
17431 loadComplete : function(deep, anim, callback){
17432 this.loading = false;
17433 this.loaded = true;
17434 this.ui.afterLoad(this);
17435 this.fireEvent("load", this);
17436 this.expand(deep, anim, callback);
17440 * Returns true if this node has been loaded
17441 * @return {Boolean}
17443 isLoaded : function(){
17444 return this.loaded;
17447 hasChildNodes : function(){
17448 if(!this.isLeaf() && !this.loaded){
17451 return Roo.tree.AsyncTreeNode.superclass.hasChildNodes.call(this);
17456 * Trigger a reload for this node
17457 * @param {Function} callback
17459 reload : function(callback){
17460 this.collapse(false, false);
17461 while(this.firstChild){
17462 this.removeChild(this.firstChild);
17464 this.childrenRendered = false;
17465 this.loaded = false;
17466 if(this.isHiddenRoot()){
17467 this.expanded = false;
17469 this.expand(false, false, callback);
17473 * Ext JS Library 1.1.1
17474 * Copyright(c) 2006-2007, Ext JS, LLC.
17476 * Originally Released Under LGPL - original licence link has changed is not relivant.
17479 * <script type="text/javascript">
17483 * @class Roo.tree.TreeNodeUI
17485 * @param {Object} node The node to render
17486 * The TreeNode UI implementation is separate from the
17487 * tree implementation. Unless you are customizing the tree UI,
17488 * you should never have to use this directly.
17490 Roo.tree.TreeNodeUI = function(node){
17492 this.rendered = false;
17493 this.animating = false;
17494 this.emptyIcon = Roo.BLANK_IMAGE_URL;
17497 Roo.tree.TreeNodeUI.prototype = {
17498 removeChild : function(node){
17500 this.ctNode.removeChild(node.ui.getEl());
17504 beforeLoad : function(){
17505 this.addClass("x-tree-node-loading");
17508 afterLoad : function(){
17509 this.removeClass("x-tree-node-loading");
17512 onTextChange : function(node, text, oldText){
17514 this.textNode.innerHTML = text;
17518 onDisableChange : function(node, state){
17519 this.disabled = state;
17521 this.addClass("x-tree-node-disabled");
17523 this.removeClass("x-tree-node-disabled");
17527 onSelectedChange : function(state){
17530 this.addClass("x-tree-selected");
17533 this.removeClass("x-tree-selected");
17537 onMove : function(tree, node, oldParent, newParent, index, refNode){
17538 this.childIndent = null;
17540 var targetNode = newParent.ui.getContainer();
17541 if(!targetNode){//target not rendered
17542 this.holder = document.createElement("div");
17543 this.holder.appendChild(this.wrap);
17546 var insertBefore = refNode ? refNode.ui.getEl() : null;
17548 targetNode.insertBefore(this.wrap, insertBefore);
17550 targetNode.appendChild(this.wrap);
17552 this.node.renderIndent(true);
17556 addClass : function(cls){
17558 Roo.fly(this.elNode).addClass(cls);
17562 removeClass : function(cls){
17564 Roo.fly(this.elNode).removeClass(cls);
17568 remove : function(){
17570 this.holder = document.createElement("div");
17571 this.holder.appendChild(this.wrap);
17575 fireEvent : function(){
17576 return this.node.fireEvent.apply(this.node, arguments);
17579 initEvents : function(){
17580 this.node.on("move", this.onMove, this);
17581 var E = Roo.EventManager;
17582 var a = this.anchor;
17584 var el = Roo.fly(a, '_treeui');
17586 if(Roo.isOpera){ // opera render bug ignores the CSS
17587 el.setStyle("text-decoration", "none");
17590 el.on("click", this.onClick, this);
17591 el.on("dblclick", this.onDblClick, this);
17594 Roo.EventManager.on(this.checkbox,
17595 Roo.isIE ? 'click' : 'change', this.onCheckChange, this);
17598 el.on("contextmenu", this.onContextMenu, this);
17600 var icon = Roo.fly(this.iconNode);
17601 icon.on("click", this.onClick, this);
17602 icon.on("dblclick", this.onDblClick, this);
17603 icon.on("contextmenu", this.onContextMenu, this);
17604 E.on(this.ecNode, "click", this.ecClick, this, true);
17606 if(this.node.disabled){
17607 this.addClass("x-tree-node-disabled");
17609 if(this.node.hidden){
17610 this.addClass("x-tree-node-disabled");
17612 var ot = this.node.getOwnerTree();
17613 var dd = ot.enableDD || ot.enableDrag || ot.enableDrop;
17614 if(dd && (!this.node.isRoot || ot.rootVisible)){
17615 Roo.dd.Registry.register(this.elNode, {
17617 handles: this.getDDHandles(),
17623 getDDHandles : function(){
17624 return [this.iconNode, this.textNode];
17629 this.wrap.style.display = "none";
17635 this.wrap.style.display = "";
17639 onContextMenu : function(e){
17640 if (this.node.hasListener("contextmenu") || this.node.getOwnerTree().hasListener("contextmenu")) {
17641 e.preventDefault();
17643 this.fireEvent("contextmenu", this.node, e);
17647 onClick : function(e){
17652 if(this.fireEvent("beforeclick", this.node, e) !== false){
17653 if(!this.disabled && this.node.attributes.href){
17654 this.fireEvent("click", this.node, e);
17657 e.preventDefault();
17662 if(this.node.attributes.singleClickExpand && !this.animating && this.node.hasChildNodes()){
17663 this.node.toggle();
17666 this.fireEvent("click", this.node, e);
17672 onDblClick : function(e){
17673 e.preventDefault();
17678 this.toggleCheck();
17680 if(!this.animating && this.node.hasChildNodes()){
17681 this.node.toggle();
17683 this.fireEvent("dblclick", this.node, e);
17686 onCheckChange : function(){
17687 var checked = this.checkbox.checked;
17688 this.node.attributes.checked = checked;
17689 this.fireEvent('checkchange', this.node, checked);
17692 ecClick : function(e){
17693 if(!this.animating && this.node.hasChildNodes()){
17694 this.node.toggle();
17698 startDrop : function(){
17699 this.dropping = true;
17702 // delayed drop so the click event doesn't get fired on a drop
17703 endDrop : function(){
17704 setTimeout(function(){
17705 this.dropping = false;
17706 }.createDelegate(this), 50);
17709 expand : function(){
17710 this.updateExpandIcon();
17711 this.ctNode.style.display = "";
17714 focus : function(){
17715 if(!this.node.preventHScroll){
17716 try{this.anchor.focus();
17718 }else if(!Roo.isIE){
17720 var noscroll = this.node.getOwnerTree().getTreeEl().dom;
17721 var l = noscroll.scrollLeft;
17722 this.anchor.focus();
17723 noscroll.scrollLeft = l;
17728 toggleCheck : function(value){
17729 var cb = this.checkbox;
17731 cb.checked = (value === undefined ? !cb.checked : value);
17737 this.anchor.blur();
17741 animExpand : function(callback){
17742 var ct = Roo.get(this.ctNode);
17744 if(!this.node.hasChildNodes()){
17745 this.updateExpandIcon();
17746 this.ctNode.style.display = "";
17747 Roo.callback(callback);
17750 this.animating = true;
17751 this.updateExpandIcon();
17754 callback : function(){
17755 this.animating = false;
17756 Roo.callback(callback);
17759 duration: this.node.ownerTree.duration || .25
17763 highlight : function(){
17764 var tree = this.node.getOwnerTree();
17765 Roo.fly(this.wrap).highlight(
17766 tree.hlColor || "C3DAF9",
17767 {endColor: tree.hlBaseColor}
17771 collapse : function(){
17772 this.updateExpandIcon();
17773 this.ctNode.style.display = "none";
17776 animCollapse : function(callback){
17777 var ct = Roo.get(this.ctNode);
17778 ct.enableDisplayMode('block');
17781 this.animating = true;
17782 this.updateExpandIcon();
17785 callback : function(){
17786 this.animating = false;
17787 Roo.callback(callback);
17790 duration: this.node.ownerTree.duration || .25
17794 getContainer : function(){
17795 return this.ctNode;
17798 getEl : function(){
17802 appendDDGhost : function(ghostNode){
17803 ghostNode.appendChild(this.elNode.cloneNode(true));
17806 getDDRepairXY : function(){
17807 return Roo.lib.Dom.getXY(this.iconNode);
17810 onRender : function(){
17814 render : function(bulkRender){
17815 var n = this.node, a = n.attributes;
17816 var targetNode = n.parentNode ?
17817 n.parentNode.ui.getContainer() : n.ownerTree.innerCt.dom;
17819 if(!this.rendered){
17820 this.rendered = true;
17822 this.renderElements(n, a, targetNode, bulkRender);
17825 if(this.textNode.setAttributeNS){
17826 this.textNode.setAttributeNS("ext", "qtip", a.qtip);
17828 this.textNode.setAttributeNS("ext", "qtitle", a.qtipTitle);
17831 this.textNode.setAttribute("ext:qtip", a.qtip);
17833 this.textNode.setAttribute("ext:qtitle", a.qtipTitle);
17836 }else if(a.qtipCfg){
17837 a.qtipCfg.target = Roo.id(this.textNode);
17838 Roo.QuickTips.register(a.qtipCfg);
17841 if(!this.node.expanded){
17842 this.updateExpandIcon();
17845 if(bulkRender === true) {
17846 targetNode.appendChild(this.wrap);
17851 renderElements : function(n, a, targetNode, bulkRender){
17852 // add some indent caching, this helps performance when rendering a large tree
17853 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
17854 var t = n.getOwnerTree();
17855 var txt = t.renderer ? t.renderer(n.attributes) : Roo.util.Format.htmlEncode(n.text);
17856 var tip = t.rendererTip ? t.rendererTip(n.attributes) : txt;
17857 var cb = typeof a.checked == 'boolean';
17858 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
17859 var buf = ['<li class="x-tree-node"><div class="x-tree-node-el ', a.cls,'">',
17860 '<span class="x-tree-node-indent">',this.indentMarkup,"</span>",
17861 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon" />',
17862 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />',
17863 cb ? ('<input class="x-tree-node-cb" type="checkbox" ' + (a.checked ? 'checked="checked" />' : ' />')) : '',
17864 '<a hidefocus="on" href="',href,'" tabIndex="1" ',
17865 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "",
17866 '><span unselectable="on" qtip="' , tip ,'">',txt,"</span></a></div>",
17867 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
17870 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
17871 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
17872 n.nextSibling.ui.getEl(), buf.join(""));
17874 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
17877 this.elNode = this.wrap.childNodes[0];
17878 this.ctNode = this.wrap.childNodes[1];
17879 var cs = this.elNode.childNodes;
17880 this.indentNode = cs[0];
17881 this.ecNode = cs[1];
17882 this.iconNode = cs[2];
17885 this.checkbox = cs[3];
17888 this.anchor = cs[index];
17889 this.textNode = cs[index].firstChild;
17892 getAnchor : function(){
17893 return this.anchor;
17896 getTextEl : function(){
17897 return this.textNode;
17900 getIconEl : function(){
17901 return this.iconNode;
17904 isChecked : function(){
17905 return this.checkbox ? this.checkbox.checked : false;
17908 updateExpandIcon : function(){
17910 var n = this.node, c1, c2;
17911 var cls = n.isLast() ? "x-tree-elbow-end" : "x-tree-elbow";
17912 var hasChild = n.hasChildNodes();
17916 c1 = "x-tree-node-collapsed";
17917 c2 = "x-tree-node-expanded";
17920 c1 = "x-tree-node-expanded";
17921 c2 = "x-tree-node-collapsed";
17924 this.removeClass("x-tree-node-leaf");
17925 this.wasLeaf = false;
17927 if(this.c1 != c1 || this.c2 != c2){
17928 Roo.fly(this.elNode).replaceClass(c1, c2);
17929 this.c1 = c1; this.c2 = c2;
17933 Roo.fly(this.elNode).replaceClass("x-tree-node-expanded", "x-tree-node-leaf");
17936 this.wasLeaf = true;
17939 var ecc = "x-tree-ec-icon "+cls;
17940 if(this.ecc != ecc){
17941 this.ecNode.className = ecc;
17947 getChildIndent : function(){
17948 if(!this.childIndent){
17952 if(!p.isRoot || (p.isRoot && p.ownerTree.rootVisible)){
17954 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-elbow-line" />');
17956 buf.unshift('<img src="'+this.emptyIcon+'" class="x-tree-icon" />');
17961 this.childIndent = buf.join("");
17963 return this.childIndent;
17966 renderIndent : function(){
17969 var p = this.node.parentNode;
17971 indent = p.ui.getChildIndent();
17973 if(this.indentMarkup != indent){ // don't rerender if not required
17974 this.indentNode.innerHTML = indent;
17975 this.indentMarkup = indent;
17977 this.updateExpandIcon();
17982 Roo.tree.RootTreeNodeUI = function(){
17983 Roo.tree.RootTreeNodeUI.superclass.constructor.apply(this, arguments);
17985 Roo.extend(Roo.tree.RootTreeNodeUI, Roo.tree.TreeNodeUI, {
17986 render : function(){
17987 if(!this.rendered){
17988 var targetNode = this.node.ownerTree.innerCt.dom;
17989 this.node.expanded = true;
17990 targetNode.innerHTML = '<div class="x-tree-root-node"></div>';
17991 this.wrap = this.ctNode = targetNode.firstChild;
17994 collapse : function(){
17996 expand : function(){
18000 * Ext JS Library 1.1.1
18001 * Copyright(c) 2006-2007, Ext JS, LLC.
18003 * Originally Released Under LGPL - original licence link has changed is not relivant.
18006 * <script type="text/javascript">
18009 * @class Roo.tree.TreeLoader
18010 * @extends Roo.util.Observable
18011 * A TreeLoader provides for lazy loading of an {@link Roo.tree.TreeNode}'s child
18012 * nodes from a specified URL. The response must be a javascript Array definition
18013 * who's elements are node definition objects. eg:
18015 [{ 'id': 1, 'text': 'A folder Node', 'leaf': false },
18016 { 'id': 2, 'text': 'A leaf Node', 'leaf': true }]
18019 * A server request is sent, and child nodes are loaded only when a node is expanded.
18020 * The loading node's id is passed to the server under the parameter name "node" to
18021 * enable the server to produce the correct child nodes.
18023 * To pass extra parameters, an event handler may be attached to the "beforeload"
18024 * event, and the parameters specified in the TreeLoader's baseParams property:
18026 myTreeLoader.on("beforeload", function(treeLoader, node) {
18027 this.baseParams.category = node.attributes.category;
18030 * This would pass an HTTP parameter called "category" to the server containing
18031 * the value of the Node's "category" attribute.
18033 * Creates a new Treeloader.
18034 * @param {Object} config A config object containing config properties.
18036 Roo.tree.TreeLoader = function(config){
18037 this.baseParams = {};
18038 this.requestMethod = "POST";
18039 Roo.apply(this, config);
18044 * @event beforeload
18045 * Fires before a network request is made to retrieve the Json text which specifies a node's children.
18046 * @param {Object} This TreeLoader object.
18047 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18048 * @param {Object} callback The callback function specified in the {@link #load} call.
18053 * Fires when the node has been successfuly loaded.
18054 * @param {Object} This TreeLoader object.
18055 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18056 * @param {Object} response The response object containing the data from the server.
18060 * @event loadexception
18061 * Fires if the network request failed.
18062 * @param {Object} This TreeLoader object.
18063 * @param {Object} node The {@link Roo.tree.TreeNode} object being loaded.
18064 * @param {Object} response The response object containing the data from the server.
18066 loadexception : true,
18069 * Fires before a node is created, enabling you to return custom Node types
18070 * @param {Object} This TreeLoader object.
18071 * @param {Object} attr - the data returned from the AJAX call (modify it to suit)
18076 Roo.tree.TreeLoader.superclass.constructor.call(this);
18079 Roo.extend(Roo.tree.TreeLoader, Roo.util.Observable, {
18081 * @cfg {String} dataUrl The URL from which to request a Json string which
18082 * specifies an array of node definition object representing the child nodes
18086 * @cfg {Object} baseParams (optional) An object containing properties which
18087 * specify HTTP parameters to be passed to each request for child nodes.
18090 * @cfg {Object} baseAttrs (optional) An object containing attributes to be added to all nodes
18091 * created by this loader. If the attributes sent by the server have an attribute in this object,
18092 * they take priority.
18095 * @cfg {Object} uiProviders (optional) An object containing properties which
18097 * DEPRECIATED - use 'create' event handler to modify attributes - which affect creation.
18098 * specify custom {@link Roo.tree.TreeNodeUI} implementations. If the optional
18099 * <i>uiProvider</i> attribute of a returned child node is a string rather
18100 * than a reference to a TreeNodeUI implementation, this that string value
18101 * is used as a property name in the uiProviders object. You can define the provider named
18102 * 'default' , and this will be used for all nodes (if no uiProvider is delivered by the node data)
18107 * @cfg {Boolean} clearOnLoad (optional) Default to true. Remove previously existing
18108 * child nodes before loading.
18110 clearOnLoad : true,
18113 * @cfg {String} root (optional) Default to false. Use this to read data from an object
18114 * property on loading, rather than expecting an array. (eg. more compatible to a standard
18115 * Grid query { data : [ .....] }
18120 * @cfg {String} queryParam (optional)
18121 * Name of the query as it will be passed on the querystring (defaults to 'node')
18122 * eg. the request will be ?node=[id]
18129 * Load an {@link Roo.tree.TreeNode} from the URL specified in the constructor.
18130 * This is called automatically when a node is expanded, but may be used to reload
18131 * a node (or append new children if the {@link #clearOnLoad} option is false.)
18132 * @param {Roo.tree.TreeNode} node
18133 * @param {Function} callback
18135 load : function(node, callback){
18136 if(this.clearOnLoad){
18137 while(node.firstChild){
18138 node.removeChild(node.firstChild);
18141 if(node.attributes.children){ // preloaded json children
18142 var cs = node.attributes.children;
18143 for(var i = 0, len = cs.length; i < len; i++){
18144 node.appendChild(this.createNode(cs[i]));
18146 if(typeof callback == "function"){
18149 }else if(this.dataUrl){
18150 this.requestData(node, callback);
18154 getParams: function(node){
18155 var buf = [], bp = this.baseParams;
18156 for(var key in bp){
18157 if(typeof bp[key] != "function"){
18158 buf.push(encodeURIComponent(key), "=", encodeURIComponent(bp[key]), "&");
18161 var n = this.queryParam === false ? 'node' : this.queryParam;
18162 buf.push(n + "=", encodeURIComponent(node.id));
18163 return buf.join("");
18166 requestData : function(node, callback){
18167 if(this.fireEvent("beforeload", this, node, callback) !== false){
18168 this.transId = Roo.Ajax.request({
18169 method:this.requestMethod,
18170 url: this.dataUrl||this.url,
18171 success: this.handleResponse,
18172 failure: this.handleFailure,
18174 argument: {callback: callback, node: node},
18175 params: this.getParams(node)
18178 // if the load is cancelled, make sure we notify
18179 // the node that we are done
18180 if(typeof callback == "function"){
18186 isLoading : function(){
18187 return this.transId ? true : false;
18190 abort : function(){
18191 if(this.isLoading()){
18192 Roo.Ajax.abort(this.transId);
18197 createNode : function(attr){
18198 // apply baseAttrs, nice idea Corey!
18199 if(this.baseAttrs){
18200 Roo.applyIf(attr, this.baseAttrs);
18202 if(this.applyLoader !== false){
18203 attr.loader = this;
18205 // uiProvider = depreciated..
18207 if(typeof(attr.uiProvider) == 'string'){
18208 attr.uiProvider = this.uiProviders[attr.uiProvider] ||
18209 /** eval:var:attr */ eval(attr.uiProvider);
18211 if(typeof(this.uiProviders['default']) != 'undefined') {
18212 attr.uiProvider = this.uiProviders['default'];
18215 this.fireEvent('create', this, attr);
18217 attr.leaf = typeof(attr.leaf) == 'string' ? attr.leaf * 1 : attr.leaf;
18219 new Roo.tree.TreeNode(attr) :
18220 new Roo.tree.AsyncTreeNode(attr));
18223 processResponse : function(response, node, callback){
18224 var json = response.responseText;
18227 var o = /** eval:var:zzzzzzzzzz */ eval("("+json+")");
18228 if (this.root !== false) {
18232 for(var i = 0, len = o.length; i < len; i++){
18233 var n = this.createNode(o[i]);
18235 node.appendChild(n);
18238 if(typeof callback == "function"){
18239 callback(this, node);
18242 this.handleFailure(response);
18246 handleResponse : function(response){
18247 this.transId = false;
18248 var a = response.argument;
18249 this.processResponse(response, a.node, a.callback);
18250 this.fireEvent("load", this, a.node, response);
18253 handleFailure : function(response){
18254 this.transId = false;
18255 var a = response.argument;
18256 this.fireEvent("loadexception", this, a.node, response);
18257 if(typeof a.callback == "function"){
18258 a.callback(this, a.node);
18263 * Ext JS Library 1.1.1
18264 * Copyright(c) 2006-2007, Ext JS, LLC.
18266 * Originally Released Under LGPL - original licence link has changed is not relivant.
18269 * <script type="text/javascript">
18273 * @class Roo.tree.TreeFilter
18274 * Note this class is experimental and doesn't update the indent (lines) or expand collapse icons of the nodes
18275 * @param {TreePanel} tree
18276 * @param {Object} config (optional)
18278 Roo.tree.TreeFilter = function(tree, config){
18280 this.filtered = {};
18281 Roo.apply(this, config);
18284 Roo.tree.TreeFilter.prototype = {
18291 * Filter the data by a specific attribute.
18292 * @param {String/RegExp} value Either string that the attribute value
18293 * should start with or a RegExp to test against the attribute
18294 * @param {String} attr (optional) The attribute passed in your node's attributes collection. Defaults to "text".
18295 * @param {TreeNode} startNode (optional) The node to start the filter at.
18297 filter : function(value, attr, startNode){
18298 attr = attr || "text";
18300 if(typeof value == "string"){
18301 var vlen = value.length;
18302 // auto clear empty filter
18303 if(vlen == 0 && this.clearBlank){
18307 value = value.toLowerCase();
18309 return n.attributes[attr].substr(0, vlen).toLowerCase() == value;
18311 }else if(value.exec){ // regex?
18313 return value.test(n.attributes[attr]);
18316 throw 'Illegal filter type, must be string or regex';
18318 this.filterBy(f, null, startNode);
18322 * Filter by a function. The passed function will be called with each
18323 * node in the tree (or from the startNode). If the function returns true, the node is kept
18324 * otherwise it is filtered. If a node is filtered, its children are also filtered.
18325 * @param {Function} fn The filter function
18326 * @param {Object} scope (optional) The scope of the function (defaults to the current node)
18328 filterBy : function(fn, scope, startNode){
18329 startNode = startNode || this.tree.root;
18330 if(this.autoClear){
18333 var af = this.filtered, rv = this.reverse;
18334 var f = function(n){
18335 if(n == startNode){
18341 var m = fn.call(scope || n, n);
18349 startNode.cascade(f);
18352 if(typeof id != "function"){
18354 if(n && n.parentNode){
18355 n.parentNode.removeChild(n);
18363 * Clears the current filter. Note: with the "remove" option
18364 * set a filter cannot be cleared.
18366 clear : function(){
18368 var af = this.filtered;
18370 if(typeof id != "function"){
18377 this.filtered = {};
18382 * Ext JS Library 1.1.1
18383 * Copyright(c) 2006-2007, Ext JS, LLC.
18385 * Originally Released Under LGPL - original licence link has changed is not relivant.
18388 * <script type="text/javascript">
18393 * @class Roo.tree.TreeSorter
18394 * Provides sorting of nodes in a TreePanel
18396 * @cfg {Boolean} folderSort True to sort leaf nodes under non leaf nodes
18397 * @cfg {String} property The named attribute on the node to sort by (defaults to text)
18398 * @cfg {String} dir The direction to sort (asc or desc) (defaults to asc)
18399 * @cfg {String} leafAttr The attribute used to determine leaf nodes in folder sort (defaults to "leaf")
18400 * @cfg {Boolean} caseSensitive true for case sensitive sort (defaults to false)
18401 * @cfg {Function} sortType A custom "casting" function used to convert node values before sorting
18403 * @param {TreePanel} tree
18404 * @param {Object} config
18406 Roo.tree.TreeSorter = function(tree, config){
18407 Roo.apply(this, config);
18408 tree.on("beforechildrenrendered", this.doSort, this);
18409 tree.on("append", this.updateSort, this);
18410 tree.on("insert", this.updateSort, this);
18412 var dsc = this.dir && this.dir.toLowerCase() == "desc";
18413 var p = this.property || "text";
18414 var sortType = this.sortType;
18415 var fs = this.folderSort;
18416 var cs = this.caseSensitive === true;
18417 var leafAttr = this.leafAttr || 'leaf';
18419 this.sortFn = function(n1, n2){
18421 if(n1.attributes[leafAttr] && !n2.attributes[leafAttr]){
18424 if(!n1.attributes[leafAttr] && n2.attributes[leafAttr]){
18428 var v1 = sortType ? sortType(n1) : (cs ? n1.attributes[p] : n1.attributes[p].toUpperCase());
18429 var v2 = sortType ? sortType(n2) : (cs ? n2.attributes[p] : n2.attributes[p].toUpperCase());
18431 return dsc ? +1 : -1;
18433 return dsc ? -1 : +1;
18440 Roo.tree.TreeSorter.prototype = {
18441 doSort : function(node){
18442 node.sort(this.sortFn);
18445 compareNodes : function(n1, n2){
18446 return (n1.text.toUpperCase() > n2.text.toUpperCase() ? 1 : -1);
18449 updateSort : function(tree, node){
18450 if(node.childrenRendered){
18451 this.doSort.defer(1, this, [node]);
18456 * Ext JS Library 1.1.1
18457 * Copyright(c) 2006-2007, Ext JS, LLC.
18459 * Originally Released Under LGPL - original licence link has changed is not relivant.
18462 * <script type="text/javascript">
18465 if(Roo.dd.DropZone){
18467 Roo.tree.TreeDropZone = function(tree, config){
18468 this.allowParentInsert = false;
18469 this.allowContainerDrop = false;
18470 this.appendOnly = false;
18471 Roo.tree.TreeDropZone.superclass.constructor.call(this, tree.innerCt, config);
18473 this.lastInsertClass = "x-tree-no-status";
18474 this.dragOverData = {};
18477 Roo.extend(Roo.tree.TreeDropZone, Roo.dd.DropZone, {
18478 ddGroup : "TreeDD",
18480 expandDelay : 1000,
18482 expandNode : function(node){
18483 if(node.hasChildNodes() && !node.isExpanded()){
18484 node.expand(false, null, this.triggerCacheRefresh.createDelegate(this));
18488 queueExpand : function(node){
18489 this.expandProcId = this.expandNode.defer(this.expandDelay, this, [node]);
18492 cancelExpand : function(){
18493 if(this.expandProcId){
18494 clearTimeout(this.expandProcId);
18495 this.expandProcId = false;
18499 isValidDropPoint : function(n, pt, dd, e, data){
18500 if(!n || !data){ return false; }
18501 var targetNode = n.node;
18502 var dropNode = data.node;
18503 // default drop rules
18504 if(!(targetNode && targetNode.isTarget && pt)){
18507 if(pt == "append" && targetNode.allowChildren === false){
18510 if((pt == "above" || pt == "below") && (targetNode.parentNode && targetNode.parentNode.allowChildren === false)){
18513 if(dropNode && (targetNode == dropNode || dropNode.contains(targetNode))){
18516 // reuse the object
18517 var overEvent = this.dragOverData;
18518 overEvent.tree = this.tree;
18519 overEvent.target = targetNode;
18520 overEvent.data = data;
18521 overEvent.point = pt;
18522 overEvent.source = dd;
18523 overEvent.rawEvent = e;
18524 overEvent.dropNode = dropNode;
18525 overEvent.cancel = false;
18526 var result = this.tree.fireEvent("nodedragover", overEvent);
18527 return overEvent.cancel === false && result !== false;
18530 getDropPoint : function(e, n, dd){
18533 return tn.allowChildren !== false ? "append" : false; // always append for root
18535 var dragEl = n.ddel;
18536 var t = Roo.lib.Dom.getY(dragEl), b = t + dragEl.offsetHeight;
18537 var y = Roo.lib.Event.getPageY(e);
18538 var noAppend = tn.allowChildren === false || tn.isLeaf();
18539 if(this.appendOnly || tn.parentNode.allowChildren === false){
18540 return noAppend ? false : "append";
18542 var noBelow = false;
18543 if(!this.allowParentInsert){
18544 noBelow = tn.hasChildNodes() && tn.isExpanded();
18546 var q = (b - t) / (noAppend ? 2 : 3);
18547 if(y >= t && y < (t + q)){
18549 }else if(!noBelow && (noAppend || y >= b-q && y <= b)){
18556 onNodeEnter : function(n, dd, e, data){
18557 this.cancelExpand();
18560 onNodeOver : function(n, dd, e, data){
18561 var pt = this.getDropPoint(e, n, dd);
18564 // auto node expand check
18565 if(!this.expandProcId && pt == "append" && node.hasChildNodes() && !n.node.isExpanded()){
18566 this.queueExpand(node);
18567 }else if(pt != "append"){
18568 this.cancelExpand();
18571 // set the insert point style on the target node
18572 var returnCls = this.dropNotAllowed;
18573 if(this.isValidDropPoint(n, pt, dd, e, data)){
18578 returnCls = n.node.isFirst() ? "x-tree-drop-ok-above" : "x-tree-drop-ok-between";
18579 cls = "x-tree-drag-insert-above";
18580 }else if(pt == "below"){
18581 returnCls = n.node.isLast() ? "x-tree-drop-ok-below" : "x-tree-drop-ok-between";
18582 cls = "x-tree-drag-insert-below";
18584 returnCls = "x-tree-drop-ok-append";
18585 cls = "x-tree-drag-append";
18587 if(this.lastInsertClass != cls){
18588 Roo.fly(el).replaceClass(this.lastInsertClass, cls);
18589 this.lastInsertClass = cls;
18596 onNodeOut : function(n, dd, e, data){
18597 this.cancelExpand();
18598 this.removeDropIndicators(n);
18601 onNodeDrop : function(n, dd, e, data){
18602 var point = this.getDropPoint(e, n, dd);
18603 var targetNode = n.node;
18604 targetNode.ui.startDrop();
18605 if(!this.isValidDropPoint(n, point, dd, e, data)){
18606 targetNode.ui.endDrop();
18609 // first try to find the drop node
18610 var dropNode = data.node || (dd.getTreeNode ? dd.getTreeNode(data, targetNode, point, e) : null);
18613 target: targetNode,
18618 dropNode: dropNode,
18621 var retval = this.tree.fireEvent("beforenodedrop", dropEvent);
18622 if(retval === false || dropEvent.cancel === true || !dropEvent.dropNode){
18623 targetNode.ui.endDrop();
18626 // allow target changing
18627 targetNode = dropEvent.target;
18628 if(point == "append" && !targetNode.isExpanded()){
18629 targetNode.expand(false, null, function(){
18630 this.completeDrop(dropEvent);
18631 }.createDelegate(this));
18633 this.completeDrop(dropEvent);
18638 completeDrop : function(de){
18639 var ns = de.dropNode, p = de.point, t = de.target;
18640 if(!(ns instanceof Array)){
18644 for(var i = 0, len = ns.length; i < len; i++){
18647 t.parentNode.insertBefore(n, t);
18648 }else if(p == "below"){
18649 t.parentNode.insertBefore(n, t.nextSibling);
18655 if(this.tree.hlDrop){
18659 this.tree.fireEvent("nodedrop", de);
18662 afterNodeMoved : function(dd, data, e, targetNode, dropNode){
18663 if(this.tree.hlDrop){
18664 dropNode.ui.focus();
18665 dropNode.ui.highlight();
18667 this.tree.fireEvent("nodedrop", this.tree, targetNode, data, dd, e);
18670 getTree : function(){
18674 removeDropIndicators : function(n){
18677 Roo.fly(el).removeClass([
18678 "x-tree-drag-insert-above",
18679 "x-tree-drag-insert-below",
18680 "x-tree-drag-append"]);
18681 this.lastInsertClass = "_noclass";
18685 beforeDragDrop : function(target, e, id){
18686 this.cancelExpand();
18690 afterRepair : function(data){
18691 if(data && Roo.enableFx){
18692 data.node.ui.highlight();
18700 * Ext JS Library 1.1.1
18701 * Copyright(c) 2006-2007, Ext JS, LLC.
18703 * Originally Released Under LGPL - original licence link has changed is not relivant.
18706 * <script type="text/javascript">
18710 if(Roo.dd.DragZone){
18711 Roo.tree.TreeDragZone = function(tree, config){
18712 Roo.tree.TreeDragZone.superclass.constructor.call(this, tree.getTreeEl(), config);
18716 Roo.extend(Roo.tree.TreeDragZone, Roo.dd.DragZone, {
18717 ddGroup : "TreeDD",
18719 onBeforeDrag : function(data, e){
18721 return n && n.draggable && !n.disabled;
18724 onInitDrag : function(e){
18725 var data = this.dragData;
18726 this.tree.getSelectionModel().select(data.node);
18727 this.proxy.update("");
18728 data.node.ui.appendDDGhost(this.proxy.ghost.dom);
18729 this.tree.fireEvent("startdrag", this.tree, data.node, e);
18732 getRepairXY : function(e, data){
18733 return data.node.ui.getDDRepairXY();
18736 onEndDrag : function(data, e){
18737 this.tree.fireEvent("enddrag", this.tree, data.node, e);
18740 onValidDrop : function(dd, e, id){
18741 this.tree.fireEvent("dragdrop", this.tree, this.dragData.node, dd, e);
18745 beforeInvalidDrop : function(e, id){
18746 // this scrolls the original position back into view
18747 var sm = this.tree.getSelectionModel();
18748 sm.clearSelections();
18749 sm.select(this.dragData.node);
18754 * Ext JS Library 1.1.1
18755 * Copyright(c) 2006-2007, Ext JS, LLC.
18757 * Originally Released Under LGPL - original licence link has changed is not relivant.
18760 * <script type="text/javascript">
18763 * @class Roo.tree.TreeEditor
18764 * @extends Roo.Editor
18765 * Provides editor functionality for inline tree node editing. Any valid {@link Roo.form.Field} can be used
18766 * as the editor field.
18768 * @param {TreePanel} tree
18769 * @param {Object} config Either a prebuilt {@link Roo.form.Field} instance or a Field config object
18771 Roo.tree.TreeEditor = function(tree, config){
18772 config = config || {};
18773 var field = config.events ? config : new Roo.form.TextField(config);
18774 Roo.tree.TreeEditor.superclass.constructor.call(this, field);
18778 tree.on('beforeclick', this.beforeNodeClick, this);
18779 tree.getTreeEl().on('mousedown', this.hide, this);
18780 this.on('complete', this.updateNode, this);
18781 this.on('beforestartedit', this.fitToTree, this);
18782 this.on('startedit', this.bindScroll, this, {delay:10});
18783 this.on('specialkey', this.onSpecialKey, this);
18786 Roo.extend(Roo.tree.TreeEditor, Roo.Editor, {
18788 * @cfg {String} alignment
18789 * The position to align to (see {@link Roo.Element#alignTo} for more details, defaults to "l-l").
18795 * @cfg {Boolean} hideEl
18796 * True to hide the bound element while the editor is displayed (defaults to false)
18800 * @cfg {String} cls
18801 * CSS class to apply to the editor (defaults to "x-small-editor x-tree-editor")
18803 cls: "x-small-editor x-tree-editor",
18805 * @cfg {Boolean} shim
18806 * True to shim the editor if selects/iframes could be displayed beneath it (defaults to false)
18812 * @cfg {Number} maxWidth
18813 * The maximum width in pixels of the editor field (defaults to 250). Note that if the maxWidth would exceed
18814 * the containing tree element's size, it will be automatically limited for you to the container width, taking
18815 * scroll and client offsets into account prior to each edit.
18822 fitToTree : function(ed, el){
18823 var td = this.tree.getTreeEl().dom, nd = el.dom;
18824 if(td.scrollLeft > nd.offsetLeft){ // ensure the node left point is visible
18825 td.scrollLeft = nd.offsetLeft;
18829 (td.clientWidth > 20 ? td.clientWidth : td.offsetWidth) - Math.max(0, nd.offsetLeft-td.scrollLeft) - /*cushion*/5);
18830 this.setSize(w, '');
18834 triggerEdit : function(node){
18835 this.completeEdit();
18836 this.editNode = node;
18837 this.startEdit(node.ui.textNode, node.text);
18841 bindScroll : function(){
18842 this.tree.getTreeEl().on('scroll', this.cancelEdit, this);
18846 beforeNodeClick : function(node, e){
18847 var sinceLast = (this.lastClick ? this.lastClick.getElapsed() : 0);
18848 this.lastClick = new Date();
18849 if(sinceLast > this.editDelay && this.tree.getSelectionModel().isSelected(node)){
18851 this.triggerEdit(node);
18857 updateNode : function(ed, value){
18858 this.tree.getTreeEl().un('scroll', this.cancelEdit, this);
18859 this.editNode.setText(value);
18863 onHide : function(){
18864 Roo.tree.TreeEditor.superclass.onHide.call(this);
18866 this.editNode.ui.focus();
18871 onSpecialKey : function(field, e){
18872 var k = e.getKey();
18876 }else if(k == e.ENTER && !e.hasModifier()){
18878 this.completeEdit();
18881 });//<Script type="text/javascript">
18884 * Ext JS Library 1.1.1
18885 * Copyright(c) 2006-2007, Ext JS, LLC.
18887 * Originally Released Under LGPL - original licence link has changed is not relivant.
18890 * <script type="text/javascript">
18894 * Not documented??? - probably should be...
18897 Roo.tree.ColumnNodeUI = Roo.extend(Roo.tree.TreeNodeUI, {
18898 //focus: Roo.emptyFn, // prevent odd scrolling behavior
18900 renderElements : function(n, a, targetNode, bulkRender){
18901 //consel.log("renderElements?");
18902 this.indentMarkup = n.parentNode ? n.parentNode.ui.getChildIndent() : '';
18904 var t = n.getOwnerTree();
18905 var tid = Pman.Tab.Document_TypesTree.tree.el.id;
18907 var cols = t.columns;
18908 var bw = t.borderWidth;
18910 var href = a.href ? a.href : Roo.isGecko ? "" : "#";
18911 var cb = typeof a.checked == "boolean";
18912 var tx = String.format('{0}',n.text || (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
18913 var colcls = 'x-t-' + tid + '-c0';
18915 '<li class="x-tree-node">',
18918 '<div class="x-tree-node-el ', a.cls,'">',
18920 '<div class="x-tree-col ', colcls, '" style="width:', c.width-bw, 'px;">',
18923 '<span class="x-tree-node-indent">',this.indentMarkup,'</span>',
18924 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon " />',
18925 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',
18926 (a.icon ? ' x-tree-node-inline-icon' : ''),
18927 (a.iconCls ? ' '+a.iconCls : ''),
18928 '" unselectable="on" />',
18929 (cb ? ('<input class="x-tree-node-cb" type="checkbox" ' +
18930 (a.checked ? 'checked="checked" />' : ' />')) : ''),
18932 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
18933 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
18934 '<span unselectable="on" qtip="' + tx + '">',
18938 '<a class="x-tree-node-anchor" hidefocus="on" href="',href,'" tabIndex="1" ',
18939 (a.hrefTarget ? ' target="' +a.hrefTarget + '"' : ''), '>',
18942 for(var i = 1, len = cols.length; i < len; i++){
18944 colcls = 'x-t-' + tid + '-c' +i;
18945 tx = String.format('{0}', (c.renderer ? c.renderer(a[c.dataIndex], n, a) : a[c.dataIndex]));
18946 buf.push('<div class="x-tree-col ', colcls, ' ' ,(c.cls?c.cls:''),'" style="width:',c.width-bw,'px;">',
18947 '<div class="x-tree-col-text" qtip="' + tx +'">',tx,"</div>",
18953 '<div class="x-clear"></div></div>',
18954 '<ul class="x-tree-node-ct" style="display:none;"></ul>',
18957 if(bulkRender !== true && n.nextSibling && n.nextSibling.ui.getEl()){
18958 this.wrap = Roo.DomHelper.insertHtml("beforeBegin",
18959 n.nextSibling.ui.getEl(), buf.join(""));
18961 this.wrap = Roo.DomHelper.insertHtml("beforeEnd", targetNode, buf.join(""));
18963 var el = this.wrap.firstChild;
18965 this.elNode = el.firstChild;
18966 this.ranchor = el.childNodes[1];
18967 this.ctNode = this.wrap.childNodes[1];
18968 var cs = el.firstChild.childNodes;
18969 this.indentNode = cs[0];
18970 this.ecNode = cs[1];
18971 this.iconNode = cs[2];
18974 this.checkbox = cs[3];
18977 this.anchor = cs[index];
18979 this.textNode = cs[index].firstChild;
18981 //el.on("click", this.onClick, this);
18982 //el.on("dblclick", this.onDblClick, this);
18985 // console.log(this);
18987 initEvents : function(){
18988 Roo.tree.ColumnNodeUI.superclass.initEvents.call(this);
18991 var a = this.ranchor;
18993 var el = Roo.get(a);
18995 if(Roo.isOpera){ // opera render bug ignores the CSS
18996 el.setStyle("text-decoration", "none");
18999 el.on("click", this.onClick, this);
19000 el.on("dblclick", this.onDblClick, this);
19001 el.on("contextmenu", this.onContextMenu, this);
19005 /*onSelectedChange : function(state){
19008 this.addClass("x-tree-selected");
19011 this.removeClass("x-tree-selected");
19014 addClass : function(cls){
19016 Roo.fly(this.elRow).addClass(cls);
19022 removeClass : function(cls){
19024 Roo.fly(this.elRow).removeClass(cls);
19030 });//<Script type="text/javascript">
19034 * Ext JS Library 1.1.1
19035 * Copyright(c) 2006-2007, Ext JS, LLC.
19037 * Originally Released Under LGPL - original licence link has changed is not relivant.
19040 * <script type="text/javascript">
19045 * @class Roo.tree.ColumnTree
19046 * @extends Roo.data.TreePanel
19047 * @cfg {Object} columns Including width, header, renderer, cls, dataIndex
19048 * @cfg {int} borderWidth compined right/left border allowance
19050 * @param {String/HTMLElement/Element} el The container element
19051 * @param {Object} config
19053 Roo.tree.ColumnTree = function(el, config)
19055 Roo.tree.ColumnTree.superclass.constructor.call(this, el , config);
19059 * Fire this event on a container when it resizes
19060 * @param {int} w Width
19061 * @param {int} h Height
19065 this.on('resize', this.onResize, this);
19068 Roo.extend(Roo.tree.ColumnTree, Roo.tree.TreePanel, {
19072 borderWidth: Roo.isBorderBox ? 0 : 2,
19075 render : function(){
19076 // add the header.....
19078 Roo.tree.ColumnTree.superclass.render.apply(this);
19080 this.el.addClass('x-column-tree');
19082 this.headers = this.el.createChild(
19083 {cls:'x-tree-headers'},this.innerCt.dom);
19085 var cols = this.columns, c;
19086 var totalWidth = 0;
19088 var len = cols.length;
19089 for(var i = 0; i < len; i++){
19091 totalWidth += c.width;
19092 this.headEls.push(this.headers.createChild({
19093 cls:'x-tree-hd ' + (c.cls?c.cls+'-hd':''),
19095 cls:'x-tree-hd-text',
19098 style:'width:'+(c.width-this.borderWidth)+'px;'
19101 this.headers.createChild({cls:'x-clear'});
19102 // prevent floats from wrapping when clipped
19103 this.headers.setWidth(totalWidth);
19104 //this.innerCt.setWidth(totalWidth);
19105 this.innerCt.setStyle({ overflow: 'auto' });
19106 this.onResize(this.width, this.height);
19110 onResize : function(w,h)
19115 this.innerCt.setWidth(this.width);
19116 this.innerCt.setHeight(this.height-20);
19119 var cols = this.columns, c;
19120 var totalWidth = 0;
19122 var len = cols.length;
19123 for(var i = 0; i < len; i++){
19125 if (this.autoExpandColumn !== false && c.dataIndex == this.autoExpandColumn) {
19126 // it's the expander..
19127 expEl = this.headEls[i];
19130 totalWidth += c.width;
19134 expEl.setWidth( ((w - totalWidth)-this.borderWidth - 20));
19136 this.headers.setWidth(w-20);
19145 * Ext JS Library 1.1.1
19146 * Copyright(c) 2006-2007, Ext JS, LLC.
19148 * Originally Released Under LGPL - original licence link has changed is not relivant.
19151 * <script type="text/javascript">
19155 * @class Roo.menu.Menu
19156 * @extends Roo.util.Observable
19157 * A menu object. This is the container to which you add all other menu items. Menu can also serve a as a base class
19158 * when you want a specialzed menu based off of another component (like {@link Roo.menu.DateMenu} for example).
19160 * Creates a new Menu
19161 * @param {Object} config Configuration options
19163 Roo.menu.Menu = function(config){
19164 Roo.apply(this, config);
19165 this.id = this.id || Roo.id();
19168 * @event beforeshow
19169 * Fires before this menu is displayed
19170 * @param {Roo.menu.Menu} this
19174 * @event beforehide
19175 * Fires before this menu is hidden
19176 * @param {Roo.menu.Menu} this
19181 * Fires after this menu is displayed
19182 * @param {Roo.menu.Menu} this
19187 * Fires after this menu is hidden
19188 * @param {Roo.menu.Menu} this
19193 * Fires when this menu is clicked (or when the enter key is pressed while it is active)
19194 * @param {Roo.menu.Menu} this
19195 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19196 * @param {Roo.EventObject} e
19201 * Fires when the mouse is hovering over this menu
19202 * @param {Roo.menu.Menu} this
19203 * @param {Roo.EventObject} e
19204 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19209 * Fires when the mouse exits this menu
19210 * @param {Roo.menu.Menu} this
19211 * @param {Roo.EventObject} e
19212 * @param {Roo.menu.Item} menuItem The menu item that was clicked
19217 * Fires when a menu item contained in this menu is clicked
19218 * @param {Roo.menu.BaseItem} baseItem The BaseItem that was clicked
19219 * @param {Roo.EventObject} e
19223 if (this.registerMenu) {
19224 Roo.menu.MenuMgr.register(this);
19227 var mis = this.items;
19228 this.items = new Roo.util.MixedCollection();
19230 this.add.apply(this, mis);
19234 Roo.extend(Roo.menu.Menu, Roo.util.Observable, {
19236 * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120)
19240 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop"
19241 * for bottom-right shadow (defaults to "sides")
19245 * @cfg {String} subMenuAlign The {@link Roo.Element#alignTo} anchor position value to use for submenus of
19246 * this menu (defaults to "tl-tr?")
19248 subMenuAlign : "tl-tr?",
19250 * @cfg {String} defaultAlign The default {@link Roo.Element#alignTo) anchor position value for this menu
19251 * relative to its element of origin (defaults to "tl-bl?")
19253 defaultAlign : "tl-bl?",
19255 * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false)
19257 allowOtherMenus : false,
19259 * @cfg {Boolean} registerMenu True (default) - means that clicking on screen etc. hides it.
19261 registerMenu : true,
19266 render : function(){
19270 var el = this.el = new Roo.Layer({
19272 shadow:this.shadow,
19274 parentEl: this.parentEl || document.body,
19278 this.keyNav = new Roo.menu.MenuNav(this);
19281 el.addClass("x-menu-plain");
19284 el.addClass(this.cls);
19286 // generic focus element
19287 this.focusEl = el.createChild({
19288 tag: "a", cls: "x-menu-focus", href: "#", onclick: "return false;", tabIndex:"-1"
19290 var ul = el.createChild({tag: "ul", cls: "x-menu-list"});
19291 ul.on("click", this.onClick, this);
19292 ul.on("mouseover", this.onMouseOver, this);
19293 ul.on("mouseout", this.onMouseOut, this);
19294 this.items.each(function(item){
19295 var li = document.createElement("li");
19296 li.className = "x-menu-list-item";
19297 ul.dom.appendChild(li);
19298 item.render(li, this);
19305 autoWidth : function(){
19306 var el = this.el, ul = this.ul;
19310 var w = this.width;
19313 }else if(Roo.isIE){
19314 el.setWidth(this.minWidth);
19315 var t = el.dom.offsetWidth; // force recalc
19316 el.setWidth(ul.getWidth()+el.getFrameWidth("lr"));
19321 delayAutoWidth : function(){
19324 this.awTask = new Roo.util.DelayedTask(this.autoWidth, this);
19326 this.awTask.delay(20);
19331 findTargetItem : function(e){
19332 var t = e.getTarget(".x-menu-list-item", this.ul, true);
19333 if(t && t.menuItemId){
19334 return this.items.get(t.menuItemId);
19339 onClick : function(e){
19341 if(t = this.findTargetItem(e)){
19343 this.fireEvent("click", this, t, e);
19348 setActiveItem : function(item, autoExpand){
19349 if(item != this.activeItem){
19350 if(this.activeItem){
19351 this.activeItem.deactivate();
19353 this.activeItem = item;
19354 item.activate(autoExpand);
19355 }else if(autoExpand){
19361 tryActivate : function(start, step){
19362 var items = this.items;
19363 for(var i = start, len = items.length; i >= 0 && i < len; i+= step){
19364 var item = items.get(i);
19365 if(!item.disabled && item.canActivate){
19366 this.setActiveItem(item, false);
19374 onMouseOver : function(e){
19376 if(t = this.findTargetItem(e)){
19377 if(t.canActivate && !t.disabled){
19378 this.setActiveItem(t, true);
19381 this.fireEvent("mouseover", this, e, t);
19385 onMouseOut : function(e){
19387 if(t = this.findTargetItem(e)){
19388 if(t == this.activeItem && t.shouldDeactivate(e)){
19389 this.activeItem.deactivate();
19390 delete this.activeItem;
19393 this.fireEvent("mouseout", this, e, t);
19397 * Read-only. Returns true if the menu is currently displayed, else false.
19400 isVisible : function(){
19401 return this.el && !this.hidden;
19405 * Displays this menu relative to another element
19406 * @param {String/HTMLElement/Roo.Element} element The element to align to
19407 * @param {String} position (optional) The {@link Roo.Element#alignTo} anchor position to use in aligning to
19408 * the element (defaults to this.defaultAlign)
19409 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
19411 show : function(el, pos, parentMenu){
19412 this.parentMenu = parentMenu;
19416 this.fireEvent("beforeshow", this);
19417 this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign), parentMenu, false);
19421 * Displays this menu at a specific xy position
19422 * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
19423 * @param {Roo.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
19425 showAt : function(xy, parentMenu, /* private: */_e){
19426 this.parentMenu = parentMenu;
19431 this.fireEvent("beforeshow", this);
19432 xy = this.el.adjustForConstraints(xy);
19436 this.hidden = false;
19438 this.fireEvent("show", this);
19441 focus : function(){
19443 this.doFocus.defer(50, this);
19447 doFocus : function(){
19449 this.focusEl.focus();
19454 * Hides this menu and optionally all parent menus
19455 * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
19457 hide : function(deep){
19458 if(this.el && this.isVisible()){
19459 this.fireEvent("beforehide", this);
19460 if(this.activeItem){
19461 this.activeItem.deactivate();
19462 this.activeItem = null;
19465 this.hidden = true;
19466 this.fireEvent("hide", this);
19468 if(deep === true && this.parentMenu){
19469 this.parentMenu.hide(true);
19474 * Addds one or more items of any type supported by the Menu class, or that can be converted into menu items.
19475 * Any of the following are valid:
19477 * <li>Any menu item object based on {@link Roo.menu.Item}</li>
19478 * <li>An HTMLElement object which will be converted to a menu item</li>
19479 * <li>A menu item config object that will be created as a new menu item</li>
19480 * <li>A string, which can either be '-' or 'separator' to add a menu separator, otherwise
19481 * it will be converted into a {@link Roo.menu.TextItem} and added</li>
19486 var menu = new Roo.menu.Menu();
19488 // Create a menu item to add by reference
19489 var menuItem = new Roo.menu.Item({ text: 'New Item!' });
19491 // Add a bunch of items at once using different methods.
19492 // Only the last item added will be returned.
19493 var item = menu.add(
19494 menuItem, // add existing item by ref
19495 'Dynamic Item', // new TextItem
19496 '-', // new separator
19497 { text: 'Config Item' } // new item by config
19500 * @param {Mixed} args One or more menu items, menu item configs or other objects that can be converted to menu items
19501 * @return {Roo.menu.Item} The menu item that was added, or the last one if multiple items were added
19504 var a = arguments, l = a.length, item;
19505 for(var i = 0; i < l; i++){
19507 if(el.render){ // some kind of Item
19508 item = this.addItem(el);
19509 }else if(typeof el == "string"){ // string
19510 if(el == "separator" || el == "-"){
19511 item = this.addSeparator();
19513 item = this.addText(el);
19515 }else if(el.tagName || el.el){ // element
19516 item = this.addElement(el);
19517 }else if(typeof el == "object"){ // must be menu item config?
19518 item = this.addMenuItem(el);
19525 * Returns this menu's underlying {@link Roo.Element} object
19526 * @return {Roo.Element} The element
19528 getEl : function(){
19536 * Adds a separator bar to the menu
19537 * @return {Roo.menu.Item} The menu item that was added
19539 addSeparator : function(){
19540 return this.addItem(new Roo.menu.Separator());
19544 * Adds an {@link Roo.Element} object to the menu
19545 * @param {String/HTMLElement/Roo.Element} el The element or DOM node to add, or its id
19546 * @return {Roo.menu.Item} The menu item that was added
19548 addElement : function(el){
19549 return this.addItem(new Roo.menu.BaseItem(el));
19553 * Adds an existing object based on {@link Roo.menu.Item} to the menu
19554 * @param {Roo.menu.Item} item The menu item to add
19555 * @return {Roo.menu.Item} The menu item that was added
19557 addItem : function(item){
19558 this.items.add(item);
19560 var li = document.createElement("li");
19561 li.className = "x-menu-list-item";
19562 this.ul.dom.appendChild(li);
19563 item.render(li, this);
19564 this.delayAutoWidth();
19570 * Creates a new {@link Roo.menu.Item} based an the supplied config object and adds it to the menu
19571 * @param {Object} config A MenuItem config object
19572 * @return {Roo.menu.Item} The menu item that was added
19574 addMenuItem : function(config){
19575 if(!(config instanceof Roo.menu.Item)){
19576 if(typeof config.checked == "boolean"){ // must be check menu item config?
19577 config = new Roo.menu.CheckItem(config);
19579 config = new Roo.menu.Item(config);
19582 return this.addItem(config);
19586 * Creates a new {@link Roo.menu.TextItem} with the supplied text and adds it to the menu
19587 * @param {String} text The text to display in the menu item
19588 * @return {Roo.menu.Item} The menu item that was added
19590 addText : function(text){
19591 return this.addItem(new Roo.menu.TextItem(text));
19595 * Inserts an existing object based on {@link Roo.menu.Item} to the menu at a specified index
19596 * @param {Number} index The index in the menu's list of current items where the new item should be inserted
19597 * @param {Roo.menu.Item} item The menu item to add
19598 * @return {Roo.menu.Item} The menu item that was added
19600 insert : function(index, item){
19601 this.items.insert(index, item);
19603 var li = document.createElement("li");
19604 li.className = "x-menu-list-item";
19605 this.ul.dom.insertBefore(li, this.ul.dom.childNodes[index]);
19606 item.render(li, this);
19607 this.delayAutoWidth();
19613 * Removes an {@link Roo.menu.Item} from the menu and destroys the object
19614 * @param {Roo.menu.Item} item The menu item to remove
19616 remove : function(item){
19617 this.items.removeKey(item.id);
19622 * Removes and destroys all items in the menu
19624 removeAll : function(){
19626 while(f = this.items.first()){
19632 // MenuNav is a private utility class used internally by the Menu
19633 Roo.menu.MenuNav = function(menu){
19634 Roo.menu.MenuNav.superclass.constructor.call(this, menu.el);
19635 this.scope = this.menu = menu;
19638 Roo.extend(Roo.menu.MenuNav, Roo.KeyNav, {
19639 doRelay : function(e, h){
19640 var k = e.getKey();
19641 if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){
19642 this.menu.tryActivate(0, 1);
19645 return h.call(this.scope || this, e, this.menu);
19648 up : function(e, m){
19649 if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
19650 m.tryActivate(m.items.length-1, -1);
19654 down : function(e, m){
19655 if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
19656 m.tryActivate(0, 1);
19660 right : function(e, m){
19662 m.activeItem.expandMenu(true);
19666 left : function(e, m){
19668 if(m.parentMenu && m.parentMenu.activeItem){
19669 m.parentMenu.activeItem.activate();
19673 enter : function(e, m){
19675 e.stopPropagation();
19676 m.activeItem.onClick(e);
19677 m.fireEvent("click", this, m.activeItem);
19683 * Ext JS Library 1.1.1
19684 * Copyright(c) 2006-2007, Ext JS, LLC.
19686 * Originally Released Under LGPL - original licence link has changed is not relivant.
19689 * <script type="text/javascript">
19693 * @class Roo.menu.MenuMgr
19694 * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
19697 Roo.menu.MenuMgr = function(){
19698 var menus, active, groups = {}, attached = false, lastShow = new Date();
19700 // private - called when first menu is created
19703 active = new Roo.util.MixedCollection();
19704 Roo.get(document).addKeyListener(27, function(){
19705 if(active.length > 0){
19712 function hideAll(){
19713 if(active && active.length > 0){
19714 var c = active.clone();
19715 c.each(function(m){
19722 function onHide(m){
19724 if(active.length < 1){
19725 Roo.get(document).un("mousedown", onMouseDown);
19731 function onShow(m){
19732 var last = active.last();
19733 lastShow = new Date();
19736 Roo.get(document).on("mousedown", onMouseDown);
19740 m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
19741 m.parentMenu.activeChild = m;
19742 }else if(last && last.isVisible()){
19743 m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
19748 function onBeforeHide(m){
19750 m.activeChild.hide();
19752 if(m.autoHideTimer){
19753 clearTimeout(m.autoHideTimer);
19754 delete m.autoHideTimer;
19759 function onBeforeShow(m){
19760 var pm = m.parentMenu;
19761 if(!pm && !m.allowOtherMenus){
19763 }else if(pm && pm.activeChild && active != m){
19764 pm.activeChild.hide();
19769 function onMouseDown(e){
19770 if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
19776 function onBeforeCheck(mi, state){
19778 var g = groups[mi.group];
19779 for(var i = 0, l = g.length; i < l; i++){
19781 g[i].setChecked(false);
19790 * Hides all menus that are currently visible
19792 hideAll : function(){
19797 register : function(menu){
19801 menus[menu.id] = menu;
19802 menu.on("beforehide", onBeforeHide);
19803 menu.on("hide", onHide);
19804 menu.on("beforeshow", onBeforeShow);
19805 menu.on("show", onShow);
19806 var g = menu.group;
19807 if(g && menu.events["checkchange"]){
19811 groups[g].push(menu);
19812 menu.on("checkchange", onCheck);
19817 * Returns a {@link Roo.menu.Menu} object
19818 * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
19819 * be used to generate and return a new Menu instance.
19821 get : function(menu){
19822 if(typeof menu == "string"){ // menu id
19823 return menus[menu];
19824 }else if(menu.events){ // menu instance
19826 }else if(typeof menu.length == 'number'){ // array of menu items?
19827 return new Roo.menu.Menu({items:menu});
19828 }else{ // otherwise, must be a config
19829 return new Roo.menu.Menu(menu);
19834 unregister : function(menu){
19835 delete menus[menu.id];
19836 menu.un("beforehide", onBeforeHide);
19837 menu.un("hide", onHide);
19838 menu.un("beforeshow", onBeforeShow);
19839 menu.un("show", onShow);
19840 var g = menu.group;
19841 if(g && menu.events["checkchange"]){
19842 groups[g].remove(menu);
19843 menu.un("checkchange", onCheck);
19848 registerCheckable : function(menuItem){
19849 var g = menuItem.group;
19854 groups[g].push(menuItem);
19855 menuItem.on("beforecheckchange", onBeforeCheck);
19860 unregisterCheckable : function(menuItem){
19861 var g = menuItem.group;
19863 groups[g].remove(menuItem);
19864 menuItem.un("beforecheckchange", onBeforeCheck);
19870 * Ext JS Library 1.1.1
19871 * Copyright(c) 2006-2007, Ext JS, LLC.
19873 * Originally Released Under LGPL - original licence link has changed is not relivant.
19876 * <script type="text/javascript">
19881 * @class Roo.menu.BaseItem
19882 * @extends Roo.Component
19883 * The base class for all items that render into menus. BaseItem provides default rendering, activated state
19884 * management and base configuration options shared by all menu components.
19886 * Creates a new BaseItem
19887 * @param {Object} config Configuration options
19889 Roo.menu.BaseItem = function(config){
19890 Roo.menu.BaseItem.superclass.constructor.call(this, config);
19895 * Fires when this item is clicked
19896 * @param {Roo.menu.BaseItem} this
19897 * @param {Roo.EventObject} e
19902 * Fires when this item is activated
19903 * @param {Roo.menu.BaseItem} this
19907 * @event deactivate
19908 * Fires when this item is deactivated
19909 * @param {Roo.menu.BaseItem} this
19915 this.on("click", this.handler, this.scope, true);
19919 Roo.extend(Roo.menu.BaseItem, Roo.Component, {
19921 * @cfg {Function} handler
19922 * A function that will handle the click event of this menu item (defaults to undefined)
19925 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
19927 canActivate : false,
19929 * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
19931 activeClass : "x-menu-item-active",
19933 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
19935 hideOnClick : true,
19937 * @cfg {Number} hideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 100)
19942 ctype: "Roo.menu.BaseItem",
19945 actionMode : "container",
19948 render : function(container, parentMenu){
19949 this.parentMenu = parentMenu;
19950 Roo.menu.BaseItem.superclass.render.call(this, container);
19951 this.container.menuItemId = this.id;
19955 onRender : function(container, position){
19956 this.el = Roo.get(this.el);
19957 container.dom.appendChild(this.el.dom);
19961 onClick : function(e){
19962 if(!this.disabled && this.fireEvent("click", this, e) !== false
19963 && this.parentMenu.fireEvent("itemclick", this, e) !== false){
19964 this.handleClick(e);
19971 activate : function(){
19975 var li = this.container;
19976 li.addClass(this.activeClass);
19977 this.region = li.getRegion().adjust(2, 2, -2, -2);
19978 this.fireEvent("activate", this);
19983 deactivate : function(){
19984 this.container.removeClass(this.activeClass);
19985 this.fireEvent("deactivate", this);
19989 shouldDeactivate : function(e){
19990 return !this.region || !this.region.contains(e.getPoint());
19994 handleClick : function(e){
19995 if(this.hideOnClick){
19996 this.parentMenu.hide.defer(this.hideDelay, this.parentMenu, [true]);
20001 expandMenu : function(autoActivate){
20006 hideMenu : function(){
20011 * Ext JS Library 1.1.1
20012 * Copyright(c) 2006-2007, Ext JS, LLC.
20014 * Originally Released Under LGPL - original licence link has changed is not relivant.
20017 * <script type="text/javascript">
20021 * @class Roo.menu.Adapter
20022 * @extends Roo.menu.BaseItem
20023 * 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.
20024 * It provides basic rendering, activation management and enable/disable logic required to work in menus.
20026 * Creates a new Adapter
20027 * @param {Object} config Configuration options
20029 Roo.menu.Adapter = function(component, config){
20030 Roo.menu.Adapter.superclass.constructor.call(this, config);
20031 this.component = component;
20033 Roo.extend(Roo.menu.Adapter, Roo.menu.BaseItem, {
20035 canActivate : true,
20038 onRender : function(container, position){
20039 this.component.render(container);
20040 this.el = this.component.getEl();
20044 activate : function(){
20048 this.component.focus();
20049 this.fireEvent("activate", this);
20054 deactivate : function(){
20055 this.fireEvent("deactivate", this);
20059 disable : function(){
20060 this.component.disable();
20061 Roo.menu.Adapter.superclass.disable.call(this);
20065 enable : function(){
20066 this.component.enable();
20067 Roo.menu.Adapter.superclass.enable.call(this);
20071 * Ext JS Library 1.1.1
20072 * Copyright(c) 2006-2007, Ext JS, LLC.
20074 * Originally Released Under LGPL - original licence link has changed is not relivant.
20077 * <script type="text/javascript">
20081 * @class Roo.menu.TextItem
20082 * @extends Roo.menu.BaseItem
20083 * Adds a static text string to a menu, usually used as either a heading or group separator.
20085 * Creates a new TextItem
20086 * @param {String} text The text to display
20088 Roo.menu.TextItem = function(text){
20090 Roo.menu.TextItem.superclass.constructor.call(this);
20093 Roo.extend(Roo.menu.TextItem, Roo.menu.BaseItem, {
20095 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
20097 hideOnClick : false,
20099 * @cfg {String} itemCls The default CSS class to use for text items (defaults to "x-menu-text")
20101 itemCls : "x-menu-text",
20104 onRender : function(){
20105 var s = document.createElement("span");
20106 s.className = this.itemCls;
20107 s.innerHTML = this.text;
20109 Roo.menu.TextItem.superclass.onRender.apply(this, arguments);
20113 * Ext JS Library 1.1.1
20114 * Copyright(c) 2006-2007, Ext JS, LLC.
20116 * Originally Released Under LGPL - original licence link has changed is not relivant.
20119 * <script type="text/javascript">
20123 * @class Roo.menu.Separator
20124 * @extends Roo.menu.BaseItem
20125 * Adds a separator bar to a menu, used to divide logical groups of menu items. Generally you will
20126 * add one of these by using "-" in you call to add() or in your items config rather than creating one directly.
20128 * @param {Object} config Configuration options
20130 Roo.menu.Separator = function(config){
20131 Roo.menu.Separator.superclass.constructor.call(this, config);
20134 Roo.extend(Roo.menu.Separator, Roo.menu.BaseItem, {
20136 * @cfg {String} itemCls The default CSS class to use for separators (defaults to "x-menu-sep")
20138 itemCls : "x-menu-sep",
20140 * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
20142 hideOnClick : false,
20145 onRender : function(li){
20146 var s = document.createElement("span");
20147 s.className = this.itemCls;
20148 s.innerHTML = " ";
20150 li.addClass("x-menu-sep-li");
20151 Roo.menu.Separator.superclass.onRender.apply(this, arguments);
20155 * Ext JS Library 1.1.1
20156 * Copyright(c) 2006-2007, Ext JS, LLC.
20158 * Originally Released Under LGPL - original licence link has changed is not relivant.
20161 * <script type="text/javascript">
20164 * @class Roo.menu.Item
20165 * @extends Roo.menu.BaseItem
20166 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
20167 * display items. Item extends the base functionality of {@link Roo.menu.BaseItem} by adding menu-specific
20168 * activation and click handling.
20170 * Creates a new Item
20171 * @param {Object} config Configuration options
20173 Roo.menu.Item = function(config){
20174 Roo.menu.Item.superclass.constructor.call(this, config);
20176 this.menu = Roo.menu.MenuMgr.get(this.menu);
20179 Roo.extend(Roo.menu.Item, Roo.menu.BaseItem, {
20181 * @cfg {String} icon
20182 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
20185 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
20187 itemCls : "x-menu-item",
20189 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
20191 canActivate : true,
20193 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
20196 // doc'd in BaseItem
20200 ctype: "Roo.menu.Item",
20203 onRender : function(container, position){
20204 var el = document.createElement("a");
20205 el.hideFocus = true;
20206 el.unselectable = "on";
20207 el.href = this.href || "#";
20208 if(this.hrefTarget){
20209 el.target = this.hrefTarget;
20211 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
20212 el.innerHTML = String.format(
20213 '<img src="{0}" class="x-menu-item-icon {2}" />{1}',
20214 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || '');
20216 Roo.menu.Item.superclass.onRender.call(this, container, position);
20220 * Sets the text to display in this menu item
20221 * @param {String} text The text to display
20223 setText : function(text){
20226 this.el.update(String.format(
20227 '<img src="{0}" class="x-menu-item-icon {2}">{1}',
20228 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
20229 this.parentMenu.autoWidth();
20234 handleClick : function(e){
20235 if(!this.href){ // if no link defined, stop the event automatically
20238 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
20242 activate : function(autoExpand){
20243 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
20253 shouldDeactivate : function(e){
20254 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
20255 if(this.menu && this.menu.isVisible()){
20256 return !this.menu.getEl().getRegion().contains(e.getPoint());
20264 deactivate : function(){
20265 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
20270 expandMenu : function(autoActivate){
20271 if(!this.disabled && this.menu){
20272 clearTimeout(this.hideTimer);
20273 delete this.hideTimer;
20274 if(!this.menu.isVisible() && !this.showTimer){
20275 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
20276 }else if (this.menu.isVisible() && autoActivate){
20277 this.menu.tryActivate(0, 1);
20283 deferExpand : function(autoActivate){
20284 delete this.showTimer;
20285 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
20287 this.menu.tryActivate(0, 1);
20292 hideMenu : function(){
20293 clearTimeout(this.showTimer);
20294 delete this.showTimer;
20295 if(!this.hideTimer && this.menu && this.menu.isVisible()){
20296 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
20301 deferHide : function(){
20302 delete this.hideTimer;
20307 * Ext JS Library 1.1.1
20308 * Copyright(c) 2006-2007, Ext JS, LLC.
20310 * Originally Released Under LGPL - original licence link has changed is not relivant.
20313 * <script type="text/javascript">
20317 * @class Roo.menu.CheckItem
20318 * @extends Roo.menu.Item
20319 * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
20321 * Creates a new CheckItem
20322 * @param {Object} config Configuration options
20324 Roo.menu.CheckItem = function(config){
20325 Roo.menu.CheckItem.superclass.constructor.call(this, config);
20328 * @event beforecheckchange
20329 * Fires before the checked value is set, providing an opportunity to cancel if needed
20330 * @param {Roo.menu.CheckItem} this
20331 * @param {Boolean} checked The new checked value that will be set
20333 "beforecheckchange" : true,
20335 * @event checkchange
20336 * Fires after the checked value has been set
20337 * @param {Roo.menu.CheckItem} this
20338 * @param {Boolean} checked The checked value that was set
20340 "checkchange" : true
20342 if(this.checkHandler){
20343 this.on('checkchange', this.checkHandler, this.scope);
20346 Roo.extend(Roo.menu.CheckItem, Roo.menu.Item, {
20348 * @cfg {String} group
20349 * All check items with the same group name will automatically be grouped into a single-select
20350 * radio button group (defaults to '')
20353 * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
20355 itemCls : "x-menu-item x-menu-check-item",
20357 * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
20359 groupClass : "x-menu-group-item",
20362 * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
20363 * if this checkbox is part of a radio group (group = true) only the last item in the group that is
20364 * initialized with checked = true will be rendered as checked.
20369 ctype: "Roo.menu.CheckItem",
20372 onRender : function(c){
20373 Roo.menu.CheckItem.superclass.onRender.apply(this, arguments);
20375 this.el.addClass(this.groupClass);
20377 Roo.menu.MenuMgr.registerCheckable(this);
20379 this.checked = false;
20380 this.setChecked(true, true);
20385 destroy : function(){
20387 Roo.menu.MenuMgr.unregisterCheckable(this);
20389 Roo.menu.CheckItem.superclass.destroy.apply(this, arguments);
20393 * Set the checked state of this item
20394 * @param {Boolean} checked The new checked value
20395 * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
20397 setChecked : function(state, suppressEvent){
20398 if(this.checked != state && this.fireEvent("beforecheckchange", this, state) !== false){
20399 if(this.container){
20400 this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
20402 this.checked = state;
20403 if(suppressEvent !== true){
20404 this.fireEvent("checkchange", this, state);
20410 handleClick : function(e){
20411 if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
20412 this.setChecked(!this.checked);
20414 Roo.menu.CheckItem.superclass.handleClick.apply(this, arguments);
20418 * Ext JS Library 1.1.1
20419 * Copyright(c) 2006-2007, Ext JS, LLC.
20421 * Originally Released Under LGPL - original licence link has changed is not relivant.
20424 * <script type="text/javascript">
20428 * @class Roo.menu.DateItem
20429 * @extends Roo.menu.Adapter
20430 * A menu item that wraps the {@link Roo.DatPicker} component.
20432 * Creates a new DateItem
20433 * @param {Object} config Configuration options
20435 Roo.menu.DateItem = function(config){
20436 Roo.menu.DateItem.superclass.constructor.call(this, new Roo.DatePicker(config), config);
20437 /** The Roo.DatePicker object @type Roo.DatePicker */
20438 this.picker = this.component;
20439 this.addEvents({select: true});
20441 this.picker.on("render", function(picker){
20442 picker.getEl().swallowEvent("click");
20443 picker.container.addClass("x-menu-date-item");
20446 this.picker.on("select", this.onSelect, this);
20449 Roo.extend(Roo.menu.DateItem, Roo.menu.Adapter, {
20451 onSelect : function(picker, date){
20452 this.fireEvent("select", this, date, picker);
20453 Roo.menu.DateItem.superclass.handleClick.call(this);
20457 * Ext JS Library 1.1.1
20458 * Copyright(c) 2006-2007, Ext JS, LLC.
20460 * Originally Released Under LGPL - original licence link has changed is not relivant.
20463 * <script type="text/javascript">
20467 * @class Roo.menu.ColorItem
20468 * @extends Roo.menu.Adapter
20469 * A menu item that wraps the {@link Roo.ColorPalette} component.
20471 * Creates a new ColorItem
20472 * @param {Object} config Configuration options
20474 Roo.menu.ColorItem = function(config){
20475 Roo.menu.ColorItem.superclass.constructor.call(this, new Roo.ColorPalette(config), config);
20476 /** The Roo.ColorPalette object @type Roo.ColorPalette */
20477 this.palette = this.component;
20478 this.relayEvents(this.palette, ["select"]);
20479 if(this.selectHandler){
20480 this.on('select', this.selectHandler, this.scope);
20483 Roo.extend(Roo.menu.ColorItem, Roo.menu.Adapter);/*
20485 * Ext JS Library 1.1.1
20486 * Copyright(c) 2006-2007, Ext JS, LLC.
20488 * Originally Released Under LGPL - original licence link has changed is not relivant.
20491 * <script type="text/javascript">
20496 * @class Roo.menu.DateMenu
20497 * @extends Roo.menu.Menu
20498 * A menu containing a {@link Roo.menu.DateItem} component (which provides a date picker).
20500 * Creates a new DateMenu
20501 * @param {Object} config Configuration options
20503 Roo.menu.DateMenu = function(config){
20504 Roo.menu.DateMenu.superclass.constructor.call(this, config);
20506 var di = new Roo.menu.DateItem(config);
20509 * The {@link Roo.DatePicker} instance for this DateMenu
20512 this.picker = di.picker;
20515 * @param {DatePicker} picker
20516 * @param {Date} date
20518 this.relayEvents(di, ["select"]);
20520 this.on('beforeshow', function(){
20522 this.picker.hideMonthPicker(true);
20526 Roo.extend(Roo.menu.DateMenu, Roo.menu.Menu, {
20530 * Ext JS Library 1.1.1
20531 * Copyright(c) 2006-2007, Ext JS, LLC.
20533 * Originally Released Under LGPL - original licence link has changed is not relivant.
20536 * <script type="text/javascript">
20541 * @class Roo.menu.ColorMenu
20542 * @extends Roo.menu.Menu
20543 * A menu containing a {@link Roo.menu.ColorItem} component (which provides a basic color picker).
20545 * Creates a new ColorMenu
20546 * @param {Object} config Configuration options
20548 Roo.menu.ColorMenu = function(config){
20549 Roo.menu.ColorMenu.superclass.constructor.call(this, config);
20551 var ci = new Roo.menu.ColorItem(config);
20554 * The {@link Roo.ColorPalette} instance for this ColorMenu
20555 * @type ColorPalette
20557 this.palette = ci.palette;
20560 * @param {ColorPalette} palette
20561 * @param {String} color
20563 this.relayEvents(ci, ["select"]);
20565 Roo.extend(Roo.menu.ColorMenu, Roo.menu.Menu);/*
20567 * Ext JS Library 1.1.1
20568 * Copyright(c) 2006-2007, Ext JS, LLC.
20570 * Originally Released Under LGPL - original licence link has changed is not relivant.
20573 * <script type="text/javascript">
20577 * @class Roo.form.Field
20578 * @extends Roo.BoxComponent
20579 * Base class for form fields that provides default event handling, sizing, value handling and other functionality.
20581 * Creates a new Field
20582 * @param {Object} config Configuration options
20584 Roo.form.Field = function(config){
20585 Roo.form.Field.superclass.constructor.call(this, config);
20588 Roo.extend(Roo.form.Field, Roo.BoxComponent, {
20590 * @cfg {String} fieldLabel Label to use when rendering a form.
20593 * @cfg {String} qtip Mouse over tip
20597 * @cfg {String} invalidClass The CSS class to use when marking a field invalid (defaults to "x-form-invalid")
20599 invalidClass : "x-form-invalid",
20601 * @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")
20603 invalidText : "The value in this field is invalid",
20605 * @cfg {String} focusClass The CSS class to use when the field receives focus (defaults to "x-form-focus")
20607 focusClass : "x-form-focus",
20609 * @cfg {String/Boolean} validationEvent The event that should initiate field validation. Set to false to disable
20610 automatic validation (defaults to "keyup").
20612 validationEvent : "keyup",
20614 * @cfg {Boolean} validateOnBlur Whether the field should validate when it loses focus (defaults to true).
20616 validateOnBlur : true,
20618 * @cfg {Number} validationDelay The length of time in milliseconds after user input begins until validation is initiated (defaults to 250)
20620 validationDelay : 250,
20622 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
20623 * {tag: "input", type: "text", size: "20", autocomplete: "off"})
20625 defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "off"},
20627 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field")
20629 fieldClass : "x-form-field",
20631 * @cfg {String} msgTarget The location where error text should display. Should be one of the following values (defaults to 'qtip'):
20634 ----------- ----------------------------------------------------------------------
20635 qtip Display a quick tip when the user hovers over the field
20636 title Display a default browser title attribute popup
20637 under Add a block div beneath the field containing the error text
20638 side Add an error icon to the right of the field with a popup on hover
20639 [element id] Add the error text directly to the innerHTML of the specified element
20642 msgTarget : 'qtip',
20644 * @cfg {String} msgFx <b>Experimental</b> The effect used when displaying a validation message under the field (defaults to 'normal').
20649 * @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.
20654 * @cfg {Boolean} disabled True to disable the field (defaults to false).
20659 * @cfg {String} inputType The type attribute for input fields -- e.g. radio, text, password (defaults to "text").
20661 inputType : undefined,
20664 * @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).
20666 tabIndex : undefined,
20669 isFormField : true,
20674 * @property {Roo.Element} fieldEl
20675 * Element Containing the rendered Field (with label etc.)
20678 * @cfg {Mixed} value A value to initialize this field with.
20683 * @cfg {String} name The field's HTML name attribute.
20686 * @cfg {String} cls A CSS class to apply to the field's underlying element.
20690 initComponent : function(){
20691 Roo.form.Field.superclass.initComponent.call(this);
20695 * Fires when this field receives input focus.
20696 * @param {Roo.form.Field} this
20701 * Fires when this field loses input focus.
20702 * @param {Roo.form.Field} this
20706 * @event specialkey
20707 * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
20708 * {@link Roo.EventObject#getKey} to determine which key was pressed.
20709 * @param {Roo.form.Field} this
20710 * @param {Roo.EventObject} e The event object
20715 * Fires just before the field blurs if the field value has changed.
20716 * @param {Roo.form.Field} this
20717 * @param {Mixed} newValue The new value
20718 * @param {Mixed} oldValue The original value
20723 * Fires after the field has been marked as invalid.
20724 * @param {Roo.form.Field} this
20725 * @param {String} msg The validation message
20730 * Fires after the field has been validated with no errors.
20731 * @param {Roo.form.Field} this
20738 * Returns the name attribute of the field if available
20739 * @return {String} name The field name
20741 getName: function(){
20742 return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
20746 onRender : function(ct, position){
20747 Roo.form.Field.superclass.onRender.call(this, ct, position);
20749 var cfg = this.getAutoCreate();
20751 cfg.name = this.name || this.id;
20753 if(this.inputType){
20754 cfg.type = this.inputType;
20756 this.el = ct.createChild(cfg, position);
20758 var type = this.el.dom.type;
20760 if(type == 'password'){
20763 this.el.addClass('x-form-'+type);
20766 this.el.dom.readOnly = true;
20768 if(this.tabIndex !== undefined){
20769 this.el.dom.setAttribute('tabIndex', this.tabIndex);
20772 this.el.addClass([this.fieldClass, this.cls]);
20777 * Apply the behaviors of this component to an existing element. <b>This is used instead of render().</b>
20778 * @param {String/HTMLElement/Element} el The id of the node, a DOM node or an existing Element
20779 * @return {Roo.form.Field} this
20781 applyTo : function(target){
20782 this.allowDomMove = false;
20783 this.el = Roo.get(target);
20784 this.render(this.el.dom.parentNode);
20789 initValue : function(){
20790 if(this.value !== undefined){
20791 this.setValue(this.value);
20792 }else if(this.el.dom.value.length > 0){
20793 this.setValue(this.el.dom.value);
20798 * Returns true if this field has been changed since it was originally loaded and is not disabled.
20800 isDirty : function() {
20801 if(this.disabled) {
20804 return String(this.getValue()) !== String(this.originalValue);
20808 afterRender : function(){
20809 Roo.form.Field.superclass.afterRender.call(this);
20814 fireKey : function(e){
20815 if(e.isNavKeyPress()){
20816 this.fireEvent("specialkey", this, e);
20821 * Resets the current field value to the originally loaded value and clears any validation messages
20823 reset : function(){
20824 this.setValue(this.originalValue);
20825 this.clearInvalid();
20829 initEvents : function(){
20830 this.el.on(Roo.isIE ? "keydown" : "keypress", this.fireKey, this);
20831 this.el.on("focus", this.onFocus, this);
20832 this.el.on("blur", this.onBlur, this);
20834 // reference to original value for reset
20835 this.originalValue = this.getValue();
20839 onFocus : function(){
20840 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
20841 this.el.addClass(this.focusClass);
20843 if(!this.hasFocus){
20844 this.hasFocus = true;
20845 this.startValue = this.getValue();
20846 this.fireEvent("focus", this);
20850 beforeBlur : Roo.emptyFn,
20853 onBlur : function(){
20855 if(!Roo.isOpera && this.focusClass){ // don't touch in Opera
20856 this.el.removeClass(this.focusClass);
20858 this.hasFocus = false;
20859 if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
20862 var v = this.getValue();
20863 if(String(v) !== String(this.startValue)){
20864 this.fireEvent('change', this, v, this.startValue);
20866 this.fireEvent("blur", this);
20870 * Returns whether or not the field value is currently valid
20871 * @param {Boolean} preventMark True to disable marking the field invalid
20872 * @return {Boolean} True if the value is valid, else false
20874 isValid : function(preventMark){
20878 var restore = this.preventMark;
20879 this.preventMark = preventMark === true;
20880 var v = this.validateValue(this.processValue(this.getRawValue()));
20881 this.preventMark = restore;
20886 * Validates the field value
20887 * @return {Boolean} True if the value is valid, else false
20889 validate : function(){
20890 if(this.disabled || this.validateValue(this.processValue(this.getRawValue()))){
20891 this.clearInvalid();
20897 processValue : function(value){
20902 // Subclasses should provide the validation implementation by overriding this
20903 validateValue : function(value){
20908 * Mark this field as invalid
20909 * @param {String} msg The validation message
20911 markInvalid : function(msg){
20912 if(!this.rendered || this.preventMark){ // not rendered
20915 this.el.addClass(this.invalidClass);
20916 msg = msg || this.invalidText;
20917 switch(this.msgTarget){
20919 this.el.dom.qtip = msg;
20920 this.el.dom.qclass = 'x-form-invalid-tip';
20921 if(Roo.QuickTips){ // fix for floating editors interacting with DND
20922 Roo.QuickTips.enable();
20926 this.el.dom.title = msg;
20930 var elp = this.el.findParent('.x-form-element', 5, true);
20931 this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
20932 this.errorEl.setWidth(elp.getWidth(true)-20);
20934 this.errorEl.update(msg);
20935 Roo.form.Field.msgFx[this.msgFx].show(this.errorEl, this);
20938 if(!this.errorIcon){
20939 var elp = this.el.findParent('.x-form-element', 5, true);
20940 this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
20942 this.alignErrorIcon();
20943 this.errorIcon.dom.qtip = msg;
20944 this.errorIcon.dom.qclass = 'x-form-invalid-tip';
20945 this.errorIcon.show();
20946 this.on('resize', this.alignErrorIcon, this);
20949 var t = Roo.getDom(this.msgTarget);
20951 t.style.display = this.msgDisplay;
20954 this.fireEvent('invalid', this, msg);
20958 alignErrorIcon : function(){
20959 this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
20963 * Clear any invalid styles/messages for this field
20965 clearInvalid : function(){
20966 if(!this.rendered || this.preventMark){ // not rendered
20969 this.el.removeClass(this.invalidClass);
20970 switch(this.msgTarget){
20972 this.el.dom.qtip = '';
20975 this.el.dom.title = '';
20979 Roo.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);
20983 if(this.errorIcon){
20984 this.errorIcon.dom.qtip = '';
20985 this.errorIcon.hide();
20986 this.un('resize', this.alignErrorIcon, this);
20990 var t = Roo.getDom(this.msgTarget);
20992 t.style.display = 'none';
20995 this.fireEvent('valid', this);
20999 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
21000 * @return {Mixed} value The field value
21002 getRawValue : function(){
21003 var v = this.el.getValue();
21004 if(v === this.emptyText){
21011 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
21012 * @return {Mixed} value The field value
21014 getValue : function(){
21015 var v = this.el.getValue();
21016 if(v === this.emptyText || v === undefined){
21023 * Sets the underlying DOM field's value directly, bypassing validation. To set the value with validation see {@link #setValue}.
21024 * @param {Mixed} value The value to set
21026 setRawValue : function(v){
21027 return this.el.dom.value = (v === null || v === undefined ? '' : v);
21031 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
21032 * @param {Mixed} value The value to set
21034 setValue : function(v){
21037 this.el.dom.value = (v === null || v === undefined ? '' : v);
21042 adjustSize : function(w, h){
21043 var s = Roo.form.Field.superclass.adjustSize.call(this, w, h);
21044 s.width = this.adjustWidth(this.el.dom.tagName, s.width);
21048 adjustWidth : function(tag, w){
21049 tag = tag.toLowerCase();
21050 if(typeof w == 'number' && Roo.isStrict && !Roo.isSafari){
21051 if(Roo.isIE && (tag == 'input' || tag == 'textarea')){
21052 if(tag == 'input'){
21055 if(tag = 'textarea'){
21058 }else if(Roo.isOpera){
21059 if(tag == 'input'){
21062 if(tag = 'textarea'){
21072 // anything other than normal should be considered experimental
21073 Roo.form.Field.msgFx = {
21075 show: function(msgEl, f){
21076 msgEl.setDisplayed('block');
21079 hide : function(msgEl, f){
21080 msgEl.setDisplayed(false).update('');
21085 show: function(msgEl, f){
21086 msgEl.slideIn('t', {stopFx:true});
21089 hide : function(msgEl, f){
21090 msgEl.slideOut('t', {stopFx:true,useDisplay:true});
21095 show: function(msgEl, f){
21096 msgEl.fixDisplay();
21097 msgEl.alignTo(f.el, 'tl-tr');
21098 msgEl.slideIn('l', {stopFx:true});
21101 hide : function(msgEl, f){
21102 msgEl.slideOut('l', {stopFx:true,useDisplay:true});
21107 * Ext JS Library 1.1.1
21108 * Copyright(c) 2006-2007, Ext JS, LLC.
21110 * Originally Released Under LGPL - original licence link has changed is not relivant.
21113 * <script type="text/javascript">
21118 * @class Roo.form.TextField
21119 * @extends Roo.form.Field
21120 * Basic text field. Can be used as a direct replacement for traditional text inputs, or as the base
21121 * class for more sophisticated input controls (like {@link Roo.form.TextArea} and {@link Roo.form.ComboBox}).
21123 * Creates a new TextField
21124 * @param {Object} config Configuration options
21126 Roo.form.TextField = function(config){
21127 Roo.form.TextField.superclass.constructor.call(this, config);
21131 * Fires when the autosize function is triggered. The field may or may not have actually changed size
21132 * according to the default logic, but this event provides a hook for the developer to apply additional
21133 * logic at runtime to resize the field if needed.
21134 * @param {Roo.form.Field} this This text field
21135 * @param {Number} width The new field width
21141 Roo.extend(Roo.form.TextField, Roo.form.Field, {
21143 * @cfg {Boolean} grow True if this field should automatically grow and shrink to its content
21147 * @cfg {Number} growMin The minimum width to allow when grow = true (defaults to 30)
21151 * @cfg {Number} growMax The maximum width to allow when grow = true (defaults to 800)
21155 * @cfg {String} vtype A validation type name as defined in {@link Roo.form.VTypes} (defaults to null)
21159 * @cfg {String} maskRe An input mask regular expression that will be used to filter keystrokes that don't match (defaults to null)
21163 * @cfg {Boolean} disableKeyFilter True to disable input keystroke filtering (defaults to false)
21165 disableKeyFilter : false,
21167 * @cfg {Boolean} allowBlank False to validate that the value length > 0 (defaults to true)
21171 * @cfg {Number} minLength Minimum input field length required (defaults to 0)
21175 * @cfg {Number} maxLength Maximum input field length allowed (defaults to Number.MAX_VALUE)
21177 maxLength : Number.MAX_VALUE,
21179 * @cfg {String} minLengthText Error text to display if the minimum length validation fails (defaults to "The minimum length for this field is {minLength}")
21181 minLengthText : "The minimum length for this field is {0}",
21183 * @cfg {String} maxLengthText Error text to display if the maximum length validation fails (defaults to "The maximum length for this field is {maxLength}")
21185 maxLengthText : "The maximum length for this field is {0}",
21187 * @cfg {Boolean} selectOnFocus True to automatically select any existing field text when the field receives input focus (defaults to false)
21189 selectOnFocus : false,
21191 * @cfg {String} blankText Error text to display if the allow blank validation fails (defaults to "This field is required")
21193 blankText : "This field is required",
21195 * @cfg {Function} validator A custom validation function to be called during field validation (defaults to null).
21196 * If available, this function will be called only after the basic validators all return true, and will be passed the
21197 * current field value and expected to return boolean true if the value is valid or a string error message if invalid.
21201 * @cfg {RegExp} regex A JavaScript RegExp object to be tested against the field value during validation (defaults to null).
21202 * If available, this regex will be evaluated only after the basic validators all return true, and will be passed the
21203 * current field value. If the test fails, the field will be marked invalid using {@link #regexText}.
21207 * @cfg {String} regexText The error text to display if {@link #regex} is used and the test fails during validation (defaults to "")
21211 * @cfg {String} emptyText The default text to display in an empty field (defaults to null).
21215 * @cfg {String} emptyClass The CSS class to apply to an empty field to style the {@link #emptyText} (defaults to
21216 * 'x-form-empty-field'). This class is automatically added and removed as needed depending on the current field value.
21218 emptyClass : 'x-form-empty-field',
21221 initEvents : function(){
21222 Roo.form.TextField.superclass.initEvents.call(this);
21223 if(this.validationEvent == 'keyup'){
21224 this.validationTask = new Roo.util.DelayedTask(this.validate, this);
21225 this.el.on('keyup', this.filterValidation, this);
21227 else if(this.validationEvent !== false){
21228 this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
21230 if(this.selectOnFocus || this.emptyText){
21231 this.on("focus", this.preFocus, this);
21232 if(this.emptyText){
21233 this.on('blur', this.postBlur, this);
21234 this.applyEmptyText();
21237 if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Roo.form.VTypes[this.vtype+'Mask']))){
21238 this.el.on("keypress", this.filterKeys, this);
21241 this.el.on("keyup", this.onKeyUp, this, {buffer:50});
21242 this.el.on("click", this.autoSize, this);
21246 processValue : function(value){
21247 if(this.stripCharsRe){
21248 var newValue = value.replace(this.stripCharsRe, '');
21249 if(newValue !== value){
21250 this.setRawValue(newValue);
21257 filterValidation : function(e){
21258 if(!e.isNavKeyPress()){
21259 this.validationTask.delay(this.validationDelay);
21264 onKeyUp : function(e){
21265 if(!e.isNavKeyPress()){
21271 * Resets the current field value to the originally-loaded value and clears any validation messages.
21272 * Also adds emptyText and emptyClass if the original value was blank.
21274 reset : function(){
21275 Roo.form.TextField.superclass.reset.call(this);
21276 this.applyEmptyText();
21279 applyEmptyText : function(){
21280 if(this.rendered && this.emptyText && this.getRawValue().length < 1){
21281 this.setRawValue(this.emptyText);
21282 this.el.addClass(this.emptyClass);
21287 preFocus : function(){
21288 if(this.emptyText){
21289 if(this.el.dom.value == this.emptyText){
21290 this.setRawValue('');
21292 this.el.removeClass(this.emptyClass);
21294 if(this.selectOnFocus){
21295 this.el.dom.select();
21300 postBlur : function(){
21301 this.applyEmptyText();
21305 filterKeys : function(e){
21306 var k = e.getKey();
21307 if(!Roo.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
21310 var c = e.getCharCode(), cc = String.fromCharCode(c);
21311 if(Roo.isIE && (e.isSpecialKey() || !cc)){
21314 if(!this.maskRe.test(cc)){
21319 setValue : function(v){
21320 if(this.emptyText && this.el && v !== undefined && v !== null && v !== ''){
21321 this.el.removeClass(this.emptyClass);
21323 Roo.form.TextField.superclass.setValue.apply(this, arguments);
21324 this.applyEmptyText();
21329 * Validates a value according to the field's validation rules and marks the field as invalid
21330 * if the validation fails
21331 * @param {Mixed} value The value to validate
21332 * @return {Boolean} True if the value is valid, else false
21334 validateValue : function(value){
21335 if(value.length < 1 || value === this.emptyText){ // if it's blank
21336 if(this.allowBlank){
21337 this.clearInvalid();
21340 this.markInvalid(this.blankText);
21344 if(value.length < this.minLength){
21345 this.markInvalid(String.format(this.minLengthText, this.minLength));
21348 if(value.length > this.maxLength){
21349 this.markInvalid(String.format(this.maxLengthText, this.maxLength));
21353 var vt = Roo.form.VTypes;
21354 if(!vt[this.vtype](value, this)){
21355 this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
21359 if(typeof this.validator == "function"){
21360 var msg = this.validator(value);
21362 this.markInvalid(msg);
21366 if(this.regex && !this.regex.test(value)){
21367 this.markInvalid(this.regexText);
21374 * Selects text in this field
21375 * @param {Number} start (optional) The index where the selection should start (defaults to 0)
21376 * @param {Number} end (optional) The index where the selection should end (defaults to the text length)
21378 selectText : function(start, end){
21379 var v = this.getRawValue();
21381 start = start === undefined ? 0 : start;
21382 end = end === undefined ? v.length : end;
21383 var d = this.el.dom;
21384 if(d.setSelectionRange){
21385 d.setSelectionRange(start, end);
21386 }else if(d.createTextRange){
21387 var range = d.createTextRange();
21388 range.moveStart("character", start);
21389 range.moveEnd("character", v.length-end);
21396 * Automatically grows the field to accomodate the width of the text up to the maximum field width allowed.
21397 * This only takes effect if grow = true, and fires the autosize event.
21399 autoSize : function(){
21400 if(!this.grow || !this.rendered){
21404 this.metrics = Roo.util.TextMetrics.createInstance(this.el);
21407 var v = el.dom.value;
21408 var d = document.createElement('div');
21409 d.appendChild(document.createTextNode(v));
21413 var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + /* add extra padding */ 10, this.growMin));
21414 this.el.setWidth(w);
21415 this.fireEvent("autosize", this, w);
21419 * Ext JS Library 1.1.1
21420 * Copyright(c) 2006-2007, Ext JS, LLC.
21422 * Originally Released Under LGPL - original licence link has changed is not relivant.
21425 * <script type="text/javascript">
21429 * @class Roo.form.Hidden
21430 * @extends Roo.form.TextField
21431 * Simple Hidden element used on forms
21433 * usage: form.add(new Roo.form.HiddenField({ 'name' : 'test1' }));
21436 * Creates a new Hidden form element.
21437 * @param {Object} config Configuration options
21442 // easy hidden field...
21443 Roo.form.Hidden = function(config){
21444 Roo.form.Hidden.superclass.constructor.call(this, config);
21447 Roo.extend(Roo.form.Hidden, Roo.form.TextField, {
21449 inputType: 'hidden',
21452 labelSeparator: '',
21454 itemCls : 'x-form-item-display-none'
21462 * Ext JS Library 1.1.1
21463 * Copyright(c) 2006-2007, Ext JS, LLC.
21465 * Originally Released Under LGPL - original licence link has changed is not relivant.
21468 * <script type="text/javascript">
21472 * @class Roo.form.TriggerField
21473 * @extends Roo.form.TextField
21474 * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
21475 * The trigger has no default action, so you must assign a function to implement the trigger click handler by
21476 * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
21477 * for which you can provide a custom implementation. For example:
21479 var trigger = new Roo.form.TriggerField();
21480 trigger.onTriggerClick = myTriggerFn;
21481 trigger.applyTo('my-field');
21484 * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
21485 * {@link Roo.form.DateField} and {@link Roo.form.ComboBox} are perfect examples of this.
21486 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
21487 * class 'x-form-trigger' by default and triggerClass will be <b>appended</b> if specified.
21489 * Create a new TriggerField.
21490 * @param {Object} config Configuration options (valid {@Roo.form.TextField} config options will also be applied
21491 * to the base TextField)
21493 Roo.form.TriggerField = function(config){
21494 this.mimicing = false;
21495 Roo.form.TriggerField.superclass.constructor.call(this, config);
21498 Roo.extend(Roo.form.TriggerField, Roo.form.TextField, {
21500 * @cfg {String} triggerClass A CSS class to apply to the trigger
21503 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
21504 * {tag: "input", type: "text", size: "16", autocomplete: "off"})
21506 defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
21508 * @cfg {Boolean} hideTrigger True to hide the trigger element and display only the base text field (defaults to false)
21512 /** @cfg {Boolean} grow @hide */
21513 /** @cfg {Number} growMin @hide */
21514 /** @cfg {Number} growMax @hide */
21520 autoSize: Roo.emptyFn,
21524 deferHeight : true,
21527 actionMode : 'wrap',
21529 onResize : function(w, h){
21530 Roo.form.TriggerField.superclass.onResize.apply(this, arguments);
21531 if(typeof w == 'number'){
21532 this.el.setWidth(this.adjustWidth('input', w - this.trigger.getWidth()));
21537 adjustSize : Roo.BoxComponent.prototype.adjustSize,
21540 getResizeEl : function(){
21545 getPositionEl : function(){
21550 alignErrorIcon : function(){
21551 this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
21555 onRender : function(ct, position){
21556 Roo.form.TriggerField.superclass.onRender.call(this, ct, position);
21557 this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
21558 this.trigger = this.wrap.createChild(this.triggerConfig ||
21559 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
21560 if(this.hideTrigger){
21561 this.trigger.setDisplayed(false);
21563 this.initTrigger();
21565 this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
21570 initTrigger : function(){
21571 this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
21572 this.trigger.addClassOnOver('x-form-trigger-over');
21573 this.trigger.addClassOnClick('x-form-trigger-click');
21577 onDestroy : function(){
21579 this.trigger.removeAllListeners();
21580 this.trigger.remove();
21583 this.wrap.remove();
21585 Roo.form.TriggerField.superclass.onDestroy.call(this);
21589 onFocus : function(){
21590 Roo.form.TriggerField.superclass.onFocus.call(this);
21591 if(!this.mimicing){
21592 this.wrap.addClass('x-trigger-wrap-focus');
21593 this.mimicing = true;
21594 Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
21595 if(this.monitorTab){
21596 this.el.on("keydown", this.checkTab, this);
21602 checkTab : function(e){
21603 if(e.getKey() == e.TAB){
21604 this.triggerBlur();
21609 onBlur : function(){
21614 mimicBlur : function(e, t){
21615 if(!this.wrap.contains(t) && this.validateBlur()){
21616 this.triggerBlur();
21621 triggerBlur : function(){
21622 this.mimicing = false;
21623 Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
21624 if(this.monitorTab){
21625 this.el.un("keydown", this.checkTab, this);
21627 this.wrap.removeClass('x-trigger-wrap-focus');
21628 Roo.form.TriggerField.superclass.onBlur.call(this);
21632 // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
21633 validateBlur : function(e, t){
21638 onDisable : function(){
21639 Roo.form.TriggerField.superclass.onDisable.call(this);
21641 this.wrap.addClass('x-item-disabled');
21646 onEnable : function(){
21647 Roo.form.TriggerField.superclass.onEnable.call(this);
21649 this.wrap.removeClass('x-item-disabled');
21654 onShow : function(){
21655 var ae = this.getActionEl();
21658 ae.dom.style.display = '';
21659 ae.dom.style.visibility = 'visible';
21665 onHide : function(){
21666 var ae = this.getActionEl();
21667 ae.dom.style.display = 'none';
21671 * The function that should handle the trigger's click event. This method does nothing by default until overridden
21672 * by an implementing function.
21674 * @param {EventObject} e
21676 onTriggerClick : Roo.emptyFn
21679 // TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
21680 // to be extended by an implementing class. For an example of implementing this class, see the custom
21681 // SearchField implementation here: http://extjs.com/deploy/ext/examples/form/custom.html
21682 Roo.form.TwinTriggerField = Roo.extend(Roo.form.TriggerField, {
21683 initComponent : function(){
21684 Roo.form.TwinTriggerField.superclass.initComponent.call(this);
21686 this.triggerConfig = {
21687 tag:'span', cls:'x-form-twin-triggers', cn:[
21688 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
21689 {tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
21693 getTrigger : function(index){
21694 return this.triggers[index];
21697 initTrigger : function(){
21698 var ts = this.trigger.select('.x-form-trigger', true);
21699 this.wrap.setStyle('overflow', 'hidden');
21700 var triggerField = this;
21701 ts.each(function(t, all, index){
21702 t.hide = function(){
21703 var w = triggerField.wrap.getWidth();
21704 this.dom.style.display = 'none';
21705 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
21707 t.show = function(){
21708 var w = triggerField.wrap.getWidth();
21709 this.dom.style.display = '';
21710 triggerField.el.setWidth(w-triggerField.trigger.getWidth());
21712 var triggerIndex = 'Trigger'+(index+1);
21714 if(this['hide'+triggerIndex]){
21715 t.dom.style.display = 'none';
21717 t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
21718 t.addClassOnOver('x-form-trigger-over');
21719 t.addClassOnClick('x-form-trigger-click');
21721 this.triggers = ts.elements;
21724 onTrigger1Click : Roo.emptyFn,
21725 onTrigger2Click : Roo.emptyFn
21728 * Ext JS Library 1.1.1
21729 * Copyright(c) 2006-2007, Ext JS, LLC.
21731 * Originally Released Under LGPL - original licence link has changed is not relivant.
21734 * <script type="text/javascript">
21738 * @class Roo.form.TextArea
21739 * @extends Roo.form.TextField
21740 * Multiline text field. Can be used as a direct replacement for traditional textarea fields, plus adds
21741 * support for auto-sizing.
21743 * Creates a new TextArea
21744 * @param {Object} config Configuration options
21746 Roo.form.TextArea = function(config){
21747 Roo.form.TextArea.superclass.constructor.call(this, config);
21748 // these are provided exchanges for backwards compat
21749 // minHeight/maxHeight were replaced by growMin/growMax to be
21750 // compatible with TextField growing config values
21751 if(this.minHeight !== undefined){
21752 this.growMin = this.minHeight;
21754 if(this.maxHeight !== undefined){
21755 this.growMax = this.maxHeight;
21759 Roo.extend(Roo.form.TextArea, Roo.form.TextField, {
21761 * @cfg {Number} growMin The minimum height to allow when grow = true (defaults to 60)
21765 * @cfg {Number} growMax The maximum height to allow when grow = true (defaults to 1000)
21769 * @cfg {Boolean} preventScrollbars True to prevent scrollbars from appearing regardless of how much text is
21770 * in the field (equivalent to setting overflow: hidden, defaults to false)
21772 preventScrollbars: false,
21774 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
21775 * {tag: "textarea", style: "width:300px;height:60px;", autocomplete: "off"})
21779 onRender : function(ct, position){
21781 this.defaultAutoCreate = {
21783 style:"width:300px;height:60px;",
21784 autocomplete: "off"
21787 Roo.form.TextArea.superclass.onRender.call(this, ct, position);
21789 this.textSizeEl = Roo.DomHelper.append(document.body, {
21790 tag: "pre", cls: "x-form-grow-sizer"
21792 if(this.preventScrollbars){
21793 this.el.setStyle("overflow", "hidden");
21795 this.el.setHeight(this.growMin);
21799 onDestroy : function(){
21800 if(this.textSizeEl){
21801 this.textSizeEl.parentNode.removeChild(this.textSizeEl);
21803 Roo.form.TextArea.superclass.onDestroy.call(this);
21807 onKeyUp : function(e){
21808 if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
21814 * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
21815 * This only takes effect if grow = true, and fires the autosize event if the height changes.
21817 autoSize : function(){
21818 if(!this.grow || !this.textSizeEl){
21822 var v = el.dom.value;
21823 var ts = this.textSizeEl;
21826 ts.appendChild(document.createTextNode(v));
21829 Roo.fly(ts).setWidth(this.el.getWidth());
21831 v = "  ";
21834 v = v.replace(/\n/g, '<p> </p>');
21836 v += " \n ";
21839 var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
21840 if(h != this.lastHeight){
21841 this.lastHeight = h;
21842 this.el.setHeight(h);
21843 this.fireEvent("autosize", this, h);
21848 * Ext JS Library 1.1.1
21849 * Copyright(c) 2006-2007, Ext JS, LLC.
21851 * Originally Released Under LGPL - original licence link has changed is not relivant.
21854 * <script type="text/javascript">
21859 * @class Roo.form.NumberField
21860 * @extends Roo.form.TextField
21861 * Numeric text field that provides automatic keystroke filtering and numeric validation.
21863 * Creates a new NumberField
21864 * @param {Object} config Configuration options
21866 Roo.form.NumberField = function(config){
21867 Roo.form.NumberField.superclass.constructor.call(this, config);
21870 Roo.extend(Roo.form.NumberField, Roo.form.TextField, {
21872 * @cfg {String} fieldClass The default CSS class for the field (defaults to "x-form-field x-form-num-field")
21874 fieldClass: "x-form-field x-form-num-field",
21876 * @cfg {Boolean} allowDecimals False to disallow decimal values (defaults to true)
21878 allowDecimals : true,
21880 * @cfg {String} decimalSeparator Character(s) to allow as the decimal separator (defaults to '.')
21882 decimalSeparator : ".",
21884 * @cfg {Number} decimalPrecision The maximum precision to display after the decimal separator (defaults to 2)
21886 decimalPrecision : 2,
21888 * @cfg {Boolean} allowNegative False to prevent entering a negative sign (defaults to true)
21890 allowNegative : true,
21892 * @cfg {Number} minValue The minimum allowed value (defaults to Number.NEGATIVE_INFINITY)
21894 minValue : Number.NEGATIVE_INFINITY,
21896 * @cfg {Number} maxValue The maximum allowed value (defaults to Number.MAX_VALUE)
21898 maxValue : Number.MAX_VALUE,
21900 * @cfg {String} minText Error text to display if the minimum value validation fails (defaults to "The minimum value for this field is {minValue}")
21902 minText : "The minimum value for this field is {0}",
21904 * @cfg {String} maxText Error text to display if the maximum value validation fails (defaults to "The maximum value for this field is {maxValue}")
21906 maxText : "The maximum value for this field is {0}",
21908 * @cfg {String} nanText Error text to display if the value is not a valid number. For example, this can happen
21909 * if a valid character like '.' or '-' is left in the field with no number (defaults to "{value} is not a valid number")
21911 nanText : "{0} is not a valid number",
21914 initEvents : function(){
21915 Roo.form.NumberField.superclass.initEvents.call(this);
21916 var allowed = "0123456789";
21917 if(this.allowDecimals){
21918 allowed += this.decimalSeparator;
21920 if(this.allowNegative){
21923 this.stripCharsRe = new RegExp('[^'+allowed+']', 'gi');
21924 var keyPress = function(e){
21925 var k = e.getKey();
21926 if(!Roo.isIE && (e.isSpecialKey() || k == e.BACKSPACE || k == e.DELETE)){
21929 var c = e.getCharCode();
21930 if(allowed.indexOf(String.fromCharCode(c)) === -1){
21934 this.el.on("keypress", keyPress, this);
21938 validateValue : function(value){
21939 if(!Roo.form.NumberField.superclass.validateValue.call(this, value)){
21942 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
21945 var num = this.parseValue(value);
21947 this.markInvalid(String.format(this.nanText, value));
21950 if(num < this.minValue){
21951 this.markInvalid(String.format(this.minText, this.minValue));
21954 if(num > this.maxValue){
21955 this.markInvalid(String.format(this.maxText, this.maxValue));
21961 getValue : function(){
21962 return this.fixPrecision(this.parseValue(Roo.form.NumberField.superclass.getValue.call(this)));
21966 parseValue : function(value){
21967 value = parseFloat(String(value).replace(this.decimalSeparator, "."));
21968 return isNaN(value) ? '' : value;
21972 fixPrecision : function(value){
21973 var nan = isNaN(value);
21974 if(!this.allowDecimals || this.decimalPrecision == -1 || nan || !value){
21975 return nan ? '' : value;
21977 return parseFloat(value).toFixed(this.decimalPrecision);
21980 setValue : function(v){
21981 Roo.form.NumberField.superclass.setValue.call(this, String(v).replace(".", this.decimalSeparator));
21985 decimalPrecisionFcn : function(v){
21986 return Math.floor(v);
21989 beforeBlur : function(){
21990 var v = this.parseValue(this.getRawValue());
21992 this.setValue(this.fixPrecision(v));
21997 * Ext JS Library 1.1.1
21998 * Copyright(c) 2006-2007, Ext JS, LLC.
22000 * Originally Released Under LGPL - original licence link has changed is not relivant.
22003 * <script type="text/javascript">
22007 * @class Roo.form.DateField
22008 * @extends Roo.form.TriggerField
22009 * Provides a date input field with a {@link Roo.DatePicker} dropdown and automatic date validation.
22011 * Create a new DateField
22012 * @param {Object} config
22014 Roo.form.DateField = function(config){
22015 Roo.form.DateField.superclass.constructor.call(this, config);
22021 * Fires when a date is selected
22022 * @param {Roo.form.DateField} combo This combo box
22023 * @param {Date} date The date selected
22030 if(typeof this.minValue == "string") this.minValue = this.parseDate(this.minValue);
22031 if(typeof this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue);
22032 this.ddMatch = null;
22033 if(this.disabledDates){
22034 var dd = this.disabledDates;
22036 for(var i = 0; i < dd.length; i++){
22038 if(i != dd.length-1) re += "|";
22040 this.ddMatch = new RegExp(re + ")");
22044 Roo.extend(Roo.form.DateField, Roo.form.TriggerField, {
22046 * @cfg {String} format
22047 * The default date format string which can be overriden for localization support. The format must be
22048 * valid according to {@link Date#parseDate} (defaults to 'm/d/y').
22052 * @cfg {String} altFormats
22053 * Multiple date formats separated by "|" to try when parsing a user input value and it doesn't match the defined
22054 * format (defaults to 'm/d/Y|m-d-y|m-d-Y|m/d|m-d|d').
22056 altFormats : "m/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d",
22058 * @cfg {Array} disabledDays
22059 * An array of days to disable, 0 based. For example, [0, 6] disables Sunday and Saturday (defaults to null).
22061 disabledDays : null,
22063 * @cfg {String} disabledDaysText
22064 * The tooltip to display when the date falls on a disabled day (defaults to 'Disabled')
22066 disabledDaysText : "Disabled",
22068 * @cfg {Array} disabledDates
22069 * An array of "dates" to disable, as strings. These strings will be used to build a dynamic regular
22070 * expression so they are very powerful. Some examples:
22072 * <li>["03/08/2003", "09/16/2003"] would disable those exact dates</li>
22073 * <li>["03/08", "09/16"] would disable those days for every year</li>
22074 * <li>["^03/08"] would only match the beginning (useful if you are using short years)</li>
22075 * <li>["03/../2006"] would disable every day in March 2006</li>
22076 * <li>["^03"] would disable every day in every March</li>
22078 * In order to support regular expressions, if you are using a date format that has "." in it, you will have to
22079 * escape the dot when restricting dates. For example: ["03\\.08\\.03"].
22081 disabledDates : null,
22083 * @cfg {String} disabledDatesText
22084 * The tooltip text to display when the date falls on a disabled date (defaults to 'Disabled')
22086 disabledDatesText : "Disabled",
22088 * @cfg {Date/String} minValue
22089 * The minimum allowed date. Can be either a Javascript date object or a string date in a
22090 * valid format (defaults to null).
22094 * @cfg {Date/String} maxValue
22095 * The maximum allowed date. Can be either a Javascript date object or a string date in a
22096 * valid format (defaults to null).
22100 * @cfg {String} minText
22101 * The error text to display when the date in the cell is before minValue (defaults to
22102 * 'The date in this field must be after {minValue}').
22104 minText : "The date in this field must be equal to or after {0}",
22106 * @cfg {String} maxText
22107 * The error text to display when the date in the cell is after maxValue (defaults to
22108 * 'The date in this field must be before {maxValue}').
22110 maxText : "The date in this field must be equal to or before {0}",
22112 * @cfg {String} invalidText
22113 * The error text to display when the date in the field is invalid (defaults to
22114 * '{value} is not a valid date - it must be in the format {format}').
22116 invalidText : "{0} is not a valid date - it must be in the format {1}",
22118 * @cfg {String} triggerClass
22119 * An additional CSS class used to style the trigger button. The trigger will always get the
22120 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-date-trigger'
22121 * which displays a calendar icon).
22123 triggerClass : 'x-form-date-trigger',
22127 * @cfg {bool} useIso
22128 * if enabled, then the date field will use a hidden field to store the
22129 * real value as iso formated date. default (false)
22133 * @cfg {String/Object} autoCreate
22134 * A DomHelper element spec, or true for a default element spec (defaults to
22135 * {tag: "input", type: "text", size: "10", autocomplete: "off"})
22138 defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
22141 hiddenField: false,
22143 onRender : function(ct, position)
22145 Roo.form.DateField.superclass.onRender.call(this, ct, position);
22147 this.el.dom.removeAttribute('name');
22148 this.hiddenField = this.el.insertSibling({ tag:'input', type:'hidden', name: this.name },
22150 this.hiddenField.value = this.formatDate(this.value, 'Y-m-d');
22151 // prevent input submission
22152 this.hiddenName = this.name;
22159 validateValue : function(value)
22161 value = this.formatDate(value);
22162 if(!Roo.form.DateField.superclass.validateValue.call(this, value)){
22165 if(value.length < 1){ // if it's blank and textfield didn't flag it then it's valid
22168 var svalue = value;
22169 value = this.parseDate(value);
22171 this.markInvalid(String.format(this.invalidText, svalue, this.format));
22174 var time = value.getTime();
22175 if(this.minValue && time < this.minValue.getTime()){
22176 this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
22179 if(this.maxValue && time > this.maxValue.getTime()){
22180 this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
22183 if(this.disabledDays){
22184 var day = value.getDay();
22185 for(var i = 0; i < this.disabledDays.length; i++) {
22186 if(day === this.disabledDays[i]){
22187 this.markInvalid(this.disabledDaysText);
22192 var fvalue = this.formatDate(value);
22193 if(this.ddMatch && this.ddMatch.test(fvalue)){
22194 this.markInvalid(String.format(this.disabledDatesText, fvalue));
22201 // Provides logic to override the default TriggerField.validateBlur which just returns true
22202 validateBlur : function(){
22203 return !this.menu || !this.menu.isVisible();
22207 * Returns the current date value of the date field.
22208 * @return {Date} The date value
22210 getValue : function(){
22212 return this.hiddenField ? this.hiddenField.value : this.parseDate(Roo.form.DateField.superclass.getValue.call(this)) || "";
22216 * Sets the value of the date field. You can pass a date object or any string that can be parsed into a valid
22217 * date, using DateField.format as the date format, according to the same rules as {@link Date#parseDate}
22218 * (the default format used is "m/d/y").
22221 //All of these calls set the same date value (May 4, 2006)
22223 //Pass a date object:
22224 var dt = new Date('5/4/06');
22225 dateField.setValue(dt);
22227 //Pass a date string (default format):
22228 dateField.setValue('5/4/06');
22230 //Pass a date string (custom format):
22231 dateField.format = 'Y-m-d';
22232 dateField.setValue('2006-5-4');
22234 * @param {String/Date} date The date or valid date string
22236 setValue : function(date){
22237 if (this.hiddenField) {
22238 this.hiddenField.value = this.formatDate(this.parseDate(date), 'Y-m-d');
22240 Roo.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
22244 parseDate : function(value){
22245 if(!value || value instanceof Date){
22248 var v = Date.parseDate(value, this.format);
22249 if(!v && this.altFormats){
22250 if(!this.altFormatsArray){
22251 this.altFormatsArray = this.altFormats.split("|");
22253 for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
22254 v = Date.parseDate(value, this.altFormatsArray[i]);
22261 formatDate : function(date, fmt){
22262 return (!date || !(date instanceof Date)) ?
22263 date : date.dateFormat(fmt || this.format);
22268 select: function(m, d){
22270 this.fireEvent('select', this, d);
22272 show : function(){ // retain focus styling
22276 this.focus.defer(10, this);
22277 var ml = this.menuListeners;
22278 this.menu.un("select", ml.select, this);
22279 this.menu.un("show", ml.show, this);
22280 this.menu.un("hide", ml.hide, this);
22285 // Implements the default empty TriggerField.onTriggerClick function to display the DatePicker
22286 onTriggerClick : function(){
22290 if(this.menu == null){
22291 this.menu = new Roo.menu.DateMenu();
22293 Roo.apply(this.menu.picker, {
22294 showClear: this.allowBlank,
22295 minDate : this.minValue,
22296 maxDate : this.maxValue,
22297 disabledDatesRE : this.ddMatch,
22298 disabledDatesText : this.disabledDatesText,
22299 disabledDays : this.disabledDays,
22300 disabledDaysText : this.disabledDaysText,
22301 format : this.format,
22302 minText : String.format(this.minText, this.formatDate(this.minValue)),
22303 maxText : String.format(this.maxText, this.formatDate(this.maxValue))
22305 this.menu.on(Roo.apply({}, this.menuListeners, {
22308 this.menu.picker.setValue(this.getValue() || new Date());
22309 this.menu.show(this.el, "tl-bl?");
22312 beforeBlur : function(){
22313 var v = this.parseDate(this.getRawValue());
22319 /** @cfg {Boolean} grow @hide */
22320 /** @cfg {Number} growMin @hide */
22321 /** @cfg {Number} growMax @hide */
22328 * Ext JS Library 1.1.1
22329 * Copyright(c) 2006-2007, Ext JS, LLC.
22331 * Originally Released Under LGPL - original licence link has changed is not relivant.
22334 * <script type="text/javascript">
22339 * @class Roo.form.ComboBox
22340 * @extends Roo.form.TriggerField
22341 * A combobox control with support for autocomplete, remote-loading, paging and many other features.
22343 * Create a new ComboBox.
22344 * @param {Object} config Configuration options
22346 Roo.form.ComboBox = function(config){
22347 Roo.form.ComboBox.superclass.constructor.call(this, config);
22351 * Fires when the dropdown list is expanded
22352 * @param {Roo.form.ComboBox} combo This combo box
22357 * Fires when the dropdown list is collapsed
22358 * @param {Roo.form.ComboBox} combo This combo box
22362 * @event beforeselect
22363 * Fires before a list item is selected. Return false to cancel the selection.
22364 * @param {Roo.form.ComboBox} combo This combo box
22365 * @param {Roo.data.Record} record The data record returned from the underlying store
22366 * @param {Number} index The index of the selected item in the dropdown list
22368 'beforeselect' : true,
22371 * Fires when a list item is selected
22372 * @param {Roo.form.ComboBox} combo This combo box
22373 * @param {Roo.data.Record} record The data record returned from the underlying store (or false on clear)
22374 * @param {Number} index The index of the selected item in the dropdown list
22378 * @event beforequery
22379 * Fires before all queries are processed. Return false to cancel the query or set cancel to true.
22380 * The event object passed has these properties:
22381 * @param {Roo.form.ComboBox} combo This combo box
22382 * @param {String} query The query
22383 * @param {Boolean} forceAll true to force "all" query
22384 * @param {Boolean} cancel true to cancel the query
22385 * @param {Object} e The query event object
22387 'beforequery': true
22389 if(this.transform){
22390 this.allowDomMove = false;
22391 var s = Roo.getDom(this.transform);
22392 if(!this.hiddenName){
22393 this.hiddenName = s.name;
22396 this.mode = 'local';
22397 var d = [], opts = s.options;
22398 for(var i = 0, len = opts.length;i < len; i++){
22400 var value = (Roo.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? o.value : o.text;
22402 this.value = value;
22404 d.push([value, o.text]);
22406 this.store = new Roo.data.SimpleStore({
22408 fields: ['value', 'text'],
22411 this.valueField = 'value';
22412 this.displayField = 'text';
22414 s.name = Roo.id(); // wipe out the name in case somewhere else they have a reference
22415 if(!this.lazyRender){
22416 this.target = true;
22417 this.el = Roo.DomHelper.insertBefore(s, this.autoCreate || this.defaultAutoCreate);
22418 s.parentNode.removeChild(s); // remove it
22419 this.render(this.el.parentNode);
22421 s.parentNode.removeChild(s); // remove it
22426 this.store = Roo.factory(this.store, Roo.data);
22429 this.selectedIndex = -1;
22430 if(this.mode == 'local'){
22431 if(config.queryDelay === undefined){
22432 this.queryDelay = 10;
22434 if(config.minChars === undefined){
22440 Roo.extend(Roo.form.ComboBox, Roo.form.TriggerField, {
22442 * @cfg {String/HTMLElement/Element} transform The id, DOM node or element of an existing select to convert to a ComboBox
22445 * @cfg {Boolean} lazyRender True to prevent the ComboBox from rendering until requested (should always be used when
22446 * rendering into an Roo.Editor, defaults to false)
22449 * @cfg {Boolean/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to:
22450 * {tag: "input", type: "text", size: "24", autocomplete: "off"})
22453 * @cfg {Roo.data.Store} store The data store to which this combo is bound (defaults to undefined)
22456 * @cfg {String} title If supplied, a header element is created containing this text and added into the top of
22457 * the dropdown list (defaults to undefined, with no header element)
22461 * @cfg {String/Roo.Template} tpl The template to use to render the output
22465 defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
22467 * @cfg {Number} listWidth The width in pixels of the dropdown list (defaults to the width of the ComboBox field)
22469 listWidth: undefined,
22471 * @cfg {String} displayField The underlying data field name to bind to this CombBox (defaults to undefined if
22472 * mode = 'remote' or 'text' if mode = 'local')
22474 displayField: undefined,
22476 * @cfg {String} valueField The underlying data value name to bind to this CombBox (defaults to undefined if
22477 * mode = 'remote' or 'value' if mode = 'local').
22478 * Note: use of a valueField requires the user make a selection
22479 * in order for a value to be mapped.
22481 valueField: undefined,
22483 * @cfg {String} hiddenName If specified, a hidden form field with this name is dynamically generated to store the
22484 * field's data value (defaults to the underlying DOM element's name)
22486 hiddenName: undefined,
22488 * @cfg {String} listClass CSS class to apply to the dropdown list element (defaults to '')
22492 * @cfg {String} selectedClass CSS class to apply to the selected item in the dropdown list (defaults to 'x-combo-selected')
22494 selectedClass: 'x-combo-selected',
22496 * @cfg {String} triggerClass An additional CSS class used to style the trigger button. The trigger will always get the
22497 * class 'x-form-trigger' and triggerClass will be <b>appended</b> if specified (defaults to 'x-form-arrow-trigger'
22498 * which displays a downward arrow icon).
22500 triggerClass : 'x-form-arrow-trigger',
22502 * @cfg {Boolean/String} shadow True or "sides" for the default effect, "frame" for 4-way shadow, and "drop" for bottom-right
22506 * @cfg {String} listAlign A valid anchor position value. See {@link Roo.Element#alignTo} for details on supported
22507 * anchor positions (defaults to 'tl-bl')
22509 listAlign: 'tl-bl?',
22511 * @cfg {Number} maxHeight The maximum height in pixels of the dropdown list before scrollbars are shown (defaults to 300)
22515 * @cfg {String} triggerAction The action to execute when the trigger field is activated. Use 'all' to run the
22516 * query specified by the allQuery config option (defaults to 'query')
22518 triggerAction: 'query',
22520 * @cfg {Number} minChars The minimum number of characters the user must type before autocomplete and typeahead activate
22521 * (defaults to 4, does not apply if editable = false)
22525 * @cfg {Boolean} typeAhead True to populate and autoselect the remainder of the text being typed after a configurable
22526 * delay (typeAheadDelay) if it matches a known value (defaults to false)
22530 * @cfg {Number} queryDelay The length of time in milliseconds to delay between the start of typing and sending the
22531 * query to filter the dropdown list (defaults to 500 if mode = 'remote' or 10 if mode = 'local')
22535 * @cfg {Number} pageSize If greater than 0, a paging toolbar is displayed in the footer of the dropdown list and the
22536 * filter queries will execute with page start and limit parameters. Only applies when mode = 'remote' (defaults to 0)
22540 * @cfg {Boolean} selectOnFocus True to select any existing text in the field immediately on focus. Only applies
22541 * when editable = true (defaults to false)
22543 selectOnFocus:false,
22545 * @cfg {String} queryParam Name of the query as it will be passed on the querystring (defaults to 'query')
22547 queryParam: 'query',
22549 * @cfg {String} loadingText The text to display in the dropdown list while data is loading. Only applies
22550 * when mode = 'remote' (defaults to 'Loading...')
22552 loadingText: 'Loading...',
22554 * @cfg {Boolean} resizable True to add a resize handle to the bottom of the dropdown list (defaults to false)
22558 * @cfg {Number} handleHeight The height in pixels of the dropdown list resize handle if resizable = true (defaults to 8)
22562 * @cfg {Boolean} editable False to prevent the user from typing text directly into the field, just like a
22563 * traditional select (defaults to true)
22567 * @cfg {String} allQuery The text query to send to the server to return all records for the list with no filtering (defaults to '')
22571 * @cfg {String} mode Set to 'local' if the ComboBox loads local data (defaults to 'remote' which loads from the server)
22575 * @cfg {Number} minListWidth The minimum width of the dropdown list in pixels (defaults to 70, will be ignored if
22576 * listWidth has a higher value)
22580 * @cfg {Boolean} forceSelection True to restrict the selected value to one of the values in the list, false to
22581 * allow the user to set arbitrary text into the field (defaults to false)
22583 forceSelection:false,
22585 * @cfg {Number} typeAheadDelay The length of time in milliseconds to wait until the typeahead text is displayed
22586 * if typeAhead = true (defaults to 250)
22588 typeAheadDelay : 250,
22590 * @cfg {String} valueNotFoundText When using a name/value combo, if the value passed to setValue is not found in
22591 * the store, valueNotFoundText will be displayed as the field text if defined (defaults to undefined)
22593 valueNotFoundText : undefined,
22595 * @cfg {bool} blockFocus Prevents all focus calls, so it can work with things like HTML edtor bar
22597 blockFocus : false,
22600 * @cfg {bool} disableClear Disable showing of clear button.
22602 disableClear : false,
22605 onRender : function(ct, position){
22606 Roo.form.ComboBox.superclass.onRender.call(this, ct, position);
22607 if(this.hiddenName){
22608 this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: (this.hiddenId||this.hiddenName)},
22610 this.hiddenField.value =
22611 this.hiddenValue !== undefined ? this.hiddenValue :
22612 this.value !== undefined ? this.value : '';
22614 // prevent input submission
22615 this.el.dom.removeAttribute('name');
22618 this.el.dom.setAttribute('autocomplete', 'off');
22621 var cls = 'x-combo-list';
22623 this.list = new Roo.Layer({
22624 shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
22627 var lw = this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth);
22628 this.list.setWidth(lw);
22629 this.list.swallowEvent('mousewheel');
22630 this.assetHeight = 0;
22633 this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
22634 this.assetHeight += this.header.getHeight();
22637 this.innerList = this.list.createChild({cls:cls+'-inner'});
22638 this.innerList.on('mouseover', this.onViewOver, this);
22639 this.innerList.on('mousemove', this.onViewMove, this);
22640 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
22642 if(this.allowBlank && !this.pageSize && !this.disableClear){
22643 this.footer = this.list.createChild({cls:cls+'-ft'});
22644 this.pageTb = new Roo.Toolbar(this.footer);
22648 this.footer = this.list.createChild({cls:cls+'-ft'});
22649 this.pageTb = new Roo.PagingToolbar(this.footer, this.store,
22650 {pageSize: this.pageSize});
22654 if (this.pageTb && this.allowBlank && !this.disableClear) {
22656 this.pageTb.add(new Roo.Toolbar.Fill(), {
22657 cls: 'x-btn-icon x-btn-clear',
22659 handler: function()
22662 _this.clearValue();
22663 _this.onSelect(false, -1);
22668 this.assetHeight += this.footer.getHeight();
22673 this.tpl = '<div class="'+cls+'-item">{' + this.displayField + '}</div>';
22676 this.view = new Roo.View(this.innerList, this.tpl, {
22677 singleSelect:true, store: this.store, selectedClass: this.selectedClass
22680 this.view.on('click', this.onViewClick, this);
22682 this.store.on('beforeload', this.onBeforeLoad, this);
22683 this.store.on('load', this.onLoad, this);
22684 this.store.on('loadexception', this.collapse, this);
22686 if(this.resizable){
22687 this.resizer = new Roo.Resizable(this.list, {
22688 pinned:true, handles:'se'
22690 this.resizer.on('resize', function(r, w, h){
22691 this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
22692 this.listWidth = w;
22693 this.innerList.setWidth(w - this.list.getFrameWidth('lr'));
22694 this.restrictHeight();
22696 this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
22698 if(!this.editable){
22699 this.editable = true;
22700 this.setEditable(false);
22705 initEvents : function(){
22706 Roo.form.ComboBox.superclass.initEvents.call(this);
22708 this.keyNav = new Roo.KeyNav(this.el, {
22709 "up" : function(e){
22710 this.inKeyMode = true;
22714 "down" : function(e){
22715 if(!this.isExpanded()){
22716 this.onTriggerClick();
22718 this.inKeyMode = true;
22723 "enter" : function(e){
22724 this.onViewClick();
22728 "esc" : function(e){
22732 "tab" : function(e){
22733 this.onViewClick(false);
22739 doRelay : function(foo, bar, hname){
22740 if(hname == 'down' || this.scope.isExpanded()){
22741 return Roo.KeyNav.prototype.doRelay.apply(this, arguments);
22748 this.queryDelay = Math.max(this.queryDelay || 10,
22749 this.mode == 'local' ? 10 : 250);
22750 this.dqTask = new Roo.util.DelayedTask(this.initQuery, this);
22751 if(this.typeAhead){
22752 this.taTask = new Roo.util.DelayedTask(this.onTypeAhead, this);
22754 if(this.editable !== false){
22755 this.el.on("keyup", this.onKeyUp, this);
22757 if(this.forceSelection){
22758 this.on('blur', this.doForce, this);
22762 onDestroy : function(){
22764 this.view.setStore(null);
22765 this.view.el.removeAllListeners();
22766 this.view.el.remove();
22767 this.view.purgeListeners();
22770 this.list.destroy();
22773 this.store.un('beforeload', this.onBeforeLoad, this);
22774 this.store.un('load', this.onLoad, this);
22775 this.store.un('loadexception', this.collapse, this);
22777 Roo.form.ComboBox.superclass.onDestroy.call(this);
22781 fireKey : function(e){
22782 if(e.isNavKeyPress() && !this.list.isVisible()){
22783 this.fireEvent("specialkey", this, e);
22788 onResize: function(w, h){
22789 Roo.form.ComboBox.superclass.onResize.apply(this, arguments);
22790 if(this.list && this.listWidth === undefined){
22791 var lw = Math.max(w, this.minListWidth);
22792 this.list.setWidth(lw);
22793 this.innerList.setWidth(lw - this.list.getFrameWidth('lr'));
22798 * Allow or prevent the user from directly editing the field text. If false is passed,
22799 * the user will only be able to select from the items defined in the dropdown list. This method
22800 * is the runtime equivalent of setting the 'editable' config option at config time.
22801 * @param {Boolean} value True to allow the user to directly edit the field text
22803 setEditable : function(value){
22804 if(value == this.editable){
22807 this.editable = value;
22809 this.el.dom.setAttribute('readOnly', true);
22810 this.el.on('mousedown', this.onTriggerClick, this);
22811 this.el.addClass('x-combo-noedit');
22813 this.el.dom.setAttribute('readOnly', false);
22814 this.el.un('mousedown', this.onTriggerClick, this);
22815 this.el.removeClass('x-combo-noedit');
22820 onBeforeLoad : function(){
22821 if(!this.hasFocus){
22824 this.innerList.update(this.loadingText ?
22825 '<div class="loading-indicator">'+this.loadingText+'</div>' : '');
22826 this.restrictHeight();
22827 this.selectedIndex = -1;
22831 onLoad : function(){
22832 if(!this.hasFocus){
22835 if(this.store.getCount() > 0){
22837 this.restrictHeight();
22838 if(this.lastQuery == this.allQuery){
22840 this.el.dom.select();
22842 if(!this.selectByValue(this.value, true)){
22843 this.select(0, true);
22847 if(this.typeAhead && this.lastKey != Roo.EventObject.BACKSPACE && this.lastKey != Roo.EventObject.DELETE){
22848 this.taTask.delay(this.typeAheadDelay);
22852 this.onEmptyResults();
22858 onTypeAhead : function(){
22859 if(this.store.getCount() > 0){
22860 var r = this.store.getAt(0);
22861 var newValue = r.data[this.displayField];
22862 var len = newValue.length;
22863 var selStart = this.getRawValue().length;
22864 if(selStart != len){
22865 this.setRawValue(newValue);
22866 this.selectText(selStart, newValue.length);
22872 onSelect : function(record, index){
22873 if(this.fireEvent('beforeselect', this, record, index) !== false){
22874 this.setFromData(index > -1 ? record.data : false);
22876 this.fireEvent('select', this, record, index);
22881 * Returns the currently selected field value or empty string if no value is set.
22882 * @return {String} value The selected value
22884 getValue : function(){
22885 if(this.valueField){
22886 return typeof this.value != 'undefined' ? this.value : '';
22888 return Roo.form.ComboBox.superclass.getValue.call(this);
22893 * Clears any text/value currently set in the field
22895 clearValue : function(){
22896 if(this.hiddenField){
22897 this.hiddenField.value = '';
22900 this.setRawValue('');
22901 this.lastSelectionText = '';
22902 this.applyEmptyText();
22906 * Sets the specified value into the field. If the value finds a match, the corresponding record text
22907 * will be displayed in the field. If the value does not match the data value of an existing item,
22908 * and the valueNotFoundText config option is defined, it will be displayed as the default field text.
22909 * Otherwise the field will be blank (although the value will still be set).
22910 * @param {String} value The value to match
22912 setValue : function(v){
22914 if(this.valueField){
22915 var r = this.findRecord(this.valueField, v);
22917 text = r.data[this.displayField];
22918 }else if(this.valueNotFoundText !== undefined){
22919 text = this.valueNotFoundText;
22922 this.lastSelectionText = text;
22923 if(this.hiddenField){
22924 this.hiddenField.value = v;
22926 Roo.form.ComboBox.superclass.setValue.call(this, text);
22930 * @property {Object} the last set data for the element
22935 * Sets the value of the field based on a object which is related to the record format for the store.
22936 * @param {Object} value the value to set as. or false on reset?
22938 setFromData : function(o){
22939 var dv = ''; // display value
22940 var vv = ''; // value value..
22942 if (this.displayField) {
22943 dv = !o || typeof(o[this.displayField]) == 'undefined' ? '' : o[this.displayField];
22945 // this is an error condition!!!
22946 console.log('no value field set for '+ this.name);
22949 if(this.valueField){
22950 vv = !o || typeof(o[this.valueField]) == 'undefined' ? dv : o[this.valueField];
22952 if(this.hiddenField){
22953 this.hiddenField.value = vv;
22955 this.lastSelectionText = dv;
22956 Roo.form.ComboBox.superclass.setValue.call(this, dv);
22960 // no hidden field.. - we store the value in 'value', but still display
22961 // display field!!!!
22962 this.lastSelectionText = dv;
22963 Roo.form.ComboBox.superclass.setValue.call(this, dv);
22969 reset : function(){
22970 // overridden so that last data is reset..
22971 this.setValue(this.originalValue);
22972 this.clearInvalid();
22973 this.lastData = false;
22976 findRecord : function(prop, value){
22978 if(this.store.getCount() > 0){
22979 this.store.each(function(r){
22980 if(r.data[prop] == value){
22990 onViewMove : function(e, t){
22991 this.inKeyMode = false;
22995 onViewOver : function(e, t){
22996 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
22999 var item = this.view.findItemFromChild(t);
23001 var index = this.view.indexOf(item);
23002 this.select(index, false);
23007 onViewClick : function(doFocus){
23008 var index = this.view.getSelectedIndexes()[0];
23009 var r = this.store.getAt(index);
23011 this.onSelect(r, index);
23013 if(doFocus !== false && !this.blockFocus){
23019 restrictHeight : function(){
23020 this.innerList.dom.style.height = '';
23021 var inner = this.innerList.dom;
23022 var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
23023 this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
23024 this.list.beginUpdate();
23025 this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
23026 this.list.alignTo(this.el, this.listAlign);
23027 this.list.endUpdate();
23031 onEmptyResults : function(){
23036 * Returns true if the dropdown list is expanded, else false.
23038 isExpanded : function(){
23039 return this.list.isVisible();
23043 * Select an item in the dropdown list by its data value. This function does NOT cause the select event to fire.
23044 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
23045 * @param {String} value The data value of the item to select
23046 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
23047 * selected item if it is not currently in view (defaults to true)
23048 * @return {Boolean} True if the value matched an item in the list, else false
23050 selectByValue : function(v, scrollIntoView){
23051 if(v !== undefined && v !== null){
23052 var r = this.findRecord(this.valueField || this.displayField, v);
23054 this.select(this.store.indexOf(r), scrollIntoView);
23062 * Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire.
23063 * The store must be loaded and the list expanded for this function to work, otherwise use setValue.
23064 * @param {Number} index The zero-based index of the list item to select
23065 * @param {Boolean} scrollIntoView False to prevent the dropdown list from autoscrolling to display the
23066 * selected item if it is not currently in view (defaults to true)
23068 select : function(index, scrollIntoView){
23069 this.selectedIndex = index;
23070 this.view.select(index);
23071 if(scrollIntoView !== false){
23072 var el = this.view.getNode(index);
23074 this.innerList.scrollChildIntoView(el, false);
23080 selectNext : function(){
23081 var ct = this.store.getCount();
23083 if(this.selectedIndex == -1){
23085 }else if(this.selectedIndex < ct-1){
23086 this.select(this.selectedIndex+1);
23092 selectPrev : function(){
23093 var ct = this.store.getCount();
23095 if(this.selectedIndex == -1){
23097 }else if(this.selectedIndex != 0){
23098 this.select(this.selectedIndex-1);
23104 onKeyUp : function(e){
23105 if(this.editable !== false && !e.isSpecialKey()){
23106 this.lastKey = e.getKey();
23107 this.dqTask.delay(this.queryDelay);
23112 validateBlur : function(){
23113 return !this.list || !this.list.isVisible();
23117 initQuery : function(){
23118 this.doQuery(this.getRawValue());
23122 doForce : function(){
23123 if(this.el.dom.value.length > 0){
23124 this.el.dom.value =
23125 this.lastSelectionText === undefined ? '' : this.lastSelectionText;
23126 this.applyEmptyText();
23131 * Execute a query to filter the dropdown list. Fires the beforequery event prior to performing the
23132 * query allowing the query action to be canceled if needed.
23133 * @param {String} query The SQL query to execute
23134 * @param {Boolean} forceAll True to force the query to execute even if there are currently fewer characters
23135 * in the field than the minimum specified by the minChars config option. It also clears any filter previously
23136 * saved in the current store (defaults to false)
23138 doQuery : function(q, forceAll){
23139 if(q === undefined || q === null){
23144 forceAll: forceAll,
23148 if(this.fireEvent('beforequery', qe)===false || qe.cancel){
23152 forceAll = qe.forceAll;
23153 if(forceAll === true || (q.length >= this.minChars)){
23154 if(this.lastQuery != q){
23155 this.lastQuery = q;
23156 if(this.mode == 'local'){
23157 this.selectedIndex = -1;
23159 this.store.clearFilter();
23161 this.store.filter(this.displayField, q);
23165 this.store.baseParams[this.queryParam] = q;
23167 params: this.getParams(q)
23172 this.selectedIndex = -1;
23179 getParams : function(q){
23181 //p[this.queryParam] = q;
23184 p.limit = this.pageSize;
23190 * Hides the dropdown list if it is currently expanded. Fires the 'collapse' event on completion.
23192 collapse : function(){
23193 if(!this.isExpanded()){
23197 Roo.get(document).un('mousedown', this.collapseIf, this);
23198 Roo.get(document).un('mousewheel', this.collapseIf, this);
23199 this.fireEvent('collapse', this);
23203 collapseIf : function(e){
23204 if(!e.within(this.wrap) && !e.within(this.list)){
23210 * Expands the dropdown list if it is currently hidden. Fires the 'expand' event on completion.
23212 expand : function(){
23213 if(this.isExpanded() || !this.hasFocus){
23216 this.list.alignTo(this.el, this.listAlign);
23218 Roo.get(document).on('mousedown', this.collapseIf, this);
23219 Roo.get(document).on('mousewheel', this.collapseIf, this);
23220 this.fireEvent('expand', this);
23224 // Implements the default empty TriggerField.onTriggerClick function
23225 onTriggerClick : function(){
23229 if(this.isExpanded()){
23231 if (!this.blockFocus) {
23236 this.hasFocus = true;
23237 if(this.triggerAction == 'all') {
23238 this.doQuery(this.allQuery, true);
23240 this.doQuery(this.getRawValue());
23242 if (!this.blockFocus) {
23249 * @cfg {Boolean} grow
23253 * @cfg {Number} growMin
23257 * @cfg {Number} growMax
23266 * Ext JS Library 1.1.1
23267 * Copyright(c) 2006-2007, Ext JS, LLC.
23269 * Originally Released Under LGPL - original licence link has changed is not relivant.
23272 * <script type="text/javascript">
23275 * @class Roo.form.Checkbox
23276 * @extends Roo.form.Field
23277 * Single checkbox field. Can be used as a direct replacement for traditional checkbox fields.
23279 * Creates a new Checkbox
23280 * @param {Object} config Configuration options
23282 Roo.form.Checkbox = function(config){
23283 Roo.form.Checkbox.superclass.constructor.call(this, config);
23287 * Fires when the checkbox is checked or unchecked.
23288 * @param {Roo.form.Checkbox} this This checkbox
23289 * @param {Boolean} checked The new checked value
23295 Roo.extend(Roo.form.Checkbox, Roo.form.Field, {
23297 * @cfg {String} focusClass The CSS class to use when the checkbox receives focus (defaults to undefined)
23299 focusClass : undefined,
23301 * @cfg {String} fieldClass The default CSS class for the checkbox (defaults to "x-form-field")
23303 fieldClass: "x-form-field",
23305 * @cfg {Boolean} checked True if the the checkbox should render already checked (defaults to false)
23309 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
23310 * {tag: "input", type: "checkbox", autocomplete: "off"})
23312 defaultAutoCreate : { tag: "input", type: 'hidden', autocomplete: "off"},
23314 * @cfg {String} boxLabel The text that appears beside the checkbox
23318 * @cfg {String} inputValue The value that should go into the generated input element's value attribute
23322 * @cfg {String} valueOff The value that should go into the generated input element's value when unchecked.
23324 valueOff: '0', // value when not checked..
23326 actionMode : 'viewEl',
23329 itemCls : 'x-menu-check-item x-form-item',
23330 groupClass : 'x-menu-group-item',
23331 inputType : 'hidden',
23334 inSetChecked: false, // check that we are not calling self...
23336 inputElement: false, // real input element?
23337 basedOn: false, // ????
23339 isFormField: true, // not sure where this is needed!!!!
23341 onResize : function(){
23342 Roo.form.Checkbox.superclass.onResize.apply(this, arguments);
23343 if(!this.boxLabel){
23344 this.el.alignTo(this.wrap, 'c-c');
23348 initEvents : function(){
23349 Roo.form.Checkbox.superclass.initEvents.call(this);
23350 this.el.on("click", this.onClick, this);
23351 this.el.on("change", this.onClick, this);
23355 getResizeEl : function(){
23359 getPositionEl : function(){
23364 onRender : function(ct, position){
23365 Roo.form.Checkbox.superclass.onRender.call(this, ct, position);
23367 if(this.inputValue !== undefined){
23368 this.el.dom.value = this.inputValue;
23371 //this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
23372 this.wrap = this.el.wrap({cls: 'x-menu-check-item '});
23373 var viewEl = this.wrap.createChild({
23374 tag: 'img', cls: 'x-menu-item-icon', style: 'margin: 0px;' ,src : Roo.BLANK_IMAGE_URL });
23375 this.viewEl = viewEl;
23376 this.wrap.on('click', this.onClick, this);
23378 this.el.on('DOMAttrModified', this.setFromHidden, this); //ff
23379 this.el.on('propertychange', this.setFromHidden, this); //ie
23384 this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
23385 // viewEl.on('click', this.onClick, this);
23387 //if(this.checked){
23388 this.setChecked(this.checked);
23390 //this.checked = this.el.dom;
23396 initValue : Roo.emptyFn,
23399 * Returns the checked state of the checkbox.
23400 * @return {Boolean} True if checked, else false
23402 getValue : function(){
23404 return String(this.el.dom.value) == String(this.inputValue ) ? this.inputValue : this.valueOff;
23406 return this.valueOff;
23411 onClick : function(){
23412 this.setChecked(!this.checked);
23414 //if(this.el.dom.checked != this.checked){
23415 // this.setValue(this.el.dom.checked);
23420 * Sets the checked state of the checkbox.
23421 * @param {Boolean/String} checked True, 'true', '1', or 'on' to check the checkbox, any other value will uncheck it.
23423 setValue : function(v,suppressEvent){
23424 //this.checked = (v === true || v === 'true' || v == '1' || String(v).toLowerCase() == 'on');
23425 //if(this.el && this.el.dom){
23426 // this.el.dom.checked = this.checked;
23427 // this.el.dom.defaultChecked = this.checked;
23429 this.setChecked(v === this.inputValue);
23430 //this.fireEvent("check", this, this.checked);
23433 setChecked : function(state,suppressEvent)
23435 if (this.inSetChecked) {
23436 this.checked = state;
23442 this.wrap[state ? 'addClass' : 'removeClass']('x-menu-item-checked');
23444 this.checked = state;
23445 if(suppressEvent !== true){
23446 this.fireEvent('checkchange', this, state);
23448 this.inSetChecked = true;
23449 this.el.dom.value = state ? this.inputValue : this.valueOff;
23450 this.inSetChecked = false;
23453 // handle setting of hidden value by some other method!!?!?
23454 setFromHidden: function()
23459 //console.log("SET FROM HIDDEN");
23460 //alert('setFrom hidden');
23461 this.setValue(this.el.dom.value);
23464 onDestroy : function()
23467 Roo.get(this.viewEl).remove();
23470 Roo.form.Checkbox.superclass.onDestroy.call(this);
23475 * Ext JS Library 1.1.1
23476 * Copyright(c) 2006-2007, Ext JS, LLC.
23478 * Originally Released Under LGPL - original licence link has changed is not relivant.
23481 * <script type="text/javascript">
23485 * @class Roo.form.Radio
23486 * @extends Roo.form.Checkbox
23487 * Single radio field. Same as Checkbox, but provided as a convenience for automatically setting the input type.
23488 * Radio grouping is handled automatically by the browser if you give each radio in a group the same name.
23490 * Creates a new Radio
23491 * @param {Object} config Configuration options
23493 Roo.form.Radio = function(){
23494 Roo.form.Radio.superclass.constructor.apply(this, arguments);
23496 Roo.extend(Roo.form.Radio, Roo.form.Checkbox, {
23497 inputType: 'radio',
23500 * If this radio is part of a group, it will return the selected value
23503 getGroupValue : function(){
23504 return this.el.up('form').child('input[name='+this.el.dom.name+']:checked', true).value;
23506 });//<script type="text/javascript">
23509 * Ext JS Library 1.1.1
23510 * Copyright(c) 2006-2007, Ext JS, LLC.
23511 * licensing@extjs.com
23513 * http://www.extjs.com/license
23519 * Default CSS appears to render it as fixed text by default (should really be Sans-Serif)
23520 * - IE ? - no idea how much works there.
23528 * @class Ext.form.HtmlEditor
23529 * @extends Ext.form.Field
23530 * Provides a lightweight HTML Editor component.
23531 * WARNING - THIS CURRENTlY ONLY WORKS ON FIREFOX - USE FCKeditor for a cross platform version
23533 * <br><br><b>Note: The focus/blur and validation marking functionality inherited from Ext.form.Field is NOT
23534 * supported by this editor.</b><br/><br/>
23535 * An Editor is a sensitive component that can't be used in all spots standard fields can be used. Putting an Editor within
23536 * any element that has display set to 'none' can cause problems in Safari and Firefox.<br/><br/>
23538 Roo.form.HtmlEditor = Roo.extend(Roo.form.Field, {
23540 * @cfg {Array} toolbars Array of toolbars. - defaults to just the Standard one
23544 * @cfg {String} createLinkText The default text for the create link prompt
23546 createLinkText : 'Please enter the URL for the link:',
23548 * @cfg {String} defaultLinkValue The default value for the create link prompt (defaults to http:/ /)
23550 defaultLinkValue : 'http:/'+'/',
23556 // private properties
23557 validationEvent : false,
23559 initialized : false,
23561 sourceEditMode : false,
23562 onFocus : Roo.emptyFn,
23564 hideMode:'offsets',
23565 defaultAutoCreate : {
23567 style:"width:500px;height:300px;",
23568 autocomplete: "off"
23572 initComponent : function(){
23575 * @event initialize
23576 * Fires when the editor is fully initialized (including the iframe)
23577 * @param {HtmlEditor} this
23582 * Fires when the editor is first receives the focus. Any insertion must wait
23583 * until after this event.
23584 * @param {HtmlEditor} this
23588 * @event beforesync
23589 * Fires before the textarea is updated with content from the editor iframe. Return false
23590 * to cancel the sync.
23591 * @param {HtmlEditor} this
23592 * @param {String} html
23596 * @event beforepush
23597 * Fires before the iframe editor is updated with content from the textarea. Return false
23598 * to cancel the push.
23599 * @param {HtmlEditor} this
23600 * @param {String} html
23605 * Fires when the textarea is updated with content from the editor iframe.
23606 * @param {HtmlEditor} this
23607 * @param {String} html
23612 * Fires when the iframe editor is updated with content from the textarea.
23613 * @param {HtmlEditor} this
23614 * @param {String} html
23618 * @event editmodechange
23619 * Fires when the editor switches edit modes
23620 * @param {HtmlEditor} this
23621 * @param {Boolean} sourceEdit True if source edit, false if standard editing.
23623 editmodechange: true,
23625 * @event editorevent
23626 * Fires when on any editor (mouse up/down cursor movement etc.) - used for toolbar hooks.
23627 * @param {HtmlEditor} this
23634 * Protected method that will not generally be called directly. It
23635 * is called when the editor creates its toolbar. Override this method if you need to
23636 * add custom toolbar buttons.
23637 * @param {HtmlEditor} editor
23639 createToolbar : function(editor){
23640 if (!editor.toolbars || !editor.toolbars.length) {
23641 editor.toolbars = [ new Roo.form.HtmlEditor.ToolbarStandard() ]; // can be empty?
23644 for (var i =0 ; i < editor.toolbars.length;i++) {
23645 editor.toolbars[i].init(editor);
23652 * Protected method that will not generally be called directly. It
23653 * is called when the editor initializes the iframe with HTML contents. Override this method if you
23654 * want to change the initialization markup of the iframe (e.g. to add stylesheets).
23656 getDocMarkup : function(){
23657 return '<html><head><style type="text/css">body{border:0;margin:0;padding:3px;height:98%;cursor:text;}</style></head><body></body></html>';
23661 onRender : function(ct, position){
23662 Roo.form.HtmlEditor.superclass.onRender.call(this, ct, position);
23663 this.el.dom.style.border = '0 none';
23664 this.el.dom.setAttribute('tabIndex', -1);
23665 this.el.addClass('x-hidden');
23666 if(Roo.isIE){ // fix IE 1px bogus margin
23667 this.el.applyStyles('margin-top:-1px;margin-bottom:-1px;')
23669 this.wrap = this.el.wrap({
23670 cls:'x-html-editor-wrap', cn:{cls:'x-html-editor-tb'}
23673 this.frameId = Roo.id();
23674 this.createToolbar(this);
23681 var iframe = this.wrap.createChild({
23684 name: this.frameId,
23685 frameBorder : 'no',
23686 'src' : Roo.SSL_SECURE_URL ? Roo.SSL_SECURE_URL : "javascript:false"
23689 // console.log(iframe);
23690 //this.wrap.dom.appendChild(iframe);
23692 this.iframe = iframe.dom;
23694 this.assignDocWin();
23696 this.doc.designMode = 'on';
23699 this.doc.write(this.getDocMarkup());
23703 var task = { // must defer to wait for browser to be ready
23705 //console.log("run task?" + this.doc.readyState);
23706 this.assignDocWin();
23707 if(this.doc.body || this.doc.readyState == 'complete'){
23711 this.doc.designMode="on";
23715 Roo.TaskMgr.stop(task);
23716 this.initEditor.defer(10, this);
23723 Roo.TaskMgr.start(task);
23726 this.setSize(this.el.getSize());
23731 onResize : function(w, h){
23732 Roo.form.HtmlEditor.superclass.onResize.apply(this, arguments);
23733 if(this.el && this.iframe){
23734 if(typeof w == 'number'){
23735 var aw = w - this.wrap.getFrameWidth('lr');
23736 this.el.setWidth(this.adjustWidth('textarea', aw));
23737 this.iframe.style.width = aw + 'px';
23739 if(typeof h == 'number'){
23741 for (var i =0; i < this.toolbars.length;i++) {
23742 // fixme - ask toolbars for heights?
23743 tbh += this.toolbars[i].tb.el.getHeight();
23749 var ah = h - this.wrap.getFrameWidth('tb') - tbh;// this.tb.el.getHeight();
23750 this.el.setHeight(this.adjustWidth('textarea', ah));
23751 this.iframe.style.height = ah + 'px';
23753 (this.doc.body || this.doc.documentElement).style.height = (ah - (this.iframePad*2)) + 'px';
23760 * Toggles the editor between standard and source edit mode.
23761 * @param {Boolean} sourceEdit (optional) True for source edit, false for standard
23763 toggleSourceEdit : function(sourceEditMode){
23765 this.sourceEditMode = sourceEditMode === true;
23767 if(this.sourceEditMode){
23770 this.iframe.className = 'x-hidden';
23771 this.el.removeClass('x-hidden');
23772 this.el.dom.removeAttribute('tabIndex');
23777 this.iframe.className = '';
23778 this.el.addClass('x-hidden');
23779 this.el.dom.setAttribute('tabIndex', -1);
23782 this.setSize(this.wrap.getSize());
23783 this.fireEvent('editmodechange', this, this.sourceEditMode);
23786 // private used internally
23787 createLink : function(){
23788 var url = prompt(this.createLinkText, this.defaultLinkValue);
23789 if(url && url != 'http:/'+'/'){
23790 this.relayCmd('createlink', url);
23794 // private (for BoxComponent)
23795 adjustSize : Roo.BoxComponent.prototype.adjustSize,
23797 // private (for BoxComponent)
23798 getResizeEl : function(){
23802 // private (for BoxComponent)
23803 getPositionEl : function(){
23808 initEvents : function(){
23809 this.originalValue = this.getValue();
23813 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23816 markInvalid : Roo.emptyFn,
23818 * Overridden and disabled. The editor element does not support standard valid/invalid marking. @hide
23821 clearInvalid : Roo.emptyFn,
23823 setValue : function(v){
23824 Roo.form.HtmlEditor.superclass.setValue.call(this, v);
23829 * Protected method that will not generally be called directly. If you need/want
23830 * custom HTML cleanup, this is the method you should override.
23831 * @param {String} html The HTML to be cleaned
23832 * return {String} The cleaned HTML
23834 cleanHtml : function(html){
23835 html = String(html);
23836 if(html.length > 5){
23837 if(Roo.isSafari){ // strip safari nonsense
23838 html = html.replace(/\sclass="(?:Apple-style-span|khtml-block-placeholder)"/gi, '');
23841 if(html == ' '){
23848 * Protected method that will not generally be called directly. Syncs the contents
23849 * of the editor iframe with the textarea.
23851 syncValue : function(){
23852 if(this.initialized){
23853 var bd = (this.doc.body || this.doc.documentElement);
23854 var html = bd.innerHTML;
23856 var bs = bd.getAttribute('style'); // Safari puts text-align styles on the body element!
23857 var m = bs.match(/text-align:(.*?);/i);
23859 html = '<div style="'+m[0]+'">' + html + '</div>';
23862 html = this.cleanHtml(html);
23863 if(this.fireEvent('beforesync', this, html) !== false){
23864 this.el.dom.value = html;
23865 this.fireEvent('sync', this, html);
23871 * Protected method that will not generally be called directly. Pushes the value of the textarea
23872 * into the iframe editor.
23874 pushValue : function(){
23875 if(this.initialized){
23876 var v = this.el.dom.value;
23880 if(this.fireEvent('beforepush', this, v) !== false){
23881 (this.doc.body || this.doc.documentElement).innerHTML = v;
23882 this.fireEvent('push', this, v);
23888 deferFocus : function(){
23889 this.focus.defer(10, this);
23893 focus : function(){
23894 if(this.win && !this.sourceEditMode){
23901 assignDocWin: function()
23903 var iframe = this.iframe;
23906 this.doc = iframe.contentWindow.document;
23907 this.win = iframe.contentWindow;
23909 this.doc = (iframe.contentDocument || Roo.get(this.frameId).dom.document);
23910 this.win = Roo.get(this.frameId).dom.contentWindow;
23915 initEditor : function(){
23916 //console.log("INIT EDITOR");
23917 this.assignDocWin();
23921 this.doc.designMode="on";
23923 this.doc.write(this.getDocMarkup());
23926 var dbody = (this.doc.body || this.doc.documentElement);
23927 //var ss = this.el.getStyles('font-size', 'font-family', 'background-image', 'background-repeat');
23928 // this copies styles from the containing element into thsi one..
23929 // not sure why we need all of this..
23930 var ss = this.el.getStyles('font-size', 'background-image', 'background-repeat');
23931 ss['background-attachment'] = 'fixed'; // w3c
23932 dbody.bgProperties = 'fixed'; // ie
23933 Roo.DomHelper.applyStyles(dbody, ss);
23934 Roo.EventManager.on(this.doc, {
23935 'mousedown': this.onEditorEvent,
23936 'dblclick': this.onEditorEvent,
23937 'click': this.onEditorEvent,
23938 'keyup': this.onEditorEvent,
23943 Roo.EventManager.on(this.doc, 'keypress', this.applyCommand, this);
23945 if(Roo.isIE || Roo.isSafari || Roo.isOpera){
23946 Roo.EventManager.on(this.doc, 'keydown', this.fixKeys, this);
23948 this.initialized = true;
23950 this.fireEvent('initialize', this);
23955 onDestroy : function(){
23961 for (var i =0; i < this.toolbars.length;i++) {
23962 // fixme - ask toolbars for heights?
23963 this.toolbars[i].onDestroy();
23966 this.wrap.dom.innerHTML = '';
23967 this.wrap.remove();
23972 onFirstFocus : function(){
23974 this.assignDocWin();
23977 this.activated = true;
23978 for (var i =0; i < this.toolbars.length;i++) {
23979 this.toolbars[i].onFirstFocus();
23982 if(Roo.isGecko){ // prevent silly gecko errors
23984 var s = this.win.getSelection();
23985 if(!s.focusNode || s.focusNode.nodeType != 3){
23986 var r = s.getRangeAt(0);
23987 r.selectNodeContents((this.doc.body || this.doc.documentElement));
23992 this.execCmd('useCSS', true);
23993 this.execCmd('styleWithCSS', false);
23996 this.fireEvent('activate', this);
24000 adjustFont: function(btn){
24001 var adjust = btn.cmd == 'increasefontsize' ? 1 : -1;
24002 //if(Roo.isSafari){ // safari
24005 var v = parseInt(this.doc.queryCommandValue('FontSize')|| 3, 10);
24006 if(Roo.isSafari){ // safari
24007 var sm = { 10 : 1, 13: 2, 16:3, 18:4, 24: 5, 32:6, 48: 7 };
24008 v = (v < 10) ? 10 : v;
24009 v = (v > 48) ? 48 : v;
24010 v = typeof(sm[v]) == 'undefined' ? 1 : sm[v];
24015 v = Math.max(1, v+adjust);
24017 this.execCmd('FontSize', v );
24020 onEditorEvent : function(e){
24021 this.fireEvent('editorevent', this, e);
24022 // this.updateToolbar();
24026 insertTag : function(tg)
24028 // could be a bit smarter... -> wrap the current selected tRoo..
24030 this.execCmd("formatblock", tg);
24034 insertText : function(txt)
24038 range = this.createRange();
24039 range.deleteContents();
24040 //alert(Sender.getAttribute('label'));
24042 range.insertNode(this.doc.createTextNode(txt));
24046 relayBtnCmd : function(btn){
24047 this.relayCmd(btn.cmd);
24051 * Executes a Midas editor command on the editor document and performs necessary focus and
24052 * toolbar updates. <b>This should only be called after the editor is initialized.</b>
24053 * @param {String} cmd The Midas command
24054 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
24056 relayCmd : function(cmd, value){
24058 this.execCmd(cmd, value);
24059 this.fireEvent('editorevent', this);
24060 //this.updateToolbar();
24065 * Executes a Midas editor command directly on the editor document.
24066 * For visual commands, you should use {@link #relayCmd} instead.
24067 * <b>This should only be called after the editor is initialized.</b>
24068 * @param {String} cmd The Midas command
24069 * @param {String/Boolean} value (optional) The value to pass to the command (defaults to null)
24071 execCmd : function(cmd, value){
24072 this.doc.execCommand(cmd, false, value === undefined ? null : value);
24077 applyCommand : function(e){
24079 var c = e.getCharCode(), cmd;
24081 c = String.fromCharCode(c);
24097 e.preventDefault();
24104 * Inserts the passed text at the current cursor position. Note: the editor must be initialized and activated
24106 * @param {String} text
24108 insertAtCursor : function(text){
24109 if(!this.activated){
24114 var r = this.doc.selection.createRange();
24121 }else if(Roo.isGecko || Roo.isOpera){
24123 this.execCmd('InsertHTML', text);
24125 }else if(Roo.isSafari){
24126 this.execCmd('InsertText', text);
24132 fixKeys : function(){ // load time branching for fastest keydown performance
24134 return function(e){
24135 var k = e.getKey(), r;
24138 r = this.doc.selection.createRange();
24141 r.pasteHTML('    ');
24144 }else if(k == e.ENTER){
24145 r = this.doc.selection.createRange();
24147 var target = r.parentElement();
24148 if(!target || target.tagName.toLowerCase() != 'li'){
24150 r.pasteHTML('<br />');
24157 }else if(Roo.isOpera){
24158 return function(e){
24159 var k = e.getKey();
24163 this.execCmd('InsertHTML','    ');
24167 }else if(Roo.isSafari){
24168 return function(e){
24169 var k = e.getKey();
24172 this.execCmd('InsertText','\t');
24179 getAllAncestors: function()
24181 var p = this.getSelectedNode();
24184 a.push(p); // push blank onto stack..
24185 p = this.getParentElement();
24189 while (p && (p.nodeType == 1) && (p.tagName.toLowerCase() != 'body')) {
24193 a.push(this.doc.body);
24197 lastSelNode : false,
24200 getSelection : function()
24202 this.assignDocWin();
24203 return Roo.isIE ? this.doc.selection : this.win.getSelection();
24206 getSelectedNode: function()
24208 // this may only work on Gecko!!!
24210 // should we cache this!!!!
24215 var range = this.createRange(this.getSelection());
24218 var parent = range.parentElement();
24220 var testRange = range.duplicate();
24221 testRange.moveToElementText(parent);
24222 if (testRange.inRange(range)) {
24225 if ((parent.nodeType != 1) || (parent.tagName.toLowerCase() == 'body')) {
24228 parent = parent.parentElement;
24234 var ar = range.endContainer.childNodes;
24236 ar = range.commonAncestorContainer.childNodes;
24237 //alert(ar.length);
24240 var other_nodes = [];
24241 var has_other_nodes = false;
24242 for (var i=0;i<ar.length;i++) {
24243 if ((ar[i].nodeType == 3) && (!ar[i].data.length)) { // empty text ?
24246 // fullly contained node.
24248 if (this.rangeIntersectsNode(range,ar[i]) && this.rangeCompareNode(range,ar[i]) == 3) {
24253 // probably selected..
24254 if ((ar[i].nodeType == 1) && this.rangeIntersectsNode(range,ar[i]) && (this.rangeCompareNode(range,ar[i]) > 0)) {
24255 other_nodes.push(ar[i]);
24258 if (!this.rangeIntersectsNode(range,ar[i])|| (this.rangeCompareNode(range,ar[i]) == 0)) {
24263 has_other_nodes = true;
24265 if (!nodes.length && other_nodes.length) {
24266 nodes= other_nodes;
24268 if (has_other_nodes || !nodes.length || (nodes.length > 1)) {
24274 createRange: function(sel)
24276 // this has strange effects when using with
24277 // top toolbar - not sure if it's a great idea.
24278 //this.editor.contentWindow.focus();
24279 if (typeof sel != "undefined") {
24281 return sel.getRangeAt ? sel.getRangeAt(0) : sel.createRange();
24283 return this.doc.createRange();
24286 return this.doc.createRange();
24289 getParentElement: function()
24292 this.assignDocWin();
24293 var sel = Roo.isIE ? this.doc.selection : this.win.getSelection();
24295 var range = this.createRange(sel);
24298 var p = range.commonAncestorContainer;
24299 while (p.nodeType == 3) { // text node
24311 // BC Hacks - cause I cant work out what i was trying to do..
24312 rangeIntersectsNode : function(range, node)
24314 var nodeRange = node.ownerDocument.createRange();
24316 nodeRange.selectNode(node);
24319 nodeRange.selectNodeContents(node);
24322 return range.compareBoundaryPoints(Range.END_TO_START, nodeRange) == -1 &&
24323 range.compareBoundaryPoints(Range.START_TO_END, nodeRange) == 1;
24325 rangeCompareNode : function(range, node) {
24326 var nodeRange = node.ownerDocument.createRange();
24328 nodeRange.selectNode(node);
24330 nodeRange.selectNodeContents(node);
24332 var nodeIsBefore = range.compareBoundaryPoints(Range.START_TO_START, nodeRange) == 1;
24333 var nodeIsAfter = range.compareBoundaryPoints(Range.END_TO_END, nodeRange) == -1;
24335 if (nodeIsBefore && !nodeIsAfter)
24337 if (!nodeIsBefore && nodeIsAfter)
24339 if (nodeIsBefore && nodeIsAfter)
24347 // hide stuff that is not compatible
24361 * @event specialkey
24365 * @cfg {String} fieldClass @hide
24368 * @cfg {String} focusClass @hide
24371 * @cfg {String} autoCreate @hide
24374 * @cfg {String} inputType @hide
24377 * @cfg {String} invalidClass @hide
24380 * @cfg {String} invalidText @hide
24383 * @cfg {String} msgFx @hide
24386 * @cfg {String} validateOnBlur @hide
24388 });// <script type="text/javascript">
24391 * Ext JS Library 1.1.1
24392 * Copyright(c) 2006-2007, Ext JS, LLC.
24398 * @class Roo.form.HtmlEditorToolbar1
24403 new Roo.form.HtmlEditor({
24406 new Roo.form.HtmlEditorToolbar1({
24407 disable : { fonts: 1 , format: 1, ..., ... , ...],
24413 * @cfg {Object} disable List of elements to disable..
24414 * @cfg {Array} btns List of additional buttons.
24418 * .x-html-editor-tb .x-edit-none .x-btn-text { background: none; }
24421 Roo.form.HtmlEditor.ToolbarStandard = function(config)
24424 Roo.apply(this, config);
24425 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
24426 // dont call parent... till later.
24429 Roo.apply(Roo.form.HtmlEditor.ToolbarStandard.prototype, {
24437 * @cfg {Object} disable List of toolbar elements to disable
24442 * @cfg {Array} fontFamilies An array of available font families
24460 // "á" , ?? a acute?
24465 "°" // , // degrees
24467 // "é" , // e ecute
24468 // "ú" , // u ecute?
24471 "form", "input:text", "input:hidden", "input:checkbox", "input:radio", "input:password",
24472 "input:submit", "input:button", "select", "textarea", "label" ],
24475 ["h1"],["h2"],["h3"],["h4"],["h5"],["h6"],
24477 ["abbr"],[ "acronym"],[ "address"],[ "cite"],[ "samp"],[ "var"]
24480 * @cfg {String} defaultFont default font to use.
24482 defaultFont: 'tahoma',
24484 fontSelect : false,
24487 formatCombo : false,
24489 init : function(editor)
24491 this.editor = editor;
24494 var fid = editor.frameId;
24496 function btn(id, toggle, handler){
24497 var xid = fid + '-'+ id ;
24501 cls : 'x-btn-icon x-edit-'+id,
24502 enableToggle:toggle !== false,
24503 scope: editor, // was editor...
24504 handler:handler||editor.relayBtnCmd,
24505 clickEvent:'mousedown',
24506 tooltip: etb.buttonTips[id] || undefined, ///tips ???
24513 var tb = new Roo.Toolbar(editor.wrap.dom.firstChild);
24515 // stop form submits
24516 tb.el.on('click', function(e){
24517 e.preventDefault(); // what does this do?
24520 if(!this.disable.font && !Roo.isSafari){
24521 /* why no safari for fonts
24522 editor.fontSelect = tb.el.createChild({
24525 cls:'x-font-select',
24526 html: editor.createFontOptions()
24528 editor.fontSelect.on('change', function(){
24529 var font = editor.fontSelect.dom.value;
24530 editor.relayCmd('fontname', font);
24531 editor.deferFocus();
24534 editor.fontSelect.dom,
24539 if(!this.disable.formats){
24540 this.formatCombo = new Roo.form.ComboBox({
24541 store: new Roo.data.SimpleStore({
24544 data : this.formats // from states.js
24547 //autoCreate : {tag: "div", size: "20"},
24548 displayField:'tag',
24552 triggerAction: 'all',
24553 emptyText:'Add tag',
24554 selectOnFocus:true,
24557 'select': function(c, r, i) {
24558 editor.insertTag(r.get('tag'));
24564 tb.addField(this.formatCombo);
24568 if(!this.disable.format){
24575 if(!this.disable.fontSize){
24580 btn('increasefontsize', false, editor.adjustFont),
24581 btn('decreasefontsize', false, editor.adjustFont)
24586 if(this.disable.colors){
24589 id:editor.frameId +'-forecolor',
24590 cls:'x-btn-icon x-edit-forecolor',
24591 clickEvent:'mousedown',
24592 tooltip: this.buttonTips['forecolor'] || undefined,
24594 menu : new Roo.menu.ColorMenu({
24595 allowReselect: true,
24596 focus: Roo.emptyFn,
24599 selectHandler: function(cp, color){
24600 editor.execCmd('forecolor', Roo.isSafari || Roo.isIE ? '#'+color : color);
24601 editor.deferFocus();
24604 clickEvent:'mousedown'
24607 id:editor.frameId +'backcolor',
24608 cls:'x-btn-icon x-edit-backcolor',
24609 clickEvent:'mousedown',
24610 tooltip: this.buttonTips['backcolor'] || undefined,
24612 menu : new Roo.menu.ColorMenu({
24613 focus: Roo.emptyFn,
24616 allowReselect: true,
24617 selectHandler: function(cp, color){
24619 editor.execCmd('useCSS', false);
24620 editor.execCmd('hilitecolor', color);
24621 editor.execCmd('useCSS', true);
24622 editor.deferFocus();
24624 editor.execCmd(Roo.isOpera ? 'hilitecolor' : 'backcolor',
24625 Roo.isSafari || Roo.isIE ? '#'+color : color);
24626 editor.deferFocus();
24630 clickEvent:'mousedown'
24635 // now add all the items...
24638 if(!this.disable.alignments){
24641 btn('justifyleft'),
24642 btn('justifycenter'),
24643 btn('justifyright')
24647 //if(!Roo.isSafari){
24648 if(!this.disable.links){
24651 btn('createlink', false, editor.createLink) /// MOVE TO HERE?!!?!?!?!
24655 if(!this.disable.lists){
24658 btn('insertorderedlist'),
24659 btn('insertunorderedlist')
24662 if(!this.disable.sourceEdit){
24665 btn('sourceedit', true, function(btn){
24666 this.toggleSourceEdit(btn.pressed);
24673 // special menu.. - needs to be tidied up..
24674 if (!this.disable.special) {
24677 cls: 'x-edit-none',
24682 for (var i =0; i < this.specialChars.length; i++) {
24683 smenu.menu.items.push({
24685 text: this.specialChars[i],
24686 handler: function(a,b) {
24687 editor.insertAtCursor(String.fromCharCode(a.text.replace('&#','').replace(';', '')));
24699 for(var i =0; i< this.btns.length;i++) {
24700 var b = this.btns[i];
24701 b.cls = 'x-edit-none';
24710 // disable everything...
24712 this.tb.items.each(function(item){
24713 if(item.id != editor.frameId+ '-sourceedit'){
24717 this.rendered = true;
24719 // the all the btns;
24720 editor.on('editorevent', this.updateToolbar, this);
24721 // other toolbars need to implement this..
24722 //editor.on('editmodechange', this.updateToolbar, this);
24728 * Protected method that will not generally be called directly. It triggers
24729 * a toolbar update by reading the markup state of the current selection in the editor.
24731 updateToolbar: function(){
24733 if(!this.editor.activated){
24734 this.editor.onFirstFocus();
24738 var btns = this.tb.items.map,
24739 doc = this.editor.doc,
24740 frameId = this.editor.frameId;
24742 if(!this.disable.font && !Roo.isSafari){
24744 var name = (doc.queryCommandValue('FontName')||this.editor.defaultFont).toLowerCase();
24745 if(name != this.fontSelect.dom.value){
24746 this.fontSelect.dom.value = name;
24750 if(!this.disable.format){
24751 btns[frameId + '-bold'].toggle(doc.queryCommandState('bold'));
24752 btns[frameId + '-italic'].toggle(doc.queryCommandState('italic'));
24753 btns[frameId + '-underline'].toggle(doc.queryCommandState('underline'));
24755 if(!this.disable.alignments){
24756 btns[frameId + '-justifyleft'].toggle(doc.queryCommandState('justifyleft'));
24757 btns[frameId + '-justifycenter'].toggle(doc.queryCommandState('justifycenter'));
24758 btns[frameId + '-justifyright'].toggle(doc.queryCommandState('justifyright'));
24760 if(!Roo.isSafari && !this.disable.lists){
24761 btns[frameId + '-insertorderedlist'].toggle(doc.queryCommandState('insertorderedlist'));
24762 btns[frameId + '-insertunorderedlist'].toggle(doc.queryCommandState('insertunorderedlist'));
24765 var ans = this.editor.getAllAncestors();
24766 if (this.formatCombo) {
24769 var store = this.formatCombo.store;
24770 this.formatCombo.setValue("");
24771 for (var i =0; i < ans.length;i++) {
24772 if (ans[i] && store.query('tag',ans[i].tagName.toLowerCase(), true).length) {
24774 this.formatCombo.setValue(ans[i].tagName.toLowerCase());
24782 // hides menus... - so this cant be on a menu...
24783 Roo.menu.MenuMgr.hideAll();
24785 //this.editorsyncValue();
24789 createFontOptions : function(){
24790 var buf = [], fs = this.fontFamilies, ff, lc;
24791 for(var i = 0, len = fs.length; i< len; i++){
24793 lc = ff.toLowerCase();
24795 '<option value="',lc,'" style="font-family:',ff,';"',
24796 (this.defaultFont == lc ? ' selected="true">' : '>'),
24801 return buf.join('');
24804 toggleSourceEdit : function(sourceEditMode){
24805 if(sourceEditMode === undefined){
24806 sourceEditMode = !this.sourceEditMode;
24808 this.sourceEditMode = sourceEditMode === true;
24809 var btn = this.tb.items.get(this.editor.frameId +'-sourceedit');
24810 // just toggle the button?
24811 if(btn.pressed !== this.editor.sourceEditMode){
24812 btn.toggle(this.editor.sourceEditMode);
24816 if(this.sourceEditMode){
24817 this.tb.items.each(function(item){
24818 if(item.cmd != 'sourceedit'){
24824 if(this.initialized){
24825 this.tb.items.each(function(item){
24831 // tell the editor that it's been pressed..
24832 this.editor.toggleSourceEdit(sourceEditMode);
24836 * Object collection of toolbar tooltips for the buttons in the editor. The key
24837 * is the command id associated with that button and the value is a valid QuickTips object.
24842 title: 'Bold (Ctrl+B)',
24843 text: 'Make the selected text bold.',
24844 cls: 'x-html-editor-tip'
24847 title: 'Italic (Ctrl+I)',
24848 text: 'Make the selected text italic.',
24849 cls: 'x-html-editor-tip'
24857 title: 'Bold (Ctrl+B)',
24858 text: 'Make the selected text bold.',
24859 cls: 'x-html-editor-tip'
24862 title: 'Italic (Ctrl+I)',
24863 text: 'Make the selected text italic.',
24864 cls: 'x-html-editor-tip'
24867 title: 'Underline (Ctrl+U)',
24868 text: 'Underline the selected text.',
24869 cls: 'x-html-editor-tip'
24871 increasefontsize : {
24872 title: 'Grow Text',
24873 text: 'Increase the font size.',
24874 cls: 'x-html-editor-tip'
24876 decreasefontsize : {
24877 title: 'Shrink Text',
24878 text: 'Decrease the font size.',
24879 cls: 'x-html-editor-tip'
24882 title: 'Text Highlight Color',
24883 text: 'Change the background color of the selected text.',
24884 cls: 'x-html-editor-tip'
24887 title: 'Font Color',
24888 text: 'Change the color of the selected text.',
24889 cls: 'x-html-editor-tip'
24892 title: 'Align Text Left',
24893 text: 'Align text to the left.',
24894 cls: 'x-html-editor-tip'
24897 title: 'Center Text',
24898 text: 'Center text in the editor.',
24899 cls: 'x-html-editor-tip'
24902 title: 'Align Text Right',
24903 text: 'Align text to the right.',
24904 cls: 'x-html-editor-tip'
24906 insertunorderedlist : {
24907 title: 'Bullet List',
24908 text: 'Start a bulleted list.',
24909 cls: 'x-html-editor-tip'
24911 insertorderedlist : {
24912 title: 'Numbered List',
24913 text: 'Start a numbered list.',
24914 cls: 'x-html-editor-tip'
24917 title: 'Hyperlink',
24918 text: 'Make the selected text a hyperlink.',
24919 cls: 'x-html-editor-tip'
24922 title: 'Source Edit',
24923 text: 'Switch to source editing mode.',
24924 cls: 'x-html-editor-tip'
24928 onDestroy : function(){
24931 this.tb.items.each(function(item){
24933 item.menu.removeAll();
24935 item.menu.el.destroy();
24943 onFirstFocus: function() {
24944 this.tb.items.each(function(item){
24953 // <script type="text/javascript">
24956 * Ext JS Library 1.1.1
24957 * Copyright(c) 2006-2007, Ext JS, LLC.
24964 * @class Roo.form.HtmlEditor.ToolbarContext
24969 new Roo.form.HtmlEditor({
24972 new Roo.form.HtmlEditor.ToolbarStandard(),
24973 new Roo.form.HtmlEditor.ToolbarContext()
24978 * @config : {Object} disable List of elements to disable.. (not done yet.)
24983 Roo.form.HtmlEditor.ToolbarContext = function(config)
24986 Roo.apply(this, config);
24987 //Roo.form.HtmlEditorToolbar1.superclass.constructor.call(this, editor.wrap.dom.firstChild, [], config);
24988 // dont call parent... till later.
24990 Roo.form.HtmlEditor.ToolbarContext.types = {
25002 opts : [ [""],[ "left"],[ "right"],[ "center"],[ "top"]],
25064 opts : [[""],[ "left"],[ "center"],[ "right"],[ "justify"],[ "char"]],
25069 opts : [[""],[ "top"],[ "middle"],[ "bottom"],[ "baseline"]],
25133 Roo.apply(Roo.form.HtmlEditor.ToolbarContext.prototype, {
25141 * @cfg {Object} disable List of toolbar elements to disable
25150 init : function(editor)
25152 this.editor = editor;
25155 var fid = editor.frameId;
25157 function btn(id, toggle, handler){
25158 var xid = fid + '-'+ id ;
25162 cls : 'x-btn-icon x-edit-'+id,
25163 enableToggle:toggle !== false,
25164 scope: editor, // was editor...
25165 handler:handler||editor.relayBtnCmd,
25166 clickEvent:'mousedown',
25167 tooltip: etb.buttonTips[id] || undefined, ///tips ???
25171 // create a new element.
25172 var wdiv = editor.wrap.createChild({
25174 }, editor.wrap.dom.firstChild.nextSibling, true);
25176 // can we do this more than once??
25178 // stop form submits
25181 // disable everything...
25182 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
25183 this.toolbars = {};
25185 for (var i in ty) {
25186 this.toolbars[i] = this.buildToolbar(ty[i],i);
25188 this.tb = this.toolbars.BODY;
25192 this.rendered = true;
25194 // the all the btns;
25195 editor.on('editorevent', this.updateToolbar, this);
25196 // other toolbars need to implement this..
25197 //editor.on('editmodechange', this.updateToolbar, this);
25203 * Protected method that will not generally be called directly. It triggers
25204 * a toolbar update by reading the markup state of the current selection in the editor.
25206 updateToolbar: function(){
25208 if(!this.editor.activated){
25209 this.editor.onFirstFocus();
25214 var ans = this.editor.getAllAncestors();
25217 var ty= Roo.form.HtmlEditor.ToolbarContext.types;
25218 var sel = ans.length ? (ans[0] ? ans[0] : ans[1]) : this.editor.doc.body;
25219 sel = sel ? sel : this.editor.doc.body;
25220 sel = sel.tagName.length ? sel : this.editor.doc.body;
25221 var tn = sel.tagName.toUpperCase();
25222 sel = typeof(ty[tn]) != 'undefined' ? sel : this.editor.doc.body;
25223 tn = sel.tagName.toUpperCase();
25224 if (this.tb.name == tn) {
25225 return; // no change
25228 ///console.log("show: " + tn);
25229 this.tb = this.toolbars[tn];
25231 this.tb.fields.each(function(e) {
25232 e.setValue(sel.getAttribute(e.name));
25234 this.tb.selectedNode = sel;
25237 Roo.menu.MenuMgr.hideAll();
25239 //this.editorsyncValue();
25244 onDestroy : function(){
25247 this.tb.items.each(function(item){
25249 item.menu.removeAll();
25251 item.menu.el.destroy();
25259 onFirstFocus: function() {
25260 // need to do this for all the toolbars..
25261 this.tb.items.each(function(item){
25265 buildToolbar: function(tlist, nm)
25267 var editor = this.editor;
25268 // create a new element.
25269 var wdiv = editor.wrap.createChild({
25271 }, editor.wrap.dom.firstChild.nextSibling, true);
25274 var tb = new Roo.Toolbar(wdiv);
25275 tb.add(nm+ ": ");
25276 for (var i in tlist) {
25277 var item = tlist[i];
25278 tb.add(item.title + ": ");
25283 tb.addField( new Roo.form.ComboBox({
25284 store: new Roo.data.SimpleStore({
25287 data : item.opts // from states.js
25290 displayField:'val',
25294 triggerAction: 'all',
25295 emptyText:'Select',
25296 selectOnFocus:true,
25297 width: item.width ? item.width : 130,
25299 'select': function(c, r, i) {
25300 tb.selectedNode.setAttribute(c.name, r.get('val'));
25311 tb.addField( new Roo.form.TextField({
25314 //allowBlank:false,
25319 tb.addField( new Roo.form.TextField({
25325 'change' : function(f, nv, ov) {
25326 tb.selectedNode.setAttribute(f.name, nv);
25332 tb.el.on('click', function(e){
25333 e.preventDefault(); // what does this do?
25335 tb.el.setVisibilityMode( Roo.Element.DISPLAY);
25338 // dont need to disable them... as they will get hidden
25355 * Ext JS Library 1.1.1
25356 * Copyright(c) 2006-2007, Ext JS, LLC.
25358 * Originally Released Under LGPL - original licence link has changed is not relivant.
25361 * <script type="text/javascript">
25365 * @class Roo.form.BasicForm
25366 * @extends Roo.util.Observable
25367 * Supplies the functionality to do "actions" on forms and initialize Roo.form.Field types on existing markup.
25369 * @param {String/HTMLElement/Roo.Element} el The form element or its id
25370 * @param {Object} config Configuration options
25372 Roo.form.BasicForm = function(el, config){
25373 this.allItems = [];
25374 this.childForms = [];
25375 Roo.apply(this, config);
25377 * The Roo.form.Field items in this form.
25378 * @type MixedCollection
25382 this.items = new Roo.util.MixedCollection(false, function(o){
25383 return o.id || (o.id = Roo.id());
25387 * @event beforeaction
25388 * Fires before any action is performed. Return false to cancel the action.
25389 * @param {Form} this
25390 * @param {Action} action The action to be performed
25392 beforeaction: true,
25394 * @event actionfailed
25395 * Fires when an action fails.
25396 * @param {Form} this
25397 * @param {Action} action The action that failed
25399 actionfailed : true,
25401 * @event actioncomplete
25402 * Fires when an action is completed.
25403 * @param {Form} this
25404 * @param {Action} action The action that completed
25406 actioncomplete : true
25411 Roo.form.BasicForm.superclass.constructor.call(this);
25414 Roo.extend(Roo.form.BasicForm, Roo.util.Observable, {
25416 * @cfg {String} method
25417 * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
25420 * @cfg {DataReader} reader
25421 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when executing "load" actions.
25422 * This is optional as there is built-in support for processing JSON.
25425 * @cfg {DataReader} errorReader
25426 * An Roo.data.DataReader (e.g. {@link Roo.data.XmlReader}) to be used to read data when reading validation errors on "submit" actions.
25427 * This is completely optional as there is built-in support for processing JSON.
25430 * @cfg {String} url
25431 * The URL to use for form actions if one isn't supplied in the action options.
25434 * @cfg {Boolean} fileUpload
25435 * Set to true if this form is a file upload.
25438 * @cfg {Object} baseParams
25439 * Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.
25442 * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
25447 activeAction : null,
25450 * @cfg {Boolean} trackResetOnLoad If set to true, form.reset() resets to the last loaded
25451 * or setValues() data instead of when the form was first created.
25453 trackResetOnLoad : false,
25457 * childForms - used for multi-tab forms
25460 childForms : false,
25463 * allItems - full list of fields.
25469 * By default wait messages are displayed with Roo.MessageBox.wait. You can target a specific
25470 * element by passing it or its id or mask the form itself by passing in true.
25473 waitMsgTarget : undefined,
25476 initEl : function(el){
25477 this.el = Roo.get(el);
25478 this.id = this.el.id || Roo.id();
25479 this.el.on('submit', this.onSubmit, this);
25480 this.el.addClass('x-form');
25484 onSubmit : function(e){
25489 * Returns true if client-side validation on the form is successful.
25492 isValid : function(){
25494 this.items.each(function(f){
25503 * Returns true if any fields in this form have changed since their original load.
25506 isDirty : function(){
25508 this.items.each(function(f){
25518 * Performs a predefined action (submit or load) or custom actions you define on this form.
25519 * @param {String} actionName The name of the action type
25520 * @param {Object} options (optional) The options to pass to the action. All of the config options listed
25521 * below are supported by both the submit and load actions unless otherwise noted (custom actions could also
25522 * accept other config options):
25524 Property Type Description
25525 ---------------- --------------- ----------------------------------------------------------------------------------
25526 url String The url for the action (defaults to the form's url)
25527 method String The form method to use (defaults to the form's method, or POST if not defined)
25528 params String/Object The params to pass (defaults to the form's baseParams, or none if not defined)
25529 clientValidation Boolean Applies to submit only. Pass true to call form.isValid() prior to posting to
25530 validate the form on the client (defaults to false)
25532 * @return {BasicForm} this
25534 doAction : function(action, options){
25535 if(typeof action == 'string'){
25536 action = new Roo.form.Action.ACTION_TYPES[action](this, options);
25538 if(this.fireEvent('beforeaction', this, action) !== false){
25539 this.beforeAction(action);
25540 action.run.defer(100, action);
25546 * Shortcut to do a submit action.
25547 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
25548 * @return {BasicForm} this
25550 submit : function(options){
25551 this.doAction('submit', options);
25556 * Shortcut to do a load action.
25557 * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
25558 * @return {BasicForm} this
25560 load : function(options){
25561 this.doAction('load', options);
25566 * Persists the values in this form into the passed Roo.data.Record object in a beginEdit/endEdit block.
25567 * @param {Record} record The record to edit
25568 * @return {BasicForm} this
25570 updateRecord : function(record){
25571 record.beginEdit();
25572 var fs = record.fields;
25573 fs.each(function(f){
25574 var field = this.findField(f.name);
25576 record.set(f.name, field.getValue());
25584 * Loads an Roo.data.Record into this form.
25585 * @param {Record} record The record to load
25586 * @return {BasicForm} this
25588 loadRecord : function(record){
25589 this.setValues(record.data);
25594 beforeAction : function(action){
25595 var o = action.options;
25597 if(this.waitMsgTarget === true){
25598 this.el.mask(o.waitMsg, 'x-mask-loading');
25599 }else if(this.waitMsgTarget){
25600 this.waitMsgTarget = Roo.get(this.waitMsgTarget);
25601 this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');
25603 Roo.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle || 'Please Wait...');
25609 afterAction : function(action, success){
25610 this.activeAction = null;
25611 var o = action.options;
25613 if(this.waitMsgTarget === true){
25615 }else if(this.waitMsgTarget){
25616 this.waitMsgTarget.unmask();
25618 Roo.MessageBox.updateProgress(1);
25619 Roo.MessageBox.hide();
25626 Roo.callback(o.success, o.scope, [this, action]);
25627 this.fireEvent('actioncomplete', this, action);
25629 Roo.callback(o.failure, o.scope, [this, action]);
25630 this.fireEvent('actionfailed', this, action);
25635 * Find a Roo.form.Field in this form by id, dataIndex, name or hiddenName
25636 * @param {String} id The value to search for
25639 findField : function(id){
25640 var field = this.items.get(id);
25642 this.items.each(function(f){
25643 if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
25649 return field || null;
25653 * Add a secondary form to this one,
25654 * Used to provide tabbed forms. One form is primary, with hidden values
25655 * which mirror the elements from the other forms.
25657 * @param {Roo.form.Form} form to add.
25660 addForm : function(form){
25662 this.childForms.push(form);
25663 Roo.each(form.allItems, function (fe) {
25665 if (this.findField(fe.name)) { // already added..
25668 this.add( new Roo.form.Hidden({
25675 * Mark fields in this form invalid in bulk.
25676 * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
25677 * @return {BasicForm} this
25679 markInvalid : function(errors){
25680 if(errors instanceof Array){
25681 for(var i = 0, len = errors.length; i < len; i++){
25682 var fieldError = errors[i];
25683 var f = this.findField(fieldError.id);
25685 f.markInvalid(fieldError.msg);
25691 if(typeof errors[id] != 'function' && (field = this.findField(id))){
25692 field.markInvalid(errors[id]);
25696 Roo.each(this.childForms || [], function (f) {
25697 f.markInvalid(errors);
25704 * Set values for fields in this form in bulk.
25705 * @param {Array/Object} values Either an array in the form [{id:'fieldId', value:'foo'},...] or an object hash of {id: value, id2: value2}
25706 * @return {BasicForm} this
25708 setValues : function(values){
25709 if(values instanceof Array){ // array of objects
25710 for(var i = 0, len = values.length; i < len; i++){
25712 var f = this.findField(v.id);
25714 f.setValue(v.value);
25715 if(this.trackResetOnLoad){
25716 f.originalValue = f.getValue();
25720 }else{ // object hash
25723 if(typeof values[id] != 'function' && (field = this.findField(id))){
25725 if (field.setFromData &&
25726 field.valueField &&
25727 field.displayField &&
25728 // combos' with local stores can
25729 // be queried via setValue()
25730 // to set their value..
25731 (field.store && !field.store.isLocal)
25735 sd[field.valueField] = typeof(values[field.hiddenName]) == 'undefined' ? '' : values[field.hiddenName];
25736 sd[field.displayField] = typeof(values[field.name]) == 'undefined' ? '' : values[field.name];
25737 field.setFromData(sd);
25740 field.setValue(values[id]);
25744 if(this.trackResetOnLoad){
25745 field.originalValue = field.getValue();
25751 Roo.each(this.childForms || [], function (f) {
25752 f.setValues(values);
25759 * Returns the fields in this form as an object with key/value pairs. If multiple fields exist with the same name
25760 * they are returned as an array.
25761 * @param {Boolean} asString
25764 getValues : function(asString){
25765 if (this.childForms) {
25766 // copy values from the child forms
25767 Roo.each(this.childForms, function (f) {
25769 Roo.each(f.allFields, function (e) {
25770 if (e.name && e.getValue && this.findField(e.name)) {
25771 this.findField(e.name).setValue(e.getValue());
25780 var fs = Roo.lib.Ajax.serializeForm(this.el.dom);
25781 if(asString === true){
25784 return Roo.urlDecode(fs);
25788 * Clears all invalid messages in this form.
25789 * @return {BasicForm} this
25791 clearInvalid : function(){
25792 this.items.each(function(f){
25796 Roo.each(this.childForms || [], function (f) {
25805 * Resets this form.
25806 * @return {BasicForm} this
25808 reset : function(){
25809 this.items.each(function(f){
25813 Roo.each(this.childForms || [], function (f) {
25822 * Add Roo.form components to this form.
25823 * @param {Field} field1
25824 * @param {Field} field2 (optional)
25825 * @param {Field} etc (optional)
25826 * @return {BasicForm} this
25829 this.items.addAll(Array.prototype.slice.call(arguments, 0));
25835 * Removes a field from the items collection (does NOT remove its markup).
25836 * @param {Field} field
25837 * @return {BasicForm} this
25839 remove : function(field){
25840 this.items.remove(field);
25845 * Looks at the fields in this form, checks them for an id attribute,
25846 * and calls applyTo on the existing dom element with that id.
25847 * @return {BasicForm} this
25849 render : function(){
25850 this.items.each(function(f){
25851 if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
25859 * Calls {@link Ext#apply} for all fields in this form with the passed object.
25860 * @param {Object} values
25861 * @return {BasicForm} this
25863 applyToFields : function(o){
25864 this.items.each(function(f){
25871 * Calls {@link Ext#applyIf} for all field in this form with the passed object.
25872 * @param {Object} values
25873 * @return {BasicForm} this
25875 applyIfToFields : function(o){
25876 this.items.each(function(f){
25884 Roo.BasicForm = Roo.form.BasicForm;/*
25886 * Ext JS Library 1.1.1
25887 * Copyright(c) 2006-2007, Ext JS, LLC.
25889 * Originally Released Under LGPL - original licence link has changed is not relivant.
25892 * <script type="text/javascript">
25896 * @class Roo.form.Form
25897 * @extends Roo.form.BasicForm
25898 * Adds the ability to dynamically render forms with JavaScript to {@link Roo.form.BasicForm}.
25900 * @param {Object} config Configuration options
25902 Roo.form.Form = function(config){
25904 if (config.items) {
25905 xitems = config.items;
25906 delete config.items;
25910 Roo.form.Form.superclass.constructor.call(this, null, config);
25911 this.url = this.url || this.action;
25913 this.root = new Roo.form.Layout(Roo.applyIf({
25917 this.active = this.root;
25919 * Array of all the buttons that have been added to this form via {@link addButton}
25923 this.allItems = [];
25926 * @event clientvalidation
25927 * If the monitorValid config option is true, this event fires repetitively to notify of valid state
25928 * @param {Form} this
25929 * @param {Boolean} valid true if the form has passed client-side validation
25931 clientvalidation: true,
25934 * Fires when the form is rendered
25935 * @param {Roo.form.Form} form
25940 Roo.each(xitems, this.addxtype, this);
25946 Roo.extend(Roo.form.Form, Roo.form.BasicForm, {
25948 * @cfg {Number} labelWidth The width of labels. This property cascades to child containers.
25951 * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
25954 * @cfg {String} buttonAlign Valid values are "left," "center" and "right" (defaults to "center")
25956 buttonAlign:'center',
25959 * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to 75)
25964 * @cfg {String} labelAlign Valid values are "left," "top" and "right" (defaults to "left").
25965 * This property cascades to child containers if not set.
25970 * @cfg {Boolean} monitorValid If true the form monitors its valid state <b>client-side</b> and
25971 * fires a looping event with that state. This is required to bind buttons to the valid
25972 * state using the config value formBind:true on the button.
25974 monitorValid : false,
25977 * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
25983 * Opens a new {@link Roo.form.Column} container in the layout stack. If fields are passed after the config, the
25984 * fields are added and the column is closed. If no fields are passed the column remains open
25985 * until end() is called.
25986 * @param {Object} config The config to pass to the column
25987 * @param {Field} field1 (optional)
25988 * @param {Field} field2 (optional)
25989 * @param {Field} etc (optional)
25990 * @return Column The column container object
25992 column : function(c){
25993 var col = new Roo.form.Column(c);
25995 if(arguments.length > 1){ // duplicate code required because of Opera
25996 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
26003 * Opens a new {@link Roo.form.FieldSet} container in the layout stack. If fields are passed after the config, the
26004 * fields are added and the fieldset is closed. If no fields are passed the fieldset remains open
26005 * until end() is called.
26006 * @param {Object} config The config to pass to the fieldset
26007 * @param {Field} field1 (optional)
26008 * @param {Field} field2 (optional)
26009 * @param {Field} etc (optional)
26010 * @return FieldSet The fieldset container object
26012 fieldset : function(c){
26013 var fs = new Roo.form.FieldSet(c);
26015 if(arguments.length > 1){ // duplicate code required because of Opera
26016 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
26023 * Opens a new {@link Roo.form.Layout} container in the layout stack. If fields are passed after the config, the
26024 * fields are added and the container is closed. If no fields are passed the container remains open
26025 * until end() is called.
26026 * @param {Object} config The config to pass to the Layout
26027 * @param {Field} field1 (optional)
26028 * @param {Field} field2 (optional)
26029 * @param {Field} etc (optional)
26030 * @return Layout The container object
26032 container : function(c){
26033 var l = new Roo.form.Layout(c);
26035 if(arguments.length > 1){ // duplicate code required because of Opera
26036 this.add.apply(this, Array.prototype.slice.call(arguments, 1));
26043 * Opens the passed container in the layout stack. The container can be any {@link Roo.form.Layout} or subclass.
26044 * @param {Object} container A Roo.form.Layout or subclass of Layout
26045 * @return {Form} this
26047 start : function(c){
26048 // cascade label info
26049 Roo.applyIf(c, {'labelAlign': this.active.labelAlign, 'labelWidth': this.active.labelWidth, 'itemCls': this.active.itemCls});
26050 this.active.stack.push(c);
26051 c.ownerCt = this.active;
26057 * Closes the current open container
26058 * @return {Form} this
26061 if(this.active == this.root){
26064 this.active = this.active.ownerCt;
26069 * Add Roo.form components to the current open container (e.g. column, fieldset, etc.). Fields added via this method
26070 * can also be passed with an additional property of fieldLabel, which if supplied, will provide the text to display
26071 * as the label of the field.
26072 * @param {Field} field1
26073 * @param {Field} field2 (optional)
26074 * @param {Field} etc. (optional)
26075 * @return {Form} this
26078 this.active.stack.push.apply(this.active.stack, arguments);
26079 this.allItems.push.apply(this.allItems,arguments);
26081 for(var i = 0, a = arguments, len = a.length; i < len; i++) {
26082 if(a[i].isFormField){
26087 Roo.form.Form.superclass.add.apply(this, r);
26097 * Find any element that has been added to a form, using it's ID or name
26098 * This can include framesets, columns etc. along with regular fields..
26099 * @param {String} id - id or name to find.
26101 * @return {Element} e - or false if nothing found.
26103 findbyId : function(id)
26109 Ext.each(this.allItems, function(f){
26110 if (f.id == id || f.name == id ){
26121 * Render this form into the passed container. This should only be called once!
26122 * @param {String/HTMLElement/Element} container The element this component should be rendered into
26123 * @return {Form} this
26125 render : function(ct){
26127 var o = this.autoCreate || {
26129 method : this.method || 'POST',
26130 id : this.id || Roo.id()
26132 this.initEl(ct.createChild(o));
26134 this.root.render(this.el);
26136 this.items.each(function(f){
26137 f.render('x-form-el-'+f.id);
26140 if(this.buttons.length > 0){
26141 // tables are required to maintain order and for correct IE layout
26142 var tb = this.el.createChild({cls:'x-form-btns-ct', cn: {
26143 cls:"x-form-btns x-form-btns-"+this.buttonAlign,
26144 html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
26146 var tr = tb.getElementsByTagName('tr')[0];
26147 for(var i = 0, len = this.buttons.length; i < len; i++) {
26148 var b = this.buttons[i];
26149 var td = document.createElement('td');
26150 td.className = 'x-form-btn-td';
26151 b.render(tr.appendChild(td));
26154 if(this.monitorValid){ // initialize after render
26155 this.startMonitoring();
26157 this.fireEvent('rendered', this);
26162 * Adds a button to the footer of the form - this <b>must</b> be called before the form is rendered.
26163 * @param {String/Object} config A string becomes the button text, an object can either be a Button config
26164 * object or a valid Roo.DomHelper element config
26165 * @param {Function} handler The function called when the button is clicked
26166 * @param {Object} scope (optional) The scope of the handler function
26167 * @return {Roo.Button}
26169 addButton : function(config, handler, scope){
26173 minWidth: this.minButtonWidth,
26176 if(typeof config == "string"){
26179 Roo.apply(bc, config);
26181 var btn = new Roo.Button(null, bc);
26182 this.buttons.push(btn);
26187 * Adds a series of form elements (using the xtype property as the factory method.
26188 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column, (and 'end' to close a block)
26189 * @param {Object} config
26192 addxtype : function()
26194 var ar = Array.prototype.slice.call(arguments, 0);
26196 for(var i = 0; i < ar.length; i++) {
26198 continue; // skip -- if this happends something invalid got sent, we
26199 // should ignore it, as basically that interface element will not show up
26200 // and that should be pretty obvious!!
26203 if (Roo.form[ar[i].xtype]) {
26205 var fe = Roo.factory(ar[i], Roo.form);
26211 fe.store.form = this;
26216 this.allItems.push(fe);
26217 if (fe.items && fe.addxtype) {
26218 fe.addxtype.apply(fe, fe.items);
26228 // console.log('adding ' + ar[i].xtype);
26230 if (ar[i].xtype == 'Button') {
26231 //console.log('adding button');
26232 //console.log(ar[i]);
26233 this.addButton(ar[i]);
26234 this.allItems.push(fe);
26238 if (ar[i].xtype == 'end') { // so we can add fieldsets... / layout etc.
26239 alert('end is not supported on xtype any more, use items');
26241 // //console.log('adding end');
26249 * Starts monitoring of the valid state of this form. Usually this is done by passing the config
26250 * option "monitorValid"
26252 startMonitoring : function(){
26255 Roo.TaskMgr.start({
26256 run : this.bindHandler,
26257 interval : this.monitorPoll || 200,
26264 * Stops monitoring of the valid state of this form
26266 stopMonitoring : function(){
26267 this.bound = false;
26271 bindHandler : function(){
26273 return false; // stops binding
26276 this.items.each(function(f){
26277 if(!f.isValid(true)){
26282 for(var i = 0, len = this.buttons.length; i < len; i++){
26283 var btn = this.buttons[i];
26284 if(btn.formBind === true && btn.disabled === valid){
26285 btn.setDisabled(!valid);
26288 this.fireEvent('clientvalidation', this, valid);
26302 Roo.Form = Roo.form.Form;
26305 * Ext JS Library 1.1.1
26306 * Copyright(c) 2006-2007, Ext JS, LLC.
26308 * Originally Released Under LGPL - original licence link has changed is not relivant.
26311 * <script type="text/javascript">
26315 * @class Roo.form.Action
26316 * Internal Class used to handle form actions
26318 * @param {Roo.form.BasicForm} el The form element or its id
26319 * @param {Object} config Configuration options
26323 // define the action interface
26324 Roo.form.Action = function(form, options){
26326 this.options = options || {};
26329 * Client Validation Failed
26332 Roo.form.Action.CLIENT_INVALID = 'client';
26334 * Server Validation Failed
26337 Roo.form.Action.SERVER_INVALID = 'server';
26339 * Connect to Server Failed
26342 Roo.form.Action.CONNECT_FAILURE = 'connect';
26344 * Reading Data from Server Failed
26347 Roo.form.Action.LOAD_FAILURE = 'load';
26349 Roo.form.Action.prototype = {
26351 failureType : undefined,
26352 response : undefined,
26353 result : undefined,
26355 // interface method
26356 run : function(options){
26360 // interface method
26361 success : function(response){
26365 // interface method
26366 handleResponse : function(response){
26370 // default connection failure
26371 failure : function(response){
26372 this.response = response;
26373 this.failureType = Roo.form.Action.CONNECT_FAILURE;
26374 this.form.afterAction(this, false);
26377 processResponse : function(response){
26378 this.response = response;
26379 if(!response.responseText){
26382 this.result = this.handleResponse(response);
26383 return this.result;
26386 // utility functions used internally
26387 getUrl : function(appendParams){
26388 var url = this.options.url || this.form.url || this.form.el.dom.action;
26390 var p = this.getParams();
26392 url += (url.indexOf('?') != -1 ? '&' : '?') + p;
26398 getMethod : function(){
26399 return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
26402 getParams : function(){
26403 var bp = this.form.baseParams;
26404 var p = this.options.params;
26406 if(typeof p == "object"){
26407 p = Roo.urlEncode(Roo.applyIf(p, bp));
26408 }else if(typeof p == 'string' && bp){
26409 p += '&' + Roo.urlEncode(bp);
26412 p = Roo.urlEncode(bp);
26417 createCallback : function(){
26419 success: this.success,
26420 failure: this.failure,
26422 timeout: (this.form.timeout*1000),
26423 upload: this.form.fileUpload ? this.success : undefined
26428 Roo.form.Action.Submit = function(form, options){
26429 Roo.form.Action.Submit.superclass.constructor.call(this, form, options);
26432 Roo.extend(Roo.form.Action.Submit, Roo.form.Action, {
26436 var o = this.options;
26437 var method = this.getMethod();
26438 var isPost = method == 'POST';
26439 if(o.clientValidation === false || this.form.isValid()){
26440 Roo.Ajax.request(Roo.apply(this.createCallback(), {
26441 form:this.form.el.dom,
26442 url:this.getUrl(!isPost),
26444 params:isPost ? this.getParams() : null,
26445 isUpload: this.form.fileUpload
26448 }else if (o.clientValidation !== false){ // client validation failed
26449 this.failureType = Roo.form.Action.CLIENT_INVALID;
26450 this.form.afterAction(this, false);
26454 success : function(response){
26455 var result = this.processResponse(response);
26456 if(result === true || result.success){
26457 this.form.afterAction(this, true);
26461 this.form.markInvalid(result.errors);
26462 this.failureType = Roo.form.Action.SERVER_INVALID;
26464 this.form.afterAction(this, false);
26467 handleResponse : function(response){
26468 if(this.form.errorReader){
26469 var rs = this.form.errorReader.read(response);
26472 for(var i = 0, len = rs.records.length; i < len; i++) {
26473 var r = rs.records[i];
26474 errors[i] = r.data;
26477 if(errors.length < 1){
26481 success : rs.success,
26487 ret = Roo.decode(response.responseText);
26491 errorMsg: "Failed to read server message: " + response.responseText,
26501 Roo.form.Action.Load = function(form, options){
26502 Roo.form.Action.Load.superclass.constructor.call(this, form, options);
26503 this.reader = this.form.reader;
26506 Roo.extend(Roo.form.Action.Load, Roo.form.Action, {
26510 Roo.Ajax.request(Roo.apply(
26511 this.createCallback(), {
26512 method:this.getMethod(),
26513 url:this.getUrl(false),
26514 params:this.getParams()
26518 success : function(response){
26519 var result = this.processResponse(response);
26520 if(result === true || !result.success || !result.data){
26521 this.failureType = Roo.form.Action.LOAD_FAILURE;
26522 this.form.afterAction(this, false);
26525 this.form.clearInvalid();
26526 this.form.setValues(result.data);
26527 this.form.afterAction(this, true);
26530 handleResponse : function(response){
26531 if(this.form.reader){
26532 var rs = this.form.reader.read(response);
26533 var data = rs.records && rs.records[0] ? rs.records[0].data : null;
26535 success : rs.success,
26539 return Roo.decode(response.responseText);
26543 Roo.form.Action.ACTION_TYPES = {
26544 'load' : Roo.form.Action.Load,
26545 'submit' : Roo.form.Action.Submit
26548 * Ext JS Library 1.1.1
26549 * Copyright(c) 2006-2007, Ext JS, LLC.
26551 * Originally Released Under LGPL - original licence link has changed is not relivant.
26554 * <script type="text/javascript">
26558 * @class Roo.form.Layout
26559 * @extends Roo.Component
26560 * Creates a container for layout and rendering of fields in an {@link Roo.form.Form}.
26562 * @param {Object} config Configuration options
26564 Roo.form.Layout = function(config){
26566 if (config.items) {
26567 xitems = config.items;
26568 delete config.items;
26570 Roo.form.Layout.superclass.constructor.call(this, config);
26572 Roo.each(xitems, this.addxtype, this);
26576 Roo.extend(Roo.form.Layout, Roo.Component, {
26578 * @cfg {String/Object} autoCreate
26579 * A DomHelper element spec used to autocreate the layout (defaults to {tag: 'div', cls: 'x-form-ct'})
26582 * @cfg {String/Object/Function} style
26583 * A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
26584 * a function which returns such a specification.
26587 * @cfg {String} labelAlign
26588 * Valid values are "left," "top" and "right" (defaults to "left")
26591 * @cfg {Number} labelWidth
26592 * Fixed width in pixels of all field labels (defaults to undefined)
26595 * @cfg {Boolean} clear
26596 * True to add a clearing element at the end of this layout, equivalent to CSS clear: both (defaults to true)
26600 * @cfg {String} labelSeparator
26601 * The separator to use after field labels (defaults to ':')
26603 labelSeparator : ':',
26605 * @cfg {Boolean} hideLabels
26606 * True to suppress the display of field labels in this layout (defaults to false)
26608 hideLabels : false,
26611 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct'},
26616 onRender : function(ct, position){
26617 if(this.el){ // from markup
26618 this.el = Roo.get(this.el);
26619 }else { // generate
26620 var cfg = this.getAutoCreate();
26621 this.el = ct.createChild(cfg, position);
26624 this.el.applyStyles(this.style);
26626 if(this.labelAlign){
26627 this.el.addClass('x-form-label-'+this.labelAlign);
26629 if(this.hideLabels){
26630 this.labelStyle = "display:none";
26631 this.elementStyle = "padding-left:0;";
26633 if(typeof this.labelWidth == 'number'){
26634 this.labelStyle = "width:"+this.labelWidth+"px;";
26635 this.elementStyle = "padding-left:"+((this.labelWidth+(typeof this.labelPad == 'number' ? this.labelPad : 5))+'px')+";";
26637 if(this.labelAlign == 'top'){
26638 this.labelStyle = "width:auto;";
26639 this.elementStyle = "padding-left:0;";
26642 var stack = this.stack;
26643 var slen = stack.length;
26645 if(!this.fieldTpl){
26646 var t = new Roo.Template(
26647 '<div class="x-form-item {5}">',
26648 '<label for="{0}" style="{2}">{1}{4}</label>',
26649 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
26651 '</div><div class="x-form-clear-left"></div>'
26653 t.disableFormats = true;
26655 Roo.form.Layout.prototype.fieldTpl = t;
26657 for(var i = 0; i < slen; i++) {
26658 if(stack[i].isFormField){
26659 this.renderField(stack[i]);
26661 this.renderComponent(stack[i]);
26666 this.el.createChild({cls:'x-form-clear'});
26671 renderField : function(f){
26672 f.fieldEl = Roo.get(this.fieldTpl.append(this.el, [
26675 f.labelStyle||this.labelStyle||'', //2
26676 this.elementStyle||'', //3
26677 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator, //4
26678 f.itemCls||this.itemCls||'' //5
26679 ], true).getPrevSibling());
26683 renderComponent : function(c){
26684 c.render(c.isLayout ? this.el : this.el.createChild());
26687 * Adds a object form elements (using the xtype property as the factory method.)
26688 * Valid xtypes are: TextField, TextArea .... Button, Layout, FieldSet, Column
26689 * @param {Object} config
26691 addxtype : function(o)
26693 // create the lement.
26694 o.form = this.form;
26695 var fe = Roo.factory(o, Roo.form);
26696 this.form.allItems.push(fe);
26697 this.stack.push(fe);
26699 if (fe.isFormField) {
26700 this.form.items.add(fe);
26708 * @class Roo.form.Column
26709 * @extends Roo.form.Layout
26710 * Creates a column container for layout and rendering of fields in an {@link Roo.form.Form}.
26712 * @param {Object} config Configuration options
26714 Roo.form.Column = function(config){
26715 Roo.form.Column.superclass.constructor.call(this, config);
26718 Roo.extend(Roo.form.Column, Roo.form.Layout, {
26720 * @cfg {Number/String} width
26721 * The fixed width of the column in pixels or CSS value (defaults to "auto")
26724 * @cfg {String/Object} autoCreate
26725 * A DomHelper element spec used to autocreate the column (defaults to {tag: 'div', cls: 'x-form-ct x-form-column'})
26729 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-column'},
26732 onRender : function(ct, position){
26733 Roo.form.Column.superclass.onRender.call(this, ct, position);
26735 this.el.setWidth(this.width);
26742 * @class Roo.form.Row
26743 * @extends Roo.form.Layout
26744 * Creates a row container for layout and rendering of fields in an {@link Roo.form.Form}.
26746 * @param {Object} config Configuration options
26750 Roo.form.Row = function(config){
26751 Roo.form.Row.superclass.constructor.call(this, config);
26754 Roo.extend(Roo.form.Row, Roo.form.Layout, {
26756 * @cfg {Number/String} width
26757 * The fixed width of the column in pixels or CSS value (defaults to "auto")
26760 * @cfg {Number/String} height
26761 * The fixed height of the column in pixels or CSS value (defaults to "auto")
26763 defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-row'},
26767 onRender : function(ct, position){
26768 //console.log('row render');
26770 var t = new Roo.Template(
26771 '<div class="x-form-item {5}" style="float:left;width:{6}px">',
26772 '<label for="{0}" style="{2}">{1}{4}</label>',
26773 '<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
26777 t.disableFormats = true;
26779 Roo.form.Layout.prototype.rowTpl = t;
26781 this.fieldTpl = this.rowTpl;
26783 //console.log('lw' + this.labelWidth +', la:' + this.labelAlign);
26784 var labelWidth = 100;
26786 if ((this.labelAlign != 'top')) {
26787 if (typeof this.labelWidth == 'number') {
26788 labelWidth = this.labelWidth
26790 this.padWidth = 20 + labelWidth;
26794 Roo.form.Column.superclass.onRender.call(this, ct, position);
26796 this.el.setWidth(this.width);
26799 this.el.setHeight(this.height);
26804 renderField : function(f){
26805 f.fieldEl = this.fieldTpl.append(this.el, [
26806 f.id, f.fieldLabel,
26807 f.labelStyle||this.labelStyle||'',
26808 this.elementStyle||'',
26809 typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator,
26810 f.itemCls||this.itemCls||'',
26811 f.width ? f.width + this.padWidth : 160 + this.padWidth
26818 * @class Roo.form.FieldSet
26819 * @extends Roo.form.Layout
26820 * Creates a fieldset container for layout and rendering of fields in an {@link Roo.form.Form}.
26822 * @param {Object} config Configuration options
26824 Roo.form.FieldSet = function(config){
26825 Roo.form.FieldSet.superclass.constructor.call(this, config);
26828 Roo.extend(Roo.form.FieldSet, Roo.form.Layout, {
26830 * @cfg {String} legend
26831 * The text to display as the legend for the FieldSet (defaults to '')
26834 * @cfg {String/Object} autoCreate
26835 * A DomHelper element spec used to autocreate the fieldset (defaults to {tag: 'fieldset', cn: {tag:'legend'}})
26839 defaultAutoCreate : {tag: 'fieldset', cn: {tag:'legend'}},
26842 onRender : function(ct, position){
26843 Roo.form.FieldSet.superclass.onRender.call(this, ct, position);
26845 this.setLegend(this.legend);
26850 setLegend : function(text){
26852 this.el.child('legend').update(text);
26857 * Ext JS Library 1.1.1
26858 * Copyright(c) 2006-2007, Ext JS, LLC.
26860 * Originally Released Under LGPL - original licence link has changed is not relivant.
26863 * <script type="text/javascript">
26866 * @class Roo.form.VTypes
26867 * Overridable validation definitions. The validations provided are basic and intended to be easily customizable and extended.
26870 Roo.form.VTypes = function(){
26871 // closure these in so they are only created once.
26872 var alpha = /^[a-zA-Z_]+$/;
26873 var alphanum = /^[a-zA-Z0-9_]+$/;
26874 var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/;
26875 var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
26877 // All these messages and functions are configurable
26880 * The function used to validate email addresses
26881 * @param {String} value The email address
26883 'email' : function(v){
26884 return email.test(v);
26887 * The error text to display when the email validation function returns false
26890 'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
26892 * The keystroke filter mask to be applied on email input
26895 'emailMask' : /[a-z0-9_\.\-@]/i,
26898 * The function used to validate URLs
26899 * @param {String} value The URL
26901 'url' : function(v){
26902 return url.test(v);
26905 * The error text to display when the url validation function returns false
26908 'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
26911 * The function used to validate alpha values
26912 * @param {String} value The value
26914 'alpha' : function(v){
26915 return alpha.test(v);
26918 * The error text to display when the alpha validation function returns false
26921 'alphaText' : 'This field should only contain letters and _',
26923 * The keystroke filter mask to be applied on alpha input
26926 'alphaMask' : /[a-z_]/i,
26929 * The function used to validate alphanumeric values
26930 * @param {String} value The value
26932 'alphanum' : function(v){
26933 return alphanum.test(v);
26936 * The error text to display when the alphanumeric validation function returns false
26939 'alphanumText' : 'This field should only contain letters, numbers and _',
26941 * The keystroke filter mask to be applied on alphanumeric input
26944 'alphanumMask' : /[a-z0-9_]/i
26946 }();//<script type="text/javascript">
26949 * @class Roo.form.FCKeditor
26950 * @extends Roo.form.TextArea
26951 * Wrapper around the FCKEditor http://www.fckeditor.net
26953 * Creates a new FCKeditor
26954 * @param {Object} config Configuration options
26956 Roo.form.FCKeditor = function(config){
26957 Roo.form.FCKeditor.superclass.constructor.call(this, config);
26960 * @event editorinit
26961 * Fired when the editor is initialized - you can add extra handlers here..
26962 * @param {FCKeditor} this
26963 * @param {Object} the FCK object.
26970 Roo.form.FCKeditor.editors = { };
26971 Roo.extend(Roo.form.FCKeditor, Roo.form.TextArea,
26973 //defaultAutoCreate : {
26974 // tag : "textarea",style : "width:100px;height:60px;" ,autocomplete : "off"
26978 * @cfg {Object} fck options - see fck manual for details.
26983 * @cfg {Object} fck toolbar set (Basic or Default)
26985 toolbarSet : 'Basic',
26987 * @cfg {Object} fck BasePath
26989 basePath : '/fckeditor/',
26997 onRender : function(ct, position)
27000 this.defaultAutoCreate = {
27002 style:"width:300px;height:60px;",
27003 autocomplete: "off"
27006 Roo.form.FCKeditor.superclass.onRender.call(this, ct, position);
27009 this.textSizeEl = Roo.DomHelper.append(document.body, {tag: "pre", cls: "x-form-grow-sizer"});
27010 if(this.preventScrollbars){
27011 this.el.setStyle("overflow", "hidden");
27013 this.el.setHeight(this.growMin);
27016 //console.log('onrender' + this.getId() );
27017 Roo.form.FCKeditor.editors[this.getId()] = this;
27020 this.replaceTextarea() ;
27024 getEditor : function() {
27025 return this.fckEditor;
27028 * Sets a data value into the field and validates it. To set the value directly without validation see {@link #setRawValue}.
27029 * @param {Mixed} value The value to set
27033 setValue : function(value)
27035 //console.log('setValue: ' + value);
27037 if(typeof(value) == 'undefined') { // not sure why this is happending...
27040 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
27042 //if(!this.el || !this.getEditor()) {
27043 // this.value = value;
27044 //this.setValue.defer(100,this,[value]);
27048 if(!this.getEditor()) {
27052 this.getEditor().SetData(value);
27059 * Returns the normalized data value (undefined or emptyText will be returned as ''). To return the raw value see {@link #getRawValue}.
27060 * @return {Mixed} value The field value
27062 getValue : function()
27065 if (this.frame && this.frame.dom.style.display == 'none') {
27066 return Roo.form.FCKeditor.superclass.getValue.call(this);
27069 if(!this.el || !this.getEditor()) {
27071 // this.getValue.defer(100,this);
27076 var value=this.getEditor().GetData();
27077 Roo.form.FCKeditor.superclass.setValue.apply(this,[value]);
27078 return Roo.form.FCKeditor.superclass.getValue.call(this);
27084 * Returns the raw data value which may or may not be a valid, defined value. To return a normalized value see {@link #getValue}.
27085 * @return {Mixed} value The field value
27087 getRawValue : function()
27089 if (this.frame && this.frame.dom.style.display == 'none') {
27090 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
27093 if(!this.el || !this.getEditor()) {
27094 //this.getRawValue.defer(100,this);
27101 var value=this.getEditor().GetData();
27102 Roo.form.FCKeditor.superclass.setRawValue.apply(this,[value]);
27103 return Roo.form.FCKeditor.superclass.getRawValue.call(this);
27107 setSize : function(w,h) {
27111 //if (this.frame && this.frame.dom.style.display == 'none') {
27112 // Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
27115 //if(!this.el || !this.getEditor()) {
27116 // this.setSize.defer(100,this, [w,h]);
27122 Roo.form.FCKeditor.superclass.setSize.apply(this, [w, h]);
27124 this.frame.dom.setAttribute('width', w);
27125 this.frame.dom.setAttribute('height', h);
27126 this.frame.setSize(w,h);
27130 toggleSourceEdit : function(value) {
27134 this.el.dom.style.display = value ? '' : 'none';
27135 this.frame.dom.style.display = value ? 'none' : '';
27140 focus: function(tag)
27142 if (this.frame.dom.style.display == 'none') {
27143 return Roo.form.FCKeditor.superclass.focus.call(this);
27145 if(!this.el || !this.getEditor()) {
27146 this.focus.defer(100,this, [tag]);
27153 var tgs = this.getEditor().EditorDocument.getElementsByTagName(tag);
27154 this.getEditor().Focus();
27156 if (!this.getEditor().Selection.GetSelection()) {
27157 this.focus.defer(100,this, [tag]);
27162 var r = this.getEditor().EditorDocument.createRange();
27163 r.setStart(tgs[0],0);
27164 r.setEnd(tgs[0],0);
27165 this.getEditor().Selection.GetSelection().removeAllRanges();
27166 this.getEditor().Selection.GetSelection().addRange(r);
27167 this.getEditor().Focus();
27174 replaceTextarea : function()
27176 if ( document.getElementById( this.getId() + '___Frame' ) )
27178 //if ( !this.checkBrowser || this._isCompatibleBrowser() )
27180 // We must check the elements firstly using the Id and then the name.
27181 var oTextarea = document.getElementById( this.getId() );
27183 var colElementsByName = document.getElementsByName( this.getId() ) ;
27185 oTextarea.style.display = 'none' ;
27187 if ( oTextarea.tabIndex ) {
27188 this.TabIndex = oTextarea.tabIndex ;
27191 this._insertHtmlBefore( this._getConfigHtml(), oTextarea ) ;
27192 this._insertHtmlBefore( this._getIFrameHtml(), oTextarea ) ;
27193 this.frame = Roo.get(this.getId() + '___Frame')
27196 _getConfigHtml : function()
27200 for ( var o in this.fckconfig ) {
27201 sConfig += sConfig.length > 0 ? '&' : '';
27202 sConfig += encodeURIComponent( o ) + '=' + encodeURIComponent( this.fckconfig[o] ) ;
27205 return '<input type="hidden" id="' + this.getId() + '___Config" value="' + sConfig + '" style="display:none" />' ;
27209 _getIFrameHtml : function()
27211 var sFile = 'fckeditor.html' ;
27212 /* no idea what this is about..
27215 if ( (/fcksource=true/i).test( window.top.location.search ) )
27216 sFile = 'fckeditor.original.html' ;
27221 var sLink = this.basePath + 'editor/' + sFile + '?InstanceName=' + encodeURIComponent( this.getId() ) ;
27222 sLink += this.toolbarSet ? ( '&Toolbar=' + this.toolbarSet) : '';
27225 var html = '<iframe id="' + this.getId() +
27226 '___Frame" src="' + sLink +
27227 '" width="' + this.width +
27228 '" height="' + this.height + '"' +
27229 (this.tabIndex ? ' tabindex="' + this.tabIndex + '"' :'' ) +
27230 ' frameborder="0" scrolling="no"></iframe>' ;
27235 _insertHtmlBefore : function( html, element )
27237 if ( element.insertAdjacentHTML ) {
27239 element.insertAdjacentHTML( 'beforeBegin', html ) ;
27241 var oRange = document.createRange() ;
27242 oRange.setStartBefore( element ) ;
27243 var oFragment = oRange.createContextualFragment( html );
27244 element.parentNode.insertBefore( oFragment, element ) ;
27257 //Roo.reg('fckeditor', Roo.form.FCKeditor);
27259 function FCKeditor_OnComplete(editorInstance){
27260 var f = Roo.form.FCKeditor.editors[editorInstance.Name];
27261 f.fckEditor = editorInstance;
27262 //console.log("loaded");
27263 f.fireEvent('editorinit', f, editorInstance);
27283 //<script type="text/javascript">
27285 * @class Roo.form.GridField
27286 * @extends Roo.form.Field
27287 * Embed a grid (or editable grid into a form)
27290 * Creates a new GridField
27291 * @param {Object} config Configuration options
27293 Roo.form.GridField = function(config){
27294 Roo.form.GridField.superclass.constructor.call(this, config);
27298 Roo.extend(Roo.form.GridField, Roo.form.Field, {
27300 * @cfg {Number} width - used to restrict width of grid..
27304 * @cfg {Number} height - used to restrict height of grid..
27308 * @cfg {Object} xgrid (xtype'd description of grid) Grid or EditorGrid
27312 * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
27313 * {tag: "input", type: "checkbox", autocomplete: "off"})
27315 // defaultAutoCreate : { tag: 'div' },
27316 defaultAutoCreate : { tag: 'input', type: 'hidden', autocomplete: 'off'},
27318 * @cfg {String} addTitle Text to include for adding a title.
27322 onResize : function(){
27323 Roo.form.Field.superclass.onResize.apply(this, arguments);
27326 initEvents : function(){
27327 // Roo.form.Checkbox.superclass.initEvents.call(this);
27328 // has no events...
27333 getResizeEl : function(){
27337 getPositionEl : function(){
27342 onRender : function(ct, position){
27344 this.style = this.style || 'overflow: hidden; border:1px solid #c3daf9;';
27345 var style = this.style;
27348 Roo.form.DisplayImage.superclass.onRender.call(this, ct, position);
27349 this.wrap = this.el.wrap({cls: ''}); // not sure why ive done thsi...
27350 this.viewEl = this.wrap.createChild({ tag: 'div' });
27352 this.viewEl.applyStyles(style);
27355 this.viewEl.setWidth(this.width);
27358 this.viewEl.setHeight(this.height);
27360 //if(this.inputValue !== undefined){
27361 //this.setValue(this.value);
27364 this.grid = new Roo.grid[this.xgrid.xtype](this.viewEl, this.xgrid);
27367 this.grid.render();
27368 this.grid.getDataSource().on('remove', this.refreshValue, this);
27369 this.grid.getDataSource().on('update', this.refreshValue, this);
27370 this.grid.on('afteredit', this.refreshValue, this);
27376 * Sets the value of the item.
27377 * @param {String} either an object or a string..
27379 setValue : function(v){
27381 v = v || []; // empty set..
27382 // this does not seem smart - it really only affects memoryproxy grids..
27383 if (this.grid && this.grid.getDataSource() && typeof(v) != 'undefined') {
27384 var ds = this.grid.getDataSource();
27385 // assumes a json reader..
27387 data[ds.reader.meta.root ] = typeof(v) == 'string' ? Roo.decode(v) : v;
27388 ds.loadData( data);
27390 Roo.form.GridField.superclass.setValue.call(this, v);
27391 this.refreshValue();
27392 // should load data in the grid really....
27396 refreshValue: function() {
27398 this.grid.getDataSource().each(function(r) {
27401 this.el.dom.value = Roo.encode(val);
27407 });//<script type="text/javasscript">
27411 * @class Roo.DDView
27412 * A DnD enabled version of Roo.View.
27413 * @param {Element/String} container The Element in which to create the View.
27414 * @param {String} tpl The template string used to create the markup for each element of the View
27415 * @param {Object} config The configuration properties. These include all the config options of
27416 * {@link Roo.View} plus some specific to this class.<br>
27418 * Drag/drop is implemented by adding {@link Roo.data.Record}s to the target DDView. If copying is
27419 * not being performed, the original {@link Roo.data.Record} is removed from the source DDView.<br>
27421 * The following extra CSS rules are needed to provide insertion point highlighting:<pre><code>
27422 .x-view-drag-insert-above {
27423 border-top:1px dotted #3366cc;
27425 .x-view-drag-insert-below {
27426 border-bottom:1px dotted #3366cc;
27432 Roo.DDView = function(container, tpl, config) {
27433 Roo.DDView.superclass.constructor.apply(this, arguments);
27434 this.getEl().setStyle("outline", "0px none");
27435 this.getEl().unselectable();
27436 if (this.dragGroup) {
27437 this.setDraggable(this.dragGroup.split(","));
27439 if (this.dropGroup) {
27440 this.setDroppable(this.dropGroup.split(","));
27442 if (this.deletable) {
27443 this.setDeletable();
27445 this.isDirtyFlag = false;
27451 Roo.extend(Roo.DDView, Roo.View, {
27452 /** @cfg {String/Array} dragGroup The ddgroup name(s) for the View's DragZone. */
27453 /** @cfg {String/Array} dropGroup The ddgroup name(s) for the View's DropZone. */
27454 /** @cfg {Boolean} copy Causes drag operations to copy nodes rather than move. */
27455 /** @cfg {Boolean} allowCopy Causes ctrl/drag operations to copy nodes rather than move. */
27459 reset: Roo.emptyFn,
27461 clearInvalid: Roo.form.Field.prototype.clearInvalid,
27463 validate: function() {
27467 destroy: function() {
27468 this.purgeListeners();
27469 this.getEl.removeAllListeners();
27470 this.getEl().remove();
27471 if (this.dragZone) {
27472 if (this.dragZone.destroy) {
27473 this.dragZone.destroy();
27476 if (this.dropZone) {
27477 if (this.dropZone.destroy) {
27478 this.dropZone.destroy();
27483 /** Allows this class to be an Roo.form.Field so it can be found using {@link Roo.form.BasicForm#findField}. */
27484 getName: function() {
27488 /** Loads the View from a JSON string representing the Records to put into the Store. */
27489 setValue: function(v) {
27491 throw "DDView.setValue(). DDView must be constructed with a valid Store";
27494 data[this.store.reader.meta.root] = v ? [].concat(v) : [];
27495 this.store.proxy = new Roo.data.MemoryProxy(data);
27499 /** @return {String} a parenthesised list of the ids of the Records in the View. */
27500 getValue: function() {
27502 this.store.each(function(rec) {
27503 result += rec.id + ',';
27505 return result.substr(0, result.length - 1) + ')';
27508 getIds: function() {
27509 var i = 0, result = new Array(this.store.getCount());
27510 this.store.each(function(rec) {
27511 result[i++] = rec.id;
27516 isDirty: function() {
27517 return this.isDirtyFlag;
27521 * Part of the Roo.dd.DropZone interface. If no target node is found, the
27522 * whole Element becomes the target, and this causes the drop gesture to append.
27524 getTargetFromEvent : function(e) {
27525 var target = e.getTarget();
27526 while ((target !== null) && (target.parentNode != this.el.dom)) {
27527 target = target.parentNode;
27530 target = this.el.dom.lastChild || this.el.dom;
27536 * Create the drag data which consists of an object which has the property "ddel" as
27537 * the drag proxy element.
27539 getDragData : function(e) {
27540 var target = this.findItemFromChild(e.getTarget());
27542 this.handleSelection(e);
27543 var selNodes = this.getSelectedNodes();
27546 copy: this.copy || (this.allowCopy && e.ctrlKey),
27550 var selectedIndices = this.getSelectedIndexes();
27551 for (var i = 0; i < selectedIndices.length; i++) {
27552 dragData.records.push(this.store.getAt(selectedIndices[i]));
27554 if (selNodes.length == 1) {
27555 dragData.ddel = target.cloneNode(true); // the div element
27557 var div = document.createElement('div'); // create the multi element drag "ghost"
27558 div.className = 'multi-proxy';
27559 for (var i = 0, len = selNodes.length; i < len; i++) {
27560 div.appendChild(selNodes[i].cloneNode(true));
27562 dragData.ddel = div;
27564 //console.log(dragData)
27565 //console.log(dragData.ddel.innerHTML)
27568 //console.log('nodragData')
27572 /** Specify to which ddGroup items in this DDView may be dragged. */
27573 setDraggable: function(ddGroup) {
27574 if (ddGroup instanceof Array) {
27575 Roo.each(ddGroup, this.setDraggable, this);
27578 if (this.dragZone) {
27579 this.dragZone.addToGroup(ddGroup);
27581 this.dragZone = new Roo.dd.DragZone(this.getEl(), {
27582 containerScroll: true,
27586 // Draggability implies selection. DragZone's mousedown selects the element.
27587 if (!this.multiSelect) { this.singleSelect = true; }
27589 // Wire the DragZone's handlers up to methods in *this*
27590 this.dragZone.getDragData = this.getDragData.createDelegate(this);
27594 /** Specify from which ddGroup this DDView accepts drops. */
27595 setDroppable: function(ddGroup) {
27596 if (ddGroup instanceof Array) {
27597 Roo.each(ddGroup, this.setDroppable, this);
27600 if (this.dropZone) {
27601 this.dropZone.addToGroup(ddGroup);
27603 this.dropZone = new Roo.dd.DropZone(this.getEl(), {
27604 containerScroll: true,
27608 // Wire the DropZone's handlers up to methods in *this*
27609 this.dropZone.getTargetFromEvent = this.getTargetFromEvent.createDelegate(this);
27610 this.dropZone.onNodeEnter = this.onNodeEnter.createDelegate(this);
27611 this.dropZone.onNodeOver = this.onNodeOver.createDelegate(this);
27612 this.dropZone.onNodeOut = this.onNodeOut.createDelegate(this);
27613 this.dropZone.onNodeDrop = this.onNodeDrop.createDelegate(this);
27617 /** Decide whether to drop above or below a View node. */
27618 getDropPoint : function(e, n, dd){
27619 if (n == this.el.dom) { return "above"; }
27620 var t = Roo.lib.Dom.getY(n), b = t + n.offsetHeight;
27621 var c = t + (b - t) / 2;
27622 var y = Roo.lib.Event.getPageY(e);
27630 onNodeEnter : function(n, dd, e, data){
27634 onNodeOver : function(n, dd, e, data){
27635 var pt = this.getDropPoint(e, n, dd);
27636 // set the insert point style on the target node
27637 var dragElClass = this.dropNotAllowed;
27640 if (pt == "above"){
27641 dragElClass = n.previousSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-above";
27642 targetElClass = "x-view-drag-insert-above";
27644 dragElClass = n.nextSibling ? "x-tree-drop-ok-between" : "x-tree-drop-ok-below";
27645 targetElClass = "x-view-drag-insert-below";
27647 if (this.lastInsertClass != targetElClass){
27648 Roo.fly(n).replaceClass(this.lastInsertClass, targetElClass);
27649 this.lastInsertClass = targetElClass;
27652 return dragElClass;
27655 onNodeOut : function(n, dd, e, data){
27656 this.removeDropIndicators(n);
27659 onNodeDrop : function(n, dd, e, data){
27660 if (this.fireEvent("drop", this, n, dd, e, data) === false) {
27663 var pt = this.getDropPoint(e, n, dd);
27664 var insertAt = (n == this.el.dom) ? this.nodes.length : n.nodeIndex;
27665 if (pt == "below") { insertAt++; }
27666 for (var i = 0; i < data.records.length; i++) {
27667 var r = data.records[i];
27668 var dup = this.store.getById(r.id);
27669 if (dup && (dd != this.dragZone)) {
27670 Roo.fly(this.getNode(this.store.indexOf(dup))).frame("red", 1);
27673 this.store.insert(insertAt++, r.copy());
27675 data.source.isDirtyFlag = true;
27677 this.store.insert(insertAt++, r);
27679 this.isDirtyFlag = true;
27682 this.dragZone.cachedTarget = null;
27686 removeDropIndicators : function(n){
27688 Roo.fly(n).removeClass([
27689 "x-view-drag-insert-above",
27690 "x-view-drag-insert-below"]);
27691 this.lastInsertClass = "_noclass";
27696 * Utility method. Add a delete option to the DDView's context menu.
27697 * @param {String} imageUrl The URL of the "delete" icon image.
27699 setDeletable: function(imageUrl) {
27700 if (!this.singleSelect && !this.multiSelect) {
27701 this.singleSelect = true;
27703 var c = this.getContextMenu();
27704 this.contextMenu.on("itemclick", function(item) {
27707 this.remove(this.getSelectedIndexes());
27711 this.contextMenu.add({
27718 /** Return the context menu for this DDView. */
27719 getContextMenu: function() {
27720 if (!this.contextMenu) {
27721 // Create the View's context menu
27722 this.contextMenu = new Roo.menu.Menu({
27723 id: this.id + "-contextmenu"
27725 this.el.on("contextmenu", this.showContextMenu, this);
27727 return this.contextMenu;
27730 disableContextMenu: function() {
27731 if (this.contextMenu) {
27732 this.el.un("contextmenu", this.showContextMenu, this);
27736 showContextMenu: function(e, item) {
27737 item = this.findItemFromChild(e.getTarget());
27740 this.select(this.getNode(item), this.multiSelect && e.ctrlKey, true);
27741 this.contextMenu.showAt(e.getXY());
27746 * Remove {@link Roo.data.Record}s at the specified indices.
27747 * @param {Array/Number} selectedIndices The index (or Array of indices) of Records to remove.
27749 remove: function(selectedIndices) {
27750 selectedIndices = [].concat(selectedIndices);
27751 for (var i = 0; i < selectedIndices.length; i++) {
27752 var rec = this.store.getAt(selectedIndices[i]);
27753 this.store.remove(rec);
27758 * Double click fires the event, but also, if this is draggable, and there is only one other
27759 * related DropZone, it transfers the selected node.
27761 onDblClick : function(e){
27762 var item = this.findItemFromChild(e.getTarget());
27764 if (this.fireEvent("dblclick", this, this.indexOf(item), item, e) === false) {
27767 if (this.dragGroup) {
27768 var targets = Roo.dd.DragDropMgr.getRelated(this.dragZone, true);
27769 while (targets.indexOf(this.dropZone) > -1) {
27770 targets.remove(this.dropZone);
27772 if (targets.length == 1) {
27773 this.dragZone.cachedTarget = null;
27774 var el = Roo.get(targets[0].getEl());
27775 var box = el.getBox(true);
27776 targets[0].onNodeDrop(el.dom, {
27778 xy: [box.x, box.y + box.height - 1]
27779 }, null, this.getDragData(e));
27785 handleSelection: function(e) {
27786 this.dragZone.cachedTarget = null;
27787 var item = this.findItemFromChild(e.getTarget());
27789 this.clearSelections(true);
27792 if (item && (this.multiSelect || this.singleSelect)){
27793 if(this.multiSelect && e.shiftKey && (!e.ctrlKey) && this.lastSelection){
27794 this.select(this.getNodes(this.indexOf(this.lastSelection), item.nodeIndex), false);
27795 }else if (this.isSelected(this.getNode(item)) && e.ctrlKey){
27796 this.unselect(item);
27798 this.select(item, this.multiSelect && e.ctrlKey);
27799 this.lastSelection = item;
27804 onItemClick : function(item, index, e){
27805 if(this.fireEvent("beforeclick", this, index, item, e) === false){
27811 unselect : function(nodeInfo, suppressEvent){
27812 var node = this.getNode(nodeInfo);
27813 if(node && this.isSelected(node)){
27814 if(this.fireEvent("beforeselect", this, node, this.selections) !== false){
27815 Roo.fly(node).removeClass(this.selectedClass);
27816 this.selections.remove(node);
27817 if(!suppressEvent){
27818 this.fireEvent("selectionchange", this, this.selections);
27826 * Ext JS Library 1.1.1
27827 * Copyright(c) 2006-2007, Ext JS, LLC.
27829 * Originally Released Under LGPL - original licence link has changed is not relivant.
27832 * <script type="text/javascript">
27836 * @class Roo.LayoutManager
27837 * @extends Roo.util.Observable
27838 * Base class for layout managers.
27840 Roo.LayoutManager = function(container, config){
27841 Roo.LayoutManager.superclass.constructor.call(this);
27842 this.el = Roo.get(container);
27843 // ie scrollbar fix
27844 if(this.el.dom == document.body && Roo.isIE && !config.allowScroll){
27845 document.body.scroll = "no";
27846 }else if(this.el.dom != document.body && this.el.getStyle('position') == 'static'){
27847 this.el.position('relative');
27849 this.id = this.el.id;
27850 this.el.addClass("x-layout-container");
27851 /** false to disable window resize monitoring @type Boolean */
27852 this.monitorWindowResize = true;
27857 * Fires when a layout is performed.
27858 * @param {Roo.LayoutManager} this
27862 * @event regionresized
27863 * Fires when the user resizes a region.
27864 * @param {Roo.LayoutRegion} region The resized region
27865 * @param {Number} newSize The new size (width for east/west, height for north/south)
27867 "regionresized" : true,
27869 * @event regioncollapsed
27870 * Fires when a region is collapsed.
27871 * @param {Roo.LayoutRegion} region The collapsed region
27873 "regioncollapsed" : true,
27875 * @event regionexpanded
27876 * Fires when a region is expanded.
27877 * @param {Roo.LayoutRegion} region The expanded region
27879 "regionexpanded" : true
27881 this.updating = false;
27882 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
27885 Roo.extend(Roo.LayoutManager, Roo.util.Observable, {
27887 * Returns true if this layout is currently being updated
27888 * @return {Boolean}
27890 isUpdating : function(){
27891 return this.updating;
27895 * Suspend the LayoutManager from doing auto-layouts while
27896 * making multiple add or remove calls
27898 beginUpdate : function(){
27899 this.updating = true;
27903 * Restore auto-layouts and optionally disable the manager from performing a layout
27904 * @param {Boolean} noLayout true to disable a layout update
27906 endUpdate : function(noLayout){
27907 this.updating = false;
27913 layout: function(){
27917 onRegionResized : function(region, newSize){
27918 this.fireEvent("regionresized", region, newSize);
27922 onRegionCollapsed : function(region){
27923 this.fireEvent("regioncollapsed", region);
27926 onRegionExpanded : function(region){
27927 this.fireEvent("regionexpanded", region);
27931 * Returns the size of the current view. This method normalizes document.body and element embedded layouts and
27932 * performs box-model adjustments.
27933 * @return {Object} The size as an object {width: (the width), height: (the height)}
27935 getViewSize : function(){
27937 if(this.el.dom != document.body){
27938 size = this.el.getSize();
27940 size = {width: Roo.lib.Dom.getViewWidth(), height: Roo.lib.Dom.getViewHeight()};
27942 size.width -= this.el.getBorderWidth("lr")-this.el.getPadding("lr");
27943 size.height -= this.el.getBorderWidth("tb")-this.el.getPadding("tb");
27948 * Returns the Element this layout is bound to.
27949 * @return {Roo.Element}
27951 getEl : function(){
27956 * Returns the specified region.
27957 * @param {String} target The region key ('center', 'north', 'south', 'east' or 'west')
27958 * @return {Roo.LayoutRegion}
27960 getRegion : function(target){
27961 return this.regions[target.toLowerCase()];
27964 onWindowResize : function(){
27965 if(this.monitorWindowResize){
27971 * Ext JS Library 1.1.1
27972 * Copyright(c) 2006-2007, Ext JS, LLC.
27974 * Originally Released Under LGPL - original licence link has changed is not relivant.
27977 * <script type="text/javascript">
27980 * @class Roo.BorderLayout
27981 * @extends Roo.LayoutManager
27982 * This class represents a common layout manager used in desktop applications. For screenshots and more details,
27983 * please see: <br><br>
27984 * <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>
27985 * <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>
27988 var layout = new Roo.BorderLayout(document.body, {
28022 preferredTabWidth: 150
28027 var CP = Roo.ContentPanel;
28029 layout.beginUpdate();
28030 layout.add("north", new CP("north", "North"));
28031 layout.add("south", new CP("south", {title: "South", closable: true}));
28032 layout.add("west", new CP("west", {title: "West"}));
28033 layout.add("east", new CP("autoTabs", {title: "Auto Tabs", closable: true}));
28034 layout.add("center", new CP("center1", {title: "Close Me", closable: true}));
28035 layout.add("center", new CP("center2", {title: "Center Panel", closable: false}));
28036 layout.getRegion("center").showPanel("center1");
28037 layout.endUpdate();
28040 <b>The container the layout is rendered into can be either the body element or any other element.
28041 If it is not the body element, the container needs to either be an absolute positioned element,
28042 or you will need to add "position:relative" to the css of the container. You will also need to specify
28043 the container size if it is not the body element.</b>
28046 * Create a new BorderLayout
28047 * @param {String/HTMLElement/Element} container The container this layout is bound to
28048 * @param {Object} config Configuration options
28050 Roo.BorderLayout = function(container, config){
28051 config = config || {};
28052 Roo.BorderLayout.superclass.constructor.call(this, container, config);
28053 this.factory = config.factory || Roo.BorderLayout.RegionFactory;
28054 for(var i = 0, len = this.factory.validRegions.length; i < len; i++) {
28055 var target = this.factory.validRegions[i];
28056 if(config[target]){
28057 this.addRegion(target, config[target]);
28062 Roo.extend(Roo.BorderLayout, Roo.LayoutManager, {
28064 * Creates and adds a new region if it doesn't already exist.
28065 * @param {String} target The target region key (north, south, east, west or center).
28066 * @param {Object} config The regions config object
28067 * @return {BorderLayoutRegion} The new region
28069 addRegion : function(target, config){
28070 if(!this.regions[target]){
28071 var r = this.factory.create(target, this, config);
28072 this.bindRegion(target, r);
28074 return this.regions[target];
28078 bindRegion : function(name, r){
28079 this.regions[name] = r;
28080 r.on("visibilitychange", this.layout, this);
28081 r.on("paneladded", this.layout, this);
28082 r.on("panelremoved", this.layout, this);
28083 r.on("invalidated", this.layout, this);
28084 r.on("resized", this.onRegionResized, this);
28085 r.on("collapsed", this.onRegionCollapsed, this);
28086 r.on("expanded", this.onRegionExpanded, this);
28090 * Performs a layout update.
28092 layout : function(){
28093 if(this.updating) return;
28094 var size = this.getViewSize();
28095 var w = size.width;
28096 var h = size.height;
28101 //var x = 0, y = 0;
28103 var rs = this.regions;
28104 var north = rs["north"];
28105 var south = rs["south"];
28106 var west = rs["west"];
28107 var east = rs["east"];
28108 var center = rs["center"];
28109 //if(this.hideOnLayout){ // not supported anymore
28110 //c.el.setStyle("display", "none");
28112 if(north && north.isVisible()){
28113 var b = north.getBox();
28114 var m = north.getMargins();
28115 b.width = w - (m.left+m.right);
28118 centerY = b.height + b.y + m.bottom;
28119 centerH -= centerY;
28120 north.updateBox(this.safeBox(b));
28122 if(south && south.isVisible()){
28123 var b = south.getBox();
28124 var m = south.getMargins();
28125 b.width = w - (m.left+m.right);
28127 var totalHeight = (b.height + m.top + m.bottom);
28128 b.y = h - totalHeight + m.top;
28129 centerH -= totalHeight;
28130 south.updateBox(this.safeBox(b));
28132 if(west && west.isVisible()){
28133 var b = west.getBox();
28134 var m = west.getMargins();
28135 b.height = centerH - (m.top+m.bottom);
28137 b.y = centerY + m.top;
28138 var totalWidth = (b.width + m.left + m.right);
28139 centerX += totalWidth;
28140 centerW -= totalWidth;
28141 west.updateBox(this.safeBox(b));
28143 if(east && east.isVisible()){
28144 var b = east.getBox();
28145 var m = east.getMargins();
28146 b.height = centerH - (m.top+m.bottom);
28147 var totalWidth = (b.width + m.left + m.right);
28148 b.x = w - totalWidth + m.left;
28149 b.y = centerY + m.top;
28150 centerW -= totalWidth;
28151 east.updateBox(this.safeBox(b));
28154 var m = center.getMargins();
28156 x: centerX + m.left,
28157 y: centerY + m.top,
28158 width: centerW - (m.left+m.right),
28159 height: centerH - (m.top+m.bottom)
28161 //if(this.hideOnLayout){
28162 //center.el.setStyle("display", "block");
28164 center.updateBox(this.safeBox(centerBox));
28167 this.fireEvent("layout", this);
28171 safeBox : function(box){
28172 box.width = Math.max(0, box.width);
28173 box.height = Math.max(0, box.height);
28178 * Adds a ContentPanel (or subclass) to this layout.
28179 * @param {String} target The target region key (north, south, east, west or center).
28180 * @param {Roo.ContentPanel} panel The panel to add
28181 * @return {Roo.ContentPanel} The added panel
28183 add : function(target, panel){
28185 target = target.toLowerCase();
28186 return this.regions[target].add(panel);
28190 * Remove a ContentPanel (or subclass) to this layout.
28191 * @param {String} target The target region key (north, south, east, west or center).
28192 * @param {Number/String/Roo.ContentPanel} panel The index, id or panel to remove
28193 * @return {Roo.ContentPanel} The removed panel
28195 remove : function(target, panel){
28196 target = target.toLowerCase();
28197 return this.regions[target].remove(panel);
28201 * Searches all regions for a panel with the specified id
28202 * @param {String} panelId
28203 * @return {Roo.ContentPanel} The panel or null if it wasn't found
28205 findPanel : function(panelId){
28206 var rs = this.regions;
28207 for(var target in rs){
28208 if(typeof rs[target] != "function"){
28209 var p = rs[target].getPanel(panelId);
28219 * Searches all regions for a panel with the specified id and activates (shows) it.
28220 * @param {String/ContentPanel} panelId The panels id or the panel itself
28221 * @return {Roo.ContentPanel} The shown panel or null
28223 showPanel : function(panelId) {
28224 var rs = this.regions;
28225 for(var target in rs){
28226 var r = rs[target];
28227 if(typeof r != "function"){
28228 if(r.hasPanel(panelId)){
28229 return r.showPanel(panelId);
28237 * Restores this layout's state using Roo.state.Manager or the state provided by the passed provider.
28238 * @param {Roo.state.Provider} provider (optional) An alternate state provider
28240 restoreState : function(provider){
28242 provider = Roo.state.Manager;
28244 var sm = new Roo.LayoutStateManager();
28245 sm.init(this, provider);
28249 * Adds a batch of multiple ContentPanels dynamically by passing a special regions config object. This config
28250 * object should contain properties for each region to add ContentPanels to, and each property's value should be
28251 * a valid ContentPanel config object. Example:
28253 // Create the main layout
28254 var layout = new Roo.BorderLayout('main-ct', {
28265 // Create and add multiple ContentPanels at once via configs
28268 id: 'source-files',
28270 title:'Ext Source Files',
28283 * @param {Object} regions An object containing ContentPanel configs by region name
28285 batchAdd : function(regions){
28286 this.beginUpdate();
28287 for(var rname in regions){
28288 var lr = this.regions[rname];
28290 this.addTypedPanels(lr, regions[rname]);
28297 addTypedPanels : function(lr, ps){
28298 if(typeof ps == 'string'){
28299 lr.add(new Roo.ContentPanel(ps));
28301 else if(ps instanceof Array){
28302 for(var i =0, len = ps.length; i < len; i++){
28303 this.addTypedPanels(lr, ps[i]);
28306 else if(!ps.events){ // raw config?
28308 delete ps.el; // prevent conflict
28309 lr.add(new Roo.ContentPanel(el || Roo.id(), ps));
28311 else { // panel object assumed!
28316 * Adds a xtype elements to the layout.
28320 xtype : 'ContentPanel',
28327 xtype : 'NestedLayoutPanel',
28333 items : [ ... list of content panels or nested layout panels.. ]
28337 * @param {Object} cfg Xtype definition of item to add.
28339 addxtype : function(cfg)
28341 // basically accepts a pannel...
28342 // can accept a layout region..!?!?
28343 // console.log('BorderLayout add ' + cfg.xtype)
28345 if (!cfg.xtype.match(/Panel$/)) {
28349 var region = cfg.region;
28355 xitems = cfg.items;
28362 case 'ContentPanel': // ContentPanel (el, cfg)
28363 if(cfg.autoCreate) {
28364 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
28366 var el = this.el.createChild();
28367 ret = new Roo[cfg.xtype](el, cfg); // new panel!!!!!
28370 this.add(region, ret);
28374 case 'TreePanel': // our new panel!
28375 cfg.el = this.el.createChild();
28376 ret = new Roo[cfg.xtype](cfg); // new panel!!!!!
28377 this.add(region, ret);
28380 case 'NestedLayoutPanel':
28381 // create a new Layout (which is a Border Layout...
28382 var el = this.el.createChild();
28383 var clayout = cfg.layout;
28385 clayout.items = clayout.items || [];
28386 // replace this exitems with the clayout ones..
28387 xitems = clayout.items;
28390 if (region == 'center' && this.active && this.getRegion('center').panels.length < 1) {
28391 cfg.background = false;
28393 var layout = new Roo.BorderLayout(el, clayout);
28395 ret = new Roo[cfg.xtype](layout, cfg); // new panel!!!!!
28396 //console.log('adding nested layout panel ' + cfg.toSource());
28397 this.add(region, ret);
28403 // needs grid and region
28405 //var el = this.getRegion(region).el.createChild();
28406 var el = this.el.createChild();
28407 // create the grid first...
28409 var grid = new Roo.grid[cfg.grid.xtype](el, cfg.grid);
28411 if (region == 'center' && this.active ) {
28412 cfg.background = false;
28414 ret = new Roo[cfg.xtype](grid, cfg); // new panel!!!!!
28416 this.add(region, ret);
28417 if (cfg.background) {
28418 ret.on('activate', function(gp) {
28419 if (!gp.grid.rendered) {
28432 alert("Can not add '" + cfg.xtype + "' to BorderLayout");
28434 // GridPanel (grid, cfg)
28437 this.beginUpdate();
28439 Roo.each(xitems, function(i) {
28449 * Shortcut for creating a new BorderLayout object and adding one or more ContentPanels to it in a single step, handling
28450 * the beginUpdate and endUpdate calls internally. The key to this method is the <b>panels</b> property that can be
28451 * provided with each region config, which allows you to add ContentPanel configs in addition to the region configs
28452 * during creation. The following code is equivalent to the constructor-based example at the beginning of this class:
28455 var CP = Roo.ContentPanel;
28457 var layout = Roo.BorderLayout.create({
28461 panels: [new CP("north", "North")]
28470 panels: [new CP("west", {title: "West"})]
28479 panels: [new CP("autoTabs", {title: "Auto Tabs", closable: true})]
28488 panels: [new CP("south", {title: "South", closable: true})]
28495 preferredTabWidth: 150,
28497 new CP("center1", {title: "Close Me", closable: true}),
28498 new CP("center2", {title: "Center Panel", closable: false})
28503 layout.getRegion("center").showPanel("center1");
28508 Roo.BorderLayout.create = function(config, targetEl){
28509 var layout = new Roo.BorderLayout(targetEl || document.body, config);
28510 layout.beginUpdate();
28511 var regions = Roo.BorderLayout.RegionFactory.validRegions;
28512 for(var j = 0, jlen = regions.length; j < jlen; j++){
28513 var lr = regions[j];
28514 if(layout.regions[lr] && config[lr].panels){
28515 var r = layout.regions[lr];
28516 var ps = config[lr].panels;
28517 layout.addTypedPanels(r, ps);
28520 layout.endUpdate();
28525 Roo.BorderLayout.RegionFactory = {
28527 validRegions : ["north","south","east","west","center"],
28530 create : function(target, mgr, config){
28531 target = target.toLowerCase();
28532 if(config.lightweight || config.basic){
28533 return new Roo.BasicLayoutRegion(mgr, config, target);
28537 return new Roo.NorthLayoutRegion(mgr, config);
28539 return new Roo.SouthLayoutRegion(mgr, config);
28541 return new Roo.EastLayoutRegion(mgr, config);
28543 return new Roo.WestLayoutRegion(mgr, config);
28545 return new Roo.CenterLayoutRegion(mgr, config);
28547 throw 'Layout region "'+target+'" not supported.';
28551 * Ext JS Library 1.1.1
28552 * Copyright(c) 2006-2007, Ext JS, LLC.
28554 * Originally Released Under LGPL - original licence link has changed is not relivant.
28557 * <script type="text/javascript">
28561 * @class Roo.BasicLayoutRegion
28562 * @extends Roo.util.Observable
28563 * This class represents a lightweight region in a layout manager. This region does not move dom nodes
28564 * and does not have a titlebar, tabs or any other features. All it does is size and position
28565 * panels. To create a BasicLayoutRegion, add lightweight:true or basic:true to your regions config.
28567 Roo.BasicLayoutRegion = function(mgr, config, pos, skipConfig){
28569 this.position = pos;
28572 * @scope Roo.BasicLayoutRegion
28576 * @event beforeremove
28577 * Fires before a panel is removed (or closed). To cancel the removal set "e.cancel = true" on the event argument.
28578 * @param {Roo.LayoutRegion} this
28579 * @param {Roo.ContentPanel} panel The panel
28580 * @param {Object} e The cancel event object
28582 "beforeremove" : true,
28584 * @event invalidated
28585 * Fires when the layout for this region is changed.
28586 * @param {Roo.LayoutRegion} this
28588 "invalidated" : true,
28590 * @event visibilitychange
28591 * Fires when this region is shown or hidden
28592 * @param {Roo.LayoutRegion} this
28593 * @param {Boolean} visibility true or false
28595 "visibilitychange" : true,
28597 * @event paneladded
28598 * Fires when a panel is added.
28599 * @param {Roo.LayoutRegion} this
28600 * @param {Roo.ContentPanel} panel The panel
28602 "paneladded" : true,
28604 * @event panelremoved
28605 * Fires when a panel is removed.
28606 * @param {Roo.LayoutRegion} this
28607 * @param {Roo.ContentPanel} panel The panel
28609 "panelremoved" : true,
28612 * Fires when this region is collapsed.
28613 * @param {Roo.LayoutRegion} this
28615 "collapsed" : true,
28618 * Fires when this region is expanded.
28619 * @param {Roo.LayoutRegion} this
28624 * Fires when this region is slid into view.
28625 * @param {Roo.LayoutRegion} this
28627 "slideshow" : true,
28630 * Fires when this region slides out of view.
28631 * @param {Roo.LayoutRegion} this
28633 "slidehide" : true,
28635 * @event panelactivated
28636 * Fires when a panel is activated.
28637 * @param {Roo.LayoutRegion} this
28638 * @param {Roo.ContentPanel} panel The activated panel
28640 "panelactivated" : true,
28643 * Fires when the user resizes this region.
28644 * @param {Roo.LayoutRegion} this
28645 * @param {Number} newSize The new size (width for east/west, height for north/south)
28649 /** A collection of panels in this region. @type Roo.util.MixedCollection */
28650 this.panels = new Roo.util.MixedCollection();
28651 this.panels.getKey = this.getPanelId.createDelegate(this);
28653 this.activePanel = null;
28654 // ensure listeners are added...
28656 if (config.listeners || config.events) {
28657 Roo.BasicLayoutRegion.superclass.constructor.call(this, {
28658 listeners : config.listeners || {},
28659 events : config.events || {}
28663 if(skipConfig !== true){
28664 this.applyConfig(config);
28668 Roo.extend(Roo.BasicLayoutRegion, Roo.util.Observable, {
28669 getPanelId : function(p){
28673 applyConfig : function(config){
28674 this.margins = config.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
28675 this.config = config;
28680 * Resizes the region to the specified size. For vertical regions (west, east) this adjusts
28681 * the width, for horizontal (north, south) the height.
28682 * @param {Number} newSize The new width or height
28684 resizeTo : function(newSize){
28685 var el = this.el ? this.el :
28686 (this.activePanel ? this.activePanel.getEl() : null);
28688 switch(this.position){
28691 el.setWidth(newSize);
28692 this.fireEvent("resized", this, newSize);
28696 el.setHeight(newSize);
28697 this.fireEvent("resized", this, newSize);
28703 getBox : function(){
28704 return this.activePanel ? this.activePanel.getEl().getBox(false, true) : null;
28707 getMargins : function(){
28708 return this.margins;
28711 updateBox : function(box){
28713 var el = this.activePanel.getEl();
28714 el.dom.style.left = box.x + "px";
28715 el.dom.style.top = box.y + "px";
28716 this.activePanel.setSize(box.width, box.height);
28720 * Returns the container element for this region.
28721 * @return {Roo.Element}
28723 getEl : function(){
28724 return this.activePanel;
28728 * Returns true if this region is currently visible.
28729 * @return {Boolean}
28731 isVisible : function(){
28732 return this.activePanel ? true : false;
28735 setActivePanel : function(panel){
28736 panel = this.getPanel(panel);
28737 if(this.activePanel && this.activePanel != panel){
28738 this.activePanel.setActiveState(false);
28739 this.activePanel.getEl().setLeftTop(-10000,-10000);
28741 this.activePanel = panel;
28742 panel.setActiveState(true);
28744 panel.setSize(this.box.width, this.box.height);
28746 this.fireEvent("panelactivated", this, panel);
28747 this.fireEvent("invalidated");
28751 * Show the specified panel.
28752 * @param {Number/String/ContentPanel} panelId The panels index, id or the panel itself
28753 * @return {Roo.ContentPanel} The shown panel or null
28755 showPanel : function(panel){
28756 if(panel = this.getPanel(panel)){
28757 this.setActivePanel(panel);
28763 * Get the active panel for this region.
28764 * @return {Roo.ContentPanel} The active panel or null
28766 getActivePanel : function(){
28767 return this.activePanel;
28771 * Add the passed ContentPanel(s)
28772 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
28773 * @return {Roo.ContentPanel} The panel added (if only one was added)
28775 add : function(panel){
28776 if(arguments.length > 1){
28777 for(var i = 0, len = arguments.length; i < len; i++) {
28778 this.add(arguments[i]);
28782 if(this.hasPanel(panel)){
28783 this.showPanel(panel);
28786 var el = panel.getEl();
28787 if(el.dom.parentNode != this.mgr.el.dom){
28788 this.mgr.el.dom.appendChild(el.dom);
28790 if(panel.setRegion){
28791 panel.setRegion(this);
28793 this.panels.add(panel);
28794 el.setStyle("position", "absolute");
28795 if(!panel.background){
28796 this.setActivePanel(panel);
28797 if(this.config.initialSize && this.panels.getCount()==1){
28798 this.resizeTo(this.config.initialSize);
28801 this.fireEvent("paneladded", this, panel);
28806 * Returns true if the panel is in this region.
28807 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
28808 * @return {Boolean}
28810 hasPanel : function(panel){
28811 if(typeof panel == "object"){ // must be panel obj
28812 panel = panel.getId();
28814 return this.getPanel(panel) ? true : false;
28818 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
28819 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
28820 * @param {Boolean} preservePanel Overrides the config preservePanel option
28821 * @return {Roo.ContentPanel} The panel that was removed
28823 remove : function(panel, preservePanel){
28824 panel = this.getPanel(panel);
28829 this.fireEvent("beforeremove", this, panel, e);
28830 if(e.cancel === true){
28833 var panelId = panel.getId();
28834 this.panels.removeKey(panelId);
28839 * Returns the panel specified or null if it's not in this region.
28840 * @param {Number/String/ContentPanel} panel The panels index, id or the panel itself
28841 * @return {Roo.ContentPanel}
28843 getPanel : function(id){
28844 if(typeof id == "object"){ // must be panel obj
28847 return this.panels.get(id);
28851 * Returns this regions position (north/south/east/west/center).
28854 getPosition: function(){
28855 return this.position;
28859 * Ext JS Library 1.1.1
28860 * Copyright(c) 2006-2007, Ext JS, LLC.
28862 * Originally Released Under LGPL - original licence link has changed is not relivant.
28865 * <script type="text/javascript">
28869 * @class Roo.LayoutRegion
28870 * @extends Roo.BasicLayoutRegion
28871 * This class represents a region in a layout manager.
28872 * @cfg {Boolean} collapsible False to disable collapsing (defaults to true)
28873 * @cfg {Boolean} collapsed True to set the initial display to collapsed (defaults to false)
28874 * @cfg {Boolean} floatable False to disable floating (defaults to true)
28875 * @cfg {Object} margins Margins for the element (defaults to {top: 0, left: 0, right:0, bottom: 0})
28876 * @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})
28877 * @cfg {String} tabPosition "top" or "bottom" (defaults to "bottom")
28878 * @cfg {String} collapsedTitle Optional string message to display in the collapsed block of a north or south region
28879 * @cfg {Boolean} alwaysShowTabs True to always display tabs even when there is only 1 panel (defaults to false)
28880 * @cfg {Boolean} autoScroll True to enable overflow scrolling (defaults to false)
28881 * @cfg {Boolean} titlebar True to display a title bar (defaults to true)
28882 * @cfg {String} title The title for the region (overrides panel titles)
28883 * @cfg {Boolean} animate True to animate expand/collapse (defaults to false)
28884 * @cfg {Boolean} autoHide False to disable auto hiding when the mouse leaves the "floated" region (defaults to true)
28885 * @cfg {Boolean} preservePanels True to preserve removed panels so they can be readded later (defaults to false)
28886 * @cfg {Boolean} closeOnTab True to place the close icon on the tabs instead of the region titlebar (defaults to false)
28887 * @cfg {Boolean} hideTabs True to hide the tab strip (defaults to false)
28888 * @cfg {Boolean} resizeTabs True to enable automatic tab resizing. This will resize the tabs so they are all the same size and fit within
28889 * the space available, similar to FireFox 1.5 tabs (defaults to false)
28890 * @cfg {Number} minTabWidth The minimum tab width (defaults to 40)
28891 * @cfg {Number} preferredTabWidth The preferred tab width (defaults to 150)
28892 * @cfg {Boolean} showPin True to show a pin button
28893 * @cfg {Boolean} hidden True to start the region hidden (defaults to false)
28894 * @cfg {Boolean} hideWhenEmpty True to hide the region when it has no panels
28895 * @cfg {Boolean} disableTabTips True to disable tab tooltips
28896 * @cfg {Number} width For East/West panels
28897 * @cfg {Number} height For North/South panels
28898 * @cfg {Boolean} split To show the splitter
28900 Roo.LayoutRegion = function(mgr, config, pos){
28901 Roo.LayoutRegion.superclass.constructor.call(this, mgr, config, pos, true);
28902 var dh = Roo.DomHelper;
28903 /** This region's container element
28904 * @type Roo.Element */
28905 this.el = dh.append(mgr.el.dom, {tag: "div", cls: "x-layout-panel x-layout-panel-" + this.position}, true);
28906 /** This region's title element
28907 * @type Roo.Element */
28909 this.titleEl = dh.append(this.el.dom, {tag: "div", unselectable: "on", cls: "x-unselectable x-layout-panel-hd x-layout-title-"+this.position, children:[
28910 {tag: "span", cls: "x-unselectable x-layout-panel-hd-text", unselectable: "on", html: " "},
28911 {tag: "div", cls: "x-unselectable x-layout-panel-hd-tools", unselectable: "on"}
28913 this.titleEl.enableDisplayMode();
28914 /** This region's title text element
28915 * @type HTMLElement */
28916 this.titleTextEl = this.titleEl.dom.firstChild;
28917 this.tools = Roo.get(this.titleEl.dom.childNodes[1], true);
28918 this.closeBtn = this.createTool(this.tools.dom, "x-layout-close");
28919 this.closeBtn.enableDisplayMode();
28920 this.closeBtn.on("click", this.closeClicked, this);
28921 this.closeBtn.hide();
28923 this.createBody(config);
28924 this.visible = true;
28925 this.collapsed = false;
28927 if(config.hideWhenEmpty){
28929 this.on("paneladded", this.validateVisibility, this);
28930 this.on("panelremoved", this.validateVisibility, this);
28932 this.applyConfig(config);
28935 Roo.extend(Roo.LayoutRegion, Roo.BasicLayoutRegion, {
28937 createBody : function(){
28938 /** This region's body element
28939 * @type Roo.Element */
28940 this.bodyEl = this.el.createChild({tag: "div", cls: "x-layout-panel-body"});
28943 applyConfig : function(c){
28944 if(c.collapsible && this.position != "center" && !this.collapsedEl){
28945 var dh = Roo.DomHelper;
28946 if(c.titlebar !== false){
28947 this.collapseBtn = this.createTool(this.tools.dom, "x-layout-collapse-"+this.position);
28948 this.collapseBtn.on("click", this.collapse, this);
28949 this.collapseBtn.enableDisplayMode();
28951 if(c.showPin === true || this.showPin){
28952 this.stickBtn = this.createTool(this.tools.dom, "x-layout-stick");
28953 this.stickBtn.enableDisplayMode();
28954 this.stickBtn.on("click", this.expand, this);
28955 this.stickBtn.hide();
28958 /** This region's collapsed element
28959 * @type Roo.Element */
28960 this.collapsedEl = dh.append(this.mgr.el.dom, {cls: "x-layout-collapsed x-layout-collapsed-"+this.position, children:[
28961 {cls: "x-layout-collapsed-tools", children:[{cls: "x-layout-ctools-inner"}]}
28963 if(c.floatable !== false){
28964 this.collapsedEl.addClassOnOver("x-layout-collapsed-over");
28965 this.collapsedEl.on("click", this.collapseClick, this);
28968 if(c.collapsedTitle && (this.position == "north" || this.position== "south")) {
28969 this.collapsedTitleTextEl = dh.append(this.collapsedEl.dom, {tag: "div", cls: "x-unselectable x-layout-panel-hd-text",
28970 id: "message", unselectable: "on", style:{"float":"left"}});
28971 this.collapsedTitleTextEl.innerHTML = c.collapsedTitle;
28973 this.expandBtn = this.createTool(this.collapsedEl.dom.firstChild.firstChild, "x-layout-expand-"+this.position);
28974 this.expandBtn.on("click", this.expand, this);
28976 if(this.collapseBtn){
28977 this.collapseBtn.setVisible(c.collapsible == true);
28979 this.cmargins = c.cmargins || this.cmargins ||
28980 (this.position == "west" || this.position == "east" ?
28981 {top: 0, left: 2, right:2, bottom: 0} :
28982 {top: 2, left: 0, right:0, bottom: 2});
28983 this.margins = c.margins || this.margins || {top: 0, left: 0, right:0, bottom: 0};
28984 this.bottomTabs = c.tabPosition != "top";
28985 this.autoScroll = c.autoScroll || false;
28986 if(this.autoScroll){
28987 this.bodyEl.setStyle("overflow", "auto");
28989 this.bodyEl.setStyle("overflow", "hidden");
28991 //if(c.titlebar !== false){
28992 if((!c.titlebar && !c.title) || c.titlebar === false){
28993 this.titleEl.hide();
28995 this.titleEl.show();
28997 this.titleTextEl.innerHTML = c.title;
29001 this.duration = c.duration || .30;
29002 this.slideDuration = c.slideDuration || .45;
29005 this.collapse(true);
29012 * Returns true if this region is currently visible.
29013 * @return {Boolean}
29015 isVisible : function(){
29016 return this.visible;
29020 * Updates the title for collapsed north/south regions (used with {@link #collapsedTitle} config option)
29021 * @param {String} title (optional) The title text (accepts HTML markup, defaults to the numeric character reference for a non-breaking space, "&#160;")
29023 setCollapsedTitle : function(title){
29024 title = title || " ";
29025 if(this.collapsedTitleTextEl){
29026 this.collapsedTitleTextEl.innerHTML = title;
29030 getBox : function(){
29032 if(!this.collapsed){
29033 b = this.el.getBox(false, true);
29035 b = this.collapsedEl.getBox(false, true);
29040 getMargins : function(){
29041 return this.collapsed ? this.cmargins : this.margins;
29044 highlight : function(){
29045 this.el.addClass("x-layout-panel-dragover");
29048 unhighlight : function(){
29049 this.el.removeClass("x-layout-panel-dragover");
29052 updateBox : function(box){
29054 if(!this.collapsed){
29055 this.el.dom.style.left = box.x + "px";
29056 this.el.dom.style.top = box.y + "px";
29057 this.updateBody(box.width, box.height);
29059 this.collapsedEl.dom.style.left = box.x + "px";
29060 this.collapsedEl.dom.style.top = box.y + "px";
29061 this.collapsedEl.setSize(box.width, box.height);
29064 this.tabs.autoSizeTabs();
29068 updateBody : function(w, h){
29070 this.el.setWidth(w);
29071 w -= this.el.getBorderWidth("rl");
29072 if(this.config.adjustments){
29073 w += this.config.adjustments[0];
29077 this.el.setHeight(h);
29078 h = this.titleEl && this.titleEl.isDisplayed() ? h - (this.titleEl.getHeight()||0) : h;
29079 h -= this.el.getBorderWidth("tb");
29080 if(this.config.adjustments){
29081 h += this.config.adjustments[1];
29083 this.bodyEl.setHeight(h);
29085 h = this.tabs.syncHeight(h);
29088 if(this.panelSize){
29089 w = w !== null ? w : this.panelSize.width;
29090 h = h !== null ? h : this.panelSize.height;
29092 if(this.activePanel){
29093 var el = this.activePanel.getEl();
29094 w = w !== null ? w : el.getWidth();
29095 h = h !== null ? h : el.getHeight();
29096 this.panelSize = {width: w, height: h};
29097 this.activePanel.setSize(w, h);
29099 if(Roo.isIE && this.tabs){
29100 this.tabs.el.repaint();
29105 * Returns the container element for this region.
29106 * @return {Roo.Element}
29108 getEl : function(){
29113 * Hides this region.
29116 if(!this.collapsed){
29117 this.el.dom.style.left = "-2000px";
29120 this.collapsedEl.dom.style.left = "-2000px";
29121 this.collapsedEl.hide();
29123 this.visible = false;
29124 this.fireEvent("visibilitychange", this, false);
29128 * Shows this region if it was previously hidden.
29131 if(!this.collapsed){
29134 this.collapsedEl.show();
29136 this.visible = true;
29137 this.fireEvent("visibilitychange", this, true);
29140 closeClicked : function(){
29141 if(this.activePanel){
29142 this.remove(this.activePanel);
29146 collapseClick : function(e){
29148 e.stopPropagation();
29151 e.stopPropagation();
29157 * Collapses this region.
29158 * @param {Boolean} skipAnim (optional) true to collapse the element without animation (if animate is true)
29160 collapse : function(skipAnim){
29161 if(this.collapsed) return;
29162 this.collapsed = true;
29164 this.split.el.hide();
29166 if(this.config.animate && skipAnim !== true){
29167 this.fireEvent("invalidated", this);
29168 this.animateCollapse();
29170 this.el.setLocation(-20000,-20000);
29172 this.collapsedEl.show();
29173 this.fireEvent("collapsed", this);
29174 this.fireEvent("invalidated", this);
29178 animateCollapse : function(){
29183 * Expands this region if it was previously collapsed.
29184 * @param {Roo.EventObject} e The event that triggered the expand (or null if calling manually)
29185 * @param {Boolean} skipAnim (optional) true to expand the element without animation (if animate is true)
29187 expand : function(e, skipAnim){
29188 if(e) e.stopPropagation();
29189 if(!this.collapsed || this.el.hasActiveFx()) return;
29191 this.afterSlideIn();
29194 this.collapsed = false;
29195 if(this.config.animate && skipAnim !== true){
29196 this.animateExpand();
29200 this.split.el.show();
29202 this.collapsedEl.setLocation(-2000,-2000);
29203 this.collapsedEl.hide();
29204 this.fireEvent("invalidated", this);
29205 this.fireEvent("expanded", this);
29209 animateExpand : function(){
29213 initTabs : function(){
29214 this.bodyEl.setStyle("overflow", "hidden");
29215 var ts = new Roo.TabPanel(this.bodyEl.dom, {
29216 tabPosition: this.bottomTabs ? 'bottom' : 'top',
29217 disableTooltips: this.config.disableTabTips
29219 if(this.config.hideTabs){
29220 ts.stripWrap.setDisplayed(false);
29223 ts.resizeTabs = this.config.resizeTabs === true;
29224 ts.minTabWidth = this.config.minTabWidth || 40;
29225 ts.maxTabWidth = this.config.maxTabWidth || 250;
29226 ts.preferredTabWidth = this.config.preferredTabWidth || 150;
29227 ts.monitorResize = false;
29228 ts.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
29229 ts.bodyEl.addClass('x-layout-tabs-body');
29230 this.panels.each(this.initPanelAsTab, this);
29233 initPanelAsTab : function(panel){
29234 var ti = this.tabs.addTab(panel.getEl().id, panel.getTitle(), null,
29235 this.config.closeOnTab && panel.isClosable());
29236 if(panel.tabTip !== undefined){
29237 ti.setTooltip(panel.tabTip);
29239 ti.on("activate", function(){
29240 this.setActivePanel(panel);
29242 if(this.config.closeOnTab){
29243 ti.on("beforeclose", function(t, e){
29245 this.remove(panel);
29251 updatePanelTitle : function(panel, title){
29252 if(this.activePanel == panel){
29253 this.updateTitle(title);
29256 var ti = this.tabs.getTab(panel.getEl().id);
29258 if(panel.tabTip !== undefined){
29259 ti.setTooltip(panel.tabTip);
29264 updateTitle : function(title){
29265 if(this.titleTextEl && !this.config.title){
29266 this.titleTextEl.innerHTML = (typeof title != "undefined" && title.length > 0 ? title : " ");
29270 setActivePanel : function(panel){
29271 panel = this.getPanel(panel);
29272 if(this.activePanel && this.activePanel != panel){
29273 this.activePanel.setActiveState(false);
29275 this.activePanel = panel;
29276 panel.setActiveState(true);
29277 if(this.panelSize){
29278 panel.setSize(this.panelSize.width, this.panelSize.height);
29281 this.closeBtn.setVisible(!this.config.closeOnTab && !this.isSlid && panel.isClosable());
29283 this.updateTitle(panel.getTitle());
29285 this.fireEvent("invalidated", this);
29287 this.fireEvent("panelactivated", this, panel);
29291 * Shows the specified panel.
29292 * @param {Number/String/ContentPanel} panelId The panel's index, id or the panel itself
29293 * @return {Roo.ContentPanel} The shown panel, or null if a panel could not be found from panelId
29295 showPanel : function(panel){
29296 if(panel = this.getPanel(panel)){
29298 var tab = this.tabs.getTab(panel.getEl().id);
29299 if(tab.isHidden()){
29300 this.tabs.unhideTab(tab.id);
29304 this.setActivePanel(panel);
29311 * Get the active panel for this region.
29312 * @return {Roo.ContentPanel} The active panel or null
29314 getActivePanel : function(){
29315 return this.activePanel;
29318 validateVisibility : function(){
29319 if(this.panels.getCount() < 1){
29320 this.updateTitle(" ");
29321 this.closeBtn.hide();
29324 if(!this.isVisible()){
29331 * Adds the passed ContentPanel(s) to this region.
29332 * @param {ContentPanel...} panel The ContentPanel(s) to add (you can pass more than one)
29333 * @return {Roo.ContentPanel} The panel added (if only one was added; null otherwise)
29335 add : function(panel){
29336 if(arguments.length > 1){
29337 for(var i = 0, len = arguments.length; i < len; i++) {
29338 this.add(arguments[i]);
29342 if(this.hasPanel(panel)){
29343 this.showPanel(panel);
29346 panel.setRegion(this);
29347 this.panels.add(panel);
29348 if(this.panels.getCount() == 1 && !this.config.alwaysShowTabs){
29349 this.bodyEl.dom.appendChild(panel.getEl().dom);
29350 if(panel.background !== true){
29351 this.setActivePanel(panel);
29353 this.fireEvent("paneladded", this, panel);
29359 this.initPanelAsTab(panel);
29361 if(panel.background !== true){
29362 this.tabs.activate(panel.getEl().id);
29364 this.fireEvent("paneladded", this, panel);
29369 * Hides the tab for the specified panel.
29370 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
29372 hidePanel : function(panel){
29373 if(this.tabs && (panel = this.getPanel(panel))){
29374 this.tabs.hideTab(panel.getEl().id);
29379 * Unhides the tab for a previously hidden panel.
29380 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
29382 unhidePanel : function(panel){
29383 if(this.tabs && (panel = this.getPanel(panel))){
29384 this.tabs.unhideTab(panel.getEl().id);
29388 clearPanels : function(){
29389 while(this.panels.getCount() > 0){
29390 this.remove(this.panels.first());
29395 * Removes the specified panel. If preservePanel is not true (either here or in the config), the panel is destroyed.
29396 * @param {Number/String/ContentPanel} panel The panel's index, id or the panel itself
29397 * @param {Boolean} preservePanel Overrides the config preservePanel option
29398 * @return {Roo.ContentPanel} The panel that was removed
29400 remove : function(panel, preservePanel){
29401 panel = this.getPanel(panel);
29406 this.fireEvent("beforeremove", this, panel, e);
29407 if(e.cancel === true){
29410 preservePanel = (typeof preservePanel != "undefined" ? preservePanel : (this.config.preservePanels === true || panel.preserve === true));
29411 var panelId = panel.getId();
29412 this.panels.removeKey(panelId);
29414 document.body.appendChild(panel.getEl().dom);
29417 this.tabs.removeTab(panel.getEl().id);
29418 }else if (!preservePanel){
29419 this.bodyEl.dom.removeChild(panel.getEl().dom);
29421 if(this.panels.getCount() == 1 && this.tabs && !this.config.alwaysShowTabs){
29422 var p = this.panels.first();
29423 var tempEl = document.createElement("div"); // temp holder to keep IE from deleting the node
29424 tempEl.appendChild(p.getEl().dom);
29425 this.bodyEl.update("");
29426 this.bodyEl.dom.appendChild(p.getEl().dom);
29428 this.updateTitle(p.getTitle());
29430 this.bodyEl.setStyle("overflow", this.config.autoScroll ? "auto" : "hidden");
29431 this.setActivePanel(p);
29433 panel.setRegion(null);
29434 if(this.activePanel == panel){
29435 this.activePanel = null;
29437 if(this.config.autoDestroy !== false && preservePanel !== true){
29438 try{panel.destroy();}catch(e){}
29440 this.fireEvent("panelremoved", this, panel);
29445 * Returns the TabPanel component used by this region
29446 * @return {Roo.TabPanel}
29448 getTabs : function(){
29452 createTool : function(parentEl, className){
29453 var btn = Roo.DomHelper.append(parentEl, {tag: "div", cls: "x-layout-tools-button",
29454 children: [{tag: "div", cls: "x-layout-tools-button-inner " + className, html: " "}]}, true);
29455 btn.addClassOnOver("x-layout-tools-button-over");
29460 * Ext JS Library 1.1.1
29461 * Copyright(c) 2006-2007, Ext JS, LLC.
29463 * Originally Released Under LGPL - original licence link has changed is not relivant.
29466 * <script type="text/javascript">
29472 * @class Roo.SplitLayoutRegion
29473 * @extends Roo.LayoutRegion
29474 * Adds a splitbar and other (private) useful functionality to a {@link Roo.LayoutRegion}.
29476 Roo.SplitLayoutRegion = function(mgr, config, pos, cursor){
29477 this.cursor = cursor;
29478 Roo.SplitLayoutRegion.superclass.constructor.call(this, mgr, config, pos);
29481 Roo.extend(Roo.SplitLayoutRegion, Roo.LayoutRegion, {
29482 splitTip : "Drag to resize.",
29483 collapsibleSplitTip : "Drag to resize. Double click to hide.",
29484 useSplitTips : false,
29486 applyConfig : function(config){
29487 Roo.SplitLayoutRegion.superclass.applyConfig.call(this, config);
29490 var splitEl = Roo.DomHelper.append(this.mgr.el.dom,
29491 {tag: "div", id: this.el.id + "-split", cls: "x-layout-split x-layout-split-"+this.position, html: " "});
29492 /** The SplitBar for this region
29493 * @type Roo.SplitBar */
29494 this.split = new Roo.SplitBar(splitEl, this.el, this.orientation);
29495 this.split.on("moved", this.onSplitMove, this);
29496 this.split.useShim = config.useShim === true;
29497 this.split.getMaximumSize = this[this.position == 'north' || this.position == 'south' ? 'getVMaxSize' : 'getHMaxSize'].createDelegate(this);
29498 if(this.useSplitTips){
29499 this.split.el.dom.title = config.collapsible ? this.collapsibleSplitTip : this.splitTip;
29501 if(config.collapsible){
29502 this.split.el.on("dblclick", this.collapse, this);
29505 if(typeof config.minSize != "undefined"){
29506 this.split.minSize = config.minSize;
29508 if(typeof config.maxSize != "undefined"){
29509 this.split.maxSize = config.maxSize;
29511 if(config.hideWhenEmpty || config.hidden || config.collapsed){
29512 this.hideSplitter();
29517 getHMaxSize : function(){
29518 var cmax = this.config.maxSize || 10000;
29519 var center = this.mgr.getRegion("center");
29520 return Math.min(cmax, (this.el.getWidth()+center.getEl().getWidth())-center.getMinWidth());
29523 getVMaxSize : function(){
29524 var cmax = this.config.maxSize || 10000;
29525 var center = this.mgr.getRegion("center");
29526 return Math.min(cmax, (this.el.getHeight()+center.getEl().getHeight())-center.getMinHeight());
29529 onSplitMove : function(split, newSize){
29530 this.fireEvent("resized", this, newSize);
29534 * Returns the {@link Roo.SplitBar} for this region.
29535 * @return {Roo.SplitBar}
29537 getSplitBar : function(){
29542 this.hideSplitter();
29543 Roo.SplitLayoutRegion.superclass.hide.call(this);
29546 hideSplitter : function(){
29548 this.split.el.setLocation(-2000,-2000);
29549 this.split.el.hide();
29555 this.split.el.show();
29557 Roo.SplitLayoutRegion.superclass.show.call(this);
29560 beforeSlide: function(){
29561 if(Roo.isGecko){// firefox overflow auto bug workaround
29562 this.bodyEl.clip();
29563 if(this.tabs) this.tabs.bodyEl.clip();
29564 if(this.activePanel){
29565 this.activePanel.getEl().clip();
29567 if(this.activePanel.beforeSlide){
29568 this.activePanel.beforeSlide();
29574 afterSlide : function(){
29575 if(Roo.isGecko){// firefox overflow auto bug workaround
29576 this.bodyEl.unclip();
29577 if(this.tabs) this.tabs.bodyEl.unclip();
29578 if(this.activePanel){
29579 this.activePanel.getEl().unclip();
29580 if(this.activePanel.afterSlide){
29581 this.activePanel.afterSlide();
29587 initAutoHide : function(){
29588 if(this.autoHide !== false){
29589 if(!this.autoHideHd){
29590 var st = new Roo.util.DelayedTask(this.slideIn, this);
29591 this.autoHideHd = {
29592 "mouseout": function(e){
29593 if(!e.within(this.el, true)){
29597 "mouseover" : function(e){
29603 this.el.on(this.autoHideHd);
29607 clearAutoHide : function(){
29608 if(this.autoHide !== false){
29609 this.el.un("mouseout", this.autoHideHd.mouseout);
29610 this.el.un("mouseover", this.autoHideHd.mouseover);
29614 clearMonitor : function(){
29615 Roo.get(document).un("click", this.slideInIf, this);
29618 // these names are backwards but not changed for compat
29619 slideOut : function(){
29620 if(this.isSlid || this.el.hasActiveFx()){
29623 this.isSlid = true;
29624 if(this.collapseBtn){
29625 this.collapseBtn.hide();
29627 this.closeBtnState = this.closeBtn.getStyle('display');
29628 this.closeBtn.hide();
29630 this.stickBtn.show();
29633 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor());
29634 this.beforeSlide();
29635 this.el.setStyle("z-index", 10001);
29636 this.el.slideIn(this.getSlideAnchor(), {
29637 callback: function(){
29639 this.initAutoHide();
29640 Roo.get(document).on("click", this.slideInIf, this);
29641 this.fireEvent("slideshow", this);
29648 afterSlideIn : function(){
29649 this.clearAutoHide();
29650 this.isSlid = false;
29651 this.clearMonitor();
29652 this.el.setStyle("z-index", "");
29653 if(this.collapseBtn){
29654 this.collapseBtn.show();
29656 this.closeBtn.setStyle('display', this.closeBtnState);
29658 this.stickBtn.hide();
29660 this.fireEvent("slidehide", this);
29663 slideIn : function(cb){
29664 if(!this.isSlid || this.el.hasActiveFx()){
29668 this.isSlid = false;
29669 this.beforeSlide();
29670 this.el.slideOut(this.getSlideAnchor(), {
29671 callback: function(){
29672 this.el.setLeftTop(-10000, -10000);
29674 this.afterSlideIn();
29682 slideInIf : function(e){
29683 if(!e.within(this.el)){
29688 animateCollapse : function(){
29689 this.beforeSlide();
29690 this.el.setStyle("z-index", 20000);
29691 var anchor = this.getSlideAnchor();
29692 this.el.slideOut(anchor, {
29693 callback : function(){
29694 this.el.setStyle("z-index", "");
29695 this.collapsedEl.slideIn(anchor, {duration:.3});
29697 this.el.setLocation(-10000,-10000);
29699 this.fireEvent("collapsed", this);
29706 animateExpand : function(){
29707 this.beforeSlide();
29708 this.el.alignTo(this.collapsedEl, this.getCollapseAnchor(), this.getExpandAdj());
29709 this.el.setStyle("z-index", 20000);
29710 this.collapsedEl.hide({
29713 this.el.slideIn(this.getSlideAnchor(), {
29714 callback : function(){
29715 this.el.setStyle("z-index", "");
29718 this.split.el.show();
29720 this.fireEvent("invalidated", this);
29721 this.fireEvent("expanded", this);
29749 getAnchor : function(){
29750 return this.anchors[this.position];
29753 getCollapseAnchor : function(){
29754 return this.canchors[this.position];
29757 getSlideAnchor : function(){
29758 return this.sanchors[this.position];
29761 getAlignAdj : function(){
29762 var cm = this.cmargins;
29763 switch(this.position){
29779 getExpandAdj : function(){
29780 var c = this.collapsedEl, cm = this.cmargins;
29781 switch(this.position){
29783 return [-(cm.right+c.getWidth()+cm.left), 0];
29786 return [cm.right+c.getWidth()+cm.left, 0];
29789 return [0, -(cm.top+cm.bottom+c.getHeight())];
29792 return [0, cm.top+cm.bottom+c.getHeight()];
29798 * Ext JS Library 1.1.1
29799 * Copyright(c) 2006-2007, Ext JS, LLC.
29801 * Originally Released Under LGPL - original licence link has changed is not relivant.
29804 * <script type="text/javascript">
29807 * These classes are private internal classes
29809 Roo.CenterLayoutRegion = function(mgr, config){
29810 Roo.LayoutRegion.call(this, mgr, config, "center");
29811 this.visible = true;
29812 this.minWidth = config.minWidth || 20;
29813 this.minHeight = config.minHeight || 20;
29816 Roo.extend(Roo.CenterLayoutRegion, Roo.LayoutRegion, {
29818 // center panel can't be hidden
29822 // center panel can't be hidden
29825 getMinWidth: function(){
29826 return this.minWidth;
29829 getMinHeight: function(){
29830 return this.minHeight;
29835 Roo.NorthLayoutRegion = function(mgr, config){
29836 Roo.LayoutRegion.call(this, mgr, config, "north", "n-resize");
29838 this.split.placement = Roo.SplitBar.TOP;
29839 this.split.orientation = Roo.SplitBar.VERTICAL;
29840 this.split.el.addClass("x-layout-split-v");
29842 var size = config.initialSize || config.height;
29843 if(typeof size != "undefined"){
29844 this.el.setHeight(size);
29847 Roo.extend(Roo.NorthLayoutRegion, Roo.SplitLayoutRegion, {
29848 orientation: Roo.SplitBar.VERTICAL,
29849 getBox : function(){
29850 if(this.collapsed){
29851 return this.collapsedEl.getBox();
29853 var box = this.el.getBox();
29855 box.height += this.split.el.getHeight();
29860 updateBox : function(box){
29861 if(this.split && !this.collapsed){
29862 box.height -= this.split.el.getHeight();
29863 this.split.el.setLeft(box.x);
29864 this.split.el.setTop(box.y+box.height);
29865 this.split.el.setWidth(box.width);
29867 if(this.collapsed){
29868 this.updateBody(box.width, null);
29870 Roo.LayoutRegion.prototype.updateBox.call(this, box);
29874 Roo.SouthLayoutRegion = function(mgr, config){
29875 Roo.SplitLayoutRegion.call(this, mgr, config, "south", "s-resize");
29877 this.split.placement = Roo.SplitBar.BOTTOM;
29878 this.split.orientation = Roo.SplitBar.VERTICAL;
29879 this.split.el.addClass("x-layout-split-v");
29881 var size = config.initialSize || config.height;
29882 if(typeof size != "undefined"){
29883 this.el.setHeight(size);
29886 Roo.extend(Roo.SouthLayoutRegion, Roo.SplitLayoutRegion, {
29887 orientation: Roo.SplitBar.VERTICAL,
29888 getBox : function(){
29889 if(this.collapsed){
29890 return this.collapsedEl.getBox();
29892 var box = this.el.getBox();
29894 var sh = this.split.el.getHeight();
29901 updateBox : function(box){
29902 if(this.split && !this.collapsed){
29903 var sh = this.split.el.getHeight();
29906 this.split.el.setLeft(box.x);
29907 this.split.el.setTop(box.y-sh);
29908 this.split.el.setWidth(box.width);
29910 if(this.collapsed){
29911 this.updateBody(box.width, null);
29913 Roo.LayoutRegion.prototype.updateBox.call(this, box);
29917 Roo.EastLayoutRegion = function(mgr, config){
29918 Roo.SplitLayoutRegion.call(this, mgr, config, "east", "e-resize");
29920 this.split.placement = Roo.SplitBar.RIGHT;
29921 this.split.orientation = Roo.SplitBar.HORIZONTAL;
29922 this.split.el.addClass("x-layout-split-h");
29924 var size = config.initialSize || config.width;
29925 if(typeof size != "undefined"){
29926 this.el.setWidth(size);
29929 Roo.extend(Roo.EastLayoutRegion, Roo.SplitLayoutRegion, {
29930 orientation: Roo.SplitBar.HORIZONTAL,
29931 getBox : function(){
29932 if(this.collapsed){
29933 return this.collapsedEl.getBox();
29935 var box = this.el.getBox();
29937 var sw = this.split.el.getWidth();
29944 updateBox : function(box){
29945 if(this.split && !this.collapsed){
29946 var sw = this.split.el.getWidth();
29948 this.split.el.setLeft(box.x);
29949 this.split.el.setTop(box.y);
29950 this.split.el.setHeight(box.height);
29953 if(this.collapsed){
29954 this.updateBody(null, box.height);
29956 Roo.LayoutRegion.prototype.updateBox.call(this, box);
29960 Roo.WestLayoutRegion = function(mgr, config){
29961 Roo.SplitLayoutRegion.call(this, mgr, config, "west", "w-resize");
29963 this.split.placement = Roo.SplitBar.LEFT;
29964 this.split.orientation = Roo.SplitBar.HORIZONTAL;
29965 this.split.el.addClass("x-layout-split-h");
29967 var size = config.initialSize || config.width;
29968 if(typeof size != "undefined"){
29969 this.el.setWidth(size);
29972 Roo.extend(Roo.WestLayoutRegion, Roo.SplitLayoutRegion, {
29973 orientation: Roo.SplitBar.HORIZONTAL,
29974 getBox : function(){
29975 if(this.collapsed){
29976 return this.collapsedEl.getBox();
29978 var box = this.el.getBox();
29980 box.width += this.split.el.getWidth();
29985 updateBox : function(box){
29986 if(this.split && !this.collapsed){
29987 var sw = this.split.el.getWidth();
29989 this.split.el.setLeft(box.x+box.width);
29990 this.split.el.setTop(box.y);
29991 this.split.el.setHeight(box.height);
29993 if(this.collapsed){
29994 this.updateBody(null, box.height);
29996 Roo.LayoutRegion.prototype.updateBox.call(this, box);
30001 * Ext JS Library 1.1.1
30002 * Copyright(c) 2006-2007, Ext JS, LLC.
30004 * Originally Released Under LGPL - original licence link has changed is not relivant.
30007 * <script type="text/javascript">
30012 * Private internal class for reading and applying state
30014 Roo.LayoutStateManager = function(layout){
30015 // default empty state
30024 Roo.LayoutStateManager.prototype = {
30025 init : function(layout, provider){
30026 this.provider = provider;
30027 var state = provider.get(layout.id+"-layout-state");
30029 var wasUpdating = layout.isUpdating();
30031 layout.beginUpdate();
30033 for(var key in state){
30034 if(typeof state[key] != "function"){
30035 var rstate = state[key];
30036 var r = layout.getRegion(key);
30039 r.resizeTo(rstate.size);
30041 if(rstate.collapsed == true){
30044 r.expand(null, true);
30050 layout.endUpdate();
30052 this.state = state;
30054 this.layout = layout;
30055 layout.on("regionresized", this.onRegionResized, this);
30056 layout.on("regioncollapsed", this.onRegionCollapsed, this);
30057 layout.on("regionexpanded", this.onRegionExpanded, this);
30060 storeState : function(){
30061 this.provider.set(this.layout.id+"-layout-state", this.state);
30064 onRegionResized : function(region, newSize){
30065 this.state[region.getPosition()].size = newSize;
30069 onRegionCollapsed : function(region){
30070 this.state[region.getPosition()].collapsed = true;
30074 onRegionExpanded : function(region){
30075 this.state[region.getPosition()].collapsed = false;
30080 * Ext JS Library 1.1.1
30081 * Copyright(c) 2006-2007, Ext JS, LLC.
30083 * Originally Released Under LGPL - original licence link has changed is not relivant.
30086 * <script type="text/javascript">
30089 * @class Roo.ContentPanel
30090 * @extends Roo.util.Observable
30091 * A basic ContentPanel element.
30092 * @cfg {Boolean} fitToFrame True for this panel to adjust its size to fit when the region resizes (defaults to false)
30093 * @cfg {Boolean} fitContainer When using {@link #fitToFrame} and {@link #resizeEl}, you can also fit the parent container (defaults to false)
30094 * @cfg {Boolean/Object} autoCreate True to auto generate the DOM element for this panel, or a {@link Roo.DomHelper} config of the element to create
30095 * @cfg {Boolean} closable True if the panel can be closed/removed
30096 * @cfg {Boolean} background True if the panel should not be activated when it is added (defaults to false)
30097 * @cfg {String/HTMLElement/Element} resizeEl An element to resize if {@link #fitToFrame} is true (instead of this panel's element)
30098 * @cfg {Toolbar} toolbar A toolbar for this panel
30099 * @cfg {Boolean} autoScroll True to scroll overflow in this panel (use with {@link #fitToFrame})
30100 * @cfg {String} title The title for this panel
30101 * @cfg {Array} adjustments Values to <b>add</b> to the width/height when doing a {@link #fitToFrame} (default is [0, 0])
30102 * @cfg {String} url Calls {@link #setUrl} with this value
30103 * @cfg {String/Object} params When used with {@link #url}, calls {@link #setUrl} with this value
30104 * @cfg {Boolean} loadOnce When used with {@link #url}, calls {@link #setUrl} with this value
30106 * Create a new ContentPanel.
30107 * @param {String/HTMLElement/Roo.Element} el The container element for this panel
30108 * @param {String/Object} config A string to set only the title or a config object
30109 * @param {String} content (optional) Set the HTML content for this panel
30110 * @param {String} region (optional) Used by xtype constructors to add to regions. (values center,east,west,south,north)
30112 Roo.ContentPanel = function(el, config, content){
30116 if(el.autoCreate || el.xtype){ // xtype is available if this is called from factory
30120 if (config && config.parentLayout) {
30121 el = config.parentLayout.el.createChild();
30124 if(el.autoCreate){ // xtype is available if this is called from factory
30128 this.el = Roo.get(el);
30129 if(!this.el && config && config.autoCreate){
30130 if(typeof config.autoCreate == "object"){
30131 if(!config.autoCreate.id){
30132 config.autoCreate.id = config.id||el;
30134 this.el = Roo.DomHelper.append(document.body,
30135 config.autoCreate, true);
30137 this.el = Roo.DomHelper.append(document.body,
30138 {tag: "div", cls: "x-layout-inactive-content", id: config.id||el}, true);
30141 this.closable = false;
30142 this.loaded = false;
30143 this.active = false;
30144 if(typeof config == "string"){
30145 this.title = config;
30147 Roo.apply(this, config);
30150 if (this.toolbar && !this.toolbar.el && this.toolbar.xtype) {
30151 this.wrapEl = this.el.wrap();
30152 this.toolbar = new Roo.Toolbar(this.el.insertSibling(false, 'before'), [] , this.toolbar);
30159 this.resizeEl = Roo.get(this.resizeEl, true);
30161 this.resizeEl = this.el;
30166 * Fires when this panel is activated.
30167 * @param {Roo.ContentPanel} this
30171 * @event deactivate
30172 * Fires when this panel is activated.
30173 * @param {Roo.ContentPanel} this
30175 "deactivate" : true,
30179 * Fires when this panel is resized if fitToFrame is true.
30180 * @param {Roo.ContentPanel} this
30181 * @param {Number} width The width after any component adjustments
30182 * @param {Number} height The height after any component adjustments
30186 if(this.autoScroll){
30187 this.resizeEl.setStyle("overflow", "auto");
30189 content = content || this.content;
30191 this.setContent(content);
30193 if(config && config.url){
30194 this.setUrl(this.url, this.params, this.loadOnce);
30199 Roo.ContentPanel.superclass.constructor.call(this);
30202 Roo.extend(Roo.ContentPanel, Roo.util.Observable, {
30204 setRegion : function(region){
30205 this.region = region;
30207 this.el.replaceClass("x-layout-inactive-content", "x-layout-active-content");
30209 this.el.replaceClass("x-layout-active-content", "x-layout-inactive-content");
30214 * Returns the toolbar for this Panel if one was configured.
30215 * @return {Roo.Toolbar}
30217 getToolbar : function(){
30218 return this.toolbar;
30221 setActiveState : function(active){
30222 this.active = active;
30224 this.fireEvent("deactivate", this);
30226 this.fireEvent("activate", this);
30230 * Updates this panel's element
30231 * @param {String} content The new content
30232 * @param {Boolean} loadScripts (optional) true to look for and process scripts
30234 setContent : function(content, loadScripts){
30235 this.el.update(content, loadScripts);
30238 ignoreResize : function(w, h){
30239 if(this.lastSize && this.lastSize.width == w && this.lastSize.height == h){
30242 this.lastSize = {width: w, height: h};
30247 * Get the {@link Roo.UpdateManager} for this panel. Enables you to perform Ajax updates.
30248 * @return {Roo.UpdateManager} The UpdateManager
30250 getUpdateManager : function(){
30251 return this.el.getUpdateManager();
30254 * Loads this content panel immediately with content from XHR. Note: to delay loading until the panel is activated, use {@link #setUrl}.
30255 * @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:
30258 url: "your-url.php",
30259 params: {param1: "foo", param2: "bar"}, // or a URL encoded string
30260 callback: yourFunction,
30261 scope: yourObject, //(optional scope)
30264 text: "Loading...",
30269 * The only required property is <i>url</i>. The optional properties <i>nocache</i>, <i>text</i> and <i>scripts</i>
30270 * are shorthand for <i>disableCaching</i>, <i>indicatorText</i> and <i>loadScripts</i> and are used to set their associated property on this panel UpdateManager instance.
30271 * @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}
30272 * @param {Function} callback (optional) Callback when transaction is complete -- called with signature (oElement, bSuccess, oResponse)
30273 * @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.
30274 * @return {Roo.ContentPanel} this
30277 var um = this.el.getUpdateManager();
30278 um.update.apply(um, arguments);
30284 * Set a URL to be used to load the content for this panel. When this panel is activated, the content will be loaded from that URL.
30285 * @param {String/Function} url The URL to load the content from or a function to call to get the URL
30286 * @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)
30287 * @param {Boolean} loadOnce (optional) Whether to only load the content once. If this is false it makes the Ajax call every time this panel is activated. (Defaults to false)
30288 * @return {Roo.UpdateManager} The UpdateManager
30290 setUrl : function(url, params, loadOnce){
30291 if(this.refreshDelegate){
30292 this.removeListener("activate", this.refreshDelegate);
30294 this.refreshDelegate = this._handleRefresh.createDelegate(this, [url, params, loadOnce]);
30295 this.on("activate", this.refreshDelegate);
30296 return this.el.getUpdateManager();
30299 _handleRefresh : function(url, params, loadOnce){
30300 if(!loadOnce || !this.loaded){
30301 var updater = this.el.getUpdateManager();
30302 updater.update(url, params, this._setLoaded.createDelegate(this));
30306 _setLoaded : function(){
30307 this.loaded = true;
30311 * Returns this panel's id
30314 getId : function(){
30319 * Returns this panel's element - used by regiosn to add.
30320 * @return {Roo.Element}
30322 getEl : function(){
30323 return this.wrapEl || this.el;
30326 adjustForComponents : function(width, height){
30327 if(this.resizeEl != this.el){
30328 width -= this.el.getFrameWidth('lr');
30329 height -= this.el.getFrameWidth('tb');
30332 var te = this.toolbar.getEl();
30333 height -= te.getHeight();
30334 te.setWidth(width);
30336 if(this.adjustments){
30337 width += this.adjustments[0];
30338 height += this.adjustments[1];
30340 return {"width": width, "height": height};
30343 setSize : function(width, height){
30344 if(this.fitToFrame && !this.ignoreResize(width, height)){
30345 if(this.fitContainer && this.resizeEl != this.el){
30346 this.el.setSize(width, height);
30348 var size = this.adjustForComponents(width, height);
30349 this.resizeEl.setSize(this.autoWidth ? "auto" : size.width, this.autoHeight ? "auto" : size.height);
30350 this.fireEvent('resize', this, size.width, size.height);
30355 * Returns this panel's title
30358 getTitle : function(){
30363 * Set this panel's title
30364 * @param {String} title
30366 setTitle : function(title){
30367 this.title = title;
30369 this.region.updatePanelTitle(this, title);
30374 * Returns true is this panel was configured to be closable
30375 * @return {Boolean}
30377 isClosable : function(){
30378 return this.closable;
30381 beforeSlide : function(){
30383 this.resizeEl.clip();
30386 afterSlide : function(){
30388 this.resizeEl.unclip();
30392 * Force a content refresh from the URL specified in the {@link #setUrl} method.
30393 * Will fail silently if the {@link #setUrl} method has not been called.
30394 * This does not activate the panel, just updates its content.
30396 refresh : function(){
30397 if(this.refreshDelegate){
30398 this.loaded = false;
30399 this.refreshDelegate();
30404 * Destroys this panel
30406 destroy : function(){
30407 this.el.removeAllListeners();
30408 var tempEl = document.createElement("span");
30409 tempEl.appendChild(this.el.dom);
30410 tempEl.innerHTML = "";
30416 * Adds a xtype elements to the panel - currently only supports Forms, View, JsonView.
30426 * @param {Object} cfg Xtype definition of item to add.
30429 addxtype : function(cfg) {
30431 if (cfg.xtype.match(/^Form$/)) {
30432 var el = this.el.createChild();
30434 this.form = new Roo.form.Form(cfg);
30437 if ( this.form.allItems.length) this.form.render(el.dom);
30440 if (['View', 'JsonView'].indexOf(cfg.xtype) > -1) {
30442 cfg.el = this.el.appendChild(document.createElement("div"));
30444 var ret = new Roo[cfg.xtype](cfg);
30445 ret.render(false, ''); // render blank..
30455 * @class Roo.GridPanel
30456 * @extends Roo.ContentPanel
30458 * Create a new GridPanel.
30459 * @param {Roo.grid.Grid} grid The grid for this panel
30460 * @param {String/Object} config A string to set only the panel's title, or a config object
30462 Roo.GridPanel = function(grid, config){
30465 this.wrapper = Roo.DomHelper.append(document.body, // wrapper for IE7 strict & safari scroll issue
30466 {tag: "div", cls: "x-layout-grid-wrapper x-layout-inactive-content"}, true);
30468 this.wrapper.dom.appendChild(grid.getGridEl().dom);
30470 Roo.GridPanel.superclass.constructor.call(this, this.wrapper, config);
30473 this.toolbar.el.insertBefore(this.wrapper.dom.firstChild);
30475 // xtype created footer. - not sure if will work as we normally have to render first..
30476 if (this.footer && !this.footer.el && this.footer.xtype) {
30478 this.footer.container = this.grid.getView().getFooterPanel(true);
30479 this.footer.dataSource = this.grid.dataSource;
30480 this.footer = Roo.factory(this.footer, Roo);
30484 grid.monitorWindowResize = false; // turn off autosizing
30485 grid.autoHeight = false;
30486 grid.autoWidth = false;
30488 this.grid.getGridEl().replaceClass("x-layout-inactive-content", "x-layout-component-panel");
30491 Roo.extend(Roo.GridPanel, Roo.ContentPanel, {
30492 getId : function(){
30493 return this.grid.id;
30497 * Returns the grid for this panel
30498 * @return {Roo.grid.Grid}
30500 getGrid : function(){
30504 setSize : function(width, height){
30505 if(!this.ignoreResize(width, height)){
30506 var grid = this.grid;
30507 var size = this.adjustForComponents(width, height);
30508 grid.getGridEl().setSize(size.width, size.height);
30513 beforeSlide : function(){
30514 this.grid.getView().scroller.clip();
30517 afterSlide : function(){
30518 this.grid.getView().scroller.unclip();
30521 destroy : function(){
30522 this.grid.destroy();
30524 Roo.GridPanel.superclass.destroy.call(this);
30530 * @class Roo.NestedLayoutPanel
30531 * @extends Roo.ContentPanel
30533 * Create a new NestedLayoutPanel.
30536 * @param {Roo.BorderLayout} layout The layout for this panel
30537 * @param {String/Object} config A string to set only the title or a config object
30539 Roo.NestedLayoutPanel = function(layout, config)
30541 // construct with only one argument..
30542 /* FIXME - implement nicer consturctors
30543 if (layout.layout) {
30545 layout = config.layout;
30546 delete config.layout;
30548 if (layout.xtype && !layout.getEl) {
30549 // then layout needs constructing..
30550 layout = Roo.factory(layout, Roo);
30554 Roo.NestedLayoutPanel.superclass.constructor.call(this, layout.getEl(), config);
30556 layout.monitorWindowResize = false; // turn off autosizing
30557 this.layout = layout;
30558 this.layout.getEl().addClass("x-layout-nested-layout");
30564 Roo.extend(Roo.NestedLayoutPanel, Roo.ContentPanel, {
30566 setSize : function(width, height){
30567 if(!this.ignoreResize(width, height)){
30568 var size = this.adjustForComponents(width, height);
30569 var el = this.layout.getEl();
30570 el.setSize(size.width, size.height);
30571 var touch = el.dom.offsetWidth;
30572 this.layout.layout();
30573 // ie requires a double layout on the first pass
30574 if(Roo.isIE && !this.initialized){
30575 this.initialized = true;
30576 this.layout.layout();
30581 // activate all subpanels if not currently active..
30583 setActiveState : function(active){
30584 this.active = active;
30586 this.fireEvent("deactivate", this);
30590 this.fireEvent("activate", this);
30591 // not sure if this should happen before or after..
30592 if (!this.layout) {
30593 return; // should not happen..
30596 for (var r in this.layout.regions) {
30597 reg = this.layout.getRegion(r);
30598 if (reg.getActivePanel()) {
30599 //reg.showPanel(reg.getActivePanel()); // force it to activate..
30600 reg.setActivePanel(reg.getActivePanel());
30603 if (!reg.panels.length) {
30606 reg.showPanel(reg.getPanel(0));
30615 * Returns the nested BorderLayout for this panel
30616 * @return {Roo.BorderLayout}
30618 getLayout : function(){
30619 return this.layout;
30623 * Adds a xtype elements to the layout of the nested panel
30627 xtype : 'ContentPanel',
30634 xtype : 'NestedLayoutPanel',
30640 items : [ ... list of content panels or nested layout panels.. ]
30644 * @param {Object} cfg Xtype definition of item to add.
30646 addxtype : function(cfg) {
30647 return this.layout.addxtype(cfg);
30652 Roo.ScrollPanel = function(el, config, content){
30653 config = config || {};
30654 config.fitToFrame = true;
30655 Roo.ScrollPanel.superclass.constructor.call(this, el, config, content);
30657 this.el.dom.style.overflow = "hidden";
30658 var wrap = this.el.wrap({cls: "x-scroller x-layout-inactive-content"});
30659 this.el.removeClass("x-layout-inactive-content");
30660 this.el.on("mousewheel", this.onWheel, this);
30662 var up = wrap.createChild({cls: "x-scroller-up", html: " "}, this.el.dom);
30663 var down = wrap.createChild({cls: "x-scroller-down", html: " "});
30664 up.unselectable(); down.unselectable();
30665 up.on("click", this.scrollUp, this);
30666 down.on("click", this.scrollDown, this);
30667 up.addClassOnOver("x-scroller-btn-over");
30668 down.addClassOnOver("x-scroller-btn-over");
30669 up.addClassOnClick("x-scroller-btn-click");
30670 down.addClassOnClick("x-scroller-btn-click");
30671 this.adjustments = [0, -(up.getHeight() + down.getHeight())];
30673 this.resizeEl = this.el;
30674 this.el = wrap; this.up = up; this.down = down;
30677 Roo.extend(Roo.ScrollPanel, Roo.ContentPanel, {
30679 wheelIncrement : 5,
30680 scrollUp : function(){
30681 this.resizeEl.scroll("up", this.increment, {callback: this.afterScroll, scope: this});
30684 scrollDown : function(){
30685 this.resizeEl.scroll("down", this.increment, {callback: this.afterScroll, scope: this});
30688 afterScroll : function(){
30689 var el = this.resizeEl;
30690 var t = el.dom.scrollTop, h = el.dom.scrollHeight, ch = el.dom.clientHeight;
30691 this.up[t == 0 ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
30692 this.down[h - t <= ch ? "addClass" : "removeClass"]("x-scroller-btn-disabled");
30695 setSize : function(){
30696 Roo.ScrollPanel.superclass.setSize.apply(this, arguments);
30697 this.afterScroll();
30700 onWheel : function(e){
30701 var d = e.getWheelDelta();
30702 this.resizeEl.dom.scrollTop -= (d*this.wheelIncrement);
30703 this.afterScroll();
30707 setContent : function(content, loadScripts){
30708 this.resizeEl.update(content, loadScripts);
30722 * @class Roo.TreePanel
30723 * @extends Roo.ContentPanel
30725 * Create a new TreePanel.
30726 * @param {String/Object} config A string to set only the panel's title, or a config object
30727 * @cfg {Roo.tree.TreePanel} tree The tree TreePanel, with config etc.
30729 Roo.TreePanel = function(config){
30730 var el = config.el;
30731 var tree = config.tree;
30732 delete config.tree;
30733 delete config.el; // hopefull!
30734 Roo.TreePanel.superclass.constructor.call(this, el, config);
30735 var treeEl = el.createChild();
30736 this.tree = new Roo.tree.TreePanel(treeEl , tree);
30737 //console.log(tree);
30738 this.on('activate', function()
30740 if (this.tree.rendered) {
30743 //console.log('render tree');
30744 this.tree.render();
30747 this.on('resize', function (cp, w, h) {
30748 this.tree.innerCt.setWidth(w);
30749 this.tree.innerCt.setHeight(h);
30750 this.tree.innerCt.setStyle('overflow-y', 'auto');
30757 Roo.extend(Roo.TreePanel, Roo.ContentPanel);
30771 * Ext JS Library 1.1.1
30772 * Copyright(c) 2006-2007, Ext JS, LLC.
30774 * Originally Released Under LGPL - original licence link has changed is not relivant.
30777 * <script type="text/javascript">
30782 * @class Roo.ReaderLayout
30783 * @extends Roo.BorderLayout
30784 * This is a pre-built layout that represents a classic, 5-pane application. It consists of a header, a primary
30785 * center region containing two nested regions (a top one for a list view and one for item preview below),
30786 * and regions on either side that can be used for navigation, application commands, informational displays, etc.
30787 * The setup and configuration work exactly the same as it does for a {@link Roo.BorderLayout} - this class simply
30788 * expedites the setup of the overall layout and regions for this common application style.
30791 var reader = new Roo.ReaderLayout();
30792 var CP = Roo.ContentPanel; // shortcut for adding
30794 reader.beginUpdate();
30795 reader.add("north", new CP("north", "North"));
30796 reader.add("west", new CP("west", {title: "West"}));
30797 reader.add("east", new CP("east", {title: "East"}));
30799 reader.regions.listView.add(new CP("listView", "List"));
30800 reader.regions.preview.add(new CP("preview", "Preview"));
30801 reader.endUpdate();
30804 * Create a new ReaderLayout
30805 * @param {Object} config Configuration options
30806 * @param {String/HTMLElement/Element} container (optional) The container this layout is bound to (defaults to
30807 * document.body if omitted)
30809 Roo.ReaderLayout = function(config, renderTo){
30810 var c = config || {size:{}};
30811 Roo.ReaderLayout.superclass.constructor.call(this, renderTo || document.body, {
30812 north: c.north !== false ? Roo.apply({
30816 }, c.north) : false,
30817 west: c.west !== false ? Roo.apply({
30825 margins:{left:5,right:0,bottom:5,top:5},
30826 cmargins:{left:5,right:5,bottom:5,top:5}
30827 }, c.west) : false,
30828 east: c.east !== false ? Roo.apply({
30836 margins:{left:0,right:5,bottom:5,top:5},
30837 cmargins:{left:5,right:5,bottom:5,top:5}
30838 }, c.east) : false,
30839 center: Roo.apply({
30840 tabPosition: 'top',
30844 margins:{left:c.west!==false ? 0 : 5,right:c.east!==false ? 0 : 5,bottom:5,top:2}
30848 this.el.addClass('x-reader');
30850 this.beginUpdate();
30852 var inner = new Roo.BorderLayout(Roo.get(document.body).createChild(), {
30853 south: c.preview !== false ? Roo.apply({
30860 cmargins:{top:5,left:0, right:0, bottom:0}
30861 }, c.preview) : false,
30862 center: Roo.apply({
30868 this.add('center', new Roo.NestedLayoutPanel(inner,
30869 Roo.apply({title: c.mainTitle || '',tabTip:''},c.innerPanelCfg)));
30873 this.regions.preview = inner.getRegion('south');
30874 this.regions.listView = inner.getRegion('center');
30877 Roo.extend(Roo.ReaderLayout, Roo.BorderLayout);/*
30879 * Ext JS Library 1.1.1
30880 * Copyright(c) 2006-2007, Ext JS, LLC.
30882 * Originally Released Under LGPL - original licence link has changed is not relivant.
30885 * <script type="text/javascript">
30889 * @class Roo.grid.Grid
30890 * @extends Roo.util.Observable
30891 * This class represents the primary interface of a component based grid control.
30892 * <br><br>Usage:<pre><code>
30893 var grid = new Roo.grid.Grid("my-container-id", {
30896 selModel: mySelectionModel,
30897 autoSizeColumns: true,
30898 monitorWindowResize: false,
30899 trackMouseOver: true
30904 * <b>Common Problems:</b><br/>
30905 * - Grid does not resize properly when going smaller: Setting overflow hidden on the container
30906 * element will correct this<br/>
30907 * - If you get el.style[camel]= NaNpx or -2px or something related, be certain you have given your container element
30908 * dimensions. The grid adapts to your container's size, if your container has no size defined then the results
30909 * are unpredictable.<br/>
30910 * - Do not render the grid into an element with display:none. Try using visibility:hidden. Otherwise there is no way for the
30911 * grid to calculate dimensions/offsets.<br/>
30913 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
30914 * The container MUST have some type of size defined for the grid to fill. The container will be
30915 * automatically set to position relative if it isn't already.
30916 * @param {Object} config A config object that sets properties on this grid.
30918 Roo.grid.Grid = function(container, config){
30919 // initialize the container
30920 this.container = Roo.get(container);
30921 this.container.update("");
30922 this.container.setStyle("overflow", "hidden");
30923 this.container.addClass('x-grid-container');
30925 this.id = this.container.id;
30927 Roo.apply(this, config);
30928 // check and correct shorthanded configs
30930 this.dataSource = this.ds;
30934 this.colModel = this.cm;
30938 this.selModel = this.sm;
30942 if (this.selModel) {
30943 this.selModel = Roo.factory(this.selModel, Roo.grid);
30944 this.sm = this.selModel;
30945 this.sm.xmodule = this.xmodule || false;
30947 if (typeof(this.colModel.config) == 'undefined') {
30948 this.colModel = new Roo.grid.ColumnModel(this.colModel);
30949 this.cm = this.colModel;
30950 this.cm.xmodule = this.xmodule || false;
30952 if (this.dataSource) {
30953 this.dataSource= Roo.factory(this.dataSource, Roo.data);
30954 this.ds = this.dataSource;
30955 this.ds.xmodule = this.xmodule || false;
30962 this.container.setWidth(this.width);
30966 this.container.setHeight(this.height);
30973 * The raw click event for the entire grid.
30974 * @param {Roo.EventObject} e
30979 * The raw dblclick event for the entire grid.
30980 * @param {Roo.EventObject} e
30984 * @event contextmenu
30985 * The raw contextmenu event for the entire grid.
30986 * @param {Roo.EventObject} e
30988 "contextmenu" : true,
30991 * The raw mousedown event for the entire grid.
30992 * @param {Roo.EventObject} e
30994 "mousedown" : true,
30997 * The raw mouseup event for the entire grid.
30998 * @param {Roo.EventObject} e
31003 * The raw mouseover event for the entire grid.
31004 * @param {Roo.EventObject} e
31006 "mouseover" : true,
31009 * The raw mouseout event for the entire grid.
31010 * @param {Roo.EventObject} e
31015 * The raw keypress event for the entire grid.
31016 * @param {Roo.EventObject} e
31021 * The raw keydown event for the entire grid.
31022 * @param {Roo.EventObject} e
31030 * Fires when a cell is clicked
31031 * @param {Grid} this
31032 * @param {Number} rowIndex
31033 * @param {Number} columnIndex
31034 * @param {Roo.EventObject} e
31036 "cellclick" : true,
31038 * @event celldblclick
31039 * Fires when a cell is double clicked
31040 * @param {Grid} this
31041 * @param {Number} rowIndex
31042 * @param {Number} columnIndex
31043 * @param {Roo.EventObject} e
31045 "celldblclick" : true,
31048 * Fires when a row is clicked
31049 * @param {Grid} this
31050 * @param {Number} rowIndex
31051 * @param {Roo.EventObject} e
31055 * @event rowdblclick
31056 * Fires when a row is double clicked
31057 * @param {Grid} this
31058 * @param {Number} rowIndex
31059 * @param {Roo.EventObject} e
31061 "rowdblclick" : true,
31063 * @event headerclick
31064 * Fires when a header is clicked
31065 * @param {Grid} this
31066 * @param {Number} columnIndex
31067 * @param {Roo.EventObject} e
31069 "headerclick" : true,
31071 * @event headerdblclick
31072 * Fires when a header cell is double clicked
31073 * @param {Grid} this
31074 * @param {Number} columnIndex
31075 * @param {Roo.EventObject} e
31077 "headerdblclick" : true,
31079 * @event rowcontextmenu
31080 * Fires when a row is right clicked
31081 * @param {Grid} this
31082 * @param {Number} rowIndex
31083 * @param {Roo.EventObject} e
31085 "rowcontextmenu" : true,
31087 * @event cellcontextmenu
31088 * Fires when a cell is right clicked
31089 * @param {Grid} this
31090 * @param {Number} rowIndex
31091 * @param {Number} cellIndex
31092 * @param {Roo.EventObject} e
31094 "cellcontextmenu" : true,
31096 * @event headercontextmenu
31097 * Fires when a header is right clicked
31098 * @param {Grid} this
31099 * @param {Number} columnIndex
31100 * @param {Roo.EventObject} e
31102 "headercontextmenu" : true,
31104 * @event bodyscroll
31105 * Fires when the body element is scrolled
31106 * @param {Number} scrollLeft
31107 * @param {Number} scrollTop
31109 "bodyscroll" : true,
31111 * @event columnresize
31112 * Fires when the user resizes a column
31113 * @param {Number} columnIndex
31114 * @param {Number} newSize
31116 "columnresize" : true,
31118 * @event columnmove
31119 * Fires when the user moves a column
31120 * @param {Number} oldIndex
31121 * @param {Number} newIndex
31123 "columnmove" : true,
31126 * Fires when row(s) start being dragged
31127 * @param {Grid} this
31128 * @param {Roo.GridDD} dd The drag drop object
31129 * @param {event} e The raw browser event
31131 "startdrag" : true,
31134 * Fires when a drag operation is complete
31135 * @param {Grid} this
31136 * @param {Roo.GridDD} dd The drag drop object
31137 * @param {event} e The raw browser event
31142 * Fires when dragged row(s) are dropped on a valid DD target
31143 * @param {Grid} this
31144 * @param {Roo.GridDD} dd The drag drop object
31145 * @param {String} targetId The target drag drop object
31146 * @param {event} e The raw browser event
31151 * Fires while row(s) are being dragged. "targetId" is the id of the Yahoo.util.DD object the selected rows are being dragged over.
31152 * @param {Grid} this
31153 * @param {Roo.GridDD} dd The drag drop object
31154 * @param {String} targetId The target drag drop object
31155 * @param {event} e The raw browser event
31160 * Fires when the dragged row(s) first cross another DD target while being dragged
31161 * @param {Grid} this
31162 * @param {Roo.GridDD} dd The drag drop object
31163 * @param {String} targetId The target drag drop object
31164 * @param {event} e The raw browser event
31166 "dragenter" : true,
31169 * Fires when the dragged row(s) leave another DD target while being dragged
31170 * @param {Grid} this
31171 * @param {Roo.GridDD} dd The drag drop object
31172 * @param {String} targetId The target drag drop object
31173 * @param {event} e The raw browser event
31178 * Fires when the grid is rendered
31179 * @param {Grid} grid
31184 Roo.grid.Grid.superclass.constructor.call(this);
31186 Roo.extend(Roo.grid.Grid, Roo.util.Observable, {
31188 * @cfg {Number} minColumnWidth The minimum width a column can be resized to. Default is 25.
31190 minColumnWidth : 25,
31193 * @cfg {Boolean} autoSizeColumns True to automatically resize the columns to fit their content
31194 * <b>on initial render.</b> It is more efficient to explicitly size the columns
31195 * through the ColumnModel's {@link Roo.grid.ColumnModel#width} config option. Default is false.
31197 autoSizeColumns : false,
31200 * @cfg {Boolean} autoSizeHeaders True to measure headers with column data when auto sizing columns. Default is true.
31202 autoSizeHeaders : true,
31205 * @cfg {Boolean} monitorWindowResize True to autoSize the grid when the window resizes. Default is true.
31207 monitorWindowResize : true,
31210 * @cfg {Boolean} maxRowsToMeasure If autoSizeColumns is on, maxRowsToMeasure can be used to limit the number of
31211 * rows measured to get a columns size. Default is 0 (all rows).
31213 maxRowsToMeasure : 0,
31216 * @cfg {Boolean} trackMouseOver True to highlight rows when the mouse is over. Default is true.
31218 trackMouseOver : true,
31221 * @cfg {Boolean} enableDragDrop True to enable drag and drop of rows. Default is false.
31223 enableDragDrop : false,
31226 * @cfg {Boolean} enableColumnMove True to enable drag and drop reorder of columns. Default is true.
31228 enableColumnMove : true,
31231 * @cfg {Boolean} enableColumnHide True to enable hiding of columns with the header context menu. Default is true.
31233 enableColumnHide : true,
31236 * @cfg {Boolean} enableRowHeightSync True to manually sync row heights across locked and not locked rows. Default is false.
31238 enableRowHeightSync : false,
31241 * @cfg {Boolean} stripeRows True to stripe the rows. Default is true.
31246 * @cfg {Boolean} autoHeight True to fit the height of the grid container to the height of the data. Default is false.
31248 autoHeight : false,
31251 * @cfg {String} autoExpandColumn The id (or dataIndex) of a column in this grid that should expand to fill unused space. This id can not be 0. Default is false.
31253 autoExpandColumn : false,
31256 * @cfg {Number} autoExpandMin The minimum width the autoExpandColumn can have (if enabled).
31259 autoExpandMin : 50,
31262 * @cfg {Number} autoExpandMax The maximum width the autoExpandColumn can have (if enabled). Default is 1000.
31264 autoExpandMax : 1000,
31267 * @cfg {Object} view The {@link Roo.grid.GridView} used by the grid. This can be set before a call to render().
31272 * @cfg {Object} loadMask An {@link Roo.LoadMask} config or true to mask the grid while loading. Default is false.
31280 * @cfg {Boolean} autoWidth True to set the grid's width to the default total width of the grid's columns instead
31281 * of a fixed width. Default is false.
31284 * @cfg {Number} maxHeight Sets the maximum height of the grid - ignored if autoHeight is not on.
31287 * Called once after all setup has been completed and the grid is ready to be rendered.
31288 * @return {Roo.grid.Grid} this
31290 render : function(){
31291 var c = this.container;
31292 // try to detect autoHeight/width mode
31293 if((!c.dom.offsetHeight || c.dom.offsetHeight < 20) || c.getStyle("height") == "auto"){
31294 this.autoHeight = true;
31296 var view = this.getView();
31299 c.on("click", this.onClick, this);
31300 c.on("dblclick", this.onDblClick, this);
31301 c.on("contextmenu", this.onContextMenu, this);
31302 c.on("keydown", this.onKeyDown, this);
31304 this.relayEvents(c, ["mousedown","mouseup","mouseover","mouseout","keypress"]);
31306 this.getSelectionModel().init(this);
31311 this.loadMask = new Roo.LoadMask(this.container,
31312 Roo.apply({store:this.dataSource}, this.loadMask));
31316 if (this.toolbar && this.toolbar.xtype) {
31317 this.toolbar.container = this.getView().getHeaderPanel(true);
31318 this.toolbar = new Ext.Toolbar(this.toolbar);
31320 if (this.footer && this.footer.xtype) {
31321 this.footer.dataSource = this.getDataSource();
31322 this.footer.container = this.getView().getFooterPanel(true);
31323 this.footer = Roo.factory(this.footer, Roo);
31325 this.rendered = true;
31326 this.fireEvent('render', this);
31331 * Reconfigures the grid to use a different Store and Column Model.
31332 * The View will be bound to the new objects and refreshed.
31333 * @param {Roo.data.Store} dataSource The new {@link Roo.data.Store} object
31334 * @param {Roo.grid.ColumnModel} The new {@link Roo.grid.ColumnModel} object
31336 reconfigure : function(dataSource, colModel){
31338 this.loadMask.destroy();
31339 this.loadMask = new Roo.LoadMask(this.container,
31340 Roo.apply({store:dataSource}, this.loadMask));
31342 this.view.bind(dataSource, colModel);
31343 this.dataSource = dataSource;
31344 this.colModel = colModel;
31345 this.view.refresh(true);
31349 onKeyDown : function(e){
31350 this.fireEvent("keydown", e);
31354 * Destroy this grid.
31355 * @param {Boolean} removeEl True to remove the element
31357 destroy : function(removeEl, keepListeners){
31359 this.loadMask.destroy();
31361 var c = this.container;
31362 c.removeAllListeners();
31363 this.view.destroy();
31364 this.colModel.purgeListeners();
31365 if(!keepListeners){
31366 this.purgeListeners();
31369 if(removeEl === true){
31375 processEvent : function(name, e){
31376 this.fireEvent(name, e);
31377 var t = e.getTarget();
31379 var header = v.findHeaderIndex(t);
31380 if(header !== false){
31381 this.fireEvent("header" + name, this, header, e);
31383 var row = v.findRowIndex(t);
31384 var cell = v.findCellIndex(t);
31386 this.fireEvent("row" + name, this, row, e);
31387 if(cell !== false){
31388 this.fireEvent("cell" + name, this, row, cell, e);
31395 onClick : function(e){
31396 this.processEvent("click", e);
31400 onContextMenu : function(e, t){
31401 this.processEvent("contextmenu", e);
31405 onDblClick : function(e){
31406 this.processEvent("dblclick", e);
31410 walkCells : function(row, col, step, fn, scope){
31411 var cm = this.colModel, clen = cm.getColumnCount();
31412 var ds = this.dataSource, rlen = ds.getCount(), first = true;
31424 if(fn.call(scope || this, row, col, cm) === true){
31442 if(fn.call(scope || this, row, col, cm) === true){
31454 getSelections : function(){
31455 return this.selModel.getSelections();
31459 * Causes the grid to manually recalculate its dimensions. Generally this is done automatically,
31460 * but if manual update is required this method will initiate it.
31462 autoSize : function(){
31464 this.view.layout();
31465 if(this.view.adjustForScroll){
31466 this.view.adjustForScroll();
31472 * Returns the grid's underlying element.
31473 * @return {Element} The element
31475 getGridEl : function(){
31476 return this.container;
31479 // private for compatibility, overridden by editor grid
31480 stopEditing : function(){},
31483 * Returns the grid's SelectionModel.
31484 * @return {SelectionModel}
31486 getSelectionModel : function(){
31487 if(!this.selModel){
31488 this.selModel = new Roo.grid.RowSelectionModel();
31490 return this.selModel;
31494 * Returns the grid's DataSource.
31495 * @return {DataSource}
31497 getDataSource : function(){
31498 return this.dataSource;
31502 * Returns the grid's ColumnModel.
31503 * @return {ColumnModel}
31505 getColumnModel : function(){
31506 return this.colModel;
31510 * Returns the grid's GridView object.
31511 * @return {GridView}
31513 getView : function(){
31515 this.view = new Roo.grid.GridView(this.viewConfig);
31520 * Called to get grid's drag proxy text, by default returns this.ddText.
31523 getDragDropText : function(){
31524 var count = this.selModel.getCount();
31525 return String.format(this.ddText, count, count == 1 ? '' : 's');
31529 * Configures the text is the drag proxy (defaults to "%0 selected row(s)").
31530 * %0 is replaced with the number of selected rows.
31533 Roo.grid.Grid.prototype.ddText = "{0} selected row{1}";/*
31535 * Ext JS Library 1.1.1
31536 * Copyright(c) 2006-2007, Ext JS, LLC.
31538 * Originally Released Under LGPL - original licence link has changed is not relivant.
31541 * <script type="text/javascript">
31544 Roo.grid.AbstractGridView = function(){
31548 "beforerowremoved" : true,
31549 "beforerowsinserted" : true,
31550 "beforerefresh" : true,
31551 "rowremoved" : true,
31552 "rowsinserted" : true,
31553 "rowupdated" : true,
31556 Roo.grid.AbstractGridView.superclass.constructor.call(this);
31559 Roo.extend(Roo.grid.AbstractGridView, Roo.util.Observable, {
31560 rowClass : "x-grid-row",
31561 cellClass : "x-grid-cell",
31562 tdClass : "x-grid-td",
31563 hdClass : "x-grid-hd",
31564 splitClass : "x-grid-hd-split",
31566 init: function(grid){
31568 var cid = this.grid.getGridEl().id;
31569 this.colSelector = "#" + cid + " ." + this.cellClass + "-";
31570 this.tdSelector = "#" + cid + " ." + this.tdClass + "-";
31571 this.hdSelector = "#" + cid + " ." + this.hdClass + "-";
31572 this.splitSelector = "#" + cid + " ." + this.splitClass + "-";
31575 getColumnRenderers : function(){
31576 var renderers = [];
31577 var cm = this.grid.colModel;
31578 var colCount = cm.getColumnCount();
31579 for(var i = 0; i < colCount; i++){
31580 renderers[i] = cm.getRenderer(i);
31585 getColumnIds : function(){
31587 var cm = this.grid.colModel;
31588 var colCount = cm.getColumnCount();
31589 for(var i = 0; i < colCount; i++){
31590 ids[i] = cm.getColumnId(i);
31595 getDataIndexes : function(){
31596 if(!this.indexMap){
31597 this.indexMap = this.buildIndexMap();
31599 return this.indexMap.colToData;
31602 getColumnIndexByDataIndex : function(dataIndex){
31603 if(!this.indexMap){
31604 this.indexMap = this.buildIndexMap();
31606 return this.indexMap.dataToCol[dataIndex];
31610 * Set a css style for a column dynamically.
31611 * @param {Number} colIndex The index of the column
31612 * @param {String} name The css property name
31613 * @param {String} value The css value
31615 setCSSStyle : function(colIndex, name, value){
31616 var selector = "#" + this.grid.id + " .x-grid-col-" + colIndex;
31617 Roo.util.CSS.updateRule(selector, name, value);
31620 generateRules : function(cm){
31621 var ruleBuf = [], rulesId = this.grid.id + '-cssrules';
31622 Roo.util.CSS.removeStyleSheet(rulesId);
31623 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
31624 var cid = cm.getColumnId(i);
31625 ruleBuf.push(this.colSelector, cid, " {\n", cm.config[i].css, "}\n",
31626 this.tdSelector, cid, " {\n}\n",
31627 this.hdSelector, cid, " {\n}\n",
31628 this.splitSelector, cid, " {\n}\n");
31630 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
31634 * Ext JS Library 1.1.1
31635 * Copyright(c) 2006-2007, Ext JS, LLC.
31637 * Originally Released Under LGPL - original licence link has changed is not relivant.
31640 * <script type="text/javascript">
31644 // This is a support class used internally by the Grid components
31645 Roo.grid.HeaderDragZone = function(grid, hd, hd2){
31647 this.view = grid.getView();
31648 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
31649 Roo.grid.HeaderDragZone.superclass.constructor.call(this, hd);
31651 this.setHandleElId(Roo.id(hd));
31652 this.setOuterHandleElId(Roo.id(hd2));
31654 this.scroll = false;
31656 Roo.extend(Roo.grid.HeaderDragZone, Roo.dd.DragZone, {
31658 getDragData : function(e){
31659 var t = Roo.lib.Event.getTarget(e);
31660 var h = this.view.findHeaderCell(t);
31662 return {ddel: h.firstChild, header:h};
31667 onInitDrag : function(e){
31668 this.view.headersDisabled = true;
31669 var clone = this.dragData.ddel.cloneNode(true);
31670 clone.id = Roo.id();
31671 clone.style.width = Math.min(this.dragData.header.offsetWidth,this.maxDragWidth) + "px";
31672 this.proxy.update(clone);
31676 afterValidDrop : function(){
31678 setTimeout(function(){
31679 v.headersDisabled = false;
31683 afterInvalidDrop : function(){
31685 setTimeout(function(){
31686 v.headersDisabled = false;
31692 * Ext JS Library 1.1.1
31693 * Copyright(c) 2006-2007, Ext JS, LLC.
31695 * Originally Released Under LGPL - original licence link has changed is not relivant.
31698 * <script type="text/javascript">
31701 // This is a support class used internally by the Grid components
31702 Roo.grid.HeaderDropZone = function(grid, hd, hd2){
31704 this.view = grid.getView();
31705 // split the proxies so they don't interfere with mouse events
31706 this.proxyTop = Roo.DomHelper.append(document.body, {
31707 cls:"col-move-top", html:" "
31709 this.proxyBottom = Roo.DomHelper.append(document.body, {
31710 cls:"col-move-bottom", html:" "
31712 this.proxyTop.hide = this.proxyBottom.hide = function(){
31713 this.setLeftTop(-100,-100);
31714 this.setStyle("visibility", "hidden");
31716 this.ddGroup = "gridHeader" + this.grid.getGridEl().id;
31717 // temporarily disabled
31718 //Roo.dd.ScrollManager.register(this.view.scroller.dom);
31719 Roo.grid.HeaderDropZone.superclass.constructor.call(this, grid.getGridEl().dom);
31721 Roo.extend(Roo.grid.HeaderDropZone, Roo.dd.DropZone, {
31722 proxyOffsets : [-4, -9],
31723 fly: Roo.Element.fly,
31725 getTargetFromEvent : function(e){
31726 var t = Roo.lib.Event.getTarget(e);
31727 var cindex = this.view.findCellIndex(t);
31728 if(cindex !== false){
31729 return this.view.getHeaderCell(cindex);
31733 nextVisible : function(h){
31734 var v = this.view, cm = this.grid.colModel;
31737 if(!cm.isHidden(v.getCellIndex(h))){
31745 prevVisible : function(h){
31746 var v = this.view, cm = this.grid.colModel;
31749 if(!cm.isHidden(v.getCellIndex(h))){
31757 positionIndicator : function(h, n, e){
31758 var x = Roo.lib.Event.getPageX(e);
31759 var r = Roo.lib.Dom.getRegion(n.firstChild);
31760 var px, pt, py = r.top + this.proxyOffsets[1];
31761 if((r.right - x) <= (r.right-r.left)/2){
31762 px = r.right+this.view.borderWidth;
31768 var oldIndex = this.view.getCellIndex(h);
31769 var newIndex = this.view.getCellIndex(n);
31771 if(this.grid.colModel.isFixed(newIndex)){
31775 var locked = this.grid.colModel.isLocked(newIndex);
31780 if(oldIndex < newIndex){
31783 if(oldIndex == newIndex && (locked == this.grid.colModel.isLocked(oldIndex))){
31786 px += this.proxyOffsets[0];
31787 this.proxyTop.setLeftTop(px, py);
31788 this.proxyTop.show();
31789 if(!this.bottomOffset){
31790 this.bottomOffset = this.view.mainHd.getHeight();
31792 this.proxyBottom.setLeftTop(px, py+this.proxyTop.dom.offsetHeight+this.bottomOffset);
31793 this.proxyBottom.show();
31797 onNodeEnter : function(n, dd, e, data){
31798 if(data.header != n){
31799 this.positionIndicator(data.header, n, e);
31803 onNodeOver : function(n, dd, e, data){
31804 var result = false;
31805 if(data.header != n){
31806 result = this.positionIndicator(data.header, n, e);
31809 this.proxyTop.hide();
31810 this.proxyBottom.hide();
31812 return result ? this.dropAllowed : this.dropNotAllowed;
31815 onNodeOut : function(n, dd, e, data){
31816 this.proxyTop.hide();
31817 this.proxyBottom.hide();
31820 onNodeDrop : function(n, dd, e, data){
31821 var h = data.header;
31823 var cm = this.grid.colModel;
31824 var x = Roo.lib.Event.getPageX(e);
31825 var r = Roo.lib.Dom.getRegion(n.firstChild);
31826 var pt = (r.right - x) <= ((r.right-r.left)/2) ? "after" : "before";
31827 var oldIndex = this.view.getCellIndex(h);
31828 var newIndex = this.view.getCellIndex(n);
31829 var locked = cm.isLocked(newIndex);
31833 if(oldIndex < newIndex){
31836 if(oldIndex == newIndex && (locked == cm.isLocked(oldIndex))){
31839 cm.setLocked(oldIndex, locked, true);
31840 cm.moveColumn(oldIndex, newIndex);
31841 this.grid.fireEvent("columnmove", oldIndex, newIndex);
31849 * Ext JS Library 1.1.1
31850 * Copyright(c) 2006-2007, Ext JS, LLC.
31852 * Originally Released Under LGPL - original licence link has changed is not relivant.
31855 * <script type="text/javascript">
31859 * @class Roo.grid.GridView
31860 * @extends Roo.util.Observable
31863 * @param {Object} config
31865 Roo.grid.GridView = function(config){
31866 Roo.grid.GridView.superclass.constructor.call(this);
31869 Roo.apply(this, config);
31872 Roo.extend(Roo.grid.GridView, Roo.grid.AbstractGridView, {
31875 * Override this function to apply custom css classes to rows during rendering
31876 * @param {Record} record The record
31877 * @param {Number} index
31878 * @method getRowClass
31880 rowClass : "x-grid-row",
31882 cellClass : "x-grid-col",
31884 tdClass : "x-grid-td",
31886 hdClass : "x-grid-hd",
31888 splitClass : "x-grid-split",
31890 sortClasses : ["sort-asc", "sort-desc"],
31892 enableMoveAnim : false,
31896 dh : Roo.DomHelper,
31898 fly : Roo.Element.fly,
31900 css : Roo.util.CSS,
31906 scrollIncrement : 22,
31908 cellRE: /(?:.*?)x-grid-(?:hd|cell|csplit)-(?:[\d]+)-([\d]+)(?:.*?)/,
31910 findRE: /\s?(?:x-grid-hd|x-grid-col|x-grid-csplit)\s/,
31912 bind : function(ds, cm){
31914 this.ds.un("load", this.onLoad, this);
31915 this.ds.un("datachanged", this.onDataChange, this);
31916 this.ds.un("add", this.onAdd, this);
31917 this.ds.un("remove", this.onRemove, this);
31918 this.ds.un("update", this.onUpdate, this);
31919 this.ds.un("clear", this.onClear, this);
31922 ds.on("load", this.onLoad, this);
31923 ds.on("datachanged", this.onDataChange, this);
31924 ds.on("add", this.onAdd, this);
31925 ds.on("remove", this.onRemove, this);
31926 ds.on("update", this.onUpdate, this);
31927 ds.on("clear", this.onClear, this);
31932 this.cm.un("widthchange", this.onColWidthChange, this);
31933 this.cm.un("headerchange", this.onHeaderChange, this);
31934 this.cm.un("hiddenchange", this.onHiddenChange, this);
31935 this.cm.un("columnmoved", this.onColumnMove, this);
31936 this.cm.un("columnlockchange", this.onColumnLock, this);
31939 this.generateRules(cm);
31940 cm.on("widthchange", this.onColWidthChange, this);
31941 cm.on("headerchange", this.onHeaderChange, this);
31942 cm.on("hiddenchange", this.onHiddenChange, this);
31943 cm.on("columnmoved", this.onColumnMove, this);
31944 cm.on("columnlockchange", this.onColumnLock, this);
31949 init: function(grid){
31950 Roo.grid.GridView.superclass.init.call(this, grid);
31952 this.bind(grid.dataSource, grid.colModel);
31954 grid.on("headerclick", this.handleHeaderClick, this);
31956 if(grid.trackMouseOver){
31957 grid.on("mouseover", this.onRowOver, this);
31958 grid.on("mouseout", this.onRowOut, this);
31960 grid.cancelTextSelection = function(){};
31961 this.gridId = grid.id;
31963 var tpls = this.templates || {};
31966 tpls.master = new Roo.Template(
31967 '<div class="x-grid" hidefocus="true">',
31968 '<div class="x-grid-topbar"></div>',
31969 '<div class="x-grid-scroller"><div></div></div>',
31970 '<div class="x-grid-locked">',
31971 '<div class="x-grid-header">{lockedHeader}</div>',
31972 '<div class="x-grid-body">{lockedBody}</div>',
31974 '<div class="x-grid-viewport">',
31975 '<div class="x-grid-header">{header}</div>',
31976 '<div class="x-grid-body">{body}</div>',
31978 '<div class="x-grid-bottombar"></div>',
31979 '<a href="#" class="x-grid-focus" tabIndex="-1"></a>',
31980 '<div class="x-grid-resize-proxy"> </div>',
31983 tpls.master.disableformats = true;
31987 tpls.header = new Roo.Template(
31988 '<table border="0" cellspacing="0" cellpadding="0">',
31989 '<tbody><tr class="x-grid-hd-row">{cells}</tr></tbody>',
31992 tpls.header.disableformats = true;
31994 tpls.header.compile();
31997 tpls.hcell = new Roo.Template(
31998 '<td class="x-grid-hd x-grid-td-{id} {cellId}"><div title="{title}" class="x-grid-hd-inner x-grid-hd-{id}">',
31999 '<div class="x-grid-hd-text" unselectable="on">{value}<img class="x-grid-sort-icon" src="', Roo.BLANK_IMAGE_URL, '" /></div>',
32002 tpls.hcell.disableFormats = true;
32004 tpls.hcell.compile();
32007 tpls.hsplit = new Roo.Template('<div class="x-grid-split {splitId} x-grid-split-{id}" style="{style}" unselectable="on"> </div>');
32008 tpls.hsplit.disableFormats = true;
32010 tpls.hsplit.compile();
32013 tpls.body = new Roo.Template(
32014 '<table border="0" cellspacing="0" cellpadding="0">',
32015 "<tbody>{rows}</tbody>",
32018 tpls.body.disableFormats = true;
32020 tpls.body.compile();
32023 tpls.row = new Roo.Template('<tr class="x-grid-row {alt}">{cells}</tr>');
32024 tpls.row.disableFormats = true;
32026 tpls.row.compile();
32029 tpls.cell = new Roo.Template(
32030 '<td class="x-grid-col x-grid-td-{id} {cellId} {css}" tabIndex="0">',
32031 '<div class="x-grid-col-{id} x-grid-cell-inner"><div class="x-grid-cell-text" unselectable="on" {attr}>{value}</div></div>',
32034 tpls.cell.disableFormats = true;
32036 tpls.cell.compile();
32038 this.templates = tpls;
32041 // remap these for backwards compat
32042 onColWidthChange : function(){
32043 this.updateColumns.apply(this, arguments);
32045 onHeaderChange : function(){
32046 this.updateHeaders.apply(this, arguments);
32048 onHiddenChange : function(){
32049 this.handleHiddenChange.apply(this, arguments);
32051 onColumnMove : function(){
32052 this.handleColumnMove.apply(this, arguments);
32054 onColumnLock : function(){
32055 this.handleLockChange.apply(this, arguments);
32058 onDataChange : function(){
32060 this.updateHeaderSortState();
32063 onClear : function(){
32067 onUpdate : function(ds, record){
32068 this.refreshRow(record);
32071 refreshRow : function(record){
32072 var ds = this.ds, index;
32073 if(typeof record == 'number'){
32075 record = ds.getAt(index);
32077 index = ds.indexOf(record);
32079 this.insertRows(ds, index, index, true);
32080 this.onRemove(ds, record, index+1, true);
32081 this.syncRowHeights(index, index);
32083 this.fireEvent("rowupdated", this, index, record);
32086 onAdd : function(ds, records, index){
32087 this.insertRows(ds, index, index + (records.length-1));
32090 onRemove : function(ds, record, index, isUpdate){
32091 if(isUpdate !== true){
32092 this.fireEvent("beforerowremoved", this, index, record);
32094 var bt = this.getBodyTable(), lt = this.getLockedTable();
32095 if(bt.rows[index]){
32096 bt.firstChild.removeChild(bt.rows[index]);
32098 if(lt.rows[index]){
32099 lt.firstChild.removeChild(lt.rows[index]);
32101 if(isUpdate !== true){
32102 this.stripeRows(index);
32103 this.syncRowHeights(index, index);
32105 this.fireEvent("rowremoved", this, index, record);
32109 onLoad : function(){
32110 this.scrollToTop();
32114 * Scrolls the grid to the top
32116 scrollToTop : function(){
32118 this.scroller.dom.scrollTop = 0;
32124 * Gets a panel in the header of the grid that can be used for toolbars etc.
32125 * After modifying the contents of this panel a call to grid.autoSize() may be
32126 * required to register any changes in size.
32127 * @param {Boolean} doShow By default the header is hidden. Pass true to show the panel
32128 * @return Roo.Element
32130 getHeaderPanel : function(doShow){
32132 this.headerPanel.show();
32134 return this.headerPanel;
32138 * Gets a panel in the footer of the grid that can be used for toolbars etc.
32139 * After modifying the contents of this panel a call to grid.autoSize() may be
32140 * required to register any changes in size.
32141 * @param {Boolean} doShow By default the footer is hidden. Pass true to show the panel
32142 * @return Roo.Element
32144 getFooterPanel : function(doShow){
32146 this.footerPanel.show();
32148 return this.footerPanel;
32151 initElements : function(){
32152 var E = Roo.Element;
32153 var el = this.grid.getGridEl().dom.firstChild;
32154 var cs = el.childNodes;
32156 this.el = new E(el);
32157 this.headerPanel = new E(el.firstChild);
32158 this.headerPanel.enableDisplayMode("block");
32160 this.scroller = new E(cs[1]);
32161 this.scrollSizer = new E(this.scroller.dom.firstChild);
32163 this.lockedWrap = new E(cs[2]);
32164 this.lockedHd = new E(this.lockedWrap.dom.firstChild);
32165 this.lockedBody = new E(this.lockedWrap.dom.childNodes[1]);
32167 this.mainWrap = new E(cs[3]);
32168 this.mainHd = new E(this.mainWrap.dom.firstChild);
32169 this.mainBody = new E(this.mainWrap.dom.childNodes[1]);
32171 this.footerPanel = new E(cs[4]);
32172 this.footerPanel.enableDisplayMode("block");
32174 this.focusEl = new E(cs[5]);
32175 this.focusEl.swallowEvent("click", true);
32176 this.resizeProxy = new E(cs[6]);
32178 this.headerSelector = String.format(
32179 '#{0} td.x-grid-hd, #{1} td.x-grid-hd',
32180 this.lockedHd.id, this.mainHd.id
32183 this.splitterSelector = String.format(
32184 '#{0} div.x-grid-split, #{1} div.x-grid-split',
32185 this.idToCssName(this.lockedHd.id), this.idToCssName(this.mainHd.id)
32188 idToCssName : function(s)
32190 return s.replace(/[^a-z0-9]+/ig, '-');
32193 getHeaderCell : function(index){
32194 return Roo.DomQuery.select(this.headerSelector)[index];
32197 getHeaderCellMeasure : function(index){
32198 return this.getHeaderCell(index).firstChild;
32201 getHeaderCellText : function(index){
32202 return this.getHeaderCell(index).firstChild.firstChild;
32205 getLockedTable : function(){
32206 return this.lockedBody.dom.firstChild;
32209 getBodyTable : function(){
32210 return this.mainBody.dom.firstChild;
32213 getLockedRow : function(index){
32214 return this.getLockedTable().rows[index];
32217 getRow : function(index){
32218 return this.getBodyTable().rows[index];
32221 getRowComposite : function(index){
32223 this.rowEl = new Roo.CompositeElementLite();
32225 var els = [], lrow, mrow;
32226 if(lrow = this.getLockedRow(index)){
32229 if(mrow = this.getRow(index)){
32232 this.rowEl.elements = els;
32236 getCell : function(rowIndex, colIndex){
32237 var locked = this.cm.getLockedCount();
32239 if(colIndex < locked){
32240 source = this.lockedBody.dom.firstChild;
32242 source = this.mainBody.dom.firstChild;
32243 colIndex -= locked;
32245 return source.rows[rowIndex].childNodes[colIndex];
32248 getCellText : function(rowIndex, colIndex){
32249 return this.getCell(rowIndex, colIndex).firstChild.firstChild;
32252 getCellBox : function(cell){
32253 var b = this.fly(cell).getBox();
32254 if(Roo.isOpera){ // opera fails to report the Y
32255 b.y = cell.offsetTop + this.mainBody.getY();
32260 getCellIndex : function(cell){
32261 var id = String(cell.className).match(this.cellRE);
32263 return parseInt(id[1], 10);
32268 findHeaderIndex : function(n){
32269 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
32270 return r ? this.getCellIndex(r) : false;
32273 findHeaderCell : function(n){
32274 var r = Roo.fly(n).findParent("td." + this.hdClass, 6);
32275 return r ? r : false;
32278 findRowIndex : function(n){
32282 var r = Roo.fly(n).findParent("tr." + this.rowClass, 6);
32283 return r ? r.rowIndex : false;
32286 findCellIndex : function(node){
32287 var stop = this.el.dom;
32288 while(node && node != stop){
32289 if(this.findRE.test(node.className)){
32290 return this.getCellIndex(node);
32292 node = node.parentNode;
32297 getColumnId : function(index){
32298 return this.cm.getColumnId(index);
32301 getSplitters : function(){
32302 if(this.splitterSelector){
32303 return Roo.DomQuery.select(this.splitterSelector);
32309 getSplitter : function(index){
32310 return this.getSplitters()[index];
32313 onRowOver : function(e, t){
32315 if((row = this.findRowIndex(t)) !== false){
32316 this.getRowComposite(row).addClass("x-grid-row-over");
32320 onRowOut : function(e, t){
32322 if((row = this.findRowIndex(t)) !== false && row !== this.findRowIndex(e.getRelatedTarget())){
32323 this.getRowComposite(row).removeClass("x-grid-row-over");
32327 renderHeaders : function(){
32329 var ct = this.templates.hcell, ht = this.templates.header, st = this.templates.hsplit;
32330 var cb = [], lb = [], sb = [], lsb = [], p = {};
32331 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
32332 p.cellId = "x-grid-hd-0-" + i;
32333 p.splitId = "x-grid-csplit-0-" + i;
32334 p.id = cm.getColumnId(i);
32335 p.title = cm.getColumnTooltip(i) || "";
32336 p.value = cm.getColumnHeader(i) || "";
32337 p.style = (this.grid.enableColumnResize === false || !cm.isResizable(i) || cm.isFixed(i)) ? 'cursor:default' : '';
32338 if(!cm.isLocked(i)){
32339 cb[cb.length] = ct.apply(p);
32340 sb[sb.length] = st.apply(p);
32342 lb[lb.length] = ct.apply(p);
32343 lsb[lsb.length] = st.apply(p);
32346 return [ht.apply({cells: lb.join(""), splits:lsb.join("")}),
32347 ht.apply({cells: cb.join(""), splits:sb.join("")})];
32350 updateHeaders : function(){
32351 var html = this.renderHeaders();
32352 this.lockedHd.update(html[0]);
32353 this.mainHd.update(html[1]);
32357 * Focuses the specified row.
32358 * @param {Number} row The row index
32360 focusRow : function(row){
32361 var x = this.scroller.dom.scrollLeft;
32362 this.focusCell(row, 0, false);
32363 this.scroller.dom.scrollLeft = x;
32367 * Focuses the specified cell.
32368 * @param {Number} row The row index
32369 * @param {Number} col The column index
32370 * @param {Boolean} hscroll false to disable horizontal scrolling
32372 focusCell : function(row, col, hscroll){
32373 var el = this.ensureVisible(row, col, hscroll);
32374 this.focusEl.alignTo(el, "tl-tl");
32376 this.focusEl.focus();
32378 this.focusEl.focus.defer(1, this.focusEl);
32383 * Scrolls the specified cell into view
32384 * @param {Number} row The row index
32385 * @param {Number} col The column index
32386 * @param {Boolean} hscroll false to disable horizontal scrolling
32388 ensureVisible : function(row, col, hscroll){
32389 if(typeof row != "number"){
32390 row = row.rowIndex;
32392 if(row < 0 && row >= this.ds.getCount()){
32395 col = (col !== undefined ? col : 0);
32396 var cm = this.grid.colModel;
32397 while(cm.isHidden(col)){
32401 var el = this.getCell(row, col);
32405 var c = this.scroller.dom;
32407 var ctop = parseInt(el.offsetTop, 10);
32408 var cleft = parseInt(el.offsetLeft, 10);
32409 var cbot = ctop + el.offsetHeight;
32410 var cright = cleft + el.offsetWidth;
32412 var ch = c.clientHeight - this.mainHd.dom.offsetHeight;
32413 var stop = parseInt(c.scrollTop, 10);
32414 var sleft = parseInt(c.scrollLeft, 10);
32415 var sbot = stop + ch;
32416 var sright = sleft + c.clientWidth;
32419 c.scrollTop = ctop;
32420 }else if(cbot > sbot){
32421 c.scrollTop = cbot-ch;
32424 if(hscroll !== false){
32426 c.scrollLeft = cleft;
32427 }else if(cright > sright){
32428 c.scrollLeft = cright-c.clientWidth;
32434 updateColumns : function(){
32435 this.grid.stopEditing();
32436 var cm = this.grid.colModel, colIds = this.getColumnIds();
32437 //var totalWidth = cm.getTotalWidth();
32439 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
32440 //if(cm.isHidden(i)) continue;
32441 var w = cm.getColumnWidth(i);
32442 this.css.updateRule(this.colSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
32443 this.css.updateRule(this.hdSelector+this.idToCssName(colIds[i]), "width", (w - this.borderWidth) + "px");
32445 this.updateSplitters();
32448 generateRules : function(cm){
32449 var ruleBuf = [], rulesId = this.idToCssName(this.grid.id)+ '-cssrules';
32450 Roo.util.CSS.removeStyleSheet(rulesId);
32451 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
32452 var cid = cm.getColumnId(i);
32454 if(cm.config[i].align){
32455 align = 'text-align:'+cm.config[i].align+';';
32458 if(cm.isHidden(i)){
32459 hidden = 'display:none;';
32461 var width = "width:" + (cm.getColumnWidth(i) - this.borderWidth) + "px;";
32463 this.colSelector, cid, " {\n", cm.config[i].css, align, width, "\n}\n",
32464 this.hdSelector, cid, " {\n", align, width, "}\n",
32465 this.tdSelector, cid, " {\n",hidden,"\n}\n",
32466 this.splitSelector, cid, " {\n", hidden , "\n}\n");
32468 return Roo.util.CSS.createStyleSheet(ruleBuf.join(""), rulesId);
32471 updateSplitters : function(){
32472 var cm = this.cm, s = this.getSplitters();
32473 if(s){ // splitters not created yet
32474 var pos = 0, locked = true;
32475 for(var i = 0, len = cm.getColumnCount(); i < len; i++){
32476 if(cm.isHidden(i)) continue;
32477 var w = cm.getColumnWidth(i);
32478 if(!cm.isLocked(i) && locked){
32483 s[i].style.left = (pos-this.splitOffset) + "px";
32488 handleHiddenChange : function(colModel, colIndex, hidden){
32490 this.hideColumn(colIndex);
32492 this.unhideColumn(colIndex);
32496 hideColumn : function(colIndex){
32497 var cid = this.getColumnId(colIndex);
32498 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "none");
32499 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "none");
32501 this.updateHeaders();
32503 this.updateSplitters();
32507 unhideColumn : function(colIndex){
32508 var cid = this.getColumnId(colIndex);
32509 this.css.updateRule(this.tdSelector+this.idToCssName(cid), "display", "");
32510 this.css.updateRule(this.splitSelector+this.idToCssName(cid), "display", "");
32513 this.updateHeaders();
32515 this.updateSplitters();
32519 insertRows : function(dm, firstRow, lastRow, isUpdate){
32520 if(firstRow == 0 && lastRow == dm.getCount()-1){
32524 this.fireEvent("beforerowsinserted", this, firstRow, lastRow);
32526 var s = this.getScrollState();
32527 var markup = this.renderRows(firstRow, lastRow);
32528 this.bufferRows(markup[0], this.getLockedTable(), firstRow);
32529 this.bufferRows(markup[1], this.getBodyTable(), firstRow);
32530 this.restoreScroll(s);
32532 this.fireEvent("rowsinserted", this, firstRow, lastRow);
32533 this.syncRowHeights(firstRow, lastRow);
32534 this.stripeRows(firstRow);
32540 bufferRows : function(markup, target, index){
32541 var before = null, trows = target.rows, tbody = target.tBodies[0];
32542 if(index < trows.length){
32543 before = trows[index];
32545 var b = document.createElement("div");
32546 b.innerHTML = "<table><tbody>"+markup+"</tbody></table>";
32547 var rows = b.firstChild.rows;
32548 for(var i = 0, len = rows.length; i < len; i++){
32550 tbody.insertBefore(rows[0], before);
32552 tbody.appendChild(rows[0]);
32559 deleteRows : function(dm, firstRow, lastRow){
32560 if(dm.getRowCount()<1){
32561 this.fireEvent("beforerefresh", this);
32562 this.mainBody.update("");
32563 this.lockedBody.update("");
32564 this.fireEvent("refresh", this);
32566 this.fireEvent("beforerowsdeleted", this, firstRow, lastRow);
32567 var bt = this.getBodyTable();
32568 var tbody = bt.firstChild;
32569 var rows = bt.rows;
32570 for(var rowIndex = firstRow; rowIndex <= lastRow; rowIndex++){
32571 tbody.removeChild(rows[firstRow]);
32573 this.stripeRows(firstRow);
32574 this.fireEvent("rowsdeleted", this, firstRow, lastRow);
32578 updateRows : function(dataSource, firstRow, lastRow){
32579 var s = this.getScrollState();
32581 this.restoreScroll(s);
32584 handleSort : function(dataSource, sortColumnIndex, sortDir, noRefresh){
32588 this.updateHeaderSortState();
32591 getScrollState : function(){
32592 var sb = this.scroller.dom;
32593 return {left: sb.scrollLeft, top: sb.scrollTop};
32596 stripeRows : function(startRow){
32597 if(!this.grid.stripeRows || this.ds.getCount() < 1){
32600 startRow = startRow || 0;
32601 var rows = this.getBodyTable().rows;
32602 var lrows = this.getLockedTable().rows;
32603 var cls = ' x-grid-row-alt ';
32604 for(var i = startRow, len = rows.length; i < len; i++){
32605 var row = rows[i], lrow = lrows[i];
32606 var isAlt = ((i+1) % 2 == 0);
32607 var hasAlt = (' '+row.className + ' ').indexOf(cls) != -1;
32608 if(isAlt == hasAlt){
32612 row.className += " x-grid-row-alt";
32614 row.className = row.className.replace("x-grid-row-alt", "");
32617 lrow.className = row.className;
32622 restoreScroll : function(state){
32623 var sb = this.scroller.dom;
32624 sb.scrollLeft = state.left;
32625 sb.scrollTop = state.top;
32629 syncScroll : function(){
32630 var sb = this.scroller.dom;
32631 var sh = this.mainHd.dom;
32632 var bs = this.mainBody.dom;
32633 var lv = this.lockedBody.dom;
32634 sh.scrollLeft = bs.scrollLeft = sb.scrollLeft;
32635 lv.scrollTop = bs.scrollTop = sb.scrollTop;
32638 handleScroll : function(e){
32640 var sb = this.scroller.dom;
32641 this.grid.fireEvent("bodyscroll", sb.scrollLeft, sb.scrollTop);
32645 handleWheel : function(e){
32646 var d = e.getWheelDelta();
32647 this.scroller.dom.scrollTop -= d*22;
32648 // set this here to prevent jumpy scrolling on large tables
32649 this.lockedBody.dom.scrollTop = this.mainBody.dom.scrollTop = this.scroller.dom.scrollTop;
32653 renderRows : function(startRow, endRow){
32654 // pull in all the crap needed to render rows
32655 var g = this.grid, cm = g.colModel, ds = g.dataSource, stripe = g.stripeRows;
32656 var colCount = cm.getColumnCount();
32658 if(ds.getCount() < 1){
32662 // build a map for all the columns
32664 for(var i = 0; i < colCount; i++){
32665 var name = cm.getDataIndex(i);
32667 name : typeof name == 'undefined' ? ds.fields.get(i).name : name,
32668 renderer : cm.getRenderer(i),
32669 id : cm.getColumnId(i),
32670 locked : cm.isLocked(i)
32674 startRow = startRow || 0;
32675 endRow = typeof endRow == "undefined"? ds.getCount()-1 : endRow;
32677 // records to render
32678 var rs = ds.getRange(startRow, endRow);
32680 return this.doRender(cs, rs, ds, startRow, colCount, stripe);
32683 // As much as I hate to duplicate code, this was branched because FireFox really hates
32684 // [].join("") on strings. The performance difference was substantial enough to
32685 // branch this function
32686 doRender : Roo.isGecko ?
32687 function(cs, rs, ds, startRow, colCount, stripe){
32688 var ts = this.templates, ct = ts.cell, rt = ts.row;
32690 var buf = "", lbuf = "", cb, lcb, c, p = {}, rp = {}, r, rowIndex;
32691 for(var j = 0, len = rs.length; j < len; j++){
32692 r = rs[j]; cb = ""; lcb = ""; rowIndex = (j+startRow);
32693 for(var i = 0; i < colCount; i++){
32695 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
32697 p.css = p.attr = "";
32698 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
32699 if(p.value == undefined || p.value === "") p.value = " ";
32700 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
32701 p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
32703 var markup = ct.apply(p);
32711 if(stripe && ((rowIndex+1) % 2 == 0)){
32712 alt[0] = "x-grid-row-alt";
32715 alt[1] = " x-grid-dirty-row";
32718 if(this.getRowClass){
32719 alt[2] = this.getRowClass(r, rowIndex);
32721 rp.alt = alt.join(" ");
32722 lbuf+= rt.apply(rp);
32724 buf+= rt.apply(rp);
32726 return [lbuf, buf];
32728 function(cs, rs, ds, startRow, colCount, stripe){
32729 var ts = this.templates, ct = ts.cell, rt = ts.row;
32731 var buf = [], lbuf = [], cb, lcb, c, p = {}, rp = {}, r, rowIndex;
32732 for(var j = 0, len = rs.length; j < len; j++){
32733 r = rs[j]; cb = []; lcb = []; rowIndex = (j+startRow);
32734 for(var i = 0; i < colCount; i++){
32736 p.cellId = "x-grid-cell-" + rowIndex + "-" + i;
32738 p.css = p.attr = "";
32739 p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds);
32740 if(p.value == undefined || p.value === "") p.value = " ";
32741 if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
32742 p.css += p.css ? ' x-grid-dirty-cell' : 'x-grid-dirty-cell';
32744 var markup = ct.apply(p);
32746 cb[cb.length] = markup;
32748 lcb[lcb.length] = markup;
32752 if(stripe && ((rowIndex+1) % 2 == 0)){
32753 alt[0] = "x-grid-row-alt";
32756 alt[1] = " x-grid-dirty-row";
32759 if(this.getRowClass){
32760 alt[2] = this.getRowClass(r, rowIndex);
32762 rp.alt = alt.join(" ");
32763 rp.cells = lcb.join("");
32764 lbuf[lbuf.length] = rt.apply(rp);
32765 rp.cells = cb.join("");
32766 buf[buf.length] = rt.apply(rp);
32768 return [lbuf.join(""), buf.join("")];
32771 renderBody : function(){
32772 var markup = this.renderRows();
32773 var bt = this.templates.body;
32774 return [bt.apply({rows: markup[0]}), bt.apply({rows: markup[1]})];
32778 * Refreshes the grid
32779 * @param {Boolean} headersToo
32781 refresh : function(headersToo){
32782 this.fireEvent("beforerefresh", this);
32783 this.grid.stopEditing();
32784 var result = this.renderBody();
32785 this.lockedBody.update(result[0]);
32786 this.mainBody.update(result[1]);
32787 if(headersToo === true){
32788 this.updateHeaders();
32789 this.updateColumns();
32790 this.updateSplitters();
32791 this.updateHeaderSortState();
32793 this.syncRowHeights();
32795 this.fireEvent("refresh", this);
32798 handleColumnMove : function(cm, oldIndex, newIndex){
32799 this.indexMap = null;
32800 var s = this.getScrollState();
32801 this.refresh(true);
32802 this.restoreScroll(s);
32803 this.afterMove(newIndex);
32806 afterMove : function(colIndex){
32807 if(this.enableMoveAnim && Roo.enableFx){
32808 this.fly(this.getHeaderCell(colIndex).firstChild).highlight(this.hlColor);
32812 updateCell : function(dm, rowIndex, dataIndex){
32813 var colIndex = this.getColumnIndexByDataIndex(dataIndex);
32814 if(typeof colIndex == "undefined"){ // not present in grid
32817 var cm = this.grid.colModel;
32818 var cell = this.getCell(rowIndex, colIndex);
32819 var cellText = this.getCellText(rowIndex, colIndex);
32822 cellId : "x-grid-cell-" + rowIndex + "-" + colIndex,
32823 id : cm.getColumnId(colIndex),
32824 css: colIndex == cm.getColumnCount()-1 ? "x-grid-col-last" : ""
32826 var renderer = cm.getRenderer(colIndex);
32827 var val = renderer(dm.getValueAt(rowIndex, dataIndex), p, rowIndex, colIndex, dm);
32828 if(typeof val == "undefined" || val === "") val = " ";
32829 cellText.innerHTML = val;
32830 cell.className = this.cellClass + " " + this.idToCssName(p.cellId) + " " + p.css;
32831 this.syncRowHeights(rowIndex, rowIndex);
32834 calcColumnWidth : function(colIndex, maxRowsToMeasure){
32836 if(this.grid.autoSizeHeaders){
32837 var h = this.getHeaderCellMeasure(colIndex);
32838 maxWidth = Math.max(maxWidth, h.scrollWidth);
32841 if(this.cm.isLocked(colIndex)){
32842 tb = this.getLockedTable();
32845 tb = this.getBodyTable();
32846 index = colIndex - this.cm.getLockedCount();
32849 var rows = tb.rows;
32850 var stopIndex = Math.min(maxRowsToMeasure || rows.length, rows.length);
32851 for(var i = 0; i < stopIndex; i++){
32852 var cell = rows[i].childNodes[index].firstChild;
32853 maxWidth = Math.max(maxWidth, cell.scrollWidth);
32856 return maxWidth + /*margin for error in IE*/ 5;
32859 * Autofit a column to its content.
32860 * @param {Number} colIndex
32861 * @param {Boolean} forceMinSize true to force the column to go smaller if possible
32863 autoSizeColumn : function(colIndex, forceMinSize, suppressEvent){
32864 if(this.cm.isHidden(colIndex)){
32865 return; // can't calc a hidden column
32868 var cid = this.cm.getColumnId(colIndex);
32869 this.css.updateRule(this.colSelector +this.idToCssName( cid), "width", this.grid.minColumnWidth + "px");
32870 if(this.grid.autoSizeHeaders){
32871 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", this.grid.minColumnWidth + "px");
32874 var newWidth = this.calcColumnWidth(colIndex);
32875 this.cm.setColumnWidth(colIndex,
32876 Math.max(this.grid.minColumnWidth, newWidth), suppressEvent);
32877 if(!suppressEvent){
32878 this.grid.fireEvent("columnresize", colIndex, newWidth);
32883 * Autofits all columns to their content and then expands to fit any extra space in the grid
32885 autoSizeColumns : function(){
32886 var cm = this.grid.colModel;
32887 var colCount = cm.getColumnCount();
32888 for(var i = 0; i < colCount; i++){
32889 this.autoSizeColumn(i, true, true);
32891 if(cm.getTotalWidth() < this.scroller.dom.clientWidth){
32894 this.updateColumns();
32900 * Autofits all columns to the grid's width proportionate with their current size
32901 * @param {Boolean} reserveScrollSpace Reserve space for a scrollbar
32903 fitColumns : function(reserveScrollSpace){
32904 var cm = this.grid.colModel;
32905 var colCount = cm.getColumnCount();
32909 for (i = 0; i < colCount; i++){
32910 if(!cm.isHidden(i) && !cm.isFixed(i)){
32911 w = cm.getColumnWidth(i);
32917 var avail = Math.min(this.scroller.dom.clientWidth, this.el.getWidth());
32918 if(reserveScrollSpace){
32921 var frac = (avail - cm.getTotalWidth())/width;
32922 while (cols.length){
32925 cm.setColumnWidth(i, Math.floor(w + w*frac), true);
32927 this.updateColumns();
32931 onRowSelect : function(rowIndex){
32932 var row = this.getRowComposite(rowIndex);
32933 row.addClass("x-grid-row-selected");
32936 onRowDeselect : function(rowIndex){
32937 var row = this.getRowComposite(rowIndex);
32938 row.removeClass("x-grid-row-selected");
32941 onCellSelect : function(row, col){
32942 var cell = this.getCell(row, col);
32944 Roo.fly(cell).addClass("x-grid-cell-selected");
32948 onCellDeselect : function(row, col){
32949 var cell = this.getCell(row, col);
32951 Roo.fly(cell).removeClass("x-grid-cell-selected");
32955 updateHeaderSortState : function(){
32956 var state = this.ds.getSortState();
32960 this.sortState = state;
32961 var sortColumn = this.cm.findColumnIndex(state.field);
32962 if(sortColumn != -1){
32963 var sortDir = state.direction;
32964 var sc = this.sortClasses;
32965 var hds = this.el.select(this.headerSelector).removeClass(sc);
32966 hds.item(sortColumn).addClass(sc[sortDir == "DESC" ? 1 : 0]);
32970 handleHeaderClick : function(g, index){
32971 if(this.headersDisabled){
32974 var dm = g.dataSource, cm = g.colModel;
32975 if(!cm.isSortable(index)){
32979 dm.sort(cm.getDataIndex(index));
32983 destroy : function(){
32985 this.colMenu.removeAll();
32986 Roo.menu.MenuMgr.unregister(this.colMenu);
32987 this.colMenu.getEl().remove();
32988 delete this.colMenu;
32991 this.hmenu.removeAll();
32992 Roo.menu.MenuMgr.unregister(this.hmenu);
32993 this.hmenu.getEl().remove();
32996 if(this.grid.enableColumnMove){
32997 var dds = Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
32999 for(var dd in dds){
33000 if(!dds[dd].config.isTarget && dds[dd].dragElId){
33001 var elid = dds[dd].dragElId;
33003 Roo.get(elid).remove();
33004 } else if(dds[dd].config.isTarget){
33005 dds[dd].proxyTop.remove();
33006 dds[dd].proxyBottom.remove();
33009 if(Roo.dd.DDM.locationCache[dd]){
33010 delete Roo.dd.DDM.locationCache[dd];
33013 delete Roo.dd.DDM.ids['gridHeader' + this.grid.getGridEl().id];
33016 Roo.util.CSS.removeStyleSheet(this.idToCssName(this.grid.id) + '-cssrules');
33017 this.bind(null, null);
33018 Roo.EventManager.removeResizeListener(this.onWindowResize, this);
33021 handleLockChange : function(){
33022 this.refresh(true);
33025 onDenyColumnLock : function(){
33029 onDenyColumnHide : function(){
33033 handleHdMenuClick : function(item){
33034 var index = this.hdCtxIndex;
33035 var cm = this.cm, ds = this.ds;
33038 ds.sort(cm.getDataIndex(index), "ASC");
33041 ds.sort(cm.getDataIndex(index), "DESC");
33044 var lc = cm.getLockedCount();
33045 if(cm.getColumnCount(true) <= lc+1){
33046 this.onDenyColumnLock();
33050 cm.setLocked(index, true, true);
33051 cm.moveColumn(index, lc);
33052 this.grid.fireEvent("columnmove", index, lc);
33054 cm.setLocked(index, true);
33058 var lc = cm.getLockedCount();
33059 if((lc-1) != index){
33060 cm.setLocked(index, false, true);
33061 cm.moveColumn(index, lc-1);
33062 this.grid.fireEvent("columnmove", index, lc-1);
33064 cm.setLocked(index, false);
33068 index = cm.getIndexById(item.id.substr(4));
33070 if(item.checked && cm.getColumnCount(true) <= 1){
33071 this.onDenyColumnHide();
33074 cm.setHidden(index, item.checked);
33080 beforeColMenuShow : function(){
33081 var cm = this.cm, colCount = cm.getColumnCount();
33082 this.colMenu.removeAll();
33083 for(var i = 0; i < colCount; i++){
33084 this.colMenu.add(new Roo.menu.CheckItem({
33085 id: "col-"+cm.getColumnId(i),
33086 text: cm.getColumnHeader(i),
33087 checked: !cm.isHidden(i),
33093 handleHdCtx : function(g, index, e){
33095 var hd = this.getHeaderCell(index);
33096 this.hdCtxIndex = index;
33097 var ms = this.hmenu.items, cm = this.cm;
33098 ms.get("asc").setDisabled(!cm.isSortable(index));
33099 ms.get("desc").setDisabled(!cm.isSortable(index));
33100 if(this.grid.enableColLock !== false){
33101 ms.get("lock").setDisabled(cm.isLocked(index));
33102 ms.get("unlock").setDisabled(!cm.isLocked(index));
33104 this.hmenu.show(hd, "tl-bl");
33107 handleHdOver : function(e){
33108 var hd = this.findHeaderCell(e.getTarget());
33109 if(hd && !this.headersDisabled){
33110 if(this.grid.colModel.isSortable(this.getCellIndex(hd))){
33111 this.fly(hd).addClass("x-grid-hd-over");
33116 handleHdOut : function(e){
33117 var hd = this.findHeaderCell(e.getTarget());
33119 this.fly(hd).removeClass("x-grid-hd-over");
33123 handleSplitDblClick : function(e, t){
33124 var i = this.getCellIndex(t);
33125 if(this.grid.enableColumnResize !== false && this.cm.isResizable(i) && !this.cm.isFixed(i)){
33126 this.autoSizeColumn(i, true);
33131 render : function(){
33134 var colCount = cm.getColumnCount();
33136 if(this.grid.monitorWindowResize === true){
33137 Roo.EventManager.onWindowResize(this.onWindowResize, this, true);
33139 var header = this.renderHeaders();
33140 var body = this.templates.body.apply({rows:""});
33141 var html = this.templates.master.apply({
33144 lockedHeader: header[0],
33148 //this.updateColumns();
33150 this.grid.getGridEl().dom.innerHTML = html;
33152 this.initElements();
33154 this.scroller.on("scroll", this.handleScroll, this);
33155 this.lockedBody.on("mousewheel", this.handleWheel, this);
33156 this.mainBody.on("mousewheel", this.handleWheel, this);
33158 this.mainHd.on("mouseover", this.handleHdOver, this);
33159 this.mainHd.on("mouseout", this.handleHdOut, this);
33160 this.mainHd.on("dblclick", this.handleSplitDblClick, this,
33161 {delegate: "."+this.splitClass});
33163 this.lockedHd.on("mouseover", this.handleHdOver, this);
33164 this.lockedHd.on("mouseout", this.handleHdOut, this);
33165 this.lockedHd.on("dblclick", this.handleSplitDblClick, this,
33166 {delegate: "."+this.splitClass});
33168 if(this.grid.enableColumnResize !== false && Roo.grid.SplitDragZone){
33169 new Roo.grid.SplitDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
33172 this.updateSplitters();
33174 if(this.grid.enableColumnMove && Roo.grid.HeaderDragZone){
33175 new Roo.grid.HeaderDragZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
33176 new Roo.grid.HeaderDropZone(this.grid, this.lockedHd.dom, this.mainHd.dom);
33179 if(this.grid.enableCtxMenu !== false && Roo.menu.Menu){
33180 this.hmenu = new Roo.menu.Menu({id: this.grid.id + "-hctx"});
33182 {id:"asc", text: this.sortAscText, cls: "xg-hmenu-sort-asc"},
33183 {id:"desc", text: this.sortDescText, cls: "xg-hmenu-sort-desc"}
33185 if(this.grid.enableColLock !== false){
33186 this.hmenu.add('-',
33187 {id:"lock", text: this.lockText, cls: "xg-hmenu-lock"},
33188 {id:"unlock", text: this.unlockText, cls: "xg-hmenu-unlock"}
33191 if(this.grid.enableColumnHide !== false){
33193 this.colMenu = new Roo.menu.Menu({id:this.grid.id + "-hcols-menu"});
33194 this.colMenu.on("beforeshow", this.beforeColMenuShow, this);
33195 this.colMenu.on("itemclick", this.handleHdMenuClick, this);
33197 this.hmenu.add('-',
33198 {id:"columns", text: this.columnsText, menu: this.colMenu}
33201 this.hmenu.on("itemclick", this.handleHdMenuClick, this);
33203 this.grid.on("headercontextmenu", this.handleHdCtx, this);
33206 if((this.grid.enableDragDrop || this.grid.enableDrag) && Roo.grid.GridDragZone){
33207 this.dd = new Roo.grid.GridDragZone(this.grid, {
33208 ddGroup : this.grid.ddGroup || 'GridDD'
33213 for(var i = 0; i < colCount; i++){
33214 if(cm.isHidden(i)){
33215 this.hideColumn(i);
33217 if(cm.config[i].align){
33218 this.css.updateRule(this.colSelector + i, "textAlign", cm.config[i].align);
33219 this.css.updateRule(this.hdSelector + i, "textAlign", cm.config[i].align);
33223 this.updateHeaderSortState();
33225 this.beforeInitialResize();
33228 // two part rendering gives faster view to the user
33229 this.renderPhase2.defer(1, this);
33232 renderPhase2 : function(){
33233 // render the rows now
33235 if(this.grid.autoSizeColumns){
33236 this.autoSizeColumns();
33240 beforeInitialResize : function(){
33244 onColumnSplitterMoved : function(i, w){
33245 this.userResized = true;
33246 var cm = this.grid.colModel;
33247 cm.setColumnWidth(i, w, true);
33248 var cid = cm.getColumnId(i);
33249 this.css.updateRule(this.colSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
33250 this.css.updateRule(this.hdSelector + this.idToCssName(cid), "width", (w-this.borderWidth) + "px");
33251 this.updateSplitters();
33253 this.grid.fireEvent("columnresize", i, w);
33256 syncRowHeights : function(startIndex, endIndex){
33257 if(this.grid.enableRowHeightSync === true && this.cm.getLockedCount() > 0){
33258 startIndex = startIndex || 0;
33259 var mrows = this.getBodyTable().rows;
33260 var lrows = this.getLockedTable().rows;
33261 var len = mrows.length-1;
33262 endIndex = Math.min(endIndex || len, len);
33263 for(var i = startIndex; i <= endIndex; i++){
33264 var m = mrows[i], l = lrows[i];
33265 var h = Math.max(m.offsetHeight, l.offsetHeight);
33266 m.style.height = l.style.height = h + "px";
33271 layout : function(initialRender, is2ndPass){
33273 var auto = g.autoHeight;
33274 var scrollOffset = 16;
33275 var c = g.getGridEl(), cm = this.cm,
33276 expandCol = g.autoExpandColumn,
33278 //c.beginMeasure();
33280 if(!c.dom.offsetWidth){ // display:none?
33282 this.lockedWrap.show();
33283 this.mainWrap.show();
33288 var hasLock = this.cm.isLocked(0);
33290 var tbh = this.headerPanel.getHeight();
33291 var bbh = this.footerPanel.getHeight();
33294 var ch = this.getBodyTable().offsetHeight + tbh + bbh + this.mainHd.getHeight();
33295 var newHeight = ch + c.getBorderWidth("tb");
33297 newHeight = Math.min(g.maxHeight, newHeight);
33299 c.setHeight(newHeight);
33303 c.setWidth(cm.getTotalWidth()+c.getBorderWidth('lr'));
33306 var s = this.scroller;
33308 var csize = c.getSize(true);
33310 this.el.setSize(csize.width, csize.height);
33312 this.headerPanel.setWidth(csize.width);
33313 this.footerPanel.setWidth(csize.width);
33315 var hdHeight = this.mainHd.getHeight();
33316 var vw = csize.width;
33317 var vh = csize.height - (tbh + bbh);
33321 var bt = this.getBodyTable();
33322 var ltWidth = hasLock ?
33323 Math.max(this.getLockedTable().offsetWidth, this.lockedHd.dom.firstChild.offsetWidth) : 0;
33325 var scrollHeight = bt.offsetHeight;
33326 var scrollWidth = ltWidth + bt.offsetWidth;
33327 var vscroll = false, hscroll = false;
33329 this.scrollSizer.setSize(scrollWidth, scrollHeight+hdHeight);
33331 var lw = this.lockedWrap, mw = this.mainWrap;
33332 var lb = this.lockedBody, mb = this.mainBody;
33334 setTimeout(function(){
33335 var t = s.dom.offsetTop;
33336 var w = s.dom.clientWidth,
33337 h = s.dom.clientHeight;
33340 lw.setSize(ltWidth, h);
33342 mw.setLeftTop(ltWidth, t);
33343 mw.setSize(w-ltWidth, h);
33345 lb.setHeight(h-hdHeight);
33346 mb.setHeight(h-hdHeight);
33348 if(is2ndPass !== true && !gv.userResized && expandCol){
33349 // high speed resize without full column calculation
33351 var ci = cm.getIndexById(expandCol);
33353 ci = cm.findColumnIndex(expandCol);
33355 ci = Math.max(0, ci); // make sure it's got at least the first col.
33356 var expandId = cm.getColumnId(ci);
33357 var tw = cm.getTotalWidth(false);
33358 var currentWidth = cm.getColumnWidth(ci);
33359 var cw = Math.min(Math.max(((w-tw)+currentWidth-2)-/*scrollbar*/(w <= s.dom.offsetWidth ? 0 : 18), g.autoExpandMin), g.autoExpandMax);
33360 if(currentWidth != cw){
33361 cm.setColumnWidth(ci, cw, true);
33362 gv.css.updateRule(gv.colSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
33363 gv.css.updateRule(gv.hdSelector+gv.idToCssName(expandId), "width", (cw - gv.borderWidth) + "px");
33364 gv.updateSplitters();
33365 gv.layout(false, true);
33377 onWindowResize : function(){
33378 if(!this.grid.monitorWindowResize || this.grid.autoHeight){
33384 appendFooter : function(parentEl){
33388 sortAscText : "Sort Ascending",
33389 sortDescText : "Sort Descending",
33390 lockText : "Lock Column",
33391 unlockText : "Unlock Column",
33392 columnsText : "Columns"
33396 Roo.grid.GridView.ColumnDragZone = function(grid, hd){
33397 Roo.grid.GridView.ColumnDragZone.superclass.constructor.call(this, grid, hd, null);
33398 this.proxy.el.addClass('x-grid3-col-dd');
33401 Roo.extend(Roo.grid.GridView.ColumnDragZone, Roo.grid.HeaderDragZone, {
33402 handleMouseDown : function(e){
33406 callHandleMouseDown : function(e){
33407 Roo.grid.GridView.ColumnDragZone.superclass.handleMouseDown.call(this, e);
33412 * Ext JS Library 1.1.1
33413 * Copyright(c) 2006-2007, Ext JS, LLC.
33415 * Originally Released Under LGPL - original licence link has changed is not relivant.
33418 * <script type="text/javascript">
33422 // This is a support class used internally by the Grid components
33423 Roo.grid.SplitDragZone = function(grid, hd, hd2){
33425 this.view = grid.getView();
33426 this.proxy = this.view.resizeProxy;
33427 Roo.grid.SplitDragZone.superclass.constructor.call(this, hd,
33428 "gridSplitters" + this.grid.getGridEl().id, {
33429 dragElId : Roo.id(this.proxy.dom), resizeFrame:false
33431 this.setHandleElId(Roo.id(hd));
33432 this.setOuterHandleElId(Roo.id(hd2));
33433 this.scroll = false;
33435 Roo.extend(Roo.grid.SplitDragZone, Roo.dd.DDProxy, {
33436 fly: Roo.Element.fly,
33438 b4StartDrag : function(x, y){
33439 this.view.headersDisabled = true;
33440 this.proxy.setHeight(this.view.mainWrap.getHeight());
33441 var w = this.cm.getColumnWidth(this.cellIndex);
33442 var minw = Math.max(w-this.grid.minColumnWidth, 0);
33443 this.resetConstraints();
33444 this.setXConstraint(minw, 1000);
33445 this.setYConstraint(0, 0);
33446 this.minX = x - minw;
33447 this.maxX = x + 1000;
33449 Roo.dd.DDProxy.prototype.b4StartDrag.call(this, x, y);
33453 handleMouseDown : function(e){
33454 ev = Roo.EventObject.setEvent(e);
33455 var t = this.fly(ev.getTarget());
33456 if(t.hasClass("x-grid-split")){
33457 this.cellIndex = this.view.getCellIndex(t.dom);
33458 this.split = t.dom;
33459 this.cm = this.grid.colModel;
33460 if(this.cm.isResizable(this.cellIndex) && !this.cm.isFixed(this.cellIndex)){
33461 Roo.grid.SplitDragZone.superclass.handleMouseDown.apply(this, arguments);
33466 endDrag : function(e){
33467 this.view.headersDisabled = false;
33468 var endX = Math.max(this.minX, Roo.lib.Event.getPageX(e));
33469 var diff = endX - this.startPos;
33470 this.view.onColumnSplitterMoved(this.cellIndex, this.cm.getColumnWidth(this.cellIndex)+diff);
33473 autoOffset : function(){
33474 this.setDelta(0,0);
33478 * Ext JS Library 1.1.1
33479 * Copyright(c) 2006-2007, Ext JS, LLC.
33481 * Originally Released Under LGPL - original licence link has changed is not relivant.
33484 * <script type="text/javascript">
33488 // This is a support class used internally by the Grid components
33489 Roo.grid.GridDragZone = function(grid, config){
33490 this.view = grid.getView();
33491 Roo.grid.GridDragZone.superclass.constructor.call(this, this.view.mainBody.dom, config);
33492 if(this.view.lockedBody){
33493 this.setHandleElId(Roo.id(this.view.mainBody.dom));
33494 this.setOuterHandleElId(Roo.id(this.view.lockedBody.dom));
33496 this.scroll = false;
33498 this.ddel = document.createElement('div');
33499 this.ddel.className = 'x-grid-dd-wrap';
33502 Roo.extend(Roo.grid.GridDragZone, Roo.dd.DragZone, {
33503 ddGroup : "GridDD",
33505 getDragData : function(e){
33506 var t = Roo.lib.Event.getTarget(e);
33507 var rowIndex = this.view.findRowIndex(t);
33508 if(rowIndex !== false){
33509 var sm = this.grid.selModel;
33510 //if(!sm.isSelected(rowIndex) || e.hasModifier()){
33511 // sm.mouseDown(e, t);
33513 if (e.hasModifier()){
33514 sm.handleMouseDown(e, t); // non modifier buttons are handled by row select.
33516 return {grid: this.grid, ddel: this.ddel, rowIndex: rowIndex, selections:sm.getSelections()};
33521 onInitDrag : function(e){
33522 var data = this.dragData;
33523 this.ddel.innerHTML = this.grid.getDragDropText();
33524 this.proxy.update(this.ddel);
33525 // fire start drag?
33528 afterRepair : function(){
33529 this.dragging = false;
33532 getRepairXY : function(e, data){
33536 onEndDrag : function(data, e){
33540 onValidDrop : function(dd, e, id){
33545 beforeInvalidDrop : function(e, id){
33550 * Ext JS Library 1.1.1
33551 * Copyright(c) 2006-2007, Ext JS, LLC.
33553 * Originally Released Under LGPL - original licence link has changed is not relivant.
33556 * <script type="text/javascript">
33561 * @class Roo.grid.ColumnModel
33562 * @extends Roo.util.Observable
33563 * This is the default implementation of a ColumnModel used by the Grid. It defines
33564 * the columns in the grid.
33567 var colModel = new Roo.grid.ColumnModel([
33568 {header: "Ticker", width: 60, sortable: true, locked: true},
33569 {header: "Company Name", width: 150, sortable: true},
33570 {header: "Market Cap.", width: 100, sortable: true},
33571 {header: "$ Sales", width: 100, sortable: true, renderer: money},
33572 {header: "Employees", width: 100, sortable: true, resizable: false}
33577 * The config options listed for this class are options which may appear in each
33578 * individual column definition.
33579 * <br/>RooJS Fix - column id's are not sequential but use Roo.id() - fixes bugs with layouts.
33581 * @param {Object} config An Array of column config objects. See this class's
33582 * config objects for details.
33584 Roo.grid.ColumnModel = function(config){
33586 * The config passed into the constructor
33588 this.config = config;
33591 // if no id, create one
33592 // if the column does not have a dataIndex mapping,
33593 // map it to the order it is in the config
33594 for(var i = 0, len = config.length; i < len; i++){
33596 if(typeof c.dataIndex == "undefined"){
33599 if(typeof c.renderer == "string"){
33600 c.renderer = Roo.util.Format[c.renderer];
33602 if(typeof c.id == "undefined"){
33605 if(c.editor && c.editor.xtype){
33606 c.editor = Roo.factory(c.editor, Roo.grid);
33608 if(c.editor && c.editor.isFormField){
33609 c.editor = new Roo.grid.GridEditor(c.editor);
33611 this.lookup[c.id] = c;
33615 * The width of columns which have no width specified (defaults to 100)
33618 this.defaultWidth = 100;
33621 * Default sortable of columns which have no sortable specified (defaults to false)
33624 this.defaultSortable = false;
33628 * @event widthchange
33629 * Fires when the width of a column changes.
33630 * @param {ColumnModel} this
33631 * @param {Number} columnIndex The column index
33632 * @param {Number} newWidth The new width
33634 "widthchange": true,
33636 * @event headerchange
33637 * Fires when the text of a header changes.
33638 * @param {ColumnModel} this
33639 * @param {Number} columnIndex The column index
33640 * @param {Number} newText The new header text
33642 "headerchange": true,
33644 * @event hiddenchange
33645 * Fires when a column is hidden or "unhidden".
33646 * @param {ColumnModel} this
33647 * @param {Number} columnIndex The column index
33648 * @param {Boolean} hidden true if hidden, false otherwise
33650 "hiddenchange": true,
33652 * @event columnmoved
33653 * Fires when a column is moved.
33654 * @param {ColumnModel} this
33655 * @param {Number} oldIndex
33656 * @param {Number} newIndex
33658 "columnmoved" : true,
33660 * @event columlockchange
33661 * Fires when a column's locked state is changed
33662 * @param {ColumnModel} this
33663 * @param {Number} colIndex
33664 * @param {Boolean} locked true if locked
33666 "columnlockchange" : true
33668 Roo.grid.ColumnModel.superclass.constructor.call(this);
33670 Roo.extend(Roo.grid.ColumnModel, Roo.util.Observable, {
33672 * @cfg {String} header The header text to display in the Grid view.
33675 * @cfg {String} dataIndex (Optional) The name of the field in the grid's {@link Roo.data.Store}'s
33676 * {@link Roo.data.Record} definition from which to draw the column's value. If not
33677 * specified, the column's index is used as an index into the Record's data Array.
33680 * @cfg {Number} width (Optional) The initial width in pixels of the column. Using this
33681 * instead of {@link Roo.grid.Grid#autoSizeColumns} is more efficient.
33684 * @cfg {Boolean} sortable (Optional) True if sorting is to be allowed on this column.
33685 * Defaults to the value of the {@link #defaultSortable} property.
33686 * Whether local/remote sorting is used is specified in {@link Roo.data.Store#remoteSort}.
33689 * @cfg {Boolean} locked (Optional) True to lock the column in place while scrolling the Grid. Defaults to false.
33692 * @cfg {Boolean} fixed (Optional) True if the column width cannot be changed. Defaults to false.
33695 * @cfg {Boolean} resizable (Optional) False to disable column resizing. Defaults to true.
33698 * @cfg {Boolean} hidden (Optional) True to hide the column. Defaults to false.
33701 * @cfg {Function} renderer (Optional) A function used to generate HTML markup for a cell
33702 * given the cell's data value. See {@link #setRenderer}. If not specified, the
33703 * default renderer uses the raw data value.
33706 * @cfg {Roo.grid.GridEditor} editor (Optional) For grid editors - returns the grid editor
33709 * @cfg {String} align (Optional) Set the CSS text-align property of the column. Defaults to undefined.
33713 * Returns the id of the column at the specified index.
33714 * @param {Number} index The column index
33715 * @return {String} the id
33717 getColumnId : function(index){
33718 return this.config[index].id;
33722 * Returns the column for a specified id.
33723 * @param {String} id The column id
33724 * @return {Object} the column
33726 getColumnById : function(id){
33727 return this.lookup[id];
33731 * Returns the index for a specified column id.
33732 * @param {String} id The column id
33733 * @return {Number} the index, or -1 if not found
33735 getIndexById : function(id){
33736 for(var i = 0, len = this.config.length; i < len; i++){
33737 if(this.config[i].id == id){
33744 * Returns the index for a specified column dataIndex.
33745 * @param {String} dataIndex The column dataIndex
33746 * @return {Number} the index, or -1 if not found
33749 findColumnIndex : function(dataIndex){
33750 for(var i = 0, len = this.config.length; i < len; i++){
33751 if(this.config[i].dataIndex == dataIndex){
33759 moveColumn : function(oldIndex, newIndex){
33760 var c = this.config[oldIndex];
33761 this.config.splice(oldIndex, 1);
33762 this.config.splice(newIndex, 0, c);
33763 this.dataMap = null;
33764 this.fireEvent("columnmoved", this, oldIndex, newIndex);
33767 isLocked : function(colIndex){
33768 return this.config[colIndex].locked === true;
33771 setLocked : function(colIndex, value, suppressEvent){
33772 if(this.isLocked(colIndex) == value){
33775 this.config[colIndex].locked = value;
33776 if(!suppressEvent){
33777 this.fireEvent("columnlockchange", this, colIndex, value);
33781 getTotalLockedWidth : function(){
33782 var totalWidth = 0;
33783 for(var i = 0; i < this.config.length; i++){
33784 if(this.isLocked(i) && !this.isHidden(i)){
33785 this.totalWidth += this.getColumnWidth(i);
33791 getLockedCount : function(){
33792 for(var i = 0, len = this.config.length; i < len; i++){
33793 if(!this.isLocked(i)){
33800 * Returns the number of columns.
33803 getColumnCount : function(visibleOnly){
33804 if(visibleOnly === true){
33806 for(var i = 0, len = this.config.length; i < len; i++){
33807 if(!this.isHidden(i)){
33813 return this.config.length;
33817 * Returns the column configs that return true by the passed function that is called with (columnConfig, index)
33818 * @param {Function} fn
33819 * @param {Object} scope (optional)
33820 * @return {Array} result
33822 getColumnsBy : function(fn, scope){
33824 for(var i = 0, len = this.config.length; i < len; i++){
33825 var c = this.config[i];
33826 if(fn.call(scope||this, c, i) === true){
33834 * Returns true if the specified column is sortable.
33835 * @param {Number} col The column index
33836 * @return {Boolean}
33838 isSortable : function(col){
33839 if(typeof this.config[col].sortable == "undefined"){
33840 return this.defaultSortable;
33842 return this.config[col].sortable;
33846 * Returns the rendering (formatting) function defined for the column.
33847 * @param {Number} col The column index.
33848 * @return {Function} The function used to render the cell. See {@link #setRenderer}.
33850 getRenderer : function(col){
33851 if(!this.config[col].renderer){
33852 return Roo.grid.ColumnModel.defaultRenderer;
33854 return this.config[col].renderer;
33858 * Sets the rendering (formatting) function for a column.
33859 * @param {Number} col The column index
33860 * @param {Function} fn The function to use to process the cell's raw data
33861 * to return HTML markup for the grid view. The render function is called with
33862 * the following parameters:<ul>
33863 * <li>Data value.</li>
33864 * <li>Cell metadata. An object in which you may set the following attributes:<ul>
33865 * <li>css A CSS style string to apply to the table cell.</li>
33866 * <li>attr An HTML attribute definition string to apply to the data container element <i>within</i> the table cell.</li></ul>
33867 * <li>The {@link Roo.data.Record} from which the data was extracted.</li>
33868 * <li>Row index</li>
33869 * <li>Column index</li>
33870 * <li>The {@link Roo.data.Store} object from which the Record was extracted</li></ul>
33872 setRenderer : function(col, fn){
33873 this.config[col].renderer = fn;
33877 * Returns the width for the specified column.
33878 * @param {Number} col The column index
33881 getColumnWidth : function(col){
33882 return this.config[col].width || this.defaultWidth;
33886 * Sets the width for a column.
33887 * @param {Number} col The column index
33888 * @param {Number} width The new width
33890 setColumnWidth : function(col, width, suppressEvent){
33891 this.config[col].width = width;
33892 this.totalWidth = null;
33893 if(!suppressEvent){
33894 this.fireEvent("widthchange", this, col, width);
33899 * Returns the total width of all columns.
33900 * @param {Boolean} includeHidden True to include hidden column widths
33903 getTotalWidth : function(includeHidden){
33904 if(!this.totalWidth){
33905 this.totalWidth = 0;
33906 for(var i = 0, len = this.config.length; i < len; i++){
33907 if(includeHidden || !this.isHidden(i)){
33908 this.totalWidth += this.getColumnWidth(i);
33912 return this.totalWidth;
33916 * Returns the header for the specified column.
33917 * @param {Number} col The column index
33920 getColumnHeader : function(col){
33921 return this.config[col].header;
33925 * Sets the header for a column.
33926 * @param {Number} col The column index
33927 * @param {String} header The new header
33929 setColumnHeader : function(col, header){
33930 this.config[col].header = header;
33931 this.fireEvent("headerchange", this, col, header);
33935 * Returns the tooltip for the specified column.
33936 * @param {Number} col The column index
33939 getColumnTooltip : function(col){
33940 return this.config[col].tooltip;
33943 * Sets the tooltip for a column.
33944 * @param {Number} col The column index
33945 * @param {String} tooltip The new tooltip
33947 setColumnTooltip : function(col, tooltip){
33948 this.config[col].tooltip = tooltip;
33952 * Returns the dataIndex for the specified column.
33953 * @param {Number} col The column index
33956 getDataIndex : function(col){
33957 return this.config[col].dataIndex;
33961 * Sets the dataIndex for a column.
33962 * @param {Number} col The column index
33963 * @param {Number} dataIndex The new dataIndex
33965 setDataIndex : function(col, dataIndex){
33966 this.config[col].dataIndex = dataIndex;
33972 * Returns true if the cell is editable.
33973 * @param {Number} colIndex The column index
33974 * @param {Number} rowIndex The row index
33975 * @return {Boolean}
33977 isCellEditable : function(colIndex, rowIndex){
33978 return (this.config[colIndex].editable || (typeof this.config[colIndex].editable == "undefined" && this.config[colIndex].editor)) ? true : false;
33982 * Returns the editor defined for the cell/column.
33983 * return false or null to disable editing.
33984 * @param {Number} colIndex The column index
33985 * @param {Number} rowIndex The row index
33988 getCellEditor : function(colIndex, rowIndex){
33989 return this.config[colIndex].editor;
33993 * Sets if a column is editable.
33994 * @param {Number} col The column index
33995 * @param {Boolean} editable True if the column is editable
33997 setEditable : function(col, editable){
33998 this.config[col].editable = editable;
34003 * Returns true if the column is hidden.
34004 * @param {Number} colIndex The column index
34005 * @return {Boolean}
34007 isHidden : function(colIndex){
34008 return this.config[colIndex].hidden;
34013 * Returns true if the column width cannot be changed
34015 isFixed : function(colIndex){
34016 return this.config[colIndex].fixed;
34020 * Returns true if the column can be resized
34021 * @return {Boolean}
34023 isResizable : function(colIndex){
34024 return colIndex >= 0 && this.config[colIndex].resizable !== false && this.config[colIndex].fixed !== true;
34027 * Sets if a column is hidden.
34028 * @param {Number} colIndex The column index
34029 * @param {Boolean} hidden True if the column is hidden
34031 setHidden : function(colIndex, hidden){
34032 this.config[colIndex].hidden = hidden;
34033 this.totalWidth = null;
34034 this.fireEvent("hiddenchange", this, colIndex, hidden);
34038 * Sets the editor for a column.
34039 * @param {Number} col The column index
34040 * @param {Object} editor The editor object
34042 setEditor : function(col, editor){
34043 this.config[col].editor = editor;
34047 Roo.grid.ColumnModel.defaultRenderer = function(value){
34048 if(typeof value == "string" && value.length < 1){
34054 // Alias for backwards compatibility
34055 Roo.grid.DefaultColumnModel = Roo.grid.ColumnModel;
34058 * Ext JS Library 1.1.1
34059 * Copyright(c) 2006-2007, Ext JS, LLC.
34061 * Originally Released Under LGPL - original licence link has changed is not relivant.
34064 * <script type="text/javascript">
34068 * @class Roo.grid.AbstractSelectionModel
34069 * @extends Roo.util.Observable
34070 * Abstract base class for grid SelectionModels. It provides the interface that should be
34071 * implemented by descendant classes. This class should not be directly instantiated.
34074 Roo.grid.AbstractSelectionModel = function(){
34075 this.locked = false;
34076 Roo.grid.AbstractSelectionModel.superclass.constructor.call(this);
34079 Roo.extend(Roo.grid.AbstractSelectionModel, Roo.util.Observable, {
34080 /** @ignore Called by the grid automatically. Do not call directly. */
34081 init : function(grid){
34087 * Locks the selections.
34090 this.locked = true;
34094 * Unlocks the selections.
34096 unlock : function(){
34097 this.locked = false;
34101 * Returns true if the selections are locked.
34102 * @return {Boolean}
34104 isLocked : function(){
34105 return this.locked;
34109 * Ext JS Library 1.1.1
34110 * Copyright(c) 2006-2007, Ext JS, LLC.
34112 * Originally Released Under LGPL - original licence link has changed is not relivant.
34115 * <script type="text/javascript">
34118 * @extends Roo.grid.AbstractSelectionModel
34119 * @class Roo.grid.RowSelectionModel
34120 * The default SelectionModel used by {@link Roo.grid.Grid}.
34121 * It supports multiple selections and keyboard selection/navigation.
34123 * @param {Object} config
34125 Roo.grid.RowSelectionModel = function(config){
34126 Roo.apply(this, config);
34127 this.selections = new Roo.util.MixedCollection(false, function(o){
34132 this.lastActive = false;
34136 * @event selectionchange
34137 * Fires when the selection changes
34138 * @param {SelectionModel} this
34140 "selectionchange" : true,
34142 * @event afterselectionchange
34143 * Fires after the selection changes (eg. by key press or clicking)
34144 * @param {SelectionModel} this
34146 "afterselectionchange" : true,
34148 * @event beforerowselect
34149 * Fires when a row is selected being selected, return false to cancel.
34150 * @param {SelectionModel} this
34151 * @param {Number} rowIndex The selected index
34152 * @param {Boolean} keepExisting False if other selections will be cleared
34154 "beforerowselect" : true,
34157 * Fires when a row is selected.
34158 * @param {SelectionModel} this
34159 * @param {Number} rowIndex The selected index
34160 * @param {Roo.data.Record} r The record
34162 "rowselect" : true,
34164 * @event rowdeselect
34165 * Fires when a row is deselected.
34166 * @param {SelectionModel} this
34167 * @param {Number} rowIndex The selected index
34169 "rowdeselect" : true
34171 Roo.grid.RowSelectionModel.superclass.constructor.call(this);
34172 this.locked = false;
34175 Roo.extend(Roo.grid.RowSelectionModel, Roo.grid.AbstractSelectionModel, {
34177 * @cfg {Boolean} singleSelect
34178 * True to allow selection of only one row at a time (defaults to false)
34180 singleSelect : false,
34183 initEvents : function(){
34185 if(!this.grid.enableDragDrop && !this.grid.enableDrag){
34186 this.grid.on("mousedown", this.handleMouseDown, this);
34187 }else{ // allow click to work like normal
34188 this.grid.on("rowclick", this.handleDragableRowClick, this);
34191 this.rowNav = new Roo.KeyNav(this.grid.getGridEl(), {
34192 "up" : function(e){
34194 this.selectPrevious(e.shiftKey);
34195 }else if(this.last !== false && this.lastActive !== false){
34196 var last = this.last;
34197 this.selectRange(this.last, this.lastActive-1);
34198 this.grid.getView().focusRow(this.lastActive);
34199 if(last !== false){
34203 this.selectFirstRow();
34205 this.fireEvent("afterselectionchange", this);
34207 "down" : function(e){
34209 this.selectNext(e.shiftKey);
34210 }else if(this.last !== false && this.lastActive !== false){
34211 var last = this.last;
34212 this.selectRange(this.last, this.lastActive+1);
34213 this.grid.getView().focusRow(this.lastActive);
34214 if(last !== false){
34218 this.selectFirstRow();
34220 this.fireEvent("afterselectionchange", this);
34225 var view = this.grid.view;
34226 view.on("refresh", this.onRefresh, this);
34227 view.on("rowupdated", this.onRowUpdated, this);
34228 view.on("rowremoved", this.onRemove, this);
34232 onRefresh : function(){
34233 var ds = this.grid.dataSource, i, v = this.grid.view;
34234 var s = this.selections;
34235 s.each(function(r){
34236 if((i = ds.indexOfId(r.id)) != -1){
34245 onRemove : function(v, index, r){
34246 this.selections.remove(r);
34250 onRowUpdated : function(v, index, r){
34251 if(this.isSelected(r)){
34252 v.onRowSelect(index);
34258 * @param {Array} records The records to select
34259 * @param {Boolean} keepExisting (optional) True to keep existing selections
34261 selectRecords : function(records, keepExisting){
34263 this.clearSelections();
34265 var ds = this.grid.dataSource;
34266 for(var i = 0, len = records.length; i < len; i++){
34267 this.selectRow(ds.indexOf(records[i]), true);
34272 * Gets the number of selected rows.
34275 getCount : function(){
34276 return this.selections.length;
34280 * Selects the first row in the grid.
34282 selectFirstRow : function(){
34287 * Select the last row.
34288 * @param {Boolean} keepExisting (optional) True to keep existing selections
34290 selectLastRow : function(keepExisting){
34291 this.selectRow(this.grid.dataSource.getCount() - 1, keepExisting);
34295 * Selects the row immediately following the last selected row.
34296 * @param {Boolean} keepExisting (optional) True to keep existing selections
34298 selectNext : function(keepExisting){
34299 if(this.last !== false && (this.last+1) < this.grid.dataSource.getCount()){
34300 this.selectRow(this.last+1, keepExisting);
34301 this.grid.getView().focusRow(this.last);
34306 * Selects the row that precedes the last selected row.
34307 * @param {Boolean} keepExisting (optional) True to keep existing selections
34309 selectPrevious : function(keepExisting){
34311 this.selectRow(this.last-1, keepExisting);
34312 this.grid.getView().focusRow(this.last);
34317 * Returns the selected records
34318 * @return {Array} Array of selected records
34320 getSelections : function(){
34321 return [].concat(this.selections.items);
34325 * Returns the first selected record.
34328 getSelected : function(){
34329 return this.selections.itemAt(0);
34334 * Clears all selections.
34336 clearSelections : function(fast){
34337 if(this.locked) return;
34339 var ds = this.grid.dataSource;
34340 var s = this.selections;
34341 s.each(function(r){
34342 this.deselectRow(ds.indexOfId(r.id));
34346 this.selections.clear();
34353 * Selects all rows.
34355 selectAll : function(){
34356 if(this.locked) return;
34357 this.selections.clear();
34358 for(var i = 0, len = this.grid.dataSource.getCount(); i < len; i++){
34359 this.selectRow(i, true);
34364 * Returns True if there is a selection.
34365 * @return {Boolean}
34367 hasSelection : function(){
34368 return this.selections.length > 0;
34372 * Returns True if the specified row is selected.
34373 * @param {Number/Record} record The record or index of the record to check
34374 * @return {Boolean}
34376 isSelected : function(index){
34377 var r = typeof index == "number" ? this.grid.dataSource.getAt(index) : index;
34378 return (r && this.selections.key(r.id) ? true : false);
34382 * Returns True if the specified record id is selected.
34383 * @param {String} id The id of record to check
34384 * @return {Boolean}
34386 isIdSelected : function(id){
34387 return (this.selections.key(id) ? true : false);
34391 handleMouseDown : function(e, t){
34392 var view = this.grid.getView(), rowIndex;
34393 if(this.isLocked() || (rowIndex = view.findRowIndex(t)) === false){
34396 if(e.shiftKey && this.last !== false){
34397 var last = this.last;
34398 this.selectRange(last, rowIndex, e.ctrlKey);
34399 this.last = last; // reset the last
34400 view.focusRow(rowIndex);
34402 var isSelected = this.isSelected(rowIndex);
34403 if(e.button !== 0 && isSelected){
34404 view.focusRow(rowIndex);
34405 }else if(e.ctrlKey && isSelected){
34406 this.deselectRow(rowIndex);
34407 }else if(!isSelected){
34408 this.selectRow(rowIndex, e.button === 0 && (e.ctrlKey || e.shiftKey));
34409 view.focusRow(rowIndex);
34412 this.fireEvent("afterselectionchange", this);
34415 handleDragableRowClick : function(grid, rowIndex, e)
34417 if(e.button === 0 && !e.shiftKey && !e.ctrlKey) {
34418 this.selectRow(rowIndex, false);
34419 grid.view.focusRow(rowIndex);
34420 this.fireEvent("afterselectionchange", this);
34425 * Selects multiple rows.
34426 * @param {Array} rows Array of the indexes of the row to select
34427 * @param {Boolean} keepExisting (optional) True to keep existing selections
34429 selectRows : function(rows, keepExisting){
34431 this.clearSelections();
34433 for(var i = 0, len = rows.length; i < len; i++){
34434 this.selectRow(rows[i], true);
34439 * Selects a range of rows. All rows in between startRow and endRow are also selected.
34440 * @param {Number} startRow The index of the first row in the range
34441 * @param {Number} endRow The index of the last row in the range
34442 * @param {Boolean} keepExisting (optional) True to retain existing selections
34444 selectRange : function(startRow, endRow, keepExisting){
34445 if(this.locked) return;
34447 this.clearSelections();
34449 if(startRow <= endRow){
34450 for(var i = startRow; i <= endRow; i++){
34451 this.selectRow(i, true);
34454 for(var i = startRow; i >= endRow; i--){
34455 this.selectRow(i, true);
34461 * Deselects a range of rows. All rows in between startRow and endRow are also deselected.
34462 * @param {Number} startRow The index of the first row in the range
34463 * @param {Number} endRow The index of the last row in the range
34465 deselectRange : function(startRow, endRow, preventViewNotify){
34466 if(this.locked) return;
34467 for(var i = startRow; i <= endRow; i++){
34468 this.deselectRow(i, preventViewNotify);
34474 * @param {Number} row The index of the row to select
34475 * @param {Boolean} keepExisting (optional) True to keep existing selections
34477 selectRow : function(index, keepExisting, preventViewNotify){
34478 if(this.locked || (index < 0 || index >= this.grid.dataSource.getCount())) return;
34479 if(this.fireEvent("beforerowselect", this, index, keepExisting) !== false){
34480 if(!keepExisting || this.singleSelect){
34481 this.clearSelections();
34483 var r = this.grid.dataSource.getAt(index);
34484 this.selections.add(r);
34485 this.last = this.lastActive = index;
34486 if(!preventViewNotify){
34487 this.grid.getView().onRowSelect(index);
34489 this.fireEvent("rowselect", this, index, r);
34490 this.fireEvent("selectionchange", this);
34496 * @param {Number} row The index of the row to deselect
34498 deselectRow : function(index, preventViewNotify){
34499 if(this.locked) return;
34500 if(this.last == index){
34503 if(this.lastActive == index){
34504 this.lastActive = false;
34506 var r = this.grid.dataSource.getAt(index);
34507 this.selections.remove(r);
34508 if(!preventViewNotify){
34509 this.grid.getView().onRowDeselect(index);
34511 this.fireEvent("rowdeselect", this, index);
34512 this.fireEvent("selectionchange", this);
34516 restoreLast : function(){
34518 this.last = this._last;
34523 acceptsNav : function(row, col, cm){
34524 return !cm.isHidden(col) && cm.isCellEditable(col, row);
34528 onEditorKey : function(field, e){
34529 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
34534 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
34536 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
34538 }else if(k == e.ENTER && !e.ctrlKey){
34542 newCell = g.walkCells(ed.row-1, ed.col, -1, this.acceptsNav, this);
34544 newCell = g.walkCells(ed.row+1, ed.col, 1, this.acceptsNav, this);
34546 }else if(k == e.ESC){
34550 g.startEditing(newCell[0], newCell[1]);
34555 * Ext JS Library 1.1.1
34556 * Copyright(c) 2006-2007, Ext JS, LLC.
34558 * Originally Released Under LGPL - original licence link has changed is not relivant.
34561 * <script type="text/javascript">
34564 * @class Roo.grid.CellSelectionModel
34565 * @extends Roo.grid.AbstractSelectionModel
34566 * This class provides the basic implementation for cell selection in a grid.
34568 * @param {Object} config The object containing the configuration of this model.
34570 Roo.grid.CellSelectionModel = function(config){
34571 Roo.apply(this, config);
34573 this.selection = null;
34577 * @event beforerowselect
34578 * Fires before a cell is selected.
34579 * @param {SelectionModel} this
34580 * @param {Number} rowIndex The selected row index
34581 * @param {Number} colIndex The selected cell index
34583 "beforecellselect" : true,
34585 * @event cellselect
34586 * Fires when a cell is selected.
34587 * @param {SelectionModel} this
34588 * @param {Number} rowIndex The selected row index
34589 * @param {Number} colIndex The selected cell index
34591 "cellselect" : true,
34593 * @event selectionchange
34594 * Fires when the active selection changes.
34595 * @param {SelectionModel} this
34596 * @param {Object} selection null for no selection or an object (o) with two properties
34598 <li>o.record: the record object for the row the selection is in</li>
34599 <li>o.cell: An array of [rowIndex, columnIndex]</li>
34602 "selectionchange" : true
34604 Roo.grid.CellSelectionModel.superclass.constructor.call(this);
34607 Roo.extend(Roo.grid.CellSelectionModel, Roo.grid.AbstractSelectionModel, {
34610 initEvents : function(){
34611 this.grid.on("mousedown", this.handleMouseDown, this);
34612 this.grid.getGridEl().on(Roo.isIE ? "keydown" : "keypress", this.handleKeyDown, this);
34613 var view = this.grid.view;
34614 view.on("refresh", this.onViewChange, this);
34615 view.on("rowupdated", this.onRowUpdated, this);
34616 view.on("beforerowremoved", this.clearSelections, this);
34617 view.on("beforerowsinserted", this.clearSelections, this);
34618 if(this.grid.isEditor){
34619 this.grid.on("beforeedit", this.beforeEdit, this);
34624 beforeEdit : function(e){
34625 this.select(e.row, e.column, false, true, e.record);
34629 onRowUpdated : function(v, index, r){
34630 if(this.selection && this.selection.record == r){
34631 v.onCellSelect(index, this.selection.cell[1]);
34636 onViewChange : function(){
34637 this.clearSelections(true);
34641 * Returns the currently selected cell,.
34642 * @return {Array} The selected cell (row, column) or null if none selected.
34644 getSelectedCell : function(){
34645 return this.selection ? this.selection.cell : null;
34649 * Clears all selections.
34650 * @param {Boolean} true to prevent the gridview from being notified about the change.
34652 clearSelections : function(preventNotify){
34653 var s = this.selection;
34655 if(preventNotify !== true){
34656 this.grid.view.onCellDeselect(s.cell[0], s.cell[1]);
34658 this.selection = null;
34659 this.fireEvent("selectionchange", this, null);
34664 * Returns true if there is a selection.
34665 * @return {Boolean}
34667 hasSelection : function(){
34668 return this.selection ? true : false;
34672 handleMouseDown : function(e, t){
34673 var v = this.grid.getView();
34674 if(this.isLocked()){
34677 var row = v.findRowIndex(t);
34678 var cell = v.findCellIndex(t);
34679 if(row !== false && cell !== false){
34680 this.select(row, cell);
34686 * @param {Number} rowIndex
34687 * @param {Number} collIndex
34689 select : function(rowIndex, colIndex, preventViewNotify, preventFocus, /*internal*/ r){
34690 if(this.fireEvent("beforecellselect", this, rowIndex, colIndex) !== false){
34691 this.clearSelections();
34692 r = r || this.grid.dataSource.getAt(rowIndex);
34695 cell : [rowIndex, colIndex]
34697 if(!preventViewNotify){
34698 var v = this.grid.getView();
34699 v.onCellSelect(rowIndex, colIndex);
34700 if(preventFocus !== true){
34701 v.focusCell(rowIndex, colIndex);
34704 this.fireEvent("cellselect", this, rowIndex, colIndex);
34705 this.fireEvent("selectionchange", this, this.selection);
34710 isSelectable : function(rowIndex, colIndex, cm){
34711 return !cm.isHidden(colIndex);
34715 handleKeyDown : function(e){
34716 if(!e.isNavKeyPress()){
34719 var g = this.grid, s = this.selection;
34722 var cell = g.walkCells(0, 0, 1, this.isSelectable, this);
34724 this.select(cell[0], cell[1]);
34729 var walk = function(row, col, step){
34730 return g.walkCells(row, col, step, sm.isSelectable, sm);
34732 var k = e.getKey(), r = s.cell[0], c = s.cell[1];
34738 newCell = walk(r, c-1, -1);
34740 newCell = walk(r, c+1, 1);
34744 newCell = walk(r+1, c, 1);
34747 newCell = walk(r-1, c, -1);
34750 newCell = walk(r, c+1, 1);
34753 newCell = walk(r, c-1, -1);
34756 if(g.isEditor && !g.editing){
34757 g.startEditing(r, c);
34764 this.select(newCell[0], newCell[1]);
34769 acceptsNav : function(row, col, cm){
34770 return !cm.isHidden(col) && cm.isCellEditable(col, row);
34773 onEditorKey : function(field, e){
34774 var k = e.getKey(), newCell, g = this.grid, ed = g.activeEditor;
34777 newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
34779 newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
34782 }else if(k == e.ENTER && !e.ctrlKey){
34785 }else if(k == e.ESC){
34789 g.startEditing(newCell[0], newCell[1]);
34794 * Ext JS Library 1.1.1
34795 * Copyright(c) 2006-2007, Ext JS, LLC.
34797 * Originally Released Under LGPL - original licence link has changed is not relivant.
34800 * <script type="text/javascript">
34804 * @class Roo.grid.EditorGrid
34805 * @extends Roo.grid.Grid
34806 * Class for creating and editable grid.
34807 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
34808 * The container MUST have some type of size defined for the grid to fill. The container will be
34809 * automatically set to position relative if it isn't already.
34810 * @param {Object} dataSource The data model to bind to
34811 * @param {Object} colModel The column model with info about this grid's columns
34813 Roo.grid.EditorGrid = function(container, config){
34814 Roo.grid.EditorGrid.superclass.constructor.call(this, container, config);
34815 this.getGridEl().addClass("xedit-grid");
34817 if(!this.selModel){
34818 this.selModel = new Roo.grid.CellSelectionModel();
34821 this.activeEditor = null;
34825 * @event beforeedit
34826 * Fires before cell editing is triggered. The edit event object has the following properties <br />
34827 * <ul style="padding:5px;padding-left:16px;">
34828 * <li>grid - This grid</li>
34829 * <li>record - The record being edited</li>
34830 * <li>field - The field name being edited</li>
34831 * <li>value - The value for the field being edited.</li>
34832 * <li>row - The grid row index</li>
34833 * <li>column - The grid column index</li>
34834 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
34836 * @param {Object} e An edit event (see above for description)
34838 "beforeedit" : true,
34841 * Fires after a cell is edited. <br />
34842 * <ul style="padding:5px;padding-left:16px;">
34843 * <li>grid - This grid</li>
34844 * <li>record - The record being edited</li>
34845 * <li>field - The field name being edited</li>
34846 * <li>value - The value being set</li>
34847 * <li>originalValue - The original value for the field, before the edit.</li>
34848 * <li>row - The grid row index</li>
34849 * <li>column - The grid column index</li>
34851 * @param {Object} e An edit event (see above for description)
34853 "afteredit" : true,
34855 * @event validateedit
34856 * Fires after a cell is edited, but before the value is set in the record.
34857 * You can use this to modify the value being set in the field, Return false
34858 * to cancel the change. The edit event object has the following properties <br />
34859 * <ul style="padding:5px;padding-left:16px;">
34860 * <li>editor - This editor</li>
34861 * <li>grid - This grid</li>
34862 * <li>record - The record being edited</li>
34863 * <li>field - The field name being edited</li>
34864 * <li>value - The value being set</li>
34865 * <li>originalValue - The original value for the field, before the edit.</li>
34866 * <li>row - The grid row index</li>
34867 * <li>column - The grid column index</li>
34868 * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
34870 * @param {Object} e An edit event (see above for description)
34872 "validateedit" : true
34874 this.on("bodyscroll", this.stopEditing, this);
34875 this.on(this.clicksToEdit == 1 ? "cellclick" : "celldblclick", this.onCellDblClick, this);
34878 Roo.extend(Roo.grid.EditorGrid, Roo.grid.Grid, {
34880 * @cfg {Number} clicksToEdit
34881 * The number of clicks on a cell required to display the cell's editor (defaults to 2)
34888 trackMouseOver: false, // causes very odd FF errors
34890 onCellDblClick : function(g, row, col){
34891 this.startEditing(row, col);
34894 onEditComplete : function(ed, value, startValue){
34895 this.editing = false;
34896 this.activeEditor = null;
34897 ed.un("specialkey", this.selModel.onEditorKey, this.selModel);
34899 var field = this.colModel.getDataIndex(ed.col);
34904 originalValue: startValue,
34911 if(String(value) !== String(startValue)){
34913 if(this.fireEvent("validateedit", e) !== false && !e.cancel){
34914 r.set(field, e.value);
34915 delete e.cancel; //?? why!!!
34916 this.fireEvent("afteredit", e);
34919 this.fireEvent("afteredit", e); // always fir it!
34921 this.view.focusCell(ed.row, ed.col);
34925 * Starts editing the specified for the specified row/column
34926 * @param {Number} rowIndex
34927 * @param {Number} colIndex
34929 startEditing : function(row, col){
34930 this.stopEditing();
34931 if(this.colModel.isCellEditable(col, row)){
34932 this.view.ensureVisible(row, col, true);
34933 var r = this.dataSource.getAt(row);
34934 var field = this.colModel.getDataIndex(col);
34939 value: r.data[field],
34944 if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
34945 this.editing = true;
34946 var ed = this.colModel.getCellEditor(col, row);
34952 ed.render(ed.parentEl || document.body);
34955 (function(){ // complex but required for focus issues in safari, ie and opera
34959 ed.on("complete", this.onEditComplete, this, {single: true});
34960 ed.on("specialkey", this.selModel.onEditorKey, this.selModel);
34961 this.activeEditor = ed;
34962 var v = r.data[field];
34963 ed.startEdit(this.view.getCell(row, col), v);
34964 }).defer(50, this);
34970 * Stops any active editing
34972 stopEditing : function(){
34973 if(this.activeEditor){
34974 this.activeEditor.completeEdit();
34976 this.activeEditor = null;
34980 * Ext JS Library 1.1.1
34981 * Copyright(c) 2006-2007, Ext JS, LLC.
34983 * Originally Released Under LGPL - original licence link has changed is not relivant.
34986 * <script type="text/javascript">
34989 // private - not really -- you end up using it !
34990 // This is a support class used internally by the Grid components
34993 * @class Roo.grid.GridEditor
34994 * @extends Roo.Editor
34995 * Class for creating and editable grid elements.
34996 * @param {Object} config any settings (must include field)
34998 Roo.grid.GridEditor = function(field, config){
34999 if (!config && field.field) {
35001 field = Roo.factory(config.field, Roo.form);
35003 Roo.grid.GridEditor.superclass.constructor.call(this, field, config);
35004 field.monitorTab = false;
35007 Roo.extend(Roo.grid.GridEditor, Roo.Editor, {
35010 * @cfg {Roo.form.Field} field Field to wrap (or xtyped)
35013 alignment: "tl-tl",
35016 cls: "x-small-editor x-grid-editor",
35021 * Ext JS Library 1.1.1
35022 * Copyright(c) 2006-2007, Ext JS, LLC.
35024 * Originally Released Under LGPL - original licence link has changed is not relivant.
35027 * <script type="text/javascript">
35032 Roo.grid.PropertyRecord = Roo.data.Record.create([
35033 {name:'name',type:'string'}, 'value'
35037 Roo.grid.PropertyStore = function(grid, source){
35039 this.store = new Roo.data.Store({
35040 recordType : Roo.grid.PropertyRecord
35042 this.store.on('update', this.onUpdate, this);
35044 this.setSource(source);
35046 Roo.grid.PropertyStore.superclass.constructor.call(this);
35051 Roo.extend(Roo.grid.PropertyStore, Roo.util.Observable, {
35052 setSource : function(o){
35054 this.store.removeAll();
35057 if(this.isEditableValue(o[k])){
35058 data.push(new Roo.grid.PropertyRecord({name: k, value: o[k]}, k));
35061 this.store.loadRecords({records: data}, {}, true);
35064 onUpdate : function(ds, record, type){
35065 if(type == Roo.data.Record.EDIT){
35066 var v = record.data['value'];
35067 var oldValue = record.modified['value'];
35068 if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
35069 this.source[record.id] = v;
35071 this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
35078 getProperty : function(row){
35079 return this.store.getAt(row);
35082 isEditableValue: function(val){
35083 if(val && val instanceof Date){
35085 }else if(typeof val == 'object' || typeof val == 'function'){
35091 setValue : function(prop, value){
35092 this.source[prop] = value;
35093 this.store.getById(prop).set('value', value);
35096 getSource : function(){
35097 return this.source;
35101 Roo.grid.PropertyColumnModel = function(grid, store){
35104 g.PropertyColumnModel.superclass.constructor.call(this, [
35105 {header: this.nameText, sortable: true, dataIndex:'name', id: 'name'},
35106 {header: this.valueText, resizable:false, dataIndex: 'value', id: 'value'}
35108 this.store = store;
35109 this.bselect = Roo.DomHelper.append(document.body, {
35110 tag: 'select', style:'display:none', cls: 'x-grid-editor', children: [
35111 {tag: 'option', value: 'true', html: 'true'},
35112 {tag: 'option', value: 'false', html: 'false'}
35115 Roo.id(this.bselect);
35118 'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
35119 'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
35120 'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
35121 'int' : new g.GridEditor(new f.NumberField({selectOnFocus:true, allowDecimals:false, style:'text-align:left;'})),
35122 'boolean' : new g.GridEditor(new f.Field({el:this.bselect,selectOnFocus:true}))
35124 this.renderCellDelegate = this.renderCell.createDelegate(this);
35125 this.renderPropDelegate = this.renderProp.createDelegate(this);
35128 Roo.extend(Roo.grid.PropertyColumnModel, Roo.grid.ColumnModel, {
35132 valueText : 'Value',
35134 dateFormat : 'm/j/Y',
35137 renderDate : function(dateVal){
35138 return dateVal.dateFormat(this.dateFormat);
35141 renderBool : function(bVal){
35142 return bVal ? 'true' : 'false';
35145 isCellEditable : function(colIndex, rowIndex){
35146 return colIndex == 1;
35149 getRenderer : function(col){
35151 this.renderCellDelegate : this.renderPropDelegate;
35154 renderProp : function(v){
35155 return this.getPropertyName(v);
35158 renderCell : function(val){
35160 if(val instanceof Date){
35161 rv = this.renderDate(val);
35162 }else if(typeof val == 'boolean'){
35163 rv = this.renderBool(val);
35165 return Roo.util.Format.htmlEncode(rv);
35168 getPropertyName : function(name){
35169 var pn = this.grid.propertyNames;
35170 return pn && pn[name] ? pn[name] : name;
35173 getCellEditor : function(colIndex, rowIndex){
35174 var p = this.store.getProperty(rowIndex);
35175 var n = p.data['name'], val = p.data['value'];
35177 if(typeof(this.grid.customEditors[n]) == 'string'){
35178 return this.editors[this.grid.customEditors[n]];
35180 if(typeof(this.grid.customEditors[n]) != 'undefined'){
35181 return this.grid.customEditors[n];
35183 if(val instanceof Date){
35184 return this.editors['date'];
35185 }else if(typeof val == 'number'){
35186 return this.editors['number'];
35187 }else if(typeof val == 'boolean'){
35188 return this.editors['boolean'];
35190 return this.editors['string'];
35196 * @class Roo.grid.PropertyGrid
35197 * @extends Roo.grid.EditorGrid
35198 * This class represents the interface of a component based property grid control.
35199 * <br><br>Usage:<pre><code>
35200 var grid = new Roo.grid.PropertyGrid("my-container-id", {
35208 * @param {String/HTMLElement/Roo.Element} container The element into which this grid will be rendered -
35209 * The container MUST have some type of size defined for the grid to fill. The container will be
35210 * automatically set to position relative if it isn't already.
35211 * @param {Object} config A config object that sets properties on this grid.
35213 Roo.grid.PropertyGrid = function(container, config){
35214 config = config || {};
35215 var store = new Roo.grid.PropertyStore(this);
35216 this.store = store;
35217 var cm = new Roo.grid.PropertyColumnModel(this, store);
35218 store.store.sort('name', 'ASC');
35219 Roo.grid.PropertyGrid.superclass.constructor.call(this, container, Roo.apply({
35222 enableColLock:false,
35223 enableColumnMove:false,
35225 trackMouseOver: false,
35228 this.getGridEl().addClass('x-props-grid');
35229 this.lastEditRow = null;
35230 this.on('columnresize', this.onColumnResize, this);
35233 * @event beforepropertychange
35234 * Fires before a property changes (return false to stop?)
35235 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
35236 * @param {String} id Record Id
35237 * @param {String} newval New Value
35238 * @param {String} oldval Old Value
35240 "beforepropertychange": true,
35242 * @event propertychange
35243 * Fires after a property changes
35244 * @param {Roo.grid.PropertyGrid} grid property grid? (check could be store)
35245 * @param {String} id Record Id
35246 * @param {String} newval New Value
35247 * @param {String} oldval Old Value
35249 "propertychange": true
35251 this.customEditors = this.customEditors || {};
35253 Roo.extend(Roo.grid.PropertyGrid, Roo.grid.EditorGrid, {
35256 * @cfg {Object} customEditors map of colnames=> custom editors.
35257 * the custom editor can be one of the standard ones (date|string|number|int|boolean), or a
35258 * grid editor eg. Roo.grid.GridEditor(new Roo.form.TextArea({selectOnFocus:true})),
35259 * false disables editing of the field.
35263 * @cfg {Object} propertyNames map of property Names to their displayed value
35266 render : function(){
35267 Roo.grid.PropertyGrid.superclass.render.call(this);
35268 this.autoSize.defer(100, this);
35271 autoSize : function(){
35272 Roo.grid.PropertyGrid.superclass.autoSize.call(this);
35274 this.view.fitColumns();
35278 onColumnResize : function(){
35279 this.colModel.setColumnWidth(1, this.container.getWidth(true)-this.colModel.getColumnWidth(0));
35283 * Sets the data for the Grid
35284 * accepts a Key => Value object of all the elements avaiable.
35285 * @param {Object} data to appear in grid.
35287 setSource : function(source){
35288 this.store.setSource(source);
35292 * Gets all the data from the grid.
35293 * @return {Object} data data stored in grid
35295 getSource : function(){
35296 return this.store.getSource();
35300 * Ext JS Library 1.1.1
35301 * Copyright(c) 2006-2007, Ext JS, LLC.
35303 * Originally Released Under LGPL - original licence link has changed is not relivant.
35306 * <script type="text/javascript">
35310 * @class Roo.LoadMask
35311 * A simple utility class for generically masking elements while loading data. If the element being masked has
35312 * an underlying {@link Roo.data.Store}, the masking will be automatically synchronized with the store's loading
35313 * process and the mask element will be cached for reuse. For all other elements, this mask will replace the
35314 * element's UpdateManager load indicator and will be destroyed after the initial load.
35316 * Create a new LoadMask
35317 * @param {String/HTMLElement/Roo.Element} el The element or DOM node, or its id
35318 * @param {Object} config The config object
35320 Roo.LoadMask = function(el, config){
35321 this.el = Roo.get(el);
35322 Roo.apply(this, config);
35324 this.store.on('beforeload', this.onBeforeLoad, this);
35325 this.store.on('load', this.onLoad, this);
35326 this.store.on('loadexception', this.onLoad, this);
35327 this.removeMask = false;
35329 var um = this.el.getUpdateManager();
35330 um.showLoadIndicator = false; // disable the default indicator
35331 um.on('beforeupdate', this.onBeforeLoad, this);
35332 um.on('update', this.onLoad, this);
35333 um.on('failure', this.onLoad, this);
35334 this.removeMask = true;
35338 Roo.LoadMask.prototype = {
35340 * @cfg {Boolean} removeMask
35341 * True to create a single-use mask that is automatically destroyed after loading (useful for page loads),
35342 * False to persist the mask element reference for multiple uses (e.g., for paged data widgets). Defaults to false.
35345 * @cfg {String} msg
35346 * The text to display in a centered loading message box (defaults to 'Loading...')
35348 msg : 'Loading...',
35350 * @cfg {String} msgCls
35351 * The CSS class to apply to the loading message element (defaults to "x-mask-loading")
35353 msgCls : 'x-mask-loading',
35356 * Read-only. True if the mask is currently disabled so that it will not be displayed (defaults to false)
35362 * Disables the mask to prevent it from being displayed
35364 disable : function(){
35365 this.disabled = true;
35369 * Enables the mask so that it can be displayed
35371 enable : function(){
35372 this.disabled = false;
35376 onLoad : function(){
35377 this.el.unmask(this.removeMask);
35381 onBeforeLoad : function(){
35382 if(!this.disabled){
35383 this.el.mask(this.msg, this.msgCls);
35388 destroy : function(){
35390 this.store.un('beforeload', this.onBeforeLoad, this);
35391 this.store.un('load', this.onLoad, this);
35392 this.store.un('loadexception', this.onLoad, this);
35394 var um = this.el.getUpdateManager();
35395 um.un('beforeupdate', this.onBeforeLoad, this);
35396 um.un('update', this.onLoad, this);
35397 um.un('failure', this.onLoad, this);
35402 * Ext JS Library 1.1.1
35403 * Copyright(c) 2006-2007, Ext JS, LLC.
35405 * Originally Released Under LGPL - original licence link has changed is not relivant.
35408 * <script type="text/javascript">
35410 Roo.XTemplate = function(){
35411 Roo.XTemplate.superclass.constructor.apply(this, arguments);
35414 s = ['<tpl>', s, '</tpl>'].join('');
35416 var re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/;
35418 var nameRe = /^<tpl\b[^>]*?for="(.*?)"/;
35419 var ifRe = /^<tpl\b[^>]*?if="(.*?)"/;
35420 var execRe = /^<tpl\b[^>]*?exec="(.*?)"/;
35424 while(m = s.match(re)){
35425 var m2 = m[0].match(nameRe);
35426 var m3 = m[0].match(ifRe);
35427 var m4 = m[0].match(execRe);
35428 var exp = null, fn = null, exec = null;
35429 var name = m2 && m2[1] ? m2[1] : '';
35431 exp = m3 && m3[1] ? m3[1] : null;
35433 fn = new Function('values', 'parent', 'with(values){ return '+(Roo.util.Format.htmlDecode(exp))+'; }');
35437 exp = m4 && m4[1] ? m4[1] : null;
35439 exec = new Function('values', 'parent', 'with(values){ '+(Roo.util.Format.htmlDecode(exp))+'; }');
35444 case '.': name = new Function('values', 'parent', 'with(values){ return values; }'); break;
35445 case '..': name = new Function('values', 'parent', 'with(values){ return parent; }'); break;
35446 default: name = new Function('values', 'parent', 'with(values){ return '+name+'; }');
35456 s = s.replace(m[0], '{xtpl'+ id + '}');
35459 for(var i = tpls.length-1; i >= 0; --i){
35460 this.compileTpl(tpls[i]);
35462 this.master = tpls[tpls.length-1];
35465 Roo.extend(Roo.XTemplate, Roo.Template, {
35467 re : /\{([\w-\.]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
35469 applySubTemplate : function(id, values, parent){
35470 var t = this.tpls[id];
35471 if(t.test && !t.test.call(this, values, parent)){
35474 if(t.exec && t.exec.call(this, values, parent)){
35477 var vs = t.target ? t.target.call(this, values, parent) : values;
35478 parent = t.target ? values : parent;
35479 if(t.target && vs instanceof Array){
35481 for(var i = 0, len = vs.length; i < len; i++){
35482 buf[buf.length] = t.compiled.call(this, vs[i], parent);
35484 return buf.join('');
35486 return t.compiled.call(this, vs, parent);
35489 compileTpl : function(tpl){
35490 var fm = Roo.util.Format;
35491 var useF = this.disableFormats !== true;
35492 var sep = Roo.isGecko ? "+" : ",";
35493 var fn = function(m, name, format, args){
35494 if(name.substr(0, 4) == 'xtpl'){
35495 return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent)'+sep+"'";
35498 if(name.indexOf('.') != -1){
35501 v = "values['" + name + "']";
35503 if(format && useF){
35504 args = args ? ',' + args : "";
35505 if(format.substr(0, 5) != "this."){
35506 format = "fm." + format + '(';
35508 format = 'this.call("'+ format.substr(5) + '", ';
35512 args= ''; format = "("+v+" === undefined ? '' : ";
35514 return "'"+ sep + format + v + args + ")"+sep+"'";
35517 // branched to use + in gecko and [].join() in others
35519 body = "tpl.compiled = function(values, parent){ return '" +
35520 tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
35523 body = ["tpl.compiled = function(values, parent){ return ['"];
35524 body.push(tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn));
35525 body.push("'].join('');};");
35526 body = body.join('');
35528 /** eval:var:zzzzzzz */
35533 applyTemplate : function(values){
35534 return this.master.compiled.call(this, values, {});
35538 apply : function(){
35539 return this.applyTemplate.apply(this, arguments);
35542 compile : function(){return this;}
35545 Roo.XTemplate.from = function(el){
35546 el = Roo.getDom(el);
35547 return new Roo.XTemplate(el.value || el.innerHTML);
35549 * Original code for Roojs - LGPL
35550 * <script type="text/javascript">
35554 * @class Roo.XComponent
35555 * A delayed Element creator...
35557 * Mypart.xyx = new Roo.XComponent({
35559 parent : 'Mypart.xyz', // empty == document.element.!!
35563 disabled : function() {}
35565 tree : function() { // return an tree of xtype declared components
35569 xtype : 'NestedLayoutPanel',
35574 * @extends Roo.util.Observable
35576 * @param cfg {Object} configuration of component
35579 Roo.XComponent = function(cfg) {
35580 Roo.apply(this, cfg);
35584 * Fires when this the componnt is built
35585 * @param {Roo.XComponent} c the component
35589 * @event buildcomplete
35590 * Fires on the top level element when all elements have been built
35591 * @param {Roo.XComponent} c the top level component.
35593 'buildcomplete' : true,
35597 Roo.XComponent.register(this);
35598 this.modules = false;
35599 this.el = false; // where the layout goes..
35603 Roo.extend(Roo.XComponent, Roo.util.Observable, {
35606 * The created element (with Roo.factory())
35607 * @type {Roo.Layout}
35613 * for BC - use el in new code
35614 * @type {Roo.Layout}
35620 * for BC - use el in new code
35621 * @type {Roo.Layout}
35626 * @cfg {Function|boolean} disabled
35627 * If this module is disabled by some rule, return true from the funtion
35632 * @cfg {String} parent
35633 * Name of parent element which it get xtype added to..
35638 * @cfg {String} order
35639 * Used to set the order in which elements are created (usefull for multiple tabs)
35644 * @cfg {String} name
35645 * String to display while loading.
35649 * @cfg {Array} items
35650 * A single item array - the first element is the root of the tree..
35651 * It's done this way to stay compatible with the Xtype system...
35659 Roo.apply(Roo.XComponent, {
35662 * @property buildCompleted
35663 * True when the builder has completed building the interface.
35666 buildCompleted : false,
35669 * @property topModule
35670 * the upper most module - uses document.element as it's constructor.
35677 * @property modules
35678 * array of modules to be created by registration system.
35679 * @type Roo.XComponent
35686 * Register components to be built later.
35688 * This solves the following issues
35689 * - Building is not done on page load, but after an authentication process has occured.
35690 * - Interface elements are registered on page load
35691 * - Parent Interface elements may not be loaded before child, so this handles that..
35698 module : 'Pman.Tab.projectMgr',
35700 parent : 'Pman.layout',
35701 disabled : false, // or use a function..
35704 * * @param {Object} details about module
35706 register : function(obj) {
35707 this.modules.push(obj);
35711 * convert a string to an object..
35715 toObject : function(str)
35717 if (!str || typeof(str) == 'object') {
35720 var ar = str.split('.');
35724 eval('if (typeof ' + rt + ' == "undefined"){ o = false;} o = ' + rt + ';');
35726 throw "Module not found : " + str;
35728 Roo.each(ar, function(e) {
35729 if (typeof(o[e]) == 'undefined') {
35730 throw "Module not found : " + str;
35740 * move modules into their correct place in the tree..
35743 preBuild : function ()
35746 Roo.each(this.modules , function (obj)
35748 obj.parent = this.toObject(obj.parent);
35751 this.topModule = obj;
35755 if (!obj.parent.modules) {
35756 obj.parent.modules = new Roo.util.MixedCollection(false,
35757 function(o) { return o.order + '' }
35761 obj.parent.modules.add(obj);
35766 * make a list of modules to build.
35767 * @return {Array} list of modules.
35770 buildOrder : function()
35773 var cmp = function(a,b) {
35774 return String(a).toUpperCase() > String(b).toUpperCase() ? 1 : -1;
35777 if (!this.topModule || !this.topModule.modules) {
35778 throw "No top level modules to build";
35781 // make a flat list in order of modules to build.
35782 var mods = [ this.topModule ];
35785 // add modules to their parents..
35786 var addMod = function(m) {
35787 // console.log(m.modKey);
35791 m.modules.keySort('ASC', cmp );
35792 m.modules.each(addMod);
35794 // not sure if this is used any more..
35796 m.finalize.name = m.name + " (clean up) ";
35797 mods.push(m.finalize);
35801 this.topModule.modules.keySort('ASC', cmp );
35802 this.topModule.modules.each(addMod);
35807 * Build the registered modules.
35808 * @param {Object} parent element.
35809 * @param {Function} optional method to call after module has been added.
35817 var mods = this.buildOrder();
35819 //this.allmods = mods;
35820 //console.log(mods);
35822 if (!mods.length) { // should not happen
35823 throw "NO modules!!!";
35828 // flash it up as modal - so we store the mask!?
35829 Roo.MessageBox.show({ title: 'loading' });
35830 Roo.MessageBox.show({
35831 title: "Please wait...",
35832 msg: "Building Interface...",
35839 var total = mods.length;
35842 var progressRun = function() {
35843 if (!mods.length) {
35844 console.log('hide?');
35845 Roo.MessageBox.hide();
35846 _this.topModule.fireEvent('buildcomplete', _this.topModule);
35850 var m = mods.shift();
35852 if (typeof(m) == 'function') { // not sure if this is supported any more..
35854 return progressRun.defer(10, _this);
35857 Roo.MessageBox.updateProgress(
35858 (total - mods.length)/total, "Building Interface " + (total - mods.length) +
35860 (m.name ? (' - ' + m.name) : '')
35865 var disabled = (typeof(m.disabled) == 'function') ?
35866 m.disabled.call(m.module.disabled) : m.disabled;
35870 return progressRun(); // we do not update the display!
35874 // it's a top level one..
35875 var layoutbase = new Ext.BorderLayout(document.body, {
35881 tabPosition: 'top',
35882 //resizeTabs: true,
35883 alwaysShowTabs: true,
35887 var tree = m.tree();
35888 tree.region = 'center';
35889 m.el = layoutbase.addxtype(tree);
35891 m.layout = m.panel.layout;
35892 return progressRun.defer(10, _this);
35895 var tree = m.tree();
35896 tree.region = tree.region || m.region;
35897 m.el = m.parent.el.addxtype(tree);
35898 m.fireEvent('built', m);
35900 m.layout = m.panel.layout;
35901 progressRun.defer(10, _this);
35904 progressRun.defer(1, _this);
35914 //<script type="text/javascript">
35919 * @extends Roo.LayoutDialog
35920 * A generic Login Dialog..... - only one needed in theory!?!?
35922 * Fires XComponent builder on success...
35925 * username,password, lang = for login actions.
35926 * check = 1 for periodic checking that sesion is valid.
35927 * passwordRequest = email request password
35928 * logout = 1 = to logout
35930 * Affects: (this id="????" elements)
35931 * loading (removed) (used to indicate application is loading)
35932 * loading-mask (hides) (used to hide application when it's building loading)
35938 * Myapp.login = Roo.Login({
35954 Roo.Login = function(cfg)
35957 'refreshed' : true,
35960 Roo.apply(this,cfg);
35962 Roo.onReady(function() {
35968 Roo.Login.superclass.constructor.call(this, this);
35969 //this.addxtype(this.items[0]);
35975 Roo.extend(Roo.Login, Roo.LayoutDialog, {
35978 * @cfg {String} method
35979 * Method used to query for login details.
35984 * @cfg {String} url
35985 * URL to query login data. - eg. baseURL + '/Login.php'
35991 * The user data - if user.id < 0 then login will be bypassed. (used for inital setup situation.
35996 * @property checkFails
35997 * Number of times we have attempted to get authentication check, and failed.
36002 * @property intervalID
36003 * The window interval that does the constant login checking.
36009 onLoad : function() // called on page load...
36013 if (Roo.get('loading')) { // clear any loading indicator..
36014 Roo.get('loading').remove();
36017 //this.switchLang('en'); // set the language to english..
36020 success: function(response, opts) { // check successfull...
36022 var res = this.processResponse(response);
36023 this.checkFails =0;
36024 if (!res.success) { // error!
36025 this.checkFails = 5;
36026 //console.log('call failure');
36027 return this.failure(response,opts);
36030 if (!res.data.id) { // id=0 == login failure.
36031 return this.show();
36035 //console.log(success);
36036 this.fillAuth(res.data);
36037 this.checkFails =0;
36038 Roo.XComponent.build();
36040 failure : this.show
36046 check: function(cfg) // called every so often to refresh cookie etc..
36048 if (cfg.again) { // could be undefined..
36051 this.checkFails = 0;
36054 if (this.sending) {
36055 if ( this.checkFails > 4) {
36056 Roo.MessageBox.alert("Error",
36057 "Error getting authentication status. - try reloading, or wait a while", function() {
36058 _this.sending = false;
36063 _this.check.defer(10000, _this, [ cfg ]); // check in 10 secs.
36066 this.sending = true;
36073 method: this.method,
36074 success: cfg.success || this.success,
36075 failure : cfg.failure || this.failure,
36085 window.onbeforeunload = function() { }; // false does not work for IE..
36095 failure : function() {
36096 Roo.MessageBox.alert("Error", "Error logging out. - continuing anyway.", function() {
36097 document.location = document.location.toString() + '?ts=' + Math.random();
36101 success : function() {
36102 _this.user = false;
36103 this.checkFails =0;
36105 document.location = document.location.toString() + '?ts=' + Math.random();
36112 processResponse : function (response)
36116 res = Roo.decode(response.responseText);
36118 if (typeof(res) != 'object') {
36119 res = { success : false, errorMsg : res, errors : true };
36121 if (typeof(res.success) == 'undefined') {
36122 res.success = false;
36126 res = { success : false, errorMsg : response.responseText, errors : true };
36131 success : function(response, opts) // check successfull...
36133 this.sending = false;
36134 var res = this.processResponse(response);
36135 if (!res.success) {
36136 return this.failure(response, opts);
36138 if (!res.data || !res.data.id) {
36139 return this.failure(response,opts);
36141 //console.log(res);
36142 this.fillAuth(res.data);
36144 this.checkFails =0;
36149 failure : function (response, opts) // called if login 'check' fails.. (causes re-check)
36151 this.authUser = -1;
36152 this.sending = false;
36153 var res = this.processResponse(response);
36154 //console.log(res);
36155 if ( this.checkFails > 2) {
36157 Roo.MessageBox.alert("Error", res.errorMsg ? res.errorMsg :
36158 "Error getting authentication status. - try reloading");
36161 opts.callCfg.again = true;
36162 this.check.defer(1000, this, [ opts.callCfg ]);
36168 fillAuth: function(au) {
36169 this.startAuthCheck();
36170 this.authUserId = au.id;
36171 this.authUser = au;
36172 this.lastChecked = new Date();
36173 this.fireEvent('refreshed', au);
36174 //Pman.Tab.FaxQueue.newMaxId(au.faxMax);
36175 //Pman.Tab.FaxTab.setTitle(au.faxNumPending);
36176 au.lang = au.lang || 'en';
36177 //this.switchLang(Roo.state.Manager.get('Pman.Login.lang', 'en'));
36178 Roo.state.Manager.set( this.realm + 'lang' , au.lang);
36179 this.switchLang(au.lang );
36182 // open system... - -on setyp..
36183 if (this.authUserId < 0) {
36184 Roo.MessageBox.alert("Warning",
36185 "This is an open system - please set up a admin user with a password.");
36188 //Pman.onload(); // which should do nothing if it's a re-auth result...
36193 startAuthCheck : function() // starter for timeout checking..
36195 if (this.intervalID) { // timer already in place...
36199 this.intervalID = window.setInterval(function() {
36200 _this.check(false);
36201 }, 120000); // every 120 secs = 2mins..
36207 switchLang : function (lang)
36209 _T = typeof(_T) == 'undefined' ? false : _T;
36210 if (!_T || !lang.length) {
36214 if (!_T && lang != 'en') {
36215 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
36219 if (typeof(_T.en) == 'undefined') {
36221 Roo.apply(_T.en, _T);
36224 if (typeof(_T[lang]) == 'undefined') {
36225 Roo.MessageBox.alert("Sorry", "Language not available yet (" + lang +')');
36230 Roo.apply(_T, _T[lang]);
36231 // just need to set the text values for everything...
36233 /* this will not work ...
36237 function formLabel(name, val) {
36238 _this.form.findField(name).fieldEl.child('label').dom.innerHTML = val;
36241 formLabel('password', "Password"+':');
36242 formLabel('username', "Email Address"+':');
36243 formLabel('lang', "Language"+':');
36244 this.dialog.setTitle("Login");
36245 this.dialog.buttons[0].setText("Forgot Password");
36246 this.dialog.buttons[1].setText("Login");
36265 collapsible: false,
36267 center: { // needed??
36270 // tabPosition: 'top',
36273 alwaysShowTabs: false
36277 show : function(dlg)
36279 //console.log(this);
36280 this.form = this.layout.getRegion('center').activePanel.form;
36281 this.form.dialog = dlg;
36282 this.buttons[0].form = this.form;
36283 this.buttons[0].dialog = dlg
36284 this.buttons[1].form = this.form;
36285 this.buttons[1].dialog = dlg;
36287 //this.resizeToLogo.defer(1000,this);
36288 // this is all related to resizing for logos..
36289 //var sz = Roo.get(Pman.Login.form.el.query('img')[0]).getSize();
36291 // this.resizeToLogo.defer(1000,this);
36294 //var w = Ext.lib.Dom.getViewWidth() - 100;
36295 //var h = Ext.lib.Dom.getViewHeight() - 100;
36296 //this.resizeTo(Math.max(350, Math.min(sz.width + 30, w)),Math.min(sz.height+200, h));
36298 if (this.disabled) {
36303 if (this.user.id < 0) { // used for inital setup situations.
36307 if (this.intervalID) {
36308 // remove the timer
36309 window.clearInterval(this.intervalID);
36310 this.intervalID = false;
36314 if (Roo.get('loading')) {
36315 Roo.get('loading').remove();
36317 if (Roo.get('loading-mask')) {
36318 Roo.get('loading-mask').hide();
36321 //incomming._node = tnode;
36323 //this.dialog.modal = !modal;
36324 //this.dialog.show();
36328 this.form.setValues({
36329 'username' : Roo.state.Manager.get(this.realm + '.username', ''),
36330 'lang' : Roo.state.Manager.get(this.realm + '.lang', 'en')
36333 this.switchLang(Roo.state.Manager.get(this.realm + '.lang', 'en'));
36334 if (this.form.findField('username').getValue().length > 0 ){
36335 this.form.findField('password').focus();
36337 this.form.findField('username').focus();
36345 xtype : 'ContentPanel',
36357 style : 'margin: 10px;',
36360 actionfailed : function(f, act) {
36361 // form can return { errors: .... }
36363 //act.result.errors // invalid form element list...
36364 //act.result.errorMsg// invalid form element list...
36366 this.dialog.el.unmask();
36367 Roo.MessageBox.alert("Error", act.result.errorMsg ? act.result.errorMsg :
36368 "Login failed - communication error - try again.");
36371 actioncomplete: function(re, act) {
36373 Roo.state.Manager.set(
36374 this.dialog.realm + '.username',
36375 this.findField('username').getValue()
36377 Roo.state.Manager.set(
36378 this.dialog.realm + '.lang',
36379 this.findField('lang').getValue()
36382 this.dialog.fillAuth(act.result.data);
36384 this.dialog.hide();
36386 if (Roo.get('loading-mask')) {
36387 Roo.get('loading-mask').show();
36389 Roo.XComponent.build();
36397 xtype : 'TextField',
36399 fieldLabel: "Email Address",
36402 autoCreate : {tag: "input", type: "text", size: "20"}
36405 xtype : 'TextField',
36407 fieldLabel: "Password",
36408 inputType: 'password',
36411 autoCreate : {tag: "input", type: "text", size: "20"},
36413 specialkey : function(e,ev) {
36414 if (ev.keyCode == 13) {
36415 this.form.dialog.el.mask("Logging in");
36416 this.form.doAction('submit', {
36417 url: this.form.dialog.url,
36418 method: this.form.dialog.method,
36425 xtype : 'ComboBox',
36427 fieldLabel: "Language",
36430 xtype : 'SimpleStore',
36431 fields: ['lang', 'ldisp'],
36433 [ 'en', 'English' ],
36434 [ 'zh_HK' , '\u7E41\u4E2D' ],
36435 [ 'zh_CN', '\u7C21\u4E2D' ]
36439 valueField : 'lang',
36440 hiddenName: 'lang',
36442 displayField:'ldisp',
36446 triggerAction: 'all',
36447 emptyText:'Select a Language...',
36448 selectOnFocus:true,
36450 select : function(cb, rec, ix) {
36451 this.form.switchLang(rec.data.lang);
36467 text : "Forgot Password",
36469 click : function() {
36470 //console.log(this);
36471 var n = this.form.findField('username').getValue();
36473 Roo.MessageBox.alert("Error", "Fill in your email address");
36477 url: this.dialog.url,
36481 method: this.dialog.method,
36482 success: function(response, opts) { // check successfull...
36484 var res = this.dialog.processResponse(response);
36485 if (!res.success) { // error!
36486 Roo.MessageBox.alert("Error" ,
36487 res.errorMsg ? res.errorMsg : "Problem Requesting Password Reset");
36490 Roo.MessageBox.alert("Notice" ,
36491 "Please check you email for the Password Reset message");
36493 failure : function() {
36494 Roo.MessageBox.alert("Error" , "Problem Requesting Password Reset");
36507 click : function () {
36509 this.dialog.el.mask("Logging in");
36510 this.form.doAction('submit', {
36511 url: this.dialog.url,
36512 method: this.dialog.method